diff options
Diffstat (limited to 'appc-outbound/appc-network-inventory-client/provider/src/main')
15 files changed, 959 insertions, 0 deletions
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/InstarClientActivator.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/InstarClientActivator.java new file mode 100644 index 000000000..1f8f037b0 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/InstarClientActivator.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar; + +import java.util.LinkedList; +import java.util.List; + +import org.openecomp.appc.instar.node.InstarClientNode; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class InstarClientActivator implements BundleActivator{ + + private List<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>(); + private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarClientActivator.class); + + @Override + public void start(BundleContext ctx) throws Exception + { + + InstarClientNode instarClientNode = new InstarClientNode(); + log.info("Registering service "+ instarClientNode.getClass().getName()); + registrations.add(ctx.registerService(instarClientNode.getClass().getName(), instarClientNode, null)); + log.info("Registering service sccessful for "+ instarClientNode.getClass().getName()); + + } + @Override + public void stop(BundleContext arg0) throws Exception + { + for (ServiceRegistration registration: registrations) + { + registration.unregister(); + registration = null; + } + + } + +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/Dme2Client.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/Dme2Client.java new file mode 100644 index 000000000..a0a57db54 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/Dme2Client.java @@ -0,0 +1,184 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.dme2client; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URI; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Properties; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; + +import org.apache.commons.io.IOUtils; +import org.openecomp.appc.instar.utils.InstarClientConstant; + + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; + + +public class Dme2Client { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(Dme2Client.class); + private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; + //DME2Client client = null; + Properties props = new Properties(); + String operationName ; + String appendContext; + + public Dme2Client(String optName, String subCtxt, HashMap<String, String> data) throws Exception{ + log.info("Setting Properties for DME2 Client for INSTAR connection"); + this.operationName=optName; + this.appendContext = data.get(subCtxt); + String propDir = System.getenv(SDNC_CONFIG_DIR_VAR); + if (propDir == null) + throw new Exception(" Cannot find Property file -" + SDNC_CONFIG_DIR_VAR); + String propFile = propDir + InstarClientConstant.OUTBOUND_PROPERTIES; + InputStream propStream = new FileInputStream(propFile); + try + { + props.load(propStream); + } + catch (Exception e) + { + throw new Exception("Could not load properties file " + propFile, e); + } + finally + { + try + { + propStream.close(); + } + catch (Exception e) + { + log.warn("Could not close FileInputStream", e); + } + } + } + + public ClientResponse sendtoInstar() throws Exception { + + log.info("Called Send with operation Name=" + this.operationName + "and = " + props.getProperty(operationName+InstarClientConstant.BASE_URL)); + String resourceUri = props.getProperty(operationName+InstarClientConstant.BASE_URL)+ + props.getProperty(operationName + InstarClientConstant.URL_SUFFIX) + + props.getProperty(operationName + InstarClientConstant.SUB_CONTEXT)+ appendContext ; + + log.info("DME Endpoint URI:" + resourceUri); + Client client = null; + WebResource webResource = null; + ClientResponse clientResponse = null; + String authorization = props.getProperty("authorization"); + String requestDataType = "application/json"; + String responseDataType= MediaType.APPLICATION_JSON; + String methodType = props.getProperty("getIpAddressByVnf_method"); + String request = ""; + String userId=props.getProperty("MechID"); + String password=props.getProperty("MechPass"); + + log.info("authorization = " + authorization + "methodType= " + methodType); + try{ + DefaultClientConfig defaultClientConfig = new DefaultClientConfig(); + System.setProperty("jsse.enableSNIExtension", "false"); + SSLContext sslContext = null; + SecureRestClientTrustManager secureRestClientTrustManager = new SecureRestClientTrustManager(); + sslContext = SSLContext.getInstance("SSL"); + sslContext.init(null, new javax.net.ssl.TrustManager[] { secureRestClientTrustManager }, null); + defaultClientConfig.getProperties().put( + com.sun.jersey.client.urlconnection.HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, + new com.sun.jersey.client.urlconnection.HTTPSProperties(getHostnameVerifier(), sslContext)); + client = Client.create(defaultClientConfig); + client.addFilter(new HTTPBasicAuthFilter(userId, password)); + + webResource = client.resource(new URI(resourceUri)); + webResource.setProperty("Content-Type", "application/json;charset=UTF-8"); + + if(HttpMethod.GET.equalsIgnoreCase(methodType)){ + clientResponse = webResource.accept(responseDataType).get(ClientResponse.class); + }else if(HttpMethod.POST.equalsIgnoreCase(methodType)){ + clientResponse = webResource.type(requestDataType).post(ClientResponse.class, request); + }else if(HttpMethod.PUT.equalsIgnoreCase(methodType)){ + clientResponse = webResource.type(requestDataType).put(ClientResponse.class,request); + }else if(HttpMethod.DELETE.equalsIgnoreCase(methodType)){ + clientResponse = webResource.delete(ClientResponse.class); + } + + return clientResponse; + + }catch (Exception e) { + log.info("failed in RESTCONT Action ("+methodType+") for the resource " + resourceUri + ", falut message :"+e.getMessage()); + throw new Exception("Error While gettting Data from INSTAR" + e.getMessage()); + } + finally { + // clean up. + webResource = null; + if(client != null){ + client.destroy(); + client = null; + } + } + + + } + + public String send() { + String response = null; + try{ + + if(props !=null && + props.getProperty(InstarClientConstant.MOCK_INSTAR) != null && + props.getProperty(InstarClientConstant.MOCK_INSTAR).equalsIgnoreCase("true")) + return IOUtils.toString(Dme2Client.class.getClassLoader().getResourceAsStream("/tmp/sampleResponse"), Charset.defaultCharset()); + + ClientResponse clientResponse = sendtoInstar(); + if(clientResponse != null){ + response = clientResponse.getEntity(String.class); + log.info(clientResponse.getStatus() + " Status, Response :" + response); + + } + } catch (Exception t) { + t.printStackTrace(); + } + return response; + } + + private HostnameVerifier getHostnameVerifier() { + return new HostnameVerifier() { + @Override + public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { + return true; + } + }; + } + + +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/SecureRestClientTrustManager.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/SecureRestClientTrustManager.java new file mode 100644 index 000000000..21e313eaf --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/SecureRestClientTrustManager.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.dme2client; + +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +import javax.net.ssl.X509TrustManager; + + +public class SecureRestClientTrustManager implements X509TrustManager { + + @Override + public void checkClientTrusted(X509Certificate[] arg0, String arg1) + throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate[] arg0, String arg1) + throws CertificateException { + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + + public boolean isClientTrusted(X509Certificate[] arg0) { + return true; + } + + public boolean isServerTrusted(X509Certificate[] arg0) { + return true; + } + +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java new file mode 100644 index 000000000..3292253da --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.interfaceImpl; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.openecomp.appc.instar.interfaces.ResponseHandlerInterface; +import org.openecomp.appc.instar.utils.InstarClientConstant; +import org.openecomp.sdnc.config.params.data.ResponseKey; +import org.openecomp.sdnc.sli.SvcLogicContext; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class InstarResponseHandlerImpl implements ResponseHandlerInterface { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarResponseHandlerImpl.class); + + ResponseKey resKey = null; + SvcLogicContext ctxt = null; + + public InstarResponseHandlerImpl(ResponseKey filterKeys, SvcLogicContext context) { + this.resKey = filterKeys; + this.ctxt = context; + + } + + @Override + public Object processResponse(String instarResponse, String instarKey) { + String fn = " InstarResponseHandlerImpl.processResponse "; + log.info(fn + " Instar Response :" + instarResponse); + + JSONObject instarKeyValues; + + log.info("Instar Data in Context : "+ ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES)); + if(ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES) != null){ + instarKeyValues = new JSONObject(ctxt.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES)); + log.info("Instar data already exsits : " + instarKeyValues.toString()); + } + else + instarKeyValues = new JSONObject(); + JSONArray instarResponses = new JSONObject(instarResponse).getJSONArray(InstarClientConstant.INSTAR_RESPONSE_BLOCK_NAME); + for (int i = 0; i < instarResponses.length(); i++){ + JSONObject res = instarResponses.getJSONObject(i); + log.info(fn + "Instar Block :" + i + " Values :" + res.toString()); + log.info(fn + "Appc Filter Key :" + ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue()); + + if(res.getString(InstarClientConstant.FDQN) != null && + res.getString(InstarClientConstant.FDQN).equalsIgnoreCase(ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue())){ + if(resKey.getFieldKeyName().equals(InstarClientConstant.V4_ADDRESS)) + instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_ADDRESS)); + else if(resKey.getFieldKeyName().equals(InstarClientConstant.V6_ADDRESS)) + instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_ADDRESS)); + break; + } + } + log.info(fn + "Instar KeyValues :" + instarKeyValues); + ctxt.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, instarKeyValues.toString()); + + + return instarKeyValues; + } + +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarRestClientImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarRestClientImpl.java new file mode 100644 index 000000000..e727ce10d --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarRestClientImpl.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.interfaceImpl; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.HashMap; + +import org.apache.commons.io.IOUtils; +import org.openecomp.appc.instar.dme2client.Dme2Client; +import org.openecomp.appc.instar.interfaces.RestClientInterface; +import org.openecomp.appc.instar.utils.InstarClientConstant; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class InstarRestClientImpl implements RestClientInterface { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarRestClientImpl.class); + HashMap<String, String> requestData = null; + Dme2Client dme2Client; + + public InstarRestClientImpl(HashMap<String, String> instarRequestData) { + + this.requestData = instarRequestData; + } + + @Override + public String sendRequest(String operation) throws Exception { + + String instarResponse = null; + try { + if(operation !=null && operation.equalsIgnoreCase(InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME)){ + dme2Client = new Dme2Client(operation, InstarClientConstant.VNF_NAME, requestData); + } + instarResponse = dme2Client.send(); + log.info("Resposne in InstarRestClientImpl = " + instarResponse); + if(instarResponse == null || instarResponse.length() < 0) + throw new Exception ("No Data received from Instar for this call " + operation); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + return instarResponse; + } + + + +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java new file mode 100644 index 000000000..2d94331aa --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.interfaceImpl; + +import java.util.HashMap; +import java.util.List; + +import org.openecomp.appc.instar.interfaces.ResponseHandlerInterface; +import org.openecomp.appc.instar.interfaces.RestClientInterface; +import org.openecomp.appc.instar.interfaces.RuleHandlerInterface; +import org.openecomp.appc.instar.node.InstarClientNode; +import org.openecomp.appc.instar.utils.InstarClientConstant; +import org.openecomp.sdnc.config.params.data.Parameter; +import org.openecomp.sdnc.config.params.data.ResponseKey; +import org.openecomp.sdnc.sli.SvcLogicContext; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class InterfaceIpAddressImpl implements RuleHandlerInterface { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(InterfaceIpAddressImpl.class); + private Parameter parameters; + private SvcLogicContext context; + + public InterfaceIpAddressImpl(Parameter params, SvcLogicContext ctx) { + this.parameters = params; + this.context = ctx; + } + + @Override + public void processRule() throws Exception { + + String fn = "InterfaceIpAddressHandler.processRule"; + log.info(fn + "Processing rule :" + parameters.getRuleType()); + String operationName ; + + RestClientInterface restClient = null; + ResponseHandlerInterface responseHandler = null; + + List<ResponseKey> responseKeyList = parameters.getResponseKeys(); + if(responseKeyList != null && responseKeyList.size() > 0){ + for(ResponseKey filterKeys : responseKeyList){ + //response.setUniqueKeyValue(response.getUniqueKeyValue()+ context.getAttribute(InstarClientConstant.VNF_NAME)); + switch(parameters.getSource()){ + case InstarClientConstant.SOURCE_SYSTEM_INSTAR: + restClient = new InstarRestClientImpl(createInstarRequestData(context)); + responseHandler = new InstarResponseHandlerImpl(filterKeys, context ); + operationName = "getIpAddressByVnf"; + break; + default: + throw new Exception("No Client registered for : " + parameters.getSource()); + + } + responseHandler.processResponse(restClient.sendRequest(operationName),parameters.getName() ); + } + } + else + { + throw new Exception("NO response Keys set for : " + parameters.getRuleType()); + } + } + + private HashMap<String, String> createInstarRequestData(SvcLogicContext ctxt) { + HashMap<String, String> requestParams = new HashMap<String, String>(); + requestParams.put(InstarClientConstant.VNF_NAME, ctxt.getAttribute(InstarClientConstant.VNF_NAME)); + return requestParams; + } +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/ResponseHandlerInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/ResponseHandlerInterface.java new file mode 100644 index 000000000..816bbdb5d --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/ResponseHandlerInterface.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.interfaces; + +public interface ResponseHandlerInterface { + + public Object processResponse(String response, String instarKey); + +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RestClientInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RestClientInterface.java new file mode 100644 index 000000000..448429163 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RestClientInterface.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.interfaces; + +public interface RestClientInterface { + + + public String sendRequest(String operation) throws Exception; + +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RuleHandlerInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RuleHandlerInterface.java new file mode 100644 index 000000000..ad13c96e0 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RuleHandlerInterface.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.interfaces; + + +public interface RuleHandlerInterface { + + public void processRule() throws Exception; + +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/node/InstarClientNode.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/node/InstarClientNode.java new file mode 100644 index 000000000..17ce64422 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/node/InstarClientNode.java @@ -0,0 +1,135 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.node; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.openecomp.appc.instar.interfaceImpl.InstarRestClientImpl; +import org.openecomp.appc.instar.interfaceImpl.InterfaceIpAddressImpl; +import org.openecomp.appc.instar.interfaces.RestClientInterface; +import org.openecomp.appc.instar.interfaces.RuleHandlerInterface; +import org.openecomp.appc.instar.utils.InstarClientConstant; +import org.openecomp.sdnc.config.params.data.Parameter; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicException; +import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; + +public class InstarClientNode implements SvcLogicJavaPlugin +{ + private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarClientNode.class); + + public void getInstarInfo(Map<String, String> inParams, SvcLogicContext ctx) + throws SvcLogicException{ + log.info("Received getInstarInfo call with params : " + inParams); + String responsePrefix = (String)inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX); + try + { + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : ""; + String [] instarKeys = getInstarKeys(inParams.get(InstarClientConstant.INSTAR_KEYS)); + for (String instarKey : instarKeys){ + log.info("Processing Key : " + instarKey); + log.info("Searching key for : " + "INSTAR." + instarKey); + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + RuleHandlerInterface handler = null; + log.info("Received Context : " + ctx.getAttribute("INSTAR." + instarKey)); + Parameter params = mapper.readValue(ctx.getAttribute(InstarClientConstant.SOURCE_SYSTEM_INSTAR + "." + instarKey), Parameter.class); + + log.info("Processing rule Type : " + params.getRuleType()); + switch(params.getRuleType()){ + case InstarClientConstant.INTERFACE_IP_ADDRESS: + handler = new InterfaceIpAddressImpl(params, ctx); + break; + default: + throw new Exception("No Rule Defined to process :" + params.getRuleType()); + } + handler.processRule(); + + } + log.info("responsePrefix =" + responsePrefix); + ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES)); + ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_SUCCESS); + ctx.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, null); + } + catch (Exception e) + { + ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed processing Instar request" + e.getMessage()); + e.printStackTrace(); + throw new SvcLogicException(e.getMessage()); + } + } + private static String[] getInstarKeys(String keyString) { + String fn = "InstarClientNode.getInstarKeys"; + System.out.println("Received instar Key String as :" + keyString); + + keyString = keyString.replace("[",""); + keyString = keyString.replace("]", ""); + keyString = keyString.replace("\"", ""); + if(keyString.contains(",")) + { + String[] keys = keyString.split(","); + return keys; + } + else{ + String[] keys = {keyString}; + return keys; + } + } + public void getInstarData(Map<String, String> inParams, SvcLogicContext ctx) + throws SvcLogicException{ + log.info("Received getInstarData call with params : " + inParams); + String responsePrefix = (String)inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX); + try + { + HashMap<String, String> input = new HashMap<String, String>(); + input.putAll(inParams); + RestClientInterface rcINterface = new InstarRestClientImpl(input); + String response = rcINterface.sendRequest(inParams.get("operationName")); + + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : ""; + ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_SUCCESS); + ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, response); + + } + catch (Exception e) + { + ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, InstarClientConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed processing Instar request" + e.getMessage()); + e.printStackTrace(); + throw new SvcLogicException(e.getMessage()); + } + } + +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/utils/InstarClientConstant.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/utils/InstarClientConstant.java new file mode 100644 index 000000000..790651f12 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/utils/InstarClientConstant.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.instar.utils; + +public class InstarClientConstant +{ + public static String INPUT_PARAM_RESPONSE_PRIFIX = "responsePrefix"; + public static String OUTPUT_PARAM_STATUS = "status"; + public static String OUTPUT_PARAM_ERROR_MESSAGE = "error-message"; + public static String OUTPUT_STATUS_SUCCESS = "success"; + public static String OUTPUT_STATUS_FAILURE = "failure"; + + + + public static final String INSTAR_KEYS = "instarKeys"; + + public static final String INTERFACE_IP_ADDRESS = "interface-ip-address"; + public static final String SOURCE_SYSTEM_INSTAR = "INSTAR"; + public static final String VNF_TYPE = "vnf-type"; + public static final String ADDRESSFDQN = "addressfqdn"; + public static final String VNF_NAME = "vnf-name"; + public static final String INSTAR_KEY_VALUES = "INSTAR-KEY-VALUES"; + public static final String INSTAR_RESPONSE_BLOCK_NAME = "vnfConfigurationParameterDetails"; + public static final String FDQN = "fqdn"; + + + public static final String MOCK_INSTAR="mock_instar"; + public static final String AFT_LATITUDE="aft_latitude"; + public static final String AFT_LONGITUDE="aft_latitude"; + public static final String AFT_ENVIRONMENT="aft_environment"; + public static final String SCLD_PLATFORM="scld_platform"; + public static final String AUTHORIZATION="authorization"; + public static final String DME2_CLIENT_TIMEOUTMS="dme2_client_timeoutms"; + public static final String DME2_CLIENT_SENDANDWAIT="dme2_client_sendandwait"; + public static final String BASE_URL="_base_url"; + public static final String HTTP_HEADERS="_http_headers"; + + public static final String V6_ADDRESS="ipaddress-v6"; + public static final String INSTAR_V6_ADDRESS="v6IPAddress"; + + + public static final String V4_ADDRESS="ipaddress-v4"; + public static final String INSTAR_V4_ADDRESS="v4IPAddress"; + + public static final String SUB_CONTEXT="_sub_context"; + public static final String URL_SUFFIX="_suffix"; + public static final String VERSION="_version"; + public static final String ENV_CONTEXT="_env_context"; + public static final String ROUTEOFFER="_routeoffer"; + public static final String APPC_PROPERTIES = "appc.properties"; + public static final String METHOD="_method"; + public static final String OPERATION_GET_IPADDRESS_BY_VNF_NAME = "getIpAddressByVnf"; + + public static final String OUTBOUND_PROPERTIES= "/outbound.properties"; + + public static String CONTENT_TYPE = "application/json"; + public static String RETURNED_RESPONSE_TYPE = "application/json"; + +} + diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/resources/adaptor.properties b/appc-outbound/appc-network-inventory-client/provider/src/main/resources/adaptor.properties new file mode 100644 index 000000000..205a8f884 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/resources/adaptor.properties @@ -0,0 +1,29 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= +### + +adaptorName= +vSphere.url= +vSphere.user= +vSphere.passwd= +org.xml.sax.driver=org.apache.xerces.parsers.SAXParser diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/resources/outbound.properties b/appc-outbound/appc-network-inventory-client/provider/src/main/resources/outbound.properties new file mode 100644 index 000000000..ede337681 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/resources/outbound.properties @@ -0,0 +1,39 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= +### + +MechID= +MechPass= +SCLD_PLATFORM=NON-PROD +dme2_client_timeoutms=100000 +dme2_client_sendandwait=1000000 +DME2.DEBUG=true + +#appc-instar service base context +getIpAddressByVnf_base_url= +getIpAddressByVnf_sub_context=vnfs/ +getIpAddressByVnf_suffix=vnfconfigparameters/ +getIpAddressByVnf_method=GET +getIpAddressByVnf_http_headers=X-CSI-MessageId=123 + + diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleInstarResponse b/appc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleInstarResponse new file mode 100755 index 000000000..7433aea62 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleInstarResponse @@ -0,0 +1,24 @@ +{
+"vnfConfigurationParameterDetails": [
+ {
+ "addressfqdn": "XXXXXX",
+ "ipaddress-purpose": "vNIC1/Data NIC",
+ "ipaddress-v4": "00.00.00.00",
+ "v4-subnet": "00.00.00.00/25",
+ "v4-default-gateway": "00.00.00.00",
+ "ipaddress-v6": "2001:1890:FC:28::1:2",
+ "v6-subnet": "2001:1890:FC:28::/64",
+ "v6-default-gateway": "2001:1890:FC:28::3"
+ },
+ {
+ "addressfqdn": "XXXXXX",
+ "ipaddress-purpose": "vNIC1/Data NIC",
+ "ipaddress-v4": "00.00.00.00",
+ "v4-subnet": "00.00.00.00/25",
+ "v4-default-gateway": "00.00.00.00",
+ "ipaddress-v6": "2001:1890:FC:28::1:4",
+ "v6-subnet": "2001:1890:FC:28::/64",
+ "v6-default-gateway": "2001:1890:FC:28::3"
+ }
+ ]
+}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleKeyContents b/appc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleKeyContents new file mode 100755 index 000000000..90e3ec789 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleKeyContents @@ -0,0 +1 @@ +{"name":"LOCAL_ACCESS_IP_ADDR","description":"this is the node0 tacplus server IP address","type":"ipv4_address","required":true,"source":"INSTAR","rule-type":"interface-ip-address","default":null,"request-keys":null,"response-keys":[{"unique-key-name":"addressfqdn","unique-key-value":"00000000000000","field-key-name":"ipaddress-v4"}]}
\ No newline at end of file |