aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-11-25 12:48:58 +0000
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-11-25 12:51:37 +0000
commit630e46ef816ea2d16d358ed3fab0d9ebed884c19 (patch)
treebe58e61d4fd5d0cae30ea65e3f53c339043b6ba7 /catalog-be/src/main
parent5e71c18416adc5c136ea9053a6bbac819da18c60 (diff)
Fix issues while importing a Service
The import service was ignoring the selected model for imported nodes. It was also trying to set a different icon for resources that already exist in the database, creating a validation error. There was also a nullpointer in relation to not found capability. Change-Id: Ifa9320c5554bbf5e8fed0cc2e2dea6b05503d213 Issue-ID: SDC-4266 Signed-off-by: André Schmid <andre.schmid@est.tech> Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
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.yaml8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java37
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java32
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java6
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml7
8 files changed, 63 insertions, 34 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 4be1cbab66..32bbf73e9d 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
@@ -2847,3 +2847,11 @@ errors:
code: 500
message: "An unexpected error occurred while %1."
messageId: "SVC4013"
+
+
+ # %1 - The capability name
+ # %2 - The model
+ CAPABILITY_NOT_FOUND:
+ code: 404
+ message: "Capability '%1' was not found for model '%2'."
+ messageId: "SVC4014" \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
index aa5706c77f..e4b54c18b5 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
@@ -157,7 +157,8 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
csarUUID, oldResource.getComponentMetadataDefinition().getMetadataDataDefinition().getImportedToscaChecksum(), checksum);
oldResource.getComponentMetadataDefinition().getMetadataDataDefinition().setImportedToscaChecksum(checksum);
}
- return new ServiceCsarInfo(user, csarUUID, csar, service.getName(), toscaYamlCsarStatus.getKey(), toscaYamlCsarStatus.getValue(), true);
+ return new ServiceCsarInfo(user, csarUUID, csar, service.getName(), service.getModel(), toscaYamlCsarStatus.getKey(),
+ toscaYamlCsarStatus.getValue(), true);
}
public ParsedToscaYamlInfo getParsedToscaYamlInfo(String topologyTemplateYaml, String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
index 3e0ea35713..af4d6e48e0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
@@ -62,11 +62,13 @@ public class ServiceCsarInfo extends CsarInfo {
private static final Logger log = Logger.getLogger(ServiceCsarInfo.class);
private final Map<String, Map<String, Object>> mainTemplateImports;
private List<NodeTypeDefinition> nodeTypeDefinitions;
+ private final String model;
- public ServiceCsarInfo(final User modifier, final String csarUUID, final Map<String, byte[]> csar, final String vfResourceName,
+ public ServiceCsarInfo(final User modifier, final String csarUUID, final Map<String, byte[]> csar,
+ final String vfResourceName, final String model,
final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) {
super(modifier, csarUUID, csar, vfResourceName, mainTemplateName, mainTemplateContent, isUpdate);
-
+ this.model = model;
final Path mainTemplateDir = Paths.get(getMainTemplateName().substring(0, getMainTemplateName().lastIndexOf('/') + 1));
final Collection<Path> filesHandled = new HashSet<>();
filesHandled.add(Paths.get(mainTemplateName));
@@ -105,9 +107,12 @@ public class ServiceCsarInfo extends CsarInfo {
if (CollectionUtils.isNotEmpty(importsList)) {
if (importsList.get(0) instanceof String) {
List<Path> importPaths = new ArrayList<>();
- importsList.stream()
- .forEach(importPath -> importPaths.add(fileParentDir == null ? Paths.get((String) importPath)
- : fileParentDir.resolve(Paths.get((String) importPath)).normalize()));
+ importsList.forEach(
+ importPath -> {
+ final Path path = fileParentDir == null ?
+ Paths.get((String) importPath) : fileParentDir.resolve(Paths.get((String) importPath)).normalize();
+ importPaths.add(path);
+ });
return importPaths;
} else if (importsList.get(0) instanceof Map) {
return getTemplateImportFilePathsMultiLineGrammar(importsList, fileParentDir);
@@ -162,14 +167,14 @@ public class ServiceCsarInfo extends CsarInfo {
private Map<String, Object> getTypes(ToscaTagNamesEnum toscaTag) {
final Map<String, Object> types = new HashMap<>();
- mainTemplateImports.entrySet().stream().forEach(entry -> types.putAll(getTypesFromTemplate(entry.getValue(), toscaTag)));
+ mainTemplateImports.entrySet().forEach(entry -> types.putAll(getTypesFromTemplate(entry.getValue(), toscaTag)));
types.putAll(getTypesFromTemplate(getMappedToscaMainTemplate(), toscaTag));
return types;
}
public Map<String, Object> getArtifactTypes() {
final Map<String, Object> artifactsTypes = new HashMap<>();
- mainTemplateImports.entrySet().stream()
+ mainTemplateImports.entrySet()
.forEach(entry -> artifactsTypes.putAll(getTypesFromTemplate(entry.getValue(), TypeUtils.ToscaTagNamesEnum.ARTIFACT_TYPES)));
artifactsTypes.putAll(getTypesFromTemplate(getMappedToscaMainTemplate(), TypeUtils.ToscaTagNamesEnum.ARTIFACT_TYPES));
return artifactsTypes;
@@ -199,7 +204,7 @@ public class ServiceCsarInfo extends CsarInfo {
for (final String dependencyName : getDependencyTypes(nodeType, nodeTypes)) {
final NodeTypeDefinition dependency = nodeTypeDefinitionsMap.get(dependencyName);
final int indexOfDependency = sortedNodeTypeDefinitions.lastIndexOf(dependency);
- highestDependencyIndex = indexOfDependency > highestDependencyIndex ? indexOfDependency : highestDependencyIndex;
+ highestDependencyIndex = Math.max(indexOfDependency, highestDependencyIndex);
}
sortedNodeTypeDefinitions.add(highestDependencyIndex + 1, nodeType);
nodeTypeDefinitionsMap.put(nodeType.getMappedNodeType().getKey(), nodeType);
@@ -221,11 +226,10 @@ public class ServiceCsarInfo extends CsarInfo {
}
private Set<NodeTypeDefinition> getNodeTypeDefinitions(final Set<String> nodeTypesToGet) {
- final Set<NodeTypeDefinition> nodeTypesToReturn = new HashSet<>();
final Set<NodeTypeDefinition> foundNodeTypes = getTypes(nodeTypesToGet);
- nodeTypesToReturn.addAll(foundNodeTypes);
+ final Set<NodeTypeDefinition> nodeTypesToReturn = new HashSet<>(foundNodeTypes);
final Set<String> recursiveNodeTypesToGet = new HashSet<>();
- foundNodeTypes.stream().forEach(nodeTypeDef -> {
+ foundNodeTypes.forEach(nodeTypeDef -> {
Either<Object, ResultStatusEnum> derivedFromTypeEither =
findToscaElement((Map<String, Object>) nodeTypeDef.getMappedNodeType().getValue(), TypeUtils.ToscaTagNamesEnum.DERIVED_FROM,
ToscaElementTypeEnum.STRING);
@@ -243,12 +247,12 @@ public class ServiceCsarInfo extends CsarInfo {
private Set<NodeTypeDefinition> getTypes(final Set<String> nodeTypes) {
Set<NodeTypeDefinition> nodeTypeDefinitionsLocal = new HashSet<>();
- mainTemplateImports.entrySet().forEach(entry -> {
- final Map<String, Object> types = getTypesFromTemplate(entry.getValue(), TypeUtils.ToscaTagNamesEnum.NODE_TYPES, nodeTypes);
+ mainTemplateImports.values().forEach(template -> {
+ final Map<String, Object> types = getTypesFromTemplate(template, ToscaTagNamesEnum.NODE_TYPES, nodeTypes);
if (MapUtils.isNotEmpty(types)) {
- types.entrySet().stream().forEach(typesEntry -> {
+ types.entrySet().forEach(typesEntry -> {
final NodeTypeMetadata metadata =
- getMetaDataFromTemplate(entry.getValue(), typesEntry.getKey());
+ getMetaDataFromTemplate(template, typesEntry.getKey());
nodeTypeDefinitionsLocal.add(new NodeTypeDefinition(typesEntry, metadata));
});
}
@@ -306,13 +310,14 @@ public class ServiceCsarInfo extends CsarInfo {
nodeTypeMetadata.setResourceType((String) metadata.get("type"));
nodeTypeMetadata.setVendorName((String) metadata.get("resourceVendor"));
nodeTypeMetadata.setVendorRelease(String.valueOf(metadata.get("resourceVendorRelease")));
- nodeTypeMetadata.setModel((String) metadata.get("model"));
+ nodeTypeMetadata.setModel(model);
nodeTypeMetadata.setNormative(false);
}
private NullNodeTypeMetadata createDefaultMetadata(String nodeTemplateType) {
NullNodeTypeMetadata nodeTypeMetadata = new NullNodeTypeMetadata();
nodeTypeMetadata.setToscaName(nodeTemplateType);
+ nodeTypeMetadata.setModel(model);
return nodeTypeMetadata;
}
}
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 992216db7e..cb57ab3b12 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
@@ -3710,6 +3710,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (newResource.getContactId() == null) {
newResource.setContactId(oldResource.getContactId());
}
+ newResource.setIcon(oldResource.getIcon());
newResource.setCategories(oldResource.getCategories());
if (newResource.getVendorName() == null) {
newResource.setVendorName(oldResource.getVendorName());
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 82add987f2..7bdaaee9a6 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
@@ -296,10 +296,9 @@ public class ServiceImportBusinessLogic {
final Map<String, Object> dataTypesToCreate = getDatatypesToCreate(service.getModel(), csarInfo);
if (MapUtils.isNotEmpty(dataTypesToCreate)) {
dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), service.getModel(), true);
- dataTypesToCreate.entrySet().stream().forEach(createdOrUpdatedDataType -> {
- applicationDataTypeCache.reload(service.getModel(),
- UniqueIdBuilder.buildDataTypeUid(service.getModel(), createdOrUpdatedDataType.getKey()));
- });
+ dataTypesToCreate.keySet().forEach(key ->
+ applicationDataTypeCache.reload(service.getModel(), UniqueIdBuilder.buildDataTypeUid(service.getModel(), key))
+ );
}
final Map<String, Object> artifactTypesToCreate = getArtifactTypesToCreate(service.getModel(), csarInfo);
@@ -465,7 +464,7 @@ public class ServiceImportBusinessLogic {
NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList();
List<NodeTypeMetadata> nodeTypeMetadataList = new ArrayList<>();
final Map<String, Object> allTypesToCreate = new HashMap<>();
- nodeTypesToCreate.stream().forEach(nodeType -> {
+ nodeTypesToCreate.forEach(nodeType -> {
allTypesToCreate.put(nodeType.getMappedNodeType().getKey(), nodeType.getMappedNodeType().getValue());
nodeTypeMetadataList.add(nodeType.getNodeTypeMetadata());
});
@@ -2675,7 +2674,8 @@ public class ServiceImportBusinessLogic {
if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
uploadComponentInstanceInfo.setType(nodeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName());
}
- Resource refResource = validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, existingnodeTypeMap);
+ Resource refResource =
+ validateResourceInstanceBeforeCreate(yamlName, component.getModel(), uploadComponentInstanceInfo, existingnodeTypeMap);
ComponentInstance componentInstance = new ComponentInstance();
componentInstance.setComponentUid(refResource.getUniqueId());
Collection<String> directives = uploadComponentInstanceInfo.getDirectives();
@@ -2707,26 +2707,28 @@ public class ServiceImportBusinessLogic {
componentInstance.setName(uploadComponentInstanceInfo.getName());
componentInstance.setIcon(origResource.getIcon());
resourcesInstancesMap.put(componentInstance, origResource);
- } catch (Exception e) {
+ } catch (final ComponentException e) {
+ throw e;
+ } catch (final Exception e) {
throw new ComponentException(ActionStatus.GENERAL_ERROR, e.getMessage());
}
}
- protected Resource validateResourceInstanceBeforeCreate(String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo,
+ protected Resource validateResourceInstanceBeforeCreate(String yamlName, String model, UploadComponentInstanceInfo uploadComponentInstanceInfo,
Map<String, Resource> nodeNamespaceMap) {
Resource refResource;
try {
if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
refResource = nodeNamespaceMap.get(uploadComponentInstanceInfo.getType());
} else {
- Either<Resource, StorageOperationStatus> findResourceEither = toscaOperationFacade
- .getLatestResourceByToscaResourceName(uploadComponentInstanceInfo.getType());
- if (findResourceEither.isRight()) {
+ final Either<Component, StorageOperationStatus> resourceEither =
+ toscaOperationFacade.getLatestByToscaResourceName(uploadComponentInstanceInfo.getType(), model);
+ if (resourceEither.isRight()) {
ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(findResourceEither.right().value()));
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(resourceEither.right().value()));
throw new ComponentException(responseFormat);
}
- refResource = findResourceEither.left().value();
+ refResource = (Resource) resourceEither.left().value();
nodeNamespaceMap.put(refResource.getToscaResourceName(), refResource);
}
String componentState = refResource.getComponentMetadataDefinition().getMetadataDataDefinition().getState();
@@ -2744,7 +2746,9 @@ public class ServiceImportBusinessLogic {
throw new ComponentException(responseFormat);
}
return refResource;
- } catch (Exception e) {
+ } catch (final ComponentException e) {
+ throw e;
+ } catch (final Exception e) {
throw new ComponentException(ActionStatus.GENERAL_ERROR, e.getMessage());
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
index dfe065a79e..36975f81d8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
@@ -800,6 +800,9 @@ public class ComponentsUtils {
case SCHEMA_VIOLATION:
responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
break;
+ case NOT_FOUND:
+ responseEnum = ActionStatus.CAPABILITY_NOT_FOUND;
+ break;
default:
responseEnum = ActionStatus.GENERAL_ERROR;
break;
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 d314f6a01d..fcac7dce35 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
@@ -661,7 +661,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
log.debug(START_HANDLE_REQUEST_OF, url);
log.debug(MODIFIER_ID_IS, userId);
try {
- final Wrapper<Response> responseWrapper = performUIImport(data, request, userId, null);
+ final Wrapper<Response> responseWrapper = performUIImport(data, request, userId);
return responseWrapper.getInnerElement();
} catch (IOException | ZipException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Import Service");
@@ -670,8 +670,8 @@ public class ServiceServlet extends AbstractValidationsServlet {
}
}
- private Wrapper<Response> performUIImport(String data, final HttpServletRequest request, String userId,
- String serviceUniqueId) throws FileNotFoundException, ZipException {
+ private Wrapper<Response> performUIImport(String data, final HttpServletRequest request,
+ String userId) throws FileNotFoundException, ZipException {
Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<User> userWrapper = new Wrapper<>();
Wrapper<UploadServiceInfo> uploadServiceInfoWrapper = new Wrapper<>();
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
index ee5f7fa836..6bed75ef2e 100644
--- a/catalog-be/src/main/resources/config/error-configuration.yaml
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -2848,3 +2848,10 @@ errors:
message: "An unexpected error occurred while %1."
messageId: "SVC4013"
+
+ # %1 - The capability name
+ # %2 - The model
+ CAPABILITY_NOT_FOUND:
+ code: 404
+ message: "Capability '%1' was not found for model '%2'."
+ messageId: "SVC4014" \ No newline at end of file