From adc29b887ccdfed63cd97e942ae6ac594d3bc44e Mon Sep 17 00:00:00 2001 From: Idan Amit Date: Sun, 16 Jul 2017 14:54:17 +0300 Subject: [sdc] - merged 1707_build into sdc LF Change-Id: Ia91f0206493d0cd8f158779ed1a94f55305c8a97 Signed-off-by: Idan Amit Signed-off-by: Michael Lando --- .../be/components/impl/ArtifactsBusinessLogic.java | 3 +- .../impl/ComponentInstanceBusinessLogic.java | 4 +- .../be/components/impl/InputsBusinessLogic.java | 192 +++++++++++++-------- .../externalapi/servlet/CrudExternalServlet.java | 4 +- 4 files changed, 126 insertions(+), 77 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index cb04cfcdc9..cec045d8a3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -3515,11 +3515,12 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { private String generateHeatEnvPayload(ArtifactDefinition artifactDefinition) { List heatParameters = artifactDefinition.getListHeatParameters(); - heatParameters.sort(Comparator.comparing(e -> e.getName())); StringBuilder sb = new StringBuilder(); sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactHeader()); sb.append("parameters:\n"); if (heatParameters != null) { + heatParameters.sort(Comparator.comparing(e -> e.getName())); + List empltyHeatValues = new ArrayList<>(); for (HeatParameterDefinition heatParameterDefinition : heatParameters) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index 643b35d17b..5da416ec0b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -383,14 +383,14 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic { StorageOperationStatus artStatus = toscaOperationFacade.addDeploymentArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, finalDeploymentArtifacts); if ( artStatus != StorageOperationStatus.OK){ log.debug("Failed to add instance deployment artifacts for instance {} in conatiner {} error {}", componentInstance.getUniqueId(), containerComponent.getUniqueId(), artStatus); - return Either.left(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false)); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false))); } StorageOperationStatus result = toscaOperationFacade .addGroupInstancesToComponentInstance(containerComponent, componentInstance, filteredGroups, groupInstancesArtifacts); if (result != StorageOperationStatus.OK) { log.debug("failed to update group instance for component instance {}", componentInstance.getUniqueId()); - return Either.left(componentsUtils.convertFromStorageResponse(result)); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result))); } componentInstance.setDeploymentArtifacts(finalDeploymentArtifacts); return Either.left(ActionStatus.OK); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java index 4f4ad7f838..d6497b58ea 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java @@ -46,6 +46,7 @@ import org.openecomp.sdc.be.model.ComponentInstancePropInput; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.IComponentInstanceConnectedElement; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.User; @@ -443,10 +444,19 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ////////////////////////////////////////////////////////////////////////////////////////////////////// List resList = new ArrayList(); - Map> newInputsMap = componentInstInputsMapUi.getComponentInstanceInputsMap(); + Map> newInputsMap = componentInstInputsMapUi.getComponentInstanceInputsMap(); List ciList = component.getComponentInstances(); if (newInputsMap != null && !newInputsMap.isEmpty()) { - int index = 0; + + result = createInputsFromProperty(component, origComponentMap, inputsToCreate, propertiesToCreateMap, inputsValueToCreateMap, dataTypes, resList, newInputsMap, true); + + if (result.isRight()) { + log.debug("Failed to create inputs of resource for id {} error {}", component.getUniqueId(), result.right().value()); + return result; + } + resList = result.left().value(); + + /*int index = 0; for (Entry> entry : newInputsMap.entrySet()) { String compInstId = entry.getKey(); @@ -486,14 +496,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } } - } + }*/ } Map> newInputsPropsMap = componentInstInputsMapUi.getComponentInstanceProperties(); if (newInputsPropsMap != null && !newInputsPropsMap.isEmpty()) { - result = createInputsFromProperty(component, origComponentMap, inputsToCreate, propertiesToCreateMap, dataTypes, resList, newInputsPropsMap); + result = createInputsFromProperty(component, origComponentMap, inputsToCreate, propertiesToCreateMap, inputsValueToCreateMap, dataTypes, resList, newInputsPropsMap, false); if (result.isRight()) { log.debug("Failed to create inputs of resource for id {} error {}", component.getUniqueId(), result.right().value()); @@ -895,25 +905,20 @@ public class InputsBusinessLogic extends BaseBusinessLogic { if(inputsValue != null && !inputsValue.isEmpty()){ for(ComponentInstanceInput inputValue: inputsValue){ - inputValue.setValue(inputValue.getDefaultValue()); - List getInputsValues = inputValue.getGetInputValues(); - if(getInputsValues != null && !getInputsValues.isEmpty()){ - Optional op = getInputsValues.stream().filter(gi -> gi.getInputId().equals(inputForDelete.getUniqueId())).findAny(); - if(op.isPresent()){ - getInputsValues.remove(op.get()); - } - } - inputValue.setGetInputValues(getInputsValues); + String compInstId = inputValue.getComponentInstanceId(); + prepareValueBeforeDelete(compInstId, inputForDelete, inputValue, inputValue.getPath()); + + status = toscaOperationFacade.updateComponentInstanceInput(component, compInstId, inputValue); List inputList = null; - String ciId = inputValue.getComponentInstanceId(); - status = toscaOperationFacade.updateComponentInstanceInput(component, ciId, inputValue); if(status != StorageOperationStatus.OK){ - log.debug("Component id: {} delete component instance input id: {} failed", componentId, inputId); + log.debug("Component id: {} update component instance property {} id: {} failed", componentId, inputValue.getUniqueId(), inputId); deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName())); return deleteEither; } + } + } // US848813 delete service input that relates to VL / CP property @@ -923,42 +928,9 @@ public class InputsBusinessLogic extends BaseBusinessLogic { //propertyList = propertyValueStatus.left().value(); for(ComponentInstanceProperty propertyValue: propertiesValue){ - String value = propertyValue.getValue(); - Map mappedToscaTemplate = (Map) new Yaml().load(value); - - resetInputName(mappedToscaTemplate, inputForDelete.getName()); - - value = ""; - if(!mappedToscaTemplate.isEmpty()){ - Either result = cleanNestedMap(mappedToscaTemplate , true); - Map modifiedMappedToscaTemplate = mappedToscaTemplate; - if (result.isLeft()) - modifiedMappedToscaTemplate = (Map)result.left().value(); - else - Log.warn("Map cleanup failed -> " +result.right().value().toString()); //continue, don't break operation - value = gson.toJson(modifiedMappedToscaTemplate); - } - propertyValue.setValue(value); String compInstId = propertyValue.getComponentInstanceId(); - propertyValue.setRules(null); - List getInputsValues = propertyValue.getGetInputValues(); - if(getInputsValues != null && !getInputsValues.isEmpty()){ - Optional op = getInputsValues.stream().filter(gi -> gi.getInputId().equals(inputForDelete.getUniqueId())).findAny(); - if(op.isPresent()){ - getInputsValues.remove(op.get()); - } - } - propertyValue.setGetInputValues(getInputsValues); - - Either findDefaultValue = propertyOperation.findDefaultValueFromSecondPosition(propertyValue.getPath(), propertyValue.getUniqueId(), propertyValue.getDefaultValue()); - if (findDefaultValue.isRight()) { - deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(findDefaultValue.right().value())))); - return deleteEither; - - } - String defaultValue = findDefaultValue.left().value(); - propertyValue.setDefaultValue(defaultValue); - log.debug("The returned default value in ResourceInstanceProperty is {}", defaultValue); + prepareValueBeforeDelete(compInstId, inputForDelete, propertyValue, propertyValue.getPath()); + status = toscaOperationFacade.updateComponentInstanceProperty(component, compInstId, propertyValue); if(status != StorageOperationStatus.OK){ log.debug("Component id: {} update component instance property {} id: {} failed", componentId, propertyValue.getUniqueId(), inputId); @@ -984,6 +956,47 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } } + private Either prepareValueBeforeDelete(String compInstId, InputDefinition inputForDelete, PropertyDefinition inputValue, List pathOfComponentInstances) { + Either deleteEither = Either.left(inputForDelete); + String value = inputValue.getValue(); + Map mappedToscaTemplate = (Map) new Yaml().load(value); + + resetInputName(mappedToscaTemplate, inputForDelete.getName()); + + value = ""; + if(!mappedToscaTemplate.isEmpty()){ + Either result = cleanNestedMap(mappedToscaTemplate , true); + Map modifiedMappedToscaTemplate = mappedToscaTemplate; + if (result.isLeft()) + modifiedMappedToscaTemplate = (Map)result.left().value(); + else + Log.warn("Map cleanup failed -> " +result.right().value().toString()); //continue, don't break operation + value = gson.toJson(modifiedMappedToscaTemplate); + } + inputValue.setValue(value); + + + List getInputsValues = inputValue.getGetInputValues(); + if(getInputsValues != null && !getInputsValues.isEmpty()){ + Optional op = getInputsValues.stream().filter(gi -> gi.getInputId().equals(inputForDelete.getUniqueId())).findAny(); + if(op.isPresent()){ + getInputsValues.remove(op.get()); + } + } + inputValue.setGetInputValues(getInputsValues); + + Either findDefaultValue = propertyOperation.findDefaultValueFromSecondPosition(pathOfComponentInstances, inputValue.getUniqueId(), inputValue.getDefaultValue()); + if (findDefaultValue.isRight()) { + deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(findDefaultValue.right().value())))); + return deleteEither; + + } + String defaultValue = findDefaultValue.left().value(); + inputValue.setDefaultValue(defaultValue); + log.debug("The returned default value in ResourceInstanceProperty is {}", defaultValue); + return deleteEither; + } + private Either prepareAndValidateInputBeforeCreate(InputDefinition newInputDefinition, Map dataTypes) { @@ -1196,7 +1209,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { - private Either, ResponseFormat> createInputsFromProperty(org.openecomp.sdc.be.model.Component component, Map origComponentMap, Map inputsToCreate, Map> propertiesToCreateMap, Map dataTypes, List resList, Map> newInputsPropsMap) { + private Either, ResponseFormat> createInputsFromProperty(org.openecomp.sdc.be.model.Component component, Map origComponentMap, Map inputsToCreate, Map> propertiesToCreateMap, Map> inputsValueToCreateMap, Map dataTypes, List resList, Map> newInputsPropsMap, boolean isInputValue) { List ciList = component.getComponentInstances(); String componentId = component.getUniqueId(); for (Entry> entry : newInputsPropsMap.entrySet()) { @@ -1206,7 +1219,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { propertiesToCreate = propertiesToCreateMap.get(compInstId); }else{ propertiesToCreate = new ArrayList<>(); - } + } + + List inputsValueToCreate = null; + if(propertiesToCreateMap.containsKey(compInstId)){ + inputsValueToCreate = inputsValueToCreateMap.get(compInstId); + }else{ + inputsValueToCreate = new ArrayList<>(); + } List properties = entry.getValue(); @@ -1238,7 +1258,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { propInput.setOwnerId(null); propInput.setParentUniqueId(null); - Either createInputRes = createInputForComponentInstance(component, origComponent,ci, inputsToCreate, propertiesToCreate, dataTypes, inputName, propInput); + Either createInputRes = createInputForComponentInstance(component, origComponent,ci, inputsToCreate, propertiesToCreate, inputsValueToCreate, dataTypes, inputName, propInput, isInputValue); if (createInputRes.isRight()) { log.debug("Failed to create input of resource instance for id {} error {}", compInstId, createInputRes.right().value()); @@ -1249,14 +1269,19 @@ public class InputsBusinessLogic extends BaseBusinessLogic { resList.add(createInputRes.left().value()); } - propertiesToCreateMap.put(compInstId, propertiesToCreate); + if(! isInputValue){ + propertiesToCreateMap.put(compInstId, propertiesToCreate); + } + else{ + inputsValueToCreateMap.put(compInstId, inputsValueToCreate); + } } } return Either.left(resList); } - private Either createInputForComponentInstance(org.openecomp.sdc.be.model.Component component,org.openecomp.sdc.be.model.Component orignComponent, ComponentInstance ci, Map inputsToCreate, List propertiesToCreate, Map dataTypes, String inputName, ComponentInstancePropInput propInput) { + private Either createInputForComponentInstance(org.openecomp.sdc.be.model.Component component,org.openecomp.sdc.be.model.Component orignComponent, ComponentInstance ci, Map inputsToCreate, List propertiesToCreate, List inputsValueToCreate, Map dataTypes, String inputName, ComponentInstancePropInput propInput, boolean isInputValue) { String propertiesName = propInput.getPropertiesName() ; PropertyDefinition selectedProp = propInput.getInput(); String[] parsedPropNames = propInput.getParsedPropNames(); @@ -1270,14 +1295,22 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } InputDefinition input = null; - ComponentInstanceProperty prop = propInput; + PropertyDefinition prop = propInput; - if(CollectionUtils.isNotEmpty(propertiesToCreate)){ + if(CollectionUtils.isNotEmpty(propertiesToCreate) && !isInputValue){ Optional propOpt = propertiesToCreate.stream().filter(p -> p.getName().equals(propInput.getName())).findFirst(); if(propOpt.isPresent()){ prop = propOpt.get(); } + }else{ + if(CollectionUtils.isNotEmpty(inputsValueToCreate) && isInputValue){ + Optional propOpt = inputsValueToCreate.stream().filter(p -> p.getName().equals(propInput.getName())).findFirst(); + if(propOpt.isPresent()){ + prop = propOpt.get(); + } + } } + boolean complexProperty = false; if(propertiesName != null && !propertiesName.isEmpty() && selectedProp != null){ complexProperty = true; @@ -1317,7 +1350,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { if(!complexProperty){ jobject.put(GET_INPUT, input.getName()); prop.setValue(jobject.toJSONString()); - prop.setRules(null); + }else{ Map mappedToscaTemplate = (Map) objValue; @@ -1325,18 +1358,19 @@ public class InputsBusinessLogic extends BaseBusinessLogic { String json = gson.toJson(mappedToscaTemplate); prop.setValue(json); - prop.setRules(null); + } }else{ jobject.put(GET_INPUT, input.getName()); prop.setValue(jobject.toJSONString()); - prop.setRules(null); + } } - prop.setComponentInstanceId(ci.getUniqueId()); - prop.setComponentInstanceName(ci.getName()); + + ((IComponentInstanceConnectedElement)prop).setComponentInstanceId(ci.getUniqueId()); + ((IComponentInstanceConnectedElement)prop).setComponentInstanceName(ci.getName()); if(CollectionUtils.isEmpty(prop.getGetInputValues())){ prop.setGetInputValues(new ArrayList<>()); @@ -1348,17 +1382,31 @@ public class InputsBusinessLogic extends BaseBusinessLogic { getInputValueDataDefinition.setInputName(input.getName()); getInputValues.add(getInputValueDataDefinition); - if(!propertiesToCreate.contains(prop)){ - propertiesToCreate.add(prop); + if(!isInputValue){ + if(!propertiesToCreate.contains(prop)){ + propertiesToCreate.add((ComponentInstanceProperty)prop); + } + + inputsToCreate.put(input.getName(), input); + List propertiesList = input.getProperties(); + if(propertiesList == null) + propertiesList = new ArrayList<>(); // adding the property with the new value for UI + propertiesList.add((ComponentInstanceProperty)prop); + input.setProperties(propertiesList); + }else{ + ComponentInstanceInput inputValue = new ComponentInstanceInput(prop); + if(!inputsValueToCreate.contains(inputValue)){ + inputsValueToCreate.add(inputValue);; + } + + inputsToCreate.put(input.getName(), input); + List inputsValueList = input.getInputs(); + if(inputsValueList == null) + inputsValueList = new ArrayList<>(); // adding the property with the new value for UI + inputsValueList.add(inputValue); + input.setInputs(inputsValueList); } - inputsToCreate.put(input.getName(), input); - List propertiesList = input.getProperties(); - if(propertiesList == null) - propertiesList = new ArrayList<>(); // adding the property with the new value for UI - propertiesList.add(prop); - input.setProperties(propertiesList); - return Either.left(input); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java index 529d2aba4d..b4240777a8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java @@ -120,7 +120,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet { @ApiOperation(value = "creates a resource", httpMethod = "POST", notes = "Creates a resource") @ApiResponses(value = { @ApiResponse(code = 200, message = "ECOMP component is authenticated and Asset created", response = Resource.class), - @ApiResponse(code = 400, message = "Missing X-ECOMP-InstanceID HTTP header - POL5001"), + @ApiResponse(code = 400, message = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"), @ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"), @ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"), @ApiResponse(code = 404, message = "Error: Requested '%1' (uuid) resource was not found - SVC4063"), @@ -269,7 +269,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet { @ApiOperation(value = "Change Resource lifecycle State", httpMethod = "POST") @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource state changed", response = AssetMetadata.class), - @ApiResponse(code = 400, message = "Missing X-ECOMP-InstanceID HTTP header - POL5001"), + @ApiResponse(code = 400, message = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"), @ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"), @ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"), @ApiResponse(code = 404, message = "Error: Requested '%1' (uuid) resource was not found - SVC4063"), -- cgit 1.2.3-korg