From 448566611416c33d58dbd73d40f9bdc1acf40404 Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Tue, 15 Aug 2017 19:13:35 -0700 Subject: Update sli-adaptor/mdsal-resource package names Update package names from org.openecomp.sdnc.adaptors.* -> onap.ccsdk.sli.adaptors.* Update groupIds from org.openecomp.sdnc.adaptors -> onap.ccsdk.sli.adaptors Issue-Id: CCSDK-19 Change-Id: I4aba920e51de27c47b1f936ccb3fc89fa81ed4b0 Signed-off-by: Marcus G K Williams --- mdsal-resource/provider/pom.xml | 8 +- .../adaptors/resource/mdsal/ConfigResource.java | 151 +++++++++++++++ .../resource/mdsal/MdsalResourceActivator.java | 106 +++++++++++ .../resource/mdsal/OperationalResource.java | 151 +++++++++++++++ .../sli/adaptors/resource/mdsal/RestService.java | 212 +++++++++++++++++++++ .../sdnc/sli/resource/mdsal/ConfigResource.java | 151 --------------- .../sli/resource/mdsal/MdsalResourceActivator.java | 106 ----------- .../sli/resource/mdsal/OperationalResource.java | 151 --------------- .../sdnc/sli/resource/mdsal/RestService.java | 212 --------------------- .../src/main/resources/svclogic.properties | 10 +- 10 files changed, 629 insertions(+), 629 deletions(-) create mode 100644 mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java create mode 100644 mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourceActivator.java create mode 100644 mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java create mode 100644 mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java delete mode 100644 mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/ConfigResource.java delete mode 100644 mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/MdsalResourceActivator.java delete mode 100644 mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/OperationalResource.java delete mode 100644 mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/RestService.java (limited to 'mdsal-resource/provider') diff --git a/mdsal-resource/provider/pom.xml b/mdsal-resource/provider/pom.xml index 4ab921a81..5a61d7624 100755 --- a/mdsal-resource/provider/pom.xml +++ b/mdsal-resource/provider/pom.xml @@ -66,10 +66,10 @@ true - org.openecomp.sdnc.sli.resource.mdsal - org.openecomp.sdnc.sli.resource.mdsal.MdsalResourceActivator - org.openecomp.sdnc.sli.resource.mdsal - org.openecomp.sdnc.sli.*,org.osgi.framework.*,org.slf4j.*,com.mysql.jdbc.* + org.onap.ccsdk.sli.adaptors.resource.mdsal + org.onap.ccsdk.sli.adaptors.resource.mdsal.MdsalResourceActivator + org.onap.ccsdk.sli.adaptors.resource.mdsal + org.onap.ccsdk.sli.adaptors.*,org.osgi.framework.*,org.slf4j.*,com.mysql.jdbc.* * true diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java new file mode 100644 index 000000000..9cade887b --- /dev/null +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java @@ -0,0 +1,151 @@ +/*- + * ============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 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(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd) + { + restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML); + } + + @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 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 parms, String prefix, SvcLogicContext ctx) + throws SvcLogicException { + return(QueryStatus.SUCCESS); + } + + + +} diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourceActivator.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourceActivator.java new file mode 100644 index 000000000..004e68227 --- /dev/null +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourceActivator.java @@ -0,0 +1,106 @@ +/*- + * ============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.io.File; +import java.io.FileInputStream; +import java.util.LinkedList; +import java.util.Properties; + +import org.onap.ccsdk.sli.core.sli.ConfigurationException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MdsalResourceActivator implements BundleActivator { + + + + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + + public LinkedList registrations = new LinkedList(); + + private static final Logger LOG = LoggerFactory + .getLogger(MdsalResourceActivator.class); + + @Override + public void start(BundleContext ctx) throws Exception { + + // Read properties + Properties props = new Properties(); + + String propDir = System.getenv(SDNC_CONFIG_DIR); + if (propDir == null) { + + propDir = "/opt/sdnc/data/properties"; + } + String propPath = propDir + "/mdsal-resource.properties"; + + + File propFile = new File(propPath); + + if (!propFile.exists()) { + + throw new ConfigurationException( + "Missing configuration properties file : " + + propFile); + } + try { + + props.load(new FileInputStream(propFile)); + } catch (Exception e) { + throw new ConfigurationException( + "Could not load properties file " + propPath, e); + + } + + 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"); + + // Advertise MD-SAL resource adaptors + SvcLogicResource impl = new ConfigResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd); + + LOG.debug("Registering MdsalResource service "+impl.getClass().getName()); + registrations.add(ctx.registerService(impl.getClass().getName(), impl, null)); + + impl = new OperationalResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd); + + LOG.debug("Registering MdsalResource service "+impl.getClass().getName()); + registrations.add(ctx.registerService(impl.getClass().getName(), impl, null)); + } + + @Override + public void stop(BundleContext ctx) throws Exception { + + for (ServiceRegistration registration : registrations) + { + registration.unregister(); + } + } + +} diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java new file mode 100644 index 000000000..92a7b6be0 --- /dev/null +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java @@ -0,0 +1,151 @@ +/*- + * ============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 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 OperationalResource implements SvcLogicResource { + + private static final Logger LOG = LoggerFactory.getLogger(OperationalResource.class); + + private RestService restService; + + public OperationalResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd) + { + restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML); + + + } + + @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 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 parms, String prefix, SvcLogicContext ctx) + throws SvcLogicException { + return(QueryStatus.SUCCESS); + } + + +} diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java new file mode 100644 index 000000000..2991e6bef --- /dev/null +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java @@ -0,0 +1,212 @@ +/*- + * ============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.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Authenticator; +import java.net.HttpURLConnection; +import java.net.PasswordAuthentication; +import java.net.URL; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSession; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; + + + + +public class RestService { + + private static final Logger LOG = LoggerFactory.getLogger(ConfigResource.class); + + public enum PayloadType { + XML, + JSON + } + + 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()); + } + + } + + private String user; + private String passwd; + private PayloadType payloadType; + + private String protocol; + private String host; + private String port; + + public RestService(String protocol, String host, String port, String user, String passwd, PayloadType payloadType) { + this.protocol = protocol; + this.host = host; + this.port = port; + this.user = user; + this.passwd = passwd; + this.payloadType = payloadType; + } + + private HttpURLConnection getRestConnection(String urlString, String method) throws IOException + { + + URL sdncUrl = new URL(urlString); + Authenticator.setDefault(new SdncAuthenticator(user, passwd)); + + HttpURLConnection conn = (HttpURLConnection) sdncUrl.openConnection(); + + String authStr = user+":"+passwd; + String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); + + conn.addRequestProperty("Authentication", "Basic "+encodedAuthStr); + + conn.setRequestMethod(method); + + if (payloadType == PayloadType.XML) { + conn.setRequestProperty("Content-Type", "application/xml"); + conn.setRequestProperty("Accept", "application/xml"); + } else { + + conn.setRequestProperty("Content-Type", "application/json"); + conn.setRequestProperty("Accept", "application/json"); + } + + conn.setDoInput(true); + conn.setDoOutput(true); + conn.setUseCaches(false); + + return(conn); + + } + + + private Document send(String urlString, byte[] msgBytes, String method) { + Document response = null; + String fullUrl = protocol + "://" + host + ":" + port + "/" + urlString; + LOG.info("Sending REST "+method +" to "+fullUrl); + + if (msgBytes != null) { + LOG.info("Message body:\n"+msgBytes); + } + + try { + HttpURLConnection conn = getRestConnection(fullUrl, method); + + if (conn instanceof HttpsURLConnection) { + HostnameVerifier hostnameVerifier = new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + ((HttpsURLConnection)conn).setHostnameVerifier(hostnameVerifier); + } + + // Write message + if (msgBytes != null) { + conn.setRequestProperty("Content-Length", ""+msgBytes.length); + DataOutputStream outStr = new DataOutputStream(conn.getOutputStream()); + outStr.write(msgBytes); + outStr.close(); + } else { + conn.setRequestProperty("Content-Length", "0"); + } + + + // Read response + BufferedReader respRdr; + + LOG.info("Response: "+conn.getResponseCode()+" "+conn.getResponseMessage()); + + + 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(); + 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")); + } +} diff --git a/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/ConfigResource.java b/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/ConfigResource.java deleted file mode 100644 index 344707f4b..000000000 --- a/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/ConfigResource.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * ============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.openecomp.sdnc.sli.resource.mdsal; - -import java.util.Map; - -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(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd) - { - restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML); - } - - @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 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 parms, String prefix, SvcLogicContext ctx) - throws SvcLogicException { - return(QueryStatus.SUCCESS); - } - - - -} diff --git a/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/MdsalResourceActivator.java b/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/MdsalResourceActivator.java deleted file mode 100644 index 7f6e7fc5b..000000000 --- a/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/MdsalResourceActivator.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============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.openecomp.sdnc.sli.resource.mdsal; - -import java.io.File; -import java.io.FileInputStream; -import java.util.LinkedList; -import java.util.Properties; - -import org.onap.ccsdk.sli.core.sli.ConfigurationException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MdsalResourceActivator implements BundleActivator { - - - - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - - public LinkedList registrations = new LinkedList(); - - private static final Logger LOG = LoggerFactory - .getLogger(MdsalResourceActivator.class); - - @Override - public void start(BundleContext ctx) throws Exception { - - // Read properties - Properties props = new Properties(); - - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - - propDir = "/opt/sdnc/data/properties"; - } - String propPath = propDir + "/mdsal-resource.properties"; - - - File propFile = new File(propPath); - - if (!propFile.exists()) { - - throw new ConfigurationException( - "Missing configuration properties file : " - + propFile); - } - try { - - props.load(new FileInputStream(propFile)); - } catch (Exception e) { - throw new ConfigurationException( - "Could not load properties file " + propPath, e); - - } - - String sdncUser = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-user", "admin"); - String sdncPasswd = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-passwd", "admin"); - String sdncHost = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-host", "localhost"); - String sdncProtocol = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-protocol", "https"); - String sdncPort = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-port", "8443"); - - // Advertise MD-SAL resource adaptors - SvcLogicResource impl = new ConfigResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd); - - LOG.debug("Registering MdsalResource service "+impl.getClass().getName()); - registrations.add(ctx.registerService(impl.getClass().getName(), impl, null)); - - impl = new OperationalResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd); - - LOG.debug("Registering MdsalResource service "+impl.getClass().getName()); - registrations.add(ctx.registerService(impl.getClass().getName(), impl, null)); - } - - @Override - public void stop(BundleContext ctx) throws Exception { - - for (ServiceRegistration registration : registrations) - { - registration.unregister(); - } - } - -} diff --git a/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/OperationalResource.java b/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/OperationalResource.java deleted file mode 100644 index 5d6ee0665..000000000 --- a/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/OperationalResource.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * ============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.openecomp.sdnc.sli.resource.mdsal; - -import java.util.Map; - -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 OperationalResource implements SvcLogicResource { - - private static final Logger LOG = LoggerFactory.getLogger(OperationalResource.class); - - private RestService restService; - - public OperationalResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd) - { - restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML); - - - } - - @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 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 parms, String prefix, SvcLogicContext ctx) - throws SvcLogicException { - return(QueryStatus.SUCCESS); - } - - -} diff --git a/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/RestService.java b/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/RestService.java deleted file mode 100644 index 21e7514b6..000000000 --- a/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/RestService.java +++ /dev/null @@ -1,212 +0,0 @@ -/*- - * ============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.openecomp.sdnc.sli.resource.mdsal; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.Authenticator; -import java.net.HttpURLConnection; -import java.net.PasswordAuthentication; -import java.net.URL; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.apache.commons.codec.binary.Base64; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; - - - - -public class RestService { - - private static final Logger LOG = LoggerFactory.getLogger(ConfigResource.class); - - public enum PayloadType { - XML, - JSON - } - - 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()); - } - - } - - private String user; - private String passwd; - private PayloadType payloadType; - - private String protocol; - private String host; - private String port; - - public RestService(String protocol, String host, String port, String user, String passwd, PayloadType payloadType) { - this.protocol = protocol; - this.host = host; - this.port = port; - this.user = user; - this.passwd = passwd; - this.payloadType = payloadType; - } - - private HttpURLConnection getRestConnection(String urlString, String method) throws IOException - { - - URL sdncUrl = new URL(urlString); - Authenticator.setDefault(new SdncAuthenticator(user, passwd)); - - HttpURLConnection conn = (HttpURLConnection) sdncUrl.openConnection(); - - String authStr = user+":"+passwd; - String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); - - conn.addRequestProperty("Authentication", "Basic "+encodedAuthStr); - - conn.setRequestMethod(method); - - if (payloadType == PayloadType.XML) { - conn.setRequestProperty("Content-Type", "application/xml"); - conn.setRequestProperty("Accept", "application/xml"); - } else { - - conn.setRequestProperty("Content-Type", "application/json"); - conn.setRequestProperty("Accept", "application/json"); - } - - conn.setDoInput(true); - conn.setDoOutput(true); - conn.setUseCaches(false); - - return(conn); - - } - - - private Document send(String urlString, byte[] msgBytes, String method) { - Document response = null; - String fullUrl = protocol + "://" + host + ":" + port + "/" + urlString; - LOG.info("Sending REST "+method +" to "+fullUrl); - - if (msgBytes != null) { - LOG.info("Message body:\n"+msgBytes); - } - - try { - HttpURLConnection conn = getRestConnection(fullUrl, method); - - if (conn instanceof HttpsURLConnection) { - HostnameVerifier hostnameVerifier = new HostnameVerifier() { - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - ((HttpsURLConnection)conn).setHostnameVerifier(hostnameVerifier); - } - - // Write message - if (msgBytes != null) { - conn.setRequestProperty("Content-Length", ""+msgBytes.length); - DataOutputStream outStr = new DataOutputStream(conn.getOutputStream()); - outStr.write(msgBytes); - outStr.close(); - } else { - conn.setRequestProperty("Content-Length", "0"); - } - - - // Read response - BufferedReader respRdr; - - LOG.info("Response: "+conn.getResponseCode()+" "+conn.getResponseMessage()); - - - 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(); - 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")); - } -} diff --git a/mdsal-resource/provider/src/main/resources/svclogic.properties b/mdsal-resource/provider/src/main/resources/svclogic.properties index 887697bdb..0abadc5c8 100644 --- a/mdsal-resource/provider/src/main/resources/svclogic.properties +++ b/mdsal-resource/provider/src/main/resources/svclogic.properties @@ -19,8 +19,8 @@ # ============LICENSE_END========================================================= ### -org.openecomp.sdnc.sli.dbtype = jdbc -org.openecomp.sdnc.sli.jdbc.url = jdbc:mysql://dbhost:3306/sdnctl -org.openecomp.sdnc.sli.jdbc.database = sdnctl -org.openecomp.sdnc.sli.jdbc.user = sdnctl -org.openecomp.sdnc.sli.jdbc.password = gamma +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 -- cgit 1.2.3-korg