From 1c192d2dd68724e292b6a30f463085a262e1e813 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 15 Feb 2017 23:11:26 -0800 Subject: Moving all files to root directory Change-Id: Ica5535fd6ec85f350fe1640b42137b49f83f10f0 Signed-off-by: Patrick Brady --- appc-dg-util/appc-dg-util-bundle/.gitignore | 1 + .../org.eclipse.wst.common.project.facet.core.xml | 4 + appc-dg-util/appc-dg-util-bundle/pom.xml | 207 +++++++++++++++ .../appc/dg/util/AppcDgUtilActivator.java | 55 ++++ .../openecomp/appc/dg/util/ExecuteNodeAction.java | 40 +++ .../appc/dg/util/InputParameterValidation.java | 39 +++ .../openecomp/appc/dg/util/UpgradeStubNode.java | 33 +++ .../appc/dg/util/impl/ExecuteNodeActionImpl.java | 293 +++++++++++++++++++++ .../dg/util/impl/InputParameterValidationImpl.java | 133 ++++++++++ .../appc/dg/util/impl/UpgradeStubNodeImpl.java | 47 ++++ .../resources/OSGI-INF/blueprint/blueprint.xml | 56 ++++ .../org/openecomp/appc/default.properties | 26 ++ 12 files changed, 934 insertions(+) create mode 100644 appc-dg-util/appc-dg-util-bundle/.gitignore create mode 100644 appc-dg-util/appc-dg-util-bundle/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 appc-dg-util/appc-dg-util-bundle/pom.xml create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/AppcDgUtilActivator.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/ExecuteNodeAction.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/InputParameterValidation.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/UpgradeStubNode.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImpl.java create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImpl.java create 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/OSGI-INF/blueprint/blueprint.xml create mode 100644 appc-dg-util/appc-dg-util-bundle/src/main/resources/org/openecomp/appc/default.properties (limited to 'appc-dg-util/appc-dg-util-bundle') diff --git a/appc-dg-util/appc-dg-util-bundle/.gitignore b/appc-dg-util/appc-dg-util-bundle/.gitignore new file mode 100644 index 000000000..b83d22266 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/appc-dg-util/appc-dg-util-bundle/.settings/org.eclipse.wst.common.project.facet.core.xml b/appc-dg-util/appc-dg-util-bundle/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 000000000..f4ef8aa0a --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/appc-dg-util/appc-dg-util-bundle/pom.xml b/appc-dg-util/appc-dg-util-bundle/pom.xml new file mode 100644 index 000000000..7d8f50df0 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/pom.xml @@ -0,0 +1,207 @@ + + + 4.0.0 + + org.openecomp.appc + appc-dg-util + 1.0.0 + + + appc-dg-util-bundle + bundle + appc-dg-util - bundle + + 4.9.1 + 1.6.0 + 1.3.1-Beryllium-SR1 + + + + + org.openecomp.appc + appc-common + ${project.version} + + + javax + javaee-api + 7.0 + + + + org.openecomp.sdnc.adaptors + aai-service-provider + + + + javax.ws.rs + javax.ws.rs-api + + + + + com.sun.jersey + jersey-client + + + + com.sun.jersey + jersey-json + + + + javax.xml.bind + jaxb-api + 2.1 + + + + javax.xml + jaxp-api + 1.4.2 + + + + + org.glassfish.jersey.core + jersey-common + 2.9.1 + + + + org.codehaus.jackson + jackson-jaxrs + 1.9.12 + + + + commons-codec + commons-codec + + + + org.apache.httpcomponents + httpclient + 4.5.1 + + + + junit + junit + test + + + org.openecomp.sdnc.core + sli-common + compile + + + + org.openecomp.sdnc.core + dblib-provider + + + + + + org.openecomp.sdnc.core + sli-provider + compile + + + + org.openecomp.sdnc.core + dblib-provider + + + + + + equinoxSDK381 + org.eclipse.osgi + + + + org.slf4j + slf4j-api + + + + org.slf4j + jcl-over-slf4j + + + + mysql + mysql-connector-java + 5.1.31 + jar + compile + + + + com.vmware + vijava + 5.1 + compile + + + + xerces + xerces + 2.4.0 + provided + + + + org.apache.httpcomponents + httpcore + ${apache.httpcomponents.version} + + + + commons-logging + commons-logging + 1.2 + + + + org.json + json + + + + org.openecomp.appc + appc-dmaap-adapter-bundle + ${project.version} + + + org.openecomp.appc + appc-netconf-adapter-bundle + + 1.0.0 + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + appc-dg-util + org.openecomp.appc.dg.util.AppcDgUtilActivator + org.openecomp.appc.dg.util.* + org.openecomp.appc.adapter.netconf,org.openecomp.appc.adapter.netconf.dao,org.openecomp.appc.adapter.netconf.util,org.openecomp.appc.adapter.netconf.exception,org.openecomp.appc.adapter.dmaap.*,org.openecomp.sdnc.sli.*,org.osgi.framework.*,org.slf4j.*,com.vmware.*,org.apache.xerces.*,javax.net.*,javax.net.ssl.*,org.xml.sax.*,javax.xml.bind.*,javax.naming.*,com.fasterxml.*,javax.xml.parsersn + appc-common,eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false + true + + + + + + + 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 new file mode 100644 index 000000000..50265183f --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/AppcDgUtilActivator.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* + * 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.openecomp.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 new file mode 100644 index 000000000..27f92a4a9 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/ExecuteNodeAction.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.util; + +import java.util.Map; + +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.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 new file mode 100644 index 000000000..5d436db9c --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/InputParameterValidation.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.util; + +import java.util.Map; + +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.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 new file mode 100644 index 000000000..6b7cab862 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/UpgradeStubNode.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.util; + +import java.util.Map; + +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.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 new file mode 100644 index 000000000..e2097a0c0 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/ExecuteNodeActionImpl.java @@ -0,0 +1,293 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.util.impl; + +import org.openecomp.appc.adapter.netconf.util.Constants; +import org.openecomp.appc.dg.util.ExecuteNodeAction; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.i18n.Msg; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicException; +import org.openecomp.sdnc.sli.SvcLogicResource; +import org.openecomp.sdnc.sli.aai.AAIClient; +import org.openecomp.sdnc.sli.aai.AAIService; +import org.openecomp.sdnc.sli.provider.ExecuteNodeExecutor; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; + +import java.util.HashMap; +import java.util.Map; +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 ExecuteNodeActionImpl() { + // getAAIservice(); + } + + /** + * 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, sref.toString())); + } + } + + /** + * 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) { + e.printStackTrace(); + } + } + + @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'"; + Map paramsVnf = new HashMap(); + paramsVnf.put("resourceType", "generic-vnf:relationship-list"); + paramsVnf.put("prefix", "vnfRetrived"); + paramsVnf.put("resourceKey", retrivalVnfKey); + logger.debug("Retrieving VNF details from A&AI"); + //Retrive all the relations of VNF + getResource(paramsVnf, ctx); + if (ctx.getAttribute("getResource_result").equals("SUCCESS")) { + if (ctx.getAttribute("vnfRetrived.heat-stack-id") != null) { + ctx.setAttribute("VNF.heat-stack-id", ctx.getAttribute("vnfRetrived.heat-stack-id")); + } + Map vnfHierarchyMap = new ConcurrentHashMap(); + int vmCount = 0; + logger.debug("Parsing Vserver details from VNF relations"); + for (String ctxKeySet : ctx + .getAttributeKeySet()) { //loop through relationship-list data, to get vserver relations + if (ctxKeySet.startsWith("vnfRetrived.") && ctx.getAttribute(ctxKeySet).equalsIgnoreCase("vserver")) { + String vmKey = ctxKeySet.substring(0, ctxKeySet.length() - "related-to".length()); + String vserverID = null; + String tenantID = null; + int relationshipLength = 0; + if (ctx.getAttributeKeySet().contains(vmKey + "relationship-data_length")) { + relationshipLength = Integer.parseInt(ctx.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 = ctx.getAttribute(vmKey + "relationship-data[" + j + "].relationship-key"); + String value = ctx.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; + } + } + int relatedPropertyLength = 0; + if (ctx.getAttributeKeySet().contains(vmKey + "related-to-property_length")) { + relatedPropertyLength = + Integer.parseInt(ctx.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 = ctx.getAttribute(vmKey + "related-to-property[" + j + "].property-key"); + String value = ctx.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-id = '" + vserverID + "' AND tenant_id = '" + tenantID + "'"; + Map paramsVm = new HashMap(); + paramsVm.put("resourceType", "vserver:relationship-list"); + 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"); + } + vnfHierarchyMap.put("VNF.VM[" + vmCount + "].URL", + vmCtx.getAttribute("vmRetrived.vserver-selflink")); + 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); + break; //VM to VNFC is 1 to 1 relation, once we got the VNFC name we can break the loop + } + } + } + } + } else { + ctx.setAttribute(Constants.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(Constants.DG_OUTPUT_STATUS_MESSAGE, "VM count is 0"); + } + 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(Constants.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======"); + } + } +} 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 new file mode 100644 index 000000000..aec1ac220 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/InputParameterValidationImpl.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.util.impl; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +import org.openecomp.appc.dg.util.InputParameterValidation; +import org.openecomp.appc.exceptions.APPCException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.openecomp.sdnc.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 new file mode 100644 index 000000000..39f86ae6f --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/java/org/openecomp/appc/dg/util/impl/UpgradeStubNodeImpl.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.util.impl; + +import java.util.Map; + +import org.openecomp.appc.dg.util.UpgradeStubNode; +import org.openecomp.appc.exceptions.APPCException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.openecomp.sdnc.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/OSGI-INF/blueprint/blueprint.xml b/appc-dg-util/appc-dg-util-bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 000000000..547b8cdfb --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 000000000..4c11b73c7 --- /dev/null +++ b/appc-dg-util/appc-dg-util-bundle/src/main/resources/org/openecomp/appc/default.properties @@ -0,0 +1,26 @@ +### +# ============LICENSE_START======================================================= +# openECOMP : APP-C +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights +# reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.openecomp.appc.bootstrap.file=appc.properties +org.openecomp.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. +# -- cgit 1.2.3-korg