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 +++++++++ .../appc/instar/InstarClientActivator.java | 64 ------- .../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 ---- .../appc/instar/node/InstarClientNode.java | 135 --------------- .../appc/instar/utils/InstarClientConstant.java | 82 --------- .../TestInstarResponseHandlerImpl.java | 78 +++++++++ .../interfaceImpl/TestInstarRestClientImpl.java | 43 +++++ .../interfaceImpl/TestInterfaceIpAddressImpl.java | 65 ++++++++ .../org/onap/appc/instar/node/TestDme2Client.java | 46 ++++++ .../appc/instar/node/TestInstarClientNode.java | 83 ++++++++++ .../node/TestSecureRestClientTrustManager.java | 43 +++++ .../TestInstarResponseHandlerImpl.java | 78 --------- .../interfaceImpl/TestInstarRestClientImpl.java | 43 ----- .../interfaceImpl/TestInterfaceIpAddressImpl.java | 65 -------- .../openecomp/appc/instar/node/TestDme2Client.java | 46 ------ .../appc/instar/node/TestInstarClientNode.java | 83 ---------- .../node/TestSecureRestClientTrustManager.java | 43 ----- 34 files changed, 1224 insertions(+), 1224 deletions(-) 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 delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/InstarClientActivator.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/Dme2Client.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/SecureRestClientTrustManager.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarRestClientImpl.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/ResponseHandlerInterface.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RestClientInterface.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RuleHandlerInterface.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/node/InstarClientNode.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/utils/InstarClientConstant.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInstarResponseHandlerImpl.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInstarRestClientImpl.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInterfaceIpAddressImpl.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestDme2Client.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientNode.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestSecureRestClientTrustManager.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInstarResponseHandlerImpl.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInstarRestClientImpl.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInterfaceIpAddressImpl.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestDme2Client.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestInstarClientNode.java delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestSecureRestClientTrustManager.java (limited to 'appc-outbound/appc-network-inventory-client/provider/src') 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"; + +} + 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 deleted file mode 100644 index 09021daa4..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/InstarClientActivator.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/dme2client/Dme2Client.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/Dme2Client.java deleted file mode 100644 index fa22a751f..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/Dme2Client.java +++ /dev/null @@ -1,184 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/dme2client/SecureRestClientTrustManager.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/SecureRestClientTrustManager.java deleted file mode 100644 index 86c2d99b3..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/dme2client/SecureRestClientTrustManager.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java deleted file mode 100644 index 08df6f02e..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/interfaceImpl/InstarRestClientImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarRestClientImpl.java deleted file mode 100644 index db43d9c41..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InstarRestClientImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java deleted file mode 100644 index cc2eeaa07..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/interfaces/ResponseHandlerInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/ResponseHandlerInterface.java deleted file mode 100644 index 8211967b0..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/ResponseHandlerInterface.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/interfaces/RestClientInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RestClientInterface.java deleted file mode 100644 index bf6c5b34d..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RestClientInterface.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/interfaces/RuleHandlerInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RuleHandlerInterface.java deleted file mode 100644 index 86f31d2fa..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/interfaces/RuleHandlerInterface.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/node/InstarClientNode.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/node/InstarClientNode.java deleted file mode 100644 index 1d343c668..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/node/InstarClientNode.java +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * ============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/openecomp/appc/instar/utils/InstarClientConstant.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/utils/InstarClientConstant.java deleted file mode 100644 index 30e59db22..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/openecomp/appc/instar/utils/InstarClientConstant.java +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * ============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"; - -} - diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInstarResponseHandlerImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInstarResponseHandlerImpl.java new file mode 100644 index 000000000..1d0db357a --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInstarResponseHandlerImpl.java @@ -0,0 +1,78 @@ +/*- + * ============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.junit.Test; +import org.openecomp.sdnc.config.params.data.ResponseKey; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class TestInstarResponseHandlerImpl { + + @Test + public void testProcessResponseForIpv4(){ + ResponseKey resKey = new ResponseKey(); + resKey.setUniqueKeyValue("x"); + SvcLogicContext svc = new SvcLogicContext(); + svc.setAttribute("vnf-name", "fqdn"); + resKey.setFieldKeyName("ipaddress-v4"); + String instarKey = "key"; + String instarRes ="{\"vnfConfigurationParameterDetails\":" + + "[{\"fqdn\":\"fqdnx\",\"v4IPAddress\":\"value2\"}]}"; + InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc); + impl.processResponse(instarRes, instarKey); + } + + @Test + public void testProcessResponseForIpv6(){ + ResponseKey resKey = new ResponseKey(); + resKey.setUniqueKeyValue("x"); + SvcLogicContext svc = new SvcLogicContext(); + svc.setAttribute("vnf-name", "fqdn"); + resKey.setFieldKeyName("ipaddress-v6"); + String instarKey = "key"; + String instarRes ="{\"vnfConfigurationParameterDetails\":" + + "[{\"fqdn\":\"fqdnx\",\"v6IPAddress\":\"value2\"}]}"; + InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc); + impl.processResponse(instarRes, instarKey); + } + + @Test + public void testProcessResponseInstarKeyValues(){ + + ResponseKey resKey = new ResponseKey(); + resKey.setUniqueKeyValue("x"); + String json ="{\"vnfConfigurationParameterDetails\":" + + "[{\"fqdn\":\"fqdnx\",\"v4IPAddress\":\"value2\"}]}"; + SvcLogicContext svc = new SvcLogicContext(); + svc.setAttribute("vnf-name", "fqdn"); + svc.setAttribute("INSTAR-KEY-VALUES", json); + resKey.setFieldKeyName("ipaddress-v6"); + String instarKey = "key"; + String instarRes ="{\"vnfConfigurationParameterDetails\":" + + "[{\"fqdn\":\"fqdnx\",\"v6IPAddress\":\"value2\"}]}"; + InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc); + impl.processResponse(instarRes, instarKey); + } +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInstarRestClientImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInstarRestClientImpl.java new file mode 100644 index 000000000..cf2427dc1 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInstarRestClientImpl.java @@ -0,0 +1,43 @@ +/*- + * ============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 org.junit.Test; +import org.mockito.Mockito; +import org.onap.appc.instar.dme2client.Dme2Client; + +public class TestInstarRestClientImpl { + + @Test(expected=Exception.class) + public void testSendRequest() throws Exception{ + HashMap map = new HashMap<>(); + map.put("key", "value"); + Dme2Client client = Mockito.mock(Dme2Client.class); + Mockito.when(client.send()).thenReturn("test"); + InstarRestClientImpl imp = new InstarRestClientImpl(map); + imp.sendRequest("getIpAddressByVnf"); + } +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInterfaceIpAddressImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInterfaceIpAddressImpl.java new file mode 100644 index 000000000..f29bebd7e --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/interfaceImpl/TestInterfaceIpAddressImpl.java @@ -0,0 +1,65 @@ +/*- + * ============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.ArrayList; +import java.util.List; +import org.junit.Test; +import org.openecomp.sdnc.config.params.data.Parameter; +import org.openecomp.sdnc.config.params.data.ResponseKey; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class TestInterfaceIpAddressImpl { + + @Test(expected=Exception.class) + public void testProcessRuleException1() throws Exception{ + Parameter param = new Parameter(); + param.setRuleType("test"); + param.setName("test"); + param.setSource("INSTAR"); + SvcLogicContext svc = new SvcLogicContext(); + svc.setAttribute("vnf-name", "test"); + InterfaceIpAddressImpl impl = new InterfaceIpAddressImpl(param,svc); + impl.processRule(); + } + + @Test(expected=Exception.class) + public void testProcessRuleException2() throws Exception{ + List list = new ArrayList<>(); + list.add(new ResponseKey()); + list.add(new ResponseKey()); + Parameter param = new Parameter(); + param.setResponseKeys(list); + param.setRuleType("test"); + param.setName("test"); + param.setSource("INSTAR"); + SvcLogicContext svc = new SvcLogicContext(); + svc.setAttribute("vnf-name", "test"); + InterfaceIpAddressImpl impl = new InterfaceIpAddressImpl(param,svc); + impl.processRule(); + param.setSource("INSTAR1"); + impl.processRule(); + } +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestDme2Client.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestDme2Client.java new file mode 100644 index 000000000..8e87ffe35 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestDme2Client.java @@ -0,0 +1,46 @@ +/*- + * ============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 java.util.HashMap; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.appc.instar.dme2client.Dme2Client; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class TestDme2Client { + + @Test(expected=Exception.class) + public void testSendtoInstar() throws Exception{ + + HashMap data = new HashMap(); + data.put("subtext","value"); + PowerMockito.mockStatic(System.class); + PowerMockito.when((System.getenv("test"))).thenReturn("test"); + Dme2Client dme2 = new Dme2Client("opt","subtext",data); + } +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientNode.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientNode.java new file mode 100644 index 000000000..285662f75 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientNode.java @@ -0,0 +1,83 @@ +/*- + * ============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 java.net.URI; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.ws.rs.HttpMethod; + +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Test; +import org.onap.appc.instar.dme2client.SecureRestClientTrustManager; +import org.onap.appc.instar.utils.InstarClientConstant; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +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 TestInstarClientNode { + + //ONAP Migration + + @Test(expected=Exception.class) + public void testInstarClientNode() throws Exception { + + SvcLogicContext ctx = new SvcLogicContext(); + String key_conetent = IOUtils.toString(TestInstarClientNode.class.getClassLoader().getResourceAsStream("templates/sampleKeyContents"), Charset.defaultCharset()); + Map inParams = new HashMap(); + inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST"); + inParams.put(InstarClientConstant.INSTAR_KEYS, "LOCAL_ACCESS_IP_ADDR"); + inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME); + ctx.setAttribute("INSTAR.LOCAL_ACCESS_IP_ADDR", key_conetent); + ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST"); + ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v"); + InstarClientNode icn = new InstarClientNode(); + icn.getInstarInfo(inParams, ctx); + String address = (new JSONObject(ctx.getAttribute("TEST." + InstarClientConstant.INSTAR_KEY_VALUES))).getString("LOCAL_ACCESS_IP_ADDR"); + } + @Test(expected=Exception.class) + public void testInstarData() throws Exception { + + InstarClientNode inNode = new InstarClientNode(); + SvcLogicContext ctx = new SvcLogicContext (); + Map inParams = new HashMap(); + + inParams.put(InstarClientConstant.VNF_NAME, "basx0003v"); + inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME); + inNode.getInstarData(inParams, ctx); + + + } +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestSecureRestClientTrustManager.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestSecureRestClientTrustManager.java new file mode 100644 index 000000000..b18673a40 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestSecureRestClientTrustManager.java @@ -0,0 +1,43 @@ +/*- + * ============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 java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.appc.instar.dme2client.SecureRestClientTrustManager; + +public class TestSecureRestClientTrustManager { + + @Test + public void testSecureRestClient() throws CertificateException{ + X509Certificate[] arg0 = new X509Certificate[1]; + SecureRestClientTrustManager sm = Mockito.mock(SecureRestClientTrustManager.class); + Mockito.when(sm.getAcceptedIssuers()).thenReturn(Mockito.any()); + Mockito.when(sm.isClientTrusted(arg0)).thenReturn(true); + Mockito.when(sm.isServerTrusted(arg0)).thenReturn(true); + } +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInstarResponseHandlerImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInstarResponseHandlerImpl.java deleted file mode 100644 index 1d0db357a..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInstarResponseHandlerImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============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.junit.Test; -import org.openecomp.sdnc.config.params.data.ResponseKey; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -public class TestInstarResponseHandlerImpl { - - @Test - public void testProcessResponseForIpv4(){ - ResponseKey resKey = new ResponseKey(); - resKey.setUniqueKeyValue("x"); - SvcLogicContext svc = new SvcLogicContext(); - svc.setAttribute("vnf-name", "fqdn"); - resKey.setFieldKeyName("ipaddress-v4"); - String instarKey = "key"; - String instarRes ="{\"vnfConfigurationParameterDetails\":" - + "[{\"fqdn\":\"fqdnx\",\"v4IPAddress\":\"value2\"}]}"; - InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc); - impl.processResponse(instarRes, instarKey); - } - - @Test - public void testProcessResponseForIpv6(){ - ResponseKey resKey = new ResponseKey(); - resKey.setUniqueKeyValue("x"); - SvcLogicContext svc = new SvcLogicContext(); - svc.setAttribute("vnf-name", "fqdn"); - resKey.setFieldKeyName("ipaddress-v6"); - String instarKey = "key"; - String instarRes ="{\"vnfConfigurationParameterDetails\":" - + "[{\"fqdn\":\"fqdnx\",\"v6IPAddress\":\"value2\"}]}"; - InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc); - impl.processResponse(instarRes, instarKey); - } - - @Test - public void testProcessResponseInstarKeyValues(){ - - ResponseKey resKey = new ResponseKey(); - resKey.setUniqueKeyValue("x"); - String json ="{\"vnfConfigurationParameterDetails\":" - + "[{\"fqdn\":\"fqdnx\",\"v4IPAddress\":\"value2\"}]}"; - SvcLogicContext svc = new SvcLogicContext(); - svc.setAttribute("vnf-name", "fqdn"); - svc.setAttribute("INSTAR-KEY-VALUES", json); - resKey.setFieldKeyName("ipaddress-v6"); - String instarKey = "key"; - String instarRes ="{\"vnfConfigurationParameterDetails\":" - + "[{\"fqdn\":\"fqdnx\",\"v6IPAddress\":\"value2\"}]}"; - InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc); - impl.processResponse(instarRes, instarKey); - } -} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInstarRestClientImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInstarRestClientImpl.java deleted file mode 100644 index cf2427dc1..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInstarRestClientImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============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 org.junit.Test; -import org.mockito.Mockito; -import org.onap.appc.instar.dme2client.Dme2Client; - -public class TestInstarRestClientImpl { - - @Test(expected=Exception.class) - public void testSendRequest() throws Exception{ - HashMap map = new HashMap<>(); - map.put("key", "value"); - Dme2Client client = Mockito.mock(Dme2Client.class); - Mockito.when(client.send()).thenReturn("test"); - InstarRestClientImpl imp = new InstarRestClientImpl(map); - imp.sendRequest("getIpAddressByVnf"); - } -} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInterfaceIpAddressImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInterfaceIpAddressImpl.java deleted file mode 100644 index f29bebd7e..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/interfaceImpl/TestInterfaceIpAddressImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============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.ArrayList; -import java.util.List; -import org.junit.Test; -import org.openecomp.sdnc.config.params.data.Parameter; -import org.openecomp.sdnc.config.params.data.ResponseKey; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -public class TestInterfaceIpAddressImpl { - - @Test(expected=Exception.class) - public void testProcessRuleException1() throws Exception{ - Parameter param = new Parameter(); - param.setRuleType("test"); - param.setName("test"); - param.setSource("INSTAR"); - SvcLogicContext svc = new SvcLogicContext(); - svc.setAttribute("vnf-name", "test"); - InterfaceIpAddressImpl impl = new InterfaceIpAddressImpl(param,svc); - impl.processRule(); - } - - @Test(expected=Exception.class) - public void testProcessRuleException2() throws Exception{ - List list = new ArrayList<>(); - list.add(new ResponseKey()); - list.add(new ResponseKey()); - Parameter param = new Parameter(); - param.setResponseKeys(list); - param.setRuleType("test"); - param.setName("test"); - param.setSource("INSTAR"); - SvcLogicContext svc = new SvcLogicContext(); - svc.setAttribute("vnf-name", "test"); - InterfaceIpAddressImpl impl = new InterfaceIpAddressImpl(param,svc); - impl.processRule(); - param.setSource("INSTAR1"); - impl.processRule(); - } -} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestDme2Client.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestDme2Client.java deleted file mode 100644 index 8e87ffe35..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestDme2Client.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============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 java.util.HashMap; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.appc.instar.dme2client.Dme2Client; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -public class TestDme2Client { - - @Test(expected=Exception.class) - public void testSendtoInstar() throws Exception{ - - HashMap data = new HashMap(); - data.put("subtext","value"); - PowerMockito.mockStatic(System.class); - PowerMockito.when((System.getenv("test"))).thenReturn("test"); - Dme2Client dme2 = new Dme2Client("opt","subtext",data); - } -} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestInstarClientNode.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestInstarClientNode.java deleted file mode 100644 index 285662f75..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestInstarClientNode.java +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * ============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 java.net.URI; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.Map; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.ws.rs.HttpMethod; - -import org.apache.commons.io.IOUtils; -import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Test; -import org.onap.appc.instar.dme2client.SecureRestClientTrustManager; -import org.onap.appc.instar.utils.InstarClientConstant; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -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 TestInstarClientNode { - - //ONAP Migration - - @Test(expected=Exception.class) - public void testInstarClientNode() throws Exception { - - SvcLogicContext ctx = new SvcLogicContext(); - String key_conetent = IOUtils.toString(TestInstarClientNode.class.getClassLoader().getResourceAsStream("templates/sampleKeyContents"), Charset.defaultCharset()); - Map inParams = new HashMap(); - inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST"); - inParams.put(InstarClientConstant.INSTAR_KEYS, "LOCAL_ACCESS_IP_ADDR"); - inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME); - ctx.setAttribute("INSTAR.LOCAL_ACCESS_IP_ADDR", key_conetent); - ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST"); - ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v"); - InstarClientNode icn = new InstarClientNode(); - icn.getInstarInfo(inParams, ctx); - String address = (new JSONObject(ctx.getAttribute("TEST." + InstarClientConstant.INSTAR_KEY_VALUES))).getString("LOCAL_ACCESS_IP_ADDR"); - } - @Test(expected=Exception.class) - public void testInstarData() throws Exception { - - InstarClientNode inNode = new InstarClientNode(); - SvcLogicContext ctx = new SvcLogicContext (); - Map inParams = new HashMap(); - - inParams.put(InstarClientConstant.VNF_NAME, "basx0003v"); - inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME); - inNode.getInstarData(inParams, ctx); - - - } -} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestSecureRestClientTrustManager.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestSecureRestClientTrustManager.java deleted file mode 100644 index b18673a40..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/openecomp/appc/instar/node/TestSecureRestClientTrustManager.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============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 java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.appc.instar.dme2client.SecureRestClientTrustManager; - -public class TestSecureRestClientTrustManager { - - @Test - public void testSecureRestClient() throws CertificateException{ - X509Certificate[] arg0 = new X509Certificate[1]; - SecureRestClientTrustManager sm = Mockito.mock(SecureRestClientTrustManager.class); - Mockito.when(sm.getAcceptedIssuers()).thenReturn(Mockito.any()); - Mockito.when(sm.isClientTrusted(arg0)).thenReturn(true); - Mockito.when(sm.isServerTrusted(arg0)).thenReturn(true); - } -} -- cgit 1.2.3-korg