summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2020-01-29 17:25:21 +0000
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-04-19 16:35:32 +0000
commitcd6f933375c412c2f79a12e909821322d58a8499 (patch)
tree758ff2e742b514169bbc84a8433d68fe221ef5c9 /catalog-be/src/main/java/org
parentdc56692a4a307f378c827f017d2efbf754c223e0 (diff)
Configure a new Artifact Type
Centralizes artifact configuration in one yaml entry. Allow the configuration of a new artifact type without the need of code changes. The configuration file now is used as a source of artifacts types instead the artifact type enum. The enum will be used as a source of base artifact types and also in hard coded business rules. Change-Id: Id0383d9fca9bce0519a4d52a4ecb3a68c8713f0f Issue-ID: SDC-2754 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java89
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IArtifactInfo.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java683
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java29
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java55
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java62
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java227
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java22
12 files changed, 502 insertions, 694 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
index 0192516bf0..dadd12f673 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
@@ -736,7 +736,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
artifactUid = newArtifact.getUniqueId();
artifactUUID = newArtifact.getArtifactUUID();
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(newArtifact.getArtifactType());
+ final ArtifactTypeEnum artifactType = ArtifactTypeEnum.parse(newArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET
|| artifactType == ArtifactTypeEnum.HEAT_VOL) {
ArtifactDefinition createHeatEnvPlaceHolder = artifactsBusinessLogic
@@ -771,7 +771,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private String checkAndGetHeatEnvId(ArtifactDefinition createdArtifact) {
String artifactEnvUid = "";
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(createdArtifact.getArtifactType());
+ final ArtifactTypeEnum artifactType = ArtifactTypeEnum.parse(createdArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET
|| artifactType == ArtifactTypeEnum.HEAT_VOL) {
artifactEnvUid = createdArtifact.getUniqueId() + ArtifactsBusinessLogic.HEAT_ENV_SUFFIX;
@@ -1245,7 +1245,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
if (!artifactsToDelete.isEmpty()) {
for (ArtifactDefinition artifact : artifactsToDelete) {
String artifactType = artifact.getArtifactType();
- ArtifactTypeEnum artifactTypeEnum = ArtifactTypeEnum.findType(artifactType);
+ final ArtifactTypeEnum artifactTypeEnum = ArtifactTypeEnum.parse(artifactType);
if (artifactTypeEnum != ArtifactTypeEnum.HEAT_ENV) {
Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic
.handleDelete(resourceId, artifact.getUniqueId(), user, AuditingActionEnum.ARTIFACT_DELETE,
@@ -1460,7 +1460,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
ArtifactDefinition newArtifact = newArtifactEither.left().value();
artifactUid = newArtifact.getUniqueId();
artifactUUID = newArtifact.getArtifactUUID();
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(newArtifact.getArtifactType());
+ final ArtifactTypeEnum artifactType = ArtifactTypeEnum.parse(newArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET
|| artifactType == ArtifactTypeEnum.HEAT_VOL) {
ArtifactDefinition createHeatEnvPlaceHolder = artifactsBusinessLogic
@@ -1619,7 +1619,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
ArtifactDefinition createdArtifact = createArtifactEither.left().value();
arifactsUids.add(createdArtifact.getUniqueId());
arifactsUuids.add(createdArtifact.getArtifactUUID());
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(createdArtifact.getArtifactType());
+ final ArtifactTypeEnum artifactType = ArtifactTypeEnum.parse(createdArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET
|| artifactType == ArtifactTypeEnum.HEAT_VOL) {
ArtifactDefinition createHeatEnvPlaceHolder = artifactsBusinessLogic
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java
index f8f6726db8..98a8550b7a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java
@@ -20,11 +20,12 @@
package org.openecomp.sdc.be.components.distribution.engine;
+import lombok.Getter;
+import lombok.Setter;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import java.util.ArrayList;
import java.util.Collection;
@@ -32,10 +33,12 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+@Getter
+@Setter
public class ArtifactInfoImpl implements IArtifactInfo {
private String artifactName;
- private ArtifactTypeEnum artifactType;
+ private String artifactType;
private String artifactURL;
private String artifactChecksum;
private String artifactDescription;
@@ -50,7 +53,7 @@ public class ArtifactInfoImpl implements IArtifactInfo {
private ArtifactInfoImpl(ArtifactDefinition artifactDef, String generatedFromUUID, List<String> relatedArtifacts) {
artifactName = artifactDef.getArtifactName();
- artifactType = ArtifactTypeEnum.findType(artifactDef.getArtifactType());
+ artifactType = artifactDef.getArtifactType();
artifactChecksum = artifactDef.getArtifactChecksum();
artifactDescription = artifactDef.getDescription();
artifactTimeout = artifactDef.getTimeout();
@@ -108,90 +111,10 @@ public class ArtifactInfoImpl implements IArtifactInfo {
return requiredArtifacts;
}
- public String getArtifactName() {
- return artifactName;
- }
-
- public void setArtifactName(String artifactName) {
- this.artifactName = artifactName;
- }
-
- public ArtifactTypeEnum getArtifactType() {
- return artifactType;
- }
-
- public void setArtifactType(ArtifactTypeEnum artifactType) {
- this.artifactType = artifactType;
- }
-
- public String getArtifactURL() {
- return artifactURL;
- }
-
- public void setArtifactURL(String artifactURL) {
- this.artifactURL = artifactURL;
- }
-
- public String getArtifactChecksum() {
- return artifactChecksum;
- }
-
- public void setArtifactChecksum(String artifactChecksum) {
- this.artifactChecksum = artifactChecksum;
- }
-
- public String getArtifactDescription() {
- return artifactDescription;
- }
-
- public void setArtifactDescription(String artifactDescription) {
- this.artifactDescription = artifactDescription;
- }
-
- public Integer getArtifactTimeout() {
- return artifactTimeout;
- }
-
- public void setArtifactTimeout(Integer artifactTimeout) {
- this.artifactTimeout = artifactTimeout;
- }
-
- public List<String> getRelatedArtifacts() {
- return relatedArtifacts;
- }
-
- public void setRelatedArtifacts(List<String> relatedArtifacts) {
- this.relatedArtifacts = relatedArtifacts;
- }
-
@Override
public String toString() {
return "ArtifactInfoImpl [artifactName=" + artifactName + ", artifactType=" + artifactType + ", artifactURL=" + artifactURL + ", artifactChecksum=" + artifactChecksum + ", artifactDescription=" + artifactDescription + ", artifactTimeout="
+ artifactTimeout + ", artifactUUID=" + artifactUUID + ", artifactVersion=" + artifactVersion + ", generatedFromUUID=" + generatedFromUUID + ", relatedArtifacts=" + relatedArtifacts + "]";
}
- public String getArtifactUUID() {
- return artifactUUID;
- }
-
- public void setArtifactUUID(String artifactUUID) {
- this.artifactUUID = artifactUUID;
- }
-
- public String getArtifactVersion() {
- return artifactVersion;
- }
-
- public void setArtifactVersion(String artifactVersion) {
- this.artifactVersion = artifactVersion;
- }
-
- public String getGeneratedFromUUID() {
- return generatedFromUUID;
- }
-
- public void setGeneratedFromUUID(String generatedFromUUID) {
- this.generatedFromUUID = generatedFromUUID;
- }
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IArtifactInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IArtifactInfo.java
index 4a917710a9..b4919dfbfe 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IArtifactInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IArtifactInfo.java
@@ -20,8 +20,6 @@
package org.openecomp.sdc.be.components.distribution.engine;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-
public interface IArtifactInfo {
/** Artifact File name */
@@ -32,7 +30,7 @@ public interface IArtifactInfo {
* Following are valid values : HEAT , DG_XML. <br>
* List of values will be extended in post-1510 releases.
*/
- ArtifactTypeEnum getArtifactType();
+ String getArtifactType();
/**
* Relative artifact's URL. Should be used in REST GET API to download the artifact's payload.<br>
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 103edd6497..b41d076e2a 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
@@ -22,13 +22,38 @@
package org.openecomp.sdc.be.components.impl;
+import static org.openecomp.sdc.be.dao.api.ActionStatus.MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import fj.data.Either;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+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;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -43,7 +68,9 @@ import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils;
+import org.openecomp.sdc.be.config.ArtifactConfiguration;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.Configuration.ArtifactTypeConfig;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -61,7 +88,6 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.info.ArtifactTemplateInfo;
import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.ArtifactType;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentParametersView;
@@ -121,31 +147,6 @@ import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.yaml.snakeyaml.Yaml;
-import javax.servlet.http.HttpServletRequest;
-import javax.xml.XMLConstants;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-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;
-import java.util.function.Predicate;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
-
-import static org.openecomp.sdc.be.dao.api.ActionStatus.MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE;
-
@org.springframework.stereotype.Component("artifactBusinessLogic")
public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private static final String RESOURCE_INSTANCE = "resource instance";
@@ -167,19 +168,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private static final Logger log = Logger.getLogger(ArtifactsBusinessLogic.class.getName());
private static final String FAILED_UPDATE_GROUPS = "Failed to update groups of the component {}. ";
- private static final String FAILED_UPDATE_ARTIFACT = "Failed to delete or update the artifact {}. Parent uniqueId is {}";
private static final String FAILED_SAVE_ARTIFACT = "Failed to save the artifact.";
public static final String ARTIFACT_ACTION_LOCK = "Artifact action - lock ";
- private static final String UPDATE_ARTIFACT_LOCK = "Update Artifact - lock ";
- private static final String FAILED_DOWNLOAD_ARTIFACT = "Download artifact {} failed";
public static final String FAILED_UPLOAD_ARTIFACT_TO_COMPONENT = "Failed to upload artifact to component with type {} and uuid {}. Status is {}. ";
- private static final String FAILED_UPLOAD_ARTIFACT_TO_INSTANCE = "Failed to upload artifact to component instance {} of component with type {} and uuid {}. Status is {}. ";
private static final String FAILED_FETCH_COMPONENT = "Could not fetch component with type {} and uuid {}. Status is {}. ";
private static final String NULL_PARAMETER = "One of the function parameteres is null";
public static final String COMPONENT_INSTANCE_NOT_FOUND = "Component instance {} was not found for component {}";
private static final String ROLLBACK = "all changes rollback";
private static final String COMMIT = "all changes committed";
- private static final String ARTIFACT_SAVED = "Artifact saved into ES - {}";
private static final String UPDATE_ARTIFACT = "Update Artifact";
private static final String FOUND_DEPLOYMENT_ARTIFACT = "Found deployment artifact {}";
private Gson gson = new GsonBuilder().setPrettyPrinting().create();
@@ -479,9 +475,13 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String operationName, AuditingActionEnum auditingAction, User user, Component parent,
boolean needUpdateGroup) {
Either<ArtifactDefinition, Operation> result;
- ArtifactTypeEnum artifactType = validateAndReturnArtifactType(artifactInfo);
- if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE
- && (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_VOL || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_ENV)) {
+ validateArtifactType(artifactInfo);
+ final String artifactType = artifactInfo.getArtifactType();
+ if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE &&
+ (ArtifactTypeEnum.HEAT.getType().equals(artifactType) ||
+ ArtifactTypeEnum.HEAT_VOL.getType().equals(artifactType) ||
+ ArtifactTypeEnum.HEAT_NET.getType().equals(artifactType) ||
+ ArtifactTypeEnum.HEAT_ENV.getType().equals(artifactType))) {
result = handleUpdateHeatEnvAndHeatMeta(componentId, artifactInfo, auditingAction, artifactId, user, componentType, parent, originData, origMd5, operation);
if (needUpdateGroup) {
ActionStatus error = updateGroupInstance(artifactInfo, result.left().value(), parent, componentId);
@@ -490,7 +490,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
}
- else if (componentType == ComponentTypeEnum.RESOURCE && artifactType == ArtifactTypeEnum.HEAT_ENV) {
+ else if (componentType == ComponentTypeEnum.RESOURCE && ArtifactTypeEnum.HEAT_ENV.getType().equals(artifactType)) {
result = handleUpdateHeatWithHeatEnvParams(componentId, artifactInfo, auditingAction, componentType, parent, originData, origMd5, operation, needUpdateGroup);
}
else {
@@ -507,16 +507,70 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return result;
}
- private ArtifactTypeEnum validateAndReturnArtifactType(ArtifactDefinition artifactInfo) {
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
- if (artifactType == null) {
+ private void validateArtifactType(final ArtifactDefinition artifactInfo) {
+ if (!isArtifactSupported(artifactInfo.getArtifactType())) {
throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
}
- return artifactType;
}
- public ActionStatus updateGroupForHeatEnv(ArtifactDefinition artifactInfo, ArtifactDefinition artAfterUpdate, Component parent) {
- return ActionStatus.OK;
+ private void validateArtifactType(final ArtifactDefinition artifactInfo,
+ final ComponentTypeEnum componentType) {
+ final ArtifactConfiguration artifactConfiguration =
+ loadArtifactTypeConfig(artifactInfo.getArtifactType()).orElse(null);
+ if (artifactConfiguration == null) {
+ BeEcompErrorManager.getInstance()
+ .logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
+ log.debug("Missing artifact type for artifact {}", artifactInfo.getArtifactName());
+ final ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_TYPE);
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
+
+ final ArtifactGroupTypeEnum artifactGroupType = artifactInfo.getArtifactGroupType();
+ try {
+ validateArtifactType(componentType, artifactGroupType, artifactConfiguration);
+ } catch (final ComponentException e) {
+ log.debug("Artifact is invalid", e);
+ BeEcompErrorManager.getInstance()
+ .logBeInvalidTypeError("Artifact Upload / Delete / Update - Not supported artifact type", artifactInfo
+ .getArtifactType(), "Artifact " + artifactInfo.getArtifactName());
+ log.debug("Not supported artifact type = {}", artifactInfo.getArtifactType());
+ final ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo
+ .getArtifactType());
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
+ }
+
+ private void validateArtifactType(final ComponentTypeEnum componentType, final ArtifactGroupTypeEnum groupType,
+ final ArtifactConfiguration artifactConfiguration) {
+ final boolean supportComponentType =
+ CollectionUtils.isNotEmpty(artifactConfiguration.getComponentTypes()) &&
+ artifactConfiguration.getComponentTypes().stream()
+ .anyMatch(componentType1 -> componentType1.getValue().equalsIgnoreCase(componentType.getValue()));
+ if (!supportComponentType) {
+ log.debug("Artifact Type '{}' not supported for Component Type '{}'",
+ artifactConfiguration.getType(), componentType.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED,
+ artifactConfiguration.getType());
+ }
+
+ final boolean supportResourceType = artifactConfiguration.hasSupport(groupType);
+ if (!supportResourceType) {
+ log.debug("Artifact Type '{}' not supported for Component Type '{}' and Category '{}'",
+ artifactConfiguration.getType(), componentType.getValue(), groupType.getType());
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED,
+ artifactConfiguration.getType());
+ }
+ }
+
+ private boolean isArtifactSupported(final String artifactType) {
+ final Configuration configuration = ConfigurationManager.getConfigurationManager().getConfiguration();
+ final List<ArtifactConfiguration> artifactConfigurationList = configuration.getArtifacts();
+ if (CollectionUtils.isEmpty(artifactConfigurationList)) {
+ return false;
+ }
+ return artifactConfigurationList.stream()
+ .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equalsIgnoreCase(artifactType));
}
@VisibleForTesting
@@ -706,7 +760,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
// step 1
// detect auditing type
Map<String, ArtifactDefinition> resMap = null;
-// Either<Map<String, ArtifactDefinition>, ResponseFormat> resultOp = null;
new Wrapper<>();
// step 2
@@ -745,7 +798,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
if (groupType == ArtifactGroupTypeEnum.DEPLOYMENT) {
- List<ArtifactDefinition> list = getDeploymentArtifacts(component, componentType.getNodeType(), componentId);
+ List<ArtifactDefinition> list = getDeploymentArtifacts(component, componentId);
if (list != null && !list.isEmpty()) {
resMap = list.stream().collect(Collectors.toMap(ArtifactDataDefinition::getArtifactLabel, Function.identity()));
}
@@ -1011,14 +1064,31 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
- private Either<ArtifactDefinition, ResponseFormat> validateInput(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, String artifactId, User user, String interfaceName, String operationName,
- ComponentTypeEnum componentType, Component parentComponent) {
+ private Either<ArtifactDefinition, ResponseFormat> validateInput(final String componentId,
+ final ArtifactDefinition artifactInfo,
+ final ArtifactOperationInfo operation,
+ final String artifactId, final User user,
+ String interfaceName,
+ String operationName,
+ final ComponentTypeEnum componentType,
+ final Component parentComponent) {
+
+ final ArtifactDefinition existingArtifactInfo =
+ findArtifact(parentComponent, componentType, componentId, operation, artifactId);
+ final Component component;
+ if (parentComponent.getUniqueId().equals(componentId)) {
+ component = parentComponent;
+ } else {
+ final ComponentInstance componentInstance = findComponentInstance(componentId, parentComponent);
+ component = findComponent(componentInstance.getComponentUid());
+ component.setComponentType(componentType);
+ }
- ArtifactDefinition currentArtifactInfo = findArtifactOnParentComponent(parentComponent, componentType, componentId, operation, artifactId);
- ignoreUnupdateableFieldsInUpdate(operation, artifactInfo, currentArtifactInfo);
- validateInformationalArtifact(artifactInfo, parentComponent);
- Either<Boolean, ResponseFormat> validateAndSetArtifactname = validateAndSetArtifactName(
- artifactInfo);
+ ignoreUnupdateableFieldsInUpdate(operation, artifactInfo, existingArtifactInfo);
+ if (isInformationalArtifact(artifactInfo)) {
+ validateInformationalArtifact(artifactInfo, component);
+ }
+ Either<Boolean, ResponseFormat> validateAndSetArtifactname = validateAndSetArtifactName(artifactInfo);
if (validateAndSetArtifactname.isRight()) {
return Either.right(validateAndSetArtifactname.right().value());
}
@@ -1036,37 +1106,43 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
// This is a patch to block possibility of updating service api fields
// through other artifacts flow
- ArtifactGroupTypeEnum artifactGroupType = operationName != null ? ArtifactGroupTypeEnum.LIFE_CYCLE : ArtifactGroupTypeEnum.INFORMATIONAL;
- if (!ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum())) {
- checkAndSetUnUpdatableFields(user, artifactInfo, currentArtifactInfo, artifactGroupType);
- }
- else {
+ final ArtifactGroupTypeEnum artifactGroupType =
+ operationName != null ? ArtifactGroupTypeEnum.LIFE_CYCLE : ArtifactGroupTypeEnum.INFORMATIONAL;
+ final boolean isCreateOrLink = ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum());
+ if (!isCreateOrLink) {
+ checkAndSetUnUpdatableFields(user, artifactInfo, existingArtifactInfo, artifactGroupType);
+ } else {
checkCreateFields(user, artifactInfo, artifactGroupType);
}
composeArtifactId(componentId, artifactId, artifactInfo, interfaceName, operationName);
- if (currentArtifactInfo != null) {
- artifactInfo.setMandatory(currentArtifactInfo.getMandatory());
+ if (existingArtifactInfo != null) {
+ artifactInfo.setMandatory(existingArtifactInfo.getMandatory());
+ if (!isCreateOrLink) {
+ validateArtifactTypeNotChanged(artifactInfo, existingArtifactInfo);
+ }
}
// artifactGroupType is not allowed to be updated
- if (!ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum())) {
- Either<ArtifactDefinition, ResponseFormat> validateGroupType = validateOrSetArtifactGroupType(artifactInfo, currentArtifactInfo);
+ if (!isCreateOrLink) {
+ Either<ArtifactDefinition, ResponseFormat> validateGroupType = validateOrSetArtifactGroupType(artifactInfo, existingArtifactInfo);
if (validateGroupType.isRight()) {
return Either.right(validateGroupType.right().value());
}
}
- // TODO TEMP !!!
- NodeTypeEnum parentType = convertParentType(componentType);
- // TODO TEMP !!!
- boolean isCreate = ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum());
-
- if (isDeploymentArtifact(artifactInfo)) {
- validateDeploymentArtifact(parentComponent, componentId, isCreate, artifactInfo, currentArtifactInfo, parentType);
+ setArtifactTimeout(artifactInfo, existingArtifactInfo);
+ if (isHeatArtifact(artifactInfo)) {
+ validateHeatArtifact(parentComponent, componentId, artifactInfo);
}
- else {
- artifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
+ if (isDeploymentArtifact(artifactInfo)) {
+ if (componentType != ComponentTypeEnum.RESOURCE_INSTANCE) {
+ final String artifactName = artifactInfo.getArtifactName();
+ if (isCreateOrLink || !artifactName.equalsIgnoreCase(existingArtifactInfo.getArtifactName())) {
+ validateSingleDeploymentArtifactName(artifactName, parentComponent);
+ }
+ }
+ validateDeploymentArtifact(artifactInfo, component);
}
Either<Boolean, ResponseFormat> descriptionResult = validateAndCleanDescription(artifactInfo);
@@ -1074,11 +1150,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.right(descriptionResult.right().value());
}
- if (currentArtifactInfo != null && currentArtifactInfo.getArtifactGroupType() == ArtifactGroupTypeEnum.SERVICE_API) {
- Either<ActionStatus, ResponseFormat> validateServiceApiType = validateArtifactType(user.getUserId(), artifactInfo, parentType);
- if (validateServiceApiType.isRight()) {
- return Either.right(validateServiceApiType.right().value());
- }
+ validateArtifactType(artifactInfo, component.getComponentType());
+ artifactInfo.setArtifactType(artifactInfo.getArtifactType().toUpperCase());
+ if (existingArtifactInfo != null && existingArtifactInfo.getArtifactGroupType() == ArtifactGroupTypeEnum.SERVICE_API) {
// Change of type is not allowed and should be ignored
artifactInfo.setArtifactType(ARTIFACT_TYPE_OTHER);
@@ -1088,23 +1162,18 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.right(validateUrl.right().value());
}
- Either<Boolean, ResponseFormat> validateUpdate = validateFirstUpdateHasPayload(artifactInfo, currentArtifactInfo);
+ Either<Boolean, ResponseFormat> validateUpdate = validateFirstUpdateHasPayload(artifactInfo, existingArtifactInfo);
if (validateUpdate.isRight()) {
log.debug("serviceApi first update cnnot be without payload.");
return Either.right(validateUpdate.right().value());
}
- }
- else {
- Either<ActionStatus, ResponseFormat> validateArtifactType = validateArtifactType(user.getUserId(), artifactInfo, parentType);
- if (validateArtifactType.isRight()) {
- return Either.right(validateArtifactType.right().value());
- }
+ } else {
if (artifactInfo.getApiUrl() != null) {
artifactInfo.setApiUrl(null);
log.error("Artifact URL cannot be set through this API - ignoring");
}
- if (artifactInfo.getServiceApi() != null && artifactInfo.getServiceApi()) {
+ if (Boolean.TRUE.equals(artifactInfo.getServiceApi())) {
artifactInfo.setServiceApi(false);
log.error("Artifact service API flag cannot be changed - ignoring");
}
@@ -1113,6 +1182,16 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(artifactInfo);
}
+ private Component findComponent(final String componentId) {
+ Either<? extends Component, StorageOperationStatus> component = toscaOperationFacade.getToscaFullElement(componentId);
+ if (component.isRight()) {
+ log.debug("Component '{}' not found ", componentId);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NOT_FOUND, componentId);
+ }
+
+ return component.left().value();
+ }
+
private void ignoreUnupdateableFieldsInUpdate(ArtifactOperationInfo operation, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifactInfo) {
if (operation.getArtifactOperationEnum() == ArtifactOperationEnum.UPDATE) {
artifactInfo.setArtifactType(currentArtifactInfo.getArtifactType());
@@ -1121,8 +1200,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
- private ArtifactDefinition findArtifactOnParentComponent(Component parentComponent, ComponentTypeEnum componentType, String parentId, ArtifactOperationInfo operation, String artifactId) {
-
+ private ArtifactDefinition findArtifact(final Component parentComponent, final ComponentTypeEnum componentType,
+ final String parentId, final ArtifactOperationInfo operation,
+ final String artifactId) {
ArtifactDefinition foundArtifact = null;
if (StringUtils.isNotEmpty(artifactId)) {
foundArtifact = findArtifact(parentComponent, componentType, parentId, artifactId);
@@ -1132,7 +1212,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_EXIST, foundArtifact.getArtifactLabel());
}
if (foundArtifact == null && !ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum())) {
- log.debug("The artifact {} was not found on parent {}. ", artifactId, parentId);
+ log.debug("The artifact {} was not found on parent component or instance {}. ", artifactId, parentId);
throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, "");
}
return foundArtifact;
@@ -1150,31 +1230,26 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return foundArtifact;
}
- private void validateInformationalArtifact(ArtifactDefinition artifactInfo, Component parentComponent) {
- ComponentTypeEnum parentComponentType = parentComponent.getComponentType();
- ArtifactGroupTypeEnum groupType = artifactInfo.getArtifactGroupType();
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
- if (artifactType == null) {
- throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
+ private void validateInformationalArtifact(final ArtifactDefinition artifactInfo, final Component component) {
+ final ArtifactGroupTypeEnum groupType = artifactInfo.getArtifactGroupType();
+ if (groupType != ArtifactGroupTypeEnum.INFORMATIONAL) {
+ return;
}
- else if (parentComponentType == ComponentTypeEnum.RESOURCE && groupType == ArtifactGroupTypeEnum.INFORMATIONAL) {
- String artifactTypeName = artifactType.getType();
- ResourceTypeEnum parentResourceType = ((Resource) parentComponent).getResourceType();
- Map<String, ArtifactTypeConfig> resourceInformationalArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceInformationalArtifacts();
- Set<String> validArtifactTypes = resourceInformationalArtifacts.keySet();
- if (!validArtifactTypes.contains(artifactTypeName)) {
- throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactTypeName);
- }
- else {
- List<String> validResourceType = resourceInformationalArtifacts.get(artifactTypeName)
- .getValidForResourceTypes();
- if (!validResourceType.contains(parentResourceType.name())) {
- throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactTypeName);
- }
- }
+ final ComponentTypeEnum parentComponentType = component.getComponentType();
+ final String artifactType = artifactInfo.getArtifactType();
+ final ArtifactConfiguration artifactConfiguration = loadArtifactTypeConfig(artifactType).orElse(null);
+ if (artifactConfiguration == null) {
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactType);
}
+ validateArtifactType(parentComponentType, artifactInfo.getArtifactGroupType(), artifactConfiguration);
+
+ if (component.getComponentType() == ComponentTypeEnum.RESOURCE ||
+ component.getComponentType() == ComponentTypeEnum.RESOURCE_INSTANCE) {
+
+ final ResourceTypeEnum resourceType = ((Resource) component).getResourceType();
+ validateResourceType(resourceType, artifactInfo, artifactConfiguration.getResourceTypes());
+ }
+ validateArtifactExtension(artifactConfiguration, artifactInfo);
}
private NodeTypeEnum convertParentType(ComponentTypeEnum componentType) {
@@ -1750,117 +1825,102 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return foundInstance;
}
- private void validateDeploymentArtifact(Component parentComponent, String parentId, boolean isCreate, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact, NodeTypeEnum parentType) {
-
- ArtifactTypeEnum artifactType = getValidArtifactType(artifactInfo);
- Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts = fillDeploymentArtifactTypeConf(parentType);
- validateDeploymentArtifactTypeIsLegalForParent(artifactInfo, artifactType, resourceDeploymentArtifacts);
- if (!isCreate) {
- validateArtifactTypeNotChanged(artifactInfo, currentArtifact);
+ private void validateDeploymentArtifact(final ArtifactDefinition artifactInfo, final Component component) {
+ final ComponentTypeEnum componentType = component.getComponentType();
+ if (componentType != ComponentTypeEnum.RESOURCE &&
+ componentType != ComponentTypeEnum.SERVICE &&
+ componentType != ComponentTypeEnum.RESOURCE_INSTANCE) {
+ log.debug("Invalid component type '{}' for artifact. "
+ + "Expected Resource, Component or Resource Instance", componentType.getValue());
+ throw new ByActionStatusComponentException(MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE,
+ componentType.getValue(), "Service, Resource or ResourceInstance", componentType.getValue());
}
- if (parentType == NodeTypeEnum.Resource) {
- Resource resource = (Resource) parentComponent;
- ResourceTypeEnum resourceType = resource.getResourceType();
- ArtifactTypeConfig config = resourceDeploymentArtifacts.get(artifactType.getType());
- if (config == null) {
- throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
- }
- List<String> myList = config.getValidForResourceTypes();
- validateResourceType(resourceType, artifactInfo, myList);
+ final String artifactType = artifactInfo.getArtifactType();
+ final ArtifactConfiguration artifactConfiguration = loadArtifactTypeConfig(artifactType).orElse(null);
+ if (artifactConfiguration == null) {
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactType);
}
+ validateArtifactType(componentType, artifactInfo.getArtifactGroupType(), artifactConfiguration);
+ if (componentType == ComponentTypeEnum.RESOURCE || componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
+ final Resource resource = (Resource) component;
+ final ResourceTypeEnum resourceType = resource.getResourceType();
- validateFileExtension(() -> getDeploymentArtifactTypeConfig(parentType, artifactType), artifactInfo, parentType, artifactType);
+ validateResourceType(resourceType, artifactInfo, artifactConfiguration.getResourceTypes());
+ }
- if (NodeTypeEnum.ResourceInstance != parentType) {
- String artifactName = artifactInfo.getArtifactName();
- if (isCreate || !artifactName.equalsIgnoreCase(currentArtifact.getArtifactName())) {
- validateSingleDeploymentArtifactName(artifactName, parentComponent, parentType);
- }
+ validateArtifactExtension(artifactConfiguration, artifactInfo);
+ }
+
+ private void validateHeatArtifact(final Component parentComponent, final String componentId,
+ final ArtifactDefinition artifactDefinition) {
+ final String artifactType = artifactDefinition.getArtifactType();
+ final ArtifactTypeEnum artifactTypeEnum = ArtifactTypeEnum.parse(artifactType);
+ if (artifactTypeEnum == null) {
+ return;
}
- switch (artifactType) {
+ switch (artifactTypeEnum) {
case HEAT:
case HEAT_VOL:
case HEAT_NET:
- validateHeatTimeoutValue(isCreate, artifactInfo, currentArtifact);
+ validateHeatTimeoutValue(artifactDefinition);
break;
case HEAT_ENV:
- validateHeatEnvDeploymentArtifact(parentComponent, parentId, artifactInfo, parentType);
- artifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
+ validateHeatEnvDeploymentArtifact(parentComponent, componentId, artifactDefinition);
break;
- case DCAE_INVENTORY_TOSCA:
- case DCAE_INVENTORY_JSON:
- case DCAE_INVENTORY_POLICY:
- // Validation is done in handle payload.
- case DCAE_INVENTORY_DOC:
- case DCAE_INVENTORY_BLUEPRINT:
- case DCAE_INVENTORY_EVENT:
- // No specific validation
default:
- artifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
break;
}
}
- @VisibleForTesting
- void validateDeploymentArtifactTypeIsLegalForParent(ArtifactDefinition artifactInfo, ArtifactTypeEnum artifactType, Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts) {
- if ((resourceDeploymentArtifacts == null) || !resourceDeploymentArtifacts.containsKey(artifactType.name())) {
- log.debug("Artifact Type: {} Not found !", artifactInfo.getArtifactType());
- throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
- }
- }
+ private void setArtifactTimeout(final ArtifactDefinition newArtifactInfo,
+ final ArtifactDefinition existingArtifactInfo) {
- private Map<String, ArtifactTypeConfig> fillDeploymentArtifactTypeConf(NodeTypeEnum parentType) {
- Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts;
- if (parentType == NodeTypeEnum.Resource) {
- resourceDeploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceDeploymentArtifacts();
- }
- else if (parentType == NodeTypeEnum.ResourceInstance) {
- resourceDeploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceInstanceDeploymentArtifacts();
+ final String artifactType = newArtifactInfo.getArtifactType();
+ final ArtifactTypeEnum artifactTypeEnum = ArtifactTypeEnum.parse(artifactType);
+ if (artifactTypeEnum == null) {
+ newArtifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
+ return;
}
- else {
- resourceDeploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getServiceDeploymentArtifacts();
+ switch (artifactTypeEnum) {
+ case HEAT:
+ case HEAT_VOL:
+ case HEAT_NET:
+ if (newArtifactInfo.getTimeout() == null) {
+ if (existingArtifactInfo == null) {
+ newArtifactInfo.setTimeout(NodeTemplateOperation.getDefaultHeatTimeout());
+ } else {
+ newArtifactInfo.setTimeout(existingArtifactInfo.getTimeout());
+ }
+ }
+ break;
+ default:
+ newArtifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
+ break;
}
- return resourceDeploymentArtifacts;
}
- public ArtifactTypeEnum getValidArtifactType(ArtifactDefinition artifactInfo) {
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
- if (artifactType == null) {
+ @VisibleForTesting
+ void validateDeploymentArtifactTypeIsLegalForParent(ArtifactDefinition artifactInfo, ArtifactTypeEnum artifactType, Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts) {
+ if ((resourceDeploymentArtifacts == null) || !resourceDeploymentArtifacts.containsKey(artifactType.name())) {
log.debug("Artifact Type: {} Not found !", artifactInfo.getArtifactType());
throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
}
- return artifactType;
}
- private ArtifactTypeConfig getDeploymentArtifactTypeConfig(NodeTypeEnum parentType, ArtifactTypeEnum artifactType) {
- ArtifactTypeConfig retConfig = null;
- String fileType = artifactType.getType();
- if (parentType == NodeTypeEnum.Resource) {
- retConfig = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceDeploymentArtifacts()
- .get(fileType);
- }
- else if (parentType == NodeTypeEnum.Service) {
- retConfig = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getServiceDeploymentArtifacts()
- .get(fileType);
+ Optional<ArtifactConfiguration> loadArtifactTypeConfig(final String artifactType) {
+ if (artifactType == null) {
+ return Optional.empty();
}
- else if (parentType == NodeTypeEnum.ResourceInstance) {
- retConfig = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceInstanceDeploymentArtifacts()
- .get(fileType);
+ final List<ArtifactConfiguration> artifactConfigurationList =
+ ConfigurationManager.getConfigurationManager().getConfiguration().getArtifacts();
+ if (CollectionUtils.isEmpty(artifactConfigurationList)) {
+ return Optional.empty();
}
- return retConfig;
+
+ return artifactConfigurationList.stream()
+ .filter(artifactConfiguration -> artifactConfiguration.getType().equalsIgnoreCase(artifactType))
+ .findFirst();
}
private Either<Boolean, ResponseFormat> extractHeatParameters(ArtifactDefinition artifactInfo) {
@@ -1884,42 +1944,33 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
@VisibleForTesting
- public void validateFileExtension(IDeploymentArtifactTypeConfigGetter deploymentConfigGetter, ArtifactDefinition artifactInfo, NodeTypeEnum parentType, ArtifactTypeEnum artifactType) {
- if (parentType != NodeTypeEnum.Resource && parentType != NodeTypeEnum.Service && parentType != NodeTypeEnum.ResourceInstance) {
- log.debug("parent type of artifact can be either resource or service");
- throw new ByActionStatusComponentException(MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE, artifactType.name(), "Service, Resource or ResourceInstance", parentType.getName());
- }
-
- String fileType = artifactType.getType();
- ArtifactTypeConfig deploymentAcceptedTypes = deploymentConfigGetter.getDeploymentArtifactConfig();
- if (deploymentAcceptedTypes == null) {
- log.debug("invalid artifact type {}", fileType);
- throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, fileType);
- }
+ void validateArtifactExtension(final ArtifactConfiguration artifactConfiguration,
+ final ArtifactDefinition artifactDefinition) {
+ final List<String> acceptedTypes = artifactConfiguration.getAcceptedTypes();
/*
* No need to check specific types. In case there are no acceptedTypes in configuration, then any type is accepted.
*/
+ if (CollectionUtils.isEmpty(acceptedTypes)) {
+ return;
+ }
+ final String artifactName = artifactDefinition.getArtifactName();
+ final String fileExtension = FilenameUtils.getExtension(artifactName);
- List<String> acceptedTypes = deploymentAcceptedTypes.getAcceptedTypes();
- String artifactName = artifactInfo.getArtifactName();
- String fileExtension = GeneralUtility.getFilenameExtension(artifactName);
- // Pavel - File extension validation is case-insensitive - Ella,
- // 21/02/2016
- if (CollectionUtils.isNotEmpty(acceptedTypes) && !acceptedTypes.contains(fileExtension.toLowerCase())) {
- log.debug("File extension \"{}\" is not allowed for {} which is of type:{}", fileExtension, artifactName, fileType);
- throw new ByActionStatusComponentException(ActionStatus.WRONG_ARTIFACT_FILE_EXTENSION, fileType);
+ if (fileExtension == null || !acceptedTypes.contains(fileExtension.toLowerCase())) {
+ final String artifactType = artifactDefinition.getArtifactType();
+ log.debug("File extension \"{}\" is not allowed for artifact type \"{}\"", fileExtension, artifactType);
+ throw new ByActionStatusComponentException(ActionStatus.WRONG_ARTIFACT_FILE_EXTENSION, artifactType);
}
}
@VisibleForTesting
- void validateHeatEnvDeploymentArtifact(Component parentComponent, String parentId, ArtifactDefinition artifactInfo, NodeTypeEnum parentType) {
-
- Wrapper<ArtifactDefinition> heatMDWrapper = new Wrapper<>();
- Wrapper<byte[]> payloadWrapper = new Wrapper<>();
+ void validateHeatEnvDeploymentArtifact(final Component parentComponent, final String parentId,
+ final ArtifactDefinition artifactInfo) {
+ final Wrapper<ArtifactDefinition> heatMDWrapper = new Wrapper<>();
+ final Wrapper<byte[]> payloadWrapper = new Wrapper<>();
validateYaml(artifactInfo);
- validateHeatExist(parentComponent.getUniqueId(), parentId, heatMDWrapper, artifactInfo,
- parentType, parentComponent.getComponentType());
+ validateHeatExist(parentComponent.getUniqueId(), parentId, heatMDWrapper, artifactInfo, parentComponent.getComponentType());
if (!heatMDWrapper.isEmpty()) {
fillArtifactPayload(payloadWrapper, heatMDWrapper.getInnerElement());
@@ -2005,42 +2056,38 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
- private void validateSingleDeploymentArtifactName(String artifactName, Component parentComponent, NodeTypeEnum parentType) {
+ private void validateSingleDeploymentArtifactName(final String artifactName, final Component parentComponent) {
boolean artifactNameFound = false;
- Iterator<ArtifactDefinition> parentDeploymentArtifactsItr = getDeploymentArtifacts(parentComponent, parentType, null)
- .iterator();
+ final Iterator<ArtifactDefinition> parentDeploymentArtifactsItr =
+ getDeploymentArtifacts(parentComponent, null).iterator();
while (!artifactNameFound && parentDeploymentArtifactsItr.hasNext()) {
artifactNameFound = artifactName.equalsIgnoreCase(parentDeploymentArtifactsItr.next().getArtifactName());
}
if (artifactNameFound) {
+ final ComponentTypeEnum componentType = parentComponent.getComponentType();
log.debug("Can't upload artifact: {}, because another artifact with this name already exist.", artifactName);
- throw new ByActionStatusComponentException(ActionStatus.DEPLOYMENT_ARTIFACT_NAME_ALREADY_EXISTS, parentType.name(),
- parentComponent.getName(), artifactName);
+ throw new ByActionStatusComponentException(ActionStatus.DEPLOYMENT_ARTIFACT_NAME_ALREADY_EXISTS,
+ componentType.getValue(), parentComponent.getName(), artifactName);
}
}
- private void validateHeatExist(String componentId, String parentRiId, Wrapper<ArtifactDefinition> heatArtifactMDWrapper, ArtifactDefinition heatEnvArtifact, NodeTypeEnum parentType,
+ private void validateHeatExist(String componentId, String parentRiId, Wrapper<ArtifactDefinition> heatArtifactMDWrapper, ArtifactDefinition heatEnvArtifact,
ComponentTypeEnum componentType) {
- Either<ArtifactDefinition, StorageOperationStatus> res = artifactToscaOperation.getHeatArtifactByHeatEnvId(parentRiId, heatEnvArtifact, parentType, componentId, componentType);
+ final Either<ArtifactDefinition, StorageOperationStatus> res = artifactToscaOperation
+ .getHeatArtifactByHeatEnvId(parentRiId, heatEnvArtifact, componentId, componentType);
if (res.isRight()) {
throw new ByActionStatusComponentException(ActionStatus.MISSING_HEAT);
- } else {
- heatArtifactMDWrapper.setInnerElement(res.left().value());
}
+
+ heatArtifactMDWrapper.setInnerElement(res.left().value());
}
@VisibleForTesting
- void validateHeatTimeoutValue(boolean isCreate, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
+ void validateHeatTimeoutValue(final ArtifactDefinition artifactInfo) {
log.trace("Started HEAT pre-payload validation for artifact {}", artifactInfo.getArtifactLabel());
// timeout > 0 for HEAT artifacts
- Integer timeout = artifactInfo.getTimeout();
- if (timeout == null) {
- Integer defaultTimeout = isCreate ? NodeTemplateOperation.getDefaultHeatTimeout() : currentArtifact.getTimeout();
- artifactInfo.setTimeout(defaultTimeout);
- // HEAT artifact but timeout is invalid
- }
- else if (timeout < 1) {
+ if (artifactInfo.getTimeout() == null || artifactInfo.getTimeout() < 1) {
throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_INVALID_TIMEOUT);
}
// US649856 - Allow several HEAT files on Resource
@@ -2048,12 +2095,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
@VisibleForTesting
- void validateResourceType(ResourceTypeEnum resourceType, ArtifactDefinition artifactInfo, List<String> typeList) {
- if (typeList == null || !typeList.contains(resourceType.name())) {
- String listToString = (typeList != null) ? typeList.toString() : "";
- throw new ByActionStatusComponentException(MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE, artifactInfo.getArtifactName(),
- listToString, resourceType.getValue());
+ void validateResourceType(final ResourceTypeEnum resourceType, final ArtifactDefinition artifactInfo,
+ final List<String> typeList) {
+ if (CollectionUtils.isEmpty(typeList) || typeList.contains(resourceType.getValue())) {
+ return;
}
+ final String listToString = typeList.stream().collect(Collectors.joining(", "));
+ throw new ByActionStatusComponentException(MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE,
+ artifactInfo.getArtifactGroupType().getType(), listToString, resourceType.getValue());
}
@VisibleForTesting
@@ -2082,22 +2131,24 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(artifactInfo);
}
- public List<ArtifactDefinition> getDeploymentArtifacts(Component parentComponent, NodeTypeEnum parentType, String ciId) {
- List<ArtifactDefinition> deploymentArtifacts = new ArrayList<>();
- if (parentComponent.getDeploymentArtifacts() != null) {
- if (NodeTypeEnum.ResourceInstance == parentType && ciId != null) {
- Either<ComponentInstance, ResponseFormat> getRI = getRIFromComponent(parentComponent, ciId, null, null, null);
- if (getRI.isRight()) {
- return deploymentArtifacts;
- }
- ComponentInstance ri = getRI.left().value();
- if (ri.getDeploymentArtifacts() != null) {
- deploymentArtifacts.addAll(ri.getDeploymentArtifacts().values());
- }
+ public List<ArtifactDefinition> getDeploymentArtifacts(final Component component, final String ciId) {
+ final ComponentTypeEnum componentType = component.getComponentType();
+ if (component.getDeploymentArtifacts() == null) {
+ return Collections.emptyList();
+ }
+ final List<ArtifactDefinition> deploymentArtifacts = new ArrayList<>();
+ if (ComponentTypeEnum.RESOURCE == componentType && ciId != null) {
+ final Either<ComponentInstance, ResponseFormat> getRI =
+ getRIFromComponent(component, ciId, null, null, null);
+ if (getRI.isRight()) {
+ return Collections.emptyList();
}
- else if (parentComponent.getDeploymentArtifacts() != null) {
- deploymentArtifacts.addAll(parentComponent.getDeploymentArtifacts().values());
+ final ComponentInstance ri = getRI.left().value();
+ if (ri.getDeploymentArtifacts() != null) {
+ deploymentArtifacts.addAll(ri.getDeploymentArtifacts().values());
}
+ } else {
+ deploymentArtifacts.addAll(component.getDeploymentArtifacts().values());
}
return deploymentArtifacts;
}
@@ -2184,90 +2235,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return id;
}
- private Either<ActionStatus, ResponseFormat> validateArtifactType(String userId, ArtifactDefinition artifactInfo, NodeTypeEnum parentType) {
- if (artifactInfo.getArtifactType() == null || artifactInfo.getArtifactType().isEmpty()) {
- BeEcompErrorManager.getInstance()
- .logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
- log.debug("Missing artifact type for artifact {}", artifactInfo.getArtifactName());
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_TYPE));
- }
-
- boolean artifactTypeExist = false;
- Either<List<ArtifactType>, ActionStatus> allArtifactTypes = null;
- ArtifactGroupTypeEnum artifactGroupType = artifactInfo.getArtifactGroupType();
-
- if ((artifactGroupType != null) && artifactGroupType == ArtifactGroupTypeEnum.DEPLOYMENT) {
- allArtifactTypes = getDeploymentArtifactTypes(parentType);
- }
- else {
-
- allArtifactTypes = elementOperation.getAllArtifactTypes();
- }
- if (allArtifactTypes.isRight()) {
- BeEcompErrorManager.getInstance()
- .logBeInvalidConfigurationError("Artifact Upload / Update", "artifactTypes", allArtifactTypes
- .right()
- .value()
- .name());
- log.debug("Failed to retrieve list of suported artifact types. error: {}", allArtifactTypes.right()
- .value());
- return Either.right(componentsUtils.getResponseFormatByUserId(allArtifactTypes.right().value(), userId));
- }
-
- for (ArtifactType type : allArtifactTypes.left().value()) {
- if (type.getName().equalsIgnoreCase(artifactInfo.getArtifactType())) {
- artifactInfo.setArtifactType(artifactInfo.getArtifactType().toUpperCase());
- artifactTypeExist = true;
- break;
- }
- }
-
- if (!artifactTypeExist) {
- BeEcompErrorManager.getInstance()
- .logBeInvalidTypeError("Artifact Upload / Delete / Update - Not supported artifact type", artifactInfo
- .getArtifactType(), "Artifact " + artifactInfo.getArtifactName());
- log.debug("Not supported artifact type = {}", artifactInfo.getArtifactType());
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo
- .getArtifactType()));
- }
-
- return Either.left(ActionStatus.OK);
- }
-
- private Either<List<ArtifactType>, ActionStatus> getDeploymentArtifactTypes(NodeTypeEnum parentType) {
-
- Map<String, ArtifactTypeConfig> deploymentArtifacts ;
- List<ArtifactType> artifactTypes = new ArrayList<>();
-
- if (parentType == NodeTypeEnum.Service) {
- deploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getServiceDeploymentArtifacts();
- }
- else if (parentType == NodeTypeEnum.ResourceInstance) {
- deploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceInstanceDeploymentArtifacts();
- }
- else {
- deploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceDeploymentArtifacts();
- }
- if (deploymentArtifacts != null) {
- for (String artifactType : deploymentArtifacts.keySet()) {
- ArtifactType artifactT = new ArtifactType();
- artifactT.setName(artifactType);
- artifactTypes.add(artifactT);
- }
- return Either.left(artifactTypes);
- }
- else {
- return Either.right(ActionStatus.GENERAL_ERROR);
- }
-
- }
-
private Either<Boolean, ResponseFormat> validateFirstUpdateHasPayload(ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
if (currentArtifact.getEsId() == null && (artifactInfo.getPayloadData() == null || artifactInfo.getPayloadData().length == 0)) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_PAYLOAD));
@@ -2922,18 +2889,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return resourceListBySystemName.left().value();
}
- /*private Either<Resource, ResponseFormat> validateResourceNameAndVersion(String resourceName, String resourceVersion) {
-
- Either<Resource, StorageOperationStatus> resourceListBySystemName = toscaOperationFacade.getComponentByNameAndVersion(ComponentTypeEnum.RESOURCE, resourceName, resourceVersion, JsonParseFlagEnum.ParseMetadata);
- if (resourceListBySystemName.isRight()) {
- log.debug("Couldn't fetch any resource with name {} and version {}. ", resourceName, resourceVersion);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceListBySystemName
- .right()
- .value()), resourceName));
- }
- return Either.left(resourceListBySystemName.left().value());
- }*/
-
public byte[] downloadServiceArtifactByNames(String serviceName, String serviceVersion, String artifactName) {
// Validation
log.trace("Starting download of service interface artifact, serviceName {}, serviceVersion {}, artifact name {}", serviceName, serviceVersion, artifactName);
@@ -3242,6 +3197,29 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return ArtifactGroupTypeEnum.DEPLOYMENT == artifactInfo.getArtifactGroupType();
}
+ private boolean isInformationalArtifact(final ArtifactDefinition artifactInfo) {
+ return ArtifactGroupTypeEnum.INFORMATIONAL == artifactInfo.getArtifactGroupType();
+ }
+
+ private boolean isHeatArtifact(final ArtifactDefinition artifactInfo) {
+ final String artifactType = artifactInfo.getArtifactType();
+ final ArtifactTypeEnum artifactTypeEnum = ArtifactTypeEnum.parse(artifactType);
+ if (artifactTypeEnum == null) {
+ artifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
+ return false;
+ }
+ switch (artifactTypeEnum) {
+ case HEAT:
+ case HEAT_VOL:
+ case HEAT_NET:
+ case HEAT_ENV:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+
public ArtifactDefinition createArtifactPlaceHolderInfo(String resourceId, String logicalName, Map<String, Object> artifactInfoMap, String userUserId, ArtifactGroupTypeEnum groupType, boolean inTransaction) {
User user = userBusinessLogic.getUser(userUserId, inTransaction);
return createArtifactPlaceHolderInfo(resourceId, logicalName, artifactInfoMap, user, groupType);
@@ -3670,7 +3648,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (origMd5 != null) {
validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
if (ArrayUtils.isNotEmpty(artifactInfo.getPayloadData())) {
- validateDeploymentArtifact(parent, componentId, false, artifactInfo, artifactInfo, NodeTypeEnum.ResourceInstance);
+ validateDeploymentArtifact(artifactInfo, parent);
handlePayload(artifactInfo, isArtifactMetadataUpdate(auditingAction));
} else { // duplicate
throw new ByActionStatusComponentException(ActionStatus.MISSING_DATA, ARTIFACT_PAYLOAD);
@@ -4305,7 +4283,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
if (getComponentRes.isRight()) {
StorageOperationStatus status = getComponentRes.right().value();
- log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
+ log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
}
@@ -4346,7 +4324,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (errorWrapper.isEmpty()) {
NodeTypeEnum parentType = convertParentType(componentType);
- List<ArtifactDefinition> existingDeploymentArtifacts = getDeploymentArtifacts(toscaComponentEither.left().value(), parentType,null);
+ final List<ArtifactDefinition> existingDeploymentArtifacts =
+ getDeploymentArtifacts(toscaComponentEither.left().value(),null);
for (ArtifactDefinition artifactDefinition: existingDeploymentArtifacts){
if(artifactInfo.getArtifactName().equalsIgnoreCase(artifactDefinition.getArtifactName())){
existingArtifactInfo = artifactDefinition;
@@ -4909,5 +4888,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
this.nodeTemplateOperation = nodeTemplateOperation;
}
+ public List<ArtifactConfiguration> getConfiguration() {
+ return ConfigurationManager.getConfigurationManager().getConfiguration().getArtifacts();
+ }
+
}
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 711e6648ed..9c092da300 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
@@ -948,16 +948,12 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return elementOperation.getAllPropertyScopes();
}
- public Either<List<ArtifactType>, ActionStatus> getAllArtifactTypes(String userId) {
+ public Either<List<ArtifactType>, ActionStatus> getAllArtifactTypes(final String userId) {
ActionStatus status = validateUserExistsActionStatus(userId);
if (ActionStatus.OK != status) {
return Either.right(status);
}
- return elementOperation.getAllArtifactTypes();
- }
-
- public Either<Map<String, Object>, ActionStatus> getAllDeploymentArtifactTypes() {
- return elementOperation.getAllDeploymentArtifactTypes();
+ return Either.left(elementOperation.getAllArtifactTypes());
}
public Either<Configuration.HeatDeploymentArtifactTimeout, ActionStatus> getDefaultHeatTimeout() {
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 45f2434482..74f78b2ce1 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
@@ -2448,8 +2448,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
.stream()
// create each artifact
.map(e -> createOrUpdateSingleNonMetaArtifact(resource, csarInfo, e.getPath(),
- e.getArtifactName(), e.getArtifactType()
- .getType(),
+ e.getArtifactName(), e.getArtifactType(),
e.getArtifactGroupType(), e.getArtifactLabel(), e.getDisplayName(),
CsarUtils.ARTIFACT_CREATED_FROM_CSAR, e.getArtifactUniqueId(),
artifactsBusinessLogic.new ArtifactOperationInfo(false, false,
@@ -2555,8 +2554,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private boolean isValidArtifactType(ArtifactDefinition artifact) {
boolean result = true;
if (artifact.getArtifactType() == null
- || ArtifactTypeEnum.findType(artifact.getArtifactType()) == ArtifactTypeEnum.VENDOR_LICENSE
- || ArtifactTypeEnum.findType(artifact.getArtifactType()) == ArtifactTypeEnum.VF_LICENSE) {
+ || ArtifactTypeEnum.parse(artifact.getArtifactType()) == ArtifactTypeEnum.VENDOR_LICENSE
+ || ArtifactTypeEnum.parse(artifact.getArtifactType()) == ArtifactTypeEnum.VF_LICENSE) {
result = false;
}
return result;
@@ -2833,10 +2832,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private void setResourceInstanceRelationsOnComponent(Resource resource, List<RequirementCapabilityRelDef> relations) {
if (resource.getComponentInstancesRelations() != null) {
- /*Map<String, RequirementCapabilityRelDef> relationsMapByUid = resource.getComponentInstancesRelations().stream().collect(Collectors.toMap(r -> r.getUid(), r -> r));
- Map<String, RequirementCapabilityRelDef> updatedRelationsByUid = relations.stream().collect(Collectors.toMap(r -> r.getUid(), r -> r));
- relationsMapByUid.putAll(updatedRelationsByUid);
- resource.setComponentInstancesRelations(new ArrayList<>(relationsMapByUid.values()));*/
resource.getComponentInstancesRelations().addAll(relations);
} else {
resource.setComponentInstancesRelations(relations);
@@ -5816,8 +5811,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
.findFirst()
.orElse(null);
if (foundArtifact != null) {
- if (ArtifactTypeEnum.findType(foundArtifact.getArtifactType()) == currNewArtifact
- .getArtifactType()) {
+ if (foundArtifact.getArtifactType().equals(currNewArtifact.getArtifactType())) {
if (!foundArtifact.getArtifactChecksum()
.equals(currNewArtifact.getArtifactChecksum())) {
currNewArtifact.setArtifactUniqueId(foundArtifact.getUniqueId());
@@ -5839,8 +5833,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
currNewArtifact.getArtifactName());
ResponseFormat responseFormat = ResponseFormatManager.getInstance()
.getResponseFormat(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR,
- currNewArtifact.getArtifactName(), currNewArtifact.getArtifactType()
- .name(),
+ currNewArtifact.getArtifactName(), currNewArtifact.getArtifactType(),
foundArtifact.getArtifactType());
AuditingActionEnum auditingAction = artifactsBusinessLogic
.detectAuditingType(artifactsBusinessLogic.new ArtifactOperationInfo(false, false,
@@ -5858,14 +5851,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
for (ArtifactDefinition currArtifact : existingArtifactsToHandle) {
if (currArtifact.getIsFromCsar()) {
artifactsToDelete.add(new NonMetaArtifactInfo(currArtifact.getArtifactName(), null,
- ArtifactTypeEnum.findType(currArtifact.getArtifactType()),
- currArtifact.getArtifactGroupType(), null, currArtifact.getUniqueId(),
- currArtifact.getIsFromCsar()));
+ currArtifact.getArtifactType(),
+ currArtifact.getArtifactGroupType(), null, currArtifact.getUniqueId(),
+ currArtifact.getIsFromCsar()));
} else {
artifactsToUpdate.add(new NonMetaArtifactInfo(currArtifact.getArtifactName(), null,
- ArtifactTypeEnum.findType(currArtifact.getArtifactType()),
- currArtifact.getArtifactGroupType(), null, currArtifact.getUniqueId(),
- currArtifact.getIsFromCsar()));
+ currArtifact.getArtifactType(),
+ currArtifact.getArtifactGroupType(), null, currArtifact.getUniqueId(),
+ currArtifact.getIsFromCsar()));
}
}
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 ba04c00cdb..e946f72851 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
@@ -1909,7 +1909,10 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private ArtifactDefinition getVfModuleInstArtifactForCompInstance(ComponentInstance currVF, Service service, Wrapper<String> payloadWrapper, Wrapper<ResponseFormat> responseWrapper) {
ArtifactDefinition vfModuleAertifact = null;
if (MapUtils.isNotEmpty(currVF.getDeploymentArtifacts())) {
- Optional<ArtifactDefinition> optionalVfModuleArtifact = currVF.getDeploymentArtifacts().values().stream().filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA.name())).findAny();
+ final Optional<ArtifactDefinition> optionalVfModuleArtifact =
+ currVF.getDeploymentArtifacts().values().stream()
+ .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA.getType()))
+ .findAny();
if (optionalVfModuleArtifact.isPresent()) {
vfModuleAertifact = optionalVfModuleArtifact.get();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java
index e4f19355dc..6a74428a90 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java
@@ -55,7 +55,7 @@ public class ComponentInstanceArtifactsMerge implements ComponentInstanceMergeIn
Map<String, ArtifactDefinition> deploymentArtifactsCreatedOnTheInstance = componentInstancesDeploymentArtifacts.entrySet()
.stream()
.filter(i -> !originalComponentDeploymentArtifacts.containsKey(i.getKey()))
- .filter(i -> !ArtifactTypeEnum.VF_MODULES_METADATA.name().equals(i.getValue().getArtifactType()))
+ .filter(i -> !ArtifactTypeEnum.VF_MODULES_METADATA.getType().equals(i.getValue().getArtifactType()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
dataHolder.setOrigComponentDeploymentArtifactsCreatedOnTheInstance(deploymentArtifactsCreatedOnTheInstance);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
index ccb6960c08..21589e0723 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
@@ -23,27 +23,29 @@ package org.openecomp.sdc.be.info;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
import lombok.Getter;
import lombok.NoArgsConstructor;
-
import lombok.Setter;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.be.config.ArtifactConfiguration;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.Configuration.ArtifactTypeConfig;
+import org.openecomp.sdc.be.config.ComponentType;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
@Getter
@Setter
@NoArgsConstructor
@@ -281,27 +283,36 @@ public class ArtifactTemplateInfo {
return Either.left(true);
}
- private static Either<List<ArtifactType>, ActionStatus> getDeploymentArtifactTypes(NodeTypeEnum parentType) {
+ private static Either<List<ArtifactType>, ActionStatus> getDeploymentArtifactTypes(final NodeTypeEnum parentType) {
- Map<String, ArtifactTypeConfig> deploymentArtifacts = null;
- List<ArtifactType> artifactTypes = new ArrayList<>();
+ final List<ArtifactConfiguration> deploymentArtifacts;
+ final List<ArtifactConfiguration> artifactConfigurationList =
+ ConfigurationManager.getConfigurationManager().getConfiguration().getArtifacts();
- if (parentType.equals(NodeTypeEnum.Service)) {
- deploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceDeploymentArtifacts();
+ if (parentType == NodeTypeEnum.Service) {
+ deploymentArtifacts = artifactConfigurationList.stream()
+ .filter(artifactConfiguration ->
+ artifactConfiguration.hasSupport(ArtifactGroupTypeEnum.DEPLOYMENT)
+ && artifactConfiguration.hasSupport(ComponentType.SERVICE))
+ .collect(Collectors.toList());
} else {
- deploymentArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts();
+ deploymentArtifacts = artifactConfigurationList.stream()
+ .filter(artifactConfiguration ->
+ artifactConfiguration.hasSupport(ArtifactGroupTypeEnum.DEPLOYMENT)
+ && artifactConfiguration.hasSupport(ComponentType.RESOURCE))
+ .collect(Collectors.toList());
}
- if (deploymentArtifacts != null) {
- for (String artifactType : deploymentArtifacts.keySet()) {
- ArtifactType artifactT = new ArtifactType();
- artifactT.setName(artifactType);
- artifactTypes.add(artifactT);
- }
+ final List<ArtifactType> artifactTypes = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(deploymentArtifacts)) {
+ deploymentArtifacts.forEach(artifactConfiguration -> {
+ final ArtifactType artifactType = new ArtifactType();
+ artifactType.setName(artifactConfiguration.getType());
+ artifactTypes.add(artifactType);
+ });
return Either.left(artifactTypes);
- } else {
- return Either.right(ActionStatus.GENERAL_ERROR);
}
+ return Either.right(ActionStatus.GENERAL_ERROR);
}
public static int compareByGroupName(ArtifactTemplateInfo art1, ArtifactTemplateInfo art2) {
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 c350812ce4..befdac48b0 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
@@ -31,6 +31,7 @@ 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.Tags;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
@@ -85,7 +86,7 @@ import java.util.Map;
@Path("/v1/")
-/****
+/**
*
* UI oriented servlet - to return elements in specific format UI needs
*
@@ -101,17 +102,18 @@ public class ElementServlet extends BeGenericServlet {
private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
private final ComponentsCleanBusinessLogic componentsCleanBusinessLogic;
private final ElementBusinessLogic elementBusinessLogic;
- private final UserBusinessLogic userBusinessLogic;
+ private final ArtifactsBusinessLogic artifactsBusinessLogic;
@Inject
- public ElementServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- ComponentsCleanBusinessLogic componentsCleanBusinessLogic,
- ElementBusinessLogic elementBusinessLogic) {
+ public ElementServlet(final UserBusinessLogic userBusinessLogic,
+ final ComponentsUtils componentsUtils,
+ final ComponentsCleanBusinessLogic componentsCleanBusinessLogic,
+ final ElementBusinessLogic elementBusinessLogic,
+ final ArtifactsBusinessLogic artifactsBusinessLogic) {
super(userBusinessLogic, componentsUtils);
this.componentsCleanBusinessLogic = componentsCleanBusinessLogic;
this.elementBusinessLogic = elementBusinessLogic;
- this.userBusinessLogic = userBusinessLogic;
+ this.artifactsBusinessLogic = artifactsBusinessLogic;
}
/*
@@ -163,33 +165,6 @@ public class ElementServlet extends BeGenericServlet {
}
}
- //TODO remove after UI alignment and tests after API consolidation ASDC-191
- /* @GET
- @Path("/categories")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Retrieve the all resource, service and product categories", httpMethod = "GET", notes = "Retrieve the all resource, service and product categories", response = Response.class)
- @ApiResponses(value = {@ApiResponse(code = 200, message = "Returns categories Ok"), @ApiResponse(code = 403, message = "Missing information"),
- @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error")})
- public Response getAllCategories(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- try {
- ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
- Either<UiCategories, ResponseFormat> either = elementBL.getAllCategories(userId);
- if (either.isRight()) {
- log.debug("No categories were found");
- return buildErrorResponse(either.right().value());
- } else {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Categories");
- log.debug("getAllCategories failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }*/
-
-
@POST
@Path("/category/{componentType}")
@Consumes(MediaType.APPLICATION_JSON)
@@ -712,7 +687,7 @@ public class ElementServlet extends BeGenericServlet {
try {
ServletContext servletContext = request.getSession().getServletContext();
- Map<String, Object> configuration = getConfigurationUi(elementBusinessLogic, userId);
+ Map<String, Object> configuration = getConfigurationUi(elementBusinessLogic);
if (!configuration.isEmpty()) {
consolidatedObject.put("configuration", configuration);
} else {
@@ -743,22 +718,12 @@ public class ElementServlet extends BeGenericServlet {
return version;
}
- private Map<String, Object> getConfigurationUi(ElementBusinessLogic elementBL, String userId) {
+ private Map<String, Object> getConfigurationUi(final ElementBusinessLogic elementBL) {
Either<Configuration.HeatDeploymentArtifactTimeout, ActionStatus> defaultHeatTimeout = elementBL.getDefaultHeatTimeout();
- Either<Map<String, Object>, ActionStatus> deploymentEither = elementBL.getAllDeploymentArtifactTypes();
Either<Map<String, String>, ActionStatus> resourceTypesMap = elementBL.getResourceTypesMap();
- Either<List<ArtifactType>, ActionStatus> otherEither = elementBL.getAllArtifactTypes(userId);
Map<String, Object> configuration = new HashMap<>();
- if (otherEither.isRight() || otherEither.left().value() == null) {
- log.debug("No other artifact types were found");
- return configuration;
- }
- if (deploymentEither.isRight() || deploymentEither.left().value() == null) {
- log.debug("No deployment artifact types were found");
- return configuration;
- }
if (defaultHeatTimeout.isRight() || defaultHeatTimeout.left().value() == null) {
log.debug("heat default timeout was not found");
return configuration;
@@ -767,10 +732,7 @@ public class ElementServlet extends BeGenericServlet {
log.debug("No resource types were found");
return configuration;
}
- Map<String, Object> artifacts = new HashMap<>();
- artifacts.put("other", otherEither.left().value());
- artifacts.put("deployment", deploymentEither.left().value());
- configuration.put("artifacts", artifacts);
+ configuration.put("artifact", artifactsBusinessLogic.getConfiguration());
configuration.put("heatDeploymentTimeout", defaultHeatTimeout.left().value());
configuration.put("componentTypes", elementBL.getAllComponentTypesParamNames());
configuration.put("roles", elementBL.getAllSupportedRoles());
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 604715d05d..92a1f8016c 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
@@ -41,6 +41,8 @@ import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@@ -50,10 +52,12 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;
import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.sdc.be.config.ArtifactConfigManager;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.ImportUtils.Constants;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
-import org.openecomp.sdc.be.config.Configuration.ArtifactTypeConfig;
+import org.openecomp.sdc.be.config.ArtifactConfiguration;
+import org.openecomp.sdc.be.config.ComponentType;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
@@ -68,7 +72,6 @@ import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.Product;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
@@ -115,7 +118,7 @@ public class CsarUtils {
private ToscaExportHandler toscaExportUtils;
@Autowired
protected ToscaOperationFacade toscaOperationFacade;
-
+
@Autowired(required = false)
private List<CsarEntryGenerator> generators;
@@ -754,19 +757,23 @@ public class CsarUtils {
return artifact;
}
+ @Getter
public static final class NonMetaArtifactInfo {
+ @Setter
+ private String artifactUniqueId;
private final String path;
private final String artifactName;
private final String displayName;
private final String artifactLabel;
- private final ArtifactTypeEnum artifactType;
+ private final String artifactType;
private final ArtifactGroupTypeEnum artifactGroupType;
- private String payloadData;
- private String artifactChecksum;
- private String artifactUniqueId;
+ private final String payloadData;
+ private final String artifactChecksum;
private final boolean isFromCsar;
- public NonMetaArtifactInfo(String artifactName, String path, ArtifactTypeEnum artifactType, ArtifactGroupTypeEnum artifactGroupType, byte[] payloadData, String artifactUniqueId, boolean isFromCsar) {
+ public NonMetaArtifactInfo(final String artifactName, final String path, final String artifactType,
+ final ArtifactGroupTypeEnum artifactGroupType, final byte[] payloadData,
+ final String artifactUniqueId, final boolean isFromCsar) {
super();
this.path = path;
this.isFromCsar = isFromCsar;
@@ -780,57 +787,16 @@ public class CsarUtils {
displayName = artifactName;
}
this.artifactLabel = ValidationUtils.normalizeArtifactLabel(artifactName);
- if (payloadData != null) {
+ if (payloadData == null) {
+ this.payloadData = null;
+ this.artifactChecksum = null;
+ } else {
this.payloadData = Base64.encodeBase64String(payloadData);
this.artifactChecksum = GeneralUtility.calculateMD5Base64EncodedByByteArray(payloadData);
}
this.artifactUniqueId = artifactUniqueId;
}
- public String getPath() {
- return path;
- }
-
- public String getArtifactName() {
- return artifactName;
- }
-
- public ArtifactTypeEnum getArtifactType() {
- return artifactType;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public ArtifactGroupTypeEnum getArtifactGroupType() {
- return artifactGroupType;
- }
-
- public String getArtifactLabel() {
- return artifactLabel;
- }
-
- public boolean isFromCsar(){
- return isFromCsar;
- }
-
- public String getPayloadData() {
- return payloadData;
- }
-
- public String getArtifactChecksum() {
- return artifactChecksum;
- }
-
- public String getArtifactUniqueId() {
- return artifactUniqueId;
- }
-
- public void setArtifactUniqueId(String artifactUniqueId) {
- this.artifactUniqueId = artifactUniqueId;
- }
-
}
/**
@@ -855,7 +821,7 @@ public class CsarUtils {
artifactType = detectArtifactTypeVF(groupTypeEnum, artifactType, collectedWarningMessages);
String artifactFileNameType = parsedArtifactPath[3];
- ret = Either.left(new NonMetaArtifactInfo(artifactFileNameType, artifactPath, ArtifactTypeEnum.findType(artifactType), groupTypeEnum, payloadData, null, true));
+ ret = Either.left(new NonMetaArtifactInfo(artifactFileNameType, artifactPath, artifactType, groupTypeEnum, payloadData, null, true));
} else {
ret = Either.right(eitherGroupType.right().value());
@@ -878,37 +844,21 @@ public class CsarUtils {
return detectArtifactType(artifactGroupType, receivedTypeName, warningMessage, collectedWarningMessages);
}
- private static String detectArtifactType(ArtifactGroupTypeEnum artifactGroupType, String receivedTypeName, String warningMessage, Map<String, Set<List<String>>> collectedWarningMessages, String... arguments) {
-
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(receivedTypeName);
- Map<String, ArtifactTypeConfig> resourceValidTypeArtifacts = null;
-
- if(artifactGroupType != null){
- switch (artifactGroupType) {
- case INFORMATIONAL:
- resourceValidTypeArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getResourceInformationalArtifacts();
- break;
- case DEPLOYMENT:
- resourceValidTypeArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getResourceDeploymentArtifacts();
- break;
- default:
- break;
- }
- }
-
- Set<String> validArtifactTypes = null;
- if(resourceValidTypeArtifacts != null){
- validArtifactTypes = resourceValidTypeArtifacts.keySet();
- }
-
- if (validArtifactTypes == null || artifactType == null || !validArtifactTypes.contains(artifactType.getType())) {
- List<String> messageArguments = new ArrayList<>();
+ private static String detectArtifactType(final ArtifactGroupTypeEnum artifactGroupType,
+ final String receivedTypeName, final String warningMessage,
+ final Map<String, Set<List<String>>> collectedWarningMessages,
+ final String... arguments) {
+ final ArtifactConfiguration artifactConfiguration =
+ ArtifactConfigManager.getInstance()
+ .find(receivedTypeName, artifactGroupType, ComponentType.RESOURCE)
+ .orElse(null);
+
+ if (artifactConfiguration == null) {
+ final List<String> messageArguments = new ArrayList<>();
messageArguments.add(receivedTypeName);
messageArguments.addAll(Arrays.asList(arguments));
if (!collectedWarningMessages.containsKey(warningMessage)) {
- Set<List<String>> messageArgumentLists = new HashSet<>();
+ final Set<List<String>> messageArgumentLists = new HashSet<>();
messageArgumentLists.add(messageArguments);
collectedWarningMessages.put(warningMessage, messageArgumentLists);
} else {
@@ -916,7 +866,7 @@ public class CsarUtils {
}
}
- return artifactType == null ? ArtifactTypeEnum.OTHER.getType() : artifactType.getType();
+ return artifactConfiguration == null ? ArtifactTypeEnum.OTHER.getType() : receivedTypeName;
}
private Either<ZipOutputStream, ResponseFormat> writeAllFilesToCsar(Component mainComponent, CsarDefinition csarDefinition, ZipOutputStream zipstream, boolean isInCertificationRequest) throws IOException{
@@ -929,7 +879,7 @@ public class CsarUtils {
}
ComponentTypeArtifacts mainTypeAndCIArtifacts = componentArtifacts.getMainTypeAndCIArtifacts();
- writeComponentArtifactsToSpecifiedPath = writeArtifactsInfoToSpecifiedtPath(mainComponent, mainTypeAndCIArtifacts.getComponentArtifacts(), zipstream, ARTIFACTS_PATH, isInCertificationRequest);
+ writeComponentArtifactsToSpecifiedPath = writeArtifactsInfoToSpecifiedPath(mainComponent, mainTypeAndCIArtifacts.getComponentArtifacts(), zipstream, ARTIFACTS_PATH, isInCertificationRequest);
if(writeComponentArtifactsToSpecifiedPath.isRight()){
return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
@@ -942,7 +892,7 @@ public class CsarUtils {
for (String keyAssetName : keySet) {
ArtifactsInfo artifactsInfo = componentInstancesArtifacts.get(keyAssetName);
String pathWithAssetName = currentPath + keyAssetName + PATH_DELIMITER;
- writeComponentArtifactsToSpecifiedPath = writeArtifactsInfoToSpecifiedtPath(mainComponent, artifactsInfo, zipstream, pathWithAssetName, isInCertificationRequest);
+ writeComponentArtifactsToSpecifiedPath = writeArtifactsInfoToSpecifiedPath(mainComponent, artifactsInfo, zipstream, pathWithAssetName, isInCertificationRequest);
if(writeComponentArtifactsToSpecifiedPath.isRight()){
return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
@@ -1036,7 +986,7 @@ public class CsarUtils {
ComponentTypeArtifacts componentInstanceArtifacts = componentTypeArtifacts.get(keyAssetName);
ArtifactsInfo componentArtifacts2 = componentInstanceArtifacts.getComponentArtifacts();
String pathWithAssetName = currentPath + keyAssetName + PATH_DELIMITER;
- Either<ZipOutputStream, ResponseFormat> writeArtifactsInfoToSpecifiedPath = writeArtifactsInfoToSpecifiedtPath(mainComponent, componentArtifacts2, zipstream, pathWithAssetName, isInCertificationRequest);
+ Either<ZipOutputStream, ResponseFormat> writeArtifactsInfoToSpecifiedPath = writeArtifactsInfoToSpecifiedPath(mainComponent, componentArtifacts2, zipstream, pathWithAssetName, isInCertificationRequest);
if(writeArtifactsInfoToSpecifiedPath.isRight()){
return writeArtifactsInfoToSpecifiedPath;
@@ -1046,32 +996,34 @@ public class CsarUtils {
return Either.left(zipstream);
}
- private Either<ZipOutputStream, ResponseFormat> writeArtifactsInfoToSpecifiedtPath(Component mainComponent, ArtifactsInfo currArtifactsInfo, ZipOutputStream zip, String path, boolean isInCertificationRequest) throws IOException {
- Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> artifactsInfo = currArtifactsInfo
- .getArtifactsInfo();
- Set<ArtifactGroupTypeEnum> groupTypeEnumKeySet = artifactsInfo.keySet();
-
- for (ArtifactGroupTypeEnum artifactGroupTypeEnum : groupTypeEnumKeySet) {
- String groupTypeFolder = path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + PATH_DELIMITER;
+ private Either<ZipOutputStream, ResponseFormat> writeArtifactsInfoToSpecifiedPath(final Component mainComponent,
+ final ArtifactsInfo currArtifactsInfo,
+ final ZipOutputStream zip,
+ final String path,
+ final boolean isInCertificationRequest) throws IOException {
+ final Map<ArtifactGroupTypeEnum, Map<String, List<ArtifactDefinition>>> artifactsInfo =
+ currArtifactsInfo.getArtifactsInfo();
+ for (final ArtifactGroupTypeEnum artifactGroupTypeEnum : artifactsInfo.keySet()) {
+ final String groupTypeFolder = path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + PATH_DELIMITER;
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactTypesMap = artifactsInfo.get(artifactGroupTypeEnum);
- Set<ArtifactTypeEnum> artifactTypeEnumKeySet = artifactTypesMap.keySet();
+ final Map<String, List<ArtifactDefinition>> artifactTypesMap = artifactsInfo.get(artifactGroupTypeEnum);
- for (ArtifactTypeEnum artifactTypeEnum : artifactTypeEnumKeySet) {
- List<ArtifactDefinition> artifactDefinitionList = artifactTypesMap.get(artifactTypeEnum);
- String artifactTypeFolder = groupTypeFolder + artifactTypeEnum.toString() + PATH_DELIMITER;
+ for (final String artifactType : artifactTypesMap.keySet()) {
+ final List<ArtifactDefinition> artifactDefinitionList = artifactTypesMap.get(artifactType);
+ String artifactTypeFolder = groupTypeFolder + artifactType + PATH_DELIMITER;
- if(artifactTypeEnum == ArtifactTypeEnum.WORKFLOW && path.contains(ARTIFACTS_PATH + RESOURCES_PATH)){
+ if(ArtifactTypeEnum.WORKFLOW.getType().equals(artifactType) && path.contains(ARTIFACTS_PATH + RESOURCES_PATH)){
// Ignore this packaging as BPMN artifacts needs to be packaged in different manner
continue;
}
- if (artifactTypeEnum == ArtifactTypeEnum.WORKFLOW) {
+ if (ArtifactTypeEnum.WORKFLOW.getType().equals(artifactType)) {
artifactTypeFolder += OperationArtifactUtil.BPMN_ARTIFACT_PATH + File.separator;
}
- Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition = writeArtifactDefinition(mainComponent, zip, artifactDefinitionList, artifactTypeFolder, isInCertificationRequest);
+ Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition =
+ writeArtifactDefinition(mainComponent, zip, artifactDefinitionList, artifactTypeFolder, isInCertificationRequest);
- if(writeArtifactDefinition.isRight()){
+ if (writeArtifactDefinition.isRight()) {
return writeArtifactDefinition;
}
}
@@ -1121,29 +1073,22 @@ public class CsarUtils {
private class ArtifactsInfo {
//Key is the type of artifacts(Informational/Deployment)
//Value is a map between an artifact type and a list of all artifacts of this type
- private Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> artifactsInfoField;
+ private Map<ArtifactGroupTypeEnum, Map<String, List<ArtifactDefinition>>> artifactsInfoField;
public ArtifactsInfo() {
this.artifactsInfoField = new EnumMap<>(ArtifactGroupTypeEnum.class);
}
- public Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> getArtifactsInfo() {
+ public Map<ArtifactGroupTypeEnum, Map<String, List<ArtifactDefinition>>> getArtifactsInfo() {
return artifactsInfoField;
}
- public List<ArtifactDefinition> getFlatArtifactsListByType(ArtifactTypeEnum artifactType){
- List<ArtifactDefinition> artifacts = new ArrayList<>();
- for (List<ArtifactDefinition> artifactsByType:artifactsInfoField.get(artifactType).values()){
- artifacts.addAll(artifactsByType);
- }
- return artifacts;
- }
-
- public void addArtifactsToGroup(ArtifactGroupTypeEnum artifactGroup,Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsDefinition){
+ public void addArtifactsToGroup(ArtifactGroupTypeEnum artifactGroup,
+ Map<String, List<ArtifactDefinition>> artifactsDefinition) {
if (artifactsInfoField.get(artifactGroup) == null) {
artifactsInfoField.put(artifactGroup, artifactsDefinition);
} else {
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactTypeEnumListMap =
+ Map<String, List<ArtifactDefinition>> artifactTypeEnumListMap =
artifactsInfoField.get(artifactGroup);
artifactTypeEnumListMap.putAll(artifactsDefinition);
artifactsInfoField.put(artifactGroup, artifactTypeEnumListMap);
@@ -1295,8 +1240,8 @@ public class CsarUtils {
private String printArtifacts(ComponentTypeArtifacts componentInstanceArtifacts) {
StringBuilder result = new StringBuilder();
ArtifactsInfo artifactsInfo = componentInstanceArtifacts.getComponentArtifacts();
- Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> componetArtifacts = artifactsInfo.getArtifactsInfo();
- printArtifacts(componetArtifacts);
+ Map<ArtifactGroupTypeEnum, Map<String, List<ArtifactDefinition>>> componentArtifacts = artifactsInfo.getArtifactsInfo();
+ printArtifacts(componentArtifacts);
result = result.append("Resources\n");
for (Map.Entry<String, ArtifactsInfo> resourceInstance:componentInstanceArtifacts.getComponentInstancesArtifacts().entrySet()){
result.append("Folder" + resourceInstance.getKey() + "\n");
@@ -1306,12 +1251,12 @@ public class CsarUtils {
return result.toString();
}
- private String printArtifacts(Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> componetArtifacts) {
+ private String printArtifacts(Map<ArtifactGroupTypeEnum, Map<String, List<ArtifactDefinition>>> componetArtifacts) {
StringBuilder result = new StringBuilder();
- for (Map.Entry<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> artifactGroup:componetArtifacts.entrySet()){
+ for (Map.Entry<ArtifactGroupTypeEnum, Map<String, List<ArtifactDefinition>>> artifactGroup:componetArtifacts.entrySet()){
result.append(" " + artifactGroup.getKey().getType());
- for (Map.Entry<ArtifactTypeEnum, List<ArtifactDefinition>> groupArtifacts:artifactGroup.getValue().entrySet()){
- result.append(" " + groupArtifacts.getKey().getType());
+ for (Map.Entry<String, List<ArtifactDefinition>> groupArtifacts:artifactGroup.getValue().entrySet()){
+ result.append(" " + groupArtifacts.getKey());
for (ArtifactDefinition artifact:groupArtifacts.getValue()){
result.append(" " + artifact.getArtifactDisplayName());
}
@@ -1361,10 +1306,10 @@ public class CsarUtils {
ComponentTypeArtifacts componentParentArtifacts = collectComponentTypeArtifacts(resourcesTypeArtifacts, componentInstance, fetchedComponent);
//3. find the artifacts specific to the instance
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> componentInstanceSpecificInformationalArtifacts =
+ Map<String, List<ArtifactDefinition>> componentInstanceSpecificInformationalArtifacts =
getComponentInstanceSpecificArtifacts(componentInstance.getArtifacts(),
componentParentArtifacts.getComponentArtifacts().getArtifactsInfo(), ArtifactGroupTypeEnum.INFORMATIONAL);
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> componentInstanceSpecificDeploymentArtifacts =
+ Map<String, List<ArtifactDefinition>> componentInstanceSpecificDeploymentArtifacts =
getComponentInstanceSpecificArtifacts(componentInstance.getDeploymentArtifacts(),
componentParentArtifacts.getComponentArtifacts().getArtifactsInfo(), ArtifactGroupTypeEnum.DEPLOYMENT);
@@ -1402,24 +1347,23 @@ public class CsarUtils {
public void setVersionFirstThreeOctets(String versionFirstThreeOctetes) {
this.versionFirstThreeOctets = versionFirstThreeOctetes;
}
- private Map<ArtifactTypeEnum, List<ArtifactDefinition>> getComponentInstanceSpecificArtifacts(Map<String, ArtifactDefinition> componentArtifacts,
- Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> componentTypeArtifacts, ArtifactGroupTypeEnum artifactGroupTypeEnum) {
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> parentArtifacts = componentTypeArtifacts.get(artifactGroupTypeEnum); //the artfiacts of the component itself and not the instance
+ private Map<String, List<ArtifactDefinition>> getComponentInstanceSpecificArtifacts(Map<String, ArtifactDefinition> componentArtifacts,
+ Map<ArtifactGroupTypeEnum, Map<String, List<ArtifactDefinition>>> componentTypeArtifacts, ArtifactGroupTypeEnum artifactGroupTypeEnum) {
+ Map<String, List<ArtifactDefinition>> parentArtifacts = componentTypeArtifacts.get(artifactGroupTypeEnum); //the artfiacts of the component itself and not the instance
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsByTypeOfComponentInstance = new EnumMap<>(ArtifactTypeEnum.class);
+ Map<String, List<ArtifactDefinition>> artifactsByTypeOfComponentInstance = new HashMap<>();
if (componentArtifacts!=null){
for (ArtifactDefinition artifact:componentArtifacts.values()){
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
List<ArtifactDefinition> parentArtifactsByType = null;
if (parentArtifacts!=null){
- parentArtifactsByType = parentArtifacts.get(artifactType);
+ parentArtifactsByType = parentArtifacts.get(artifact.getArtifactType());
}
//the artifact is of instance
if (parentArtifactsByType == null || !parentArtifactsByType.contains(artifact)){
- List<ArtifactDefinition> typeArtifacts = artifactsByTypeOfComponentInstance.get(artifactType);
+ List<ArtifactDefinition> typeArtifacts = artifactsByTypeOfComponentInstance.get(artifact.getArtifactType());
if (typeArtifacts == null){
typeArtifacts = new ArrayList<>();
- artifactsByTypeOfComponentInstance.put(artifactType, typeArtifacts);
+ artifactsByTypeOfComponentInstance.put(artifact.getArtifactType(), typeArtifacts);
}
typeArtifacts.add(artifact);
}
@@ -1431,12 +1375,12 @@ public class CsarUtils {
private ArtifactsInfo collectComponentArtifacts(Component component) {
Map<String, ArtifactDefinition> informationalArtifacts = component.getArtifacts();
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> informationalArtifactsByType = collectGroupArtifacts(informationalArtifacts);
+ Map<String, List<ArtifactDefinition>> informationalArtifactsByType = collectGroupArtifacts(informationalArtifacts);
Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> deploymentArtifactsByType = collectGroupArtifacts(deploymentArtifacts);
+ Map<String, List<ArtifactDefinition>> deploymentArtifactsByType = collectGroupArtifacts(deploymentArtifacts);
Map<String, ArtifactDefinition> interfaceOperationArtifacts =
OperationArtifactUtil.getDistinctInterfaceOperationArtifactsByName(component);
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> interfaceOperationArtifactsByType = collectGroupArtifacts(
+ Map<String, List<ArtifactDefinition>> interfaceOperationArtifactsByType = collectGroupArtifacts(
interfaceOperationArtifacts);
ArtifactsInfo artifactsInfo = new ArtifactsInfo();
if (!informationalArtifactsByType.isEmpty()){
@@ -1453,16 +1397,13 @@ public class CsarUtils {
return artifactsInfo;
}
- private Map<ArtifactTypeEnum, List<ArtifactDefinition>> collectGroupArtifacts(Map<String, ArtifactDefinition> componentArtifacts) {
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsByType = new EnumMap<>(ArtifactTypeEnum.class);
- for (ArtifactDefinition artifact:componentArtifacts.values()){
- if (artifact.getArtifactUUID()!=null){
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
- List<ArtifactDefinition> typeArtifacts = artifactsByType.get(artifactType);
- if (typeArtifacts==null){
- typeArtifacts = new ArrayList<>();
- artifactsByType.put(artifactType, typeArtifacts);
- }
+ private Map<String, List<ArtifactDefinition>> collectGroupArtifacts(
+ final Map<String, ArtifactDefinition> componentArtifacts) {
+ final Map<String, List<ArtifactDefinition>> artifactsByType = new HashMap<>();
+ for (final ArtifactDefinition artifact : componentArtifacts.values()) {
+ if (artifact.getArtifactUUID() != null) {
+ artifactsByType.putIfAbsent(artifact.getArtifactType(), new ArrayList<>());
+ final List<ArtifactDefinition> typeArtifacts = artifactsByType.get(artifact.getArtifactType());
typeArtifacts.add(artifact);
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
index bab82ada1b..08e4406d6a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
@@ -16,6 +16,13 @@
package org.openecomp.sdc.be.tosca.utils;
+import java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.WordUtils;
import org.openecomp.sdc.be.components.impl.ImportUtils.Constants;
@@ -33,15 +40,6 @@ import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.stream.Collectors;
-
public class OperationArtifactUtil {
public static final String BPMN_ARTIFACT_PATH = "BPMN";
@@ -86,11 +84,11 @@ public class OperationArtifactUtil {
return implementationArtifactName.substring(1, implementationArtifactName.length()-1);
} else {
return CsarUtils.ARTIFACTS + File.separator + WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name())
- + File.separator + ArtifactTypeEnum.WORKFLOW.name() + File.separator + BPMN_ARTIFACT_PATH
+ + File.separator + ArtifactTypeEnum.WORKFLOW.getType() + File.separator + BPMN_ARTIFACT_PATH
+ File.separator + operation.getImplementation().getArtifactName();
}
}
-
+
private static boolean artifactNameIsALiteralValue(final String artifactName) {
return artifactName.startsWith(Constants.ESCAPED_DOUBLE_QUOTE) && artifactName.endsWith(Constants.ESCAPED_DOUBLE_QUOTE);
}
@@ -99,7 +97,7 @@ public class OperationArtifactUtil {
OperationDataDefinition operation) {
return CsarUtils.ARTIFACTS + File.separator + toscaComponentName + File.separator +
WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator +
- ArtifactTypeEnum.WORKFLOW.name() + File.separator + BPMN_ARTIFACT_PATH + File.separator +
+ ArtifactTypeEnum.WORKFLOW.getType() + File.separator + BPMN_ARTIFACT_PATH + File.separator +
operation.getImplementation().getArtifactName();
}