ONOS-5937
- created enum for target config and replaced all appropiate usages
- added old methods and had them pointing to new implementation
- added deprecated annotation to old methods
Change-Id: I2562588d32c7ab944eb44a13e9b25a342196edf2
diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java
index 172d53c..e2d435d 100644
--- a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java
+++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java
@@ -17,6 +17,7 @@
package org.onosproject.netconf;
import com.google.common.annotations.Beta;
+
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -88,26 +89,57 @@
/**
* Retrives the specified configuration.
*
- * @param targetConfiguration the type of configuration to retrieve.
+ * @param netconfTargetConfig the type of configuration to retrieve.
* @return specified configuration.
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- String getConfig(String targetConfiguration) throws NetconfException;
+ String getConfig(TargetConfig netconfTargetConfig) throws NetconfException;
+
+ /**
+ * Retrives the specified configuration.
+ *
+ * @param netconfTargetConfig the type of configuration to retrieve.
+ * @return specified configuration.
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ String getConfig(String netconfTargetConfig) throws NetconfException;
+
/**
* Retrives part of the specivied configuration based on the filterSchema.
*
- * @param targetConfiguration the type of configuration to retrieve.
+ * @param netconfTargetConfig the type of configuration to retrieve.
+ * @param configurationFilterSchema XML schema to filter the configuration
+ * elements we are interested in
+ * @return device running configuration.
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ String getConfig(String netconfTargetConfig, String configurationFilterSchema)
+ throws NetconfException;
+
+ /**
+ * Retrives part of the specivied configuration based on the filterSchema.
+ *
+ * @param netconfTargetConfig the type of configuration to retrieve.
* @param configurationFilterSchema XML schema to filter the configuration
* elements we are interested in
* @return device running configuration.
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- String getConfig(String targetConfiguration, String configurationFilterSchema)
+ String getConfig(TargetConfig netconfTargetConfig, String configurationFilterSchema)
throws NetconfException;
+
/**
* Retrives part of the specified configuration based on the filterSchema.
*
@@ -122,14 +154,30 @@
/**
* Retrives part of the specified configuration based on the filterSchema.
*
- * @param targetConfiguration the targetConfiguration to change
+ * @param netconfTargetConfig the targetConfiguration to change
+ * @param mode selected mode to change the configuration
+ * @param newConfiguration configuration to set
+ * @return true if the configuration was edited correctly
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ boolean editConfig(String netconfTargetConfig, String mode, String newConfiguration)
+ throws NetconfException;
+
+ /**
+ * Retrives part of the specified configuration based on the filterSchema.
+ *
+ * @param netconfTargetConfig the targetConfiguration to change
* @param mode selected mode to change the configuration
* @param newConfiguration configuration to set
* @return true if the configuration was edited correctly
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
+ boolean editConfig(TargetConfig netconfTargetConfig, String mode, String newConfiguration)
throws NetconfException;
/**
@@ -137,24 +185,54 @@
* to the target configuration.
* The target configuration can't be the running one
*
- * @param targetConfiguration the type of configuration to retrieve.
+ * @param netconfTargetConfig the type of configuration to retrieve.
+ * @param newConfiguration configuration to set
+ * @return true if the configuration was copied correctly
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ boolean copyConfig(String netconfTargetConfig, String newConfiguration)
+ throws NetconfException;
+
+ /**
+ * Copies the new configuration, an Url or a complete configuration xml tree
+ * to the target configuration.
+ * The target configuration can't be the running one
+ *
+ * @param netconfTargetConfig the type of configuration to retrieve.
* @param newConfiguration configuration to set
* @return true if the configuration was copied correctly
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- boolean copyConfig(String targetConfiguration, String newConfiguration)
+ boolean copyConfig(TargetConfig netconfTargetConfig, String newConfiguration)
throws NetconfException;
/**
* Deletes part of the specified configuration based on the filterSchema.
*
- * @param targetConfiguration the name of the configuration to delete
+ * @param netconfTargetConfig the name of the configuration to delete
+ * @return true if the configuration was copied correctly
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ boolean deleteConfig(String netconfTargetConfig) throws NetconfException;
+
+ /**
+ * Deletes part of the specified configuration based on the filterSchema.
+ *
+ * @param netconfTargetConfig the name of the configuration to delete
* @return true if the configuration was copied correctly
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- boolean deleteConfig(String targetConfiguration) throws NetconfException;
+ boolean deleteConfig(TargetConfig netconfTargetConfig) throws NetconfException;
/**
* Starts subscription to the device's notifications.
diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java
new file mode 100644
index 0000000..ecc924c
--- /dev/null
+++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.netconf;
+
+public enum TargetConfig {
+ RUNNING("running"),
+ CANDIDATE("candidate"),
+ STARTUP("startup");
+
+ private String name;
+
+ TargetConfig(String name) {
+ this.name = name;
+ }
+
+ TargetConfig toTargetConfig(String targetConfig) {
+ switch (targetConfig) {
+ case "running":
+ return RUNNING;
+ case "candidate":
+ return CANDIDATE;
+ case "startup":
+ return STARTUP;
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return this.name;
+ }
+}
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
index 73c6f93..72ae513 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
@@ -20,6 +20,7 @@
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import com.google.common.base.Preconditions;
+import org.onosproject.netconf.TargetConfig;
import org.onosproject.netconf.NetconfDeviceInfo;
import org.onosproject.netconf.NetconfDeviceOutputEvent;
import org.onosproject.netconf.NetconfDeviceOutputEventListener;
@@ -385,12 +386,22 @@
}
@Override
- public String getConfig(String targetConfiguration) throws NetconfException {
- return getConfig(targetConfiguration, null);
+ public String getConfig(TargetConfig netconfTargetConfig) throws NetconfException {
+ return getConfig(netconfTargetConfig, null);
}
@Override
- public String getConfig(String targetConfiguration, String configurationSchema) throws NetconfException {
+ public String getConfig(String netconfTargetConfig) throws NetconfException {
+ return getConfig(TargetConfig.valueOf(netconfTargetConfig));
+ }
+
+ @Override
+ public String getConfig(String netconfTargetConfig, String configurationFilterSchema) throws NetconfException {
+ return getConfig(TargetConfig.valueOf(netconfTargetConfig), configurationFilterSchema);
+ }
+
+ @Override
+ public String getConfig(TargetConfig netconfTargetConfig, String configurationSchema) throws NetconfException {
StringBuilder rpc = new StringBuilder(XML_HEADER);
rpc.append("<rpc ");
rpc.append(MESSAGE_ID_STRING);
@@ -401,7 +412,7 @@
rpc.append("xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
rpc.append("<get-config>\n");
rpc.append("<source>\n");
- rpc.append("<").append(targetConfiguration).append("/>");
+ rpc.append("<").append(netconfTargetConfig).append("/>");
rpc.append("</source>");
if (configurationSchema != null) {
rpc.append("<filter type=\"subtree\">\n");
@@ -422,7 +433,13 @@
}
@Override
- public boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
+ public boolean editConfig(String netconfTargetConfig, String mode, String newConfiguration)
+ throws NetconfException {
+ return editConfig(TargetConfig.valueOf(netconfTargetConfig), mode, newConfiguration);
+ }
+
+ @Override
+ public boolean editConfig(TargetConfig netconfTargetConfig, String mode, String newConfiguration)
throws NetconfException {
newConfiguration = newConfiguration.trim();
StringBuilder rpc = new StringBuilder(XML_HEADER);
@@ -435,7 +452,7 @@
rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
rpc.append(EDIT_CONFIG_OPEN).append("\n");
rpc.append(TARGET_OPEN);
- rpc.append("<").append(targetConfiguration).append("/>");
+ rpc.append("<").append(netconfTargetConfig).append("/>");
rpc.append(TARGET_CLOSE).append("\n");
if (mode != null) {
rpc.append(DEFAULT_OPERATION_OPEN);
@@ -454,7 +471,12 @@
}
@Override
- public boolean copyConfig(String targetConfiguration, String newConfiguration)
+ public boolean copyConfig(String netconfTargetConfig, String newConfiguration) throws NetconfException {
+ return copyConfig(TargetConfig.valueOf(netconfTargetConfig), newConfiguration);
+ }
+
+ @Override
+ public boolean copyConfig(TargetConfig netconfTargetConfig, String newConfiguration)
throws NetconfException {
newConfiguration = newConfiguration.trim();
if (!newConfiguration.startsWith("<config>")) {
@@ -466,7 +488,7 @@
rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
rpc.append("<copy-config>");
rpc.append("<target>");
- rpc.append("<").append(targetConfiguration).append("/>");
+ rpc.append("<").append(netconfTargetConfig).append("/>");
rpc.append("</target>");
rpc.append("<source>");
rpc.append(newConfiguration);
@@ -478,17 +500,22 @@
}
@Override
- public boolean deleteConfig(String targetConfiguration) throws NetconfException {
- if (targetConfiguration.equals("running")) {
+ public boolean deleteConfig(String netconfTargetConfig) throws NetconfException {
+ return deleteConfig(TargetConfig.valueOf(netconfTargetConfig));
+ }
+
+ @Override
+ public boolean deleteConfig(TargetConfig netconfTargetConfig) throws NetconfException {
+ if (netconfTargetConfig.equals("running")) {
log.warn("Target configuration for delete operation can't be \"running\"",
- targetConfiguration);
+ netconfTargetConfig);
return false;
}
StringBuilder rpc = new StringBuilder(XML_HEADER);
rpc.append("<rpc>");
rpc.append("<delete-config>");
rpc.append("<target>");
- rpc.append("<").append(targetConfiguration).append("/>");
+ rpc.append("<").append(netconfTargetConfig).append("/>");
rpc.append("</target>");
rpc.append("</delete-config>");
rpc.append("</rpc>");
diff --git a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/NetconfSessionImplTest.java b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/NetconfSessionImplTest.java
index 661c290..fe2a0d5 100644
--- a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/NetconfSessionImplTest.java
+++ b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/NetconfSessionImplTest.java
@@ -18,6 +18,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.onosproject.netconf.TargetConfig.*;
import java.util.ArrayList;
import java.util.Arrays;
@@ -42,6 +43,7 @@
import org.junit.Test;
import org.onlab.junit.TestTools;
import org.onlab.packet.Ip4Address;
+import org.onosproject.netconf.TargetConfig;
import org.onosproject.netconf.NetconfDeviceInfo;
import org.onosproject.netconf.NetconfException;
import org.onosproject.netconf.NetconfSession;
@@ -128,7 +130,7 @@
log.info("Starting edit-config async");
assertNotNull("Incorrect sessionId", session1.getSessionId());
try {
- assertTrue("NETCONF edit-config command failed", session1.editConfig("running", null, SAMPLE_REQUEST));
+ assertTrue("NETCONF edit-config command failed", session1.editConfig(RUNNING, null, SAMPLE_REQUEST));
} catch (NetconfException e) {
e.printStackTrace();
fail("NETCONF edit-config test failed: " + e.getMessage());
@@ -141,7 +143,7 @@
log.info("Starting copy-config async");
assertNotNull("Incorrect sessionId", session1.getSessionId());
try {
- assertTrue("NETCONF edit-config command failed", session1.copyConfig("running", "candidate"));
+ assertTrue("NETCONF edit-config command failed", session1.copyConfig(RUNNING, "candidate"));
} catch (NetconfException e) {
e.printStackTrace();
fail("NETCONF edit-config test failed: " + e.getMessage());
@@ -155,10 +157,10 @@
assertNotNull("Incorrect sessionId", session1.getSessionId());
try {
assertTrue("NETCONF get-config running command failed. ",
- GET_REPLY_PATTERN.matcher(session1.getConfig("running", SAMPLE_REQUEST)).matches());
+ GET_REPLY_PATTERN.matcher(session1.getConfig(RUNNING, SAMPLE_REQUEST)).matches());
assertTrue("NETCONF get-config candidate command failed. ",
- GET_REPLY_PATTERN.matcher(session1.getConfig("candidate", SAMPLE_REQUEST)).matches());
+ GET_REPLY_PATTERN.matcher(session1.getConfig(CANDIDATE, SAMPLE_REQUEST)).matches());
} catch (NetconfException e) {
e.printStackTrace();
@@ -184,8 +186,8 @@
@Test
public void testConcurrentSameSessionAccess() throws InterruptedException {
- NCCopyConfigCallable testCopyConfig1 = new NCCopyConfigCallable(session1, "running", "candidate");
- NCCopyConfigCallable testCopyConfig2 = new NCCopyConfigCallable(session1, "candidate", "startup");
+ NCCopyConfigCallable testCopyConfig1 = new NCCopyConfigCallable(session1, RUNNING, "candidate");
+ NCCopyConfigCallable testCopyConfig2 = new NCCopyConfigCallable(session1, RUNNING, "startup");
FutureTask<Boolean> futureCopyConfig1 = new FutureTask<Boolean>(testCopyConfig1);
FutureTask<Boolean> futureCopyConfig2 = new FutureTask<Boolean>(testCopyConfig2);
@@ -210,8 +212,8 @@
@Test
public void test2SessionAccess() throws InterruptedException {
- NCCopyConfigCallable testCopySession1 = new NCCopyConfigCallable(session1, "running", "candidate");
- NCCopyConfigCallable testCopySession2 = new NCCopyConfigCallable(session2, "running", "candidate");
+ NCCopyConfigCallable testCopySession1 = new NCCopyConfigCallable(session1, RUNNING, "candidate");
+ NCCopyConfigCallable testCopySession2 = new NCCopyConfigCallable(session2, RUNNING, "candidate");
FutureTask<Boolean> futureCopySession1 = new FutureTask<Boolean>(testCopySession1);
FutureTask<Boolean> futureCopySession2 = new FutureTask<Boolean>(testCopySession2);
@@ -338,10 +340,10 @@
public class NCCopyConfigCallable implements Callable<Boolean> {
private NetconfSession session;
- private String target;
+ private TargetConfig target;
private String source;
- public NCCopyConfigCallable(NetconfSession session, String target, String source) {
+ public NCCopyConfigCallable(NetconfSession session, TargetConfig target, String source) {
this.session = session;
this.target = target;
this.source = source;