From 1c192d2dd68724e292b6a30f463085a262e1e813 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 15 Feb 2017 23:11:26 -0800 Subject: Moving all files to root directory Change-Id: Ica5535fd6ec85f350fe1640b42137b49f83f10f0 Signed-off-by: Patrick Brady --- .../org.eclipse.wst.common.project.facet.core.xml | 4 + .../org.eclipse.wst.common.project.facet.core.xml | 4 + .../appc-netconf-adapter-bundle/pom.xml | 189 +++++++++++++++++ .../netconf/AppcNetconfAdapterActivator.java | 130 ++++++++++++ .../appc/adapter/netconf/ConnectionDetails.java | 64 ++++++ .../netconf/MockOperationalStateValidatorImpl.java | 45 ++++ .../appc/adapter/netconf/NetconfClient.java | 61 ++++++ .../appc/adapter/netconf/NetconfClientFactory.java | 40 ++++ .../adapter/netconf/NetconfClientRestconf.java | 70 +++++++ .../appc/adapter/netconf/NetconfClientType.java | 28 +++ .../adapter/netconf/NetconfConnectionDetails.java | 92 ++++++++ .../adapter/netconf/NetconfDataAccessService.java | 82 ++++++++ .../adapter/netconf/OperationalStateValidator.java | 32 +++ .../netconf/OperationalStateValidatorFactory.java | 52 +++++ .../netconf/VNFOperationalStateValidatorImpl.java | 132 ++++++++++++ .../openecomp/appc/adapter/netconf/VnfType.java | 55 +++++ .../netconf/exception/DataAccessException.java | 44 ++++ .../netconf/exception/NetconfDAOException.java | 44 ++++ .../adapter/netconf/internal/NetconfAdapter.java | 129 ++++++++++++ .../adapter/netconf/internal/NetconfAdapter2.java | 103 +++++++++ .../netconf/internal/NetconfConstMessages.java | 53 +++++ .../internal/NetconfDataAccessServiceImpl.java | 154 ++++++++++++++ .../adapter/netconf/internal/NetconfMessage.java | 94 +++++++++ .../appc/adapter/netconf/jsch/JSchLogger.java | 60 ++++++ .../adapter/netconf/jsch/NetconfClientJsch.java | 171 +++++++++++++++ .../odlconnector/NetconfClientRestconfImpl.java | 233 +++++++++++++++++++++ .../appc/adapter/netconf/util/Constants.java | 64 ++++++ .../org/openecomp/appc/default.properties | 41 ++++ .../test/java/OperationalStateValidatorTest.java | 197 +++++++++++++++++ .../netconf/internal/TestNetconfAdapter.java | 88 ++++++++ .../adapter/netconf/jsch/TestGetRunningConfig.java | 60 ++++++ .../adapter/netconf/jsch/TestModifyConfig.java | 93 ++++++++ .../adapter/netconf/jsch/TestModifyConfigMock.java | 93 ++++++++ .../netconf/jsch/TestModifyConfigRouterMock.java | 91 ++++++++ .../netconf/jsch/TestOperationalStates.java | 87 ++++++++ .../appc-netconf-adapter-features/pom.xml | 122 +++++++++++ .../src/main/resources/features.xml | 37 ++++ .../appc-netconf-installer/pom.xml | 130 ++++++++++++ .../src/assembly/assemble_installer_zip.xml | 59 ++++++ .../src/assembly/assemble_mvnrepo_zip.xml | 47 +++++ .../src/main/resources/scripts/install-feature.sh | 40 ++++ appc-adapters/appc-netconf-adapter/pom.xml | 127 +++++++++++ 42 files changed, 3541 insertions(+) create mode 100644 appc-adapters/appc-netconf-adapter/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/pom.xml create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/AppcNetconfAdapterActivator.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/ConnectionDetails.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/MockOperationalStateValidatorImpl.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClient.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientFactory.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientRestconf.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientType.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfConnectionDetails.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfDataAccessService.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/OperationalStateValidator.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/OperationalStateValidatorFactory.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/VNFOperationalStateValidatorImpl.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/VnfType.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/exception/DataAccessException.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/exception/NetconfDAOException.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfAdapter.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfAdapter2.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfConstMessages.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfMessage.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/jsch/JSchLogger.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/jsch/NetconfClientJsch.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/util/Constants.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/internal/TestNetconfAdapter.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestGetRunningConfig.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfig.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigMock.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestOperationalStates.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-features/pom.xml create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-features/src/main/resources/features.xml create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-installer/pom.xml create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/assembly/assemble_installer_zip.xml create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/assembly/assemble_mvnrepo_zip.xml create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/main/resources/scripts/install-feature.sh create mode 100644 appc-adapters/appc-netconf-adapter/pom.xml (limited to 'appc-adapters/appc-netconf-adapter') diff --git a/appc-adapters/appc-netconf-adapter/.settings/org.eclipse.wst.common.project.facet.core.xml b/appc-adapters/appc-netconf-adapter/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 000000000..f4ef8aa0a --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/.settings/org.eclipse.wst.common.project.facet.core.xml b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 000000000..f4ef8aa0a --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/pom.xml b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/pom.xml new file mode 100644 index 000000000..861529836 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/pom.xml @@ -0,0 +1,189 @@ + + + 4.0.0 + + org.openecomp.appc + appc-netconf-adapter + 1.0.0 + + + appc-netconf-adapter-bundle + bundle + NETCONF Adapter - bundle + + 4.9.1 + 1.6.0 + 1.3.1-Beryllium-SR1 + + + + + org.openecomp.appc + appc-common + ${project.version} + + + org.openecomp.appc + appc-dmaap-adapter-bundle + ${project.version} + + + + javax + javaee-api + 7.0 + + + + com.att.cdp + cdp-pal-common + compile + + + + com.att.cdp + cdp-pal-openstack + compile + + + + javax.ws.rs + javax.ws.rs-api + + + + + com.sun.jersey + jersey-client + + + + com.sun.jersey + jersey-json + + + + javax.xml.bind + jaxb-api + 2.1 + + + + + org.glassfish.jersey.core + jersey-common + 2.9.1 + + + + org.codehaus.jackson + jackson-jaxrs + 1.9.12 + + + + commons-codec + commons-codec + + + + org.apache.httpcomponents + httpclient + 4.5.1 + + + + junit + junit + test + + + org.openecomp.sdnc.core + sli-common + compile + + + + org.openecomp.sdnc.core + sli-provider + compile + + + + equinoxSDK381 + org.eclipse.osgi + + + + org.slf4j + slf4j-api + + + + org.slf4j + jcl-over-slf4j + + + + org.openecomp.sdnc.core + dblib-provider + + + + com.vmware + vijava + 5.1 + compile + + + + xerces + xerces + 2.4.0 + provided + + + + org.apache.httpcomponents + httpcore + ${apache.httpcomponents.version} + + + + commons-logging + commons-logging + 1.2 + + + + org.json + json + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + appc-netconf-adapter + org.openecomp.appc.adapter.netconf.AppcNetconfAdapterActivator + org.openecomp.appc.adapter.netconf,org.openecomp.appc.adapter.netconf.dao,org.openecomp.appc.adapter.netconf.util,org.openecomp.appc.adapter.netconf.exception + + org.w3c.dom.*,com.sun.org.apache.xerces.*,javax.sql.*,javax.sql.rowset.*,javax.xml.*,org.openecomp.appc.adapter.dmaap.*,javax.crypto.*,org.openecomp.appc.common.exception.*,com.mysql.*,org.openecomp.sdnc.sli.*,org.osgi.framework.*,org.slf4j.*,com.vmware.*,org.apache.xerces.*,javax.net.*,javax.net.ssl.*,org.xml.sax.*,javax.xml.bind.*,javax.naming.* + + *;scope=compile|runtime;artifactId=!sli-common|dblib-provider|org.eclipse.osgi|slf4j-api|jcl-over-slf4j|mysql-connector-java|xml-apis|appc-dmaap-adapter-bundle + true + + + ${project.basedir}/src/main/resources/META-INF + + + + + + diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/AppcNetconfAdapterActivator.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/AppcNetconfAdapterActivator.java new file mode 100644 index 000000000..aac49c288 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/AppcNetconfAdapterActivator.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import org.openecomp.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl; +import org.openecomp.sdnc.sli.resource.dblib.DbLibService; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; + +public class AppcNetconfAdapterActivator implements BundleActivator { + + /** + * The bundle registration + */ + private ServiceRegistration registration = null; + private ServiceRegistration reporterRegistration = null; + private ServiceRegistration factoryRegistration = null; + private ServiceRegistration dbRegistration = null; + + /** + * The reference to the actual implementation object that implements the services + */ + private NetconfClientFactory clientFactory; + private NetconfDataAccessService DAService; + + /** + * The logger to be used + */ + //private static final EELFLogger logger = EELFManager.getInstance().getLogger(AppcNetconfAdapterActivator.class); + + /** + * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start + * this bundle. This method can be used to register services or to allocate any resources that this bundle needs. + *

+ * This method must complete and return to its caller in a timely manner. + *

+ * + * @param context + * The execution context of the bundle being started. + * @throws java.lang.Exception + * If this method throws an exception, this bundle is marked as stopped and the Framework will remove + * this bundle's listeners, unregister all services registered by this bundle, and release all services + * used by this bundle. + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + + if (registration == null) { + clientFactory = new NetconfClientFactory(); + factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null); + + DAService = new NetconfDataAccessServiceImpl(); + //set dblib service + DbLibService dblibSvc = null; + ServiceReference sref = context.getServiceReference(DbLibService.class.getName()); + dblibSvc = (DbLibService)context.getService(sref); + DAService.setDbLibService(dblibSvc); + /////////////////////////////////// + factoryRegistration = context.registerService(NetconfDataAccessService.class, DAService, null); + } + + //logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter"); + } + + /** + * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop + * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There + * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not + * call any Framework objects. + *

+ * This method must complete and return to its caller in a timely manner. + *

+ * + * @param context + * The execution context of the bundle being stopped. + * @throws java.lang.Exception + * If this method throws an exception, the bundle is still marked as stopped, and the Framework will + * remove the bundle's listeners, unregister all services registered by the bundle, and release all + * services used by the bundle. * + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + if (registration != null) { + registration.unregister(); + registration = null; + } + if (reporterRegistration != null) { + reporterRegistration.unregister(); + reporterRegistration = null; + } + + if (null != factoryRegistration) { + factoryRegistration.unregister(); + factoryRegistration = null; + } + + if (dbRegistration != null) { + dbRegistration.unregister(); + dbRegistration = null; + } + } + + public String getName() { + return "APPC NETCONF adapter"; + } + +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/ConnectionDetails.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/ConnectionDetails.java new file mode 100644 index 000000000..71fe16f6b --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/ConnectionDetails.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + + +public class ConnectionDetails { + + private String host; + private int port; + private String username; + private String password; + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/MockOperationalStateValidatorImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/MockOperationalStateValidatorImpl.java new file mode 100644 index 000000000..95eae28af --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/MockOperationalStateValidatorImpl.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import org.openecomp.appc.exceptions.APPCException; + + +public class MockOperationalStateValidatorImpl implements OperationalStateValidator { + @Override + public VnfType getVnfType() { + return VnfType.MOCK; + } + + @Override + public String getConfigurationFileName() { + String configFileName = OperationalStateValidatorFactory.configuration.getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX); + return configFileName; + } + + @Override + public void validateResponse(String response) throws APPCException { + if(response != null && response.toUpperCase().contains("INVALID")){ + throw new APPCException("INVALID"); + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClient.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClient.java new file mode 100644 index 000000000..904155273 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClient.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import org.openecomp.appc.exceptions.APPCException; + + + +public interface NetconfClient { + + /** + * Open connection to netconf device. + * + * @param connectionDetails object providing details required for netconf connection + */ + void connect(NetconfConnectionDetails connectionDetails) throws APPCException; + + /** + * Send Netconf message to device and receive response. + * + * @param message input netconf xml message + * @return output netconf xml message + */ + String exchangeMessage(String message) throws APPCException; + + /** + * send configuration to Netconf server + * + * @param configuration - xml configuration payload + */ + void configure(String configuration) throws APPCException; + + /** + * returns running configuration of Netconf server + */ + String getConfiguration() throws APPCException; + + /** + * Disconnect from netconf device. + */ + void disconnect() throws APPCException; +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientFactory.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientFactory.java new file mode 100644 index 000000000..20fec5c49 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientFactory.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.adapter.netconf.odlconnector.NetconfClientRestconfImpl; + + +public class NetconfClientFactory { + + public NetconfClient GetNetconfClient(NetconfClientType type){ + + if(type==NetconfClientType.RESTCONF) { + return new NetconfClientRestconfImpl(); + }else if(type == NetconfClientType.SSH){ + return new NetconfClientJsch(); + } + + return null; + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientRestconf.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientRestconf.java new file mode 100644 index 000000000..04368615a --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientRestconf.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import org.openecomp.appc.exceptions.APPCException; + + + +public interface NetconfClientRestconf { + + /* + mount device to controller + @param deviceMountPointName - the name of the mounting point in controller + @param payload - json data describing device info + */ + void connect(String deviceMountPointName, String payload) throws APPCException; + + /* + check connection to device + @param deviceMountPointName - the name of the mounting point in controller + */ + boolean checkConnection(String deviceMountPointName) throws APPCException; + + /* + send configuration to Netconf server + @param configuration - xml configuration payload + @param deviceMountPointName - the name of the mounting point in controller + @param moduleName - name of the yang model + @param nodeName - name of the node created in server + */ + void configure(String configuration, String deviceMountPointName, String moduleName, String nodeName) throws APPCException; + + /* + backup device configuration + @param deviceMountPointName - the name of the mounting point in controlle + */ + //void backupConfiguration(String deviceMountPointName); + /* + returns configuration of Netconf server + @param deviceMountPointName - the name of the mounting point in controller + @param moduleName - name of the yang model + @param nodeName - name of the node created in server + */ + String getConfiguration(String deviceName, String moduleName, String nodeName) throws APPCException; + + /* + unmount device + @param deviceMountPointName - the name of the mounting point in controller + */ + void disconnect(String deviceMountPointName) throws APPCException; +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientType.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientType.java new file mode 100644 index 000000000..9757ae9ec --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfClientType.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + + +public enum NetconfClientType { + RESTCONF, + SSH +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfConnectionDetails.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfConnectionDetails.java new file mode 100644 index 000000000..fdbda2916 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfConnectionDetails.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import java.util.List; +import java.util.Properties; + +/** + * Provides details required for connecting to netconf device. + */ +public class NetconfConnectionDetails { + + private String host; + private int port; + private String username; + private String password; + + public static int DEFAULT_PORT = 830; + private List capabilities; + private Properties additionalProperties; + + public NetconfConnectionDetails() { + super(); + setPort(DEFAULT_PORT); + } + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public List getCapabilities() { + return capabilities; + } + + public void setCapabilities(List capabilities) { + this.capabilities = capabilities; + } + + public Properties getAdditionalProperties() { + return additionalProperties; + } + + public void setAdditionalProperties(Properties additionalProperties) { + this.additionalProperties = additionalProperties; + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfDataAccessService.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfDataAccessService.java new file mode 100644 index 000000000..3536cf3b9 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/NetconfDataAccessService.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import org.openecomp.appc.adapter.netconf.exception.DataAccessException; +import org.openecomp.sdnc.sli.resource.dblib.DbLibService; + + +@SuppressWarnings("JavaDoc") +public interface NetconfDataAccessService { + + /** + * + * @param schema + */ + void setSchema(String schema); + + /** + * + * @param dbLibService + */ + void setDbLibService(DbLibService dbLibService); + + /** + * + * @param xmlID + * @return + * @throws DataAccessException + */ + String retrieveConfigFileName(String xmlID) throws DataAccessException; + + /** + * + * @param vnfType + * @param connectionDetails + * @return + * @throws DataAccessException + */ + boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) throws DataAccessException; + + /** + * + * @param vnfType + * @param connectionDetails + * @return + * @throws DataAccessException + */ + boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) throws + DataAccessException; + + /** + * + * @param instanceId + * @param requestId + * @param creationDate + * @param logText + * @return + * @throws DataAccessException + */ + boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) throws + DataAccessException; + +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/OperationalStateValidator.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/OperationalStateValidator.java new file mode 100644 index 000000000..fb9aba002 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/OperationalStateValidator.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import org.openecomp.appc.exceptions.APPCException; + + +public interface OperationalStateValidator { + public VnfType getVnfType(); + public String getConfigurationFileName(); + public void validateResponse(String response) throws APPCException; + final public static String CONFIG_FILE_PROPERTY_SUFFIX = "-CONFIG_FILE"; +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/OperationalStateValidatorFactory.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/OperationalStateValidatorFactory.java new file mode 100644 index 000000000..94b87f497 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/OperationalStateValidatorFactory.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import org.apache.commons.lang3.NotImplementedException; +import org.openecomp.appc.configuration.Configuration; +import org.openecomp.appc.configuration.ConfigurationFactory; + +public class OperationalStateValidatorFactory { + protected static final Configuration configuration = ConfigurationFactory.getConfiguration(); + + public static OperationalStateValidator getOperationalStateValidator(String vnfType) { + VnfType vnfTypeEnum = null; + try { + vnfTypeEnum = VnfType.getVnfType(vnfType); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("Illegal value in vnfType. vnfType="+vnfType,e); + } + return getOperationalStateValidator(vnfTypeEnum); + } + + public static OperationalStateValidator getOperationalStateValidator(VnfType vnfType) { + switch (vnfType) { + case VNF: + case VNF_MOCK: + return new VNFOperationalStateValidatorImpl(); + case MOCK: + return new MockOperationalStateValidatorImpl(); + default: + throw new NotImplementedException("missing implementaion for the given vnfType:" + vnfType.name()); + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/VNFOperationalStateValidatorImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/VNFOperationalStateValidatorImpl.java new file mode 100644 index 000000000..fa84ea1a1 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/VNFOperationalStateValidatorImpl.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +import org.apache.commons.lang3.StringUtils; +import org.openecomp.appc.configuration.Configuration; +import org.openecomp.appc.configuration.ConfigurationFactory; +import org.openecomp.appc.exceptions.APPCException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.StringReader; +import java.util.*; + +public class VNFOperationalStateValidatorImpl implements OperationalStateValidator { + private static final String OPERATIONAL_STATE_ELEMENT_NAME = "operationalState"; + @Override + public VnfType getVnfType() { + return VnfType.VNF; + } + + @Override + public String getConfigurationFileName() { + String configFileName = OperationalStateValidatorFactory.configuration.getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX); + configFileName = configFileName == null? "VnfGetOperationalStates" : configFileName; + return configFileName; + } + + @Override + public void validateResponse(String response) throws APPCException { + if(StringUtils.isEmpty(response)) { + throw new APPCException("empty response"); + } + + boolean isValid = false; + String errorMsg = "unexpected response"; + try { + List operationalStateList = getOperationalStateList(response); + if(operationalStateList != null && !operationalStateList.isEmpty()) { + for (Map.Entry stateEntry : operationalStateList) { + if(!((String)stateEntry.getValue()).equalsIgnoreCase("ENABLED")){ + errorMsg = "at least one "+OPERATIONAL_STATE_ELEMENT_NAME+" is not in valid satae. "+operationalStateList.toString(); + isValid = false; + break; + }else{ + isValid =true; + } + } + }else { + errorMsg = "response without any "+OPERATIONAL_STATE_ELEMENT_NAME+" element"; + } + } catch (Exception e ) { + isValid = false; + errorMsg = e.toString(); + } + if(!isValid) throw new APPCException(errorMsg); + } + + private static List getOperationalStateList(String xmlText) throws IOException, ParserConfigurationException, SAXException { + List entryList = null; + if(StringUtils.isNotEmpty(xmlText)) { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + + Document document = builder.parse(new ByteArrayInputStream(xmlText.getBytes("UTF-8"))); + if(document != null) { + Element rootElement = document.getDocumentElement(); + NodeList nodeList = rootElement.getElementsByTagName(OPERATIONAL_STATE_ELEMENT_NAME); + if (nodeList != null && nodeList.getLength() > 0) { + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + String text = node.getTextContent(); + String id = getElementID(node); + entryList = (entryList == null) ? new ArrayList() : entryList; + Map.Entry entry = new AbstractMap.SimpleEntry(id, text); + entryList.add(entry); + } + } + } + } + return entryList; + } + + private static String getElementID(Node node) { + String id = null; + Node parentNode = node.getParentNode(); + if (parentNode != null) { + if (node.getNodeType() == Node.ELEMENT_NODE) { + NodeList nodeList = ((Element) parentNode).getElementsByTagName("id"); + if (nodeList != null && nodeList.getLength() > 0) { + Node idNode = nodeList.item(0); + id = idNode != null ? idNode.getTextContent() : null; + } + }else { + id = parentNode.getNodeValue()+"|"+parentNode.getTextContent(); + } + } + + id = StringUtils.isEmpty(id) ? null : StringUtils.normalizeSpace(id); + id = StringUtils.isBlank(id) ? null : id; + id = id != null ? id : "unknown-id"; + return id; + } + +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/VnfType.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/VnfType.java new file mode 100644 index 000000000..18f334fa1 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/VnfType.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf; + +public enum VnfType { + VNF("VNF"), + MOCK("MOCK"), + VNF_MOCK("MOCK"), + ; + + String familyType; + String upperCaseName; + VnfType(String familyType) { + this.familyType = familyType; + this.upperCaseName = name().toUpperCase(); + } + + public VnfType getFamilyType() { + return VnfType.valueOf(familyType); + } + + public String getUpperCaseName() { + return upperCaseName; + } + + public static VnfType getVnfType(String inSensitiveCaseName){ + String localUpperCaseName = inSensitiveCaseName.toUpperCase(); + for(VnfType vnfType : VnfType.values()){ + if(vnfType.getUpperCaseName().equals(localUpperCaseName)){ + return vnfType; + } + } + throw new IllegalArgumentException( + "No enum with upperCaseName for this input value:" + inSensitiveCaseName ); + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/exception/DataAccessException.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/exception/DataAccessException.java new file mode 100644 index 000000000..1f3b9d830 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/exception/DataAccessException.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.exception; + + +public class DataAccessException extends RuntimeException { + + private static final long serialVersionUID = -155423437162622414L; + + public DataAccessException(){ + } + + public DataAccessException(String message){ + super(message); + } + + public DataAccessException(Throwable cause){ + super(cause); + } + + public DataAccessException(String message , Throwable cause){ + super(message , cause); + } + +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/exception/NetconfDAOException.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/exception/NetconfDAOException.java new file mode 100644 index 000000000..c8c692c2a --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/exception/NetconfDAOException.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.exception; + +public class NetconfDAOException extends RuntimeException { + + private static final long serialVersionUID = -155423437162622414L; + + public NetconfDAOException(){ + } + + public NetconfDAOException(String message){ + super(message); + } + + public NetconfDAOException(Throwable cause){ + super(cause); + } + + public NetconfDAOException(String message , Throwable cause){ + super(message , cause); + } + + +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfAdapter.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfAdapter.java new file mode 100644 index 000000000..7740728f4 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfAdapter.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.internal; + +import org.openecomp.appc.configuration.ConfigurationFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.concurrent.*; + +/** + * Provides basic methods for exchanging netconf messages. + */ +public class NetconfAdapter { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfAdapter.class); + private static final long MAX_WAITING_TIME = 1800000; + private static ExecutorService executor = Executors.newFixedThreadPool(5); + + // device input stream + private InputStream in; + // device output stream + private OutputStream out; + private long maxWaitingTime = ConfigurationFactory.getConfiguration().getLongProperty("org.openecomp.appc.netconf.recv.timeout", MAX_WAITING_TIME); + + /** + * Constructor. + * + * @param in InputStream this instance will read netconf messages from + * @param out OutputStream this instance will write netconf messages to + * @throws IOException + */ + public NetconfAdapter(InputStream in, OutputStream out) throws IOException { + this.in = in; + this.out = out; + } + + /** + * Receives netconf message from InputStream and return it's text (without netconf frame characters). + * + * @return text of message received from netconf device + * @throws IOException + */ + public String receiveMessage() throws IOException { + + final NetconfMessage message = new NetconfMessage(); + final byte[] buf = new byte[1024]; + + //int readByte = 1; + // Read data with timeout + Callable readTask = new Callable() { + @Override + public Boolean call() throws Exception { + int c; + while ((c = in.read(buf)) > 0) { + if (c > 0) { + message.append(buf, 0, c); + if (message.isCompleted()) { + break; + } + } + } + + if (c < 0) { + return false; + } + return true; + } + }; + + Future future = executor.submit(readTask); + Boolean status; + try { + status = future.get(maxWaitingTime, TimeUnit.MILLISECONDS); + } catch (Exception e) { + throw new IOException(e); + } + + if (status == false) { + throw new IOException("Failed to read netconf message"); + } + + + String text = message.getText(); + if (text != null) { + text = text.trim(); + } + if (LOG.isDebugEnabled()) { + LOG.debug("Received message from netconf device:\n" + text); + } + return text; + } + + /** + * Sends netconf message with provided text (adds netconf frame characters and sends the message). + * + * @param text text of message to be sent to netconf device + * @throws IOException + */ + public void sendMessage(final String text) throws IOException { + if (LOG.isDebugEnabled()) { + LOG.debug("Sending message to netconf device:\n" + text); + } + out.write(new NetconfMessage(text).getFrame()); + out.flush(); + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfAdapter2.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfAdapter2.java new file mode 100644 index 000000000..e0f166483 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfAdapter2.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.internal; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; + +/** + * Provides basic methods for exchanging netconf messages. + */ +public class NetconfAdapter2 { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfAdapter2.class); + + // device input pipe + private final PipedOutputStream pipedOutIn = new PipedOutputStream(); + private PipedInputStream in; + // device output pipe + private final PipedInputStream pipedInOut = new PipedInputStream(); + private PipedOutputStream out; + + /** + * Constructor. + * + * @throws IOException + */ + public NetconfAdapter2() throws IOException { + in = new PipedInputStream(pipedOutIn); + out = new PipedOutputStream(pipedInOut); + } + + /** + * @return InputStream this instance will read netconf messages from. + */ + public InputStream getIn() { + return in; + } + + /** + * @return OutputStream this instance will write netconf messages to. + */ + public OutputStream getOut() { + return out; + } + + /** + * Receives netconf message from InputStream and return it's text (without netconf frame characters). + * + * @return text of message received from netconf device + * @throws IOException + */ + public String receiveMessage() throws IOException { + NetconfMessage message = new NetconfMessage(); + byte[] buf = new byte[1024]; + int c; + while((c = pipedInOut.read(buf)) > 0) { + message.append(buf, 0, c); + if (message.isCompleted()) { + break; + } + } + String text = message.getText(); + if(LOG.isDebugEnabled()) { + LOG.debug("Received message from netconf device:\n" + text); + } + return text; + } + + /** + * Sends netconf message with provided text (adds netconf frame characters and sends the message). + * + * @param text text of message to be sent to netconf device + * @throws IOException + */ + public void sendMessage(final String text) throws IOException { + if(LOG.isDebugEnabled()) { + LOG.debug("Sending message to netconf device:\n" + text); + } + pipedOutIn.write(new NetconfMessage(text).getFrame()); +// pipedOutIn.flush(); + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfConstMessages.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfConstMessages.java new file mode 100644 index 000000000..d68900802 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfConstMessages.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.internal; + +public class NetconfConstMessages { + + public static final String CAPABILITIES_START = + "\n" + + "\n" + + " \n"; + + public static final String CAPABILITIES_BASE = + " urn:ietf:params:netconf:base:1.0\n"; + + public static final String CAPABILITIES_END = + " \n" + + ""; + + public static final String GET_RUNNING_CONFIG = + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + public static final String CLOSE_SESSION = + "\n" + + "\n" + + " \n" + + ""; +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java new file mode 100644 index 000000000..53eb5b520 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java @@ -0,0 +1,154 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.internal; + +import javax.sql.rowset.CachedRowSet; + +import org.openecomp.appc.adapter.netconf.ConnectionDetails; +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.NetconfDataAccessService; +import org.openecomp.appc.adapter.netconf.exception.DataAccessException; +import org.openecomp.appc.adapter.netconf.util.Constants; +import org.openecomp.appc.exceptions.APPCException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.openecomp.sdnc.sli.resource.dblib.DbLibService; + +import java.sql.SQLException; +import java.util.ArrayList; + + +public class NetconfDataAccessServiceImpl implements NetconfDataAccessService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class); + + public void setSchema(String schema) { + this.schema = schema; + } + + private String schema; + + public void setDbLibService(DbLibService service) {dbLibService = service;} + + private DbLibService dbLibService; + + @Override + public String retrieveConfigFileName(String xmlID) throws DataAccessException { + String fileContent = ""; + + String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " + + "from " + Constants.CONFIGFILES_TABLE_NAME + " " + + "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?"; + + ArrayList argList = new ArrayList<>(); + argList.add(xmlID); + + try { + + final CachedRowSet data = dbLibService.getData(queryString, argList, schema); + if (data.first()) { + fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME); + } + + } catch (Throwable e) { + logger.error("Error Accessing Database " + e); + throw new DataAccessException(e); + } + + return fileContent; + } + + @Override + public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) throws + DataAccessException { + boolean recordFound = false; + + String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " + + "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " + + "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?"; + + ArrayList argList = new ArrayList<>(); + argList.add(vnfType); + + try { + + final CachedRowSet data = dbLibService.getData(queryString, argList, schema); + if (data.first()) { + connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME)); + connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME)); + connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME)); + recordFound = true; + } + + } catch (SQLException e) { + logger.error("Error Accessing Database " + e); + throw new DataAccessException(e); + } + + return recordFound; + } + + @Override + public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) throws + DataAccessException + { + ConnectionDetails connDetails = new ConnectionDetails(); + if(this.retrieveConnectionDetails(vnfType, connDetails)) + { + connectionDetails.setHost(connDetails.getHost()); + connectionDetails.setPort(connDetails.getPort()); + connectionDetails.setUsername(connDetails.getUsername()); + connectionDetails.setPassword(connDetails.getPassword()); + } + return true; + } + + @Override + public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) throws + DataAccessException { + + String queryString = "INSERT INTO "+ Constants.DEVICE_INTERFACE_LOG_TABLE_NAME+"("+ + Constants.SERVICE_INSTANCE_ID_FIELD_NAME+","+ + Constants.REQUEST_ID_FIELD_NAME+","+ + Constants.CREATION_DATE_FIELD_NAME+","+ + Constants.LOG_FIELD_NAME+") "; + queryString += "values(?,?,?,?)"; + + ArrayList argList = new ArrayList<>(); + argList.add(instanceId); + argList.add(requestId); + argList.add(creationDate); + argList.add(logText); + + try { + + dbLibService.writeData(queryString, argList, schema); + + } catch (SQLException e) { + logger.error("Logging Device interaction failed - "+ queryString); + throw new DataAccessException(e); + } + + return true; + } + +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfMessage.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfMessage.java new file mode 100644 index 000000000..200145b0a --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/internal/NetconfMessage.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.internal; + +import java.io.ByteArrayOutputStream; + +class NetconfMessage { + + private static final String EOM = "]]>]]>"; + + private String text; + private MessageBuffer buffer = new MessageBuffer(); + private int eomNotch; + + NetconfMessage() { + } + + NetconfMessage(String text) { + if(text == null) { + throw new NullPointerException("Netconf message payload is null"); + } + append(text.getBytes(), 0, text.length()); + if(this.text == null) { + this.text = text; + } + } + + void append(byte[] bytes, int start, int end) { + boolean eomFound = false; + for(int i = start; i < end; i++) { + if(bytes[i] == EOM.charAt(eomNotch)) { + // advance notch + eomNotch++; + } else { + // reset notch + eomNotch = 0; + } + if(eomNotch == EOM.length()) { + // end of message found + eomFound = true; + end = i + 1; + break; + } + } + buffer.write(bytes, start, end); + if(eomFound) { + text = new String(buffer.getBytes(), 0, buffer.size() - EOM.length()); + buffer.reset(); + } + } + + String getText() { + return text; + } + + boolean isCompleted() { + return (text != null); + } + + byte[] getFrame() { + StringBuilder sb = new StringBuilder(); + if(text != null) { + sb.append(text).append("\n"); + } + sb.append(EOM); + return sb.toString().getBytes(); + } + + private class MessageBuffer extends ByteArrayOutputStream { + + byte[] getBytes() { + return buf; + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/jsch/JSchLogger.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/jsch/JSchLogger.java new file mode 100644 index 000000000..e6b47db38 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/jsch/JSchLogger.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.jsch; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * JSch logger implementation delegating to logback. + */ +public class JSchLogger implements com.jcraft.jsch.Logger { + + private static final Logger LOG = LoggerFactory.getLogger(JSchLogger.class); + + @Override + public boolean isEnabled(int level) { + return true; + } + + @Override + public void log(int level, String message) { + switch(level) { + case com.jcraft.jsch.Logger.DEBUG: + LOG.debug(message); + break; + + case com.jcraft.jsch.Logger.INFO: + LOG.info(message); + break; + + case com.jcraft.jsch.Logger.WARN: + LOG.warn(message); + break; + + case com.jcraft.jsch.Logger.ERROR: + case com.jcraft.jsch.Logger.FATAL: + LOG.error(message); + break; + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/jsch/NetconfClientJsch.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/jsch/NetconfClientJsch.java new file mode 100644 index 000000000..c743b2dd8 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/jsch/NetconfClientJsch.java @@ -0,0 +1,171 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.jsch; + +import com.jcraft.jsch.Channel; +import com.jcraft.jsch.ChannelSubsystem; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.Session; + +import java.io.IOException; +import java.util.List; +import java.util.Properties; + +import org.openecomp.appc.adapter.netconf.NetconfClient; +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.internal.NetconfAdapter; +import org.openecomp.appc.adapter.netconf.internal.NetconfConstMessages; +import org.openecomp.appc.encryption.EncryptionTool; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.i18n.Msg; +import com.att.eelf.i18n.EELFResourceManager; + +/** + * Implementation of NetconfClient interface based on JCraft jsch library. + */ +public class NetconfClientJsch implements NetconfClient { + + private static final int SESSION_CONNECT_TIMEOUT = 30000; + private static final int CHANNEL_CONNECT_TIMEOUT = 10000; + + private Session session; + private Channel channel; + private NetconfAdapter netconfAdapter; +// private NetconfAdapter2 netconfAdapter; + + + @Override + public void connect(NetconfConnectionDetails connectionDetails) throws APPCException { + String host = connectionDetails.getHost(); + int port = connectionDetails.getPort(); + String username = connectionDetails.getUsername(); + String password = connectionDetails.getPassword(); + try { + JSch.setLogger(new JSchLogger()); + JSch jsch = new JSch(); + session = jsch.getSession(EncryptionTool.getInstance().decrypt(username), host, port); + session.setPassword(EncryptionTool.getInstance().decrypt(password)); + session.setConfig("StrictHostKeyChecking", "no"); + + Properties additionalProps = connectionDetails.getAdditionalProperties(); + if((additionalProps != null) && !additionalProps.isEmpty()) { + session.setConfig(additionalProps); + } + + session.connect(SESSION_CONNECT_TIMEOUT); + session.setTimeout(10000); + try { +// session.setServerAliveCountMax(0); // If this is not set to '0', then socket timeout on all reads will not work!!!! + channel = session.openChannel("subsystem"); + ((ChannelSubsystem)channel).setSubsystem("netconf"); + netconfAdapter = new NetconfAdapter(channel.getInputStream(), channel.getOutputStream()); +// netconfAdapter = new NetconfAdapter2(); +// channel.setInputStream(netconfAdapter.getIn()); +// channel.setOutputStream(netconfAdapter.getOut()); + channel.connect(CHANNEL_CONNECT_TIMEOUT); + hello(connectionDetails.getCapabilities()); + } catch(Exception e) { + disconnect(); + throw e; + } + } catch(Exception e) { + String message = EELFResourceManager.format(Msg.CANNOT_ESTABLISH_CONNECTION, host, String.valueOf(port), username); + throw new APPCException(message, e); + } + } + + @Override + public String exchangeMessage(String message) throws APPCException { + try { + netconfAdapter.sendMessage(message); + return netconfAdapter.receiveMessage(); + } catch(IOException e) { + throw new APPCException(e); + } + } + + @Override + public void configure(String configuration) throws APPCException { + try { + isOk(exchangeMessage(configuration)); + } catch(IOException e) { + throw new APPCException(e); + } + } + + @Override + public String getConfiguration() throws APPCException { + return exchangeMessage(NetconfConstMessages.GET_RUNNING_CONFIG); + } + + @Override + public void disconnect() { + try { + if((channel != null) && !channel.isClosed()) { + netconfAdapter.sendMessage(NetconfConstMessages.CLOSE_SESSION); + isOk(netconfAdapter.receiveMessage()); + } + } catch(IOException e) { + throw new RuntimeException("Error closing netconf device", e); + } finally { + netconfAdapter = null; + if(channel != null) { + channel.disconnect(); + channel = null; + } + if(session != null) { + session.disconnect(); + session = null; + } + } + } + + private void hello(List capabilities) throws IOException { + String helloIn = netconfAdapter.receiveMessage(); + if(helloIn == null) { + throw new IOException("Expected hello message, but nothing received error from netconf device"); + } + if(helloIn.contains("")) { + throw new IOException("Expected hello message, but received error from netconf device:\n" + helloIn); + } + StringBuilder sb = new StringBuilder(); + sb.append(NetconfConstMessages.CAPABILITIES_START); + sb.append(NetconfConstMessages.CAPABILITIES_BASE); + if(capabilities != null) { + for(String capability: capabilities) { + sb.append(" ").append(capability).append("\n"); + } + } + sb.append(NetconfConstMessages.CAPABILITIES_END); + String helloOut = sb.toString(); + netconfAdapter.sendMessage(helloOut); + } + + private void isOk(String response) throws IOException { + if(response == null) { + throw new IOException("No response from netconf device"); + } + if(!response.contains("")) { + throw new IOException("Error response from netconf device: \n" + response); + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java new file mode 100644 index 000000000..2c10cdedd --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java @@ -0,0 +1,233 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.odlconnector; + +import org.apache.http.HttpStatus; +import org.openecomp.appc.adapter.netconf.NetconfClient; +import org.openecomp.appc.adapter.netconf.NetconfClientRestconf; +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.util.Constants; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.util.httpClient; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.Properties; + +public class NetconfClientRestconfImpl implements NetconfClient, NetconfClientRestconf { + + private EELFLogger logger = EELFManager.getInstance().getLogger(NetconfClientRestconfImpl.class); + + private NetconfConnectionDetails connectionDetails; + + //constructor + public NetconfClientRestconfImpl(){ + } + + //restconf client impl + + @SuppressWarnings("deprecation") + @Override + public void configure(String configuration, String deviceMountPointName, String moduleName, String nodeName) throws APPCException { + + logger.info("Configuring device "+deviceMountPointName+" with configuration "+configuration); + + int httpCode = httpClient.putMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getModuleConfigurePath(deviceMountPointName, moduleName, nodeName),configuration,"application/json"); + + if (httpCode != HttpStatus.SC_OK) { + logger.error("Configuration request failed. throwing Exception !"); + throw new APPCException("Error configuring node :"+nodeName + ", of Module :" + moduleName + ", in device :" + deviceMountPointName); + } + } + + @Override + public void connect(String deviceMountPointName, String payload) throws APPCException{ + + logger.info("Connecting device "+deviceMountPointName); + + int httpCode = httpClient.postMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getConnectPath(),payload,"application/json"); + + if(httpCode != HttpStatus.SC_NO_CONTENT){ + logger.error("Connect request failed with code "+httpCode+". throwing Exception !"); + throw new APPCException("Error connecting device :" + deviceMountPointName); + } + } + + @Override + public boolean checkConnection(String deviceMountPointName) throws APPCException { + logger.info("Checking device "+deviceMountPointName+" connectivity"); + + String result = httpClient.getMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getCheckConnectivityPath(deviceMountPointName),"application/json"); + + return result != null; + } + + @Override + public void disconnect(String deviceMountPointName) throws APPCException { + logger.info("Disconnecting "+deviceMountPointName); + + int httpCode = httpClient.deleteMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getDisconnectPath(deviceMountPointName),"application/json"); + + if(httpCode != HttpStatus.SC_OK){ + logger.error("Disconnection of device "+deviceMountPointName+" failed!"); + throw new APPCException("Disconnection of device "+deviceMountPointName+" failed!"); + } + } + + @Override + public String getConfiguration(String deviceMountPointName, String moduleName, String nodeName) throws APPCException{ + logger.info("Getting configuration of device "+deviceMountPointName); + + String result = httpClient.getMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getModuleConfigurePath(deviceMountPointName, moduleName, nodeName),"application/json"); + + if (result == null) { + logger.error("Configuration request failed. throwing Exception !"); + throw new APPCException("Error getting configuration of node :"+nodeName + ", of Module :" + moduleName + ", in device :" + deviceMountPointName); + } + + return result; + } + + //netconf client impl + + @Override + public void connect(NetconfConnectionDetails connectionDetails) throws APPCException { + if(connectionDetails == null){ + throw new APPCException("Invalid connection details - null value"); + } + this.connectionDetails = connectionDetails; + this.connect(connectionDetails.getHost(),getPayload()); + } + + @Override + public String exchangeMessage(String message) throws APPCException { + // TODO implement + return null; + } + + @Override + public void configure(String configuration) throws APPCException { + if(connectionDetails == null){ + throw new APPCException("Invalid connection details - null value"); + } + + Properties props = connectionDetails.getAdditionalProperties(); + if(props == null || !props.containsKey("module.name") || !props.containsKey("node.name")){ + throw new APPCException("Invalid properties!"); + } + + String moduleName = props.getProperty("module.name"); + String nodeName = props.getProperty("node.name"); + String deviceMountPointName = connectionDetails.getHost(); + + int httpCode = httpClient.putMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getModuleConfigurePath(deviceMountPointName, moduleName, nodeName),configuration,"application/xml"); + + if (httpCode != HttpStatus.SC_OK) { + logger.error("Configuration request failed. throwing Exception !"); + throw new APPCException("Error configuring node :"+nodeName + ", of Module :" + moduleName + ", in device :" + deviceMountPointName); + } + } + + @Override + public String getConfiguration() throws APPCException { + if(connectionDetails == null){ + throw new APPCException("Invalid connection details - null value"); + } + + Properties props = connectionDetails.getAdditionalProperties(); + if(props == null || !props.containsKey("module.name") || !props.containsKey("node.name")){ + throw new APPCException("Invalid properties!"); + } + + return this.getConfiguration(connectionDetails.getHost(),props.getProperty("module.name"),props.getProperty("node.name")); + } + + @Override + public void disconnect() throws APPCException { + if(connectionDetails == null){ + throw new APPCException("Invalid connection details - null value"); + } + this.disconnect(connectionDetails.getHost()); + } + + //private methods + private String getModuleConfigurePath(String deviceMountPointName, String moduleName, String nodeName){ + + + String deviceSpecificPath = deviceMountPointName + "/yang-ext:mount/" + moduleName + ":" + nodeName; + + return Constants.CONFIGURE_PATH + deviceSpecificPath; + } + + private String getConnectPath(){ + + return Constants.CONNECT_PATH; + } + + private String getCheckConnectivityPath(String deviceMountPointName) { + return Constants.CHECK_CONNECTION_PATH + deviceMountPointName; + } + + private String getDisconnectPath(String deviceMountPointName) { + return Constants.DISCONNECT_PATH + deviceMountPointName; + } + + private String getPayload() { + return "{\n" + + " \"config:module\":\n" + + " {\n" + + " \"type\":\"odl-sal-netconf-connector-cfg:sal-netconf-connector\",\n" + + " \"netconf-northbound-ssh\\odl-sal-netconf-connector-cfg:name\":"+connectionDetails.getHost()+",\n" + + " \"odl-sal-netconf-connector-cfg:address\":"+connectionDetails.getHost()+",\n" + + " \"odl-sal-netconf-connector-cfg:port\":"+connectionDetails.getPort()+",\n" + + " \"odl-sal-netconf-connector-cfg:username\":"+connectionDetails.getUsername()+",\n" + + " \"odl-sal-netconf-connector-cfg:password\":"+connectionDetails.getPassword()+",\n" + + " \"tcp-only\":\"false\",\n" + + " \"odl-sal-netconf-connector-cfg:event-executor\":\n" + + " {\n" + + " \"type\":\"netty:netty-event-executor\",\n" + + " \"name\":\"global-event-executor\"\n" + + " },\n" + + " \"odl-sal-netconf-connector-cfg:binding-registry\":\n" + + " {\n" + + " \"type\":\"opendaylight-md-sal-binding:binding-broker-osgi-registry\",\n" + + " \"name\":\"binding-osgi-broker\"\n" + + " },\n" + + " \"odl-sal-netconf-connector-cfg:dom-registry\":\n" + + " {\n" + + " \"type\":\"opendaylight-md-sal-dom:dom-broker-osgi-registry\",\n" + + " \"name\":\"dom-broker\"\n" + + " },\n" + + " \"odl-sal-netconf-connector-cfg:client-dispatcher\":\n" + + " {\n" + + " \"type\":\"odl-netconf-cfg:netconf-client-dispatcher\",\n" + + " \"name\":\"global-netconf-dispatcher\"\n" + + " },\n" + + " \"odl-sal-netconf-connector-cfg:processing-executor\":\n" + + " {\n" + + " \"type\":\"threadpool:threadpool\",\n" + + " \"name\":\"global-netconf-processing-executor\"\n" + + " }\n" + + " }\n" + + "}"; + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/util/Constants.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/util/Constants.java new file mode 100644 index 000000000..92141e1b7 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/openecomp/appc/adapter/netconf/util/Constants.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.util; + +public class Constants { + + public static final String CONFIGURE_PATH = "/restconf/config/opendaylight-inventory:nodes/node/"; + public static final String CONNECT_PATH = "/restconf/config/opendaylight-inventory:nodes/node/controller-config/yang-ext:mount/config:modules"; + public static final String CHECK_CONNECTION_PATH = "/restconf/operational/opendaylight-inventory:nodes/node/"; + public static final String DISCONNECT_PATH = "/restconf/config/opendaylight-inventory:nodes/node/controller-config/yang-ext:mount/config:modules/module/odl-sal-netconf-connector-cfg:sal-netconf-connector/"; + + public static final String CONTROLLER_IP = "127.0.0.1"; + public static final int CONTROLLER_PORT = 8181; + public static final String PROTOCOL = "http"; + + // tables and fields + public static final String NETCONF_SCHEMA = "sdnctl"; + public static final String DEVICE_AUTHENTICATION_TABLE_NAME = "DEVICE_AUTHENTICATION"; + public static final String CONFIGFILES_TABLE_NAME = "CONFIGFILES"; + public static final String DEVICE_INTERFACE_LOG_TABLE_NAME = "DEVICE_INTERFACE_LOG"; + public static final String FILE_CONTENT_TABLE_FIELD_NAME = "FILE_CONTENT"; + public static final String FILE_NAME_TABLE_FIELD_NAME = "FILE_NAME"; + public static final String USER_NAME_TABLE_FIELD_NAME = "USER_NAME"; + public static final String PASSWORD_TABLE_FIELD_NAME = "PASSWORD"; + public static final String VM_HOST_TABLE_FIELD_NAME = "VM_HOST"; + public static final String VM_NAME_TABLE_FIELD_NAME = "VM_NAME"; + public static final String PORT_NUMBER_TABLE_FIELD_NAME = "PORT_NUMBER"; + public static final String VNF_TYPE_TABLE_FIELD_NAME = "VNF_TYPE"; + public static final String SERVICE_INSTANCE_ID_FIELD_NAME = "SERVICE_INSTANCE_ID"; + public static final String REQUEST_ID_FIELD_NAME = "REQUEST_ID"; + public static final String CREATION_DATE_FIELD_NAME = "CREATION_DATE"; + public static final String LOG_FIELD_NAME = "LOG"; + + // input fields names + public static final String VNF_TYPE_FIELD_NAME = "org.openecomp.appc.vftype"; + public static final String TARGET_VNF_TYPE = "target-vnf-type"; + public static final String FILE_CONTENT_FIELD_NAME = "file-content"; + public static final String CONNECTION_DETAILS_FIELD_NAME = "connection-details"; + public static final String CONFIGURATION_FILE_FIELD_NAME = "configuration-file-name"; + public static final String VNF_HOST_IP_ADDRESS_FIELD_NAME = "vnf-host-ip-address"; + public static final String DG_ERROR_FIELD_NAME = "org.openecomp.appc.dg.error"; + public static final String RESOURCEKEY = "resourceKey"; + public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message"; + +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties new file mode 100644 index 000000000..fc741daf5 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties @@ -0,0 +1,41 @@ +### +# ============LICENSE_START======================================================= +# openECOMP : APP-C +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights +# reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +### + +org.openecomp.appc.bootstrap.file=appc.properties +org.openecomp.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. + +org.openecomp.appc.netconf.db.jdbc.driver=netconfctl +org.openecomp.appc.netconf.db.url.netconfctl=jdbc:mysql://127.0.0.1:3306/test +org.openecomp.appc.netconf.db.user.netconfctl=test +org.openecomp.appc.netconf.db.pass.netconfctl=123456 +org.openecomp.appc.netconf.recv.timeout=1800000 + +### ### +### Properties commented out below provided in appc.properties ### +### ### +#event.pool.members=:3904 +event.topic.write=APPC-TEST1 +event.client.key=VIlbtVl6YLhNUrtU +event.client.secret=64AG2hF4pYeG2pq7CT6XwUOT +#restconf.user= +#restconf.pass= + +org.openecomp.appc.adapter.netconf.VNFOperationalStateValidatorImpl-CONFIG_FILE=VnfGetOperationalStates diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java new file mode 100644 index 000000000..d6d5ae278 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java @@ -0,0 +1,197 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +import org.openecomp.appc.exceptions.APPCException; +import org.junit.Test; +import org.openecomp.appc.adapter.netconf.OperationalStateValidator; +import org.openecomp.appc.adapter.netconf.OperationalStateValidatorFactory; +import org.openecomp.appc.adapter.netconf.VnfType; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + + +public class OperationalStateValidatorTest { + + @Test + public void testVNFValidResponse() { + String validResponse = "\n" + + "\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " ENABLED\n" + + " \n" + + " processor_0_5\n" + + " ENABLED\n" + + " \n" + + " \n" + + " processor_0_7\n" + + " ENABLED\n" + + " \n" + + " \n" + + " \n" + + " SC-1\n" + + " ENABLED\n" + + " \n" + + " \n" + + " SC-2\n" + + " ENABLED\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); + assertValidResponse(validResponse, operationalStateValidator); + } + + void assertInvalidResponse(String response, OperationalStateValidator operationalStateValidator) { + try { + operationalStateValidator.validateResponse(response); + fail("invalid resposne passed without exception!!!"); + } catch (APPCException e) { + assertNotNull(e.getMessage()); + } + } + + @Test + public void testVNFInvalidResponses() { + + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); + assertInvalidResponse(null, operationalStateValidator); + + assertInvalidResponse("", operationalStateValidator); + + String response = ""; + assertInvalidResponse(response, operationalStateValidator); + + response = "\n" + + "\n" + + ""; + assertInvalidResponse(response, operationalStateValidator); + + response = "\n" + + "\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " ENABLED\n" + + " \n" + + " processor_0_5\n" + + " ENABLED\n" + + " \n" + + " \n" + + " processor_0_7\n" + + " ENABLED\n" + + " \n" + + " \n" + + " \n" + + " SC-1\n" + + " ENABLED\n" + + " \n" + + " \n" + + " SC-2\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + assertInvalidResponse(response, operationalStateValidator); + } + + void assertValidResponse(String response, OperationalStateValidator operationalStateValidator) { + try { + operationalStateValidator.validateResponse(response); + } catch (APPCException e) { + fail("Got unexpected exception. Validation failed. " + e.getMessage()); + } + } + + @Test + public void testMockValidResponse() { + String response = "valid"; + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator("mock"); + assertValidResponse(response, operationalStateValidator); + + response = ""; + assertValidResponse(response, operationalStateValidator); + + response = null; + assertValidResponse(response, operationalStateValidator); + } + + @Test + public void testMockInValidResponse() { + String response = "anything InValid anything.. "; + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.MOCK); + assertInvalidResponse(response, operationalStateValidator); + } + + @Test + public void testGetOperationalStateValidatorForInValidVnfType() { + try{ + OperationalStateValidatorFactory.getOperationalStateValidator("wrongVnfType"); + fail("invalid vnfType without exception!!!"); + } catch (Exception e) { + assertNotNull(e.getMessage()); + } + } + + @Test + public void testGetOperationalStateValidatorForValidVnfType() { + String vnfType = VnfType.VNF.name().toLowerCase(); + assertGettingValidatorForValidVnf(vnfType); + + vnfType = VnfType.VNF.name().toUpperCase(); + assertGettingValidatorForValidVnf(vnfType); + + vnfType = VnfType.MOCK.name().toLowerCase(); + assertGettingValidatorForValidVnf(vnfType); + + vnfType = VnfType.MOCK.name().toUpperCase(); + assertGettingValidatorForValidVnf(vnfType); + } + + void assertGettingValidatorForValidVnf(String vnfType) { + try{ + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(vnfType); + assertNotNull(operationalStateValidator); + } catch (Exception e) { + fail("valid vnfType throw exception!!!"); + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/internal/TestNetconfAdapter.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/internal/TestNetconfAdapter.java new file mode 100644 index 000000000..5e63d5010 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/internal/TestNetconfAdapter.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.internal; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.appc.adapter.netconf.internal.NetconfAdapter; + +import java.io.IOException; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; + +public class TestNetconfAdapter { + + private static final String EOM = "]]>]]>"; + + @Test + public void testReceiveMessage() throws IOException { + PipedOutputStream pos = new PipedOutputStream(); + PipedInputStream is = new PipedInputStream(pos); + + PipedInputStream pis = new PipedInputStream(); + PipedOutputStream os = new PipedOutputStream(pis); + + NetconfAdapter netconfAdapter = new NetconfAdapter(is, os); + + String request = "Hello, netconf!"; + pos.write(request.getBytes()); + pos.write(EOM.getBytes()); + String response = netconfAdapter.receiveMessage(); + Assert.assertNotNull(response); + Assert.assertEquals(request, response.trim()); + } + + @Test + public void testSendMessage() throws IOException { + PipedOutputStream pos = new PipedOutputStream(); + PipedInputStream is = new PipedInputStream(pos); + + PipedInputStream pis = new PipedInputStream(); + PipedOutputStream os = new PipedOutputStream(pis); + + NetconfAdapter netconfAdapter = new NetconfAdapter(is, os); + + String request = "Hello, netconf!"; + netconfAdapter.sendMessage(request); + byte[] bytes = new byte[request.length()+EOM.length()+2]; + int count = pis.read(bytes); + String response = new String(bytes, 0, count); + Assert.assertNotNull(response); + Assert.assertTrue(response.endsWith(EOM)); + response = response.substring(0, response.length() - EOM.length()).trim(); + Assert.assertEquals(request, response); + } + + @Test + public void testSendReceive() throws IOException { + PipedOutputStream os = new PipedOutputStream(); + PipedInputStream is = new PipedInputStream(os); + + NetconfAdapter netconfAdapter = new NetconfAdapter(is, os); + + String request = "Hello, netconf!"; + netconfAdapter.sendMessage(request); + String response = netconfAdapter.receiveMessage(); + Assert.assertNotNull(response); + Assert.assertEquals(request, response.trim()); + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestGetRunningConfig.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestGetRunningConfig.java new file mode 100644 index 000000000..a26c6e9e9 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestGetRunningConfig.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +public class TestGetRunningConfig { + + private static final String HOST = "192.168.1.2"; + private static final String USER = "test"; + private static final String PSWD = "test123"; + private static final int PORT = 830; + private static final List CAPABILITIES = Collections.singletonList("urn:org:openecomp:appc:capability:1.1.0"); + + public static void main(String[] args) throws APPCException { + try { + NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); + connectionDetails.setHost(HOST); + connectionDetails.setPort(PORT); + connectionDetails.setUsername(USER); + connectionDetails.setPassword(PSWD); + connectionDetails.setCapabilities(CAPABILITIES); + NetconfClientJsch netconfClientJsch = new NetconfClientJsch(); + netconfClientJsch.connect(connectionDetails); + try { + System.out.println("=> Running get configuration..."); + String configuration = netconfClientJsch.getConfiguration(); + System.out.println("=> Configuration:\n" + configuration); + } finally { + netconfClientJsch.disconnect(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfig.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfig.java new file mode 100644 index 000000000..e4baecc89 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfig.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +public class TestModifyConfig { + + private static final String HOST = "192.168.1.2"; + private static final String USER = "test"; + private static final String PSWD = "test123"; + private static final int PORT = 830; + private static final List CAPABILITIES = Collections.singletonList("urn:org:openecomp:appc:capability:1.1.0"); + private static final String CONFIG = + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " merge\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " example.com\n" + + " 60\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + public static void main(String[] args) throws APPCException { + try { + NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); + connectionDetails.setHost(HOST); + connectionDetails.setPort(PORT); + connectionDetails.setUsername(USER); + connectionDetails.setPassword(PSWD); + connectionDetails.setCapabilities(CAPABILITIES); + NetconfClientJsch netconfClientJsch = new NetconfClientJsch(); + netconfClientJsch.connect(connectionDetails); + try { + System.out.println("=> Running get configuration..."); + String configuration = netconfClientJsch.getConfiguration(); + System.out.println("=> Configuration:\n" + configuration); + + System.out.println("=> Reconfiguring device..."); + String outMessage = netconfClientJsch.exchangeMessage(CONFIG); + System.out.println("=> Reconfiguration response:\n" + outMessage); + + System.out.println("=> Running get configuration..."); + configuration = netconfClientJsch.getConfiguration(); + System.out.println("=> Configuration:\n" + configuration); + } finally { + netconfClientJsch.disconnect(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigMock.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigMock.java new file mode 100644 index 000000000..1fe2e1093 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigMock.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +public class TestModifyConfigMock { + + private static final String HOST = "192.168.1.2"; + private static final String USER = "test"; + private static final String PSWD = "test123"; + private static final int PORT = 830; + private static final List CAPABILITIES = Collections.singletonList("urn:org:openecomp:appc:capability:1.1.0"); + private static final String CONFIG = + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " merge\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " example.com\n" + + " 60\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + public static void main(String[] args) throws APPCException { + try { + NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); + connectionDetails.setHost(HOST); + connectionDetails.setPort(PORT); + connectionDetails.setUsername(USER); + connectionDetails.setPassword(PSWD); + connectionDetails.setCapabilities(CAPABILITIES); + NetconfClientJsch netconfClientJsch = new NetconfClientJsch(); + netconfClientJsch.connect(connectionDetails); + try { + System.out.println("=> Running get configuration..."); + String configuration = netconfClientJsch.getConfiguration(); + System.out.println("=> Configuration:\n" + configuration); + + System.out.println("=> Reconfiguring device..."); + String outMessage = netconfClientJsch.exchangeMessage(CONFIG); + System.out.println("=> Reconfiguration response:\n" + outMessage); + + System.out.println("=> Running get configuration..."); + configuration = netconfClientJsch.getConfiguration(); + System.out.println("=> Configuration:\n" + configuration); + } finally { + netconfClientJsch.disconnect(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java new file mode 100644 index 000000000..256e8e8f5 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +public class TestModifyConfigRouterMock { + + private static final String HOST = "10.147.27.50"; // yuma netconf simulator + private static final int PORT = 830; + private static final String USER = "admin"; + private static final String PSWD = "admin"; + private static final List CAPABILITIES = Collections.emptyList(); + private static final String CONFIG = + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 100.100.100.0/24\n" + + " 10\n" + + " \n" + + " \n" + + " \n" + + " 1000\n" + + " 10.10.1.1\n" + + " \n" + + " 2000\n" + + " 10.10.1.2\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n"; + + public static void main(String[] args) throws APPCException { + try { + NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); + connectionDetails.setHost(HOST); + connectionDetails.setPort(PORT); + connectionDetails.setUsername(USER); + connectionDetails.setPassword(PSWD); + connectionDetails.setCapabilities(CAPABILITIES); + NetconfClientJsch netconfClientJsch = new NetconfClientJsch(); + netconfClientJsch.connect(connectionDetails); + try { + System.out.println("=> Running get configuration..."); + String configuration = netconfClientJsch.getConfiguration(); + System.out.println("=> Configuration:\n" + configuration); + + System.out.println("=> Reconfiguring device..."); + String outMessage = netconfClientJsch.exchangeMessage(CONFIG); + System.out.println("=> Reconfiguration response:\n" + outMessage); + } finally { + netconfClientJsch.disconnect(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestOperationalStates.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestOperationalStates.java new file mode 100644 index 000000000..39c1a871c --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestOperationalStates.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +public class TestOperationalStates { + + private static final String HOST = "192.168.1.2"; + private static final String USER = "test"; + private static final String PSWD = "test123"; + private static final int PORT = 830; + private static final List CAPABILITIES = Collections.singletonList("urn:org:openecomp:appc:capability:1.1.0"); + private static final String GET_OPERATIONAL_STATES = + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + public static void main(String[] args) throws APPCException { + try { + NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails(); + connectionDetails.setHost(HOST); + connectionDetails.setPort(PORT); + connectionDetails.setUsername(USER); + connectionDetails.setPassword(PSWD); + connectionDetails.setCapabilities(CAPABILITIES); + NetconfClientJsch netconfClientJsch = new NetconfClientJsch(); + netconfClientJsch.connect(connectionDetails); + try { + System.out.println("=> Running get configuration..."); + String configuration = netconfClientJsch.getConfiguration(); + System.out.println("=> Configuration:\n" + configuration); + + System.out.println("=> Running get operational states..."); + String outMessage = netconfClientJsch.exchangeMessage(GET_OPERATIONAL_STATES); + System.out.println("=> Operational states:\n" + outMessage); + } finally { + netconfClientJsch.disconnect(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-features/pom.xml b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-features/pom.xml new file mode 100644 index 000000000..e94bdba56 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-features/pom.xml @@ -0,0 +1,122 @@ + + + + appc-netconf-adapter + org.openecomp.appc + 1.0.0 + + 4.0.0 + + appc-netconf-adapter-features + jar + + + + org.openecomp.appc + appc-netconf-adapter-bundle + ${project.version} + + + + commons-lang + commons-lang + compile + + + + org.opendaylight.controller + features-mdsal + features + xml + runtime + + + + + org.opendaylight.controller + opendaylight-karaf-empty + zip + + + + + + + + org.opendaylight.yangtools + features-yangtools + features + xml + runtime + + + + + + + true + src/main/resources + + + + + org.apache.maven.plugins + maven-resources-plugin + + + filter + + resources + + generate-resources + + + + + + + + + + + + + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + + attach-artifact + + package + + + + ${project.build.directory}/classes/${features.file} + xml + features + + + + + + + + + + \ No newline at end of file diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-features/src/main/resources/features.xml b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-features/src/main/resources/features.xml new file mode 100644 index 000000000..bfb4b8090 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-features/src/main/resources/features.xml @@ -0,0 +1,37 @@ + + + + + + + mvn:org.opendaylight.mdsal/features-mdsal/${features-mdsal.version}/xml/features + + + + odl-mdsal-broker + mvn:org.openecomp.appc/appc-dmaap-adapter-bundle/${project.version} + mvn:org.openecomp.appc/appc-netconf-adapter-bundle/${project.version} + + + diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-installer/pom.xml b/appc-adapters/appc-netconf-adapter/appc-netconf-installer/pom.xml new file mode 100644 index 000000000..141a1e254 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-installer/pom.xml @@ -0,0 +1,130 @@ + + + 4.0.0 + + appc-netconf-adapter + org.openecomp.appc + 1.0.0 + + appc-netconf-adapter-installer + NETCONF Adapter - Karaf Installer + pom + + + appc-netconf-adapter + appc-netconf-adapter + mvn:org.openecomp.appc/appc-netconf-adapter-features/${project.version}/xml/features + false + + + + + org.openecomp.appc + appc-netconf-adapter-features + features + xml + + + * + * + + + + + + org.openecomp.appc + appc-netconf-adapter-bundle + ${project.version} + + + + + + + maven-assembly-plugin + + + maven-repo-zip + + single + + package + + false + false + stage/${application.name}-${project.version} + + src/assembly/assemble_mvnrepo_zip.xml + + + + + installer-zip + + single + + package + + false + true + ${application.name}-${project.version} + + src/assembly/assemble_installer_zip.xml + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + + copy-dependencies + + prepare-package + + ${project.build.directory}/assembly/system + false + true + true + true + false + false + org.opendaylight + + + + + + maven-resources-plugin + + + copy-version + + copy-resources + + + validate + + ${basedir}/target/stage + + + src/main/resources/scripts + + install-feature.sh + + true + + + + + + + + + + + diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/assembly/assemble_installer_zip.xml b/appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/assembly/assemble_installer_zip.xml new file mode 100644 index 000000000..9fbaad8c5 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/assembly/assemble_installer_zip.xml @@ -0,0 +1,59 @@ + + + + + + adapter + + zip + + + + false + + + + target/stage/ + ${application.name} + 755 + + *.sh + + + + target/stage/ + ${application.name} + 644 + + *.sh + + + + + + + diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/assembly/assemble_mvnrepo_zip.xml b/appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/assembly/assemble_mvnrepo_zip.xml new file mode 100644 index 000000000..1ac5a82bc --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/assembly/assemble_mvnrepo_zip.xml @@ -0,0 +1,47 @@ + + + + + + adapter + + zip + + + + false + + + + target/assembly/ + . + + + + + + diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/main/resources/scripts/install-feature.sh b/appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/main/resources/scripts/install-feature.sh new file mode 100644 index 000000000..1d769fada --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-installer/src/main/resources/scripts/install-feature.sh @@ -0,0 +1,40 @@ +### +# ============LICENSE_START======================================================= +# openECOMP : APP-C +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights +# reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +### + +#!/bin/bash + +ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} +ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} +ODL_KARAF_CLIENT_OPTS=${ODL_KARAF_CLIENT_OPTS:-"-u karaf"} +INSTALLERDIR=$(dirname $0) + +REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip + +if [ -f ${REPOZIP} ] +then + unzip -n -d ${ODL_HOME} ${REPOZIP} +else + echo "ERROR : repo zip ($REPOZIP) not found" + exit 1 +fi + +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:repo-add ${features.repositories} +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:install ${features.boot} diff --git a/appc-adapters/appc-netconf-adapter/pom.xml b/appc-adapters/appc-netconf-adapter/pom.xml new file mode 100644 index 000000000..5ef2cd3e3 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/pom.xml @@ -0,0 +1,127 @@ + + + + appc-adapters + org.openecomp.appc + 1.0.0 + + 4.0.0 + + appc-netconf-adapter + NETCONF adapter + pom + + + 1.0.1-Beryllium-SR1 + + + + + + maven-javadoc-plugin + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.antlr + antlr4 + ${antlr.version} + + + org.antlr + antlr4-runtime + 4.3 + + + + + + + javadoc-no-fork + test-javadoc-no-fork + + + + aggregate + + aggregate + test-aggregate + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.3 + + + aggregate + + aggregate + test-aggregate + + + + + + + maven-surefire-plugin + + + + org.apache.maven.plugins + maven-changelog-plugin + 2.3 + + + dual-report + + range + 30 + + + changelog + file-activity + + + + + + + org.codehaus.mojo + taglist-maven-plugin + 2.4 + + + + + + + + org.openecomp.appc + appc-netconf-adapter-features + features + xml + ${project.version} + + + org.openecomp.appc + appc-netconf-adapter-provider + ${project.version} + + + + + + appc-netconf-adapter-bundle + appc-netconf-adapter-features + appc-netconf-installer + + + + \ No newline at end of file -- cgit 1.2.3-korg