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 --- .../org/onap/appc/dg/util/AppcDgUtilActivator.java | 58 ++++ .../org/onap/appc/dg/util/ExecuteNodeAction.java | 43 +++ .../appc/dg/util/InputParameterValidation.java | 42 +++ .../org/onap/appc/dg/util/UpgradeStubNode.java | 36 ++ .../appc/dg/util/impl/ExecuteNodeActionImpl.java | 362 +++++++++++++++++++++ .../dg/util/impl/InputParameterValidationImpl.java | 136 ++++++++ .../appc/dg/util/impl/UpgradeStubNodeImpl.java | 50 +++ .../appc/dg/util/AppcDgUtilActivator.java | 58 ---- .../openecomp/appc/dg/util/ExecuteNodeAction.java | 43 --- .../appc/dg/util/InputParameterValidation.java | 42 --- .../openecomp/appc/dg/util/UpgradeStubNode.java | 36 -- .../appc/dg/util/impl/ExecuteNodeActionImpl.java | 362 --------------------- .../dg/util/impl/InputParameterValidationImpl.java | 136 -------- .../appc/dg/util/impl/UpgradeStubNodeImpl.java | 50 --- .../resources/org/onap/appc/default.properties | 29 ++ .../org/openecomp/appc/default.properties | 29 -- .../onap/appc/dg/util/AppcDgUtilActivatorTest.java | 59 ++++ .../dg/util/impl/ExecuteNodeActionImplTest.java | 235 +++++++++++++ .../impl/InputParameterValidationImplTest.java | 165 ++++++++++ .../appc/dg/util/impl/UpgradeStubNodeImplTest.java | 63 ++++ .../appc/dg/util/AppcDgUtilActivatorTest.java | 59 ---- .../dg/util/impl/ExecuteNodeActionImplTest.java | 235 ------------- .../impl/InputParameterValidationImplTest.java | 165 ---------- .../appc/dg/util/impl/UpgradeStubNodeImplTest.java | 63 ---- 24 files changed, 1278 insertions(+), 1278 deletions(-) create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/AppcDgUtilActivator.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/ExecuteNodeAction.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/InputParameterValidation.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/UpgradeStubNode.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/InputParameterValidationImpl.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImpl.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/AppcDgUtilActivator.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/ExecuteNodeAction.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/InputParameterValidation.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/UpgradeStubNode.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImpl.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImpl.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImpl.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/resources/org/onap/appc/default.properties delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/resources/org/openecomp/appc/default.properties create mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/InputParameterValidationImplTest.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/AppcDgUtilActivatorTest.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImplTest.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImplTest.java delete mode 100644 appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImplTest.java (limited to 'appc-dg-util/appc-dg-util-bundle') diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/AppcDgUtilActivator.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/AppcDgUtilActivator.java new file mode 100644 index 000000000..486d475f4 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/AppcDgUtilActivator.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========================================================= + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.onap.appc.dg.util; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class AppcDgUtilActivator implements BundleActivator { + + public void start(BundleContext context) { + System.out.println("Starting the bundle"); + } + + public void stop(BundleContext context) { + System.out.println("Stopping the bundle"); + } + +} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/ExecuteNodeAction.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/ExecuteNodeAction.java new file mode 100644 index 000000000..38bc0955d --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/ExecuteNodeAction.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.dg.util; + +import java.util.Map; + +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + +public interface ExecuteNodeAction extends SvcLogicJavaPlugin { + void getResource(Map params, SvcLogicContext ctx) throws APPCException; + + void postResource(Map params, SvcLogicContext ctx) throws APPCException; + + void deleteResource(Map params, SvcLogicContext ctx) throws APPCException; + + void getVnfHierarchy(Map params, SvcLogicContext ctx) throws APPCException; + void waitMethod(Map params, SvcLogicContext ctx) throws APPCException; +} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/InputParameterValidation.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/InputParameterValidation.java new file mode 100644 index 000000000..714e12a03 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/InputParameterValidation.java @@ -0,0 +1,42 @@ +/*- + * ============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.dg.util; + +import java.util.Map; + +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + +public interface InputParameterValidation extends SvcLogicJavaPlugin { + + void validateAttribute(Map params, SvcLogicContext ctx) throws APPCException; + + void validateAttributeLength(Map params, SvcLogicContext ctx) throws APPCException; + + void validateAttributeCharacter(Map params, SvcLogicContext ctx) throws APPCException; + +} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/UpgradeStubNode.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/UpgradeStubNode.java new file mode 100644 index 000000000..4f0a80f5a --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/UpgradeStubNode.java @@ -0,0 +1,36 @@ +/*- + * ============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.dg.util; + +import java.util.Map; + +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + +public interface UpgradeStubNode extends SvcLogicJavaPlugin { + void handleUpgradeStub(Map params, SvcLogicContext ctx) throws APPCException; +} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java new file mode 100644 index 000000000..b5dc40712 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImpl.java @@ -0,0 +1,362 @@ +/*- + * ============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.dg.util.impl; + +import org.onap.appc.dg.util.ExecuteNodeAction; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.i18n.Msg; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + + +public class ExecuteNodeActionImpl implements ExecuteNodeAction { + + private AAIService aaiService; + protected static AAIClient client; + private static final EELFLogger logger = EELFManager.getInstance().getLogger(ExecuteNodeActionImpl.class); + + public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message"; + public ExecuteNodeActionImpl() { + } + + /** + * initialize the SDNC adapter (AAIService) by building the context. + */ + private void initialize() { + getAAIservice(); + } + + private void getAAIservice() { + BundleContext bctx = FrameworkUtil.getBundle(AAIService.class).getBundleContext(); + // Get AAIadapter reference + ServiceReference sref = bctx.getServiceReference(AAIService.class.getName()); + if (sref != null) { + logger.info("AAIService from bundlecontext"); + aaiService = (AAIService) bctx.getService(sref); + + } else { + logger.info("AAIService error from bundlecontext"); + logger.error(EELFResourceManager.format(Msg.AAI_CONNECTION_FAILED, "AAIService")); + } + } + + /** + * Method called in TestDG to test timeout scenario + * + * @param params waitTime time in millisecond DG is going to sleep + * @param ctx + * @throws APPCException + */ + @Override public void waitMethod(Map params, SvcLogicContext ctx) throws APPCException { + try { + String waitTime = params.get("waitTime"); + + logger.info("DG will waits for " + Long.parseLong(waitTime) + "milliseconds"); + Thread.sleep(Long.parseLong(waitTime)); + logger.info("DG waits for " + Long.parseLong(waitTime) + " milliseconds completed"); + } catch (InterruptedException e) { + logger.error("Error In ExecuteNodeActionImpl for waitMethod() due to InterruptedException: reason = " + e.getMessage()); + } + } + + @Override public void getResource(Map params, SvcLogicContext ctx) throws APPCException { + initialize(); + String resourceType = params.get("resourceType"), ctx_prefix = params.get("prefix"), resourceKey = + params.get("resourceKey"); + if (logger.isDebugEnabled()) { + logger.debug("inside getResorce"); + logger.debug("Retrieving " + resourceType + " details from A&AI for Key : " + resourceKey); + } + client = aaiService; + try { + SvcLogicResource.QueryStatus response = + client.query(resourceType, false, null, resourceKey, ctx_prefix, null, ctx); + logger.info("AAIResponse: " + response.toString()); + ctx.setAttribute("getResource_result", response.toString()); + } catch (SvcLogicException e) { + logger.error(EELFResourceManager.format(Msg.AAI_GET_DATA_FAILED, resourceKey, "", e.getMessage())); + } + if (logger.isDebugEnabled()) { + logger.debug("exiting getResource======"); + } + } + + @Override public void postResource(Map params, SvcLogicContext ctx) throws APPCException { + initialize(); + String resourceType = params.get("resourceType"), ctx_prefix = params.get("prefix"), resourceKey = + params.get("resourceKey"), att_name = params.get("attributeName"), att_value = + params.get("attributeValue"); + if (logger.isDebugEnabled()) { + logger.debug("inside postResource"); + logger.debug("Updating " + resourceType + " details in A&AI for Key : " + resourceKey); + logger.debug("Updating " + att_name + " to : " + att_value); + } + Map data = new HashMap(); + data.put(att_name, att_value); + client = aaiService; + + try { + SvcLogicResource.QueryStatus response = client.update(resourceType, resourceKey, data, ctx_prefix, ctx); + logger.info("AAIResponse: " + response.toString()); + ctx.setAttribute("postResource_result", response.toString()); + } catch (SvcLogicException e) { + logger.error(EELFResourceManager.format(Msg.AAI_UPDATE_FAILED, resourceKey, att_value, e.getMessage())); + } + if (logger.isDebugEnabled()) { + logger.debug("exiting postResource======"); + } + } + + @Override public void deleteResource(Map params, SvcLogicContext ctx) throws APPCException { + initialize(); + String resourceType = params.get("resourceType"), resourceKey = params.get("resourceKey"); + + if (logger.isDebugEnabled()) { + logger.debug("inside deleteResource"); + logger.debug("Deleting " + resourceType + " details From A&AI for Key : " + resourceKey); + } + client = aaiService; + try { + SvcLogicResource.QueryStatus response = client.delete(resourceType, resourceKey, ctx); + logger.info("AAIResponse: " + response.toString()); + ctx.setAttribute("deleteResource_result", response.toString()); + } catch (SvcLogicException e) { + logger.error(EELFResourceManager.format(Msg.AAI_DELETE_FAILED, resourceKey, e.getMessage())); + } + if (logger.isDebugEnabled()) { + logger.debug("exiting deleteResource======"); + } + } + + @Override public void getVnfHierarchy(Map params, SvcLogicContext ctx) throws APPCException { + if (logger.isDebugEnabled()) { + logger.debug("Inside getVnfHierarchy======"); + } + //String ctx_prefix = params.get("prefix"); + String resourceKey = params.get("resourceKey"); + // String retrivalVnfKey = "vnf-id = '" + resourceKey + "' AND relationship-key = 'vserver.vserver-id'"; + String retrivalVnfKey = "generic-vnf.vnf-id = '" + resourceKey + "'"; + Map paramsVnf = new HashMap(); + paramsVnf.put("resourceType", "generic-vnf"); + paramsVnf.put("prefix", "vnfRetrived"); + paramsVnf.put("resourceKey", retrivalVnfKey); + logger.debug("Retrieving VNF details from A&AI"); + //Retrive all the relations of VNF + SvcLogicContext vnfCtx = new SvcLogicContext(); + getResource(paramsVnf, vnfCtx); + if (vnfCtx.getAttribute("getResource_result").equals("SUCCESS")) { + if (vnfCtx.getAttribute("vnfRetrived.heat-stack-id") != null) { + ctx.setAttribute("VNF.heat-stack-id", vnfCtx.getAttribute("vnfRetrived.heat-stack-id")); + } + ctx.setAttribute("vnf.type",vnfCtx.getAttribute("vnfRetrived.vnf-type")); + Map vnfHierarchyMap = new ConcurrentHashMap(); + + Map> vnfcHierarchyMap = new HashMap>(); + int vmCount = 0; + int vnfcCount = 0; + Set vmSet = null; + String vmURL = ""; + logger.debug("Parsing Vserver details from VNF relations"); + for (String ctxKeySet : vnfCtx + .getAttributeKeySet()) { //loop through relationship-list data, to get vserver relations + if (ctxKeySet.startsWith("vnfRetrived.") && vnfCtx.getAttribute(ctxKeySet).equalsIgnoreCase("vserver")) { + String vmKey = ctxKeySet.substring(0, ctxKeySet.length() - "related-to".length()); + String vserverID = null; + String tenantID = null; + String cloudOwner = null; + String cloudRegionId = null; + int relationshipLength = 0; + if (vnfCtx.getAttributeKeySet().contains(vmKey + "relationship-data_length")) { + relationshipLength = Integer.parseInt(vnfCtx.getAttribute(vmKey + "relationship-data_length")); + } + + for (int j = 0; j + < relationshipLength; j++) { //loop inside relationship data, to get vserver-id and tenant-id + String key = vnfCtx.getAttribute(vmKey + "relationship-data[" + j + "].relationship-key"); + String value = vnfCtx.getAttribute(vmKey + "relationship-data[" + j + "].relationship-value"); + vnfHierarchyMap.put("VNF.VM[" + vmCount + "]." + key, value); + if ("vserver.vserver-id".equals(key)) { + vserverID = value; + } + if ("tenant.tenant-id".equals(key)) { + tenantID = value; + } + if ("cloud-region.cloud-owner".equals(key)) { + cloudOwner = value; + } + if ("cloud-region.cloud-region-id".equals(key)) { + cloudRegionId = value; + } + } + int relatedPropertyLength = 0; + if (vnfCtx.getAttributeKeySet().contains(vmKey + "related-to-property_length")) { + relatedPropertyLength = + Integer.parseInt(vnfCtx.getAttribute(vmKey + "related-to-property_length")); + } + for (int j = 0; + j < relatedPropertyLength; j++) { //loop inside related-to-property data, to get vserver-name + String key = vnfCtx.getAttribute(vmKey + "related-to-property[" + j + "].property-key"); + String value = vnfCtx.getAttribute(vmKey + "related-to-property[" + j + "].property-value"); + vnfHierarchyMap.put("VNF.VM[" + vmCount + "]." + key, value); + } + //Retrive VM relations to find vnfc's + //VM to VNFC is 1 to 1 relation + String vmRetrivalKey = "vserver.vserver-id = '" + vserverID + "' AND tenant.tenant_id = '" + tenantID + "'" + "' AND cloud-region.cloud-owner = '" + cloudOwner + "' AND cloud-region.cloud-region-id = '" + cloudRegionId + "'"; + Map paramsVm = new HashMap(); + paramsVm.put("resourceType", "vserver"); + paramsVm.put("prefix", "vmRetrived"); + paramsVm.put("resourceKey", vmRetrivalKey); + SvcLogicContext vmCtx = new SvcLogicContext(); + + logger.debug("Retrieving VM details from A&AI"); + getResource(paramsVm, vmCtx); + if (vmCtx.getAttribute("getResource_result").equals("SUCCESS")) { + if (logger.isDebugEnabled()) { + logger.debug("Parsing VNFC details from VM relations"); + } + vmURL = vmCtx.getAttribute("vmRetrived.vserver-selflink"); + vnfHierarchyMap.put("VNF.VM[" + vmCount + "].URL",vmURL); + for (String ctxVnfcKeySet : vmCtx + .getAttributeKeySet()) { //loop through relationship-list data, to get vnfc relations + if (ctxVnfcKeySet.startsWith("vmRetrived.") && vmCtx.getAttribute(ctxVnfcKeySet) + .equalsIgnoreCase("vnfc")) { + String vnfcKey = ctxVnfcKeySet.substring(0, + ctxVnfcKeySet.length() - "related-to".length()); + relationshipLength = 0; + if (vmCtx.getAttributeKeySet().contains(vnfcKey + "relationship-data_length")) { + relationshipLength = Integer.parseInt( + vmCtx.getAttribute(vnfcKey + "relationship-data_length")); + } + for (int j = 0; j + < relationshipLength; j++) { //loop through relationship data, to get vnfc name + String key = vmCtx.getAttribute( + vnfcKey + "relationship-data[" + j + "].relationship-key"); + String value = vmCtx.getAttribute( + vnfcKey + "relationship-data[" + j + "].relationship-value"); + if (key.equalsIgnoreCase("vnfc.vnfc-name")) { + vnfHierarchyMap.put("VNF.VM[" + vmCount + "].VNFC", value); + vmSet = vnfcHierarchyMap.get(value); + if(vmSet == null){ + vmSet = new HashSet<>(); + } + vmSet.add(vmURL); + vnfcHierarchyMap.put(value,vmSet); + break; //VM to VNFC is 1 to 1 relation, once we got the VNFC name we can break the loop + } + } + } + } + } else { + ctx.setAttribute(DG_OUTPUT_STATUS_MESSAGE, "Error Retrieving VNFC hierarchy"); + vnfHierarchyMap.put("getVnfHierarchy_result", "FAILURE"); + logger.error("Failed in getVnfHierarchy, Error retrieving Vserver details. Error message: " + + vmCtx.getAttribute("getResource_result")); + logger.warn("Incorrect or Incomplete VNF Hierarchy"); + throw new APPCException("Error Retrieving VNFC hierarchy"); + } + vmCount++; + } + } + vnfHierarchyMap.put("VNF.VMCount", vmCount + ""); + if (vmCount == 0) { + ctx.setAttribute(DG_OUTPUT_STATUS_MESSAGE, "VM count is 0"); + } + //code changes for getting vnfcs hirearchy + populateVnfcsDetailsinContext(vnfcHierarchyMap,ctx); + //vnf,vnfcCount + ctx.setAttribute("VNF.VNFCCount", + Integer.toString(vnfcHierarchyMap.size())); + //code changes for getting vnfcs hirearchy + ctx.setAttribute("getVnfHierarchy_result", "SUCCESS"); + //Finally set all attributes to ctx + for (String attribute : vnfHierarchyMap.keySet()) { + ctx.setAttribute(attribute, vnfHierarchyMap.get(attribute)); + } + } else { + ctx.setAttribute("getVnfHierarchy_result", "FAILURE"); + ctx.setAttribute(DG_OUTPUT_STATUS_MESSAGE, "Error Retrieving VNFC hierarchy"); + logger.error("Failed in getVnfHierarchy, Error retrieving VNF details. Error message: " + ctx + .getAttribute("getResource_result")); + logger.warn("Incorrect or Incomplete VNF Hierarchy"); + throw new APPCException("Error Retrieving VNFC hierarchy"); + } + if (logger.isDebugEnabled()) { + logger.debug("exiting getVnfHierarchy======"); + } + } + + private void populateVnfcsDetailsinContext(Map> vnfcHierarchyMap, SvcLogicContext ctx) throws APPCException { +// int vnfcCount = vnfcHierarchyMap.size(); + SvcLogicContext vnfcCtx = new SvcLogicContext(); + int vnfcCounter = 0; + for (String vnfcName : vnfcHierarchyMap.keySet()) { + String vnfcRetrivalKey = "vnfc-name = '" + vnfcName + "'"; + Map paramsVnfc = new HashMap(); + paramsVnfc.put("resourceType", "vnfc"); + paramsVnfc.put("prefix", "vnfcRetrived"); + paramsVnfc.put("resourceKey", vnfcRetrivalKey); + + logger.debug("Retrieving VM details from A&AI"); + getResource(paramsVnfc, vnfcCtx); + if (vnfcCtx.getAttribute("getResource_result").equals("SUCCESS")) { + if (logger.isDebugEnabled()) { + logger.debug("Parsing VNFC details from VM relations"); + } + //putting required values in the map + //vnf.vnfc[vnfcIndex].type + ctx.setAttribute("VNF.VNFC[" + vnfcCounter + "].TYPE", + vnfcCtx.getAttribute("vnfcRetrived.vnfc-type")); + + // vnf.vnfc[vnfcIndex].name + ctx.setAttribute("VNF.VNFC[" + vnfcCounter + "].NAME", + vnfcCtx.getAttribute("vnfcRetrived.vnfc-name")); + + //vnf.vnfc[vnfcIndex].vmCount + Set vmSet = vnfcHierarchyMap.get(vnfcName); + String vmCountinVnfcs = Integer.toString(vmSet.size()); + ctx.setAttribute("VNF.VNFC[" + vnfcCounter + "].VM_COUNT", + vmCountinVnfcs); + int vmCount =0; + for(String vmURL:vmSet){ + ctx.setAttribute("VNF.VNFC[" + vnfcCounter + "].VM[" + vmCount++ + "].URL",vmURL); + } + + } + vnfcCounter++; + } + } +} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/InputParameterValidationImpl.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/InputParameterValidationImpl.java new file mode 100644 index 000000000..5ea48bf44 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/InputParameterValidationImpl.java @@ -0,0 +1,136 @@ +/*- + * ============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.dg.util.impl; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +import org.onap.appc.dg.util.InputParameterValidation; +import org.onap.appc.exceptions.APPCException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + + + +public class InputParameterValidationImpl implements InputParameterValidation +{ + private static final char NL = '\n'; + private static final EELFLogger logger = EELFManager.getInstance().getLogger(InputParameterValidationImpl.class); + + public InputParameterValidationImpl() { + } + + + @SuppressWarnings("nls") + @Override + public void validateAttribute(Map params, SvcLogicContext ctx) throws APPCException { + Map contextParams=getValueFromContext(ctx); + boolean isSuccess = true; + try { + for (String k : params.keySet()) { + logger.info("validating attribute " + k); + if (!contextParams.containsKey(k)) { + logger.info("missing attribute " + k); + isSuccess =false; + } + if(contextParams.get(k)==null){ + logger.info("mandatory attribute " + k+ "is null"); + isSuccess =false; + } + } + }catch (NullPointerException np) { + isSuccess =false; + } + ctx.setAttribute("validateAttribute", String.valueOf(isSuccess)); + } + + @SuppressWarnings("nls") + @Override + public void validateAttributeLength(Map params, SvcLogicContext ctx) throws APPCException { + Map contextParams=getValueFromContext(ctx); + boolean isSuccess =true; + try { + int maxLength = Integer.parseInt(params.get("maximum_length_param")); + params.remove("maximum_length_param"); + + for (String k : params.keySet()) { + logger.info("validating attribute " + k); + if(contextParams.get(k).length() > maxLength){ + logger.info("attribute " + k+ "'s length is exceeding Maximum limit of " + maxLength +" character"); + isSuccess=false; + } + } + }catch (NullPointerException np) { + isSuccess=false; + } + ctx.setAttribute("validateAttributeLength", String.valueOf(isSuccess)); + } + + @SuppressWarnings("nls") + @Override + public void validateAttributeCharacter(Map params, SvcLogicContext ctx) throws APPCException { + Map contextParams=getValueFromContext(ctx); + boolean isSuccess =true; + try { + String specialCharacter = params.get("special_characters"); + String pattern = ".*[" + Pattern.quote(specialCharacter) + "].*"; + params.remove("special_characters"); + + for (String k : params.keySet()) { + logger.info("validating attribute " + k); + if(contextParams.get(k).matches(pattern)){ + logger.info("attribute " + k + " contains any of these " + specialCharacter + " special character "); + isSuccess =false; + } + + } + }catch (NullPointerException np) { + isSuccess =false; + } + ctx.setAttribute("validateAttributeCharacter", String.valueOf(isSuccess)); + } + + + private Map getValueFromContext(SvcLogicContext context) { + Set keys = context.getAttributeKeySet(); + Map params = new HashMap(); + StringBuilder builder = new StringBuilder(); + if (keys != null && !keys.isEmpty()) { + builder.append(NL); + for (String key : keys) { + String value = context.getAttribute(key); + params.put(key,value); + + } + } + return params; + + } + + +} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImpl.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImpl.java new file mode 100644 index 000000000..a7e650e9f --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImpl.java @@ -0,0 +1,50 @@ +/*- + * ============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.dg.util.impl; + +import java.util.Map; + +import org.onap.appc.dg.util.UpgradeStubNode; +import org.onap.appc.exceptions.APPCException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + + +public class UpgradeStubNodeImpl implements UpgradeStubNode { + + public static final String FAILURE_INDICATOR_FIELD_NAME = "failureIndicator"; + private static final EELFLogger logger = EELFManager.getInstance().getLogger(UpgradeStubNodeImpl.class); + + @Override + public void handleUpgradeStub(Map params, SvcLogicContext ctx) throws APPCException { + logger.debug("Entering in handleUpgradeStub : "+ params.toString()); + String failureInd = params.get(FAILURE_INDICATOR_FIELD_NAME); + if (null != failureInd && Boolean.valueOf(failureInd)){ + throw new APPCException("Simulating exception..."); + } + logger.info("Simulating was successful"); + } +} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/AppcDgUtilActivator.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/AppcDgUtilActivator.java deleted file mode 100644 index 486d475f4..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/AppcDgUtilActivator.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========================================================= - */ - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ -package org.onap.appc.dg.util; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -public class AppcDgUtilActivator implements BundleActivator { - - public void start(BundleContext context) { - System.out.println("Starting the bundle"); - } - - public void stop(BundleContext context) { - System.out.println("Stopping the bundle"); - } - -} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/ExecuteNodeAction.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/ExecuteNodeAction.java deleted file mode 100644 index 38bc0955d..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/ExecuteNodeAction.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.dg.util; - -import java.util.Map; - -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - - -public interface ExecuteNodeAction extends SvcLogicJavaPlugin { - void getResource(Map params, SvcLogicContext ctx) throws APPCException; - - void postResource(Map params, SvcLogicContext ctx) throws APPCException; - - void deleteResource(Map params, SvcLogicContext ctx) throws APPCException; - - void getVnfHierarchy(Map params, SvcLogicContext ctx) throws APPCException; - void waitMethod(Map params, SvcLogicContext ctx) throws APPCException; -} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/InputParameterValidation.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/InputParameterValidation.java deleted file mode 100644 index 714e12a03..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/InputParameterValidation.java +++ /dev/null @@ -1,42 +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.dg.util; - -import java.util.Map; - -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - - -public interface InputParameterValidation extends SvcLogicJavaPlugin { - - void validateAttribute(Map params, SvcLogicContext ctx) throws APPCException; - - void validateAttributeLength(Map params, SvcLogicContext ctx) throws APPCException; - - void validateAttributeCharacter(Map params, SvcLogicContext ctx) throws APPCException; - -} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/UpgradeStubNode.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/UpgradeStubNode.java deleted file mode 100644 index 4f0a80f5a..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/UpgradeStubNode.java +++ /dev/null @@ -1,36 +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.dg.util; - -import java.util.Map; - -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - - -public interface UpgradeStubNode extends SvcLogicJavaPlugin { - void handleUpgradeStub(Map params, SvcLogicContext ctx) throws APPCException; -} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImpl.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImpl.java deleted file mode 100644 index b5dc40712..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImpl.java +++ /dev/null @@ -1,362 +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.dg.util.impl; - -import org.onap.appc.dg.util.ExecuteNodeAction; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.i18n.Msg; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.att.eelf.i18n.EELFResourceManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; -import org.onap.ccsdk.sli.adaptors.aai.AAIService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - - -public class ExecuteNodeActionImpl implements ExecuteNodeAction { - - private AAIService aaiService; - protected static AAIClient client; - private static final EELFLogger logger = EELFManager.getInstance().getLogger(ExecuteNodeActionImpl.class); - - public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message"; - public ExecuteNodeActionImpl() { - } - - /** - * initialize the SDNC adapter (AAIService) by building the context. - */ - private void initialize() { - getAAIservice(); - } - - private void getAAIservice() { - BundleContext bctx = FrameworkUtil.getBundle(AAIService.class).getBundleContext(); - // Get AAIadapter reference - ServiceReference sref = bctx.getServiceReference(AAIService.class.getName()); - if (sref != null) { - logger.info("AAIService from bundlecontext"); - aaiService = (AAIService) bctx.getService(sref); - - } else { - logger.info("AAIService error from bundlecontext"); - logger.error(EELFResourceManager.format(Msg.AAI_CONNECTION_FAILED, "AAIService")); - } - } - - /** - * Method called in TestDG to test timeout scenario - * - * @param params waitTime time in millisecond DG is going to sleep - * @param ctx - * @throws APPCException - */ - @Override public void waitMethod(Map params, SvcLogicContext ctx) throws APPCException { - try { - String waitTime = params.get("waitTime"); - - logger.info("DG will waits for " + Long.parseLong(waitTime) + "milliseconds"); - Thread.sleep(Long.parseLong(waitTime)); - logger.info("DG waits for " + Long.parseLong(waitTime) + " milliseconds completed"); - } catch (InterruptedException e) { - logger.error("Error In ExecuteNodeActionImpl for waitMethod() due to InterruptedException: reason = " + e.getMessage()); - } - } - - @Override public void getResource(Map params, SvcLogicContext ctx) throws APPCException { - initialize(); - String resourceType = params.get("resourceType"), ctx_prefix = params.get("prefix"), resourceKey = - params.get("resourceKey"); - if (logger.isDebugEnabled()) { - logger.debug("inside getResorce"); - logger.debug("Retrieving " + resourceType + " details from A&AI for Key : " + resourceKey); - } - client = aaiService; - try { - SvcLogicResource.QueryStatus response = - client.query(resourceType, false, null, resourceKey, ctx_prefix, null, ctx); - logger.info("AAIResponse: " + response.toString()); - ctx.setAttribute("getResource_result", response.toString()); - } catch (SvcLogicException e) { - logger.error(EELFResourceManager.format(Msg.AAI_GET_DATA_FAILED, resourceKey, "", e.getMessage())); - } - if (logger.isDebugEnabled()) { - logger.debug("exiting getResource======"); - } - } - - @Override public void postResource(Map params, SvcLogicContext ctx) throws APPCException { - initialize(); - String resourceType = params.get("resourceType"), ctx_prefix = params.get("prefix"), resourceKey = - params.get("resourceKey"), att_name = params.get("attributeName"), att_value = - params.get("attributeValue"); - if (logger.isDebugEnabled()) { - logger.debug("inside postResource"); - logger.debug("Updating " + resourceType + " details in A&AI for Key : " + resourceKey); - logger.debug("Updating " + att_name + " to : " + att_value); - } - Map data = new HashMap(); - data.put(att_name, att_value); - client = aaiService; - - try { - SvcLogicResource.QueryStatus response = client.update(resourceType, resourceKey, data, ctx_prefix, ctx); - logger.info("AAIResponse: " + response.toString()); - ctx.setAttribute("postResource_result", response.toString()); - } catch (SvcLogicException e) { - logger.error(EELFResourceManager.format(Msg.AAI_UPDATE_FAILED, resourceKey, att_value, e.getMessage())); - } - if (logger.isDebugEnabled()) { - logger.debug("exiting postResource======"); - } - } - - @Override public void deleteResource(Map params, SvcLogicContext ctx) throws APPCException { - initialize(); - String resourceType = params.get("resourceType"), resourceKey = params.get("resourceKey"); - - if (logger.isDebugEnabled()) { - logger.debug("inside deleteResource"); - logger.debug("Deleting " + resourceType + " details From A&AI for Key : " + resourceKey); - } - client = aaiService; - try { - SvcLogicResource.QueryStatus response = client.delete(resourceType, resourceKey, ctx); - logger.info("AAIResponse: " + response.toString()); - ctx.setAttribute("deleteResource_result", response.toString()); - } catch (SvcLogicException e) { - logger.error(EELFResourceManager.format(Msg.AAI_DELETE_FAILED, resourceKey, e.getMessage())); - } - if (logger.isDebugEnabled()) { - logger.debug("exiting deleteResource======"); - } - } - - @Override public void getVnfHierarchy(Map params, SvcLogicContext ctx) throws APPCException { - if (logger.isDebugEnabled()) { - logger.debug("Inside getVnfHierarchy======"); - } - //String ctx_prefix = params.get("prefix"); - String resourceKey = params.get("resourceKey"); - // String retrivalVnfKey = "vnf-id = '" + resourceKey + "' AND relationship-key = 'vserver.vserver-id'"; - String retrivalVnfKey = "generic-vnf.vnf-id = '" + resourceKey + "'"; - Map paramsVnf = new HashMap(); - paramsVnf.put("resourceType", "generic-vnf"); - paramsVnf.put("prefix", "vnfRetrived"); - paramsVnf.put("resourceKey", retrivalVnfKey); - logger.debug("Retrieving VNF details from A&AI"); - //Retrive all the relations of VNF - SvcLogicContext vnfCtx = new SvcLogicContext(); - getResource(paramsVnf, vnfCtx); - if (vnfCtx.getAttribute("getResource_result").equals("SUCCESS")) { - if (vnfCtx.getAttribute("vnfRetrived.heat-stack-id") != null) { - ctx.setAttribute("VNF.heat-stack-id", vnfCtx.getAttribute("vnfRetrived.heat-stack-id")); - } - ctx.setAttribute("vnf.type",vnfCtx.getAttribute("vnfRetrived.vnf-type")); - Map vnfHierarchyMap = new ConcurrentHashMap(); - - Map> vnfcHierarchyMap = new HashMap>(); - int vmCount = 0; - int vnfcCount = 0; - Set vmSet = null; - String vmURL = ""; - logger.debug("Parsing Vserver details from VNF relations"); - for (String ctxKeySet : vnfCtx - .getAttributeKeySet()) { //loop through relationship-list data, to get vserver relations - if (ctxKeySet.startsWith("vnfRetrived.") && vnfCtx.getAttribute(ctxKeySet).equalsIgnoreCase("vserver")) { - String vmKey = ctxKeySet.substring(0, ctxKeySet.length() - "related-to".length()); - String vserverID = null; - String tenantID = null; - String cloudOwner = null; - String cloudRegionId = null; - int relationshipLength = 0; - if (vnfCtx.getAttributeKeySet().contains(vmKey + "relationship-data_length")) { - relationshipLength = Integer.parseInt(vnfCtx.getAttribute(vmKey + "relationship-data_length")); - } - - for (int j = 0; j - < relationshipLength; j++) { //loop inside relationship data, to get vserver-id and tenant-id - String key = vnfCtx.getAttribute(vmKey + "relationship-data[" + j + "].relationship-key"); - String value = vnfCtx.getAttribute(vmKey + "relationship-data[" + j + "].relationship-value"); - vnfHierarchyMap.put("VNF.VM[" + vmCount + "]." + key, value); - if ("vserver.vserver-id".equals(key)) { - vserverID = value; - } - if ("tenant.tenant-id".equals(key)) { - tenantID = value; - } - if ("cloud-region.cloud-owner".equals(key)) { - cloudOwner = value; - } - if ("cloud-region.cloud-region-id".equals(key)) { - cloudRegionId = value; - } - } - int relatedPropertyLength = 0; - if (vnfCtx.getAttributeKeySet().contains(vmKey + "related-to-property_length")) { - relatedPropertyLength = - Integer.parseInt(vnfCtx.getAttribute(vmKey + "related-to-property_length")); - } - for (int j = 0; - j < relatedPropertyLength; j++) { //loop inside related-to-property data, to get vserver-name - String key = vnfCtx.getAttribute(vmKey + "related-to-property[" + j + "].property-key"); - String value = vnfCtx.getAttribute(vmKey + "related-to-property[" + j + "].property-value"); - vnfHierarchyMap.put("VNF.VM[" + vmCount + "]." + key, value); - } - //Retrive VM relations to find vnfc's - //VM to VNFC is 1 to 1 relation - String vmRetrivalKey = "vserver.vserver-id = '" + vserverID + "' AND tenant.tenant_id = '" + tenantID + "'" + "' AND cloud-region.cloud-owner = '" + cloudOwner + "' AND cloud-region.cloud-region-id = '" + cloudRegionId + "'"; - Map paramsVm = new HashMap(); - paramsVm.put("resourceType", "vserver"); - paramsVm.put("prefix", "vmRetrived"); - paramsVm.put("resourceKey", vmRetrivalKey); - SvcLogicContext vmCtx = new SvcLogicContext(); - - logger.debug("Retrieving VM details from A&AI"); - getResource(paramsVm, vmCtx); - if (vmCtx.getAttribute("getResource_result").equals("SUCCESS")) { - if (logger.isDebugEnabled()) { - logger.debug("Parsing VNFC details from VM relations"); - } - vmURL = vmCtx.getAttribute("vmRetrived.vserver-selflink"); - vnfHierarchyMap.put("VNF.VM[" + vmCount + "].URL",vmURL); - for (String ctxVnfcKeySet : vmCtx - .getAttributeKeySet()) { //loop through relationship-list data, to get vnfc relations - if (ctxVnfcKeySet.startsWith("vmRetrived.") && vmCtx.getAttribute(ctxVnfcKeySet) - .equalsIgnoreCase("vnfc")) { - String vnfcKey = ctxVnfcKeySet.substring(0, - ctxVnfcKeySet.length() - "related-to".length()); - relationshipLength = 0; - if (vmCtx.getAttributeKeySet().contains(vnfcKey + "relationship-data_length")) { - relationshipLength = Integer.parseInt( - vmCtx.getAttribute(vnfcKey + "relationship-data_length")); - } - for (int j = 0; j - < relationshipLength; j++) { //loop through relationship data, to get vnfc name - String key = vmCtx.getAttribute( - vnfcKey + "relationship-data[" + j + "].relationship-key"); - String value = vmCtx.getAttribute( - vnfcKey + "relationship-data[" + j + "].relationship-value"); - if (key.equalsIgnoreCase("vnfc.vnfc-name")) { - vnfHierarchyMap.put("VNF.VM[" + vmCount + "].VNFC", value); - vmSet = vnfcHierarchyMap.get(value); - if(vmSet == null){ - vmSet = new HashSet<>(); - } - vmSet.add(vmURL); - vnfcHierarchyMap.put(value,vmSet); - break; //VM to VNFC is 1 to 1 relation, once we got the VNFC name we can break the loop - } - } - } - } - } else { - ctx.setAttribute(DG_OUTPUT_STATUS_MESSAGE, "Error Retrieving VNFC hierarchy"); - vnfHierarchyMap.put("getVnfHierarchy_result", "FAILURE"); - logger.error("Failed in getVnfHierarchy, Error retrieving Vserver details. Error message: " - + vmCtx.getAttribute("getResource_result")); - logger.warn("Incorrect or Incomplete VNF Hierarchy"); - throw new APPCException("Error Retrieving VNFC hierarchy"); - } - vmCount++; - } - } - vnfHierarchyMap.put("VNF.VMCount", vmCount + ""); - if (vmCount == 0) { - ctx.setAttribute(DG_OUTPUT_STATUS_MESSAGE, "VM count is 0"); - } - //code changes for getting vnfcs hirearchy - populateVnfcsDetailsinContext(vnfcHierarchyMap,ctx); - //vnf,vnfcCount - ctx.setAttribute("VNF.VNFCCount", - Integer.toString(vnfcHierarchyMap.size())); - //code changes for getting vnfcs hirearchy - ctx.setAttribute("getVnfHierarchy_result", "SUCCESS"); - //Finally set all attributes to ctx - for (String attribute : vnfHierarchyMap.keySet()) { - ctx.setAttribute(attribute, vnfHierarchyMap.get(attribute)); - } - } else { - ctx.setAttribute("getVnfHierarchy_result", "FAILURE"); - ctx.setAttribute(DG_OUTPUT_STATUS_MESSAGE, "Error Retrieving VNFC hierarchy"); - logger.error("Failed in getVnfHierarchy, Error retrieving VNF details. Error message: " + ctx - .getAttribute("getResource_result")); - logger.warn("Incorrect or Incomplete VNF Hierarchy"); - throw new APPCException("Error Retrieving VNFC hierarchy"); - } - if (logger.isDebugEnabled()) { - logger.debug("exiting getVnfHierarchy======"); - } - } - - private void populateVnfcsDetailsinContext(Map> vnfcHierarchyMap, SvcLogicContext ctx) throws APPCException { -// int vnfcCount = vnfcHierarchyMap.size(); - SvcLogicContext vnfcCtx = new SvcLogicContext(); - int vnfcCounter = 0; - for (String vnfcName : vnfcHierarchyMap.keySet()) { - String vnfcRetrivalKey = "vnfc-name = '" + vnfcName + "'"; - Map paramsVnfc = new HashMap(); - paramsVnfc.put("resourceType", "vnfc"); - paramsVnfc.put("prefix", "vnfcRetrived"); - paramsVnfc.put("resourceKey", vnfcRetrivalKey); - - logger.debug("Retrieving VM details from A&AI"); - getResource(paramsVnfc, vnfcCtx); - if (vnfcCtx.getAttribute("getResource_result").equals("SUCCESS")) { - if (logger.isDebugEnabled()) { - logger.debug("Parsing VNFC details from VM relations"); - } - //putting required values in the map - //vnf.vnfc[vnfcIndex].type - ctx.setAttribute("VNF.VNFC[" + vnfcCounter + "].TYPE", - vnfcCtx.getAttribute("vnfcRetrived.vnfc-type")); - - // vnf.vnfc[vnfcIndex].name - ctx.setAttribute("VNF.VNFC[" + vnfcCounter + "].NAME", - vnfcCtx.getAttribute("vnfcRetrived.vnfc-name")); - - //vnf.vnfc[vnfcIndex].vmCount - Set vmSet = vnfcHierarchyMap.get(vnfcName); - String vmCountinVnfcs = Integer.toString(vmSet.size()); - ctx.setAttribute("VNF.VNFC[" + vnfcCounter + "].VM_COUNT", - vmCountinVnfcs); - int vmCount =0; - for(String vmURL:vmSet){ - ctx.setAttribute("VNF.VNFC[" + vnfcCounter + "].VM[" + vmCount++ + "].URL",vmURL); - } - - } - vnfcCounter++; - } - } -} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImpl.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImpl.java deleted file mode 100644 index 5ea48bf44..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImpl.java +++ /dev/null @@ -1,136 +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.dg.util.impl; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.regex.Pattern; - -import org.onap.appc.dg.util.InputParameterValidation; -import org.onap.appc.exceptions.APPCException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - - - -public class InputParameterValidationImpl implements InputParameterValidation -{ - private static final char NL = '\n'; - private static final EELFLogger logger = EELFManager.getInstance().getLogger(InputParameterValidationImpl.class); - - public InputParameterValidationImpl() { - } - - - @SuppressWarnings("nls") - @Override - public void validateAttribute(Map params, SvcLogicContext ctx) throws APPCException { - Map contextParams=getValueFromContext(ctx); - boolean isSuccess = true; - try { - for (String k : params.keySet()) { - logger.info("validating attribute " + k); - if (!contextParams.containsKey(k)) { - logger.info("missing attribute " + k); - isSuccess =false; - } - if(contextParams.get(k)==null){ - logger.info("mandatory attribute " + k+ "is null"); - isSuccess =false; - } - } - }catch (NullPointerException np) { - isSuccess =false; - } - ctx.setAttribute("validateAttribute", String.valueOf(isSuccess)); - } - - @SuppressWarnings("nls") - @Override - public void validateAttributeLength(Map params, SvcLogicContext ctx) throws APPCException { - Map contextParams=getValueFromContext(ctx); - boolean isSuccess =true; - try { - int maxLength = Integer.parseInt(params.get("maximum_length_param")); - params.remove("maximum_length_param"); - - for (String k : params.keySet()) { - logger.info("validating attribute " + k); - if(contextParams.get(k).length() > maxLength){ - logger.info("attribute " + k+ "'s length is exceeding Maximum limit of " + maxLength +" character"); - isSuccess=false; - } - } - }catch (NullPointerException np) { - isSuccess=false; - } - ctx.setAttribute("validateAttributeLength", String.valueOf(isSuccess)); - } - - @SuppressWarnings("nls") - @Override - public void validateAttributeCharacter(Map params, SvcLogicContext ctx) throws APPCException { - Map contextParams=getValueFromContext(ctx); - boolean isSuccess =true; - try { - String specialCharacter = params.get("special_characters"); - String pattern = ".*[" + Pattern.quote(specialCharacter) + "].*"; - params.remove("special_characters"); - - for (String k : params.keySet()) { - logger.info("validating attribute " + k); - if(contextParams.get(k).matches(pattern)){ - logger.info("attribute " + k + " contains any of these " + specialCharacter + " special character "); - isSuccess =false; - } - - } - }catch (NullPointerException np) { - isSuccess =false; - } - ctx.setAttribute("validateAttributeCharacter", String.valueOf(isSuccess)); - } - - - private Map getValueFromContext(SvcLogicContext context) { - Set keys = context.getAttributeKeySet(); - Map params = new HashMap(); - StringBuilder builder = new StringBuilder(); - if (keys != null && !keys.isEmpty()) { - builder.append(NL); - for (String key : keys) { - String value = context.getAttribute(key); - params.put(key,value); - - } - } - return params; - - } - - -} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImpl.java b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImpl.java deleted file mode 100644 index a7e650e9f..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImpl.java +++ /dev/null @@ -1,50 +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.dg.util.impl; - -import java.util.Map; - -import org.onap.appc.dg.util.UpgradeStubNode; -import org.onap.appc.exceptions.APPCException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - - -public class UpgradeStubNodeImpl implements UpgradeStubNode { - - public static final String FAILURE_INDICATOR_FIELD_NAME = "failureIndicator"; - private static final EELFLogger logger = EELFManager.getInstance().getLogger(UpgradeStubNodeImpl.class); - - @Override - public void handleUpgradeStub(Map params, SvcLogicContext ctx) throws APPCException { - logger.debug("Entering in handleUpgradeStub : "+ params.toString()); - String failureInd = params.get(FAILURE_INDICATOR_FIELD_NAME); - if (null != failureInd && Boolean.valueOf(failureInd)){ - throw new APPCException("Simulating exception..."); - } - logger.info("Simulating was successful"); - } -} diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/resources/org/onap/appc/default.properties b/appc-dg-util/appc-dg-util-bundle/src/main/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..0185c72a9 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/resources/org/onap/appc/default.properties @@ -0,0 +1,29 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= +### + +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. +# diff --git a/appc-dg-util/appc-dg-util-bundle/src/main/resources/org/openecomp/appc/default.properties b/appc-dg-util/appc-dg-util-bundle/src/main/resources/org/openecomp/appc/default.properties deleted file mode 100644 index 0185c72a9..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/main/resources/org/openecomp/appc/default.properties +++ /dev/null @@ -1,29 +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========================================================= -### - -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. -# diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java new file mode 100644 index 000000000..066863bb8 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java @@ -0,0 +1,59 @@ +/*- + * ============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.dg.util; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.osgi.framework.BundleContext; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class AppcDgUtilActivatorTest { + + @Mock + private BundleContext bundleContext; + + private AppcDgUtilActivator appcDgUtilActivator; + + @Before + public void setUp() throws Exception { + appcDgUtilActivator = new AppcDgUtilActivator(); + } + + @Test + public void start() { + appcDgUtilActivator.start(bundleContext); + PowerMockito.verifyStatic(); + } + + @Test + public void stop() { + appcDgUtilActivator.stop(bundleContext); + PowerMockito.verifyStatic(); + } +} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java new file mode 100644 index 000000000..3280cb954 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/ExecuteNodeActionImplTest.java @@ -0,0 +1,235 @@ +/*- + * ============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.dg.util.impl; + +import com.att.eelf.configuration.EELFLogger; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.appc.exceptions.APPCException; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.reflect.Whitebox; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyMap; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.verifyPrivate; +import static org.powermock.api.mockito.PowerMockito.verifyStatic; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ExecuteNodeActionImpl.class, FrameworkUtil.class, Thread.class}) +public class ExecuteNodeActionImplTest { + @Spy + private ExecuteNodeActionImpl mockedExecuteNodeActionImpl = new ExecuteNodeActionImpl(); + @Mock + private EELFLogger eelfLogger; + @Mock + private AAIService aaiService; + + private final String resourceType = "resourceType"; + private final String prefix = "prefix"; + private final String resourceKey = "resourceKey"; + private final String attributeName = "attributeName"; + private final String attributeValue = "attributeValue"; + + private Map params = new HashMap<>(); + private SvcLogicContext svcLogicContext = new SvcLogicContext(); + private SvcLogicResource.QueryStatus queryStatus = SvcLogicResource.QueryStatus.SUCCESS; + + + @Before + public void setUp() throws Exception { + Whitebox.setInternalState(mockedExecuteNodeActionImpl, "aaiService", aaiService); + + params.put("resourceType", resourceType); + params.put("prefix", prefix); + params.put("resourceKey", resourceKey); + params.put("attributeName", attributeName); + params.put("attributeValue", attributeValue); + } + + @Test + public void testInitialize() throws Exception { + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "getAAIservice"); + Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "initialize"); + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("getAAIservice"); + } + + @Test + public void testGetAAIservice() throws Exception { + // sref is not null + mockStatic(FrameworkUtil.class); + Bundle mockedBundle = mock(Bundle.class); + BundleContext mockedBundleContext = mock(BundleContext.class); + ServiceReference mockedServiceReference = mock(ServiceReference.class); + PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(mockedBundle); + PowerMockito.doReturn(mockedBundleContext).when(mockedBundle).getBundleContext(); + PowerMockito.doReturn(mockedServiceReference).when(mockedBundleContext) + .getServiceReference(AAIService.class.getName()); + + Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "getAAIservice"); + verify(mockedBundleContext, times(1)).getService(mockedServiceReference); + + // sref is null + PowerMockito.doReturn(null).when(mockedBundleContext) + .getServiceReference(AAIService.class.getName()); + Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "getAAIservice"); + verify(mockedBundleContext, times(1)).getService(mockedServiceReference); + } + + @Test + public void testWaitMethod() throws Exception { + mockStatic(Thread.class); + params.put("waitTime", "1"); + mockedExecuteNodeActionImpl.waitMethod(params, svcLogicContext); + verifyStatic(times(1)); + } + + @Test + public void testGetResource() throws Exception { + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.doReturn(queryStatus).when(aaiService).query(resourceType, false, null, + resourceKey, prefix, null, svcLogicContext); + + mockedExecuteNodeActionImpl.getResource(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + verify(aaiService, times(1)).query(resourceType, false, null, + resourceKey, prefix, null, svcLogicContext); + assertEquals(queryStatus.toString(), svcLogicContext.getAttribute("getResource_result")); + } + + @Test + public void testPostResource() throws Exception { + + + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.doReturn(queryStatus).when(aaiService).update(eq(resourceType), eq(resourceKey), anyMap(), + eq(prefix), eq(svcLogicContext)); + + mockedExecuteNodeActionImpl.postResource(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + verify(aaiService, times(1)).update(eq(resourceType), eq(resourceKey), anyMap(), + eq(prefix), eq(svcLogicContext)); + assertEquals(svcLogicContext.getAttribute("postResource_result"), queryStatus.toString()); + } + + @Test + public void testDeleteResource() throws Exception { + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + + PowerMockito.doReturn(queryStatus).when(aaiService).delete(eq(resourceType), eq(resourceKey), + eq(svcLogicContext)); + + mockedExecuteNodeActionImpl.deleteResource(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + verify(aaiService, times(1)).delete(eq(resourceType), eq(resourceKey), + eq(svcLogicContext)); + assertEquals(svcLogicContext.getAttribute("deleteResource_result"), queryStatus.toString()); + } + + @Test + public void testGetVnfHierarchySuccess() throws Exception { + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", anyMap(), eq + (svcLogicContext)); + PowerMockito.when(aaiService.query(any(), eq(false), anyString(), any(), any(), anyString(), + any(SvcLogicContext.class))).thenReturn(queryStatus); + + mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount")); + assertEquals("SUCCESS", svcLogicContext.getAttribute("getVnfHierarchy_result")); + } + + @Test(expected = APPCException.class) + public void testGetVnfHierarchyFailure() throws Exception { + queryStatus = SvcLogicResource.QueryStatus.FAILURE; + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", anyMap(), + eq(svcLogicContext)); + PowerMockito.when(aaiService.query(any(), eq(false), anyString(), any(), any(), anyString(), + any(SvcLogicContext.class))).thenReturn(queryStatus); + + mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext); + + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount")); + assertEquals("FAILURE", svcLogicContext.getAttribute("getVnfHierarchy_result")); + assertTrue(svcLogicContext.getAttribute("output.status.message") != null); + } + + @Test + public void testPopulateVnfcsDetailsinContext() throws Exception { + Map> vnfcHierarchyMap = new HashMap<>(); + Set vServersList = new HashSet<>(); + vnfcHierarchyMap.put("SMP", vServersList); + vServersList.add("smp-0-url"); + vServersList.add("smp-1-url"); + + PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); + PowerMockito.when(aaiService.query(eq("vnfc"), eq(false), anyString(), + eq("vnfc-name = 'SMP'"), eq("vnfcRetrived"), anyString(), any(SvcLogicContext.class))) + .thenReturn(queryStatus); + + Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", + vnfcHierarchyMap, svcLogicContext); + + verify(mockedExecuteNodeActionImpl, times(1)).getResource(anyMap(), + any(SvcLogicContext.class)); + verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); + assertEquals(null, svcLogicContext.getAttribute("VNF.VNFC[0].TYPE")); + assertEquals(null, svcLogicContext.getAttribute("VNF.VNFC[0].NAME")); + assertEquals("2", svcLogicContext.getAttribute("VNF.VNFC[0].VM_COUNT")); + assertTrue(vServersList.contains(svcLogicContext.getAttribute("VNF.VNFC[0].VM[0].URL"))); + assertTrue(vServersList.contains(svcLogicContext.getAttribute("VNF.VNFC[0].VM[1].URL"))); + } +} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/InputParameterValidationImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/InputParameterValidationImplTest.java new file mode 100644 index 000000000..405c1d92a --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/InputParameterValidationImplTest.java @@ -0,0 +1,165 @@ +/*- + * ============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.dg.util.impl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; +import org.powermock.reflect.Whitebox; + +import java.util.HashMap; +import java.util.Map; + +public class InputParameterValidationImplTest { + private SvcLogicContext svcLogicContext; + + private InputParameterValidationImpl inputParameterValidation; + + @Before + public void setUp() throws Exception { + inputParameterValidation = new InputParameterValidationImpl(); + svcLogicContext = new SvcLogicContext(); + svcLogicContext.setAttribute("a", "b"); + svcLogicContext.setAttribute("b", "c"); + } + + @Test + public void validateAttributeSuccess() throws Exception { + Map params = new HashMap<>(); + params.put("a", "b"); + params.put("b", "c"); + + inputParameterValidation.validateAttribute(params, svcLogicContext); + + Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttribute")); + } + + @Test + public void validateAttributeFailure() throws Exception { + // wrong value + Map params = new HashMap<>(); + params.put("e", "f"); + + inputParameterValidation.validateAttribute(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); + + // null value + params = new HashMap<>(); + params.put("e", null); + + inputParameterValidation.validateAttribute(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); + } + + @Test + public void validateAttributeNull() throws Exception { + inputParameterValidation.validateAttribute(null, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); + } + + @Test + public void validateAttributeLengthSuccess() throws Exception { + Map params = new HashMap<>(); + params.put("maximum_length_param", "2"); + params.put("a", "1"); + + inputParameterValidation.validateAttributeLength(params, svcLogicContext); + + Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeLength")); + } + + @Test + public void validateAttributeLengthFailure() throws Exception { + // wrong key + Map params = new HashMap<>(); + params.put("maximum_length_param", "2"); + params.put("e", "1"); + + inputParameterValidation.validateAttributeLength(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); + + //over length + params = new HashMap<>(); + params.put("maximum_length_param", "2"); + params.put("c", "3"); + + inputParameterValidation.validateAttributeLength(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); + } + + @Test + public void validateAttributeLengthNull() throws Exception { + inputParameterValidation.validateAttributeLength(null, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); + } + + @Test + public void validateAttributeCharacterSuccess() throws Exception { + Map params = new HashMap<>(); + params.put("special_characters", "z"); + params.put("a", "1"); + + inputParameterValidation.validateAttributeCharacter(params, svcLogicContext); + + Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeCharacter")); + } + + @Test + public void validateAttributeCharacterFailure() throws Exception { + Map params = new HashMap<>(); + params.put("special_characters", "z"); + params.put("d", "1"); + + inputParameterValidation.validateAttributeCharacter(params, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter")); + } + + @Test + public void validateAttributeCharacterNull() throws Exception { + inputParameterValidation.validateAttributeCharacter(null, svcLogicContext); + + Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter")); + } + + @Test + public void testGetValueFromContext() throws Exception { + Map result = Whitebox.invokeMethod(inputParameterValidation, "getValueFromContext", + svcLogicContext); + Assert.assertEquals("b", result.get("a")); + Assert.assertEquals("c", result.get("b")); + } +} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java new file mode 100644 index 000000000..6eb732064 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.dg.util.impl; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; + +import java.util.HashMap; +import java.util.Map; + +public class UpgradeStubNodeImplTest { + @Mock + private SvcLogicContext svcLogicContext; + + private UpgradeStubNodeImpl upgradeStubNode; + + @Before + public void setUp() throws Exception { + upgradeStubNode = new UpgradeStubNodeImpl(); + } + + @Test + public void testHandleUpgradeStubSuccess() throws APPCException { + Map params = new HashMap<>(); + upgradeStubNode.handleUpgradeStub(params, svcLogicContext); + } + + @Test(expected = APPCException.class) + public void testHandleUpgradeStubException() throws APPCException { + Map params = new HashMap<>(); + params.put("failureIndicator", "true"); + upgradeStubNode.handleUpgradeStub(params, svcLogicContext); + } +} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/AppcDgUtilActivatorTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/AppcDgUtilActivatorTest.java deleted file mode 100644 index 066863bb8..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/AppcDgUtilActivatorTest.java +++ /dev/null @@ -1,59 +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.dg.util; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.osgi.framework.BundleContext; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -public class AppcDgUtilActivatorTest { - - @Mock - private BundleContext bundleContext; - - private AppcDgUtilActivator appcDgUtilActivator; - - @Before - public void setUp() throws Exception { - appcDgUtilActivator = new AppcDgUtilActivator(); - } - - @Test - public void start() { - appcDgUtilActivator.start(bundleContext); - PowerMockito.verifyStatic(); - } - - @Test - public void stop() { - appcDgUtilActivator.stop(bundleContext); - PowerMockito.verifyStatic(); - } -} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImplTest.java deleted file mode 100644 index 3280cb954..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImplTest.java +++ /dev/null @@ -1,235 +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.dg.util.impl; - -import com.att.eelf.configuration.EELFLogger; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Spy; -import org.onap.ccsdk.sli.adaptors.aai.AAIService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.appc.exceptions.APPCException; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.verifyPrivate; -import static org.powermock.api.mockito.PowerMockito.verifyStatic; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ExecuteNodeActionImpl.class, FrameworkUtil.class, Thread.class}) -public class ExecuteNodeActionImplTest { - @Spy - private ExecuteNodeActionImpl mockedExecuteNodeActionImpl = new ExecuteNodeActionImpl(); - @Mock - private EELFLogger eelfLogger; - @Mock - private AAIService aaiService; - - private final String resourceType = "resourceType"; - private final String prefix = "prefix"; - private final String resourceKey = "resourceKey"; - private final String attributeName = "attributeName"; - private final String attributeValue = "attributeValue"; - - private Map params = new HashMap<>(); - private SvcLogicContext svcLogicContext = new SvcLogicContext(); - private SvcLogicResource.QueryStatus queryStatus = SvcLogicResource.QueryStatus.SUCCESS; - - - @Before - public void setUp() throws Exception { - Whitebox.setInternalState(mockedExecuteNodeActionImpl, "aaiService", aaiService); - - params.put("resourceType", resourceType); - params.put("prefix", prefix); - params.put("resourceKey", resourceKey); - params.put("attributeName", attributeName); - params.put("attributeValue", attributeValue); - } - - @Test - public void testInitialize() throws Exception { - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "getAAIservice"); - Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "initialize"); - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("getAAIservice"); - } - - @Test - public void testGetAAIservice() throws Exception { - // sref is not null - mockStatic(FrameworkUtil.class); - Bundle mockedBundle = mock(Bundle.class); - BundleContext mockedBundleContext = mock(BundleContext.class); - ServiceReference mockedServiceReference = mock(ServiceReference.class); - PowerMockito.when(FrameworkUtil.getBundle(AAIService.class)).thenReturn(mockedBundle); - PowerMockito.doReturn(mockedBundleContext).when(mockedBundle).getBundleContext(); - PowerMockito.doReturn(mockedServiceReference).when(mockedBundleContext) - .getServiceReference(AAIService.class.getName()); - - Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "getAAIservice"); - verify(mockedBundleContext, times(1)).getService(mockedServiceReference); - - // sref is null - PowerMockito.doReturn(null).when(mockedBundleContext) - .getServiceReference(AAIService.class.getName()); - Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "getAAIservice"); - verify(mockedBundleContext, times(1)).getService(mockedServiceReference); - } - - @Test - public void testWaitMethod() throws Exception { - mockStatic(Thread.class); - params.put("waitTime", "1"); - mockedExecuteNodeActionImpl.waitMethod(params, svcLogicContext); - verifyStatic(times(1)); - } - - @Test - public void testGetResource() throws Exception { - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.doReturn(queryStatus).when(aaiService).query(resourceType, false, null, - resourceKey, prefix, null, svcLogicContext); - - mockedExecuteNodeActionImpl.getResource(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - verify(aaiService, times(1)).query(resourceType, false, null, - resourceKey, prefix, null, svcLogicContext); - assertEquals(queryStatus.toString(), svcLogicContext.getAttribute("getResource_result")); - } - - @Test - public void testPostResource() throws Exception { - - - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.doReturn(queryStatus).when(aaiService).update(eq(resourceType), eq(resourceKey), anyMap(), - eq(prefix), eq(svcLogicContext)); - - mockedExecuteNodeActionImpl.postResource(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - verify(aaiService, times(1)).update(eq(resourceType), eq(resourceKey), anyMap(), - eq(prefix), eq(svcLogicContext)); - assertEquals(svcLogicContext.getAttribute("postResource_result"), queryStatus.toString()); - } - - @Test - public void testDeleteResource() throws Exception { - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - - PowerMockito.doReturn(queryStatus).when(aaiService).delete(eq(resourceType), eq(resourceKey), - eq(svcLogicContext)); - - mockedExecuteNodeActionImpl.deleteResource(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - verify(aaiService, times(1)).delete(eq(resourceType), eq(resourceKey), - eq(svcLogicContext)); - assertEquals(svcLogicContext.getAttribute("deleteResource_result"), queryStatus.toString()); - } - - @Test - public void testGetVnfHierarchySuccess() throws Exception { - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", anyMap(), eq - (svcLogicContext)); - PowerMockito.when(aaiService.query(any(), eq(false), anyString(), any(), any(), anyString(), - any(SvcLogicContext.class))).thenReturn(queryStatus); - - mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount")); - assertEquals("SUCCESS", svcLogicContext.getAttribute("getVnfHierarchy_result")); - } - - @Test(expected = APPCException.class) - public void testGetVnfHierarchyFailure() throws Exception { - queryStatus = SvcLogicResource.QueryStatus.FAILURE; - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", anyMap(), - eq(svcLogicContext)); - PowerMockito.when(aaiService.query(any(), eq(false), anyString(), any(), any(), anyString(), - any(SvcLogicContext.class))).thenReturn(queryStatus); - - mockedExecuteNodeActionImpl.getVnfHierarchy(params, svcLogicContext); - - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - assertEquals("0", svcLogicContext.getAttribute("VNF.VNFCCount")); - assertEquals("FAILURE", svcLogicContext.getAttribute("getVnfHierarchy_result")); - assertTrue(svcLogicContext.getAttribute("output.status.message") != null); - } - - @Test - public void testPopulateVnfcsDetailsinContext() throws Exception { - Map> vnfcHierarchyMap = new HashMap<>(); - Set vServersList = new HashSet<>(); - vnfcHierarchyMap.put("SMP", vServersList); - vServersList.add("smp-0-url"); - vServersList.add("smp-1-url"); - - PowerMockito.doNothing().when(mockedExecuteNodeActionImpl, "initialize"); - PowerMockito.when(aaiService.query(eq("vnfc"), eq(false), anyString(), - eq("vnfc-name = 'SMP'"), eq("vnfcRetrived"), anyString(), any(SvcLogicContext.class))) - .thenReturn(queryStatus); - - Whitebox.invokeMethod(mockedExecuteNodeActionImpl, "populateVnfcsDetailsinContext", - vnfcHierarchyMap, svcLogicContext); - - verify(mockedExecuteNodeActionImpl, times(1)).getResource(anyMap(), - any(SvcLogicContext.class)); - verifyPrivate(mockedExecuteNodeActionImpl, times(1)).invoke("initialize"); - assertEquals(null, svcLogicContext.getAttribute("VNF.VNFC[0].TYPE")); - assertEquals(null, svcLogicContext.getAttribute("VNF.VNFC[0].NAME")); - assertEquals("2", svcLogicContext.getAttribute("VNF.VNFC[0].VM_COUNT")); - assertTrue(vServersList.contains(svcLogicContext.getAttribute("VNF.VNFC[0].VM[0].URL"))); - assertTrue(vServersList.contains(svcLogicContext.getAttribute("VNF.VNFC[0].VM[1].URL"))); - } -} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImplTest.java deleted file mode 100644 index 405c1d92a..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImplTest.java +++ /dev/null @@ -1,165 +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.dg.util.impl; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; -import org.onap.ccsdk.sli.adaptors.aai.AAIService; -import org.powermock.reflect.Whitebox; - -import java.util.HashMap; -import java.util.Map; - -public class InputParameterValidationImplTest { - private SvcLogicContext svcLogicContext; - - private InputParameterValidationImpl inputParameterValidation; - - @Before - public void setUp() throws Exception { - inputParameterValidation = new InputParameterValidationImpl(); - svcLogicContext = new SvcLogicContext(); - svcLogicContext.setAttribute("a", "b"); - svcLogicContext.setAttribute("b", "c"); - } - - @Test - public void validateAttributeSuccess() throws Exception { - Map params = new HashMap<>(); - params.put("a", "b"); - params.put("b", "c"); - - inputParameterValidation.validateAttribute(params, svcLogicContext); - - Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttribute")); - } - - @Test - public void validateAttributeFailure() throws Exception { - // wrong value - Map params = new HashMap<>(); - params.put("e", "f"); - - inputParameterValidation.validateAttribute(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); - - // null value - params = new HashMap<>(); - params.put("e", null); - - inputParameterValidation.validateAttribute(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); - } - - @Test - public void validateAttributeNull() throws Exception { - inputParameterValidation.validateAttribute(null, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttribute")); - } - - @Test - public void validateAttributeLengthSuccess() throws Exception { - Map params = new HashMap<>(); - params.put("maximum_length_param", "2"); - params.put("a", "1"); - - inputParameterValidation.validateAttributeLength(params, svcLogicContext); - - Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeLength")); - } - - @Test - public void validateAttributeLengthFailure() throws Exception { - // wrong key - Map params = new HashMap<>(); - params.put("maximum_length_param", "2"); - params.put("e", "1"); - - inputParameterValidation.validateAttributeLength(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); - - //over length - params = new HashMap<>(); - params.put("maximum_length_param", "2"); - params.put("c", "3"); - - inputParameterValidation.validateAttributeLength(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); - } - - @Test - public void validateAttributeLengthNull() throws Exception { - inputParameterValidation.validateAttributeLength(null, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeLength")); - } - - @Test - public void validateAttributeCharacterSuccess() throws Exception { - Map params = new HashMap<>(); - params.put("special_characters", "z"); - params.put("a", "1"); - - inputParameterValidation.validateAttributeCharacter(params, svcLogicContext); - - Assert.assertEquals("true", svcLogicContext.getAttribute("validateAttributeCharacter")); - } - - @Test - public void validateAttributeCharacterFailure() throws Exception { - Map params = new HashMap<>(); - params.put("special_characters", "z"); - params.put("d", "1"); - - inputParameterValidation.validateAttributeCharacter(params, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter")); - } - - @Test - public void validateAttributeCharacterNull() throws Exception { - inputParameterValidation.validateAttributeCharacter(null, svcLogicContext); - - Assert.assertEquals("false", svcLogicContext.getAttribute("validateAttributeCharacter")); - } - - @Test - public void testGetValueFromContext() throws Exception { - Map result = Whitebox.invokeMethod(inputParameterValidation, "getValueFromContext", - svcLogicContext); - Assert.assertEquals("b", result.get("a")); - Assert.assertEquals("c", result.get("b")); - } -} \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImplTest.java deleted file mode 100644 index 6eb732064..000000000 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImplTest.java +++ /dev/null @@ -1,63 +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.dg.util.impl; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; -import org.onap.ccsdk.sli.adaptors.aai.AAIService; - -import java.util.HashMap; -import java.util.Map; - -public class UpgradeStubNodeImplTest { - @Mock - private SvcLogicContext svcLogicContext; - - private UpgradeStubNodeImpl upgradeStubNode; - - @Before - public void setUp() throws Exception { - upgradeStubNode = new UpgradeStubNodeImpl(); - } - - @Test - public void testHandleUpgradeStubSuccess() throws APPCException { - Map params = new HashMap<>(); - upgradeStubNode.handleUpgradeStub(params, svcLogicContext); - } - - @Test(expected = APPCException.class) - public void testHandleUpgradeStubException() throws APPCException { - Map params = new HashMap<>(); - params.put("failureIndicator", "true"); - upgradeStubNode.handleUpgradeStub(params, svcLogicContext); - } -} \ No newline at end of file -- cgit 1.2.3-korg