From 0fe581513227caf8e1f07345d95b9c21ef9350db Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Wed, 11 Oct 2017 15:37:55 +0300 Subject: VoltE fix Change-Id: I5ebff7b2f8fabc9e9058b7451404eb4e705c0196 Issue-ID: SDC-410 Signed-off-by: Tal Gitelman --- .../be/components/impl/ResourceBusinessLogic.java | 54 ++++++++++++++++++---- 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index ba26576648..8ead372bc8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -4265,7 +4265,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.left(validRegDef); } - @SuppressWarnings("unchecked") public Either parseResourceInfoFromYaml(String yamlFileName, Resource resource, String resourceYml, Map createdNodesToscaResourceNames, Map nodeTypesInfo, String nodeName) { Map mappedToscaTemplate; @@ -4357,15 +4356,17 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ComponentTypeEnum containerComponentType = resource.getComponentType(); NodeTypeEnum containerNodeType = containerComponentType.getNodeType(); - - if (containerNodeType.equals(NodeTypeEnum.Resource) && uploadComponentInstanceInfo.getCapabilities() != null) { - Either>, ResponseFormat> getValidComponentInstanceCapabilitiesRes = getValidComponentInstanceCapabilities(refResource.getCapabilities(), uploadComponentInstanceInfo.getCapabilities()); + //************ + if (containerNodeType.equals(NodeTypeEnum.Resource) && MapUtils.isNotEmpty(uploadComponentInstanceInfo.getCapabilities()) && MapUtils.isNotEmpty(refResource.getCapabilities())) { + setCapabilityNamesTypes(refResource.getCapabilities(), uploadComponentInstanceInfo.getCapabilities()); + Either>, ResponseFormat> getValidComponentInstanceCapabilitiesRes = getValidComponentInstanceCapabilities(refResource.getUniqueId(), refResource.getCapabilities(), uploadComponentInstanceInfo.getCapabilities()); if (getValidComponentInstanceCapabilitiesRes.isRight()) { return Either.right(getValidComponentInstanceCapabilitiesRes.right().value()); } else { componentInstance.setCapabilities(getValidComponentInstanceCapabilitiesRes.left().value()); } } + //*********************** if (!existingnodeTypeMap.containsKey(uploadComponentInstanceInfo.getType())) { log.debug("createResourceInstances - not found lates version for resource instance with name {} and type ", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType()); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType()); @@ -4417,7 +4418,21 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.left(eitherGerResource.left().value()); } + + private void setCapabilityNamesTypes(Map> originCapabilities, Map> uploadedCapabilities) { + for(Entry> currEntry : uploadedCapabilities.entrySet()){ + if(originCapabilities.containsKey(currEntry.getKey())){ + currEntry.getValue().stream().forEach(cap -> cap.setType(currEntry.getKey())); + } + } + + for(Map.Entry> capabilities : originCapabilities.entrySet()){ + capabilities.getValue().stream().forEach(cap -> {if(uploadedCapabilities.containsKey(cap.getName())){uploadedCapabilities.get(cap.getName()).stream().forEach(c -> {c.setName(cap.getName());c.setType(cap.getType());});};}); + } + } + + private Either validateResourceInstanceBeforeCreate(String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo, Map nodeNamespaceMap) { log.debug("validateResourceInstanceBeforeCreate - going to validate resource instance with name {} and type before create", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType()); Resource refResource = null; @@ -7021,7 +7036,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return null; } - private Either>, ResponseFormat> getValidComponentInstanceCapabilities(Map> defaultCapabilities, Map> uploadedCapabilities) { + private Either>, ResponseFormat> getValidComponentInstanceCapabilities(String resourceId, Map> defaultCapabilities, Map> uploadedCapabilities) { ResponseFormat responseFormat; Map> validCapabilitiesMap = new HashMap<>(); @@ -7031,14 +7046,33 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, capabilityType); return Either.right(responseFormat); } else { - CapabilityDefinition delaultCapability = defaultCapabilities.get(capabilityType).get(0); - Either validationRes = validateUniquenessUpdateUploadedComponentInstanceCapability(delaultCapability, uploadedCapabilitiesEntry.getValue().get(0)); - if (validationRes.isRight()) { - responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS, validationRes.right().value()); + CapabilityDefinition defaultCapability; + if(CollectionUtils.isNotEmpty(defaultCapabilities.get(capabilityType).get(0).getProperties())){ + defaultCapability = defaultCapabilities.get(capabilityType).get(0); + } else { + Either getFullComponentRes = toscaOperationFacade.getToscaFullElement(resourceId); + if(getFullComponentRes.isRight()){ + log.debug("Failed to get full component {}. Status is {}. ", resourceId, getFullComponentRes.right().value()); + responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND, resourceId); + return Either.right(responseFormat); + } + defaultCapability = getFullComponentRes.left().value().getCapabilities().get(capabilityType).get(0); + } + if(CollectionUtils.isEmpty(defaultCapability.getProperties()) && CollectionUtils.isNotEmpty(uploadedCapabilitiesEntry.getValue().get(0).getProperties())){ + log.debug("Failed to validate capability {} of component {}. Property list is empty. ", defaultCapability.getName(), resourceId); + log.debug("Failed to update capability property values. Property list of fetched capability {} is empty. ", defaultCapability.getName()); + responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, resourceId); return Either.right(responseFormat); } + if(CollectionUtils.isNotEmpty(defaultCapability.getProperties()) && CollectionUtils.isNotEmpty(uploadedCapabilitiesEntry.getValue().get(0).getProperties())){ + Either validationRes = validateUniquenessUpdateUploadedComponentInstanceCapability(defaultCapability, uploadedCapabilitiesEntry.getValue().get(0)); + if (validationRes.isRight()) { + responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS, validationRes.right().value()); + return Either.right(responseFormat); + } + } List validCapabilityList = new ArrayList<>(); - validCapabilityList.add(delaultCapability); + validCapabilityList.add(defaultCapability); validCapabilitiesMap.put(uploadedCapabilitiesEntry.getKey(), validCapabilityList); } } -- cgit 1.2.3-korg