aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-03-21 20:48:30 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-03-24 06:59:24 +0000
commita6ae7294ecd336d7e88f915710b08e2658eaee00 (patch)
tree5353e6fd9ae41888f0f1cb5eb542ad90c261342e /catalog-be/src/main/java
parent1ccd74fb7723bc41424ca93902d68d351ce55462 (diff)
Enable selection of base type of service
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-3506 Change-Id: Iaba39955fac9056cb0d0f1eccd223c05dfb9c5b4 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java34
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java23
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java23
6 files changed, 92 insertions, 16 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
index 499a6127a1..3b92e62e72 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
@@ -67,6 +67,7 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.BaseType;
import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentParametersView;
@@ -1286,4 +1287,12 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
janusGraphDao.commit();
}
}
+
+ public Either<List<BaseType>, ActionStatus> getBaseTypes(final String categoryName, final String userId) {
+ final ActionStatus status = validateUserExistsActionStatus(userId);
+ if (ActionStatus.OK != status) {
+ return Either.right(status);
+ }
+ return Either.left(elementOperation.getBaseTypes(categoryName));
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java
index a00f44ce39..313d345da1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/generic/GenericTypeBusinessLogic.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -62,13 +63,19 @@ public class GenericTypeBusinessLogic {
log.debug("Failed to fetch certified generic node type for component {}", component.getName());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
- Either<Resource, StorageOperationStatus> findLatestGeneric = toscaOperationFacade
+ Either<Resource, StorageOperationStatus> genericType;
+ if (StringUtils.isEmpty(component.getDerivedFromGenericVersion())){
+ genericType = toscaOperationFacade
.getLatestCertifiedNodeTypeByToscaResourceName(genericTypeToscaName);
- if (findLatestGeneric.isRight()) {
- log.debug("Failed to fetch certified node type by tosca resource name {}", genericTypeToscaName);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType(), genericTypeToscaName));
+ if (genericType.isRight()) {
+ log.debug("Failed to fetch certified node type by tosca resource name {}", genericTypeToscaName);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType(), genericTypeToscaName));
+ }
+ } else {
+ genericType = toscaOperationFacade.getByToscaResourceNameAndVersion(genericTypeToscaName, component.getDerivedFromGenericVersion());
}
- Resource genericTypeResource = findLatestGeneric.left().value();
+
+ Resource genericTypeResource = genericType.left().value();
return Either.left(genericTypeResource);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
index 5bbf84906f..8439ffbefd 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
@@ -445,6 +445,8 @@ public class UiComponentDataConverter {
UiServiceMetadata metadata = new UiServiceMetadata(service.getCategories(),
(ServiceMetadataDataDefinition) service.getComponentMetadataDefinition().getMetadataDataDefinition());
dataTransfer.setMetadata(metadata);
+ dataTransfer.setDerivedFromGenericType(service.getDerivedFromGenericType());
+ dataTransfer.setDerivedFromGenericVersion(service.getDerivedFromGenericVersion());
break;
case NODE_FILTER:
if (service.getNodeFilterComponents() == null) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
index 395c610e34..4efca8a2b8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
@@ -65,6 +65,7 @@ import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.info.ArtifactTypesInfo;
import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.BaseType;
import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
import org.openecomp.sdc.be.model.Category;
import org.openecomp.sdc.be.model.Component;
@@ -189,6 +190,39 @@ public class ElementServlet extends BeGenericServlet {
throw e;
}
}
+
+ @GET
+ @Path("/category/{componentType}/{categoryName}/baseTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get base types for category", method = "GET", summary = "Get base types for category",
+ responses = {@ApiResponse(responseCode = "200", description = "Returns base types Ok"),
+ @ApiResponse(responseCode = "404", description = "No base types were found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getCategoryBaseTypes(@PathParam(value = "categoryName") final String categoryName,
+ @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ final ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ final Either<List<BaseType>, ActionStatus> either = elementBL.getBaseTypes(categoryName, userId);
+
+ if (either.isRight() || either.left().value() == null) {
+ log.debug("No base types were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else {
+ final Map<String, Object> baseTypesMap = new HashMap<>();
+ baseTypesMap.put("baseTypes", either.left().value());
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), baseTypesMap);
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get base types of category");
+ log.debug("getCategoryBaseTypes failed with exception", e);
+ throw e;
+ }
+ }
@DELETE
@Path("/category/{componentType}/{categoryUniqueId}")
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
index 3597c5c23c..b083fbfe2a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -418,7 +418,7 @@ public class CsarUtils {
//US798487 - Abstraction of complex types
if (!ModelConverter.isAtomicComponent(component)) {
log.debug("Component {} is complex - generating abstract type for it..", component.getName());
- writeComponentInterface(component, zip, fileName, false);
+ dependencies.addAll(writeComponentInterface(component, zip, fileName, false));
}
//UID <cassandraId,filename,component>
Either<ZipOutputStream, ResponseFormat> zipOutputStreamOrResponseFormat = getZipOutputStreamResponseFormatEither(zip, dependencies);
@@ -747,18 +747,31 @@ public class CsarUtils {
return componentRI;
}
- private Either<ZipOutputStream, ResponseFormat> writeComponentInterface(Component component, ZipOutputStream zip, String fileName,
+ private List<Triple<String, String, Component>> writeComponentInterface(Component component,
+ ZipOutputStream zip,
+ String fileName,
+ boolean isAssociatedComponent
+ ){
+ final Either<ToscaRepresentation, ToscaError> interfaceRepresentation = toscaExportUtils.exportComponentInterface(component, false);
+ writeComponentInterface(interfaceRepresentation, zip, fileName, false);
+ return interfaceRepresentation.left().value().getDependencies().getOrElse(new ArrayList<>());
+ }
+
+
+ private Either<ZipOutputStream, ResponseFormat> writeComponentInterface(
+ Either<ToscaRepresentation,ToscaError> interfaceRepresentation, ZipOutputStream zip, String fileName,
boolean isAssociatedComponent) {
// TODO: This should not be done but we need this to keep the refactoring small enough to be easily reviewable
- return writeComponentInterface(component, fileName, isAssociatedComponent, ZipWriter.live(zip))
+ return writeComponentInterface(interfaceRepresentation, fileName, isAssociatedComponent, ZipWriter.live(zip))
.map(void0 -> Either.<ZipOutputStream, ResponseFormat>left(zip)).recover(th -> {
log.error("#writeComponentInterface - zip writing failed with error: ", th);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}).get();
}
- private Try<Void> writeComponentInterface(Component component, String fileName, boolean isAssociatedComponent, ZipWriter zw) {
- Either<byte[], ToscaError> yml = toscaExportUtils.exportComponentInterface(component, isAssociatedComponent).left()
+ private Try<Void> writeComponentInterface(
+ Either<ToscaRepresentation,ToscaError> interfaceRepresentation, String fileName, boolean isAssociatedComponent, ZipWriter zw) {
+ Either<byte[], ToscaError> yml = interfaceRepresentation.left()
.map(ToscaRepresentation::getMainYaml);
return fromEither(yml, ToscaErrorException::new).flatMap(zw.write(DEFINITIONS_PATH + ToscaExportHandler.getInterfaceFilename(fileName)));
}
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 988f709bfc..efb3f49d03 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
@@ -199,17 +199,27 @@ public class ToscaExportHandler {
}
public Either<ToscaRepresentation, ToscaError> exportComponentInterface(final Component component, final boolean isAssociatedComponent) {
- final List<Map<String, Map<String, String>>> defaultToscaImportConfig = getDefaultToscaImportConfig();
- if (CollectionUtils.isEmpty(defaultToscaImportConfig)) {
+ final List<Map<String, Map<String, String>>> imports = getDefaultToscaImportConfig();
+ if (CollectionUtils.isEmpty(imports)) {
log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
return Either.right(ToscaError.GENERAL_ERROR);
}
+ List<Triple<String, String, Component>> dependencies = new ArrayList<>();
+ if (component.getDerivedFromGenericType() != null && !component.getDerivedFromGenericType().startsWith("org.openecomp.resource.abstract.nodes.")) {
+ final Either<Component, StorageOperationStatus> baseType = toscaOperationFacade.getByToscaResourceNameAndVersion(component.getDerivedFromGenericType(), component.getDerivedFromGenericVersion());
+ if (baseType.isLeft() && baseType.left().value() != null) {
+ addDependencies(imports, dependencies , baseType.left().value());
+ } else {
+ log.debug("Failed to fetch derived from type {}", component.getDerivedFromGenericType());
+ }
+ }
+
String toscaVersion = null;
if (component instanceof Resource) {
toscaVersion = ((Resource) component).getToscaVersion();
}
ToscaTemplate toscaTemplate = new ToscaTemplate(toscaVersion != null ? toscaVersion : TOSCA_VERSION);
- toscaTemplate.setImports(new ArrayList<>(defaultToscaImportConfig));
+ toscaTemplate.setImports(new ArrayList<>(imports));
final Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
final Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component, toscaTemplate, nodeTypes,
isAssociatedComponent);
@@ -217,6 +227,7 @@ public class ToscaExportHandler {
return Either.right(toscaTemplateRes.right().value());
}
toscaTemplate = toscaTemplateRes.left().value();
+ toscaTemplate.setDependencies(dependencies);
ToscaRepresentation toscaRepresentation = this.createToscaRepresentation(toscaTemplate);
return Either.left(toscaRepresentation);
}
@@ -493,7 +504,7 @@ public class ToscaExportHandler {
if (!ModelConverter.isAtomicComponent(component)) {
final List<Map<String, Map<String, String>>> additionalImports =
toscaTemplate.getImports() == null ? new ArrayList<>(defaultToscaImportConfig) : new ArrayList<>(toscaTemplate.getImports());
- List<Triple<String, String, Component>> dependecies = new ArrayList<>();
+ List<Triple<String, String, Component>> dependencies = new ArrayList<>();
Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
if (isNotEmpty(toscaArtifacts)) {
ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
@@ -510,9 +521,9 @@ public class ToscaExportHandler {
}
List<ComponentInstance> componentInstances = component.getComponentInstances();
if (componentInstances != null && !componentInstances.isEmpty()) {
- componentInstances.forEach(ci -> createDependency(componentCache, additionalImports, dependecies, ci));
+ componentInstances.forEach(ci -> createDependency(componentCache, additionalImports, dependencies, ci));
}
- toscaTemplate.setDependencies(dependecies);
+ toscaTemplate.setDependencies(dependencies);
toscaTemplate.setImports(additionalImports);
} else {
log.debug("currently imports supported for VF and service only");