From 13b9505921e2cbbd4b155a78bfdaa5caa3375ec0 Mon Sep 17 00:00:00 2001 From: Ramya Balaji Date: Tue, 2 Jan 2018 21:58:59 -0500 Subject: Updated SDC listener and dependent bundles Changes related to SDC adapter.Also includes sequence generator changes and changes to appc-dg-shared. Issue-ID: APPC-355 Change-Id: Ib8a0b1d304199db6d2595291539b266885842d63 Signed-off-by: Ramya Balaji --- .../onap/appc/dg/common/impl/JsonDgUtilImpl.java | 4 +- .../appc/dg/common/impl/VnfExecutionFlowImpl.java | 137 +++++++++++++-------- 2 files changed, 87 insertions(+), 54 deletions(-) (limited to 'appc-dg/appc-dg-shared/appc-dg-common/src/main') diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java index fff43cbf5..caad8b809 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java @@ -29,7 +29,7 @@ import java.text.SimpleDateFormat; import java.util.Map; import java.util.Set; -import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.onap.appc.dg.common.JsonDgUtil; import org.onap.appc.exceptions.APPCException; @@ -63,7 +63,7 @@ public class JsonDgUtilImpl implements JsonDgUtil { try { String paramName = Constants.PAYLOAD; String payload = params.get(paramName); - if (payload == "") + if (payload == null || payload.isEmpty()) payload = ctx.getAttribute("input.payload"); if (!StringUtils.isEmpty(payload)) { Map flatMap = JsonUtil.convertJsonStringToFlatMap(payload); diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java index 65b364f62..8129e2e02 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java @@ -28,6 +28,7 @@ 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.appc.exceptions.APPCException; import java.util.*; @@ -36,7 +37,7 @@ import org.onap.appc.dg.dependencymanager.DependencyManager; import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound; import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory; import org.onap.appc.dg.flowbuilder.FlowBuilder; -import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException; import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory; import org.onap.appc.dg.objects.*; import org.onap.appc.domainmodel.Vnf; @@ -47,10 +48,15 @@ import org.onap.appc.metadata.objects.DependencyModelIdentifier; public class VnfExecutionFlowImpl implements VnfExecutionFlow { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(VnfExecutionFlowImpl.class); - + private final EELFLogger logger = EELFManager.getInstance().getLogger(VnfExecutionFlowImpl.class); + private static final String VNFC_FLOW="vnfcFlow["; + private static final String VNF_VNFC="vnf.vnfc["; + /** + * Constructor + *

Used through blueprint + */ public VnfExecutionFlowImpl(){ - + // do nothing } @Override @@ -58,7 +64,7 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { String dependencyType = params.get(Constants.DEPENDENCY_TYPE); String flowStrategy = params.get(Constants.FLOW_STRATEGY); DependencyModelIdentifier modelIdentifier = readDependencyModelIdentifier(params); - VnfcDependencyModel dependencyModel = null; + VnfcDependencyModel dependencyModel; try { validateInput(dependencyType, flowStrategy, params); @@ -69,8 +75,6 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { } DependencyManager dependencyManager = DependencyModelFactory.createDependencyManager(); - - dependencyModel = dependencyManager.getVnfcDependencyModel( modelIdentifier, DependencyTypes.findByString(dependencyType)); } catch (DependencyModelNotFound e) { @@ -79,12 +83,17 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); context.setAttribute("dependencyModelFound","false"); return; - } catch (InvalidDependencyModel e){ + } catch (InvalidDependencyModelException e){ String msg = EELFResourceManager.format(Msg.INVALID_DEPENDENCY_MODEL,params.get(Constants.VNF_TYPE), e.getMessage()); logger.error(msg); context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); - throw e; - }catch (RuntimeException e){ + throw new RuntimeException(e.getMessage(),e); + } catch (APPCException e){ + logger.error(e.getMessage()); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); + throw new RuntimeException(e.getMessage(),e); + } + catch (RuntimeException e){ logger.error(e.getMessage()); context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); throw e; @@ -96,7 +105,14 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { logger.debug("Dependency Model = " +dependencyModel); } logger.info("Building Inventory Model from DG context"); - InventoryModel inventoryModel = readInventoryModel(context); + InventoryModel inventoryModel = null; + try { + inventoryModel = readInventoryModel(context); + } catch (APPCException e) { + logger.error(e.getMessage()); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); + throw new RuntimeException(e.getMessage(),e); + } if(logger.isDebugEnabled()){ logger.debug("Inventory Model = " +inventoryModel); } @@ -106,25 +122,26 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { } try { validateInventoryModelWithDependencyModel(dependencyModel, inventoryModel); - }catch (RuntimeException e){ + } + catch (APPCException e){ logger.error(e.getMessage()); context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); - throw e; + throw new RuntimeException(e.getMessage(),e); } logger.info("Creating flow builder"); FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder( FlowStrategies.findByString(flowStrategy)); logger.info("Building Vnf flow model"); - VnfcFlowModel flowModel = null; + VnfcFlowModel flowModel; try{ flowModel = flowBuilder.buildFlowModel(dependencyModel,inventoryModel); } - catch (InvalidDependencyModel e){ + catch (InvalidDependencyModelException e){ String msg = EELFResourceManager.format(Msg.INVALID_DEPENDENCY_MODEL,params.get(Constants.VNF_TYPE), e.getMessage()); logger.error(msg); context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); - throw e; + throw new RuntimeException(e.getMessage(),e); } // remove VNFCs from the flow model where vserver list is empty @@ -137,22 +154,22 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { context.setAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg); } - private void validateInput(String dependencyType, String flowStrategy, Map params) { + private void validateInput(String dependencyType, String flowStrategy, Map params) throws APPCException { DependencyTypes dependencyTypes = DependencyTypes.findByString(dependencyType); if(dependencyTypes == null){ - throw new RuntimeException("Dependency type from the input : " + dependencyType +" is invalid."); + throw new APPCException("Dependency type from the input : " + dependencyType +" is invalid."); } FlowStrategies flowStrategies = FlowStrategies.findByString(flowStrategy); if(flowStrategies == null){ - throw new RuntimeException("Flow Strategy from the input : " + flowStrategy +" is invalid."); + throw new APPCException("Flow Strategy from the input : " + flowStrategy +" is invalid."); } String vnfType = params.get(Constants.VNF_TYPE); if(vnfType ==null || vnfType.length() ==0){ - throw new RuntimeException("Vnf Type is not passed in the input"); + throw new APPCException("Vnf Type is not passed in the input"); } String vnfVersion = params.get(Constants.VNF_VERION); if(vnfVersion == null || vnfVersion.length() ==0){ - throw new RuntimeException("Vnf Version not found"); + throw new APPCException("Vnf Version not found"); } } @@ -167,13 +184,13 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { Iterator> iterator = flowModel.getModelIterator(); while (iterator.hasNext()){ for(Vnfc vnfc:iterator.next()){ - context.setAttribute("vnfcFlow["+flowIndex+"].vnfcName",vnfc.getVnfcName()); - context.setAttribute("vnfcFlow["+flowIndex+"].vnfcType",vnfc.getVnfcType()); - context.setAttribute("vnfcFlow["+flowIndex+"].resilienceType",vnfc.getResilienceType()); - context.setAttribute("vnfcFlow["+flowIndex+"].vmCount",Integer.toString(vnfc.getVserverList().size())); + context.setAttribute(VNFC_FLOW+flowIndex+"].vnfcName",vnfc.getVnfcName()); + context.setAttribute(VNFC_FLOW+flowIndex+"].vnfcType",vnfc.getVnfcType()); + context.setAttribute(VNFC_FLOW+flowIndex+"].resilienceType",vnfc.getResilienceType()); + context.setAttribute(VNFC_FLOW+flowIndex+"].vmCount",Integer.toString(vnfc.getVserverList().size())); int vmIndex =0; for(Vserver vm :vnfc.getVserverList()){ - context.setAttribute("vnfcFlow["+flowIndex+"].vm["+vmIndex+"].url",vm.getUrl()); + context.setAttribute(VNFC_FLOW+flowIndex+"].vm["+vmIndex+"].url",vm.getUrl()); vmIndex++; } flowIndex++; @@ -182,73 +199,88 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { context.setAttribute("vnfcFlowCount",Integer.toString(flowIndex)); } - private InventoryModel readInventoryModel(SvcLogicContext context) { + private InventoryModel readInventoryModel(SvcLogicContext context) throws APPCException { String vnfId = context.getAttribute("input.action-identifiers.vnf-id"); String vnfType = context.getAttribute("vnf.type"); String vnfVersion = context.getAttribute("vnf.version"); String vnfcCountStr = context.getAttribute("vnf.vnfcCount"); Integer vnfcCount = Integer.parseInt(vnfcCountStr); - - Vnf vnf = new Vnf(vnfId,vnfType,vnfVersion); - + Vnf vnf = createVnf(vnfId, vnfType, vnfVersion); for(Integer i=0;i params) { String vnfType = params.get(Constants.VNF_TYPE); String catalogVersion = params.get(Constants.VNF_VERION); return new DependencyModelIdentifier(vnfType,catalogVersion); } - private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) { - Set dependencyModelVnfcSet = new HashSet(); - Set dependencyModelMandatoryVnfcSet = new HashSet(); - Set inventoryModelVnfcsSet = new HashSet(); - + private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) throws APPCException { + Set dependencyModelVnfcSet = new HashSet<>(); + Set dependencyModelMandatoryVnfcSet = new HashSet<>(); + Set inventoryModelVnfcsSet = new HashSet<>(); for (Node node : dependencyModel.getDependencies()) { dependencyModelVnfcSet.add(node.getChild().getVnfcType().toLowerCase()); if (node.getChild().isMandatory()) { dependencyModelMandatoryVnfcSet.add(node.getChild().getVnfcType().toLowerCase()); } } - for (Vnfc vnfc : inventoryModel.getVnf().getVnfcs()) { inventoryModelVnfcsSet.add(vnfc.getVnfcType().toLowerCase()); } - // if dependency model and inventory model contains same set of VNFCs, validation succeed and hence return if (dependencyModelVnfcSet.equals(inventoryModelVnfcsSet)) { return; } - if (inventoryModelVnfcsSet.size() >= dependencyModelVnfcSet.size()) { - Set difference = new HashSet(inventoryModelVnfcsSet); + Set difference = new HashSet<>(inventoryModelVnfcsSet); difference.removeAll(dependencyModelVnfcSet); logger.error("Dependency model is missing following vnfc type(s): " + difference); - throw new RuntimeException("Dependency model is missing following vnfc type(s): " + difference); + throw new APPCException("Dependency model is missing following vnfc type(s): " + difference); } else { - Set difference = new HashSet(dependencyModelVnfcSet); + Set difference = new HashSet<>(dependencyModelMandatoryVnfcSet); difference.removeAll(inventoryModelVnfcsSet); - difference.retainAll(dependencyModelMandatoryVnfcSet); if (difference.size() > 0) { logger.error("Inventory model is missing following mandatory vnfc type(s): " + difference); - throw new RuntimeException("Inventory model is missing following mandatory vnfc type(s): " + difference); + throw new APPCException("Inventory model is missing following mandatory vnfc type(s): " + difference); } } } @@ -268,4 +300,5 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { } } } + } -- cgit 1.2.3-korg