diff options
author | 2017-07-31 15:50:46 +0300 | |
---|---|---|
committer | 2017-08-02 21:18:34 +0300 | |
commit | f5854fd32c19c44d32a3e6739b30271d4dccd393 (patch) | |
tree | 6e7420dd3d82200849e51c2af3f2696f11815d12 /catalog-be/src/main/java/org/openecomp | |
parent | e280d7229f42210719b76775cd47bddb675c3c53 (diff) |
[SDC] code rebase for sdc resync to LF
Change-Id: If6d87c9e324f508a8a6b80b10a03d1843901472e
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp')
13 files changed, 308 insertions, 114 deletions
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 e4c75eab05..902bc8a298 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 @@ -1526,7 +1526,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null); return Either.right(responseFormat); } - Either<ArtifactDefinition, Operation> insideEither = Either.left(artifactDefinition); + if(artifactDefinition.getPayloadData() == null) { + log.debug("Empty payload data returned from DB by artifat id {}", artifactId); + ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactId); + handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null); + return Either.right(responseFormat); + + } + Either<ArtifactDefinition, Operation> insideEither = Either.left(artifactDefinition); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK); handleAuditing(auditingAction, parent, componentId, user, artifactDefinition, null, artifactId, responseFormat, componentType, null); return Either.left(insideEither); 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 5b6488d788..6dc83bfc2b 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 @@ -401,6 +401,15 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic { return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result))); } componentInstance.setDeploymentArtifacts(finalDeploymentArtifacts); + + + artStatus = toscaOperationFacade.addInformationalArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, originComponent.getArtifacts()); + if ( artStatus != StorageOperationStatus.OK){ + log.debug("Failed to add informational artifacts to the instance {} belonging to the conatiner {}. Status is {}", componentInstance.getUniqueId(), containerComponent.getUniqueId(), artStatus); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false))); + + } + componentInstance.setArtifacts(originComponent.getArtifacts()); return Either.left(ActionStatus.OK); } @@ -1828,23 +1837,23 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } return result; } + + public Either<ComponentInstance, ResponseFormat> deleteServiceProxy(String containerComponentType, String containerComponentId, String serviceProxyId, String userId) { + // TODO Add implementation + Either<ComponentInstance, ResponseFormat> result = Either.left(new ComponentInstance()); + return result; + } - private Boolean validateInstanceNameUniqueness(Component containerComponent, ComponentInstance oldComponentInstance, String newInstanceName) { - Boolean isUnique = true; - String newInstanceNormalizedName = ValidationUtils.normalizeComponentInstanceName(newInstanceName); - if (!oldComponentInstance.getNormalizedName().equals(newInstanceNormalizedName)) { - Optional<ComponentInstance> foundComponentInstance = containerComponent.getComponentInstances().stream().filter(ci -> ci.getNormalizedName().equals(newInstanceNormalizedName)).findFirst(); - if (foundComponentInstance.isPresent()) { - isUnique = false; - } - if (isUnique) { - foundComponentInstance = containerComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId().endsWith(newInstanceNormalizedName)).findFirst(); - if (foundComponentInstance.isPresent()) { - isUnique = false; - } - } - } - return isUnique; + public Either<ComponentInstance, ResponseFormat> createServiceProxy(String containerComponentType, String containerComponentId, String userId, ComponentInstance componentInstance) { + // TODO Add implementation + Either<ComponentInstance, ResponseFormat> result = Either.left(new ComponentInstance()); + return result; + } + + public Either<ComponentInstance, ResponseFormat> changeServiceProxyVersion(String containerComponentType, String containerComponentId, String serviceProxyId, String userId) { + // TODO Add implementation + Either<ComponentInstance, ResponseFormat> result = Either.left(new ComponentInstance()); + return result; } private Boolean validateInstanceNameUniquenessUponUpdate(Component containerComponent, ComponentInstance oldComponentInstance, String newInstanceName) { @@ -1889,12 +1898,11 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic { resourceInstanceForUpdate.setCustomizationUUID(origInstanceForUpdate.getCustomizationUUID()); - if (StringUtils.isEmpty(resourceInstanceForUpdate.getName())) { + if (StringUtils.isEmpty(resourceInstanceForUpdate.getName()) && StringUtils.isNotEmpty(origInstanceForUpdate.getName())) { resourceInstanceForUpdate.setName(origInstanceForUpdate.getName()); - } - if (StringUtils.isEmpty(resourceInstanceForUpdate.getNormalizedName())) - resourceInstanceForUpdate.setNormalizedName(origInstanceForUpdate.getNormalizedName()); + + resourceInstanceForUpdate.setNormalizedName(ValidationUtils.normalizeComponentInstanceName(resourceInstanceForUpdate.getName())); if (StringUtils.isEmpty(resourceInstanceForUpdate.getIcon())) resourceInstanceForUpdate.setIcon(origInstanceForUpdate.getIcon()); 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 838cd53458..1755d0b20c 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 @@ -21,12 +21,7 @@ package org.openecomp.sdc.be.components.impl; import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; import java.util.function.Consumer; import java.util.function.Function; @@ -61,22 +56,55 @@ public final class ImportUtils { private ImportUtils() { } - public static Yaml STRICT_MAPPING_YAML_LOADER = new YamlLoader().getStrictYamlLoader(); private static CustomResolver customResolver = new CustomResolver(); + private static Yaml STRICT_MAPPING_YAML_LOADER = new YamlLoader().getStrictYamlLoader(); private static class CustomResolver extends Resolver { - @Override + @Override protected void addImplicitResolvers() { - // avoid implicit resolvers for strings that can be interpreted as boolean values - addImplicitResolver(Tag.STR, EMPTY, ""); - addImplicitResolver(Tag.STR, NULL, null); - addImplicitResolver(Tag.NULL, NULL, "~nN\0"); - addImplicitResolver(Tag.NULL, EMPTY, null); - addImplicitResolver(Tag.YAML, YAML, "!&*"); + // avoid implicit resolvers for strings that can be interpreted as boolean values + addImplicitResolver(Tag.STR, EMPTY, ""); + addImplicitResolver(Tag.STR, NULL, null); + addImplicitResolver(Tag.NULL, NULL, "~nN\0"); + addImplicitResolver(Tag.NULL, EMPTY, null); + addImplicitResolver(Tag.INT, INT, "-+0123456789"); + addImplicitResolver(Tag.FLOAT, FLOAT, "-+0123456789."); + addImplicitResolver(Tag.YAML, YAML, "!&*"); } } - + + + private static void buildMap(Map<String, Object> output, Map<String, Object> map) { + for (Entry<String, Object> entry : map.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + if (value instanceof Map) { + Map<String, Object> result = new LinkedHashMap<>(); + buildMap(result, (Map) value); + output.put(key, result); + } + else if (value instanceof Collection) { + Map<String, Object> result = new LinkedHashMap<>(); + int i = 0; + for(Object item : (Collection<Object>) value) { + buildMap(result, Collections.singletonMap("[" + (i++) + "]", item)); + } + output.put(key, new ArrayList<>(result.values())); + } + else { + output.put(key, value); + } + } + } + + public static Map<String, Object> loadYamlAsStrictMap(String content){ + Map<String, Object> result = new LinkedHashMap<>(); + Object map = STRICT_MAPPING_YAML_LOADER.load(content); + buildMap(result, (Map<String, Object>)map); + return result; + } + private static class YamlLoader extends YamlProcessor { public Yaml getStrictYamlLoader() { return createYaml(); 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 f85e25e5fb..892da8af9d 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 @@ -1274,6 +1274,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { input.setName(inputName + "_" + prop.getName()); } + input.setDefaultValue(prop.getValue()); input.setName(inputName); input.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(component.getUniqueId(), input.getName())); input.setInputPath(propertiesName); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 0aa4a6f006..a8d841387b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -154,6 +154,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import fj.data.Either; +import org.yaml.snakeyaml.parser.ParserException; @org.springframework.stereotype.Component("resourceBusinessLogic") public class ResourceBusinessLogic extends ComponentBusinessLogic { @@ -686,7 +687,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return result; } - private Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle(Map<String, NodeTypeInfo> nodeTypesInfo, Map<String, byte[]> csar, String csarUUID, String yamlFileName, Resource oldResource, User user) { Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts = CsarUtils.extractVfcsArtifactsFromCsar(csar); @@ -695,8 +695,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { try { nodeTypesArtifactsToHandleRes = Either.left(nodeTypesArtifactsToHandle); - Map<String, String> extractedVfcToscaNames = extractVfcToscaNames(nodeTypesInfo, yamlFileName, oldResource.getSystemName()); - Either<EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>, ResponseFormat> curNodeTypeArtifactsToHandleRes = null; + Map<String, String> extractedVfcToscaNames = extractVfcToscaNames(nodeTypesInfo, yamlFileName, oldResource.getName()); + Either<EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>, ResponseFormat> curNodeTypeArtifactsToHandleRes; EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> curNodeTypeArtifactsToHandle = null; log.debug("Going to fetch node types for resource with name {} during import csar with UUID {}. ", oldResource.getName(), csarUUID); @@ -3348,7 +3348,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { resStatus = Either.right(responseFormat); return resStatus; } - currHeatParam.setCurrentValue(HeatParameterType.isValidType(currHeatParam.getType()).getConverter().convert(updatedParamValue, null, null)); + currHeatParam.setCurrentValue(paramType.getConverter().convert(updatedParamValue, null, null)); // newHeatEnvParams.add(currHeatParam); break; } @@ -3558,6 +3558,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties = new HashMap<>(); Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); + Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); Map<String, List<PropertyDefinition>> instAttributes = new HashMap<>(); Map<String, Resource> originCompMap = new HashMap<>(); @@ -3629,7 +3630,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { instRequirements.put(currentCompInstance, originRequirements); } if (originResource.getDeploymentArtifacts() != null && !originResource.getDeploymentArtifacts().isEmpty()) - instArtifacts.put(resourceInstanceId, originResource.getDeploymentArtifacts()); + instDeploymentArtifacts.put(resourceInstanceId, originResource.getDeploymentArtifacts()); + if (originResource.getArtifacts() != null && !originResource.getArtifacts().isEmpty()) + instArtifacts.put(resourceInstanceId, originResource.getArtifacts()); if (originResource.getAttributes() != null && !originResource.getAttributes().isEmpty()) instAttributes.put(resourceInstanceId, originResource.getAttributes()); if (originResource.getResourceType() != ResourceTypeEnum.CVFC) { @@ -3667,7 +3670,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.right(responseFormat); } } - StorageOperationStatus addArtToInst = toscaOperationFacade.associateArtifactToInstances(instArtifacts, resource.getUniqueId(), user); + StorageOperationStatus addArtToInst = toscaOperationFacade.associateDeploymentArtifactsToInstances(instDeploymentArtifacts, resource.getUniqueId(), user); + if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) { + log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst); + ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName); + return Either.right(responseFormat); + } + + addArtToInst = toscaOperationFacade.associateArtifactsToInstances(instArtifacts, resource.getUniqueId(), user); if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) { log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst); ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName); @@ -4212,7 +4222,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { mappedToscaTemplate = nodeTypesInfo.get(nodeName).getMappedToscaTemplate(); } else { - mappedToscaTemplate = (Map<String, Object>) new Yaml().load(resourceYml); + try { + //DE154502 Fail if duplicate key found in file + mappedToscaTemplate = ImportUtils.loadYamlAsStrictMap(resourceYml); + + } catch(ParserException e) { + log.error("Failed to load yaml file {}", yamlFileName, e); + ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.TOSCA_PARSE_ERROR, yamlFileName, e.getMessage()); + return Either.right(responseFormat); + } } Either<Object, ResultStatusEnum> toscaElementEither = ImportUtils.findToscaElement(mappedToscaTemplate, ToscaTagNamesEnum.TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL); if (toscaElementEither.isRight()) { @@ -5573,10 +5591,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { // IResourceOperation dataModel = getResourceOperation(); Either<Resource, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(resourceId); - if (storageStatus.isRight()) { log.debug("failed to get resource by id {}", resourceId); - return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus.right().value()), "")); + return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus.right().value()), resourceId)); + } + if(!(storageStatus.left().value() instanceof Resource)){ + return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND), resourceId)); } return Either.left(storageStatus.left().value()); @@ -6807,14 +6827,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { try { if (groupTemplateJson != null && groupTemplateJson instanceof Map) { Map<String, Object> groupTemplateJsonMap = (Map<String, Object>) groupTemplateJson; - // Type - String groupType = null; - if (groupTemplateJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) { - groupType = (String) groupTemplateJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName()); + String groupType = (String) groupTemplateJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName()); + if (!StringUtils.isEmpty(groupType)) { groupInfo.setType(groupType); } else { log.debug("The 'type' member is not found under group {}", groupName); - result = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE)); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_MISSING_GROUP_TYPE, groupName)); } if (groupTemplateJsonMap.containsKey(ToscaTagNamesEnum.DESCRIPTION.getElementName())) { @@ -6832,8 +6850,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } groupInfo.setMembers(membersLoaded); } else { - log.debug("The 'type' member is not found under group {}", groupName); - result = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE)); + log.debug("The 'members' member is not of type list under group {}", groupName); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE)); } } } @@ -6873,7 +6891,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either<GroupTypeDefinition, StorageOperationStatus> groupTypeRes = groupTypeOperation.getLatestGroupTypeByType(groupType, true); if (groupTypeRes.isRight()) { - return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_MISSING_GROUP_TYPE, groupType)); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_TYPE_IS_INVALID, groupType)); } Map<String, PropertyDefinition> gtProperties = new HashMap<>(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index ae7ae31ed9..85db9a2c0f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -1144,17 +1144,22 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { if (eitherCreator.isRight()) { return Either.right(eitherCreator.right().value()); } - user = eitherCreator.left().value(); Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId); if (storageStatus.isRight()) { log.debug("failed to get service by id {}", serviceId); return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), serviceId)); } - // Service service = - // createServiceApiArtifactLIst(storageStatus.left().value()); + + if(!(storageStatus.left().value() instanceof Service)){ + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND), serviceId)); + } Service service = storageStatus.left().value(); return Either.left(service); + + + + } public Either<Service, ResponseFormat> getServiceByNameAndVersion(String serviceName, String serviceVersion, String userId) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java b/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java index 34a56cdd13..6be300d6db 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java @@ -74,7 +74,8 @@ public class EsGateway extends ProxyServlet { esPort = monitoringBL.getEsPort(); } - String scheme = request.getScheme(); + //String scheme = request.getScheme(); esGateway HTTP + String scheme = "http"; String contextPath = request.getContextPath(); // /mywebapp String servletPath = request.getServletPath(); // /servlet/MyServlet String pathInfo = request.getPathInfo(); // /a/b;c=123 diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java index d7db4ec3a3..a89d8b109b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java @@ -880,6 +880,120 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet { } + @POST + @Path("/{containerComponentType}/{containerComponentId}/serviceProxy") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Create service proxy", httpMethod = "POST", notes = "Returns created service proxy", response = Response.class) + @ApiResponses(value = { @ApiResponse(code = 201, message = "Service proxy created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"), + @ApiResponse(code = 409, message = "Service proxy already exist") }) + public Response createServiceProxy(@ApiParam(value = "RI object to be created", required = true) String data, @PathParam("containerComponentId") final String containerComponentId, + @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType, + @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId, @Context final HttpServletRequest request) { + ServletContext context = request.getSession().getServletContext(); + + try { + + ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class); + componentInstance.setInvariantName(null); + ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); + if(componentTypeEnum != ComponentTypeEnum.SERVICE){ + log.debug("Unsupported container component type {}", containerComponentType); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); + } + ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum); + if (componentInstanceLogic == null) { + log.debug("Unsupported component type {}", containerComponentType); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); + } + Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.createServiceProxy(containerComponentType, containerComponentId, userId, componentInstance); + + if (actionResponse.isRight()) { + return buildErrorResponse(actionResponse.right().value()); + } + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value()); + + } catch (Exception e) { + BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create service proxy"); + log.debug("Create service proxy failed with exception", e); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); + } + } + + @DELETE + @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Delete service proxy", httpMethod = "DELETE", notes = "Returns delete service proxy", response = Response.class) + @ApiResponses(value = { @ApiResponse(code = 201, message = "Service proxy deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") }) + public Response deleteServiceProxy(@PathParam("containerComponentId") final String containerComponentId, @PathParam("serviceProxyId") final String serviceProxyId, + @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + "," + + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType, + @Context final HttpServletRequest request) { + ServletContext context = request.getSession().getServletContext(); + String url = request.getMethod() + " " + request.getRequestURI(); + Response response = null; + try { + log.debug("Start handle request of {}", url); + ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); + ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum); + if (componentInstanceLogic == null) { + log.debug("Unsupported component type {}", containerComponentType); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); + } + String userId = request.getHeader(Constants.USER_ID_HEADER); + Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.deleteServiceProxy(containerComponentType, containerComponentId, serviceProxyId, userId); + + if (actionResponse.isRight()) { + response = buildErrorResponse(actionResponse.right().value()); + } else { + response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null); + } + return response; + } catch (Exception e) { + BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete service proxy"); + log.debug("Delete service proxy failed with exception", e); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); + } + } + + @POST + @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}/changeVersion/{newServiceId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Update service proxy with new version", httpMethod = "POST", notes = "Returns updated service proxy", response = Response.class) + @ApiResponses(value = { @ApiResponse(code = 201, message = "Service proxy created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") }) + public Response changeServiceProxyVersion(@PathParam("containerComponentId") final String containerComponentId, @PathParam("serviceProxyId") final String serviceProxyId, + @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType, + @Context final HttpServletRequest request) { + ServletContext context = request.getSession().getServletContext(); + + String url = request.getMethod() + " " + request.getRequestURI(); + log.debug("Start handle request of {}", url); + try { + + String userId = request.getHeader(Constants.USER_ID_HEADER); + + ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType); + ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum); + if (componentInstanceLogic == null) { + log.debug("Unsupported component type {}", containerComponentType); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType)); + } + Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.changeServiceProxyVersion(containerComponentType, containerComponentId, serviceProxyId, userId); + + if (actionResponse.isRight()) { + return buildErrorResponse(actionResponse.right().value()); + } + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value()); + + } catch (Exception e) { + BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update service proxy with new version"); + log.debug("Update service proxy with new version failed with exception", e); + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); + } + } + private Either<ComponentInstance, ResponseFormat> convertToResourceInstance(String data) { // Either<ComponentInstance, ActionStatus> convertStatus = diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java index 22943bccea..2e961f294b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.be.servlets; +import java.lang.reflect.Type; import java.util.Map; import javax.inject.Singleton; @@ -39,7 +40,9 @@ import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.PropertyConstraint; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintSerialiser; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.config.EcompErrorName; import org.openecomp.sdc.common.datastructure.Wrapper; @@ -48,6 +51,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.context.WebApplicationContext; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; import com.jcabi.aspects.Loggable; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -95,9 +101,12 @@ public class TypesFetchServlet extends AbstractValidationsServlet { // return buildErrorResponse(allDataTypes.right().value()); } else { + Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value(); - Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypes); + String dataTypeJson = gson.toJson(dataTypes); + Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson); responseWrapper.setInnerElement(okResponse); + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java index 3fd5297439..6c4c5fafe1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java @@ -122,7 +122,7 @@ public class CapabiltyRequirementConvertor { if (prop.getSchema() != null && prop.getSchema().getProperty() != null) { innerType = prop.getSchema().getProperty().getType(); } - Object convertedValue = PropertyConvertor.getInstance().convertToToscaObject(propertyType, prop.getName(), prop.getValue(), innerType, dataTypes); + Object convertedValue = PropertyConvertor.getInstance().convertToToscaObject(propertyType, prop.getValue(), innerType, dataTypes); return convertedValue; } @@ -183,9 +183,19 @@ public class CapabiltyRequirementConvertor { if (requirements != null) { for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) { entry.getValue().stream().forEach(r -> { - String fullReqName = getRequirementPath(r); + String fullReqName; + String sourceCapName; + if(ToscaUtils.isComplexVfc(component)){ + fullReqName = r.getName(); + sourceCapName = getSourceCvfcDataTypeName(r.getName(), r.getOwnerName()); + } else { + fullReqName = getRequirementPath(r); + sourceCapName = getSubPathByFirstDelimiterAppearance(fullReqName); + } log.debug("the requirement {} belongs to resource {} ", fullReqName, component.getUniqueId()); - toscaRequirements.put(fullReqName, new String[]{r.getOwnerName(), getSubPathByFirstDelimiterAppearance(fullReqName)}); + if(sourceCapName!= null){ + toscaRequirements.put(fullReqName, new String[]{r.getOwnerName(), sourceCapName}); + } }); log.debug("Finish convert Requirements for node type"); } @@ -195,6 +205,13 @@ public class CapabiltyRequirementConvertor { return toscaRequirements; } + private String getSourceCvfcDataTypeName(String name, String ownerName) { + if(name.contains(ownerName)){ + return name.substring(0, name.length() - ownerName.length() - 1); + } + return null; + } + private String getRequirementPath(RequirementDefinition r) { List<String> pathArray = Lists.reverse(r.getPath().stream() .map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path))) @@ -254,9 +271,19 @@ public class CapabiltyRequirementConvertor { if (capabilities != null) { for (Map.Entry<String, List<CapabilityDefinition>> entry : capabilities.entrySet()) { entry.getValue().stream().forEach(c -> { - String fullCapName = getCapabilityPath(c); + String fullCapName; + String sourceReqName; + if(ToscaUtils.isComplexVfc(component)){ + fullCapName = c.getName(); + sourceReqName = getSourceCvfcDataTypeName(c.getName(), c.getOwnerName()); + } else { + fullCapName = getCapabilityPath(c); + sourceReqName = getSubPathByFirstDelimiterAppearance(fullCapName); + } log.debug("the capabilty {} belongs to resource {} ", fullCapName, component.getUniqueId()); - toscaCapabilities.put(fullCapName, new String[]{c.getOwnerName(), getSubPathByFirstDelimiterAppearance(fullCapName)}); + if(sourceReqName!= null){ + toscaCapabilities.put(fullCapName, new String[]{c.getOwnerName(), sourceReqName}); + } }); } } else { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java index b8414367aa..646a7ecc8b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java @@ -20,12 +20,11 @@ package org.openecomp.sdc.be.tosca; -import java.io.StringReader; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.stream.JsonReader; +import fj.data.Either; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.model.Component; @@ -33,6 +32,7 @@ import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; +import org.openecomp.sdc.be.model.tosca.converters.DataTypePropertyConverter; import org.openecomp.sdc.be.model.tosca.converters.ToscaMapValueConverter; import org.openecomp.sdc.be.model.tosca.converters.ToscaValueConverter; import org.openecomp.sdc.be.tosca.model.EntrySchema; @@ -41,14 +41,10 @@ import org.openecomp.sdc.be.tosca.model.ToscaProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonSyntaxException; -import com.google.gson.stream.JsonReader; - -import fj.data.Either; +import java.io.StringReader; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class PropertyConvertor { private static PropertyConvertor instance; @@ -101,7 +97,7 @@ public class PropertyConvertor { prop.setEntry_schema(eschema); } log.trace("try to convert property {} from type {} with default value [{}]", property.getName(), property.getType(), property.getDefaultValue()); - prop.setDefaultp(convertToToscaObject(property.getType(), property.getName(), property.getDefaultValue(), innerType, dataTypes)); + prop.setDefaultp(convertToToscaObject(property.getType(), property.getDefaultValue(), innerType, dataTypes)); prop.setType(property.getType()); prop.setDescription(property.getDescription()); if (isCapabiltyProperty) { @@ -111,10 +107,10 @@ public class PropertyConvertor { return prop; } - public Object convertToToscaObject(String propertyType, String propertyName, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) { + public Object convertToToscaObject(String propertyType, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) { log.trace("try to convert propertyType {} , value [{}], innerType {}", propertyType, value, innerType); - if (value == null) { - value = getDataTypeDefaultValue(propertyName, dataTypes.get(propertyType)); + if (StringUtils.isEmpty(value)) { + value = DataTypePropertyConverter.getInstance().getDataTypePropertiesDefaultValuesRec(propertyType, dataTypes); if(StringUtils.isEmpty(value)){ return null; } @@ -193,35 +189,4 @@ public class PropertyConvertor { } - private String getDataTypeDefaultValue(String propertyName, DataTypeDefinition dataTypeDefinition) { - - String delaultValue = null; - JsonObject asJsonObjectIn = new JsonObject(); - Map<String, PropertyDefinition> allParentsProps = new HashMap<>(); - while (dataTypeDefinition != null) { - - List<PropertyDefinition> currentParentsProps = dataTypeDefinition.getProperties(); - if (currentParentsProps != null) { - currentParentsProps.stream().forEach(p -> allParentsProps.put(p.getName(), p)); - } - - dataTypeDefinition = dataTypeDefinition.getDerivedFrom(); - } - for (Entry<String, PropertyDefinition> entry : allParentsProps.entrySet()) { - String propName = entry.getKey(); - PropertyDefinition propertyDefinition = entry.getValue(); - JsonElement elementValue = asJsonObjectIn.get(propName); - if(elementValue == null && propertyDefinition.getDefaultValue() != null){ - JsonReader jsonReader = new JsonReader(new StringReader(propertyDefinition.getDefaultValue())); - jsonReader.setLenient(true); - elementValue = jsonParser.parse(jsonReader); - asJsonObjectIn.add(propName, elementValue); - } - } - if(!asJsonObjectIn.isJsonNull()){ - delaultValue = gson.toJson(asJsonObjectIn); - } - return delaultValue; - } - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index f802d0f412..8e0c312f1a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -634,7 +634,8 @@ public class ToscaExportHandler { List<ComponentInstanceInput> instanceInputsList = componentInstancesInputs.get(instanceUniqueId); if (instanceInputsList != null) { instanceInputsList.forEach(input -> { - Supplier<String> supplier = () -> input.getValue(); + + Supplier<String> supplier = () -> input.getValue() != null && !input.getValue().isEmpty()? input.getValue(): input.getDefaultValue(); convertAndAddValue(dataTypes, componentInstance, props, input, supplier); }); } @@ -695,7 +696,7 @@ public class ToscaExportHandler { if (input.getSchema() != null && input.getSchema().getProperty() != null) { innerType = input.getSchema().getProperty().getType(); } - return propertyConvertor.convertToToscaObject(propertyType, input.getName(), supplier.get(), innerType, dataTypes); + return propertyConvertor.convertToToscaObject(propertyType, supplier.get(), innerType, dataTypes); } private ToscaGroupTemplate convertGroup(GroupDefinition group) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java index dce3b3bbc0..24586d9ea0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java @@ -44,6 +44,16 @@ public class ToscaUtils { } return false; } + + public static boolean isComplexVfc(Component component) { + if (ComponentTypeEnum.RESOURCE == component.getComponentType()) { + ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType(); + if (ResourceTypeEnum.CVFC == resourceType) { + return true; + } + } + return false; + } public static Map<String, Object> objectToMap(Object objectToConvert, Class clazz) throws IllegalArgumentException, IllegalAccessException { Map<String, Object> map = new HashMap<>(); |