From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../onap/appc/instar/InstarClientActivator.java | 64 +++++++ .../onap/appc/instar/dme2client/Dme2Client.java | 184 +++++++++++++++++++++ .../dme2client/SecureRestClientTrustManager.java | 58 +++++++ .../interfaceImpl/InstarResponseHandlerImpl.java | 86 ++++++++++ .../instar/interfaceImpl/InstarRestClientImpl.java | 71 ++++++++ .../interfaceImpl/InterfaceIpAddressImpl.java | 91 ++++++++++ .../interfaces/ResponseHandlerInterface.java | 31 ++++ .../instar/interfaces/RestClientInterface.java | 32 ++++ .../instar/interfaces/RuleHandlerInterface.java | 32 ++++ .../onap/appc/instar/node/InstarClientNode.java | 135 +++++++++++++++ .../appc/instar/utils/InstarClientConstant.java | 82 +++++++++ 11 files changed, 866 insertions(+) create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/InstarClientActivator.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/SecureRestClientTrustManager.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarRestClientImpl.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/ResponseHandlerInterface.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RestClientInterface.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RuleHandlerInterface.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/node/InstarClientNode.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/utils/InstarClientConstant.java (limited to 'appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap') diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/InstarClientActivator.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/InstarClientActivator.java new file mode 100644 index 000000000..09021daa4 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.appc.instar; + +import java.util.LinkedList; +import java.util.List; + +import org.onap.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 registrations = new LinkedList(); + 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/onap/appc/instar/dme2client/Dme2Client.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java new file mode 100644 index 000000000..fa22a751f --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.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.onap.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 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) { + log.error("Error in Dme2Client for send() method while sending response:" ,t); + } + 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/onap/appc/instar/dme2client/SecureRestClientTrustManager.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/SecureRestClientTrustManager.java new file mode 100644 index 000000000..86c2d99b3 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.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/onap/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java new file mode 100644 index 000000000..08df6f02e --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.appc.instar.interfaceImpl; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.appc.instar.interfaces.ResponseHandlerInterface; +import org.onap.appc.instar.utils.InstarClientConstant; +import org.openecomp.sdnc.config.params.data.ResponseKey; +import org.onap.ccsdk.sli.core.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/onap/appc/instar/interfaceImpl/InstarRestClientImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarRestClientImpl.java new file mode 100644 index 000000000..db43d9c41 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.appc.instar.interfaceImpl; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.HashMap; + +import org.apache.commons.io.IOUtils; +import org.onap.appc.instar.dme2client.Dme2Client; +import org.onap.appc.instar.interfaces.RestClientInterface; +import org.onap.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 requestData = null; + Dme2Client dme2Client; + + public InstarRestClientImpl(HashMap 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/onap/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java new file mode 100644 index 000000000..cc2eeaa07 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.appc.instar.interfaceImpl; + +import java.util.HashMap; +import java.util.List; + +import org.onap.appc.instar.interfaces.ResponseHandlerInterface; +import org.onap.appc.instar.interfaces.RestClientInterface; +import org.onap.appc.instar.interfaces.RuleHandlerInterface; +import org.onap.appc.instar.node.InstarClientNode; +import org.onap.appc.instar.utils.InstarClientConstant; +import org.openecomp.sdnc.config.params.data.Parameter; +import org.openecomp.sdnc.config.params.data.ResponseKey; +import org.onap.ccsdk.sli.core.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 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 createInstarRequestData(SvcLogicContext ctxt) { + HashMap requestParams = new HashMap(); + 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/onap/appc/instar/interfaces/ResponseHandlerInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/ResponseHandlerInterface.java new file mode 100644 index 000000000..8211967b0 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.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/onap/appc/instar/interfaces/RestClientInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RestClientInterface.java new file mode 100644 index 000000000..bf6c5b34d --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.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/onap/appc/instar/interfaces/RuleHandlerInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RuleHandlerInterface.java new file mode 100644 index 000000000..86f31d2fa --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.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/onap/appc/instar/node/InstarClientNode.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/node/InstarClientNode.java new file mode 100644 index 000000000..1d343c668 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.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.onap.appc.instar.interfaceImpl.InstarRestClientImpl; +import org.onap.appc.instar.interfaceImpl.InterfaceIpAddressImpl; +import org.onap.appc.instar.interfaces.RestClientInterface; +import org.onap.appc.instar.interfaces.RuleHandlerInterface; +import org.onap.appc.instar.utils.InstarClientConstant; +import org.openecomp.sdnc.config.params.data.Parameter; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +public class InstarClientNode implements SvcLogicJavaPlugin +{ + private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarClientNode.class); + + public void getInstarInfo(Map 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 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 input = new HashMap(); + 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/onap/appc/instar/utils/InstarClientConstant.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/utils/InstarClientConstant.java new file mode 100644 index 000000000..30e59db22 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/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.onap.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"; + +} + -- cgit 1.2.3-korg