From 0e9e5821fbd918fb9b33ad8ba5d311e7f527bcab Mon Sep 17 00:00:00 2001 From: "Balaji, Ramya (rb111y)" Date: Sat, 19 Jan 2019 21:28:38 -0500 Subject: Network Inventory Cient Platform Hardening Renamed class files to be more meaningful and synched up directories Issue-ID: APPC-1338 Change-Id: I5eee7c96013e8733fb14e4b0a1de88d4c9611a0f Signed-off-by: Balaji, Ramya (rb111y) --- .../interfaceImpl/AaiInterfaceRulesHandler.java | 2 +- .../onap/appc/instar/InstarClientActivator.java | 17 +- .../interfaceImpl/InterfaceIpAddressImpl.java | 8 +- .../instar/interfaces/RuleHandlerInterface.java | 33 ---- .../onap/appc/instar/node/InstarClientNode.java | 167 -------------------- .../system/interfaces/RuleHandlerInterface.java | 34 ++++ .../onap/appc/system/node/SourceSystemNode.java | 175 +++++++++++++++++++++ .../appc/instar/node/TestInstarClientNode.java | 149 ------------------ .../appc/system/node/SourceSystemNodeTest.java | 153 ++++++++++++++++++ 9 files changed, 376 insertions(+), 362 deletions(-) delete mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RuleHandlerInterface.java delete 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/system/interfaces/RuleHandlerInterface.java create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/system/node/SourceSystemNode.java delete 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/system/node/SourceSystemNodeTest.java (limited to 'appc-outbound') diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/interfaceImpl/AaiInterfaceRulesHandler.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/interfaceImpl/AaiInterfaceRulesHandler.java index 37a40f7c4..f82404303 100644 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/interfaceImpl/AaiInterfaceRulesHandler.java +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/interfaceImpl/AaiInterfaceRulesHandler.java @@ -33,7 +33,7 @@ import org.onap.appc.aai.data.AaiVmInfo; import org.onap.appc.aai.data.AaiVnfInfo; import org.onap.appc.aai.data.AaiVnfcInfo; import org.onap.appc.aai.utils.AaiClientConstant; -import org.onap.appc.instar.interfaces.RuleHandlerInterface; +import org.onap.appc.system.interfaces.RuleHandlerInterface; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.sdnc.config.params.data.Parameter; import org.onap.sdnc.config.params.data.ResponseKey; 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 index a703f816b..137ef9ee5 100644 --- 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 @@ -9,15 +9,15 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ============LICENSE_END========================================================= */ @@ -27,7 +27,8 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.util.LinkedList; import java.util.List; -import org.onap.appc.instar.node.InstarClientNode; + +import org.onap.appc.system.node.SourceSystemNode; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; @@ -40,10 +41,10 @@ public class InstarClientActivator implements BundleActivator { @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()); + SourceSystemNode sourceSystemNode = new SourceSystemNode(); + log.info("Registering service " + sourceSystemNode.getClass().getName()); + registrations.add(ctx.registerService(sourceSystemNode.getClass().getName(), sourceSystemNode, null)); + log.info("Registering service sccessful for " + sourceSystemNode.getClass().getName()); } @Override 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 index f5f4924d6..88ab4c137 100644 --- 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 @@ -9,15 +9,15 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ============LICENSE_END========================================================= */ @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; 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.system.interfaces.RuleHandlerInterface; import org.onap.appc.instar.utils.InstarClientConstant; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.sdnc.config.params.data.Parameter; 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 deleted file mode 100644 index f86d25272..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RuleHandlerInterface.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017-2018 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. - * - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.instar.interfaces; - -import java.io.IOException; -import org.onap.appc.instar.interfaceImpl.InstarResponseException; - -@FunctionalInterface -public interface RuleHandlerInterface { - - void processRule() throws InstarResponseException, IOException; -} 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 deleted file mode 100644 index 4087e2ad2..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/node/InstarClientNode.java +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ================================================================================ - * Modifications Copyright (C) 2018 Ericsson - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============LICENSE_END========================================================= - */ - -package org.onap.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.HashMap; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.appc.aai.interfaceImpl.AaiInterfaceRulesHandler; -import org.onap.appc.aai.utils.AaiClientConstant; -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.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; -import org.onap.sdnc.config.params.data.Parameter; - -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 = inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX); - try { - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : ""; - String[] instarKeys = getKeys(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()); - log.info("Received Context : " + ctx.getAttribute("INSTAR." + instarKey)); - Parameter params = mapper - .readValue(ctx.getAttribute(InstarClientConstant.SOURCE_SYSTEM_INSTAR + "." + instarKey), - Parameter.class); - RuleHandlerInterface handler; - log.info("Processing rule Type : " + params.getRuleType()); - if (params.getRuleType().equals(InstarClientConstant.INTERFACE_IP_ADDRESS)) { - handler = createHandler(params, ctx); - } else { - throw new SvcLogicException("No Rule Defined to process :" + params.getRuleType()); - } - handler.processRule(); - } - log.info("responsePrefix =" + responsePrefix); - log.info("instar key values =" + ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES)); - ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, - ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES)); - ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, - InstarClientConstant.OUTPUT_STATUS_SUCCESS); - log.info(ctx.getAttribute("TEST." + InstarClientConstant.OUTPUT_PARAM_STATUS)); - 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); - throw new SvcLogicException(e.getMessage()); - } - } - - private static String[] getKeys(String keyString) { - log.error("Received Key String as :" + keyString); - String key = keyString - .replace("[", "") - .replace("]", "") - .replace("\"", ""); - if (key.contains(",")) { - return key.split(","); - } else { - return new String[]{key}; - } - } - - public void getInstarData(Map inParams, SvcLogicContext ctx) - throws SvcLogicException { - log.info("Received getInstarData call with params : " + inParams); - String responsePrefix = inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX); - try { - HashMap input = new HashMap<>(); - input.putAll(inParams); - RestClientInterface rcINterface = createRestClientInterface(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); - throw new SvcLogicException(e.getMessage()); - } - } - - public void getAaiInfo(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - log.info("Received getAaiInfo call with params : " + inParams); - String responsePrefix = inParams.get(AaiClientConstant.INPUT_PARAM_RESPONSE_PRIFIX); - try { - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : ""; - String[] aaiKeys = getKeys(inParams.get(AaiClientConstant.AAI_KEYS)); - for (String aaiKey : aaiKeys) { - log.info("Processing Key : " + aaiKey); - log.info("Searching key for : " + "AAI." + aaiKey); - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - log.info("Received Context : " + ctx.getAttribute("AAI." + aaiKey)); - Parameter params = mapper.readValue( - ctx.getAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + aaiKey), Parameter.class); - log.info("Processing rule Type : " + params.getRuleType()); - RuleHandlerInterface handler = new AaiInterfaceRulesHandler(params, ctx); - handler.processRule(); - } - log.info("responsePrefix =" + responsePrefix); - ctx.setAttribute(responsePrefix + AaiClientConstant.AAI_KEY_VALUES, - ctx.getAttribute(AaiClientConstant.AAI_KEY_VALUES)); - ctx.setAttribute(responsePrefix + AaiClientConstant.OUTPUT_PARAM_STATUS, - AaiClientConstant.OUTPUT_STATUS_SUCCESS); - ctx.setAttribute(AaiClientConstant.AAI_KEY_VALUES, null); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + AaiClientConstant.OUTPUT_PARAM_STATUS, - InstarClientConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + AaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - log.error("Failed processing AAI data", e); - throw new SvcLogicException(e.getMessage()); - } - } - - protected RuleHandlerInterface createHandler(Parameter params, SvcLogicContext ctx) { - return new InterfaceIpAddressImpl(params, ctx); - } - - protected RestClientInterface createRestClientInterface(Map input) { - return new InstarRestClientImpl(input); - } -} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/system/interfaces/RuleHandlerInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/system/interfaces/RuleHandlerInterface.java new file mode 100644 index 000000000..2f4580701 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/system/interfaces/RuleHandlerInterface.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 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. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.system.interfaces; + +import java.io.IOException; + +import org.onap.appc.instar.interfaceImpl.InstarResponseException; + +@FunctionalInterface +public interface RuleHandlerInterface { + + void processRule() throws InstarResponseException, IOException; +} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/system/node/SourceSystemNode.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/system/node/SourceSystemNode.java new file mode 100644 index 000000000..32a65df59 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/system/node/SourceSystemNode.java @@ -0,0 +1,175 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2018 Ericsson + * ================================================================================ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + + +package org.onap.appc.system.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.HashMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.appc.aai.interfaceImpl.AaiInterfaceRulesHandler; +import org.onap.appc.aai.utils.AaiClientConstant; +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.system.interfaces.RuleHandlerInterface; +import org.onap.appc.instar.utils.InstarClientConstant; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; +import org.onap.sdnc.config.params.data.Parameter; + +public class SourceSystemNode implements SvcLogicJavaPlugin { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(SourceSystemNode.class); + + + public void getInstarInfo(Map inParams, SvcLogicContext ctx) + throws SvcLogicException { + log.info("Received getInstarInfo call with params : " + inParams); + String responsePrefix = inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX); + try { + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : ""; + String[] instarKeys = getKeys(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()); + log.info("Received Context : " + ctx.getAttribute("INSTAR." + instarKey)); + Parameter params = mapper + .readValue(ctx.getAttribute(InstarClientConstant.SOURCE_SYSTEM_INSTAR + "." + instarKey), + Parameter.class); + RuleHandlerInterface handler; + log.info("Processing rule Type : " + params.getRuleType()); + if (params.getRuleType().equals(InstarClientConstant.INTERFACE_IP_ADDRESS)) { + handler = createHandler(params, ctx); + } else { + throw new SvcLogicException("No Rule Defined to process :" + params.getRuleType()); + } + handler.processRule(); + } + log.info("responsePrefix =" + responsePrefix); + log.info("instar key values =" + ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES)); + ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, + ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES)); + ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS, + InstarClientConstant.OUTPUT_STATUS_SUCCESS); + log.info(ctx.getAttribute("TEST." + InstarClientConstant.OUTPUT_PARAM_STATUS)); + 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); + throw new SvcLogicException(e.getMessage()); + } + } + + private static String[] getKeys(String keyString) { + log.error("Received Key String as :" + keyString); + + String key = keyString + .replace("[", "") + .replace("]", "") + .replace("\"", ""); + + if (key.contains(",")) { + return key.split(","); + } else { + return new String[]{key}; + } + } + + public void getInstarData(Map inParams, SvcLogicContext ctx) + throws SvcLogicException { + log.info("Received getInstarData call with params : " + inParams); + String responsePrefix = inParams.get(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX); + try { + HashMap input = new HashMap<>(); + input.putAll(inParams); + RestClientInterface rcINterface = createRestClientInterface(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); + throw new SvcLogicException(e.getMessage()); + } + } + + public void getAaiInfo(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + log.info("Received getAaiInfo call with params : " + inParams); + String responsePrefix = inParams.get(AaiClientConstant.INPUT_PARAM_RESPONSE_PRIFIX); + try { + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : ""; + String[] aaiKeys = getKeys(inParams.get(AaiClientConstant.AAI_KEYS)); + for (String aaiKey : aaiKeys) { + log.info("Processing Key : " + aaiKey); + log.info("Searching key for : " + "AAI." + aaiKey); + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + log.info("Received Context : " + ctx.getAttribute("AAI." + aaiKey)); + Parameter params = mapper.readValue( + ctx.getAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + aaiKey), Parameter.class); + log.info("Processing rule Type : " + params.getRuleType()); + RuleHandlerInterface handler = new AaiInterfaceRulesHandler(params, ctx); + handler.processRule(); + } + log.info("responsePrefix =" + responsePrefix); + ctx.setAttribute(responsePrefix + AaiClientConstant.AAI_KEY_VALUES, + ctx.getAttribute(AaiClientConstant.AAI_KEY_VALUES)); + ctx.setAttribute(responsePrefix + AaiClientConstant.OUTPUT_PARAM_STATUS, + AaiClientConstant.OUTPUT_STATUS_SUCCESS); + ctx.setAttribute(AaiClientConstant.AAI_KEY_VALUES, null); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + AaiClientConstant.OUTPUT_PARAM_STATUS, + InstarClientConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + AaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + log.error("Failed processing AAI data", e); + throw new SvcLogicException(e.getMessage()); + } + } + + + protected RuleHandlerInterface createHandler(Parameter params, SvcLogicContext ctx) { + return new InterfaceIpAddressImpl(params, ctx); + } + + protected RestClientInterface createRestClientInterface(Map input) { + return new InstarRestClientImpl(input); + } + +} 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 deleted file mode 100644 index ce3dd76dc..000000000 --- a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientNode.java +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ================================================================================ - * Modifications Copyrigh (C) 2018 Ericsson - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.instar.node; - -import java.util.HashMap; -import java.util.Map; -import org.jline.utils.Log; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.powermock.api.mockito.PowerMockito; -import org.mockito.Mockito; -import org.onap.appc.aai.utils.AaiClientConstant; -import org.onap.appc.instar.interfaceImpl.InstarRestClientImpl; -import org.onap.appc.instar.interfaceImpl.InterfaceIpAddressImpl; -import org.onap.appc.instar.interfaces.RuleHandlerInterface; -import org.onap.appc.instar.utils.InstarClientConstant; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - - -public class TestInstarClientNode { - - //ONAP Migration - - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - - @Test - public void testInstarClientNode() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - String key_content = "{\"name\":\"LOCAL_ACCESS_IP_ADDR\",\"description\":\"this is the node0 tacplus server IP address\",\"type\":" - + "\"ipv4_address\",\"required\":true,\"source\":\"INSTAR\",\"rule-type\":\"interface-ip-address\",\"default\":null,\"request-keys\":" - + "null,\"response-keys\":[{\"unique-key-name\":\"addressfqdn\",\"unique-key-value\":\"00000000000000\",\"field-key-name\":\"ipaddress-v4\"}]}"; - Map inParams = new HashMap(); - inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, ""); - 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_content); - ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, ""); - ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v"); - InstarClientNode icn = PowerMockito.spy(new InstarClientNode()); - RuleHandlerInterface mockRuleHandler = Mockito.mock(InterfaceIpAddressImpl.class); - Mockito.doReturn(mockRuleHandler).when(icn).createHandler(Mockito.any(), Mockito.any()); - Mockito.doNothing().when(mockRuleHandler).processRule(); - icn.getInstarInfo(inParams, ctx); - Log.info(ctx.getStatus()); - Assert.assertEquals(InstarClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("" + InstarClientConstant.OUTPUT_PARAM_STATUS)); - } - - @Test - public void testInstarClientNodeFailure() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - String key_content = "{\"name\":\"LOCAL_ACCESS_IP_ADDR\",\"description\":\"this is the node0 tacplus server IP address\",\"type\":" - + "\"ipv4_address\",\"required\":true,\"source\":\"INSTAR\",\"rule-type\":\"NON_INTERFACE_IP_ADDRESS\",\"default\":null,\"request-keys\":" - + "null,\"response-keys\":[{\"unique-key-name\":\"addressfqdn\",\"unique-key-value\":\"00000000000000\",\"field-key-name\":\"ipaddress-v4\"}]}"; - Log.info(key_content); - 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_content); - ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST"); - ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v"); - InstarClientNode icn = new InstarClientNode(); - expectedEx.expect(SvcLogicException.class); - expectedEx.expectMessage("No Rule Defined to process :"); - icn.getInstarInfo(inParams, ctx); - } - - @Test - public void testInstarData() throws Exception { - InstarClientNode icn = Mockito.spy(new InstarClientNode()); - SvcLogicContext ctx = new SvcLogicContext (); - Map inParams = new HashMap(); - InstarRestClientImpl mockRestClient = Mockito.mock(InstarRestClientImpl.class); - Mockito.doReturn(mockRestClient).when(icn).createRestClientInterface(Mockito.any()); - Mockito.doReturn("Test-data").when(mockRestClient).sendRequest(Mockito.anyString()); - inParams.put(InstarClientConstant.VNF_NAME, "basx0003v"); - inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME); - icn.getInstarData(inParams, ctx); - Assert.assertEquals(InstarClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("" + InstarClientConstant.OUTPUT_PARAM_STATUS)); - Assert.assertEquals("Test-data", ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES)); - } - - @Test - public void testInstarDataFailure() throws Exception { - InstarClientNode icn = 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); - expectedEx.expect(SvcLogicException.class); - expectedEx.expectMessage("Cannot find Property file -SDNC_CONFIG_DIR"); - icn.getInstarData(inParams, ctx); - } - - @Test - public void TestGetAaiInfo() throws Exception { - InstarClientNode aaiNode=new InstarClientNode(); - Map inParams=new HashMap (); - SvcLogicContext ctx=new SvcLogicContext(); - String keyVals = new String("[\"vnf_name\"]"); - inParams.put("aaiKeys",keyVals); - inParams.put("responsePrefix","test"); - String parameterString="{\"name\":\"vnf_name\",\"description\":null,\"type\":null,\"required\":false,\"source\":\"A&AI\"," - + "\"rule-type\":\"vnf-name\",\"default\":null,\"request-keys\":null,\"response-keys\":[{\"unique-key-name\":\"parent-name\"," - + "\"unique-key-value\":\"vnf\",\"field-key-name\":\"vnf-name\",\"filter-by-field\":null,\"filter-by-value\":null}]}"; - ctx.setAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + "vnf_name",parameterString); - aaiNode.getAaiInfo(inParams, ctx); - Assert.assertEquals(InstarClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("test." + InstarClientConstant.OUTPUT_PARAM_STATUS)); - } - - @Test - public void TestGetAaiInfoFailure() throws Exception { - InstarClientNode aaiNode=new InstarClientNode(); - Map inParams= Mockito.spy(new HashMap ()); - inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, ""); - Mockito.doThrow(new RuntimeException("Test-exception")).when(inParams).get(AaiClientConstant.AAI_KEYS); - SvcLogicContext ctx=new SvcLogicContext(); - expectedEx.expect(SvcLogicException.class); - expectedEx.expectMessage("Test-exception"); - aaiNode.getAaiInfo(inParams, ctx); - } -} diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/system/node/SourceSystemNodeTest.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/system/node/SourceSystemNodeTest.java new file mode 100644 index 000000000..37be9fe99 --- /dev/null +++ b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/system/node/SourceSystemNodeTest.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2018 Ericsson + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.system.node; + + +import java.util.HashMap; +import java.util.Map; +import org.jline.utils.Log; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.powermock.api.mockito.PowerMockito; +import org.mockito.Mockito; +import org.onap.appc.aai.utils.AaiClientConstant; +import org.onap.appc.instar.interfaceImpl.InstarRestClientImpl; +import org.onap.appc.instar.interfaceImpl.InterfaceIpAddressImpl; +import org.onap.appc.system.interfaces.RuleHandlerInterface; +import org.onap.appc.instar.utils.InstarClientConstant; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + + +public class SourceSystemNodeTest { + + + //ONAP Migration + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void testSourceSystemNode() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + String key_content = "{\"name\":\"LOCAL_ACCESS_IP_ADDR\",\"description\":\"this is the node0 tacplus server IP address\",\"type\":" + + "\"ipv4_address\",\"required\":true,\"source\":\"INSTAR\",\"rule-type\":\"interface-ip-address\",\"default\":null,\"request-keys\":" + + "null,\"response-keys\":[{\"unique-key-name\":\"addressfqdn\",\"unique-key-value\":\"00000000000000\",\"field-key-name\":\"ipaddress-v4\"}]}"; + Map inParams = new HashMap(); + inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, ""); + 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_content); + ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, ""); + ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v"); + SourceSystemNode icn = PowerMockito.spy(new SourceSystemNode()); + RuleHandlerInterface mockRuleHandler = Mockito.mock(InterfaceIpAddressImpl.class); + Mockito.doReturn(mockRuleHandler).when(icn).createHandler(Mockito.any(), Mockito.any()); + Mockito.doNothing().when(mockRuleHandler).processRule(); + icn.getInstarInfo(inParams, ctx); + Log.info(ctx.getStatus()); + Assert.assertEquals(InstarClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("" + InstarClientConstant.OUTPUT_PARAM_STATUS)); + } + + @Test + public void testSourceSystemNodeFailure() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + String key_content = "{\"name\":\"LOCAL_ACCESS_IP_ADDR\",\"description\":\"this is the node0 tacplus server IP address\",\"type\":" + + "\"ipv4_address\",\"required\":true,\"source\":\"INSTAR\",\"rule-type\":\"NON_INTERFACE_IP_ADDRESS\",\"default\":null,\"request-keys\":" + + "null,\"response-keys\":[{\"unique-key-name\":\"addressfqdn\",\"unique-key-value\":\"00000000000000\",\"field-key-name\":\"ipaddress-v4\"}]}"; + Log.info(key_content); + 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_content); + ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST"); + ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v"); + SourceSystemNode icn = new SourceSystemNode(); + expectedEx.expect(SvcLogicException.class); + expectedEx.expectMessage("No Rule Defined to process :"); + icn.getInstarInfo(inParams, ctx); + } + + @Test + public void testInstarData() throws Exception { + SourceSystemNode icn = Mockito.spy(new SourceSystemNode()); + SvcLogicContext ctx = new SvcLogicContext (); + Map inParams = new HashMap(); + InstarRestClientImpl mockRestClient = Mockito.mock(InstarRestClientImpl.class); + Mockito.doReturn(mockRestClient).when(icn).createRestClientInterface(Mockito.any()); + Mockito.doReturn("Test-data").when(mockRestClient).sendRequest(Mockito.anyString()); + inParams.put(InstarClientConstant.VNF_NAME, "basx0003v"); + inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME); + icn.getInstarData(inParams, ctx); + Assert.assertEquals(InstarClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("" + InstarClientConstant.OUTPUT_PARAM_STATUS)); + Assert.assertEquals("Test-data", ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES)); + } + + @Test + public void testInstarDataFailure() throws Exception { + SourceSystemNode icn = new SourceSystemNode(); + SvcLogicContext ctx = new SvcLogicContext (); + Map inParams = new HashMap(); + inParams.put(InstarClientConstant.VNF_NAME, "basx0003v"); + inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME); + expectedEx.expect(SvcLogicException.class); + //expectedEx.expectMessage("Cannot find Property file -SDNC_CONFIG_DIR"); + icn.getInstarData(inParams, ctx); + } + + @Test + public void TestGetAaiInfo() throws Exception { + SourceSystemNode aaiNode=new SourceSystemNode(); + Map inParams=new HashMap (); + SvcLogicContext ctx=new SvcLogicContext(); + String keyVals = new String("[\"vnf_name\"]"); + inParams.put("aaiKeys",keyVals); + inParams.put("responsePrefix","test"); + String parameterString="{\"name\":\"vnf_name\",\"description\":null,\"type\":null,\"required\":false,\"source\":\"A&AI\"," + + "\"rule-type\":\"vnf-name\",\"default\":null,\"request-keys\":null,\"response-keys\":[{\"unique-key-name\":\"parent-name\"," + + "\"unique-key-value\":\"vnf\",\"field-key-name\":\"vnf-name\",\"filter-by-field\":null,\"filter-by-value\":null}]}"; + ctx.setAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + "vnf_name",parameterString); + aaiNode.getAaiInfo(inParams, ctx); + Assert.assertEquals(InstarClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("test." + InstarClientConstant.OUTPUT_PARAM_STATUS)); + } + + @Test + public void TestGetAaiInfoFailure() throws Exception { + SourceSystemNode aaiNode=new SourceSystemNode(); + Map inParams= Mockito.spy(new HashMap ()); + inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, ""); + Mockito.doThrow(new RuntimeException("Test-exception")).when(inParams).get(AaiClientConstant.AAI_KEYS); + SvcLogicContext ctx=new SvcLogicContext(); + expectedEx.expect(SvcLogicException.class); + expectedEx.expectMessage("Test-exception"); + aaiNode.getAaiInfo(inParams, ctx); + } + +} + -- cgit 1.2.3-korg