From b734ea21ac7be393c59cf9976f0e5ddeaf27d568 Mon Sep 17 00:00:00 2001 From: siddharth0905 Date: Thu, 22 Nov 2018 13:37:31 +0530 Subject: Service Workflow changes Service workflow change with few bug fixes Change-Id: Ice2376565bf46fb8d86fb6062654ec54bb2daa43 Issue-ID: SDC-1937 Signed-off-by: siddharth0905 --- .../be/components/impl/ArtifactResolverImpl.java | 16 ++--- .../be/components/impl/ArtifactsBusinessLogic.java | 75 ++++++++++------------ .../impl/InterfaceOperationBusinessLogic.java | 11 +++- .../validation/InterfaceOperationValidation.java | 31 +++++---- .../servlet/ArtifactExternalServlet.java | 26 +++++--- .../tosca/utils/InterfacesOperationsToscaUtil.java | 15 +++-- .../sdc/be/tosca/utils/OperationArtifactUtil.java | 3 +- 7 files changed, 99 insertions(+), 78 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java index c7f92d2184..2b23c52cd0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java @@ -54,20 +54,20 @@ public class ArtifactResolverImpl implements ArtifactsResolver { Map deploymentArtifacts = Optional.ofNullable(component.getDeploymentArtifacts()).orElse(Collections.emptyMap()); Map artifacts = Optional.ofNullable(component.getArtifacts()).orElse(Collections.emptyMap()); Map interfaceArtifacts= Collections.emptyMap(); - if (componentType == ComponentTypeEnum.RESOURCE) { - Map interfaces = ((Resource) component).getInterfaces(); - if (MapUtils.isNotEmpty(interfaces)) { - interfaceArtifacts = interfaces.values().stream() - .flatMap(inte -> inte.getOperationsMap().values().stream()) - .map(operation -> operation.getImplementationArtifact()) - .collect(Collectors.toMap(artifactDefinition -> artifactDefinition.getUniqueId(), artifactDefinition -> artifactDefinition)); - } + Map interfaces = component.getInterfaces(); + if (MapUtils.isNotEmpty(interfaces)) { + interfaceArtifacts = interfaces.values().stream() + .flatMap(inte -> inte.getOperationsMap().values().stream()) + .map(operation -> operation.getImplementationArtifact()) + .collect(Collectors.toMap(artifactDefinition -> artifactDefinition.getUniqueId(), + artifactDefinition -> artifactDefinition)); } Map serviceApiArtifacts = Collections.emptyMap(); if (componentType.equals(ComponentTypeEnum.SERVICE)) { serviceApiArtifacts = Optional.ofNullable(((Service) component).getServiceApiArtifacts()).orElse(Collections.emptyMap()); } + return appendAllArtifacts(deploymentArtifacts, artifacts, interfaceArtifacts, serviceApiArtifacts); } 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 fc4a739614..65a87d444b 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 @@ -3100,24 +3100,23 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } NodeTypeEnum convertParentType = convertParentType(componentType); // fetch the resource from storage - Either resourceStorageOperationStatusEither = + Either componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(parentId); - if (resourceStorageOperationStatusEither.isRight()) { - StorageOperationStatus errorStatus = resourceStorageOperationStatusEither.right().value(); + if (componentStorageOperationStatusEither.isRight()) { + StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value(); log.debug("Failed to fetch resource information by resource id, error {}", errorStatus); return Either.right(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus))); } - Resource storedResource = resourceStorageOperationStatusEither.left().value(); + Component storedComponent = componentStorageOperationStatusEither.left().value(); String interfaceToscaName = InterfaceUtils.createInterfaceToscaResourceName( - storedResource.getName()); + storedComponent.getName()); //fetch the interface from storage - Optional interfaceDefinition = storedResource.getInterfaces().values() - .stream() - .filter(interfaceDef -> interfaceDef.getToscaResourceName() - .equals(interfaceToscaName)) - .findFirst(); + Optional interfaceDefinition = + storedComponent.getInterfaces().values().stream() + .filter(interfaceDef -> interfaceDef.getToscaResourceName() + .equals(interfaceToscaName)).findFirst(); if (!interfaceDefinition.isPresent()) { log.debug("Failed to get resource interface for resource Id {}", parentId); ResponseFormat responseFormat = componentsUtils.getResponseFormat( @@ -3154,7 +3153,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { operation.setImplementation(implementationArtifact); gotInterface.setOperationsMap(operationsMap); Either interfaceDefinitionStorageOperationStatusEither = - interfaceOperation.updateInterface(storedResource.getUniqueId(), gotInterface); + interfaceOperation.updateInterface(storedComponent.getUniqueId(), gotInterface); if (interfaceDefinitionStorageOperationStatusEither.isRight()){ StorageOperationStatus storageOperationStatus = interfaceDefinitionStorageOperationStatusEither.right().value(); ActionStatus actionStatus = @@ -3163,16 +3162,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } String uniqueId = implementationArtifact.getUniqueId(); - Either artifactCount = artifactCassandraDao.getCountOfArtifactById(uniqueId); - if(artifactCount.isLeft()){ - CassandraOperationStatus cassandraOperationStatus = artifactCassandraDao.deleteArtifact(uniqueId); - if(cassandraOperationStatus != CassandraOperationStatus.OK){ - log.debug("Failed to persist operation {} artifact, error is {}",operation.getName(),cassandraOperationStatus); - StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraOperationStatus); - ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus); - return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse)); - } - } artifactData.setId(uniqueId); CassandraOperationStatus cassandraOperationStatus = artifactCassandraDao.saveArtifact(artifactData); if(cassandraOperationStatus != CassandraOperationStatus.OK){ @@ -3647,23 +3636,25 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } } } - switch (component.getComponentType()) { - case RESOURCE: - Map interfaces = ((Resource) component).getInterfaces(); - if (!found && interfaces != null) { - for (Map.Entry entry : interfaces.entrySet()) { - Map operations = entry.getValue().getOperationsMap(); - for (Map.Entry entryOp : operations.entrySet()) { - if (entryOp.getValue().getImplementation() != null && entryOp.getValue() - .getImplementation() - .getUniqueId() - .equals(artifactId)) { - found = true; - break; - } - } + + Map interfaces = component.getInterfaces(); + if (!found && interfaces != null) { + for (Map.Entry entry : interfaces.entrySet()) { + Map operations = entry.getValue().getOperationsMap(); + for (Map.Entry entryOp : operations.entrySet()) { + if (entryOp.getValue().getImplementation() != null && entryOp.getValue() + .getImplementation() + .getUniqueId() + .equals(artifactId)) { + found = true; + break; } } + } + } + + switch (component.getComponentType()) { + case RESOURCE: break; case SERVICE: Map apiArtifacts = ((Service) component).getServiceApiArtifacts(); @@ -5106,18 +5097,18 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } private Either fetchInterfaceName(String componentId) { - Either resourceStorageOperationStatusEither = + Either componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId); - if (resourceStorageOperationStatusEither.isRight()) { - StorageOperationStatus errorStatus = resourceStorageOperationStatusEither.right().value(); - log.debug("Failed to fetch resource information by resource id, error {}", errorStatus); + if (componentStorageOperationStatusEither.isRight()) { + StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value(); + log.debug("Failed to fetch component information by component id, error {}", errorStatus); return Either.right(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus))); } - Resource storedResource = resourceStorageOperationStatusEither.left().value(); + Component storedComponent = componentStorageOperationStatusEither.left().value(); return Either.left(InterfaceUtils.createInterfaceToscaResourceName( - storedResource.getName())); + storedComponent.getName())); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index 26e256fb00..fed2cac518 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -208,7 +208,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { if (getOperationEither.isRight()){ return Either.right(getOperationEither.right().value()); } - operation.setImplementation(getOperationEither.left().value().getImplementation()); + updateExistingOperation(operation, getOperationEither.left().value().getImplementation().getArtifactUUID()); result = interfaceOperation.updateInterfaceOperation(componentId, interfaceDefinition, operation); } @@ -265,6 +265,15 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { operation.setImplementation(artifactDefinition); } + private void updateExistingOperation(Operation operation, String artifactUUID){ + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setArtifactUUID(artifactUUID); + artifactDefinition.setUniqueId(artifactUUID); + artifactDefinition.setArtifactType(ArtifactTypeEnum.WORKFLOW.getType()); + artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT); + operation.setImplementation(artifactDefinition); + } + private Either lockComponentResult(boolean lock, org.openecomp.sdc.be.model.Component component, String action){ if (lock) { Either lockResult = lockComponent(component.getUniqueId(), component, action); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java index 8c90501140..7b650e4fad 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java @@ -16,6 +16,17 @@ package org.openecomp.sdc.be.components.validation; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + import fj.data.Either; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; @@ -33,17 +44,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - @Component("interfaceOperationValidation") public class InterfaceOperationValidation { @@ -279,8 +279,8 @@ public class InterfaceOperationValidation { .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY)); } private Boolean isOutputParameterNameEmpty(Operation operationDataDefinition) { - return operationDataDefinition.getInputs().getListToscaDataDefinition().stream() - .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY)); + return operationDataDefinition.getOutputs().getListToscaDataDefinition().stream() + .anyMatch(outputParam -> outputParam.getName() == null || outputParam.getName().trim().equals(StringUtils.EMPTY)); } private Either validateInputPropertyExistInComponent(Operation operation, @@ -305,7 +305,10 @@ public class InterfaceOperationValidation { private boolean validateInputExistsInComponent(OperationInputDefinition input, List inputs) { - return inputs.stream().anyMatch(inp -> inp.getUniqueId().equals(input.getInputId())); + return inputs.stream().anyMatch(inp -> inp.getUniqueId().equals(input.getInputId())) + || ((input.getInputId().contains(".") + && inputs.stream().anyMatch(inp -> inp.getUniqueId().equals( + input.getInputId().substring(0, input.getInputId().lastIndexOf(".")))))) ; } private ResponseFormatManager getResponseFormatManager() { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java index c53e343512..03c5e0fbf1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,6 +21,14 @@ package org.openecomp.sdc.be.externalapi.servlet; import com.jcabi.aspects.Loggable; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; + import fj.data.Either; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -65,11 +73,12 @@ import javax.ws.rs.core.Response; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.EnumMap; import java.util.HashMap; import java.util.Map; /** * This Servlet serves external users operations on artifacts. - * + * * @author mshitrit * */ @@ -89,7 +98,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { private static String startLog = "Start handle request of "; @POST - @Path("/resources/{uuid}/interfaces/{operationUUID}/artifacts/{artifactUUID}") + @Path("/{assetType}/{uuid}/interfaces/{operationUUID}/artifacts/{artifactUUID}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "uploads of artifact to VF operation workflow", httpMethod = "POST", notes = "uploads of artifact to VF operation workflow") @ApiResponses(value = { @@ -116,6 +125,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { @ApiParam(value = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader, @ApiParam(value = "Determines the format of the body of the response", required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept, @ApiParam(value = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + @ApiParam(value = "Asset type") @PathParam("assetType") String assetType, @ApiParam(value = "The uuid of the asset as published in the metadata", required = true)@PathParam("uuid") final String uuid, @ApiParam(value = "The uuid of the operation", required = true)@PathParam("operationUUID") final String operationUUID, @ApiParam(value = "The uuid of the artifact", required = true)@PathParam("artifactUUID") final String artifactUUID, @@ -125,9 +135,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { String requestURI = request.getRequestURI(); String url = request.getMethod() + " " + requestURI; log.debug("{} {}", startLog, url); - ComponentTypeEnum componentType = ComponentTypeEnum.RESOURCE; - String componentTypeValue = componentType.getValue(); - ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue); + ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(assetType); ArtifactDefinition artifactDefinition = null; if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) { @@ -144,7 +152,9 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { if (responseWrapper.isEmpty()) { ServletContext context = request.getSession().getServletContext(); ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context); - Either uploadArtifactEither = artifactsLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request, componentType, uuid, artifactUUID, operationUUID, + Either uploadArtifactEither = artifactsLogic + .updateArtifactOnInterfaceOperationByResourceUUID(data, request, ComponentTypeEnum + .findByParamName(assetType), uuid, artifactUUID, operationUUID, resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE)); if (uploadArtifactEither.isRight()) { log.debug(FAILED_TO_UPDATE_ARTIFACT); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java index c3628df17b..7afad74f64 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -181,9 +182,13 @@ public class InterfacesOperationsToscaUtil { for (OperationInputDefinition input : operation.getInputs().getListToscaDataDefinition()) { ToscaProperty toscaInput = new ToscaProperty(); toscaInput.setDescription(input.getDescription()); - String mappedPropertyName = getLastPartOfName(input.getInputId()); - toscaInput.setType(input.getType()); + String mappedPropertyName = null; + if (Objects.nonNull(input.getInputId())) { + mappedPropertyName = input.getInputId().substring(input.getInputId().indexOf(DOT) + 1); + } toscaInput.setDefaultp(createDefaultValue(mappedPropertyName)); + + toscaInput.setType(input.getType()); toscaInput.setRequired(input.isRequired()); toscaInputs.put(input.getName(), toscaInput); } @@ -195,13 +200,15 @@ public class InterfacesOperationsToscaUtil { Map> getPropertyMap = new HashMap<>(); List values = new ArrayList<>(); values.add(SELF); - values.add(propertyName); + if (Objects.nonNull(propertyName) && !propertyName.isEmpty()) { + values.addAll(Arrays.asList(propertyName.split("\\."))); + } + getPropertyMap.put(GET_PROPERTY, values); return getPropertyMap; } - private static Map getObjectAsMap(Object obj) { ObjectMapper objectMapper = new ObjectMapper(); if (obj instanceof ToscaInterfaceDefinition) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java index b70ae90f7c..0d772cfcab 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java @@ -33,6 +33,7 @@ import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.tosca.CsarUtils; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.common.api.ArtifactTypeEnum; @@ -53,7 +54,7 @@ public class OperationArtifactUtil { */ static String createOperationArtifactPath(Component component, OperationDataDefinition operation, boolean isAssociatedResourceComponent) { - if (!(component instanceof Resource)) { + if (!(component instanceof Resource || component instanceof Service)) { return null; } if (isAssociatedResourceComponent) { -- cgit 1.2.3-korg