2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 import com.ericsson.testvnf.server.models.RpcData;
22 import java.util.concurrent.TimeUnit;
24 import groovy.util.XmlParser
25 import java.util.logging.Logger;
26 Logger logger = Logger.getLogger("")
27 println "edit config - candidate!"
28 def RpcData data = binding.getVariable("RpcData")
31 def operationsData = new XmlParser().parseText(data.getOperationTagContent())
32 println "operations data::::" + operationsData
37 if (!operationsData.config.'target-name'.isEmpty()){
38 targetName = operationsData.config.'target-name'.text()
39 println "target-name ::::" + operationsData.config.'target-name'.text()
41 logger.info("targetName not found");
42 println("targetName not found")
44 if (!operationsData.config.'target-address'.isEmpty()){
45 targetAddress = operationsData.config.'target-address'.text()
46 println "target-address ::::" + operationsData.config.'target-address'.text()
48 logger.info("targetAddress not found");
49 println ("targetAddress not found");
52 def db = [url: "jdbc:mariadb://localhost:3306/netconf_db?useSSL=false",
53 user: "root", password: "root", driver: 'org.mariadb.jdbc.Driver']
54 // def db = [url: "jdbc:mariadb://mariadb:3306/netconf_db?useSSL=false",
55 // user: "root", password: "root", driver: 'org.mariadb.jdbc.Driver']
56 def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
57 println "DB connection ready"
58 logger.info("DB connection ready")
59 if (targetName != null && targetAddress != null){
60 def metadata = sql.connection.getMetaData()
61 def tables = metadata.getTables(null, null, "AddressTable", null)
63 logger.info("table not found");
64 println "table not found"
65 sql.execute("CREATE TABLE AddressTable (Name varchar(255), HTTPAddress varchar(255), PRIMARY KEY (Name))")
67 def query = "INSERT INTO AddressTable (NAME, HTTPAddress) VALUES(\""+targetName+"\",\""+targetAddress+"\") ON DUPLICATE KEY UPDATE Name=\""+targetName+"\", HTTPAddress=\""+targetAddress+"\""
68 println "query" + query
71 result = "<rpc-reply message-id=\"<MID>\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> <ok/> </rpc-reply>"
73 result = "<rpc-reply message-id=\\\"<MID>\\\" xmlns=\\\"urn:ietf:params:xml:ns:netconf:base:1.0\\\"> <rpc-error><error-type>application</error-type><error-message xml:lang=\"en\">edit-conf failed. Target name or address not found in request.</error-message></rpc-error></rpc-reply>"
79 result = "<rpc-reply message-id=\\\"<MID>\\\" xmlns=\\\"urn:ietf:params:xml:ns:netconf:base:1.0\\\"> <rpc-error><error-type>application</error-type><error-message xml:lang=\"en\">edit-conf failed</error-message></rpc-error></rpc-reply>"