summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2021-05-18 20:57:07 +0100
committerChristophe Closset <christophe.closset@intl.att.com>2021-07-05 14:36:03 +0000
commit6047cd212696f5260d1296ce1fc3449dadb6005d (patch)
tree06812f8814816ade1442ca0393a91f09655f4fd1 /catalog-be/src/main
parentb835031b83230c36649c6e77787867a465e0ac47 (diff)
Support for associating node types to models
Issue-ID: SDC-3597 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Signed-off-by: MichaelMorris <michael.morris@est.tech> Change-Id: Icd0066240b78ba98d8f0efab66d11756f18cb251
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml24
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java28
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java46
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/UploadResourceException.java30
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java59
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java9
10 files changed, 164 insertions, 47 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
index b277aeef2f..c87e1e394b 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
@@ -2495,3 +2495,27 @@ errors:
message: "Could not read imports zip.",
messageId: "SVC4147"
}
+
+ #---------SVC4148------------------------------
+ # %1 - "Model name"
+ MODEL_NOT_FOUND: {
+ code: 404,
+ message: "Error: Model name '%1' not found. Please, make sure the model is created.",
+ messageId: "SVC4148"
+ }
+
+ #---------SVC4149------------------------------
+ MODEL_NAME_CANNOT_BE_EMPTY: {
+ code: 409,
+ message: "Error: Model name cannot be empty.",
+ messageId: "SVC4149"
+ }
+
+ #-----------SVC4150---------------------------
+ # %1 - "Component name"
+ # %2 - "Model name"
+ COMPONENT_WITH_MODEL_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Component %1 with Model %2 already exist.",
+ messageId: "SVC4150"
+ }
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 2e54ff7adb..bce343efaf 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
@@ -425,7 +425,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
private Component getOrigComponentForServiceProxy(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance resourceInstance) {
- Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade.getLatestByName(SERVICE_PROXY);
+ Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade.getLatestByName(SERVICE_PROXY, null);
if (isServiceProxyOrigin(serviceProxyOrigin)) {
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value()));
}
@@ -527,7 +527,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
validateInstanceName(resourceInstance);
if (originType == OriginTypeEnum.ServiceProxy) {
log.debug("enter createRealComponentInstance,originType equals ServiceProxy");
- Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade.getLatestByName(SERVICE_PROXY);
+ Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade.getLatestByName(SERVICE_PROXY, null);
if (isServiceProxyOrigin(serviceProxyOrigin)) {
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value()));
}
@@ -2839,7 +2839,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
newComponentInstance.setOriginType(originType);
if (originType == OriginTypeEnum.ServiceProxy) {
Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade
- .getLatestByName(SERVICE_PROXY);
+ .getLatestByName(SERVICE_PROXY, null);
if (isServiceProxyOrigin(serviceProxyOrigin)) {
throw new ByActionStatusComponentException(
componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value()));
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
index a048af4ac8..6eb806d3d1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
@@ -34,6 +34,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+
+/**
+ * This class is responsible for handling the business logic of a Model.
+ */
@Component("modelBusinessLogic")
public class ModelBusinessLogic {
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 99ceb2158e..f5b890e438 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
@@ -19,7 +19,6 @@
*/
package org.openecomp.sdc.be.components.impl;
-import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;
@@ -44,6 +43,7 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
@@ -1314,6 +1314,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
resourceMetaData.setContactId(user.getUserId());
resourceMetaData.setVendorName(resourceVf.getVendorName());
resourceMetaData.setVendorRelease(resourceVf.getVendorRelease());
+ resourceMetaData.setModel(resourceVf.getModel());
// Setting tag
final List<String> tags = new ArrayList<>();
tags.add(resourceMetaData.getName());
@@ -1346,6 +1347,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
cvfc.setCreatorUserId(csarInfo.getModifier().getUserId());
cvfc.setVendorName(resourceVf.getVendorName());
cvfc.setVendorRelease(resourceVf.getVendorRelease());
+ cvfc.setModel(resourceVf.getModel());
cvfc.setResourceVendorModelNumber(resourceVf.getResourceVendorModelNumber());
cvfc.setToscaResourceName(buildNestedToscaResourceName(ResourceTypeEnum.CVFC.name(), csarInfo.getVfResourceName(), nodeName).getLeft());
cvfc.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
@@ -1892,7 +1894,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
throw e;
}
}
-
+
private boolean nodeTypeAlreadyExists(final String toscaResourceName) {
return toscaOperationFacade.getLatestByToscaResourceName(toscaResourceName).isLeft();
}
@@ -3277,10 +3279,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ImmutablePair<Resource, ActionStatus> result = null;
// check if resource already exists (search by tosca name = type)
final boolean isNestedResource = isNestedResourceUpdate(csarInfo, nodeName);
+ final String resourceName = resource.getToscaResourceName();
final Either<Resource, StorageOperationStatus> latestByToscaName = toscaOperationFacade
- .getLatestByToscaResourceName(resource.getToscaResourceName());
- if (latestByToscaName.isLeft()) {
- Resource foundResource = latestByToscaName.left().value();
+ .getLatestByToscaResourceNameAndModel(resourceName, resource.getModel());
+ if (latestByToscaName.isLeft() && Objects.nonNull(latestByToscaName.left().value())) {
+ final Resource foundResource = latestByToscaName.left().value();
// we don't allow updating names of top level types
if (!isNestedResource && !StringUtils.equals(resource.getName(), foundResource.getName())) {
BeEcompErrorManager.getInstance()
@@ -3349,7 +3352,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
public boolean isResourceExist(String resourceName) {
- Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resourceName);
+ Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resourceName, null);
return latestByName.isLeft();
}
@@ -3464,6 +3467,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (newResource.getResourceVendorModelNumber() == null) {
newResource.setResourceVendorModelNumber(oldResource.getResourceVendorModelNumber());
}
+ if (newResource.getModel() == null) {
+ newResource.setModel(oldResource.getModel());
+ }
if (newResource.getContactId() == null) {
newResource.setContactId(oldResource.getContactId());
}
@@ -3749,10 +3755,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Resource createResourceTransaction(Resource resource, User user, boolean isNormative) {
- // validate resource name uniqueness
- log.debug("validate resource name");
- Either<Boolean, StorageOperationStatus> eitherValidation = toscaOperationFacade
- .validateComponentNameExists(resource.getName(), resource.getResourceType(), resource.getComponentType());
+ final String resourceName = resource.getName();
+ final String modelName = resource.getModel();
+ final ResourceTypeEnum resourceType = resource.getResourceType();
+ final ComponentTypeEnum componentType = resource.getComponentType();
+ final Either<Boolean, StorageOperationStatus> eitherValidation = toscaOperationFacade
+ .validateComponentNameAndModelExists(resourceName, modelName, resourceType, componentType);
if (eitherValidation.isRight()) {
loggerSupportability.log(LoggerSupportabilityActions.VALIDATE_NAME, resource.getComponentMetadataForSupportLog(), StatusCode.ERROR,
"ERROR while validate component name {} Status is: {}", resource.getName(), eitherValidation.right().value());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
index b1841e55d8..77d8f897e7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
@@ -171,19 +171,7 @@ public class ResourceImportManager {
setMetaDataFromJson(resourceMetaData, resource);
populateResourceFromYaml(resourceYml, resource);
validationFunction.apply(resource);
- if (!createNewVersion) {
- Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resource.getName());
- if (latestByName.isLeft()) {
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource.getName());
- }
- } else if (!isCsarPresent(csarInfo)) {
- final Either<Resource, StorageOperationStatus> component = toscaOperationFacade
- .getComponentByNameAndVendorRelease(resource.getComponentType(), resource.getName(), resource.getVendorRelease(),
- JsonParseFlagEnum.ParseAll);
- if (component.isLeft()) {
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, resource.getName());
- }
- }
+ checkResourceExistsBeforeCreate(createNewVersion, csarInfo, resource);
resource = resourceBusinessLogic
.createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock, csarInfo, nodeName, isNested).left;
Resource changeStateResponse;
@@ -210,6 +198,35 @@ public class ResourceImportManager {
return responsePair;
}
+ private void checkResourceExistsBeforeCreate(final boolean createNewVersion, final CsarInfo csarInfo, final Resource resource) {
+ final String resourceName = resource.getName();
+ final String model = resource.getModel();
+ final Either<Resource, StorageOperationStatus> latestByToscaName = toscaOperationFacade
+ .getLatestByToscaResourceNameAndModel(resourceName, model);
+ if (latestByToscaName.isLeft()) {
+ final Resource foundResource = latestByToscaName.left().value();
+ validateComponentWithModelExist(resourceName, model, foundResource);
+ if (!createNewVersion) {
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resourceName);
+ }
+ if (!isCsarPresent(csarInfo)) {
+ final Either<Resource, StorageOperationStatus> component = toscaOperationFacade
+ .getComponentByNameAndVendorRelease(resource.getComponentType(), resource.getName(), resource.getVendorRelease(),
+ JsonParseFlagEnum.ParseAll);
+ if (component.isLeft()) {
+ validateComponentWithModelExist(resourceName, model, foundResource);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, resource.getName());
+ }
+ }
+ }
+ }
+
+ private void validateComponentWithModelExist(final String resourceName, final String model, final Resource foundResource) {
+ if (model != null && toscaOperationFacade.isNodeAssociatedToModel(model, foundResource).isPresent()) {
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_MODEL_ALREADY_EXIST, resourceName, model);
+ }
+ }
+
private boolean isCsarPresent(final CsarInfo csarInfo) {
return csarInfo != null && StringUtils.isNotEmpty(csarInfo.getCsarUUID());
}
@@ -246,6 +263,9 @@ public class ResourceImportManager {
if (resourceMetaData.getVendorRelease() != null) {
resource.setVendorRelease(resourceMetaData.getVendorRelease());
}
+ if (resourceMetaData.getModel() != null) {
+ resource.setModel(resourceMetaData.getModel());
+ }
}
}
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 a87fdb6ca7..ccaadbad76 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
@@ -994,7 +994,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private Component getForwardingPathOriginComponent() {
Either<Component, StorageOperationStatus> forwardingPathOrigin = toscaOperationFacade
- .getLatestByName(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME);
+ .getLatestByName(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME, null);
if (forwardingPathOrigin.isRight()) {
StorageOperationStatus errorStatus = forwardingPathOrigin.right().value();
log.debug("Failed to fetch normative forwarding path resource by tosca name, error {}", errorStatus);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/UploadResourceException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/UploadResourceException.java
new file mode 100644
index 0000000000..de7a47c85c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/UploadResourceException.java
@@ -0,0 +1,30 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.components.impl.exceptions;
+
+import lombok.Data;
+import org.openecomp.sdc.be.exception.BusinessException;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@Data
+public class UploadResourceException extends BusinessException {
+
+ private final ResponseFormat responseFormat;
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
index 9cf8f67089..bdc9ffce43 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
@@ -27,11 +27,8 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.servers.Server;
-import io.swagger.v3.oas.annotations.servers.Servers;
import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.tags.Tags;
import java.io.File;
-import java.io.FileNotFoundException;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
@@ -48,19 +45,23 @@ import javax.ws.rs.core.Response;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ModelBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.exception.BusinessException;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.model.UploadResourceInfo;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.zip.exception.ZipException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
/**
@@ -68,8 +69,8 @@ import org.springframework.stereotype.Controller;
*/
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/v1/catalog/upload")
-@Tags({@Tag(name = "SDCE-2 APIs")})
-@Servers({@Server(url = "/sdc2/rest")})
+@Tag(name = "SDCE-2 APIs")
+@Server(url = "/sdc2/rest")
@Controller
public class ResourceUploadServlet extends AbstractValidationsServlet {
@@ -77,12 +78,16 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
public static final String CSAR_TYPE_RESOURCE = "csar";
public static final String USER_TYPE_RESOURCE = "user-resource";
public static final String USER_TYPE_RESOURCE_UI_IMPORT = "user-resource-ui-import";
- private static final Logger log = Logger.getLogger(ResourceUploadServlet.class);
+ private static final Logger log = LoggerFactory.getLogger(ResourceUploadServlet.class);
+
+ private ModelBusinessLogic modelBusinessLogic;
@Inject
public ResourceUploadServlet(UserBusinessLogic userBusinessLogic, ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils, ResourceImportManager resourceImportManager) {
+ ComponentsUtils componentsUtils, ServletUtils servletUtils, ResourceImportManager resourceImportManager,
+ ModelBusinessLogic modelBusinessLogic) {
super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.modelBusinessLogic = modelBusinessLogic;
}
@POST
@@ -103,8 +108,8 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
@Parameter(description = "ContentDisposition") @FormDataParam("resourceZip") FormDataContentDisposition contentDispositionHeader,
@Parameter(description = "resourceMetadata") @FormDataParam("resourceMetadata") String resourceInfoJsonString,
@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- // updateResourse Query Parameter if false checks if already exist
- @DefaultValue("true") @QueryParam("createNewVersion") boolean createNewVersion) throws FileNotFoundException, ZipException {
+ // updateResource Query Parameter if false checks if already exist
+ @DefaultValue("true") @QueryParam("createNewVersion") boolean createNewVersion) {
try {
Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<User> userWrapper = new Wrapper<>();
@@ -112,12 +117,14 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
Wrapper<String> yamlStringWrapper = new Wrapper<>();
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("Start handle request of {}", url);
- // When we get an errorResponse it will be filled into the
-
- // responseWrapper
+ // When we get an errorResponse it will be filled into the responseWrapper
validateAuthorityType(responseWrapper, resourceAuthority);
ResourceAuthorityTypeEnum resourceAuthorityEnum = ResourceAuthorityTypeEnum.findByUrlPath(resourceAuthority);
commonGeneralValidations(responseWrapper, userWrapper, uploadResourceInfoWrapper, resourceAuthorityEnum, userId, resourceInfoJsonString);
+ final String modelNameToBeAssociated = uploadResourceInfoWrapper.getInnerElement().getModel();
+ if (modelNameToBeAssociated != null) {
+ validateModel(modelNameToBeAssociated);
+ }
fillPayload(responseWrapper, uploadResourceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), resourceInfoJsonString,
resourceAuthorityEnum, file);
// PayLoad Validations
@@ -132,10 +139,23 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
yamlStringWrapper.getInnerElement(), resourceAuthorityEnum, createNewVersion, null);
}
return responseWrapper.getInnerElement();
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Upload Resource");
- log.debug("upload resource failed with exception", e);
+ } catch (final BusinessException e) {
throw e;
+ } catch (final Exception e) {
+ var errorMsg = String.format("Unexpected error while uploading Resource '%s'", resourceInfoJsonString);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(errorMsg);
+ log.error(errorMsg, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ /**
+ * The Model field is an optional entry when uploading a resource. If the field is present, it validates if the Model name exists.
+ * @param modelName Model names declared on the resource json representation
+ */
+ private void validateModel(final String modelName) {
+ if (modelBusinessLogic.findModel(modelName).isEmpty()) {
+ throw ModelOperationExceptionSupplier.invalidModel(modelName).get();
}
}
@@ -148,7 +168,8 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
// @formatter:on
private String urlPath;
- private boolean isBackEndImport, isUserTypeResource;
+ private boolean isBackEndImport;
+ private boolean isUserTypeResource;
public static ResourceAuthorityTypeEnum findByUrlPath(String urlPath) {
ResourceAuthorityTypeEnum found = null;
@@ -161,7 +182,7 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
return found;
}
- private ResourceAuthorityTypeEnum(String urlPath, boolean isBackEndImport, boolean isUserTypeResource) {
+ ResourceAuthorityTypeEnum(String urlPath, boolean isBackEndImport, boolean isUserTypeResource) {
this.urlPath = urlPath;
this.isBackEndImport = isBackEndImport;
this.isUserTypeResource = isUserTypeResource;
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 f193510485..52ced65996 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
@@ -472,6 +472,7 @@ public class ToscaExportHandler {
toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR.getPresentation(), resource.getVendorName());
toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR_RELEASE.getPresentation(), resource.getVendorRelease());
toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR_MODEL_NUMBER.getPresentation(), resource.getResourceVendorModelNumber());
+ toscaMetadata.put(JsonPresentationFields.MODEL.getPresentation(), resource.getModel());
break;
case SERVICE:
Service service = (Service) component;
@@ -1122,7 +1123,7 @@ public class ToscaExportHandler {
return res;
}
Either<Resource, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade
- .getLatestByName("serviceProxy");
+ .getLatestByName("serviceProxy", null);
if (serviceProxyOrigin.isRight()) {
log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
serviceProxyOrigin.right().value());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
index 97dab3649e..54d382ff82 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
@@ -44,6 +44,7 @@ public class ToscaMetadata implements IToscaMetadata {
private String sourceModelName;
private String sourceModelUuid;
private String serviceFunction;
+ private String model;
public String getName() {
return name;
@@ -232,4 +233,12 @@ public class ToscaMetadata implements IToscaMetadata {
public void setEnvironmentContext(String environmentContext) {
this.environmentContext = environmentContext;
}
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
}