summaryrefslogtreecommitdiffstats
path: root/adaptors/mdsal-resource/provider/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'adaptors/mdsal-resource/provider/src/main')
-rw-r--r--adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java153
-rwxr-xr-xadaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProvider.java28
-rwxr-xr-xadaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProviderImpl.java186
-rw-r--r--adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java147
-rw-r--r--adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java184
-rwxr-xr-xadaptors/mdsal-resource/provider/src/main/resources/IPV4_ADDRESS_POOL.csv9
-rwxr-xr-xadaptors/mdsal-resource/provider/src/main/resources/OSGI-INF/blueprint/mdsal-resource-blueprint.xml49
-rwxr-xr-xadaptors/mdsal-resource/provider/src/main/resources/VLAN_ID_POOL.csv22
-rw-r--r--adaptors/mdsal-resource/provider/src/main/resources/crtables.sql70
-rw-r--r--adaptors/mdsal-resource/provider/src/main/resources/mdsal-resource.properties27
-rwxr-xr-xadaptors/mdsal-resource/provider/src/main/resources/org/opendaylight/blueprint/mdsal-resource-blueprint.xml49
-rw-r--r--adaptors/mdsal-resource/provider/src/main/resources/svclogic.properties26
12 files changed, 950 insertions, 0 deletions
diff --git a/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java
new file mode 100644
index 000000000..e2e9bc230
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java
@@ -0,0 +1,153 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-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.onap.ccsdk.sli.adaptors.resource.mdsal;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+public class ConfigResource implements SvcLogicResource {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigResource.class);
+
+ private RestService restService;
+
+ public ConfigResource(MdsalResourcePropertiesProvider propProvider) {
+ LOG.info("Loading ConfigResource using property provider");
+ Properties props = propProvider.getProperties();
+
+ String sdncUser = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user", "admin");
+ String sdncPasswd = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd", "admin");
+ String sdncHost = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host", "localhost");
+ String sdncProtocol = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol", "https");
+ String sdncPort = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port", "8443");
+
+ restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, "XML", "XML");
+ }
+
+ public ConfigResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd)
+ {
+ restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, "XML", "XML");
+ }
+
+ public ConfigResource(RestService restService) {
+ this.restService = restService;
+ }
+
+ @Override
+ public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException
+ {
+ return(query(resource, false, null, key, prefix, null, null));
+ }
+
+ @Override
+ public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException
+ {
+ return(query(resource, false, null, key, prefix, null, null));
+ }
+
+ @Override
+ public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix,
+ String orderBy, SvcLogicContext ctx) throws SvcLogicException {
+ String module = resource;
+ StringBuffer restQuery = new StringBuffer();
+
+ String[] keyParts = key.split("/");
+ for (String keyPart : keyParts) {
+ if (restQuery.length() > 0) {
+ restQuery.append("/");
+ }
+ if (keyPart.startsWith("$")) {
+ restQuery.append(ctx.resolve(keyPart.substring(1)));
+ } else {
+ restQuery.append(keyPart);
+ }
+ }
+
+ String restQueryStr = restQuery.toString();
+ if ((restQueryStr.startsWith("'") && restQueryStr.endsWith("'")) ||
+ (restQueryStr.startsWith("\"") && restQueryStr.endsWith("\""))) {
+ restQueryStr = restQueryStr.substring(1, restQueryStr.length()-1);
+ }
+
+ String urlString = "restconf/config/" + module + ":" + restQueryStr;
+ LOG.info("Querying resource: " + resource + ". At URL: " + urlString);
+
+ Document results = restService.get(urlString);
+ if (results == null) {
+ return(QueryStatus.NOT_FOUND);
+ } else {
+ if (ctx != null) {
+ ctx.mergeDocument(prefix, results);
+ }
+ return(QueryStatus.SUCCESS);
+ }
+ }
+
+ @Override
+ public QueryStatus reserve(String resource, String select, String key, String prefix,
+ SvcLogicContext ctx) throws SvcLogicException {
+ return(QueryStatus.SUCCESS);
+
+ }
+
+ @Override
+ public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
+ return(QueryStatus.SUCCESS);
+ }
+
+ @Override
+ public QueryStatus delete(String arg0, String arg1, SvcLogicContext arg2)
+ throws SvcLogicException {
+ // TODO Auto-generated method stub
+ return(QueryStatus.SUCCESS);
+ }
+
+ @Override
+ public QueryStatus save(String arg0, boolean arg1, boolean localOnly, String arg2,
+ Map<String, String> arg3, String arg4, SvcLogicContext arg5)
+ throws SvcLogicException {
+ // TODO Auto-generated method stub
+ return(QueryStatus.SUCCESS);
+ }
+
+ @Override
+ public QueryStatus notify(String resource, String action, String key,
+ SvcLogicContext ctx) throws SvcLogicException {
+ return(QueryStatus.SUCCESS);
+ }
+
+
+ public QueryStatus update(String resource, String key,
+ Map<String, String> parms, String prefix, SvcLogicContext ctx)
+ throws SvcLogicException {
+ return(QueryStatus.SUCCESS);
+ }
+
+}
diff --git a/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProvider.java b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProvider.java
new file mode 100755
index 000000000..e433a4c13
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProvider.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.resource.mdsal;
+
+import java.util.Properties;
+
+public interface MdsalResourcePropertiesProvider {
+
+ public Properties getProperties();
+}
diff --git a/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProviderImpl.java b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProviderImpl.java
new file mode 100755
index 000000000..e9e006f17
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProviderImpl.java
@@ -0,0 +1,186 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.resource.mdsal;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.onap.ccsdk.sli.core.sli.ConfigurationException;
+import org.onap.ccsdk.sli.core.utils.JREFileResolver;
+import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver;
+import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
+import org.onap.ccsdk.sli.core.utils.common.CoreDefaultFileResolver;
+import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Responsible for determining the properties file to use and instantiating the
+ * <code>SqlResource</code> Service. The priority for properties file
+ * resolution is as follows:
+ *
+ * <ol>
+ * <li>A directory identified by the system environment variable
+ * <code>SDNC_CONFIG_DIR</code></li>
+ * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li>
+ * <li>A directory identified by the JRE argument
+ * <code>sql-resource.properties</code></li>
+ * <li>A <code>sql-resource.properties</code> file located in the karaf root
+ * directory</li>
+ * </ol>
+ */
+public class MdsalResourcePropertiesProviderImpl implements MdsalResourcePropertiesProvider {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MdsalResourcePropertiesProviderImpl.class);
+
+ /**
+ * The name of the properties file for database configuration
+ */
+ private static final String MDSALRESOURCE_PROP_FILE_NAME = "mdsal-resource.properties";
+
+ /**
+ * A prioritized list of strategies for resolving sql-resource properties files.
+ */
+ private Vector<PropertiesFileResolver> mdsalResourcePropertiesFileResolvers = new Vector<>();
+
+ /**
+ * The configuration properties for the db connection.
+ */
+ private Properties properties;
+
+ /**
+ * Set up the prioritized list of strategies for resolving dblib properties
+ * files.
+ */
+ public MdsalResourcePropertiesProviderImpl() {
+ mdsalResourcePropertiesFileResolvers
+ .add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable"));
+ mdsalResourcePropertiesFileResolvers.add(new CoreDefaultFileResolver("Using property file (2) from default directory"));
+
+ mdsalResourcePropertiesFileResolvers.add(
+ new JREFileResolver("Using property file (3) from JRE argument", MdsalResourcePropertiesProviderImpl.class));
+ mdsalResourcePropertiesFileResolvers.add(new KarafRootFileResolver("Using property file (4) from karaf root", this));
+
+ // determines properties file as according to the priority described in the
+ // class header comment
+ final File propertiesFile = determinePropertiesFile(this);
+ if (propertiesFile != null) {
+ try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) {
+ properties = new Properties();
+ properties.load(fileInputStream);
+ } catch (final IOException e) {
+ LOG.error("Failed to load properties for file: {}", propertiesFile.toString(),
+ new ConfigurationException("Failed to load properties for file: " + propertiesFile.toString(),
+ e));
+ }
+ } else {
+ // Try to read properties as resource
+
+ InputStream propStr = getClass().getResourceAsStream("/" + MDSALRESOURCE_PROP_FILE_NAME);
+ if (propStr != null) {
+ properties = new Properties();
+ try {
+ properties.load(propStr);
+ propStr.close();
+ } catch (IOException e) {
+ properties = null;
+ }
+ }
+
+ }
+
+ if (properties == null) {
+ reportFailure("Missing configuration properties resource(3)", new ConfigurationException(
+ "Missing configuration properties resource(3): " + MDSALRESOURCE_PROP_FILE_NAME));
+ }
+ }
+
+ /**
+ * Extract svclogic config properties.
+ *
+ * @return the svclogic config properties
+ */
+ public Properties getProperties() {
+ return properties;
+ }
+
+ /**
+ * Reports the method chosen for properties resolution to the
+ * <code>Logger</code>.
+ *
+ * @param message
+ * Some user friendly message
+ * @param fileOptional
+ * The file location of the chosen properties file
+ * @return the file location of the chosen properties file
+ */
+ private static File reportSuccess(final String message, final Optional<File> fileOptional) {
+ if (fileOptional.isPresent()) {
+ final File file = fileOptional.get();
+ LOG.info("{} {}", message, file.getPath());
+ return file;
+ }
+ return null;
+ }
+
+ /**
+ * Reports fatal errors. This is the case in which no properties file could be
+ * found.
+ *
+ * @param message
+ * An appropriate fatal error message
+ * @param configurationException
+ * An exception describing what went wrong during resolution
+ */
+ private static void reportFailure(final String message, final ConfigurationException configurationException) {
+
+ LOG.error("{}", message, configurationException);
+ }
+
+ /**
+ * Determines the sql-resource properties file to use based on the following priority:
+ * <ol>
+ * <li>A directory identified by the system environment variable
+ * <code>SDNC_CONFIG_DIR</code></li>
+ * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li>
+ * <li>A directory identified by the JRE argument
+ * <code>mdsal-resource.properties</code></li>
+ * <li>A <code>sql-resource.properties</code> file located in the karaf root
+ * directory</li>
+ * </ol>
+ */
+ File determinePropertiesFile(final MdsalResourcePropertiesProviderImpl resourceProvider) {
+
+ for (final PropertiesFileResolver sliPropertiesFileResolver : mdsalResourcePropertiesFileResolvers) {
+ final Optional<File> fileOptional = sliPropertiesFileResolver.resolveFile(MDSALRESOURCE_PROP_FILE_NAME);
+ if (fileOptional.isPresent()) {
+ return reportSuccess(sliPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional);
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java
new file mode 100644
index 000000000..320878126
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java
@@ -0,0 +1,147 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-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.onap.ccsdk.sli.adaptors.resource.mdsal;
+
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class OperationalResource implements SvcLogicResource {
+
+ private static final Logger LOG = LoggerFactory.getLogger(OperationalResource.class);
+
+ private RestService restService;
+
+ public OperationalResource(MdsalResourcePropertiesProvider propProvider) {
+ Properties props = propProvider.getProperties();
+
+ String sdncUser = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user", "admin");
+ String sdncPasswd = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd", "admin");
+ String sdncHost = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host", "localhost");
+ String sdncProtocol = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol", "https");
+ String sdncPort = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port", "8443");
+
+ restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, "XML", "XML");
+ }
+
+ public OperationalResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd) {
+ restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, "XML", "XML");
+ }
+
+ public OperationalResource(RestService restService) {
+ this.restService = restService;
+ }
+
+ @Override
+ public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException {
+ return (query(resource, false, null, key, prefix, null, null));
+ }
+
+ @Override
+ public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException {
+ return (query(resource, false, null, key, prefix, null, null));
+ }
+
+ @Override
+ public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix,
+ String orderBy, SvcLogicContext ctx) throws SvcLogicException {
+ String module = resource;
+ StringBuffer restQuery = new StringBuffer();
+
+ String[] keyParts = key.split("/");
+ for (String keyPart : keyParts) {
+ if (restQuery.length() > 0) {
+ restQuery.append("/");
+ }
+ if (keyPart.startsWith("$")) {
+ restQuery.append(ctx.resolve(keyPart.substring(1)));
+ } else {
+ restQuery.append(keyPart);
+ }
+ }
+
+ String restQueryStr = restQuery.toString();
+ if ((restQueryStr.startsWith("'") && restQueryStr.endsWith("'")) ||
+ (restQueryStr.startsWith("\"") && restQueryStr.endsWith("\""))) {
+ restQueryStr = restQueryStr.substring(1, restQueryStr.length() - 1);
+ }
+
+ String urlString = "restconf/operational/" + module + ":" + restQueryStr;
+ LOG.info("Querying resource: " + resource + ". At URL: " + urlString);
+
+ Document results = restService.get(urlString);
+
+ if (results == null) {
+ return (QueryStatus.NOT_FOUND);
+ } else {
+ if (ctx != null) {
+ ctx.mergeDocument(prefix, results);
+ }
+ return (QueryStatus.SUCCESS);
+ }
+ }
+
+ @Override
+ public QueryStatus reserve(String resource, String select, String key, String prefix,
+ SvcLogicContext ctx) throws SvcLogicException {
+ return (QueryStatus.SUCCESS);
+ }
+
+ @Override
+ public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
+ return (QueryStatus.SUCCESS);
+ }
+
+ @Override
+ public QueryStatus delete(String arg0, String arg1, SvcLogicContext arg2)
+ throws SvcLogicException {
+ // TODO Auto-generated method stub
+ return (QueryStatus.SUCCESS);
+ }
+
+ @Override
+ public QueryStatus save(String arg0, boolean arg1, boolean localOnly, String arg2,
+ Map<String, String> arg3, String arg4, SvcLogicContext arg5)
+ throws SvcLogicException {
+ // TODO Auto-generated method stub
+ return (QueryStatus.SUCCESS);
+ }
+
+ @Override
+ public QueryStatus notify(String resource, String action, String key,
+ SvcLogicContext ctx) throws SvcLogicException {
+ return (QueryStatus.SUCCESS);
+ }
+
+ public QueryStatus update(String resource, String key,
+ Map<String, String> parms, String prefix, SvcLogicContext ctx)
+ throws SvcLogicException {
+ return (QueryStatus.SUCCESS);
+ }
+
+}
diff --git a/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java
new file mode 100644
index 000000000..ebddc24ae
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java
@@ -0,0 +1,184 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-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.onap.ccsdk.sli.adaptors.resource.mdsal;
+
+import org.apache.commons.codec.binary.Base64;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.*;
+import java.net.Authenticator;
+import java.net.HttpURLConnection;
+import java.net.PasswordAuthentication;
+import java.net.URL;
+
+public class RestService {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigResource.class);
+ private String user;
+ private String passwd;
+ private String contentType;
+ private String accept;
+ private String protocol;
+ private String host;
+ private String port;
+
+ public RestService(String protocol, String host, String port, String user, String passwd, String accept, String contentType) {
+ this.protocol = protocol;
+ this.host = host;
+ this.port = port;
+ this.user = user;
+ this.passwd = passwd;
+ this.accept = accept;
+ this.contentType = contentType;
+ }
+
+ private HttpURLConnection getRestConnection(String urlString, String method) throws IOException {
+ URL sdncUrl = new URL(urlString);
+ Authenticator.setDefault(new SdncAuthenticator(user, passwd));
+
+ String authStr = user + ":" + passwd;
+ String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes()));
+
+ HttpURLConnection conn = (HttpURLConnection) sdncUrl.openConnection();
+ conn.addRequestProperty("Authentication", "Basic " + encodedAuthStr);
+ conn.setRequestMethod(method);
+ conn.setDoInput(true);
+ conn.setDoOutput(true);
+ conn.setUseCaches(false);
+
+ //Setting Accept header (doesn't dependent on Msg Body if present or not)
+ if ("XML".equalsIgnoreCase(accept)) {
+ conn.setRequestProperty("Accept", "application/xml");
+ } else {
+ conn.setRequestProperty("Accept", "application/json");
+ }
+
+ return (conn);
+ }
+
+ private Document send(String urlString, byte[] msgBytes, String method) {
+ Document response = null;
+ String fullUrl = protocol + "://" + host + ":" + port + "/" + urlString;
+ LOG.info("Sending REST {} to {}", method, fullUrl);
+
+ try {
+ HttpURLConnection conn = getRestConnection(fullUrl, method);
+ if (conn instanceof HttpsURLConnection) {
+ HostnameVerifier hostnameVerifier = (hostname, session) -> true;
+ ((HttpsURLConnection) conn).setHostnameVerifier(hostnameVerifier);
+ }
+
+ // Write message
+ if (msgBytes != null) {
+ LOG.info("Message body:\n{}", msgBytes);
+ conn.setRequestProperty("Content-Length", "" + msgBytes.length);
+
+ // Setting Content-Type header only if Msg Body is present
+ if ("XML".equalsIgnoreCase(contentType)) {
+ conn.setRequestProperty("Content-Type", "application/xml");
+ } else {
+ conn.setRequestProperty("Content-Type", "application/json");
+ }
+
+ DataOutputStream outStr = new DataOutputStream(conn.getOutputStream());
+ outStr.write(msgBytes);
+ outStr.close();
+ } else {
+ conn.setRequestProperty("Content-Length", "0");
+ }
+
+ // Read response
+ LOG.info("Response: {} {}", conn.getResponseCode(), conn.getResponseMessage());
+
+ BufferedReader respRdr;
+ if (conn.getResponseCode() < 300) {
+ respRdr = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ } else {
+ respRdr = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
+ }
+
+ StringBuffer respBuff = new StringBuffer();
+ String respLn;
+ while ((respLn = respRdr.readLine()) != null) {
+ respBuff.append(respLn + "\n");
+ }
+ respRdr.close();
+
+ String respString = respBuff.toString();
+ LOG.info("Response body :\n{}", respString);
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
+ dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ response = db.parse(new ByteArrayInputStream(respString.getBytes()));
+
+ } catch (Exception e) {
+ LOG.error("Caught exception executing REST command", e);
+ }
+
+ return (response);
+ }
+
+ public Document get(String urlString) {
+ return (send(urlString, null, "GET"));
+ }
+
+ public Document delete(String urlString) {
+ return (send(urlString, null, "DELETE"));
+ }
+
+ public Document post(String urlString, byte[] msgBytes) {
+ return (send(urlString, msgBytes, "POST"));
+ }
+
+ public Document put(String urlString, byte[] msgBytes) {
+ return (send(urlString, msgBytes, "PUT"));
+ }
+
+
+ private class SdncAuthenticator extends Authenticator {
+ private String user;
+ private String passwd;
+
+ SdncAuthenticator(String user, String passwd) {
+ this.user = user;
+ this.passwd = passwd;
+ }
+
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(user, passwd.toCharArray());
+ }
+
+ }
+
+}
diff --git a/adaptors/mdsal-resource/provider/src/main/resources/IPV4_ADDRESS_POOL.csv b/adaptors/mdsal-resource/provider/src/main/resources/IPV4_ADDRESS_POOL.csv
new file mode 100755
index 000000000..30ce117bc
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/resources/IPV4_ADDRESS_POOL.csv
@@ -0,0 +1,9 @@
+"192.168.1.2","OAM","AVAILABLE"
+"192.168.1.3","OAM","AVAILABLE"
+"192.168.1.4","OAM","AVAILABLE"
+"192.168.1.5","OAM","AVAILABLE"
+"192.168.1.6","OAM","AVAILABLE"
+"192.168.1.7","OAM","AVAILABLE"
+"192.168.1.8","OAM","AVAILABLE"
+"192.168.1.9","OAM","AVAILABLE"
+"192.168.1.10","OAM","AVAILABLE"
diff --git a/adaptors/mdsal-resource/provider/src/main/resources/OSGI-INF/blueprint/mdsal-resource-blueprint.xml b/adaptors/mdsal-resource/provider/src/main/resources/OSGI-INF/blueprint/mdsal-resource-blueprint.xml
new file mode 100755
index 000000000..9c691263c
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/resources/OSGI-INF/blueprint/mdsal-resource-blueprint.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : SDN-C
+ ================================================================================
+ Copyright (C) 2017 - 2018 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=========================================================
+ -->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <bean id="propProvider" class="org.onap.ccsdk.sli.adaptors.resource.mdsal.MdsalResourcePropertiesProviderImpl" />
+
+
+ <bean id="configResourceInstance" class="org.onap.ccsdk.sli.adaptors.resource.mdsal.ConfigResource">
+ <argument ref="propProvider"/>
+ </bean>
+
+ <bean id="operResourceInstance" class="org.onap.ccsdk.sli.adaptors.resource.mdsal.OperationalResource">
+ <argument ref="propProvider"/>
+ </bean>
+
+ <service ref="configResourceInstance">
+ <interfaces>
+ <value>org.onap.ccsdk.sli.adaptors.resource.mdsal.ConfigResource</value>
+ </interfaces>
+ </service>
+
+ <service ref="operResourceInstance">
+ <interfaces>
+ <value>org.onap.ccsdk.sli.adaptors.resource.mdsal.OperationalResource</value>
+ </interfaces>
+ </service>
+</blueprint>
diff --git a/adaptors/mdsal-resource/provider/src/main/resources/VLAN_ID_POOL.csv b/adaptors/mdsal-resource/provider/src/main/resources/VLAN_ID_POOL.csv
new file mode 100755
index 000000000..6c4b0f775
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/resources/VLAN_ID_POOL.csv
@@ -0,0 +1,22 @@
+"1100","IPAG","AVAILABLE",NULL
+"1101","IPAG","AVAILABLE",NULL
+"1102","IPAG","AVAILABLE",NULL
+"1103","IPAG","AVAILABLE",NULL
+"1104","IPAG","AVAILABLE",NULL
+"1105","IPAG","AVAILABLE",NULL
+"1106","IPAG","AVAILABLE",NULL
+"1107","IPAG","AVAILABLE",NULL
+"1108","IPAG","AVAILABLE",NULL
+"1109","IPAG","AVAILABLE",NULL
+"1110","IPAG","AVAILABLE",NULL
+"1200","VPE","AVAILABLE",NULL
+"1201","VPE","AVAILABLE",NULL
+"1202","VPE","AVAILABLE",NULL
+"1203","VPE","AVAILABLE",NULL
+"1204","VPE","AVAILABLE",NULL
+"1205","VPE","AVAILABLE",NULL
+"1206","VPE","AVAILABLE",NULL
+"1207","VPE","AVAILABLE",NULL
+"1208","VPE","AVAILABLE",NULL
+"1209","VPE","AVAILABLE",NULL
+"1210","VPE","AVAILABLE",NULL
diff --git a/adaptors/mdsal-resource/provider/src/main/resources/crtables.sql b/adaptors/mdsal-resource/provider/src/main/resources/crtables.sql
new file mode 100644
index 000000000..5ee75f4e4
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/resources/crtables.sql
@@ -0,0 +1,70 @@
+---
+-- ============LICENSE_START=======================================================
+-- openECOMP : SDN-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=========================================================
+---
+
+CREATE TABLE sdnctl.VNF (
+vnf_id varchar(80) NOT NULL,
+vnf_name varchar(80) NOT NULL,
+vnf_type varchar(10) NOT NULL,
+orchestration_status varchar(20),
+heat_stack_id varchar(80),
+mso_catalog_key varchar(80),
+availability_zone varchar(80),
+aic_site_id varchar(80),
+oam_ipv4_address varchar(20),
+CONSTRAINT P_VNF PRIMARY KEY(vnf_id));
+
+CREATE TABLE sdnctl.VNF_NETWORK_CONNECTION (
+connection_uuid varchar(80) NOT NULL,
+vnf_id varchar(80) NOT NULL,
+connection_id varchar(80),
+connection_type varchar(20),
+neutron_network_id varchar(80),
+neutron_network_name varchar(80),
+orchestration_status varchar(20),
+switch_id varchar(40),
+heat_stack_id varchar(80),
+mso_catalog_key varchar(80),
+provider_network varchar(80),
+port_group_id varchar(80),
+port_group_name varchar(80),
+CONSTRAINT P_NETWORK_CONNECTION PRIMARY KEY(connection_uuid));
+
+CREATE TABLE sdnctl.VNF_NETWORK_CONNECTION_VLAN (
+vlan_uuid varchar(80) NOT NULL,
+vlan_id numeric(4) NOT NULL,
+vlan_type varchar(5) NOT NULL,
+connection_uuid varchar(80),
+CONSTRAINT P_VNF_NETWORK_CONNECTION_VLAN PRIMARY KEY(vlan_uuid));
+
+CREATE TABLE sdnctl.VLAN_ID_POOL (
+vlan_id numeric(4) NOT NULL,
+universe varchar(40) NOT NULL,
+status varchar(40) NOT NULL,
+vlan_uuid varchar(80),
+CONSTRAINT P_VLAN_ID_POOL PRIMARY KEY(vlan_id,universe));
+
+CREATE TABLE sdnctl.IPV4_ADDRESS_POOL (
+ipv4_addr varchar(20) NOT NULL,
+universe varchar(40) NOT NULL,
+status varchar(40) NOT NULL,
+CONSTRAINT P_IPV4_ADDRESS_POOL PRIMARY KEY(ipv4_addr, universe));
+
+
diff --git a/adaptors/mdsal-resource/provider/src/main/resources/mdsal-resource.properties b/adaptors/mdsal-resource/provider/src/main/resources/mdsal-resource.properties
new file mode 100644
index 000000000..47c8ebf77
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/resources/mdsal-resource.properties
@@ -0,0 +1,27 @@
+###
+# ============LICENSE_START=======================================================
+# openECOMP : SDN-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.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user=admin
+org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U
+org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host=localhost
+org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol=http
+org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port=8181
+
diff --git a/adaptors/mdsal-resource/provider/src/main/resources/org/opendaylight/blueprint/mdsal-resource-blueprint.xml b/adaptors/mdsal-resource/provider/src/main/resources/org/opendaylight/blueprint/mdsal-resource-blueprint.xml
new file mode 100755
index 000000000..9c691263c
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/resources/org/opendaylight/blueprint/mdsal-resource-blueprint.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : SDN-C
+ ================================================================================
+ Copyright (C) 2017 - 2018 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=========================================================
+ -->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <bean id="propProvider" class="org.onap.ccsdk.sli.adaptors.resource.mdsal.MdsalResourcePropertiesProviderImpl" />
+
+
+ <bean id="configResourceInstance" class="org.onap.ccsdk.sli.adaptors.resource.mdsal.ConfigResource">
+ <argument ref="propProvider"/>
+ </bean>
+
+ <bean id="operResourceInstance" class="org.onap.ccsdk.sli.adaptors.resource.mdsal.OperationalResource">
+ <argument ref="propProvider"/>
+ </bean>
+
+ <service ref="configResourceInstance">
+ <interfaces>
+ <value>org.onap.ccsdk.sli.adaptors.resource.mdsal.ConfigResource</value>
+ </interfaces>
+ </service>
+
+ <service ref="operResourceInstance">
+ <interfaces>
+ <value>org.onap.ccsdk.sli.adaptors.resource.mdsal.OperationalResource</value>
+ </interfaces>
+ </service>
+</blueprint>
diff --git a/adaptors/mdsal-resource/provider/src/main/resources/svclogic.properties b/adaptors/mdsal-resource/provider/src/main/resources/svclogic.properties
new file mode 100644
index 000000000..0abadc5c8
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/main/resources/svclogic.properties
@@ -0,0 +1,26 @@
+###
+# ============LICENSE_START=======================================================
+# openECOMP : SDN-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.onap.ccsdk.sli.adaptors.dbtype = jdbc
+org.onap.ccsdk.sli.adaptors.jdbc.url = jdbc:mysql://dbhost:3306/sdnctl
+org.onap.ccsdk.sli.adaptors.jdbc.database = sdnctl
+org.onap.ccsdk.sli.adaptors.jdbc.user = sdnctl
+org.onap.ccsdk.sli.adaptors.jdbc.password = gamma