diff options
author | vasraz <vasyl.razinkov@est.tech> | 2022-07-14 21:06:58 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-07-15 13:16:16 +0000 |
commit | ee8876059c520d97bf068734b25a02365d7fe1ea (patch) | |
tree | 46176fc6a016818c6d17dd0ac20054ec884e7802 /catalog-be/src/main/java | |
parent | e4055451d3fbfe1fba35dcf546907ad432f6b4fc (diff) |
Support Outputs during Import Service
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I4d58576b70ef738d6fa7545cd268ec030b43f95c
Issue-ID: SDC-4051
Diffstat (limited to 'catalog-be/src/main/java')
9 files changed, 216 insertions, 109 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java index 79bfcc6df7..394d6b314b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java @@ -25,7 +25,6 @@ import com.google.gson.Gson; import fj.data.Either; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -182,7 +181,7 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie outputDefinition.setOutputPath(attributesName); outputDefinition.setInstanceUniqueId(propertiesOwner.getUniqueId()); outputDefinition.setAttributeId(attributeOutput.getUniqueId()); - outputDefinition.setAttributes(Arrays.asList(attributeOutput)); + outputDefinition.setAttribute(attributeOutput); if (attribute instanceof IComponentInstanceConnectedElement) { ((IComponentInstanceConnectedElement) attribute).setComponentInstanceId(propertiesOwner.getUniqueId()); ((IComponentInstanceConnectedElement) attribute).setComponentInstanceName(propertiesOwner.getName()); @@ -201,7 +200,7 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie attributeDataDefinition.setValue(jsonObject.toJSONString()); } else { jsonObject - .put(GET_ATTRIBUTE, Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName())); + .put(GET_ATTRIBUTE, Arrays.asList(output.getAttribute().getComponentInstanceName(), attributeDataDefinition.getName())); output.setValue(jsonObject.toJSONString()); } } else { @@ -209,7 +208,7 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie if (objValue instanceof Map || objValue instanceof List) { if (!complexProperty) { jsonObject.put(GET_ATTRIBUTE, - Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName())); + Arrays.asList(output.getAttribute().getComponentInstanceName(), attributeDataDefinition.getName())); output.setValue(jsonObject.toJSONString()); } else { final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue; @@ -218,7 +217,7 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie } } else { jsonObject - .put(GET_ATTRIBUTE, Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName())); + .put(GET_ATTRIBUTE, Arrays.asList(output.getAttribute().getComponentInstanceName(), attributeDataDefinition.getName())); output.setValue(jsonObject.toJSONString()); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index 31281db0c7..ed753fdd18 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -42,6 +42,7 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.MEMBERS; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TYPE; +import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.OUTPUTS; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.POLICIES; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.PROPERTIES; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIREMENTS; @@ -93,6 +94,7 @@ import org.openecomp.sdc.be.model.GroupDefinition; import org.openecomp.sdc.be.model.GroupTypeDefinition; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.NodeTypeInfo; +import org.openecomp.sdc.be.model.OutputDefinition; import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.PolicyTypeDefinition; @@ -135,13 +137,16 @@ public class YamlTemplateParsingHandler { Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName, Component component, String interfaceTemplateYaml) { log.debug("#parseResourceInfoFromYAML - Going to parse yaml {} ", fileName); - Map<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName); - ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo(); - Map<String, Object> mappedTopologyTemplate = (Map<String, Object>) findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, + final Map<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName); + final ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo(); + final Map<String, Object> mappedTopologyTemplate = (Map<String, Object>) findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL).left().on(err -> failIfNotTopologyTemplate(fileName)); - Map<String, Object> mappedTopologyTemplateInputs = mappedTopologyTemplate.entrySet().stream() + final Map<String, Object> mappedTopologyTemplateInputs = mappedTopologyTemplate.entrySet().stream() .filter(entry -> entry.getKey().equals(INPUTS.getElementName())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + final Map<String, Object> mappedTopologyTemplateOutputs = mappedTopologyTemplate.entrySet().stream() + .filter(entry -> entry.getKey().equals(OUTPUTS.getElementName())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); parsedToscaYamlInfo.setInputs(getInputs(mappedTopologyTemplateInputs)); + parsedToscaYamlInfo.setOutputs(getOutputs(mappedTopologyTemplateOutputs)); parsedToscaYamlInfo.setInstances(getInstances(mappedToscaTemplate, createdNodesToscaResourceNames)); parsedToscaYamlInfo.setGroups(getGroups(mappedToscaTemplate, component.getModel())); parsedToscaYamlInfo.setPolicies(getPolicies(mappedToscaTemplate, component.getModel())); @@ -190,6 +195,10 @@ public class YamlTemplateParsingHandler { return inputs; } + private Map<String, OutputDefinition> getOutputs(Map<String, Object> toscaJson) { + return ImportUtils.getOutputs(toscaJson).left().on(err -> new HashMap<>()); + } + private Map<String, PropertyDefinition> getProperties(Map<String, Object> toscaJson) { return ImportUtils.getProperties(toscaJson).left().on(err -> new HashMap<>()); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java index 7719187cda..b4f6ee3950 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java @@ -41,7 +41,7 @@ import java.util.Map.Entry; import java.util.function.Consumer; import java.util.function.Function; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.text.StringEscapeUtils; import org.onap.sdc.tosca.datatypes.model.EntrySchema; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -56,6 +56,7 @@ import org.openecomp.sdc.be.model.AttributeDefinition; import org.openecomp.sdc.be.model.HeatParameterDefinition; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.OutputDefinition; import org.openecomp.sdc.be.model.PropertyConstraint; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.heat.HeatParameterType; @@ -92,8 +93,8 @@ public final class ImportUtils { } @Autowired - public static void setComponentsUtils(ComponentsUtils componentsUtils) { - componentsUtils = componentsUtils; + public static void setComponentsUtils(ComponentsUtils cu) { + componentsUtils = cu; } private static void buildMap(Map<String, Object> output, Map<String, Object> map) { @@ -257,8 +258,8 @@ public final class ImportUtils { * @param toscaTagName * @return */ - public static Either<String, ResultStatusEnum> findFirstToscaBooleanElement(Map<String, Object> toscaJson, - TypeUtils.ToscaTagNamesEnum toscaTagName) { + private static Either<String, ResultStatusEnum> findFirstToscaBooleanElement(Map<String, Object> toscaJson, + TypeUtils.ToscaTagNamesEnum toscaTagName) { Either<String, ResultStatusEnum> returnedElement = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND); Either<Object, ResultStatusEnum> findFirstToscaElements = findToscaElement(toscaJson, toscaTagName, ToscaElementTypeEnum.BOOLEAN); if (findFirstToscaElements.isLeft()) { @@ -310,7 +311,7 @@ public final class ImportUtils { } catch (ClassCastException | JsonParseException e) { throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS_FORMAT, constraintJson.toString()); } - if (propertyConstraint != null && propertyConstraint instanceof ValidValuesConstraint) { + if (propertyConstraint instanceof ValidValuesConstraint) { try { ((ValidValuesConstraint) propertyConstraint).validateType(propertyType); } catch (ConstraintValueDoNotMatchPropertyTypeException e) { @@ -323,7 +324,7 @@ public final class ImportUtils { return propertyConstraint; } - public static PropertyDefinition createModuleProperty(Map<String, Object> propertyValue) { + static PropertyDefinition createModuleProperty(Map<String, Object> propertyValue) { PropertyDefinition propertyDef = new PropertyDefinition(); setField(propertyValue, TypeUtils.ToscaTagNamesEnum.TYPE, propertyDef::setType); setFieldBoolean(propertyValue, ToscaTagNamesEnum.REQUIRED, req -> propertyDef.setRequired(Boolean.parseBoolean(req))); @@ -340,12 +341,11 @@ public final class ImportUtils { private static void setJsonStringField(Map<String, Object> propertyValue, ToscaTagNamesEnum elementName, String type, Consumer<String> setter) { Either<Object, ResultStatusEnum> eitherValue = findToscaElement(propertyValue, elementName, ToscaElementTypeEnum.ALL); if (eitherValue.isLeft()) { - String propertyJsonStringValue = getPropertyJsonStringValue(eitherValue.left().value(), type); - setter.accept(propertyJsonStringValue); + setter.accept(getPropertyJsonStringValue(eitherValue.left().value(), type)); } } - public static Annotation createModuleAnnotation(Map<String, Object> annotationMap, AnnotationTypeOperations annotationTypeOperations) { + private static Annotation createModuleAnnotation(Map<String, Object> annotationMap, AnnotationTypeOperations annotationTypeOperations) { String parsedAnnotationType = findFirstToscaStringElement(annotationMap, TypeUtils.ToscaTagNamesEnum.TYPE).left().value(); AnnotationTypeDefinition annotationTypeObject = annotationTypeOperations.getLatestType(parsedAnnotationType); if (annotationTypeObject != null) { @@ -387,11 +387,11 @@ public final class ImportUtils { return result; } - public static InputDefinition createModuleInput(final Map<String, Object> inputValue, final AnnotationTypeOperations annotationTypeOperations) { + private static InputDefinition createModuleInput(final Map<String, Object> inputValue, final AnnotationTypeOperations annotationTypeOperations) { return parseAnnotationsAndAddItToInput(createModuleInput(inputValue), inputValue, annotationTypeOperations); } - public static InputDefinition createModuleInput(final Map<String, Object> inputValue) { + private static InputDefinition createModuleInput(final Map<String, Object> inputValue) { final InputDefinition inputDef = new InputDefinition(); setField(inputValue, TypeUtils.ToscaTagNamesEnum.TYPE, inputDef::setType); setFieldBoolean(inputValue, ToscaTagNamesEnum.REQUIRED, req -> inputDef.setRequired(Boolean.parseBoolean(req))); @@ -408,8 +408,17 @@ public final class ImportUtils { return inputDef; } - public static InputDefinition parseAnnotationsAndAddItToInput(InputDefinition inputDef, Map<String, Object> inputValue, - AnnotationTypeOperations annotationTypeOperations) { + private static OutputDefinition createModuleOutput(final Map<String, Object> outputValue) { + final OutputDefinition outputDef = new OutputDefinition(); + setField(outputValue, TypeUtils.ToscaTagNamesEnum.TYPE, outputDef::setType); + setField(outputValue, TypeUtils.ToscaTagNamesEnum.DESCRIPTION, outputDef::setDescription); + setJsonStringField(outputValue, TypeUtils.ToscaTagNamesEnum.VALUE, outputDef.getType(), outputDef::setValue); + setField(outputValue, TypeUtils.ToscaTagNamesEnum.STATUS, outputDef::setStatus); + return outputDef; + } + + private static InputDefinition parseAnnotationsAndAddItToInput(InputDefinition inputDef, Map<String, Object> inputValue, + AnnotationTypeOperations annotationTypeOperations) { Function<String, Annotation> elementGenByName = ImportUtils::createAnnotation; Function<Map<String, Object>, Annotation> func = annotation -> createModuleAnnotation(annotation, annotationTypeOperations); return getElements(inputValue, TypeUtils.ToscaTagNamesEnum.ANNOTATIONS, elementGenByName, func).left() @@ -425,7 +434,7 @@ public final class ImportUtils { return inputDef; } - public static AttributeDefinition createModuleAttribute(Map<String, Object> attributeMap) { + static AttributeDefinition createModuleAttribute(Map<String, Object> attributeMap) { AttributeDefinition attributeDef = new AttributeDefinition(); setField(attributeMap, TypeUtils.ToscaTagNamesEnum.TYPE, attributeDef::setType); setField(attributeMap, TypeUtils.ToscaTagNamesEnum.DESCRIPTION, attributeDef::setDescription); @@ -486,7 +495,7 @@ public final class ImportUtils { } } - public static void setFieldBoolean(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum tagName, Consumer<String> setter) { + private static void setFieldBoolean(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum tagName, Consumer<String> setter) { Either<String, ResultStatusEnum> fieldStringValue = findFirstToscaBooleanElement(toscaJson, tagName); if (fieldStringValue.isLeft()) { setter.accept(fieldStringValue.left().value()); @@ -520,13 +529,19 @@ public final class ImportUtils { return getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS, elementGenByName, func); } + public static Either<Map<String, OutputDefinition>, ResultStatusEnum> getOutputs(Map<String, Object> toscaJson) { + final Function<String, OutputDefinition> elementGenByName = ImportUtils::createOutputs; + final Function<Map<String, Object>, OutputDefinition> func = ImportUtils::createModuleOutput; + return getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.OUTPUTS, elementGenByName, func); + } + public static Either<Map<String, InputDefinition>, ResultStatusEnum> getInputs(final Map<String, Object> toscaJson) { return getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS, ImportUtils::createInputs, ImportUtils::createModuleInput); } - public static <T> Either<Map<String, T>, ResultStatusEnum> getElements(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum elementTagName, - Function<String, T> elementGenByName, - Function<Map<String, Object>, T> func) { + private static <T> Either<Map<String, T>, ResultStatusEnum> getElements(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum elementTagName, + Function<String, T> elementGenByName, + Function<Map<String, Object>, T> func) { Either<Map<String, T>, ResultStatusEnum> eitherResult = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND); Either<Map<String, Object>, ResultStatusEnum> toscaAttributes = findFirstToscaMapElement(toscaJson, elementTagName); if (toscaAttributes.isLeft()) { @@ -571,13 +586,19 @@ public final class ImportUtils { return input; } + private static OutputDefinition createOutputs(final String name) { + final OutputDefinition output = new OutputDefinition(); + output.setName(name); + return output; + } + private static Annotation createAnnotation(String name) { Annotation annotation = new Annotation(); annotation.setName(name); return annotation; } - public static Either<List<HeatParameterDefinition>, ResultStatusEnum> getHeatParameters(Map<String, Object> heatData, String artifactType) { + static Either<List<HeatParameterDefinition>, ResultStatusEnum> getHeatParameters(Map<String, Object> heatData, String artifactType) { Either<List<HeatParameterDefinition>, ResultStatusEnum> eitherResult = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND); Either<Map<String, Object>, ResultStatusEnum> toscaProperties = findFirstToscaMapElement(heatData, TypeUtils.ToscaTagNamesEnum.PARAMETERS); if (toscaProperties.isLeft()) { @@ -657,13 +678,16 @@ public final class ImportUtils { } public static String getPropertyJsonStringValue(Object value, String type) { - Gson gson = new Gson(); if (type == null) { return null; } ToscaPropertyType validType = ToscaPropertyType.isValidType(type); - if (validType == null || validType == ToscaPropertyType.JSON || validType == ToscaPropertyType.MAP || validType == ToscaPropertyType.LIST) { - return gson.toJson(value); + if (validType == null + || validType == ToscaPropertyType.JSON + || validType == ToscaPropertyType.MAP + || validType == ToscaPropertyType.LIST + || value instanceof Map) { + return (new Gson()).toJson(value); } return value.toString(); } 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 18993e8f65..bca901ee8b 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 @@ -127,14 +127,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ComponentParametersView filters = new ComponentParametersView(); filters.disableAll(); filters.setIgnoreInputs(false); - Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade + Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade .getToscaElement(componentId, filters); if (getComponentEither.isRight()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus); return Either.right(componentsUtils.getResponseFormat(actionStatus)); } - org.openecomp.sdc.be.model.Component component = getComponentEither.left().value(); + Component component = getComponentEither.left().value(); List<InputDefinition> inputs = component.getInputs(); return Either.left(inputs); } @@ -147,14 +147,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { filters.setIgnoreInputs(false); filters.setIgnoreComponentInstances(false); filters.setIgnoreComponentInstancesInputs(false); - Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade + Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade .getToscaElement(componentId, filters); if (getComponentEither.isRight()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus); return Either.right(componentsUtils.getResponseFormat(actionStatus)); } - org.openecomp.sdc.be.model.Component component = getComponentEither.left().value(); + Component component = getComponentEither.left().value(); if (!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)) { ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND; log.debug("Failed to found component instance inputs {}, error: {}", componentInstanceId, actionStatus); @@ -182,12 +182,12 @@ public class InputsBusinessLogic extends BaseBusinessLogic { String instanceId, String inputId) { validateUserExists(userId); String parentId = componentId; - org.openecomp.sdc.be.model.Component component; + Component component; ComponentParametersView filters = new ComponentParametersView(); filters.disableAll(); filters.setIgnoreComponentInstances(false); if (!instanceId.equals(inputId)) { - Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade + Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade .getToscaElement(parentId, filters); if (getComponentEither.isRight()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); @@ -204,7 +204,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { filters.setIgnoreComponentInstancesProperties(false); filters.setIgnoreComponentInstancesInputs(false); filters.setIgnoreProperties(false); - Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade + Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade .getToscaElement(parentId, filters); if (getComponentEither.isRight()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); @@ -266,7 +266,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { List<InputDefinition> inputs, String userId, boolean shouldLockComp) { List<InputDefinition> returnInputs = new ArrayList<>(); Either<List<InputDefinition>, ResponseFormat> result = null; - org.openecomp.sdc.be.model.Component component = null; + Component component = null; try { validateUserExists(userId); ComponentParametersView componentParametersView = new ComponentParametersView(); @@ -353,14 +353,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { public Either<List<ComponentInstanceInput>, ResponseFormat> getInputsForComponentInput(String userId, String componentId, String inputId) { validateUserExists(userId); - org.openecomp.sdc.be.model.Component component = null; + Component component = null; ComponentParametersView filters = new ComponentParametersView(); filters.disableAll(); filters.setIgnoreComponentInstances(false); filters.setIgnoreInputs(false); filters.setIgnoreComponentInstancesInputs(false); filters.setIgnoreProperties(false); - Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade + Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade .getToscaElement(componentId, filters); if (getComponentEither.isRight()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); @@ -388,7 +388,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { boolean shouldLockComp, boolean inTransaction) { Either<List<InputDefinition>, ResponseFormat> result = null; - org.openecomp.sdc.be.model.Component component = null; + Component component = null; try { validateUserExists(userId); component = getAndValidateComponentForCreate(userId, componentId, componentType, shouldLockComp); @@ -431,7 +431,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { ComponentInstListInput componentListInput, boolean shouldLockComp, boolean inTransaction) { Either<List<InputDefinition>, ResponseFormat> result = null; - org.openecomp.sdc.be.model.Component component = null; + Component component = null; log.trace("#createListInput: enter"); try { /* check if user exists */ @@ -513,11 +513,11 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return componentParametersView; } - private org.openecomp.sdc.be.model.Component getAndValidateComponentForCreate( + private Component getAndValidateComponentForCreate( String userId, String componentId, ComponentTypeEnum componentType, boolean shouldLockComp ) { ComponentParametersView componentParametersView = getBaseComponentParametersView(); - org.openecomp.sdc.be.model.Component component = validateComponentExists(componentId, componentType, componentParametersView); + Component component = validateComponentExists(componentId, componentType, componentParametersView); if (shouldLockComp) { // lock the component lockComponent(component, CREATE_INPUT); @@ -566,7 +566,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(Map<String, InputDefinition> inputs, - org.openecomp.sdc.be.model.Component component) { + Component component) { List<InputDefinition> resourceProperties = component.getInputs(); @@ -604,7 +604,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { private Either<List<InputDefinition>, ResponseFormat> createListInputsInGraph(Map<String, InputDefinition> inputs, Map<String, DataTypeDefinition> privateDataTypes, - org.openecomp.sdc.be.model.Component component) { + Component component) { log.trace("#createListInputsInGraph: enter"); @@ -652,12 +652,12 @@ public class InputsBusinessLogic extends BaseBusinessLogic { componentParametersView.setIgnoreInterfaces(false); componentParametersView.setIgnoreDataType(false); componentParametersView.setIgnoreProperties(false); - Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither = toscaOperationFacade + Either<Component, StorageOperationStatus> componentEither = toscaOperationFacade .getToscaElement(componentId, componentParametersView); if (componentEither.isRight()) { throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(componentEither.right().value())); } - org.openecomp.sdc.be.model.Component component = componentEither.left().value(); + Component component = componentEither.left().value(); // Validate inputId is child of the component Optional<InputDefinition> optionalInput = component.getInputs().stream(). // filter by ID @@ -700,10 +700,9 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } private Either<InputDefinition, ResponseFormat> deleteListInput(String componentId, String inputId, - org.openecomp.sdc.be.model.Component component, InputDefinition inputForDelete, + Component component, InputDefinition inputForDelete, StorageOperationStatus status) { // the input is created by 'Declare List'. - // need to 1. undeclare properties, 2. delete input, 3. delete private data type StorageOperationStatus storageOperationStatus = propertyDeclarationOrchestrator.unDeclarePropertiesAsListInputs(component, inputForDelete); if (storageOperationStatus != StorageOperationStatus.OK) { @@ -762,14 +761,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { filters.setIgnoreComponentInstancesInputs(false); filters.setIgnoreComponentInstancesProperties(false); filters.setIgnoreProperties(false); - Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade + Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade .getToscaElement(componentId, filters); if (getComponentEither.isRight()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus); return Either.right(componentsUtils.getResponseFormat(actionStatus)); } - org.openecomp.sdc.be.model.Component component = getComponentEither.left().value(); + Component component = getComponentEither.left().value(); Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst(); if (!op.isPresent()) { ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java index 2d6a619cc7..a5f819d9b0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java @@ -20,10 +20,12 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; +import org.apache.commons.collections4.CollectionUtils; import org.openecomp.sdc.be.components.attribute.AttributeDeclarationOrchestrator; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; @@ -32,8 +34,12 @@ import org.openecomp.sdc.be.components.validation.ComponentValidations; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.utils.MapUtil; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstOutputsMap; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.ComponentInstanceAttribOutput; +import org.openecomp.sdc.be.model.ComponentInstanceAttribute; import org.openecomp.sdc.be.model.ComponentInstanceOutput; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.OutputDefinition; @@ -51,6 +57,7 @@ import org.openecomp.sdc.common.log.enums.StatusCode; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; @org.springframework.stereotype.Component("outputsBusinessLogic") public class OutputsBusinessLogic extends BaseBusinessLogic { @@ -58,8 +65,8 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { private static final String CREATE_OUTPUT = "CreateOutput"; private static final Logger log = Logger.getLogger(OutputsBusinessLogic.class); private static final String FAILED_TO_FOUND_COMPONENT_ERROR = "Failed to found component {}, error: {}"; - private static final String GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP = "Going to execute rollback on create group."; - private static final String GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP = "Going to execute commit on create group."; + private static final String GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_OUTPUTS = "Going to execute rollback on create outputs."; + private static final String GOING_TO_EXECUTE_COMMIT_ON_CREATE_OUTPUTS = "Going to execute commit on create outputs."; private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(OutputsBusinessLogic.class); private static final String FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_COMPONENT_INSTANCE_ID = "Failed to found component instance outputs componentInstanceId: {}"; private static final String FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_ERROR = "Failed to found component instance outputs {}, error: {}"; @@ -94,7 +101,7 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { if (!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)) { final ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND; log.debug(FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_ERROR, componentInstanceId, actionStatus); - loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS, component.getComponentMetadataForSupportLog(), StatusCode.ERROR, + loggerSupportability.log(LoggerSupportabilityActions.CREATE_OUTPUTS, component.getComponentMetadataForSupportLog(), StatusCode.ERROR, FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_COMPONENT_INSTANCE_ID, componentInstanceId); return Either.right(componentsUtils.getResponseFormat(actionStatus)); } @@ -110,11 +117,11 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { return createMultipleOutputs(userId, componentId, componentTypeEnum, componentInstOutputsMap, true, false); } - public Either<List<OutputDefinition>, ResponseFormat> createMultipleOutputs(final String userId, final String componentId, - final ComponentTypeEnum componentType, - final ComponentInstOutputsMap componentInstOutputsMapUi, - final boolean shouldLockComp, final boolean inTransaction) { - Either<List<OutputDefinition>, ResponseFormat> result = null; + private Either<List<OutputDefinition>, ResponseFormat> createMultipleOutputs(final String userId, final String componentId, + final ComponentTypeEnum componentType, + final ComponentInstOutputsMap componentInstOutputsMapUi, + final boolean shouldLockComp, final boolean inTransaction) { + Either<List<OutputDefinition>, ResponseFormat> result = Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST.value())); org.openecomp.sdc.be.model.Component component = null; try { validateUserExists(userId); @@ -129,11 +136,11 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { return result; } finally { if (!inTransaction) { - if (result == null || result.isRight()) { - log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP); + if (result.isRight()) { + log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_OUTPUTS); janusGraphDao.rollback(); } else { - log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP); + log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_OUTPUTS); janusGraphDao.commit(); } } @@ -144,11 +151,11 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { } } - private org.openecomp.sdc.be.model.Component getAndValidateComponentForCreate(final String userId, final String componentId, - final ComponentTypeEnum componentType, - final boolean shouldLockComp) { + private Component getAndValidateComponentForCreate(final String userId, final String componentId, + final ComponentTypeEnum componentType, + final boolean shouldLockComp) { final ComponentParametersView componentParametersView = getBaseComponentParametersView(); - final org.openecomp.sdc.be.model.Component component = validateComponentExists(componentId, componentType, componentParametersView); + final Component component = validateComponentExists(componentId, componentType, componentParametersView); if (shouldLockComp) { // lock the component lockComponent(component, CREATE_OUTPUT); @@ -161,7 +168,11 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { final List<OutputDefinition> outputsToCreate) { final Map<String, OutputDefinition> outputsToPersist = MapUtil.toMap(outputsToCreate, OutputDefinition::getName); assignOwnerIdToOutputs(userId, outputsToPersist); - return toscaOperationFacade.addOutputsToComponent(outputsToPersist, cmptId).left().map(persistedOutputs -> outputsToCreate); + final var statusEither = toscaOperationFacade.addOutputsToComponent(outputsToPersist, cmptId); + if (statusEither.isRight()) { + return statusEither; + } + return statusEither.left().map(persistedOutputs -> outputsToCreate); } private void assignOwnerIdToOutputs(final String userId, final Map<String, OutputDefinition> outputsToCreate) { @@ -189,7 +200,6 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { * @return */ public OutputDefinition deleteOutput(final String componentId, final String userId, final String outputId) { - Either<OutputDefinition, ResponseFormat> deleteEither = null; if (log.isDebugEnabled()) { log.debug("Going to delete output id: {}", outputId); } @@ -236,4 +246,62 @@ public class OutputsBusinessLogic extends BaseBusinessLogic { unlockComponent(failed, component); } } + + public Either<List<OutputDefinition>, ResponseFormat> createOutputsInGraph(final Map<String, OutputDefinition> outputs, + final Component component, + final String userId) { + + final List<OutputDefinition> result = new ArrayList<>(); + for (final Map.Entry<String, OutputDefinition> outputDefinition : outputs.entrySet()) { + final var outputDefinitionValue = outputDefinition.getValue(); + outputDefinitionValue.setName(outputDefinition.getKey()); + + final String value = outputDefinitionValue.getValue(); + if (value != null) { + final List<String> getAttribute = (List<String>) ImportUtils.loadYamlAsStrictMap(value) + .get(ToscaGetFunctionType.GET_ATTRIBUTE.getFunctionName()); + if (getAttribute.size() == 2) { + final var optionalComponentInstance = component.getComponentInstanceByName(getAttribute.get(0)); + if (optionalComponentInstance.isPresent()) { + final var createdOutputs + = createOutputs(component.getUniqueId(), userId, getAttribute.get(1), optionalComponentInstance.get()); + if (createdOutputs.isRight()) { + return Either.right((createdOutputs.right().value())); + } + result.addAll(createdOutputs.left().value()); + } else { + // From SELF + outputDefinitionValue.setInstanceUniqueId(component.getUniqueId()); + } + } + } + } + return Either.left(result); + + } + + private Either<List<OutputDefinition>, ResponseFormat> createOutputs(final String componentUniqueId, final String userId, + final String attributeName, + final ComponentInstance componentInstance) { + // From Instance + final List<OutputDefinition> result = new ArrayList<>(); + final var componentInstanceAttributes = componentInstance.getAttributes(); + if (CollectionUtils.isNotEmpty(componentInstanceAttributes)) { + final var componentInstanceAttributeOptional = componentInstanceAttributes.stream() + .filter(ad -> ad.getName().equals(attributeName)).map(ComponentInstanceAttribute::new).findFirst(); + if (componentInstanceAttributeOptional.isPresent()) { + final var componentInstOutputsMap = new ComponentInstOutputsMap(); + componentInstOutputsMap.setComponentInstanceAttributes(Collections.singletonMap(componentInstance.getUniqueId(), + Collections.singletonList(new ComponentInstanceAttribOutput(componentInstanceAttributeOptional.get())))); + final var createdOutputs = createMultipleOutputs(userId, componentUniqueId, ComponentTypeEnum.SERVICE, + componentInstOutputsMap, true, false); + if (createdOutputs.isRight()) { + return Either.right((createdOutputs.right().value())); + } + result.addAll(createdOutputs.left().value()); + } + } + return Either.left(result); + } + } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index 34460f46d5..3c21ae16a7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -97,6 +97,7 @@ import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.NodeTypeInfo; import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.OutputDefinition; import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; @@ -252,7 +253,7 @@ public class ServiceImportBusinessLogic { throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value()); } return createServiceFromYaml(service, csarInfo.getMainTemplateContent(), csarInfo.getMainTemplateName(), nodeTypesInfo, csarInfo, - findNodeTypesArtifactsToHandleRes.left().value(), true, false, null); + findNodeTypesArtifactsToHandleRes.left().value(), true, false, null, user.getUserId()); } catch (Exception e) { log.debug("Exception occured when createServiceFromCsar,error is:{}", e.getMessage(), e); throw new ComponentException(ActionStatus.GENERAL_ERROR); @@ -262,7 +263,8 @@ public class ServiceImportBusinessLogic { protected Service createServiceFromYaml(Service service, String topologyTemplateYaml, String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo, Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate, - boolean shouldLock, boolean inTransaction, String nodeName) throws BusinessLogicException { + boolean shouldLock, boolean inTransaction, String nodeName, final String userId) + throws BusinessLogicException { List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); Service createdService; CreateServiceFromYamlParameter csfyp = new CreateServiceFromYamlParameter(); @@ -277,7 +279,7 @@ public class ServiceImportBusinessLogic { csfyp.setNodeTypesInfo(nodeTypesInfo); csfyp.setCsarInfo(csarInfo); csfyp.setNodeName(nodeName); - createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp); + createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp, userId); log.debug("#createResourceFromYaml - The resource {} has been created ", service.getName()); } catch (ComponentException | BusinessLogicException e) { log.debug("Create Service from yaml failed", e); @@ -291,7 +293,8 @@ public class ServiceImportBusinessLogic { protected Service createServiceAndRIsFromYaml(Service service, boolean isNormative, Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate, - boolean shouldLock, boolean inTransaction, CreateServiceFromYamlParameter csfyp) + boolean shouldLock, boolean inTransaction, CreateServiceFromYamlParameter csfyp, + final String userId) throws BusinessLogicException { List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>(); String yamlName = csfyp.getYamlName(); @@ -325,7 +328,7 @@ public class ServiceImportBusinessLogic { log.trace("************* Going to add inputs from yaml {}", yamlName); Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs(); service = serviceImportParseLogic.createInputsOnService(service, inputs); - log.trace("************* Finish to add inputs from yaml {}", yamlName); + log.trace("************* Finished to add inputs from yaml {}", yamlName); ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties = parsedToscaYamlInfo.getSubstitutionFilterProperties(); service = serviceImportParseLogic.createSubstitutionFilterOnService(service, substitutionFilterProperties); log.trace("************* Added Substitution filter from interface yaml {}", yamlName); @@ -334,6 +337,11 @@ public class ServiceImportBusinessLogic { service = createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap, topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName); log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName); + log.trace("************* Going to add outputs from yaml {}", yamlName); + Map<String, OutputDefinition> outputs = parsedToscaYamlInfo.getOutputs(); + service = serviceImportParseLogic.createOutputsOnService(service, outputs, userId); + log.trace("************* Finished to add outputs from yaml {}", yamlName); + Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), service.getSystemName()); if (validateUpdateVfGroupNamesRes.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java index 7a5b90976f..507f4ad32c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java @@ -77,6 +77,7 @@ import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.NodeTypeInfo; import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.OutputDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.RelationshipImpl; import org.openecomp.sdc.be.model.RelationshipInfo; @@ -112,7 +113,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.GeneralUtility; import org.openecomp.sdc.common.util.ValidationUtils; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.beans.factory.annotation.Autowired; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; @@ -131,27 +131,18 @@ public class ServiceImportParseLogic { private static final String CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES = "Create Resource - validateCapabilityTypesCreate"; private static final String CATEGORY_IS_EMPTY = "Resource category is empty"; private static final Logger log = Logger.getLogger(ServiceImportParseLogic.class); - @Autowired private final ServiceBusinessLogic serviceBusinessLogic; - @Autowired private final ComponentsUtils componentsUtils; - @Autowired private final ToscaOperationFacade toscaOperationFacade; - @Autowired private final LifecycleBusinessLogic lifecycleBusinessLogic; - @Autowired private final InputsBusinessLogic inputsBusinessLogic; - @Autowired private final ResourceImportManager resourceImportManager; - @Autowired private final ComponentSubstitutionFilterBusinessLogic substitutionFilterBusinessLogic; - @Autowired private final IInterfaceLifecycleOperation interfaceTypeOperation; - @Autowired private final ICapabilityTypeOperation capabilityTypeOperation; - @Autowired private final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic; private final GroupBusinessLogic groupBusinessLogic; + private final OutputsBusinessLogic outputsBusinessLogic; public ServiceImportParseLogic(final ServiceBusinessLogic serviceBusinessLogic, final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade, final LifecycleBusinessLogic lifecycleBusinessLogic, @@ -159,7 +150,7 @@ public class ServiceImportParseLogic { final ComponentSubstitutionFilterBusinessLogic substitutionFilterBusinessLogic, final IInterfaceLifecycleOperation interfaceTypeOperation, final ICapabilityTypeOperation capabilityTypeOperation, final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic, - final GroupBusinessLogic groupBusinessLogic) { + final GroupBusinessLogic groupBusinessLogic, final OutputsBusinessLogic outputsBusinessLogic) { this.serviceBusinessLogic = serviceBusinessLogic; this.componentsUtils = componentsUtils; this.toscaOperationFacade = toscaOperationFacade; @@ -171,6 +162,7 @@ public class ServiceImportParseLogic { this.capabilityTypeOperation = capabilityTypeOperation; this.componentNodeFilterBusinessLogic = componentNodeFilterBusinessLogic; this.groupBusinessLogic = groupBusinessLogic; + this.outputsBusinessLogic = outputsBusinessLogic; } public Either<Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle( @@ -1039,8 +1031,6 @@ public class ServiceImportParseLogic { reqDef.setLeftOccurrences(String.valueOf(left)); validRegDef = reqDef; break; - } else { - continue; } } else { validRegDef = reqDef; @@ -1066,8 +1056,6 @@ public class ServiceImportParseLogic { reqDef.setLeftOccurrences(String.valueOf(left)); validRegDef = reqDef; break; - } else { - continue; } } else { validRegDef = reqDef; @@ -1371,6 +1359,24 @@ public class ServiceImportParseLogic { return updatedResource.left().value(); } + public Service createOutputsOnService(final Service service, final Map<String, OutputDefinition> outputs, final String userId) { + if (MapUtils.isNotEmpty(outputs) || isNotEmpty(service.getOutputs())) { + final Either<List<OutputDefinition>, ResponseFormat> createOutputs = outputsBusinessLogic.createOutputsInGraph(outputs, service, userId); + if (createOutputs.isRight()) { + throw new ComponentException(createOutputs.right().value()); + } + } else { + return service; + } + final Either<Service, StorageOperationStatus> updatedResource = toscaOperationFacade.getToscaElement(service.getUniqueId()); + if (updatedResource.isRight()) { + throw new ComponentException( + componentsUtils.getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(updatedResource.right().value()), service, + ComponentTypeEnum.SERVICE)); + } + return updatedResource.left().value(); + } + public Service createSubstitutionFilterOnService(Service service, ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties) throws BusinessLogicException { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java index 7c300b310d..1b1111a86e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java @@ -1061,16 +1061,16 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { } } - protected void handleImportService(Wrapper<Response> responseWrapper, User user, UploadServiceInfo serviceInfoObject, String yamlAsString, - ServiceAuthorityTypeEnum authority, boolean createNewVersion, String serviceUniqueId) throws ZipException { + protected void handleImportService(Wrapper<Response> responseWrapper, User user, UploadServiceInfo serviceInfoObject, String serviceUniqueId) + throws ZipException { Response response = null; - Object representation = null; ImmutablePair<Service, ActionStatus> importedServiceStatus = null; if (CsarValidationUtils.isCsarPayloadName(serviceInfoObject.getPayloadName())) { log.debug("import service from csar"); importedServiceStatus = importServiceFromUICsar(serviceInfoObject, user, serviceUniqueId); } if (importedServiceStatus != null) { + Object representation = null; try { representation = RepresentationUtils.toRepresentation(importedServiceStatus.left); } catch (IOException e) { @@ -1083,18 +1083,14 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { private ImmutablePair<Service, ActionStatus> importServiceFromUICsar(UploadServiceInfo serviceInfoObject, User user, String serviceUniqueId) throws ZipException { - Service newService; - ImmutablePair<Service, ActionStatus> result = null; - ActionStatus actionStatus; Service service = new Service(); String payloadName = serviceInfoObject.getPayloadName(); fillServiceFromServiceInfoObject(service, serviceInfoObject); Map<String, byte[]> csarUIPayloadRes = getCsarFromPayload(serviceInfoObject); getAndValidateCsarYaml(csarUIPayloadRes, service, user, payloadName); - newService = serviceImportManager.getServiceImportBusinessLogic() + final Service newService = serviceImportManager.getServiceImportBusinessLogic() .createService(service, AuditingActionEnum.CREATE_SERVICE, user, csarUIPayloadRes, payloadName); - actionStatus = ActionStatus.CREATED; - return new ImmutablePair<>(newService, actionStatus); + return new ImmutablePair<>(newService, ActionStatus.CREATED); } private void fillServiceFromServiceInfoObject(Service service, UploadServiceInfo serviceInfoObject) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java index c26f3ca522..f49bfdc637 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java @@ -672,18 +672,17 @@ public class ServiceServlet extends AbstractValidationsServlet { } private Wrapper<Response> performUIImport(String data, final HttpServletRequest request, String userId, - String ServiceUniqueId) throws FileNotFoundException, ZipException { + String serviceUniqueId) throws FileNotFoundException, ZipException { Wrapper<Response> responseWrapper = new Wrapper<>(); Wrapper<User> userWrapper = new Wrapper<>(); Wrapper<UploadServiceInfo> uploadServiceInfoWrapper = new Wrapper<>(); Wrapper<String> yamlStringWrapper = new Wrapper<>(); - ServiceAuthorityTypeEnum ServiceAuthorityEnum = ServiceAuthorityTypeEnum.USER_TYPE_UI; - commonServiceGeneralValidations(responseWrapper, userWrapper, uploadServiceInfoWrapper, ServiceAuthorityEnum, userId, data); + ServiceAuthorityTypeEnum serviceAuthorityTypeEnum = ServiceAuthorityTypeEnum.USER_TYPE_UI; + commonServiceGeneralValidations(responseWrapper, userWrapper, uploadServiceInfoWrapper, serviceAuthorityTypeEnum, userId, data); specificServiceAuthorityValidations(responseWrapper, uploadServiceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), request, - data, ServiceAuthorityEnum); + data, serviceAuthorityTypeEnum); if (responseWrapper.isEmpty()) { - handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), - yamlStringWrapper.getInnerElement(), ServiceAuthorityEnum, true, ServiceUniqueId); + handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), serviceUniqueId); } return responseWrapper; } @@ -775,8 +774,7 @@ public class ServiceServlet extends AbstractValidationsServlet { uploadServiceInfoWrapper.getInnerElement().setProjectCode(oldService.getProjectCode()); if (responseWrapper.isEmpty()) { log.debug("importReplaceService:start handleImportService"); - handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), - yamlStringWrapper.getInnerElement(), serviceAuthorityEnum, true, null); + handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), null); } return responseWrapper.getInnerElement(); } catch (IOException | ZipException e) { |