aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
authorTal Gitelman <tg851x@intl.att.com>2017-12-10 18:55:03 +0200
committerTal Gitelman <tg851x@intl.att.com>2017-12-10 19:33:38 +0200
commit51d50f0ef642e0f996a1c8b8d2ef4838bdfec892 (patch)
tree3ac236a864d74d19b0f5c9020891a7a7e5c31b44 /catalog-model/src/main
parentb5cc2e0695f195716d6ccdc65e73807a6632ec70 (diff)
Final commit to master merge from
Change-Id: Ib464f9a8828437c86fe6def8af238aaf83473507 Issue-ID: SDC-714 Signed-off-by: Tal Gitelman <tg851x@intl.att.com>
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/CapabilityDefinition.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/CapabilityRequirementRelationship.java39
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java59
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java17
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstancePropInput.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java7
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupProperty.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ImplementationArtifact.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyDefinition.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyValueDefinition.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/RelationshipInfo.java (renamed from catalog-model/src/main/java/org/openecomp/sdc/be/model/RequirementAndRelationshipPair.java)24
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/TargetCapabilityRelDef.java15
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadPropInfo.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java5
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/CheckAndUpdateJob.java5
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/DeleteJob.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/Job.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/OverrideJob.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java7
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/SyncWorker.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java18
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ByToscaNameDerivedNodeTypeResolver.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/GroupsOperation.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java438
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java108
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java69
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java20
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java4229
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java119
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IAdditionalInformationOperation.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IArtifactOperation.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICacheMangerOperation.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICapabilityOperation.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IComponentInstanceOperation.java14
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IConsumerOperation.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupInstanceOperation.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInputsOperation.java6
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IUserAdminOperation.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperation.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java25
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityOperation.java23
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java16
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ConsumerOperation.java6
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java40
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java27
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InputsOperation.java38
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java38
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UserAdminOperation.java21
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtils.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintFunctionalException.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintRequiredParameterException.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintValueDoNotMatchPropertyTypeException.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintViolationException.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java17
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/JsonConverter.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java7
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentMetadata.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceMetadata.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceMetadata.java5
77 files changed, 3096 insertions, 2535 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/CapabilityDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/CapabilityDefinition.java
index 548f72df9c..ccc52480b8 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/CapabilityDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/CapabilityDefinition.java
@@ -23,9 +23,9 @@ package org.openecomp.sdc.be.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
-import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
/**
* Specifies the capabilities that the Node Type exposes.
@@ -59,7 +59,7 @@ public class CapabilityDefinition extends CapabilityDataDefinition implements Se
super((CapabilityDefinition)other);
if (other.properties != null) {
- this.properties = new ArrayList<>(other.properties);
+ this.properties = new ArrayList<>(other.properties.stream().map(p -> new ComponentInstanceProperty(p)).collect(Collectors.toList()));
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/CapabilityRequirementRelationship.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/CapabilityRequirementRelationship.java
new file mode 100644
index 0000000000..54b998d0dd
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/CapabilityRequirementRelationship.java
@@ -0,0 +1,39 @@
+package org.openecomp.sdc.be.model;
+
+import java.io.Serializable;
+
+import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
+/**
+ * Contains the Capability, Requirement and Relationship info
+ */
+public class CapabilityRequirementRelationship implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private RelationshipInfo relation;
+ private CapabilityDataDefinition capability;
+ private RequirementDataDefinition requirement;
+
+ public RelationshipInfo getRelation() {
+ return relation;
+ }
+ public void setRelation(RelationshipInfo relation) {
+ this.relation = relation;
+ }
+ public CapabilityDataDefinition getCapability() {
+ return capability;
+ }
+ public void setCapability(CapabilityDataDefinition capability) {
+ this.capability = capability;
+ }
+ public RequirementDataDefinition getRequirement() {
+ return requirement;
+ }
+ public void setRequirement(RequirementDataDefinition requirement) {
+ this.requirement = requirement;
+ }
+ public static long getSerialversionuid() {
+ return serialVersionUID;
+ }
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
index 9ffefa6384..5760e0b11b 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
@@ -28,12 +28,14 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import java.util.stream.Collectors;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
public abstract class Component implements Serializable {
@@ -342,6 +344,27 @@ public abstract class Component implements Serializable {
return componentInstances;
}
+ public Map<String, ArtifactDefinition> safeGetComponentInstanceDeploymentArtifacts(String componentInstanceId) {
+ Optional<ComponentInstance> componentInstanceById = getComponentInstanceById(componentInstanceId);
+ Map<String, ArtifactDefinition> instanceDeploymentArtifacts = componentInstanceById.get().safeGetDeploymentArtifacts();
+ return instanceDeploymentArtifacts != null ? instanceDeploymentArtifacts : Collections.EMPTY_MAP;
+ }
+
+ public Map<String, ArtifactDefinition> safeGetComponentInstanceInformationalArtifacts(String componentInstanceId) {
+ Optional<ComponentInstance> componentInstanceById = getComponentInstanceById(componentInstanceId);
+ Map<String, ArtifactDefinition> instanceInformationalArtifacts = componentInstanceById.get().safeGetInformationalArtifacts();
+ return instanceInformationalArtifacts != null ? instanceInformationalArtifacts : Collections.EMPTY_MAP;
+ }
+
+ public List<ArtifactDefinition> safeGetComponentInstanceHeatArtifacts(String componentInstanceId) {
+ Optional<ComponentInstance> componentInstanceById = getComponentInstanceById(componentInstanceId);
+ List<ArtifactDefinition> instanceHeatEnvArtifacts = Optional.ofNullable(componentInstanceById.get().safeGetDeploymentArtifacts().values()).orElse(new ArrayList<ArtifactDefinition>())
+ .stream()
+ .filter(artifact -> artifact.getArtifactType() != null && artifact.getArtifactType().equals(ArtifactTypeEnum.HEAT_ENV.name()))
+ .collect(Collectors.toList());
+ return instanceHeatEnvArtifacts == null ? Collections.EMPTY_LIST : instanceHeatEnvArtifacts;
+ }
+
public void setComponentInstances(List<ComponentInstance> resourceInstances) {
this.componentInstances = resourceInstances;
}
@@ -358,6 +381,14 @@ public abstract class Component implements Serializable {
return componentInstancesProperties;
}
+ public List<ComponentInstanceProperty> safeGetComponentInstanceProperties(String cmptInstacneId) {
+ return this.safeGetComponentInstanceEntity(cmptInstacneId, this.componentInstancesProperties);
+ }
+
+ public List<ComponentInstanceInput> safeGetComponentInstanceInput(String comptInstanceId) {
+ return this.safeGetComponentInstanceEntity(comptInstanceId, this.componentInstancesInputs);
+ }
+
public void setComponentInstancesProperties(
Map<String, List<ComponentInstanceProperty>> resourceInstancesProperties) {
this.componentInstancesProperties = resourceInstancesProperties;
@@ -411,6 +442,10 @@ public abstract class Component implements Serializable {
componentMetadataDefinition.getMetadataDataDefinition().setInvariantUUID(invariantUUID);
}
+ public Optional<ComponentInstance> getComponentInstanceById(String id) {
+ return componentInstances.stream().filter(instance -> id.equals(instance.getUniqueId())).findFirst();
+ }
+
public List<GroupDefinition> getGroups() {
return groups;
}
@@ -632,6 +667,30 @@ public abstract class Component implements Serializable {
return componentInstancesInputs;
}
+ public List<ComponentInstanceInput> safeGetComponentInstanceInputsByName(String cmptInstanceName) {
+ List<ComponentInstanceInput> emptyPropsList = Collections.emptyList();
+ if (this.componentInstancesInputs == null) {
+ return emptyPropsList;
+ }
+ Optional<List<ComponentInstanceInput>> instanceInputsByName = this.componentInstances.stream()
+ .filter(ci -> ci.getName().equals(cmptInstanceName))
+ .map(ComponentInstance::getUniqueId)
+ .map(instanceId -> safeGetComponentInstanceEntity(instanceId, this.componentInstancesInputs))
+ .findAny();
+ return instanceInputsByName.orElse(emptyPropsList);
+ }
+
+ private <T> List<T> safeGetComponentInstanceEntity(String cmptInstanceId, Map<String, List<T>> instanceEntities) {
+ List<T> emptyPropsList = Collections.emptyList();
+ if (instanceEntities == null) {
+ return emptyPropsList;
+ }
+ List<T> cmptInstanceProps = instanceEntities.get(cmptInstanceId);
+ return cmptInstanceProps == null ? emptyPropsList : cmptInstanceProps;
+ }
+
+
+
public void setComponentInstancesInputs(Map<String, List<ComponentInstanceInput>> componentInstancesInputs) {
this.componentInstancesInputs = componentInstancesInputs;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java
index 0b7e523813..8ed256c555 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.model;
import java.io.Serializable;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -67,6 +68,14 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement
return deploymentArtifacts;
}
+ public Map<String, ArtifactDefinition> safeGetDeploymentArtifacts() {
+ return deploymentArtifacts == null ? Collections.EMPTY_MAP : deploymentArtifacts;
+ }
+
+ public Map<String, ArtifactDefinition> safeGetInformationalArtifacts() {
+ return artifacts == null ? Collections.EMPTY_MAP : deploymentArtifacts;
+ }
+
public void setDeploymentArtifacts(Map<String, ArtifactDefinition> deploymentArtifacts) {
this.deploymentArtifacts = deploymentArtifacts;
}
@@ -75,6 +84,10 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement
return artifacts;
}
+ public Map<String, ArtifactDefinition> safeGetArtifacts() {
+ return artifacts == null ? Collections.EMPTY_MAP : artifacts;
+ }
+
public void setArtifacts(Map<String, ArtifactDefinition> artifacts) {
this.artifacts = artifacts;
}
@@ -86,5 +99,9 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement
public void setGroupInstances(List<GroupInstance> groupInstances) {
this.groupInstances = groupInstances;
}
+
+ public String getActualComponentUid() {
+ return getIsProxy() ? getSourceModelUid() : getComponentUid();
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstancePropInput.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstancePropInput.java
index 9f5e3e9eea..ace83812ab 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstancePropInput.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstancePropInput.java
@@ -21,7 +21,6 @@
package org.openecomp.sdc.be.model;
import java.io.Serializable;
-import java.util.Map;
public class ComponentInstancePropInput extends ComponentInstanceProperty implements Serializable{
/**
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
index 972884682e..a9cc32d9b0 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
@@ -24,8 +24,6 @@ import java.util.List;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
public class DataTypeDefinition extends DataTypeDataDefinition {
// @JsonIgnore
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java
index f841fcb6da..0e30211454 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java
@@ -20,13 +20,12 @@
package org.openecomp.sdc.be.model;
-import fj.data.Either;
+import java.util.List;
+
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import java.util.List;
+import fj.data.Either;
public interface DerivedNodeTypeResolver {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java
index f0e08b85fd..e7d7c69efc 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstance.java
@@ -23,6 +23,7 @@ package org.openecomp.sdc.be.model;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
+
import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupProperty.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupProperty.java
index d8589d51b9..649aa1f710 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupProperty.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupProperty.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.model;
-import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
public class GroupProperty extends PropertyDefinition {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ImplementationArtifact.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ImplementationArtifact.java
index fb5943e1bd..afd555ee91 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ImplementationArtifact.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ImplementationArtifact.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.be.model;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
+
/**
* Specifies an implementation artifact for interfaces or operations of a
* {@link NodeType node type} or {@link RelationshipType relation type}.
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java
index 8897d6ed4e..5eb5e8c05c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java
@@ -21,12 +21,10 @@
package org.openecomp.sdc.be.model;
import java.io.Serializable;
-import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.codehaus.jackson.annotate.JsonIgnore;
-import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyDefinition.java
index 34ecdbf06d..6292218837 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyDefinition.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.model;
import java.io.Serializable;
import java.util.List;
+
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyValueDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyValueDefinition.java
index 0264262ab3..bc22e55923 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyValueDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PropertyValueDefinition.java
@@ -21,7 +21,6 @@
package org.openecomp.sdc.be.model;
import org.openecomp.sdc.be.datatypes.elements.InputsValueDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
public class PropertyValueDefinition extends InputsValueDataDefinition implements IOperationParameter {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/RequirementAndRelationshipPair.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/RelationshipInfo.java
index a3e4f48c51..02c9f70236 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/RequirementAndRelationshipPair.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/RelationshipInfo.java
@@ -24,11 +24,8 @@ import java.io.Serializable;
import org.openecomp.sdc.be.datatypes.elements.RelationshipInstDataDefinition;
-public class RequirementAndRelationshipPair implements Serializable {
+public class RelationshipInfo implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = -5763126570618602135L;
private String requirement;
@@ -43,17 +40,17 @@ public class RequirementAndRelationshipPair implements Serializable {
private String capabilityUid;
private String requirementUid;
- public RequirementAndRelationshipPair() {
+ public RelationshipInfo() {
super();
}
- public RequirementAndRelationshipPair(String requirement, RelationshipImpl relationship) {
+ public RelationshipInfo(String requirement, RelationshipImpl relationship) {
super();
this.requirement = requirement;
this.relationship = relationship;
}
- public RequirementAndRelationshipPair(String requirement, RelationshipImpl relationship, String capability) {
+ public RelationshipInfo(String requirement, RelationshipImpl relationship, String capability) {
super();
this.requirement = requirement;
this.relationship = relationship;
@@ -134,9 +131,16 @@ public class RequirementAndRelationshipPair implements Serializable {
if ( savedRelation == null ){
return false;
}
- if ( !savedRelation.getType().equals(this.getRelationship().getType()) ){
- return false;
- }
+ if(getRelationship().getType() == null ){
+ if(savedRelation.getType() != null){
+ return false;
+ }
+ }
+ else {
+ if ( !savedRelation.getType().equals(this.getRelationship().getType()) ){
+ return false;
+ }
+ }
if ( !savedRelation.getCapabilityOwnerId().equals(this.getCapabilityOwnerId()) ){
return false;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java
index 45fc5f62b3..d48718bbff 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map;
import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.utils.MapUtil;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -299,5 +300,15 @@ public class Resource extends Component implements Serializable {
public boolean deriveFromGeneric(){
return this.shouldGenerateInputs() || (derivedFrom != null && derivedFrom.contains(fetchGenericTypeToscaNameFromConfig()));
}
-
+
+ public Map<String, List<RequirementCapabilityRelDef>> groupRelationsByInstanceName(Resource resource) {
+ Map<String, List<RequirementCapabilityRelDef>> relationsByInstanceId = MapUtil.groupListBy(resource.getComponentInstancesRelations(), RequirementCapabilityRelDef::getFromNode);
+ return MapUtil.convertMapKeys(relationsByInstanceId, (instId) -> getInstanceNameFromInstanceId(resource, instId));
+ }
+
+ private String getInstanceNameFromInstanceId(Resource resource, String instId) {
+ return resource.getComponentInstanceById(instId).get().getName();
+ }
+
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java
index cdd171184c..563030e147 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.model;
import java.util.Map;
+
import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
@@ -89,7 +90,13 @@ public class Service extends Component {
public String getNamingPolicy() {
return getServiceMetadataDefinition().getNamingPolicy();
}
-
+
+ public String getEnvironmentContext() { return getServiceMetadataDefinition().getEnvironmentContext(); }
+
+ public void setEnvironmentContext(String environmentContext) {
+ getServiceMetadataDefinition().setEnvironmentContext(environmentContext);
+ }
+
public void setServiceType(String serviceType){
getServiceMetadataDefinition().setServiceType(serviceType);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/TargetCapabilityRelDef.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/TargetCapabilityRelDef.java
index f30ef353b1..6a1fcac7e8 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/TargetCapabilityRelDef.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/TargetCapabilityRelDef.java
@@ -33,15 +33,13 @@ public class TargetCapabilityRelDef implements Serializable {
private String uid;
private String toNode;
- // private List<ImmutablePair<String, RelationshipImpl>> relationships;
-
- private List<RequirementAndRelationshipPair> relationships;
+ private List<CapabilityRequirementRelationship> relationships;
public TargetCapabilityRelDef() {
super();
}
- public TargetCapabilityRelDef(String toNode, List<RequirementAndRelationshipPair> relationships) {
+ public TargetCapabilityRelDef(String toNode, List<CapabilityRequirementRelationship> relationships) {
super();
this.toNode = toNode;
this.relationships = relationships;
@@ -63,10 +61,15 @@ public class TargetCapabilityRelDef implements Serializable {
// this.capabilityOwnerId = capabilityOwnerId;
// }
- public List<RequirementAndRelationshipPair> getRelationships() {
+ public List<CapabilityRequirementRelationship> getRelationships() {
return relationships;
}
+
+ public CapabilityRequirementRelationship getSingleRelationship() {//currently only single relationship is supported
+ return relationships == null || relationships.isEmpty() ? null : relationships.get(0);
+ }
+
public String getUid() {
return uid;
}
@@ -75,7 +78,7 @@ public class TargetCapabilityRelDef implements Serializable {
this.uid = uid;
}
- public void setRelationships(List<RequirementAndRelationshipPair> relationships) {
+ public void setRelationships(List<CapabilityRequirementRelationship> relationships) {
this.relationships = relationships;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadPropInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadPropInfo.java
index 5640f5582c..2683407fa2 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadPropInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadPropInfo.java
@@ -21,7 +21,6 @@
package org.openecomp.sdc.be.model;
import java.util.List;
-import java.util.Map;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java
index 7f2834bddf..e2a6c3c662 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java
@@ -20,8 +20,6 @@
package org.openecomp.sdc.be.model;
-import java.util.Map;
-
public class UploadReqInfo extends UploadInfo {
/**
* specify the node type(Optional by tosca)
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java
index cb85deeb2d..22b46a0458 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java
@@ -39,11 +39,11 @@ import javax.annotation.PostConstruct;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.Configuration;
-import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.Configuration.ApplicationL1CacheCatalogInfo;
import org.openecomp.sdc.be.config.Configuration.ApplicationL2CacheConfig;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.cassandra.ComponentCassandraDao;
@@ -58,7 +58,6 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.*;
import org.openecomp.sdc.be.resources.data.ComponentCacheData;
import org.openecomp.sdc.common.util.SerializationUtils;
import org.openecomp.sdc.common.util.ZipUtil;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/CheckAndUpdateJob.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/CheckAndUpdateJob.java
index dfc39042bd..ff1c21c7bd 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/CheckAndUpdateJob.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/CheckAndUpdateJob.java
@@ -20,7 +20,8 @@
package org.openecomp.sdc.be.model.cache.jobs;
-import fj.data.Either;
+import java.util.function.Function;
+
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -31,7 +32,7 @@ import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.function.Function;
+import fj.data.Either;
/**
* Created by mlando on 9/7/2016.
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/DeleteJob.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/DeleteJob.java
index ac1a56f9db..20dd4141f9 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/DeleteJob.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/DeleteJob.java
@@ -20,13 +20,9 @@
package org.openecomp.sdc.be.model.cache.jobs;
-import fj.data.Either;
-
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.cache.DaoInfo;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/Job.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/Job.java
index 198325b6b5..f701aaf661 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/Job.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/Job.java
@@ -20,8 +20,6 @@
package org.openecomp.sdc.be.model.cache.jobs;
-import fj.data.Either;
-
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.Component;
@@ -31,6 +29,8 @@ import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import fj.data.Either;
+
public abstract class Job<E> {
private static Logger log = LoggerFactory.getLogger(Job.class.getName());
protected DaoInfo daoInfo;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/OverrideJob.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/OverrideJob.java
index 47edae8968..641d125122 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/OverrideJob.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/jobs/OverrideJob.java
@@ -20,8 +20,6 @@
package org.openecomp.sdc.be.model.cache.jobs;
-import fj.data.Either;
-
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.cache.DaoInfo;
@@ -29,6 +27,8 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import fj.data.Either;
+
/**
* Created by mlando on 9/20/2016.
*/
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java
index 7d6ff49507..d29ade9c95 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java
@@ -20,15 +20,14 @@
package org.openecomp.sdc.be.model.cache.workers;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
import org.openecomp.sdc.be.model.cache.jobs.Job;
-import org.openecomp.sdc.be.model.cache.workers.IWorker;
import org.openecomp.sdc.be.workers.Worker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
/**
* Created by mlando on 9/6/2016. the class represents a worker the pull job
* from a queue and evacuates them.
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/SyncWorker.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/SyncWorker.java
index 824dd3496f..64cc1c8eea 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/SyncWorker.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/SyncWorker.java
@@ -20,7 +20,11 @@
package org.openecomp.sdc.be.model.cache.workers;
-import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
@@ -33,8 +37,7 @@ import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
-import java.util.stream.Collectors;
+import fj.data.Either;
/**
* the class creates a worker that is used to update cache date, in case of
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java
index 5fbeb4f808..7f02684825 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/heat/HeatParameterType.java
@@ -20,14 +20,12 @@
package org.openecomp.sdc.be.model.heat;
-import org.openecomp.sdc.be.model.tosca.converters.DefaultConverter;
import org.openecomp.sdc.be.model.tosca.converters.HeatBooleanConverter;
import org.openecomp.sdc.be.model.tosca.converters.HeatCommaDelimitedListConverter;
import org.openecomp.sdc.be.model.tosca.converters.HeatJsonConverter;
import org.openecomp.sdc.be.model.tosca.converters.HeatNumberConverter;
import org.openecomp.sdc.be.model.tosca.converters.HeatStringConverter;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
-import org.openecomp.sdc.be.model.tosca.converters.StringConvertor;
import org.openecomp.sdc.be.model.tosca.validators.HeatBooleanValidator;
import org.openecomp.sdc.be.model.tosca.validators.HeatCommaDelimitedListValidator;
import org.openecomp.sdc.be.model.tosca.validators.HeatNumberValidator;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java
index 07c2f8d51c..706007bdd7 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java
@@ -67,7 +67,11 @@ public class ArtifactsOperations extends BaseOperation {
public Either<ArtifactDefinition, StorageOperationStatus> addArifactToComponent(ArtifactDefinition artifactInfo, String parentId, NodeTypeEnum type, boolean failIfExist, String instanceId) {
- Either<ArtifactDataDefinition, StorageOperationStatus> status = updateArtifactOnGraph(parentId, artifactInfo, type, artifactInfo.getUniqueId(), instanceId, false);
+ String artifactId = artifactInfo.getUniqueId();
+ if (artifactId == null && artifactInfo.getEsId()!=null) {
+ artifactId = artifactInfo.getEsId();
+ }
+ Either<ArtifactDataDefinition, StorageOperationStatus> status = updateArtifactOnGraph(parentId, artifactInfo, type, artifactId, instanceId, false, false);
if (status.isRight()) {
log.debug("Failed to update artifact {} of {} {}. status is {}", artifactInfo.getArtifactName(), type.getName(), parentId, status.right().value());
@@ -86,7 +90,7 @@ public class ArtifactsOperations extends BaseOperation {
public Either<ArtifactDefinition, StorageOperationStatus> updateArifactOnResource(ArtifactDefinition artifactInfo, String id, String artifactId, NodeTypeEnum type, String instanceId) {
- Either<ArtifactDataDefinition, StorageOperationStatus> status = updateArtifactOnGraph(id, artifactInfo, type, artifactId, instanceId, true);
+ Either<ArtifactDataDefinition, StorageOperationStatus> status = updateArtifactOnGraph(id, artifactInfo, type, artifactId, instanceId, true, false);
if (status.isRight()) {
log.debug("Failed to update artifact {} of {} {}. status is {}", artifactInfo.getArtifactName(), type.getName(), id, status.right().value());
@@ -269,8 +273,6 @@ public class ArtifactsOperations extends BaseOperation {
} else {
updateVersionAndDate(artifactData, oldVesrion);
}
- long time = System.currentTimeMillis();
- artifactData.setHeatParamsUpdateDate(time);
break;
case HEAT:
case HEAT_NET:
@@ -481,7 +483,7 @@ public class ArtifactsOperations extends BaseOperation {
}
- public Either<ArtifactDataDefinition, StorageOperationStatus> updateArtifactOnGraph(String componentId, ArtifactDefinition artifactInfo, NodeTypeEnum type, String artifactId, String instanceId, boolean isUpdate) {
+ public Either<ArtifactDataDefinition, StorageOperationStatus> updateArtifactOnGraph(String componentId, ArtifactDefinition artifactInfo, NodeTypeEnum type, String artifactId, String instanceId, boolean isUpdate, boolean isDeletePlaceholder) {
Either<ArtifactDataDefinition, StorageOperationStatus> res = null;
ArtifactDataDefinition artifactToUpdate = new ArtifactDataDefinition(artifactInfo);
ArtifactGroupTypeEnum groupType = artifactInfo.getArtifactGroupType();
@@ -506,7 +508,8 @@ public class ArtifactsOperations extends BaseOperation {
uniqueId = UniqueIdBuilder.buildPropertyUniqueId(instanceId, artifactToUpdate.getArtifactLabel());
}
artifactToUpdate.setUniqueId(uniqueId);
- artifactToUpdate.setEsId(uniqueId);
+ if(!isDeletePlaceholder)
+ artifactToUpdate.setEsId(uniqueId);
} else
artifactToUpdate.setUniqueId(artifactId);
@@ -552,7 +555,8 @@ public class ArtifactsOperations extends BaseOperation {
String id = type != NodeTypeEnum.ResourceInstance ? componentId : instanceId;
String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(id, artifactToUpdate.getArtifactLabel());
artifactToUpdate.setUniqueId(uniqueId);
- artifactToUpdate.setEsId(uniqueId);
+ if(!isDeletePlaceholder)
+ artifactToUpdate.setEsId(uniqueId);
artifactToUpdate.setDuplicated(Boolean.FALSE);
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java
index 79360f6e10..537198d395 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java
@@ -25,7 +25,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -90,6 +89,9 @@ public abstract class BaseOperation {
@Autowired
protected TopologyTemplateOperation topologyTemplateOperation;
+ public void setTitanDao(TitanDao titanDao) {
+ this.titanDao = titanDao;
+ }
/**
* Returns reference to appropriate toscaTemplateOperation
*
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ByToscaNameDerivedNodeTypeResolver.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ByToscaNameDerivedNodeTypeResolver.java
index 1afb43c132..5e5ee63a59 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ByToscaNameDerivedNodeTypeResolver.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ByToscaNameDerivedNodeTypeResolver.java
@@ -20,7 +20,10 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
-import fj.data.Either;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
@@ -32,9 +35,7 @@ import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import fj.data.Either;
@Component("derived-resource-resolver")
public class ByToscaNameDerivedNodeTypeResolver implements DerivedNodeTypeResolver {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/GroupsOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/GroupsOperation.java
index f7e4245492..87053ff454 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/GroupsOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/GroupsOperation.java
@@ -20,7 +20,12 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
-import fj.data.Either;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
@@ -46,11 +51,7 @@ import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
+import fj.data.Either;
@org.springframework.stereotype.Component("groups-operation")
public class GroupsOperation extends BaseOperation {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java
index 7ff42ae42e..f59f097bdb 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
import java.util.ArrayList;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -30,6 +31,8 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
+import java.util.function.BiConsumer;
+import java.util.function.BiPredicate;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
@@ -59,21 +62,27 @@ import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapListCapabiltyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RelationshipInstDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupInstance;
import org.openecomp.sdc.be.model.RelationshipImpl;
-import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
+import org.openecomp.sdc.be.model.RelationshipInfo;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
@@ -138,6 +147,7 @@ public class NodeTemplateOperation extends BaseOperation {
}
if (result == null) {
+
newInstanceNameRes = buildValidateInstanceName(container, originToscaElement, componentInstance, instanceNumberSuffix);
if (newInstanceNameRes.isRight()) {
result = Either.right(newInstanceNameRes.right().value());
@@ -155,6 +165,14 @@ public class NodeTemplateOperation extends BaseOperation {
}
result = Either.right(status);
}
+ if(componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy){
+ TopologyTemplate updatedContainer = addComponentInstanceRes.left().value();
+ result = addServerCapAndReqToProxyServerInstance(
+ updatedContainer, componentInstance, componentInstanceData);
+
+
+
+ }
}
if (result == null) {
result = Either.left(new ImmutablePair<>(addComponentInstanceRes.left().value(), componentInstanceData.getUniqueId()));
@@ -162,11 +180,130 @@ public class NodeTemplateOperation extends BaseOperation {
return result;
}
+ private Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> addServerCapAndReqToProxyServerInstance(TopologyTemplate updatedContainer, ComponentInstance componentInstance,
+
+ ComponentInstanceDataDefinition componentInstanceData) {
+
+ Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> result;
+
+
+ Map<String, MapListCapabiltyDataDefinition> calcCap = updatedContainer.getCalculatedCapabilities();
+ Map<String, MapListRequirementDataDefinition> calcReg = updatedContainer.getCalculatedRequirements();
+ Map<String, MapCapabiltyProperty> calcCapProp = updatedContainer.getCalculatedCapabilitiesProperties();
+
+
+ Map<String, List<CapabilityDefinition>> additionalCap = componentInstance.getCapabilities();
+ Map<String, List<RequirementDefinition>> additionalReq = componentInstance.getRequirements();
+
+ MapListCapabiltyDataDefinition allCalculatedCap = calcCap==null ||!calcCap.containsKey(componentInstanceData.getUniqueId())?new MapListCapabiltyDataDefinition() :calcCap.get(componentInstanceData.getUniqueId());
+ /********capability****************************/
+ StorageOperationStatus status = deleteToscaDataDeepElementsBlockToToscaElement(updatedContainer.getUniqueId(), EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, componentInstanceData.getUniqueId());
+ if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to remove calculated capabilty for instance {} in container {}. error {] ", componentInstanceData.getUniqueId(), updatedContainer.getUniqueId(), status);
+ return Either.right(status);
+ }
+
+ if(additionalCap != null && !additionalCap.isEmpty()){
+
+ Map<String, ListCapabilityDataDefinition> serverCap = additionalCap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, en -> new ListCapabilityDataDefinition(en.getValue().stream().map(iCap -> new CapabilityDataDefinition(iCap)).collect(Collectors.toList()))));
+
+ serverCap.entrySet().forEach(entryPerType -> {
+ entryPerType.getValue().getListToscaDataDefinition().forEach(cap -> {
+ cap.addToPath(componentInstance.getUniqueId());
+ allCalculatedCap.add(entryPerType.getKey(), cap);
+ });
+ });
+
+ status = addToscaDataDeepElementsBlockToToscaElement(updatedContainer.getUniqueId(), EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, allCalculatedCap,
+ componentInstance.getUniqueId());
+
+ /********capability property****************************/
+ status = deleteToscaDataDeepElementsBlockToToscaElement(updatedContainer.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, componentInstanceData.getUniqueId());
+ if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to remove calculated capabilty properties for instance {} in container {}. error {] ", componentInstanceData.getUniqueId(), updatedContainer.getUniqueId(), status);
+ return Either.right(status);
+ }
+
+
+ MapCapabiltyProperty allCalculatedCapProp = calcCapProp==null ||!calcCapProp.containsKey(componentInstanceData.getUniqueId())?new MapCapabiltyProperty() :calcCapProp.get(componentInstanceData.getUniqueId());
+
+
+ additionalCap.forEach(new BiConsumer<String, List<CapabilityDefinition>>() {
+ @Override
+ public void accept(String s, List<CapabilityDefinition> caps) {
+
+ if (caps != null && !caps.isEmpty()) {
+
+ MapPropertiesDataDefinition dataToCreate = new MapPropertiesDataDefinition();
+
+ for (CapabilityDefinition cap : caps) {
+ List<ComponentInstanceProperty> capPrps = cap.getProperties();
+ if (capPrps != null) {
+
+ for (ComponentInstanceProperty cip : capPrps) {
+ dataToCreate.put(cip.getName(), new PropertyDataDefinition(cip));
+ }
+
+
+ StringBuffer sb = new StringBuffer(componentInstance.getUniqueId());
+ sb.append(ModelConverter.CAP_PROP_DELIM);
+
+ sb.append(cap.getOwnerId());
+
+ sb.append(ModelConverter.CAP_PROP_DELIM).append(s).append(ModelConverter.CAP_PROP_DELIM).append(cap.getName());
+ allCalculatedCapProp.put(sb.toString(), dataToCreate);
+ }
+ }
+
+ }
+
+ }
+ });
+
+ status = addToscaDataDeepElementsBlockToToscaElement(updatedContainer.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, allCalculatedCapProp,
+ componentInstance.getUniqueId());
+ }
+
+ /********Requirements property****************************/
+ if(additionalReq != null && !additionalReq.isEmpty()){
+
+ MapListRequirementDataDefinition allCalculatedReq = calcReg==null ||!calcReg.containsKey(componentInstanceData.getUniqueId())?new MapListRequirementDataDefinition() :calcReg.get(componentInstanceData.getUniqueId());
+ status = deleteToscaDataDeepElementsBlockToToscaElement(updatedContainer.getUniqueId(), EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, componentInstanceData.getUniqueId());
+ if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to remove calculated Requirements for instance {} in container {}. error {] ", componentInstanceData.getUniqueId(), updatedContainer.getUniqueId(), status);
+ return Either.right(status);
+ }
+
+ Map<String, ListRequirementDataDefinition> serverReq = additionalReq.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, en -> new ListRequirementDataDefinition(en.getValue().stream().map(iCap -> new RequirementDataDefinition(iCap)).collect(Collectors.toList()))));
+
+ serverReq.entrySet().forEach(entryPerType -> {
+ entryPerType.getValue().getListToscaDataDefinition().forEach(cap -> {
+ cap.addToPath(componentInstance.getUniqueId());
+ allCalculatedReq.add(entryPerType.getKey(), cap);
+ });
+ });
+
+ status = addToscaDataDeepElementsBlockToToscaElement(updatedContainer.getUniqueId(), EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, allCalculatedReq,
+ componentInstance.getUniqueId());
+
+ }
+
+
+ Either<ToscaElement, StorageOperationStatus> updatedComponentInstanceRes = topologyTemplateOperation.getToscaElement(updatedContainer.getUniqueId());
+ if (updatedComponentInstanceRes.isRight()) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch updated topology template {} with new component instance {}. ", updatedContainer.getName(), componentInstance.getName());
+ result = Either.right(updatedComponentInstanceRes.right().value());
+ }
+ result = Either.left(new ImmutablePair<>((TopologyTemplate)updatedComponentInstanceRes.left().value(), componentInstanceData.getUniqueId()));
+ return result;
+ }
+
+
private Either<String, StorageOperationStatus> buildValidateInstanceName(TopologyTemplate container, ToscaElement originToscaElement, ComponentInstance componentInstance, String instanceNumberSuffix) {
Either<String, StorageOperationStatus> result = null;
String instanceName = componentInstance.getName();
- if (StringUtils.isEmpty(instanceName) || instanceName.equalsIgnoreCase(originToscaElement.getName())) {
+ if (StringUtils.isEmpty(instanceName) || instanceName.equalsIgnoreCase(originToscaElement.getName()) || componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) {
instanceName = buildComponentInstanceName(instanceNumberSuffix, instanceName);
} else if (!isUniqueInstanceName(container, componentInstance.getName())) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to create component instance with name {} on component container {}. The instance with the same name already exists. ", componentInstance.getName(), container.getName());
@@ -265,7 +402,7 @@ public class NodeTemplateOperation extends BaseOperation {
return result;
}
- public Either<TopologyTemplate, StorageOperationStatus> updateComponentInstanceMetadataOfTopologyTemplate(TopologyTemplate container) {
+ public Either<TopologyTemplate, StorageOperationStatus> updateComponentInstanceMetadataOfTopologyTemplate(TopologyTemplate container, ComponentParametersView filter) {
Either<TopologyTemplate, StorageOperationStatus> result = null;
Either<ToscaElement, StorageOperationStatus> updateContainerComponentRes = null;
@@ -291,7 +428,7 @@ public class NodeTemplateOperation extends BaseOperation {
}
}
if (result == null) {
- updateContainerComponentRes = topologyTemplateOperation.getToscaElement(containerComponentId);
+ updateContainerComponentRes = topologyTemplateOperation.getToscaElement(containerComponentId, filter);
if (updateContainerComponentRes.isRight()) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch updated topology template {}. ", container.getName());
result = Either.right(updateContainerComponentRes.right().value());
@@ -368,8 +505,8 @@ public class NodeTemplateOperation extends BaseOperation {
Map<String, MapListCapabiltyDataDefinition> calculatedCapabilty = capResult.left().value().getRight();
Either<Pair<GraphVertex, Map<String, MapListCapabiltyDataDefinition>>, StorageOperationStatus> capFullResult = fetchContainerCalculatedCapability(containerV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
- if (capResult.isRight()) {
- return capResult.right().value();
+ if (capFullResult.isRight()) {
+ return capFullResult.right().value();
}
Map<String, MapListCapabiltyDataDefinition> fullFilledCapabilty = capFullResult.left().value().getRight();
@@ -393,12 +530,12 @@ public class NodeTemplateOperation extends BaseOperation {
if (relationToDelete.getFromId().equals(ciToRemove) || relationToDelete.getToId().equals(ciToRemove)) {
iterator.remove();
if (relationToDelete.getFromId().equals(ciToRemove)) {
- updateCalculatedRequirementsAfterDeleteRelation(calculatedRequirement, fullfilledRequirement, ciToRemove, relationToDelete);
- updateCalculatedCapabiltyAfterDeleteRelation(calculatedCapabilty, fullFilledCapabilty, relationToDelete.getToId(), relationToDelete);
+ updateCalculatedRequirementsAfterDeleteRelation(calculatedRequirement, fullfilledRequirement, ciToRemove, relationToDelete, null);
+ updateCalculatedCapabiltyAfterDeleteRelation(calculatedCapabilty, fullFilledCapabilty, relationToDelete.getToId(), relationToDelete, null);
}
if (relationToDelete.getToId().equals(ciToRemove)) {
- updateCalculatedRequirementsAfterDeleteRelation(calculatedRequirement, fullfilledRequirement, relationToDelete.getFromId(), relationToDelete);
- updateCalculatedCapabiltyAfterDeleteRelation(calculatedCapabilty, fullFilledCapabilty, ciToRemove, relationToDelete);
+ updateCalculatedRequirementsAfterDeleteRelation(calculatedRequirement, fullfilledRequirement, relationToDelete.getFromId(), relationToDelete, null);
+ updateCalculatedCapabiltyAfterDeleteRelation(calculatedCapabilty, fullFilledCapabilty, ciToRemove, relationToDelete, null);
}
}
}
@@ -594,14 +731,14 @@ public class NodeTemplateOperation extends BaseOperation {
if (status != StorageOperationStatus.OK) {
return status;
}
-
+
return addCalculatedCapReqFromNodeType(originNodeType, componentInstance, updatedContainerVertex);
}
public MapArtifactDataDefinition prepareInstDeploymentArtifactPerInstance(Map<String, ArtifactDataDefinition> deploymentArtifacts, String componentInstanceId, User user, String envType) {
if (deploymentArtifacts != null && envType.equals(HEAT_VF_ENV_NAME)) {
Map<String, ArtifactDataDefinition> instDeploymentArtifacts = new HashMap<>();
-
+
deploymentArtifacts.entrySet().forEach(e -> {
ArtifactDataDefinition artifact = e.getValue();
String type = artifact.getArtifactType();
@@ -610,10 +747,10 @@ public class NodeTemplateOperation extends BaseOperation {
instDeploymentArtifacts.put(artifactEnv.getArtifactLabel(), artifactEnv);
}
});
-
+
deploymentArtifacts.putAll(instDeploymentArtifacts);
MapArtifactDataDefinition instArtifacts = new MapArtifactDataDefinition(deploymentArtifacts);
-
+
return instArtifacts;
}
return null;
@@ -744,13 +881,21 @@ public class NodeTemplateOperation extends BaseOperation {
sb.append(ModelConverter.CAP_PROP_DELIM).append(instanceId).append(ModelConverter.CAP_PROP_DELIM).append(key);
return sb.toString();
}
-
+
+ /**
+ * Prepares a map of capabilities lists
+ * Produces a deep copy of the received map of capabilities
+ * Sets values to the specific fields according to received component instance
+ * @param capabilities
+ * @param componentInstance
+ * @return
+ */
public MapListCapabiltyDataDefinition prepareCalculatedCapabiltyForNodeType(Map<String, ListCapabilityDataDefinition> capabilities, ComponentInstanceDataDefinition componentInstance) {
if (capabilities != null) {
MapListCapabiltyDataDefinition allCalculatedCap = new MapListCapabiltyDataDefinition();
capabilities.entrySet().forEach(e -> {
- List<CapabilityDataDefinition> listCapabilities = e.getValue().getListToscaDataDefinition();
+ List<CapabilityDataDefinition> listCapabilities = e.getValue().getListToscaDataDefinition().stream().map(c -> new CapabilityDataDefinition(c)).collect(Collectors.toList());
listCapabilities.forEach(cap -> {
cap.setSource(componentInstance.getComponentUid());
cap.addToPath(componentInstance.getUniqueId());
@@ -765,13 +910,21 @@ public class NodeTemplateOperation extends BaseOperation {
return null;
}
+ /**
+ * Prepares a map of requirements lists
+ * Produces a deep copy of the received map of requirements
+ * Sets values to the specific fields according to received component instance
+ * @param requirements
+ * @param componentInstance
+ * @return
+ */
public MapListRequirementDataDefinition prepareCalculatedRequirementForNodeType(Map<String, ListRequirementDataDefinition> requirements, ComponentInstanceDataDefinition componentInstance) {
if (requirements != null) {
MapListRequirementDataDefinition allCalculatedReq = new MapListRequirementDataDefinition();
requirements.entrySet().forEach(e -> {
- List<RequirementDataDefinition> listCapabilities = e.getValue().getListToscaDataDefinition();
- listCapabilities.forEach(req -> {
+ List<RequirementDataDefinition> listRequirements = e.getValue().getListToscaDataDefinition().stream().map(r -> new RequirementDataDefinition(r)).collect(Collectors.toList());
+ listRequirements.forEach(req -> {
req.setSource(componentInstance.getComponentUid());
req.addToPath(componentInstance.getUniqueId());
req.setOwnerId(componentInstance.getUniqueId());
@@ -809,8 +962,6 @@ public class NodeTemplateOperation extends BaseOperation {
return result;
}
-
-
private ComponentInstanceDataDefinition buildComponentInstanceDataDefinition(ComponentInstance resourceInstance, String containerComponentId, String instanceNewName, boolean generateUid, ToscaElement originToscaElement) {
String ciOriginComponentUid = resourceInstance.getComponentUid();
@@ -845,7 +996,7 @@ public class NodeTemplateOperation extends BaseOperation {
dataDefinition.setComponentVersion((String) originToscaElement.getMetadataValue(JsonPresentationFields.VERSION));
if (StringUtils.isEmpty(dataDefinition.getComponentName()) && originToscaElement != null)
dataDefinition.setComponentName((String) originToscaElement.getMetadataValue(JsonPresentationFields.NAME));
- if (originToscaElement != null)
+ if (originToscaElement != null && dataDefinition.getToscaComponentName() == null)
dataDefinition.setToscaComponentName((String) originToscaElement.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
if (dataDefinition.getOriginType() == null && originToscaElement != null) {
ResourceTypeEnum resourceType = originToscaElement.getResourceType();
@@ -869,11 +1020,20 @@ public class NodeTemplateOperation extends BaseOperation {
case PNF:
originType = OriginTypeEnum.PNF;
break;
+ case ServiceProxy:
+ originType = OriginTypeEnum.ServiceProxy;
+ break;
+ case Configuration:
+ originType = OriginTypeEnum.Configuration;
+ break;
default:
break;
}
dataDefinition.setOriginType(originType);
}
+ if(dataDefinition.getOriginType() == OriginTypeEnum.ServiceProxy)
+ dataDefinition.setIsProxy(true);
+
return dataDefinition;
}
@@ -888,10 +1048,6 @@ public class NodeTemplateOperation extends BaseOperation {
return isUniqueName;
}
-
-
-
-
private String buildComponentInstanceName(String instanceSuffixNumber, String instanceName) {
return instanceName + " " + (instanceSuffixNumber == null ? 0 : instanceSuffixNumber);
}
@@ -907,7 +1063,7 @@ public class NodeTemplateOperation extends BaseOperation {
}
@SuppressWarnings({ "unchecked" })
- public Either<List<RequirementCapabilityRelDef>, StorageOperationStatus> associateResourceInstances(String componentId, List<RequirementCapabilityRelDef> relations) {
+ public <T extends ToscaDataDefinition> Either<List<RequirementCapabilityRelDef>, StorageOperationStatus> associateResourceInstances(String componentId, List<RequirementCapabilityRelDef> relations) {
Either<GraphVertex, TitanOperationStatus> containerVEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
if (containerVEither.isRight()) {
@@ -916,7 +1072,7 @@ public class NodeTemplateOperation extends BaseOperation {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(error));
}
GraphVertex containerV = containerVEither.left().value();
- List<RequirementAndRelationshipPair> relationshipsResult = new ArrayList<RequirementAndRelationshipPair>();
+ List<CapabilityRequirementRelationship> relationshipsResult = new ArrayList<>();
Either<Pair<GraphVertex, Map<String, MapListCapabiltyDataDefinition>>, StorageOperationStatus> capResult = fetchContainerCalculatedCapability(containerV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
if (capResult.isRight()) {
return Either.right(capResult.right().value());
@@ -952,17 +1108,17 @@ public class NodeTemplateOperation extends BaseOperation {
String fromNode = relation.getFromNode();
String toNode = relation.getToNode();
- List<RequirementAndRelationshipPair> relationships = relation.getRelationships();
+ List<CapabilityRequirementRelationship> relationships = relation.getRelationships();
if (relationships == null || relationships.isEmpty()) {
BeEcompErrorManager.getInstance().logBeFailedAddingResourceInstanceError("AssociateResourceInstances - missing relationship", fromNode, componentId);
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "No requirement definition sent in order to set the relation between {} to {}", fromNode, toNode);
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT));
}
- for (RequirementAndRelationshipPair immutablePair : relationships) {
- String requirement = immutablePair.getRequirement();
+ for (CapabilityRequirementRelationship immutablePair : relationships) {
+ String requirement = immutablePair.getRelation().getRequirement();
- Either<RelationshipInstDataDefinition, StorageOperationStatus> associateRes = connectInstancesInContainer(fromNode, toNode, immutablePair, calculatedCapabilty, calculatedRequirement, fullFilledCapabilty, fullfilledRequirement,
+ Either<Map<JsonPresentationFields, T>, StorageOperationStatus> associateRes = connectInstancesInContainer(fromNode, toNode, immutablePair.getRelation(), calculatedCapabilty, calculatedRequirement, fullFilledCapabilty, fullfilledRequirement,
compositionDataDefinition, containerV.getUniqueId());
if (associateRes.isRight()) {
@@ -972,16 +1128,22 @@ public class NodeTemplateOperation extends BaseOperation {
return Either.right(status);
}
- RelationshipInstDataDefinition relationshipInstData = associateRes.left().value();
+ RelationshipInstDataDefinition relationshipInstData = (RelationshipInstDataDefinition) associateRes.left().value().get(JsonPresentationFields.RELATIONSHIP);
RelationshipImpl relationshipImplResult = new RelationshipImpl();
relationshipImplResult.setType(relationshipInstData.getType());
- RequirementAndRelationshipPair requirementAndRelationshipPair = new RequirementAndRelationshipPair(requirement, relationshipImplResult);
- requirementAndRelationshipPair.setCapability(immutablePair.getCapability());
+ RelationshipInfo requirementAndRelationshipPair = new RelationshipInfo(requirement, relationshipImplResult);
+ requirementAndRelationshipPair.setCapability(immutablePair.getRelation().getCapability());
+ requirementAndRelationshipPair.setRequirement(immutablePair.getRelation().getRequirement());
requirementAndRelationshipPair.setCapabilityOwnerId(relationshipInstData.getCapabilityOwnerId());
requirementAndRelationshipPair.setRequirementOwnerId(relationshipInstData.getRequirementOwnerId());
- requirementAndRelationshipPair.setCapabilityUid(immutablePair.getCapabilityUid());
- requirementAndRelationshipPair.setRequirementUid(immutablePair.getRequirementUid());
- relationshipsResult.add(requirementAndRelationshipPair);
+ requirementAndRelationshipPair.setCapabilityUid(immutablePair.getRelation().getCapabilityUid());
+ requirementAndRelationshipPair.setRequirementUid(immutablePair.getRelation().getRequirementUid());
+ requirementAndRelationshipPair.setId(relationshipInstData.getUniqueId());
+ CapabilityRequirementRelationship capReqRel = new CapabilityRequirementRelationship();
+ capReqRel.setRelation(requirementAndRelationshipPair);
+ capReqRel.setCapability((CapabilityDataDefinition) associateRes.left().value().get(JsonPresentationFields.CAPAPILITY));
+ capReqRel.setRequirement((RequirementDataDefinition) associateRes.left().value().get(JsonPresentationFields.REQUIREMENT));
+ relationshipsResult.add(capReqRel);
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "update customization UUID for from CI {} and to CI {}", relation.getFromNode(), relation.getToNode());
status = updateCustomizationUUID(relation.getFromNode(), compositionDataDefinition);
if (status != StorageOperationStatus.OK) {
@@ -1088,7 +1250,7 @@ public class NodeTemplateOperation extends BaseOperation {
}
Map<String, RelationshipInstDataDefinition> relations = compositionDataDefinition.getRelations();
- List<RequirementAndRelationshipPair> relationPairList = requirementDef.getRelationships();
+ List<CapabilityRequirementRelationship> relationPairList = requirementDef.getRelationships();
Either<Pair<GraphVertex, Map<String, MapListCapabiltyDataDefinition>>, StorageOperationStatus> capResult = fetchContainerCalculatedCapability(containerV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
if (capResult.isRight()) {
return Either.right(capResult.right().value());
@@ -1114,24 +1276,24 @@ public class NodeTemplateOperation extends BaseOperation {
}
Map<String, MapListRequirementDataDefinition> fulfilledRequirement = reqFullResult.left().value().getRight();
- for (RequirementAndRelationshipPair relationPair : relationPairList) {
+ for (CapabilityRequirementRelationship relationPair : relationPairList) {
Iterator<Entry<String, RelationshipInstDataDefinition>> iterator = relations.entrySet().iterator();
boolean isDeleted = false;
while (iterator.hasNext()) {
Entry<String, RelationshipInstDataDefinition> entryInJson = iterator.next();
RelationshipInstDataDefinition relationInJson = entryInJson.getValue();
- if (relationInJson.getFromId().equals(fromResInstanceUid) && relationInJson.getToId().equals(toResInstanceUid)) {
- if (relationPair.equalsTo(relationInJson)) {
+ if (relationInJson.getFromId().equals(fromResInstanceUid) && relationInJson.getToId().equals(toResInstanceUid) && relationInJson.getUniqueId().equals(relationPair.getRelation().getId())) {
+ if (relationPair.getRelation().equalsTo(relationInJson)) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Remove relation from {} to {} capability {} capOwnerId {} reqOwnerId {} ", toResInstanceUid, componentId, relationInJson.getType(),
relationInJson.getCapabilityOwnerId(), relationInJson.getRequirementOwnerId());
iterator.remove();
// update calculated cap/req
- StorageOperationStatus status = updateCalculatedCapabiltyAfterDeleteRelation(calculatedCapability, fulfilledCapability, toResInstanceUid, relationInJson);
+ StorageOperationStatus status = updateCalculatedCapabiltyAfterDeleteRelation(calculatedCapability, fulfilledCapability, toResInstanceUid, relationInJson, relationPair);
if (status != StorageOperationStatus.OK) {
return Either.right(status);
}
- status = updateCalculatedRequirementsAfterDeleteRelation(calculatedRequirement, fulfilledRequirement, fromResInstanceUid, relationInJson);
+ status = updateCalculatedRequirementsAfterDeleteRelation(calculatedRequirement, fulfilledRequirement, fromResInstanceUid, relationInJson, relationPair);
if (status != StorageOperationStatus.OK) {
return Either.right(status);
}
@@ -1139,9 +1301,9 @@ public class NodeTemplateOperation extends BaseOperation {
}
}
}
- if (isDeleted == false) {
+ if (!isDeleted) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "No relation to delete from {} to {} capabilty {} capOwnerId {} reqOwnerId {} ", toResInstanceUid, componentId, relationPair.getCapability(),
- relationPair.getCapabilityOwnerId(), relationPair.getRequirementOwnerId());
+ relationPair.getRelation().getCapabilityOwnerId(), relationPair.getRelation().getRequirementOwnerId());
return Either.right(StorageOperationStatus.NOT_FOUND);
}
}
@@ -1163,15 +1325,108 @@ public class NodeTemplateOperation extends BaseOperation {
return Either.left(requirementDef);
}
+
+ /**
+ * Retrieves fulfilled requirement according to relation and received predicate
+ * @param componentId
+ * @param instanceId
+ * @param foundRelation
+ * @param predicate
+ * @return
+ */
+ public Either<RequirementDataDefinition, StorageOperationStatus> getFulfilledRequirementByRelation(String componentId, String instanceId, RequirementCapabilityRelDef foundRelation, BiPredicate<RelationshipInfo, RequirementDataDefinition> predicate) {
+
+ Either<RequirementDataDefinition, StorageOperationStatus> result = null;
+ Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> reqFullResult = null;
+ MapListRequirementDataDefinition reqMapOfLists = null;
+ Optional<RequirementDataDefinition> foundRequirement;
+ RelationshipInfo relationshipInfo = foundRelation.getSingleRelationship().getRelation();
+ Either<GraphVertex, TitanOperationStatus> containerVEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
+ if (containerVEither.isRight()) {
+ TitanOperationStatus error = containerVEither.right().value();
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch container vertex {} error {}", componentId, error);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(error));
+ }
+ if(result == null){
+ GraphVertex containerV = containerVEither.left().value();
+ reqFullResult = fetchContainerCalculatedRequirement(containerV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
+ if (reqFullResult.isRight()) {
+ result = Either.right(reqFullResult.right().value());
+ }
+ }
+ if(result == null){
+ Map<String, MapListRequirementDataDefinition> fulfilledRequirement = reqFullResult.left().value().getRight();
+ reqMapOfLists = fulfilledRequirement.get(instanceId);
+ if(reqMapOfLists == null){
+ result = Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ }
+ if(result == null && reqMapOfLists != null){
+ for(ListRequirementDataDefinition requirements : reqMapOfLists.getMapToscaDataDefinition().values()){
+ foundRequirement = requirements.getListToscaDataDefinition().stream().filter(req -> predicate.test(relationshipInfo, req)).findFirst();
+ if(foundRequirement.isPresent()){
+ result = Either.left(foundRequirement.get());
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Retrieves fulfilled capability according to relation and received predicate
+ * @param componentId
+ * @param instanceId
+ * @param foundRelation
+ * @param predicate
+ * @return
+ */
+ public Either<CapabilityDataDefinition, StorageOperationStatus> getFulfilledCapabilityByRelation(String componentId, String instanceId, RequirementCapabilityRelDef foundRelation, BiPredicate<RelationshipInfo, CapabilityDataDefinition> predicate) {
+
+ Either<CapabilityDataDefinition, StorageOperationStatus> result = null;
+ Either<Pair<GraphVertex, Map<String, MapListCapabiltyDataDefinition>>, StorageOperationStatus> capFullResult = null;
+ MapListCapabiltyDataDefinition capMapOfLists = null;
+ Optional<CapabilityDataDefinition> foundRequirement;
+
+ RelationshipInfo relationshipInfo = foundRelation.getSingleRelationship().getRelation();
+ Either<GraphVertex, TitanOperationStatus> containerVEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
+ if (containerVEither.isRight()) {
+ TitanOperationStatus error = containerVEither.right().value();
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch container vertex {} error {}", componentId, error);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(error));
+ }
+ if(result == null){
+ GraphVertex containerV = containerVEither.left().value();
+ capFullResult = fetchContainerCalculatedCapability(containerV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
+ if (capFullResult.isRight()) {
+ result = Either.right(capFullResult.right().value());
+ }
+ }
+ if(result == null){
+ Map<String, MapListCapabiltyDataDefinition> fulfilledCapability = capFullResult.left().value().getRight();
+ capMapOfLists = fulfilledCapability.get(instanceId);
+ if(capMapOfLists == null){
+ result = Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ }
+ if(result == null && capMapOfLists != null){
+ for(ListCapabilityDataDefinition capabilities : capMapOfLists.getMapToscaDataDefinition().values()){
+ foundRequirement = capabilities.getListToscaDataDefinition().stream().filter(cap -> predicate.test(relationshipInfo, cap)).findFirst();
+ if(foundRequirement.isPresent()){
+ result = Either.left(foundRequirement.get());
+ }
+ }
+ }
+ return result;
+ }
private StorageOperationStatus updateCalculatedRequirementsAfterDeleteRelation(Map<String, MapListRequirementDataDefinition> calculatedRequirement, Map<String, MapListRequirementDataDefinition> fullFilledRequirement, String fromResInstanceUid,
- RelationshipInstDataDefinition relation) {
+ RelationshipInstDataDefinition relation, CapabilityRequirementRelationship relationship) {
StorageOperationStatus status;
String hereIsTheKey = null;
MapListRequirementDataDefinition reqByInstance = calculatedRequirement.get(fromResInstanceUid);
if (reqByInstance == null || reqByInstance.findKeyByItemUidMatch(relation.getRequirementId()) == null) {
// move from fulfilled
- status = moveFromFullFilledRequirement(calculatedRequirement, fullFilledRequirement, fromResInstanceUid, relation, hereIsTheKey);
+ status = moveFromFullFilledRequirement(calculatedRequirement, fullFilledRequirement, fromResInstanceUid, relation, hereIsTheKey, relationship);
} else {
hereIsTheKey = reqByInstance.findKeyByItemUidMatch(relation.getRequirementId());
ListRequirementDataDefinition reqByType = reqByInstance.findByKey(hereIsTheKey);
@@ -1187,29 +1442,31 @@ public class NodeTemplateOperation extends BaseOperation {
++leftIntValue;
requirement.setLeftOccurrences(String.valueOf(leftIntValue));
}
+ if(relationship != null){
+ relationship.setRequirement(requirement);
+ }
status = StorageOperationStatus.OK;
} else {
// move from fulfilled
- status = moveFromFullFilledRequirement(calculatedRequirement, fullFilledRequirement, fromResInstanceUid, relation, hereIsTheKey);
+ status = moveFromFullFilledRequirement(calculatedRequirement, fullFilledRequirement, fromResInstanceUid, relation, hereIsTheKey, relationship);
}
}
return status;
}
-
private StorageOperationStatus updateCalculatedCapabiltyAfterDeleteRelation(Map<String, MapListCapabiltyDataDefinition> calculatedCapability, Map<String, MapListCapabiltyDataDefinition> fullFilledCapability, String toResInstanceUid,
- RelationshipInstDataDefinition relation) {
+ RelationshipInstDataDefinition relation, CapabilityRequirementRelationship relationship) {
StorageOperationStatus status;
String hereIsTheKey = null;
MapListCapabiltyDataDefinition capByInstance = calculatedCapability.get(toResInstanceUid);
if (capByInstance == null || capByInstance.findKeyByItemUidMatch(relation.getCapabilityId()) == null) {
// move from fulfilled
- status = moveFromFullFilledCapabilty(calculatedCapability, fullFilledCapability, toResInstanceUid, relation, hereIsTheKey);
+ status = moveFromFullFilledCapabilty(calculatedCapability, fullFilledCapability, toResInstanceUid, relation, hereIsTheKey, relationship);
} else {
hereIsTheKey = capByInstance.findKeyByItemUidMatch(relation.getCapabilityId());
ListCapabilityDataDefinition capByType = capByInstance.findByKey(hereIsTheKey);
- Optional<CapabilityDataDefinition> capabilityOptional = capByType.getListToscaDataDefinition().stream()
- .filter(cap -> cap.getOwnerId().equals(relation.getCapabilityOwnerId()) && cap.getUniqueId().equals(relation.getCapabilityId())).findFirst();
+ Optional<CapabilityDataDefinition> capabilityOptional = capByType.getListToscaDataDefinition().stream().filter(cap -> cap.getOwnerId().equals(relation.getCapabilityOwnerId()) && cap.getUniqueId().equals(relation.getCapabilityId()))
+ .findFirst();
if (capabilityOptional.isPresent()) {
@@ -1220,17 +1477,20 @@ public class NodeTemplateOperation extends BaseOperation {
++leftIntValue;
capability.setLeftOccurrences(String.valueOf(leftIntValue));
}
+ if(relationship != null){
+ relationship.setCapability(capability);
+ }
status = StorageOperationStatus.OK;
} else {
// move from fulfilled
- status = moveFromFullFilledCapabilty(calculatedCapability, fullFilledCapability, toResInstanceUid, relation, hereIsTheKey);
+ status = moveFromFullFilledCapabilty(calculatedCapability, fullFilledCapability, toResInstanceUid, relation, hereIsTheKey, relationship);
}
}
return status;
}
private StorageOperationStatus moveFromFullFilledCapabilty(Map<String, MapListCapabiltyDataDefinition> calculatedCapability, Map<String, MapListCapabiltyDataDefinition> fullFilledCapability, String toResInstanceUid,
- RelationshipInstDataDefinition relation, String hereIsTheKey) {
+ RelationshipInstDataDefinition relation, String hereIsTheKey, CapabilityRequirementRelationship relationship) {
MapListCapabiltyDataDefinition capByInstance = fullFilledCapability.get(toResInstanceUid);
if (capByInstance == null) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "No capability in fulfilled list for instance {} ", toResInstanceUid);
@@ -1266,6 +1526,7 @@ public class NodeTemplateOperation extends BaseOperation {
mapListCapaDataDef.put(hereIsTheKey, findByKey);
}
findByKey.add(cap);
+ relationship.setCapability(cap);
break;
}
}
@@ -1277,13 +1538,13 @@ public class NodeTemplateOperation extends BaseOperation {
}
private StorageOperationStatus moveFromFullFilledRequirement(Map<String, MapListRequirementDataDefinition> calculatedRequirement, Map<String, MapListRequirementDataDefinition> fullFilledRequirement, String fromResInstanceUid,
- RelationshipInstDataDefinition relation, String hereIsTheKey) {
+ RelationshipInstDataDefinition relation, String hereIsTheKey, CapabilityRequirementRelationship relationship) {
MapListRequirementDataDefinition reqByInstance = fullFilledRequirement.get(fromResInstanceUid);
if (reqByInstance == null) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "No requirement in fullfilled list for instance {} ", fromResInstanceUid);
return StorageOperationStatus.GENERAL_ERROR;
}
- if(null == hereIsTheKey)
+ if (null == hereIsTheKey)
hereIsTheKey = reqByInstance.findKeyByItemUidMatch(relation.getRequirementId());
if (null == hereIsTheKey) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "No requirement with id {} in fulfilled list for instance {} ", relation.getRequirementId(), fromResInstanceUid);
@@ -1313,6 +1574,7 @@ public class NodeTemplateOperation extends BaseOperation {
mapListReqDataDef.put(hereIsTheKey, findByKey);
}
findByKey.add(req);
+ relationship.setRequirement(req);
break;
}
}
@@ -1337,7 +1599,7 @@ public class NodeTemplateOperation extends BaseOperation {
return StorageOperationStatus.OK;
}
- public Either<RelationshipInstDataDefinition, StorageOperationStatus> connectInstancesInContainer(String fromResInstanceUid, String toResInstanceUid, RequirementAndRelationshipPair relationPair,
+ public <T extends ToscaDataDefinition> Either<Map<JsonPresentationFields, T>, StorageOperationStatus> connectInstancesInContainer(String fromResInstanceUid, String toResInstanceUid, RelationshipInfo relationPair,
Map<String, MapListCapabiltyDataDefinition> calculatedCapabilty, Map<String, MapListRequirementDataDefinition> calculatedRequirement, Map<String, MapListCapabiltyDataDefinition> fullfilledCapabilty,
Map<String, MapListRequirementDataDefinition> fullfilledRequirement, CompositionDataDefinition compositionDataDefinition, String containerId) {
String requirement = relationPair.getRequirement();
@@ -1356,19 +1618,19 @@ public class NodeTemplateOperation extends BaseOperation {
return Either.right(StorageOperationStatus.NOT_FOUND);
}
- Either<RelationshipInstDataDefinition, StorageOperationStatus> reqVsCap = connectRequirementVsCapability(fromResourceInstData, toResourceInstData, relationPair, calculatedCapabilty, calculatedRequirement, fullfilledCapabilty,
+ Either<Map<JsonPresentationFields, T>, StorageOperationStatus> reqVsCap = connectRequirementVsCapability(fromResourceInstData, toResourceInstData, relationPair, calculatedCapabilty, calculatedRequirement, fullfilledCapabilty,
fullfilledRequirement, containerId);
if (reqVsCap.isRight()) {
StorageOperationStatus status = reqVsCap.right().value();
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to connect requirement {} between resource instance {} to resource instance {}. status is {}", requirement, fromResInstanceUid, toResInstanceUid, status);
return Either.right(status);
}
- RelationshipInstDataDefinition relation = reqVsCap.left().value();
+ Map<JsonPresentationFields, T> relationship = reqVsCap.left().value();
// add to json new relations
- compositionDataDefinition.addRelation(relation.getUniqueId(), relation);
+ compositionDataDefinition.addRelation(((RelationshipInstDataDefinition)relationship.get(JsonPresentationFields.RELATIONSHIP)).getUniqueId(), (RelationshipInstDataDefinition)relationship.get(JsonPresentationFields.RELATIONSHIP));
- return Either.left(relation);
+ return Either.left(relationship);
}
private Either<Pair<GraphVertex, Map<String, MapListCapabiltyDataDefinition>>, StorageOperationStatus> fetchContainerCalculatedCapability(GraphVertex containerV, EdgeLabelEnum capLabel) {
@@ -1394,7 +1656,8 @@ public class NodeTemplateOperation extends BaseOperation {
return Either.left(calculatedRequirement);
}
- private Either<RelationshipInstDataDefinition, StorageOperationStatus> connectRequirementVsCapability(ComponentInstanceDataDefinition fromResInstance, ComponentInstanceDataDefinition toResInstance, RequirementAndRelationshipPair relationPair,
+ @SuppressWarnings("unchecked")
+ private <T extends ToscaDataDefinition> Either<Map<JsonPresentationFields, T>, StorageOperationStatus> connectRequirementVsCapability(ComponentInstanceDataDefinition fromResInstance, ComponentInstanceDataDefinition toResInstance, RelationshipInfo relationPair,
Map<String, MapListCapabiltyDataDefinition> calculatedCapabilty, Map<String, MapListRequirementDataDefinition> calculatedRequirement, Map<String, MapListCapabiltyDataDefinition> fullfilledCapabilty,
Map<String, MapListRequirementDataDefinition> fullfilledRequirement, String containerId) {
String type = relationPair.getRelationship().getType();
@@ -1402,6 +1665,7 @@ public class NodeTemplateOperation extends BaseOperation {
String toInstId = toResInstance.getUniqueId();
MapListCapabiltyDataDefinition mapListCapabiltyDataDefinition = calculatedCapabilty.get(toInstId);
+ Map<JsonPresentationFields, T> capReqRelationship = new EnumMap<>(JsonPresentationFields.class);
if (mapListCapabiltyDataDefinition == null) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch calculated capabilities for instance {} in container {}.", toInstId, containerId);
@@ -1418,6 +1682,7 @@ public class NodeTemplateOperation extends BaseOperation {
CapabilityDataDefinition cap = iteratorCap.next();
if (cap.getUniqueId().equals(relationPair.getCapabilityUid()) && cap.getOwnerId().equals(relationPair.getCapabilityOwnerId())) {
capabilityForRelation = cap;
+ capReqRelationship.put(JsonPresentationFields.CAPAPILITY, (T)capabilityForRelation);
String leftOccurrences = cap.getLeftOccurrences();
if (leftOccurrences != null && !leftOccurrences.equals(CapabilityDataDefinition.MAX_OCCURRENCES)) {
Integer leftIntValue = Integer.parseInt(leftOccurrences);
@@ -1473,7 +1738,7 @@ public class NodeTemplateOperation extends BaseOperation {
RequirementDataDefinition req = iteratorReq.next();
if (req.getUniqueId().equals(relationPair.getRequirementUid()) && req.getOwnerId().equals(relationPair.getRequirementOwnerId())) {
requirementForRelation = req;
-
+ capReqRelationship.put(JsonPresentationFields.REQUIREMENT, (T)requirementForRelation);
String leftOccurrences = req.getLeftOccurrences();
if (leftOccurrences != null && !leftOccurrences.equals(RequirementDataDefinition.MAX_OCCURRENCES)) {
Integer leftIntValue = Integer.parseInt(leftOccurrences);
@@ -1506,17 +1771,19 @@ public class NodeTemplateOperation extends BaseOperation {
}
}
if (!capabilityForRelation.getType().equals(requirementForRelation.getCapability())) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "No math for capability from type {} and requirement {} from {} to {} in container {}.", capabilityForRelation.getType(), requirementForRelation.getCapability(), fromInstId, toInstId,
- containerId);
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "No math for capability from type {} and requirement {} from {} to {} in container {}.", capabilityForRelation.getType(), requirementForRelation.getCapability(), fromInstId,
+ toInstId, containerId);
return Either.right(StorageOperationStatus.MATCH_NOT_FOUND);
}
RelationshipInstDataDefinition relationshipTypeData = buildRelationshipInstData(fromInstId, toInstId, relationPair);
- relationshipTypeData.setType(requirementForRelation.getRelationship());
- return Either.left(relationshipTypeData);
+ if(requirementForRelation.getRelationship() != null)
+ relationshipTypeData.setType(requirementForRelation.getRelationship());
+ capReqRelationship.put(JsonPresentationFields.RELATIONSHIP, (T)relationshipTypeData);
+ return Either.left(capReqRelationship);
}
- private RelationshipInstDataDefinition buildRelationshipInstData(String fromResInstanceUid, String toInstId, RequirementAndRelationshipPair relationPair) {
+ private RelationshipInstDataDefinition buildRelationshipInstData(String fromResInstanceUid, String toInstId, RelationshipInfo relationPair) {
RelationshipInstDataDefinition relationshipInstData = new RelationshipInstDataDefinition();
relationshipInstData.setUniqueId(UniqueIdBuilder.buildRelationsipInstInstanceUid(fromResInstanceUid, toInstId));
@@ -1620,13 +1887,13 @@ public class NodeTemplateOperation extends BaseOperation {
}
public StorageOperationStatus addDeploymentArtifactsToInstance(String toscaElementId, String instanceId, Map<String, ArtifactDataDefinition> instDeplArtifacts) {
- return addArtifactsToInstance(toscaElementId, instanceId, instDeplArtifacts, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS);
+ return addArtifactsToInstance(toscaElementId, instanceId, instDeplArtifacts, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS);
}
-
+
public StorageOperationStatus addInformationalArtifactsToInstance(String toscaElementId, String instanceId, Map<String, ArtifactDataDefinition> instDeplArtifacts) {
- return addArtifactsToInstance(toscaElementId, instanceId, instDeplArtifacts, EdgeLabelEnum.INSTANCE_ARTIFACTS, VertexTypeEnum.INSTANCE_ARTIFACTS);
+ return addArtifactsToInstance(toscaElementId, instanceId, instDeplArtifacts, EdgeLabelEnum.INSTANCE_ARTIFACTS, VertexTypeEnum.INSTANCE_ARTIFACTS);
}
-
+
public StorageOperationStatus addArtifactsToInstance(String toscaElementId, String instanceId, Map<String, ArtifactDataDefinition> instDeplArtifacts, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexType) {
Either<GraphVertex, TitanOperationStatus> metadataVertex = titanDao.getVertexById(toscaElementId, JsonParseFlagEnum.NoParse);
if (metadataVertex.isRight()) {
@@ -1637,7 +1904,7 @@ public class NodeTemplateOperation extends BaseOperation {
return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
}
MapArtifactDataDefinition instArtifacts = new MapArtifactDataDefinition(instDeplArtifacts);
- return addToscaDataDeepElementsBlockToToscaElement(metadataVertex.left().value(),edgeLabel, vertexType, instArtifacts, instanceId);
+ return addToscaDataDeepElementsBlockToToscaElement(metadataVertex.left().value(), edgeLabel, vertexType, instArtifacts, instanceId);
}
@@ -1710,14 +1977,26 @@ public class NodeTemplateOperation extends BaseOperation {
pathKeys.add(componentInstanceId);
return updateToscaDataDeepElementOfToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, property, pathKeys, JsonPresentationFields.NAME);
}
-
-
+
+ public StorageOperationStatus updateComponentInstanceCapabilityProperty(Component containerComponent, String componentInstanceId, String capabilityUniqueId, ComponentInstanceProperty property) {
+ List<String> pathKeys = new ArrayList<>();
+ pathKeys.add(componentInstanceId);
+ pathKeys.add(capabilityUniqueId);
+ return updateToscaDataDeepElementOfToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, property, pathKeys, JsonPresentationFields.NAME);
+ }
+
public StorageOperationStatus addComponentInstanceProperty(Component containerComponent, String componentInstanceId, ComponentInstanceProperty property) {
List<String> pathKeys = new ArrayList<>();
pathKeys.add(componentInstanceId);
return addToscaDataDeepElementToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, property, pathKeys, JsonPresentationFields.NAME);
}
+ public StorageOperationStatus updateComponentInstanceProperties(Component containerComponent, String componentInstanceId, List<ComponentInstanceProperty> properties) {
+ List<String> pathKeys = new ArrayList<>();
+ pathKeys.add(componentInstanceId);
+ return updateToscaDataDeepElementsOfToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, properties, pathKeys, JsonPresentationFields.NAME);
+ }
+
public StorageOperationStatus updateComponentInstanceInput(Component containerComponent, String componentInstanceId, ComponentInstanceInput property) {
List<String> pathKeys = new ArrayList<>();
@@ -1725,11 +2004,16 @@ public class NodeTemplateOperation extends BaseOperation {
return updateToscaDataDeepElementOfToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, property, pathKeys, JsonPresentationFields.NAME);
}
+ public StorageOperationStatus updateComponentInstanceInputs(Component containerComponent, String componentInstanceId, List<ComponentInstanceInput> properties) {
+ List<String> pathKeys = new ArrayList<>();
+ pathKeys.add(componentInstanceId);
+ return updateToscaDataDeepElementsOfToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, properties, pathKeys, JsonPresentationFields.NAME);
+ }
+
public StorageOperationStatus addComponentInstanceInput(Component containerComponent, String componentInstanceId, ComponentInstanceInput property) {
List<String> pathKeys = new ArrayList<>();
pathKeys.add(componentInstanceId);
return addToscaDataDeepElementToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, property, pathKeys, JsonPresentationFields.NAME);
}
-
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java
index e530144fe0..d46743cfa9 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java
@@ -20,7 +20,15 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
-import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.tinkerpop.gremlin.structure.Direction;
@@ -54,16 +62,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
+import fj.data.Either;
@org.springframework.stereotype.Component("node-type-operation")
public class NodeTypeOperation extends ToscaElementOperation {
@@ -472,20 +471,27 @@ public class NodeTypeOperation extends ToscaElementOperation {
});
ToscaDataDefinition.mergeDataMaps(capabiltiesAll, capabilties);
+ capabiltiesAll.values().forEach(l -> {
+ l.getListToscaDataDefinition().forEach(c -> {
+ List<String> capabilitySources = c.getCapabilitySources();
+ if (capabilitySources == null) {
+ capabilitySources = new ArrayList<>();
+ }
+ capabilitySources.add((String) nodeType.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
+ c.setCapabilitySources(capabilitySources);
+ });
+ });
}
-
capabiltiesAll.values().forEach(l -> {
- l.getListToscaDataDefinition().forEach(c -> {
- List<String> capabilitySources = c.getCapabilitySources();
- if ( capabilitySources == null ){
- capabilitySources = new ArrayList<>();
- }
- capabilitySources.add((String) nodeType.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
- c.setCapabilitySources(capabilitySources);
- });
- });
-
-
+ l.getListToscaDataDefinition().forEach(c -> {
+ List<String> capabilitySources = c.getCapabilitySources();
+ if (capabilitySources == null) {
+ capabilitySources = new ArrayList<>();
+ }
+ capabilitySources.add((String) nodeType.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
+ c.setCapabilitySources(capabilitySources);
+ });
+ });
if (!capabiltiesAll.isEmpty()) {
Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILTIES, EdgeLabelEnum.CAPABILITIES, capabiltiesAll);
if (assosiateElementToData.isRight()) {
@@ -514,7 +520,7 @@ public class NodeTypeOperation extends ToscaElementOperation {
p.setUniqueId(uid);
});
});
-
+
ToscaDataDefinition.mergeDataMaps(requirementsAll, requirements);
}
@@ -615,27 +621,25 @@ public class NodeTypeOperation extends ToscaElementOperation {
}
return Either.left(derivedResources);
}
-
- Either<List<GraphVertex>, StorageOperationStatus> handleMultipleParent(String parentResource, List<GraphVertex> derivedResource, List<GraphVertex> fetchedDerivedResources){
-
+
+ Either<List<GraphVertex>, StorageOperationStatus> handleMultipleParent(String parentResource, List<GraphVertex> derivedResource, List<GraphVertex> fetchedDerivedResources) {
+
Either<List<GraphVertex>, StorageOperationStatus> result = Either.left(derivedResource);
- try{
- fetchedDerivedResources.sort((d1,d2)->{
- return new Double(Double.parseDouble((String)d1.getMetadataProperty(GraphPropertyEnum.VERSION)))
- .compareTo(Double.parseDouble((String)d2.getMetadataProperty(GraphPropertyEnum.VERSION)));
+ try {
+ fetchedDerivedResources.sort((d1, d2) -> {
+ return new Double(Double.parseDouble((String) d1.getMetadataProperty(GraphPropertyEnum.VERSION))).compareTo(Double.parseDouble((String) d2.getMetadataProperty(GraphPropertyEnum.VERSION)));
});
-
+
int actualHighestIndex = fetchedDerivedResources.size() - 1;
derivedResource.add(fetchedDerivedResources.get(actualHighestIndex));
fetchedDerivedResources.remove(actualHighestIndex);
-
+
StorageOperationStatus status = fixMultipleParent(fetchedDerivedResources);
- if(status != StorageOperationStatus.OK){
+ if (status != StorageOperationStatus.OK) {
result = Either.right(status);
}
- } catch (Exception e){
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Exception occured during handle multiple parent {}. Exception is {}",
- parentResource, e.getMessage());
+ } catch (Exception e) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Exception occured during handle multiple parent {}. Exception is {}", parentResource, e.getMessage());
result = Either.right(StorageOperationStatus.GENERAL_ERROR);
}
return result;
@@ -643,13 +647,12 @@ public class NodeTypeOperation extends ToscaElementOperation {
private StorageOperationStatus fixMultipleParent(List<GraphVertex> fetchedDerivedResources) {
StorageOperationStatus result = StorageOperationStatus.OK;
- for(GraphVertex fetchedDerivedResource : fetchedDerivedResources){
+ for (GraphVertex fetchedDerivedResource : fetchedDerivedResources) {
fetchedDerivedResource.addMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION, false);
Either<GraphVertex, TitanOperationStatus> updateVertexRes = titanDao.updateVertex(fetchedDerivedResource);
if (updateVertexRes.isRight()) {
TitanOperationStatus titatStatus = updateVertexRes.right().value();
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to set highest version of node type {} to false. Status is {}",
- fetchedDerivedResource.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME), titatStatus);
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to set highest version of node type {} to false. Status is {}", fetchedDerivedResource.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME), titatStatus);
result = DaoStatusConverter.convertTitanStatusToStorageStatus(titatStatus);
break;
}
@@ -805,9 +808,9 @@ public class NodeTypeOperation extends ToscaElementOperation {
return StorageOperationStatus.OK;
}
-
+
private StorageOperationStatus associateDerivedDataByType(EdgeLabelEnum edgeLabel, GraphVertex nodeTypeV, NodeType nodeToUpdate, List<GraphVertex> newDerived) {
-
+
switch (edgeLabel) {
case CAPABILITIES:
return associateCapabilitiesToResource(nodeTypeV, nodeToUpdate, newDerived);
@@ -873,12 +876,24 @@ public class NodeTypeOperation extends ToscaElementOperation {
return dataFromDerived.right().value();
}
Map<String, T> dataFromDerivedAll = dataFromDerived.left().value();
-
+
Either<Map<String, T>, String> merged = ToscaDataDefinition.mergeDataMaps(dataFromDerivedAll, mapFromGraph);
- if(merged.isRight()){
+ if (merged.isRight()) {
log.debug("property {} cannot be overriden", merged.right().value());
return StorageOperationStatus.INVALID_PROPERTY;
}
+ if (mergeValues && valuesFrmPrev != null) {
+ valuesFrmPrev.entrySet().forEach(e -> {
+ T newData = merged.left().value().get(e.getKey());
+ if (newData != null) {
+ if (isSimpleHierarchy(label)) {
+ e.getValue().mergeFunction(newData, true);
+ }else{
+ e.getValue().updateIfExist(newData, true);
+ }
+ }
+ });
+ }
dataV.setJson(dataFromDerivedAll);
Either<GraphVertex, TitanOperationStatus> updateDataV = updateOrCopyOnUpdate(dataV, nodeTypeV, label);
if (updateDataV.isRight()) {
@@ -886,8 +901,8 @@ public class NodeTypeOperation extends ToscaElementOperation {
}
return StorageOperationStatus.OK;
}
-
- private boolean isSimpleHierarchy(EdgeLabelEnum label) {
+
+ private boolean isSimpleHierarchy(EdgeLabelEnum label) {
switch (label) {
case PROPERTIES:
case ATTRIBUTES:
@@ -901,7 +916,6 @@ public class NodeTypeOperation extends ToscaElementOperation {
}
}
-
@Override
public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
fillMetadata(elementV, (NodeType) toscaElementToUpdate);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
index 989707bf0c..b1d4f151d8 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
@@ -26,9 +26,10 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.Map.Entry;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.MapUtils;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
@@ -51,7 +52,6 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
-import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DistributionStatusEnum;
@@ -61,6 +61,7 @@ import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
+import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
@@ -1072,5 +1073,69 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
return result;
}
+ /**
+ * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name and type
+ * @param componentId
+ * @param instanceId
+ * @param capabilityName
+ * @param capabilityType
+ * @return
+ */
+ public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType) {
+
+ Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
+ Map<String, MapCapabiltyProperty> mapPropertiesDataDefinition = null;
+ Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TopologyTemplate, JsonParseFlagEnum.NoParse);
+ if (componentByLabelAndId.isRight()) {
+ result = Either.right(componentByLabelAndId.right().value());
+ }
+ if(componentByLabelAndId.isLeft()){
+ Either<Map<String, MapCapabiltyProperty>, TitanOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
+ if (getDataRes.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getDataRes.right().value()));
+ } else {
+ mapPropertiesDataDefinition = getDataRes.left().value();
+ }
+ }
+ if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
+ result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
+ }
+ return result;
+ }
+
+ private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabiltyProperty> mapPropertiesDataDefinition) {
+ return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
+ mapPropertiesDataDefinition.get(instanceId) != null &&
+ MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
+ }
+
+ private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, Map<String, MapPropertiesDataDefinition> propertiesMap) {
+ List<ComponentInstanceProperty> capPropsList = null;
+ for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
+ if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, capProp)) {
+ Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
+ if (capMap != null && !capMap.isEmpty()) {
+ capPropsList = capMap.values().stream().map(o -> new ComponentInstanceProperty(o)).collect(Collectors.toList());
+ break;
+ }
+ }
+ }
+ if(capPropsList == null){
+ capPropsList = new ArrayList<>();
+ }
+ return capPropsList;
+ }
+
+ private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, Entry<String, MapPropertiesDataDefinition> capProp) {
+ if (capProp != null) {
+ String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
+ if (path.length < 4) {
+ log.debug("wrong key format for capabilty, key {}", capProp);
+ return false;
+ }
+ return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[0].equals(instanceId);
+ }
+ return false;
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java
index 708ef783f1..ec55ddaf3b 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java
@@ -20,9 +20,16 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-import fj.data.Either;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -59,9 +66,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import java.lang.reflect.Type;
-import java.util.*;
-import java.util.Map.Entry;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+
+import fj.data.Either;
public abstract class ToscaElementOperation extends BaseOperation {
private static Logger log = LoggerFactory.getLogger(ToscaElementOperation.class.getName());
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
index 394231938a..15fb63f14c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
@@ -20,26 +20,68 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
-import java.util.*;
-import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.BiPredicate;
import java.util.stream.Collectors;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.*;
-import org.openecomp.sdc.be.datatypes.enums.*;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty;
+import org.openecomp.sdc.be.datatypes.elements.MapListCapabiltyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RelationshipInfo;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
@@ -47,7 +89,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
-import org.openecomp.sdc.be.utils.CommonBeUtils;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
import org.openecomp.sdc.common.util.ValidationUtils;
@@ -55,489 +96,492 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
+import fj.data.Either;
@org.springframework.stereotype.Component("tosca-operation-facade")
public class ToscaOperationFacade {
- @Autowired
- private NodeTypeOperation nodeTypeOperation;
- @Autowired
- private TopologyTemplateOperation topologyTemplateOperation;
- @Autowired
- private NodeTemplateOperation nodeTemplateOperation;
- @Autowired
- private GroupsOperation groupsOperation;
- @Autowired
- private TitanDao titanDao;
-
- private static Logger log = LoggerFactory.getLogger(ToscaOperationFacade.class.getName());
-
- public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(String componentId) {
-
- return getToscaElement(componentId, JsonParseFlagEnum.ParseAll);
-
- }
-
- public <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement(String componentId) {
- ComponentParametersView filters = new ComponentParametersView();
- filters.setIgnoreCapabiltyProperties(false);
-
- return getToscaElement(componentId, filters);
- }
-
- public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(String componentId, ComponentParametersView filters) {
-
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, filters.detectParseFlag());
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
-
- }
- return getToscaElementByOperation(getVertexEither.left().value(), filters);
- }
-
- public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(String componentId, JsonParseFlagEnum parseFlag) {
-
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, parseFlag);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
-
- }
- return getToscaElementByOperation(getVertexEither.left().value());
- }
-
- public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(GraphVertex componentVertex) {
- return getToscaElementByOperation(componentVertex);
- }
-
- public Either<Boolean, StorageOperationStatus> validateComponentExists(String componentId) {
-
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getVertexEither.isRight()) {
- TitanOperationStatus status = getVertexEither.right().value();
- if (status == TitanOperationStatus.NOT_FOUND) {
- return Either.left(false);
- } else {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
- }
- }
- return Either.left(true);
- }
-
- public <T extends Component> Either<T, StorageOperationStatus> findLastCertifiedToscaElementByUUID(T component) {
- Map<GraphPropertyEnum, Object> props = new HashMap<>();
- props.put(GraphPropertyEnum.UUID, component.getUUID());
- props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
-
- Either<List<GraphVertex>, TitanOperationStatus> getVertexEither = titanDao.getByCriteria(ModelConverter.getVertexType(component), props);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", component.getUniqueId(), getVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
-
- }
- return getToscaElementByOperation(getVertexEither.left().value().get(0));
- }
-
- private <T extends Component> Either<T, StorageOperationStatus> getToscaElementByOperation(GraphVertex componentV) {
- return getToscaElementByOperation(componentV, new ComponentParametersView());
- }
-
- private <T extends Component> Either<T, StorageOperationStatus> getToscaElementByOperation(GraphVertex componentV, ComponentParametersView filters) {
- VertexTypeEnum label = componentV.getLabel();
-
- ToscaElementOperation toscaOperation = getToscaElementOperation(componentV);
- Either<ToscaElement, StorageOperationStatus> toscaElement;
- String componentId = componentV.getUniqueId();
- if (toscaOperation != null) {
- log.debug("Need to fetch tosca element for id {}", componentId);
- toscaElement = toscaOperation.getToscaElement(componentV, filters);
- } else {
- log.debug("not supported tosca type {} for id {}", label, componentId);
- toscaElement = Either.right(StorageOperationStatus.BAD_REQUEST);
- }
- if (toscaElement.isRight()) {
- return Either.right(toscaElement.right().value());
- }
- return Either.left(ModelConverter.convertFromToscaElement(toscaElement.left().value()));
- }
-
- private ToscaElementOperation getToscaElementOperation(GraphVertex componentV) {
- VertexTypeEnum label = componentV.getLabel();
- switch (label) {
- case NODE_TYPE:
- return nodeTypeOperation;
- case TOPOLOGY_TEMPLATE:
- return topologyTemplateOperation;
- default:
- return null;
- }
- }
-
- /**
- *
- * @param resource
- * @return
- */
- public <T extends Component> Either<T, StorageOperationStatus> createToscaComponent(T resource) {
- ToscaElement toscaElement = ModelConverter.convertToToscaElement(resource);
-
- ToscaElementOperation toscaElementOperation = getToscaElementOperation(resource);
- Either<ToscaElement, StorageOperationStatus> createToscaElement = toscaElementOperation.createToscaElement(toscaElement);
- if (createToscaElement.isLeft()) {
- log.debug("Component created successfully!!!");
- T dataModel = ModelConverter.convertFromToscaElement(createToscaElement.left().value());
- return Either.left(dataModel);
- }
- return Either.right(createToscaElement.right().value());
- }
-
- /**
- *
- * @param componentToDelete
- * @return
- */
- public StorageOperationStatus markComponentToDelete(Component componentToDelete) {
-
- if ((componentToDelete.getIsDeleted() != null) && componentToDelete.getIsDeleted() && !componentToDelete.isHighestVersion()) {
- // component already marked for delete
- return StorageOperationStatus.OK;
- } else {
-
- Either<GraphVertex, TitanOperationStatus> getResponse = titanDao.getVertexById(componentToDelete.getUniqueId(), JsonParseFlagEnum.ParseAll);
- if (getResponse.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentToDelete.getUniqueId(), getResponse.right().value());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(getResponse.right().value());
-
- }
- GraphVertex componentV = getResponse.left().value();
-
- // same operation for node type and topology template operations
- Either<GraphVertex, StorageOperationStatus> result = nodeTypeOperation.markComponentToDelete(componentV);
- if (result.isRight()) {
- return result.right().value();
- }
- return StorageOperationStatus.OK;
- }
- }
-
- /**
- *
- * @param componentId
- * @return
- */
- public <T extends Component> Either<T, StorageOperationStatus> deleteToscaComponent(String componentId) {
-
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component vertex with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
-
- }
- Either<ToscaElement, StorageOperationStatus> deleteElement = deleteToscaElement(getVertexEither.left().value());
- if (deleteElement.isRight()) {
- log.debug("Failed to delete component with and unique id {}, error: {}", componentId, deleteElement.right().value());
- return Either.right(deleteElement.right().value());
- }
- T dataModel = ModelConverter.convertFromToscaElement(deleteElement.left().value());
-
- return Either.left(dataModel);
- }
-
- private Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex componentV) {
- VertexTypeEnum label = componentV.getLabel();
- Either<ToscaElement, StorageOperationStatus> toscaElement;
- Object componentId = componentV.getUniqueId();
- switch (label) {
- case NODE_TYPE:
- log.debug("Need to fetch node type for id {}", componentId);
- toscaElement = nodeTypeOperation.deleteToscaElement(componentV);
- break;
- case TOPOLOGY_TEMPLATE:
- log.debug("Need to fetch topology template for id {}", componentId);
- toscaElement = topologyTemplateOperation.deleteToscaElement(componentV);
- break;
- default:
- log.debug("not supported tosca type {} for id {}", label, componentId);
- toscaElement = Either.right(StorageOperationStatus.BAD_REQUEST);
- break;
- }
- return toscaElement;
- }
-
- private ToscaElementOperation getToscaElementOperation(Component component) {
- return ModelConverter.isAtomicComponent(component) ? nodeTypeOperation : topologyTemplateOperation;
- }
-
- public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) {
- return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
- }
-
+
+ // region - Fields
+
+ @Autowired
+ private NodeTypeOperation nodeTypeOperation;
+ @Autowired
+ private TopologyTemplateOperation topologyTemplateOperation;
+ @Autowired
+ private NodeTemplateOperation nodeTemplateOperation;
+ @Autowired
+ private GroupsOperation groupsOperation;
+ @Autowired
+ private TitanDao titanDao;
+ private static Logger log = LoggerFactory.getLogger(ToscaOperationFacade.class.getName());
+ // endregion
+
+ // region - ToscaElement - GetById
+ public static final String PROXY_SUFFIX = "_proxy";
+
+ public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(String componentId) {
+
+ return getToscaElement(componentId, JsonParseFlagEnum.ParseAll);
+
+ }
+
+ public <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement(String componentId) {
+ ComponentParametersView filters = new ComponentParametersView();
+ filters.setIgnoreCapabiltyProperties(false);
+
+ return getToscaElement(componentId, filters);
+ }
+
+ public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(String componentId, ComponentParametersView filters) {
+
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, filters.detectParseFlag());
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+
+ }
+ return getToscaElementByOperation(getVertexEither.left().value(), filters);
+ }
+
+ public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(String componentId, JsonParseFlagEnum parseFlag) {
+
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, parseFlag);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+
+ }
+ return getToscaElementByOperation(getVertexEither.left().value());
+ }
+
+ public <T extends Component> Either<T, StorageOperationStatus> getToscaElement(GraphVertex componentVertex) {
+ return getToscaElementByOperation(componentVertex);
+ }
+
+ public Either<Boolean, StorageOperationStatus> validateComponentExists(String componentId) {
+
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ TitanOperationStatus status = getVertexEither.right().value();
+ if (status == TitanOperationStatus.NOT_FOUND) {
+ return Either.left(false);
+ } else {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+ }
+ }
+ return Either.left(true);
+ }
+
+ public <T extends Component> Either<T, StorageOperationStatus> findLastCertifiedToscaElementByUUID(T component) {
+ Map<GraphPropertyEnum, Object> props = new HashMap<>();
+ props.put(GraphPropertyEnum.UUID, component.getUUID());
+ props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+
+ Either<List<GraphVertex>, TitanOperationStatus> getVertexEither = titanDao.getByCriteria(ModelConverter.getVertexType(component), props);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", component.getUniqueId(), getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+
+ }
+ return getToscaElementByOperation(getVertexEither.left().value().get(0));
+ }
+
+ // endregion
+ // region - ToscaElement - GetByOperation
+ private <T extends Component> Either<T, StorageOperationStatus> getToscaElementByOperation(GraphVertex componentV) {
+ return getToscaElementByOperation(componentV, new ComponentParametersView());
+ }
+
+ private <T extends Component> Either<T, StorageOperationStatus> getToscaElementByOperation(GraphVertex componentV, ComponentParametersView filters) {
+ VertexTypeEnum label = componentV.getLabel();
+
+ ToscaElementOperation toscaOperation = getToscaElementOperation(componentV);
+ Either<ToscaElement, StorageOperationStatus> toscaElement;
+ String componentId = componentV.getUniqueId();
+ if (toscaOperation != null) {
+ log.debug("Need to fetch tosca element for id {}", componentId);
+ toscaElement = toscaOperation.getToscaElement(componentV, filters);
+ } else {
+ log.debug("not supported tosca type {} for id {}", label, componentId);
+ toscaElement = Either.right(StorageOperationStatus.BAD_REQUEST);
+ }
+ if (toscaElement.isRight()) {
+ return Either.right(toscaElement.right().value());
+ }
+ return Either.left(ModelConverter.convertFromToscaElement(toscaElement.left().value()));
+ }
+
+ // endregion
+ private ToscaElementOperation getToscaElementOperation(GraphVertex componentV) {
+ VertexTypeEnum label = componentV.getLabel();
+ switch (label) {
+ case NODE_TYPE:
+ return nodeTypeOperation;
+ case TOPOLOGY_TEMPLATE:
+ return topologyTemplateOperation;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ *
+ * @param resource
+ * @return
+ */
+ public <T extends Component> Either<T, StorageOperationStatus> createToscaComponent(T resource) {
+ ToscaElement toscaElement = ModelConverter.convertToToscaElement(resource);
+
+ ToscaElementOperation toscaElementOperation = getToscaElementOperation(resource);
+ Either<ToscaElement, StorageOperationStatus> createToscaElement = toscaElementOperation.createToscaElement(toscaElement);
+ if (createToscaElement.isLeft()) {
+ log.debug("Component created successfully!!!");
+ T dataModel = ModelConverter.convertFromToscaElement(createToscaElement.left().value());
+ return Either.left(dataModel);
+ }
+ return Either.right(createToscaElement.right().value());
+ }
+
+ // region - ToscaElement Delete
+ /**
+ *
+ * @param componentToDelete
+ * @return
+ */
+ public StorageOperationStatus markComponentToDelete(Component componentToDelete) {
+
+ if ((componentToDelete.getIsDeleted() != null) && componentToDelete.getIsDeleted() && !componentToDelete.isHighestVersion()) {
+ // component already marked for delete
+ return StorageOperationStatus.OK;
+ } else {
+
+ Either<GraphVertex, TitanOperationStatus> getResponse = titanDao.getVertexById(componentToDelete.getUniqueId(), JsonParseFlagEnum.ParseAll);
+ if (getResponse.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentToDelete.getUniqueId(), getResponse.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(getResponse.right().value());
+
+ }
+ GraphVertex componentV = getResponse.left().value();
+
+ // same operation for node type and topology template operations
+ Either<GraphVertex, StorageOperationStatus> result = nodeTypeOperation.markComponentToDelete(componentV);
+ if (result.isRight()) {
+ return result.right().value();
+ }
+ return StorageOperationStatus.OK;
+ }
+ }
+
+ /**
+ *
+ * @param componentId
+ * @return
+ */
+ public <T extends Component> Either<T, StorageOperationStatus> deleteToscaComponent(String componentId) {
+
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component vertex with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+
+ }
+ Either<ToscaElement, StorageOperationStatus> deleteElement = deleteToscaElement(getVertexEither.left().value());
+ if (deleteElement.isRight()) {
+ log.debug("Failed to delete component with and unique id {}, error: {}", componentId, deleteElement.right().value());
+ return Either.right(deleteElement.right().value());
+ }
+ T dataModel = ModelConverter.convertFromToscaElement(deleteElement.left().value());
+
+ return Either.left(dataModel);
+ }
+
+ private Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex componentV) {
+ VertexTypeEnum label = componentV.getLabel();
+ Either<ToscaElement, StorageOperationStatus> toscaElement;
+ Object componentId = componentV.getUniqueId();
+ switch (label) {
+ case NODE_TYPE:
+ log.debug("Need to fetch node type for id {}", componentId);
+ toscaElement = nodeTypeOperation.deleteToscaElement(componentV);
+ break;
+ case TOPOLOGY_TEMPLATE:
+ log.debug("Need to fetch topology template for id {}", componentId);
+ toscaElement = topologyTemplateOperation.deleteToscaElement(componentV);
+ break;
+ default:
+ log.debug("not supported tosca type {} for id {}", label, componentId);
+ toscaElement = Either.right(StorageOperationStatus.BAD_REQUEST);
+ break;
+ }
+ return toscaElement;
+ }
+ // endregion
+
+ private ToscaElementOperation getToscaElementOperation(Component component) {
+ return ModelConverter.isAtomicComponent(component) ? nodeTypeOperation : topologyTemplateOperation;
+ }
+
+ public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) {
+ return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
+ }
+
public <T extends Component> Either<T, StorageOperationStatus> getFullLatestComponentByToscaResourceName(String toscaResourceName) {
return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, JsonParseFlagEnum.ParseAll);
}
- public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName) {
- return getLatestByName(GraphPropertyEnum.NAME, resourceName);
+ public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName) {
+ return getLatestByName(GraphPropertyEnum.NAME, resourceName);
- }
+ }
- public Either<Integer, StorageOperationStatus> validateCsarUuidUniqueness(String csarUUID) {
- Either<List<ToscaElement>, StorageOperationStatus> byCsar = null;
+ public Either<Integer, StorageOperationStatus> validateCsarUuidUniqueness(String csarUUID) {
- Map<GraphPropertyEnum, Object> properties = new HashMap<GraphPropertyEnum, Object>();
- properties.put(GraphPropertyEnum.CSAR_UUID, csarUUID);
+ Map<GraphPropertyEnum, Object> properties = new HashMap<GraphPropertyEnum, Object>();
+ properties.put(GraphPropertyEnum.CSAR_UUID, csarUUID);
- Either<List<GraphVertex>, TitanOperationStatus> resources = titanDao.getByCriteria(null, properties, JsonParseFlagEnum.ParseMetadata);
+ Either<List<GraphVertex>, TitanOperationStatus> resources = titanDao.getByCriteria(null, properties, JsonParseFlagEnum.ParseMetadata);
- if (resources.isRight()) {
- if (resources.right().value() == TitanOperationStatus.NOT_FOUND) {
- return Either.left(new Integer(0));
- } else {
- log.debug("failed to get resources from graph with property name: {}", csarUUID);
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resources.right().value()));
- }
- }
+ if (resources.isRight()) {
+ if (resources.right().value() == TitanOperationStatus.NOT_FOUND) {
+ return Either.left(new Integer(0));
+ } else {
+ log.debug("failed to get resources from graph with property name: {}", csarUUID);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resources.right().value()));
+ }
+ }
- List<GraphVertex> resourceList = (resources.isLeft() ? resources.left().value() : null);
+ List<GraphVertex> resourceList = (resources.isLeft() ? resources.left().value() : null);
- return Either.left(new Integer(resourceList.size()));
+ return Either.left(new Integer(resourceList.size()));
- }
+ }
public <T extends Component> Either<Set<T>, StorageOperationStatus> getFollowed(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates, ComponentTypeEnum componentType) {
- Either<List<ToscaElement>, StorageOperationStatus> followedResources;
- if (componentType == ComponentTypeEnum.RESOURCE) {
- followedResources = nodeTypeOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType);
- } else {
- followedResources = topologyTemplateOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType);
- }
+ Either<List<ToscaElement>, StorageOperationStatus> followedResources;
+ if (componentType == ComponentTypeEnum.RESOURCE) {
+ followedResources = nodeTypeOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType);
+ } else {
+ followedResources = topologyTemplateOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType);
+ }
Set<T> components = new HashSet<>();
- if (followedResources.isRight() && followedResources.right().value() != StorageOperationStatus.NOT_FOUND) {
- return Either.right(followedResources.right().value());
- }
- if (followedResources.isLeft()) {
- List<ToscaElement> toscaElements = followedResources.left().value();
- toscaElements.forEach(te -> {
- T component = ModelConverter.convertFromToscaElement(te);
- components.add(component);
- });
- }
- return Either.left(components);
- }
-
- public Either<Resource, StorageOperationStatus> getLatestCertifiedNodeTypeByToscaResourceName(String toscaResourceName) {
-
- return getLatestCertifiedByToscaResourceName(toscaResourceName, VertexTypeEnum.NODE_TYPE, JsonParseFlagEnum.ParseMetadata);
- }
-
- public Either<Resource, StorageOperationStatus> getLatestCertifiedByToscaResourceName(String toscaResourceName, VertexTypeEnum vertexType, JsonParseFlagEnum parseFlag) {
-
- Either<Resource, StorageOperationStatus> result = null;
- Map<GraphPropertyEnum, Object> props = new HashMap<GraphPropertyEnum, Object>();
- props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
- props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- Either<List<GraphVertex>, TitanOperationStatus> getLatestRes = titanDao.getByCriteria(vertexType, props, parseFlag);
-
- if (getLatestRes.isRight()) {
- TitanOperationStatus status = getLatestRes.right().value();
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch {} with name {}. status={} ", vertexType, toscaResourceName, status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- if (result == null) {
- List<GraphVertex> resources = getLatestRes.left().value();
- double version = 0.0;
- GraphVertex highestResource = null;
- for (GraphVertex resource : resources) {
- double resourceVersion = Double.parseDouble((String) resource.getJsonMetadataField(JsonPresentationFields.VERSION));
- if (resourceVersion > version) {
- version = resourceVersion;
- highestResource = resource;
- }
- }
- result = getToscaElement(highestResource.getUniqueId());
- }
- return result;
- }
-
- public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExists(String templateName) {
- Either<Boolean, StorageOperationStatus> validateUniquenessRes = validateToscaResourceNameUniqueness(templateName);
- if (validateUniquenessRes.isLeft()) {
- return Either.left(!validateUniquenessRes.left().value());
- }
- return validateUniquenessRes;
- }
-
- public Either<RequirementCapabilityRelDef, StorageOperationStatus> dissociateResourceInstances(String componentId, RequirementCapabilityRelDef requirementDef) {
- return nodeTemplateOperation.dissociateResourceInstances(componentId, requirementDef);
-
- }
-
- public StorageOperationStatus associateResourceInstances(String componentId, List<RequirementCapabilityRelDef> relations) {
- Either<List<RequirementCapabilityRelDef>, StorageOperationStatus> status = nodeTemplateOperation.associateResourceInstances(componentId, relations);
- if (status.isRight()) {
- return status.right().value();
- }
- return StorageOperationStatus.OK;
- }
-
- protected Either<Boolean, StorageOperationStatus> validateToscaResourceNameUniqueness(String name) {
-
- Map<GraphPropertyEnum, Object> properties = new HashMap<GraphPropertyEnum, Object>();
- properties.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, name);
-
- Either<List<GraphVertex>, TitanOperationStatus> resources = titanDao.getByCriteria(null, properties, JsonParseFlagEnum.ParseMetadata);
-
- if (resources.isRight() && resources.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("failed to get resources from graph with property name: {}", name);
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resources.right().value()));
- }
- List<GraphVertex> resourceList = (resources.isLeft() ? resources.left().value() : null);
- if (resourceList != null && resourceList.size() > 0) {
- if (log.isDebugEnabled()) {
- StringBuilder builder = new StringBuilder();
- for (GraphVertex resourceData : resourceList) {
- builder.append(resourceData.getUniqueId() + "|");
- }
- log.debug("resources with property name:{} exists in graph. found {}", name, builder.toString());
- }
- return Either.left(false);
- } else {
- log.debug("resources with property name:{} does not exists in graph", name);
- return Either.left(true);
- }
-
- }
-
- /**
- *
- * @param newComponent
- * @param oldComponent
- * @return
- */
- public <T extends Component> Either<T, StorageOperationStatus> overrideComponent(T newComponent, T oldComponent) {
-
- // TODO
- // newComponent.setInterfaces(oldComponent.getInterfaces);
- newComponent.setArtifacts(oldComponent.getArtifacts());
- newComponent.setDeploymentArtifacts(oldComponent.getDeploymentArtifacts());
- newComponent.setGroups(oldComponent.getGroups());
- newComponent.setInputs(null);
- newComponent.setLastUpdateDate(null);
- newComponent.setHighestVersion(true);
-
- Either<GraphVertex, TitanOperationStatus> componentVEither = titanDao.getVertexById(oldComponent.getUniqueId(), JsonParseFlagEnum.NoParse);
- if (componentVEither.isRight()) {
- log.debug("Falied to fetch component {} error {}", oldComponent.getUniqueId(), componentVEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(componentVEither.right().value()));
- }
- GraphVertex componentv = componentVEither.left().value();
- Either<GraphVertex, TitanOperationStatus> parentVertexEither = titanDao.getParentVertex(componentv, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
- if (parentVertexEither.isRight() && parentVertexEither.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Falied to fetch parent version for component {} error {}", oldComponent.getUniqueId(), parentVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(parentVertexEither.right().value()));
- }
-
- Either<ToscaElement, StorageOperationStatus> deleteToscaComponent = deleteToscaElement(componentv);
- if (deleteToscaComponent.isRight()) {
- log.debug("Falied to remove old component {} error {}", oldComponent.getUniqueId(), deleteToscaComponent.right().value());
- return Either.right(deleteToscaComponent.right().value());
- }
- Either<T, StorageOperationStatus> createToscaComponent = createToscaComponent(newComponent);
- if (createToscaComponent.isRight()) {
- log.debug("Falied to create tosca element component {} error {}", newComponent.getUniqueId(), createToscaComponent.right().value());
- return Either.right(createToscaComponent.right().value());
- }
- T newElement = createToscaComponent.left().value();
- Either<GraphVertex, TitanOperationStatus> newVersionEither = titanDao.getVertexById(newElement.getUniqueId(), JsonParseFlagEnum.NoParse);
- if (newVersionEither.isRight()) {
- log.debug("Falied to fetch new tosca element component {} error {}", newComponent.getUniqueId(), newVersionEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(newVersionEither.right().value()));
- }
- if (parentVertexEither.isLeft()) {
- GraphVertex previousVersionV = parentVertexEither.left().value();
- TitanOperationStatus createEdge = titanDao.createEdge(previousVersionV, newVersionEither.left().value(), EdgeLabelEnum.VERSION, null);
- if (createEdge != TitanOperationStatus.OK) {
- log.debug("Falied to associate to previous version {} new version {} error {}", previousVersionV.getUniqueId(), newVersionEither.right().value(), createEdge);
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge));
- }
- }
- return Either.left(newElement);
- }
-
- /**
- *
- * @param componentToUpdate
- * @return
- */
- public <T extends Component> Either<T, StorageOperationStatus> updateToscaElement(T componentToUpdate) {
- return updateToscaElement(componentToUpdate, new ComponentParametersView());
- }
-
- /**
- *
- * @param componentToUpdate
- * @param type
- * @param filterResult
- * @return
- */
- public <T extends Component> Either<T, StorageOperationStatus> updateToscaElement(T componentToUpdate, ComponentParametersView filterResult) {
- String componentId = componentToUpdate.getUniqueId();
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
- }
- GraphVertex elementV = getVertexEither.left().value();
- ToscaElementOperation toscaElementOperation = getToscaElementOperation(elementV);
-
- ToscaElement toscaElementToUpdate = ModelConverter.convertToToscaElement(componentToUpdate);
- Either<ToscaElement, StorageOperationStatus> updateToscaElement = toscaElementOperation.updateToscaElement(toscaElementToUpdate, elementV, filterResult);
- if (updateToscaElement.isRight()) {
- log.debug("Failed to update tosca element {} error {}", componentId, updateToscaElement.right().value());
- return Either.right(updateToscaElement.right().value());
- }
- return Either.left(ModelConverter.convertFromToscaElement(updateToscaElement.left().value()));
- }
-
- private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName) {
- Either<T, StorageOperationStatus> result;
-
- Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
- Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
-
- propertiesToMatch.put(property, nodeName);
- propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
-
- propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
-
- Either<List<GraphVertex>, TitanOperationStatus> highestResources = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata);
- if (highestResources.isRight()) {
- TitanOperationStatus status = highestResources.right().value();
- log.debug("failed to find resource with name {}. status={} ", nodeName, status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- return result;
- }
-
- List<GraphVertex> resources = highestResources.left().value();
- double version = 0.0;
- GraphVertex highestResource = null;
- for (GraphVertex vertex : resources) {
- Object versionObj = vertex.getMetadataProperty(GraphPropertyEnum.VERSION);
- double resourceVersion = Double.valueOf((String) versionObj);
- if (resourceVersion > version) {
- version = resourceVersion;
- highestResource = vertex;
- }
- }
- return getToscaElementByOperation(highestResource);
- }
+ if (followedResources.isRight() && followedResources.right().value() != StorageOperationStatus.NOT_FOUND) {
+ return Either.right(followedResources.right().value());
+ }
+ if (followedResources.isLeft()) {
+ List<ToscaElement> toscaElements = followedResources.left().value();
+ toscaElements.forEach(te -> {
+ T component = ModelConverter.convertFromToscaElement(te);
+ components.add(component);
+ });
+ }
+ return Either.left(components);
+ }
+
+ public Either<Resource, StorageOperationStatus> getLatestCertifiedNodeTypeByToscaResourceName(String toscaResourceName) {
+
+ return getLatestCertifiedByToscaResourceName(toscaResourceName, VertexTypeEnum.NODE_TYPE, JsonParseFlagEnum.ParseMetadata);
+ }
+
+ public Either<Resource, StorageOperationStatus> getLatestCertifiedByToscaResourceName(String toscaResourceName, VertexTypeEnum vertexType, JsonParseFlagEnum parseFlag) {
+
+ Either<Resource, StorageOperationStatus> result = null;
+ Map<GraphPropertyEnum, Object> props = new HashMap<GraphPropertyEnum, Object>();
+ props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
+ props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ Either<List<GraphVertex>, TitanOperationStatus> getLatestRes = titanDao.getByCriteria(vertexType, props, parseFlag);
+
+ if (getLatestRes.isRight()) {
+ TitanOperationStatus status = getLatestRes.right().value();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch {} with name {}. status={} ", vertexType, toscaResourceName, status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ if (result == null) {
+ List<GraphVertex> resources = getLatestRes.left().value();
+ double version = 0.0;
+ GraphVertex highestResource = null;
+ for (GraphVertex resource : resources) {
+ double resourceVersion = Double.parseDouble((String) resource.getJsonMetadataField(JsonPresentationFields.VERSION));
+ if (resourceVersion > version) {
+ version = resourceVersion;
+ highestResource = resource;
+ }
+ }
+ result = getToscaFullElement(highestResource.getUniqueId());
+ }
+ return result;
+ }
+
+ public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExists(String templateName) {
+ Either<Boolean, StorageOperationStatus> validateUniquenessRes = validateToscaResourceNameUniqueness(templateName);
+ if (validateUniquenessRes.isLeft()) {
+ return Either.left(!validateUniquenessRes.left().value());
+ }
+ return validateUniquenessRes;
+ }
+
+ public Either<RequirementCapabilityRelDef, StorageOperationStatus> dissociateResourceInstances(String componentId, RequirementCapabilityRelDef requirementDef) {
+ return nodeTemplateOperation.dissociateResourceInstances(componentId, requirementDef);
+ }
+ /**
+ * Allows to get fulfilled requirement by relation and received predicate
+ * @param componentId
+ * @param instanceId
+ * @param relation
+ * @param predicate
+ * @return
+ */
+ public Either<RequirementDataDefinition, StorageOperationStatus> getFulfilledRequirementByRelation(String componentId, String instanceId, RequirementCapabilityRelDef relation, BiPredicate<RelationshipInfo, RequirementDataDefinition> predicate) {
+ return nodeTemplateOperation.getFulfilledRequirementByRelation(componentId, instanceId, relation, predicate);
+ }
+ /**
+ * Allows to get fulfilled capability by relation and received predicate
+ * @param componentId
+ * @param instanceId
+ * @param relation
+ * @param predicate
+ * @return
+ */
+ public Either<CapabilityDataDefinition, StorageOperationStatus> getFulfilledCapabilityByRelation(String componentId, String instanceId, RequirementCapabilityRelDef relation, BiPredicate<RelationshipInfo, CapabilityDataDefinition> predicate) {
+ return nodeTemplateOperation.getFulfilledCapabilityByRelation(componentId, instanceId, relation, predicate);
+ }
+
+ public StorageOperationStatus associateResourceInstances(String componentId, List<RequirementCapabilityRelDef> relations) {
+ Either<List<RequirementCapabilityRelDef>, StorageOperationStatus> status = nodeTemplateOperation.associateResourceInstances(componentId, relations);
+ if (status.isRight()) {
+ return status.right().value();
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ protected Either<Boolean, StorageOperationStatus> validateToscaResourceNameUniqueness(String name) {
+
+ Map<GraphPropertyEnum, Object> properties = new HashMap<GraphPropertyEnum, Object>();
+ properties.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, name);
+
+ Either<List<GraphVertex>, TitanOperationStatus> resources = titanDao.getByCriteria(null, properties, JsonParseFlagEnum.ParseMetadata);
+
+ if (resources.isRight() && resources.right().value() != TitanOperationStatus.NOT_FOUND) {
+ log.debug("failed to get resources from graph with property name: {}", name);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resources.right().value()));
+ }
+ List<GraphVertex> resourceList = (resources.isLeft() ? resources.left().value() : null);
+ if (resourceList != null && resourceList.size() > 0) {
+ if (log.isDebugEnabled()) {
+ StringBuilder builder = new StringBuilder();
+ for (GraphVertex resourceData : resourceList) {
+ builder.append(resourceData.getUniqueId() + "|");
+ }
+ log.debug("resources with property name:{} exists in graph. found {}", name, builder.toString());
+ }
+ return Either.left(false);
+ } else {
+ log.debug("resources with property name:{} does not exists in graph", name);
+ return Either.left(true);
+ }
+
+ }
+
+ private List<InputDefinition> getNewInputsByResourceType(Resource component) {
+ return component.getResourceType().equals(ResourceTypeEnum.CVFC) ?
+ component.getInputs() : null;
+ }
+
+ // region - Component Update
+ /**
+ *
+ * @param newComponent
+ * @param oldComponent
+ * @return
+ */
+ public Either<Resource, StorageOperationStatus> overrideComponent(Resource newComponent, Resource oldComponent) {
+
+ // TODO
+ // newComponent.setInterfaces(oldComponent.getInterfaces);
+ newComponent.setArtifacts(oldComponent.getArtifacts());
+ newComponent.setDeploymentArtifacts(oldComponent.getDeploymentArtifacts());
+ newComponent.setGroups(oldComponent.getGroups());
+ List<InputDefinition> newInputs = getNewInputsByResourceType(oldComponent);
+ newComponent.setInputs(newInputs);
+ newComponent.setLastUpdateDate(null);
+ newComponent.setHighestVersion(true);
+
+ Either<GraphVertex, TitanOperationStatus> componentVEither = titanDao.getVertexById(oldComponent.getUniqueId(), JsonParseFlagEnum.NoParse);
+ if (componentVEither.isRight()) {
+ log.debug("Falied to fetch component {} error {}", oldComponent.getUniqueId(), componentVEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(componentVEither.right().value()));
+ }
+ GraphVertex componentv = componentVEither.left().value();
+ Either<GraphVertex, TitanOperationStatus> parentVertexEither = titanDao.getParentVertex(componentv, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+ if (parentVertexEither.isRight() && parentVertexEither.right().value() != TitanOperationStatus.NOT_FOUND) {
+ log.debug("Falied to fetch parent version for component {} error {}", oldComponent.getUniqueId(), parentVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(parentVertexEither.right().value()));
+ }
+
+ Either<ToscaElement, StorageOperationStatus> deleteToscaComponent = deleteToscaElement(componentv);
+ if (deleteToscaComponent.isRight()) {
+ log.debug("Falied to remove old component {} error {}", oldComponent.getUniqueId(), deleteToscaComponent.right().value());
+ return Either.right(deleteToscaComponent.right().value());
+ }
+ Either<Resource, StorageOperationStatus> createToscaComponent = createToscaComponent(newComponent);
+ if (createToscaComponent.isRight()) {
+ log.debug("Falied to create tosca element component {} error {}", newComponent.getUniqueId(), createToscaComponent.right().value());
+ return Either.right(createToscaComponent.right().value());
+ }
+ Resource newElement = createToscaComponent.left().value();
+ Either<GraphVertex, TitanOperationStatus> newVersionEither = titanDao.getVertexById(newElement.getUniqueId(), JsonParseFlagEnum.NoParse);
+ if (newVersionEither.isRight()) {
+ log.debug("Falied to fetch new tosca element component {} error {}", newComponent.getUniqueId(), newVersionEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(newVersionEither.right().value()));
+ }
+ if (parentVertexEither.isLeft()) {
+ GraphVertex previousVersionV = parentVertexEither.left().value();
+ TitanOperationStatus createEdge = titanDao.createEdge(previousVersionV, newVersionEither.left().value(), EdgeLabelEnum.VERSION, null);
+ if (createEdge != TitanOperationStatus.OK) {
+ log.debug("Falied to associate to previous version {} new version {} error {}", previousVersionV.getUniqueId(), newVersionEither.right().value(), createEdge);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge));
+ }
+ }
+ return Either.left(newElement);
+ }
+
+ /**
+ *
+ * @param componentToUpdate
+ * @return
+ */
+ public <T extends Component> Either<T, StorageOperationStatus> updateToscaElement(T componentToUpdate) {
+ return updateToscaElement(componentToUpdate, new ComponentParametersView());
+ }
+
+ /**
+ *
+ * @param componentToUpdate
+ * @param type
+ * @param filterResult
+ * @return
+ */
+ public <T extends Component> Either<T, StorageOperationStatus> updateToscaElement(T componentToUpdate, ComponentParametersView filterResult) {
+ String componentId = componentToUpdate.getUniqueId();
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+ }
+ GraphVertex elementV = getVertexEither.left().value();
+ ToscaElementOperation toscaElementOperation = getToscaElementOperation(elementV);
+
+ ToscaElement toscaElementToUpdate = ModelConverter.convertToToscaElement(componentToUpdate);
+ Either<ToscaElement, StorageOperationStatus> updateToscaElement = toscaElementOperation.updateToscaElement(toscaElementToUpdate, elementV, filterResult);
+ if (updateToscaElement.isRight()) {
+ log.debug("Failed to update tosca element {} error {}", componentId, updateToscaElement.right().value());
+ return Either.right(updateToscaElement.right().value());
+ }
+ return Either.left(ModelConverter.convertFromToscaElement(updateToscaElement.left().value()));
+ }
private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName, JsonParseFlagEnum parseFlag) {
Either<T, StorageOperationStatus> result;
@@ -572,453 +616,545 @@ public class ToscaOperationFacade {
return getToscaElementByOperation(highestResource);
}
- public <T extends Component> Either<List<T>, StorageOperationStatus> getBySystemName(ComponentTypeEnum componentType, String systemName) {
-
- Either<List<T>, StorageOperationStatus> result = null;
- Either<T, StorageOperationStatus> getComponentRes;
- List<T> components = new ArrayList<>();
- List<GraphVertex> componentVertices;
- Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
- Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
-
- propertiesToMatch.put(GraphPropertyEnum.SYSTEM_NAME, systemName);
- if (componentType != null)
- propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
-
- propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
-
- Either<List<GraphVertex>, TitanOperationStatus> getComponentsRes = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
- if (getComponentsRes.isRight()) {
- TitanOperationStatus status = getComponentsRes.right().value();
- log.debug("Failed to fetch the component with system name {}. Status is {} ", systemName, status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- if (result == null) {
- componentVertices = getComponentsRes.left().value();
- for (GraphVertex componentVertex : componentVertices) {
- getComponentRes = getToscaElementByOperation(componentVertex);
- if (getComponentRes.isRight()) {
- log.debug("Failed to get the component {}. Status is {} ", componentVertex.getJsonMetadataField(JsonPresentationFields.NAME), getComponentRes.right().value());
- result = Either.right(getComponentRes.right().value());
- break;
- }
- T componentBySystemName = getComponentRes.left().value();
- log.debug("Found component, id: {}", componentBySystemName.getUniqueId());
- components.add(componentBySystemName);
- }
- }
- if (result == null) {
- result = Either.left(components);
- }
- return result;
- }
-
- public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVersion(ComponentTypeEnum componentType, String name, String version) {
- return getComponentByNameAndVersion(componentType, name, version, JsonParseFlagEnum.ParseAll);
- }
-
- public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVersion(ComponentTypeEnum componentType, String name, String version, JsonParseFlagEnum parseFlag) {
- Either<T, StorageOperationStatus> result;
-
- Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
- Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
-
- hasProperties.put(GraphPropertyEnum.NAME, name);
- hasProperties.put(GraphPropertyEnum.VERSION, version);
- hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true);
- if (componentType != null) {
- hasProperties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
- }
- Either<List<GraphVertex>, TitanOperationStatus> getResourceRes = titanDao.getByCriteria(null, hasProperties, hasNotProperties, parseFlag);
- if (getResourceRes.isRight()) {
- TitanOperationStatus status = getResourceRes.right().value();
- log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- return result;
- }
- return getToscaElementByOperation(getResourceRes.left().value().get(0));
- }
-
- public <T extends Component> Either<List<T>, StorageOperationStatus> getCatalogComponents(ComponentTypeEnum componentType, List<OriginTypeEnum> excludeTypes, boolean isHighestVersions) {
- List<T> components = new ArrayList<>();
- Either<List<ToscaElement>, StorageOperationStatus> catalogDataResult;
- List<ToscaElement> toscaElements = new ArrayList<>();
- List<ResourceTypeEnum> excludedResourceTypes =
- Optional.ofNullable(excludeTypes).orElse(Collections.emptyList())
- .stream()
- .filter(type -> !type.equals(OriginTypeEnum.SERVICE))
- .map(type -> ResourceTypeEnum.getTypeByName(type.name())).collect(Collectors.toList());
-
- switch (componentType) {
- case RESOURCE:
- catalogDataResult = nodeTypeOperation.getElementCatalogData(ComponentTypeEnum.RESOURCE,excludedResourceTypes , isHighestVersions);
- if (catalogDataResult.isRight()) {
- return Either.right(catalogDataResult.right().value());
- }
- toscaElements = catalogDataResult.left().value();
- break;
- case SERVICE:
- if (excludeTypes!= null && excludeTypes.contains(OriginTypeEnum.SERVICE)) {
- break;
- }
- catalogDataResult = topologyTemplateOperation.getElementCatalogData(ComponentTypeEnum.SERVICE, null, isHighestVersions);
- if (catalogDataResult.isRight()) {
- return Either.right(catalogDataResult.right().value());
- }
- toscaElements = catalogDataResult.left().value();
- break;
- default:
- log.debug("Not supported component type {}", componentType);
- return Either.right(StorageOperationStatus.BAD_REQUEST);
- }
- toscaElements.forEach(te -> {
- T component = ModelConverter.convertFromToscaElement(te);
- components.add(component);
- });
- return Either.left(components);
- }
-
- public Either<List<String>, StorageOperationStatus> deleteMarkedElements(ComponentTypeEnum componentType) {
- Either<List<GraphVertex>, StorageOperationStatus> allComponentsMarkedForDeletion;
- List<String> deleted = new ArrayList<>();
- switch (componentType) {
- case RESOURCE:
- allComponentsMarkedForDeletion = nodeTypeOperation.getAllComponentsMarkedForDeletion(componentType);
- break;
- case SERVICE:
- case PRODUCT:
- allComponentsMarkedForDeletion = topologyTemplateOperation.getAllComponentsMarkedForDeletion(componentType);
- break;
- default:
- log.debug("Not supported component type {}", componentType);
- return Either.right(StorageOperationStatus.BAD_REQUEST);
- }
- if (allComponentsMarkedForDeletion.isRight()) {
- return Either.right(allComponentsMarkedForDeletion.right().value());
- }
- List<GraphVertex> allMarked = allComponentsMarkedForDeletion.left().value();
-
- Either<List<GraphVertex>, TitanOperationStatus> allNotDeletedElements = topologyTemplateOperation.getAllNotDeletedElements();
- if (allNotDeletedElements.isRight()) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(allNotDeletedElements.right().value()));
- }
- List<GraphVertex> allNonMarked = allNotDeletedElements.left().value();
- for (GraphVertex elementV : allMarked) {
- if (topologyTemplateOperation.isInUse(elementV, allNonMarked) == false) {
- Either<ToscaElement, StorageOperationStatus> deleteToscaElement = deleteToscaElement(elementV);
- if (deleteToscaElement.isRight()) {
- log.debug("Failed to delete marked element {} error {}", elementV.getUniqueId(), deleteToscaElement.right().value());
- }
- } else {
- deleted.add(elementV.getUniqueId());
- log.debug("Marked element {} in use. don't delete it", elementV.getUniqueId());
- }
- }
- return Either.left(deleted);
- }
-
- public Either<List<String>, StorageOperationStatus> getAllComponentsMarkedForDeletion(ComponentTypeEnum componentType) {
- Either<List<GraphVertex>, StorageOperationStatus> allComponentsMarkedForDeletion;
- switch (componentType) {
- case RESOURCE:
- allComponentsMarkedForDeletion = nodeTypeOperation.getAllComponentsMarkedForDeletion(componentType);
- break;
- case SERVICE:
- case PRODUCT:
- allComponentsMarkedForDeletion = topologyTemplateOperation.getAllComponentsMarkedForDeletion(componentType);
- break;
- default:
- log.debug("Not supported component type {}", componentType);
- return Either.right(StorageOperationStatus.BAD_REQUEST);
- }
- if (allComponentsMarkedForDeletion.isRight()) {
- return Either.right(allComponentsMarkedForDeletion.right().value());
- }
- return Either.left(allComponentsMarkedForDeletion.left().value().stream().map(v -> v.getUniqueId()).collect(Collectors.toList()));
- }
-
- public Either<Boolean, StorageOperationStatus> isComponentInUse(String componentId) {
- Either<Boolean, StorageOperationStatus> result;
- Either<List<GraphVertex>, TitanOperationStatus> allNotDeletedElements = topologyTemplateOperation.getAllNotDeletedElements();
- if (allNotDeletedElements.isRight()) {
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(allNotDeletedElements.right().value()));
- } else {
- result = Either.left(topologyTemplateOperation.isInUse(componentId, allNotDeletedElements.left().value()));
- }
- return result;
- }
-
- public Either<ImmutablePair<Component, String>, StorageOperationStatus> addComponentInstanceToTopologyTemplate(Component containerComponent, Component origComponent, ComponentInstance componentInstance, boolean allowDeleted, User user) {
-
- Either<ImmutablePair<Component, String>, StorageOperationStatus> result = null;
- Either<ToscaElement, StorageOperationStatus> updateContainerComponentRes = null;
- componentInstance.setIcon(origComponent.getIcon());
- Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> addResult = nodeTemplateOperation.addComponentInstanceToTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent),
- ModelConverter.convertToToscaElement(origComponent), getNextComponentInstanceCounter(containerComponent, origComponent.getName()), componentInstance, allowDeleted, user);
-
- if (addResult.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the component instance {} to container component {}. ", componentInstance.getName(), containerComponent.getName());
- result = Either.right(addResult.right().value());
- }
- if (result == null) {
- updateContainerComponentRes = topologyTemplateOperation.getToscaElement(containerComponent.getUniqueId());
- if (updateContainerComponentRes.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch updated topology template {} with updated component instance {}. ", containerComponent.getName(), componentInstance.getName());
- result = Either.right(updateContainerComponentRes.right().value());
- }
- }
- if (result == null) {
- Component updatedComponent = ModelConverter.convertFromToscaElement(updateContainerComponentRes.left().value());
- String createdInstanceId = addResult.left().value().getRight();
- CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The component instance {} has been added to container component {}. ", createdInstanceId, updatedComponent.getName());
- result = Either.left(new ImmutablePair<>(updatedComponent, createdInstanceId));
- }
- return result;
- }
-
- public StorageOperationStatus associateComponentInstancesToComponent(Component containerComponent, Map<ComponentInstance, Resource> resourcesInstancesMap, boolean allowDeleted) {
-
- StorageOperationStatus result = null;
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Going to add component instances to component {}", containerComponent.getUniqueId());
-
- Either<GraphVertex, TitanOperationStatus> metadataVertex = titanDao.getVertexById(containerComponent.getUniqueId(), JsonParseFlagEnum.ParseAll);
- if (metadataVertex.isRight()) {
- TitanOperationStatus status = metadataVertex.right().value();
- if (status == TitanOperationStatus.NOT_FOUND) {
- status = TitanOperationStatus.INVALID_ID;
- }
- result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
- }
- if (result == null) {
- result = nodeTemplateOperation.associateComponentInstancesToComponent(containerComponent, resourcesInstancesMap, metadataVertex.left().value(), allowDeleted);
- }
- return result;
- }
-
- public Either<ImmutablePair<Component, String>, StorageOperationStatus> updateComponentInstanceMetadataOfTopologyTemplate(Component containerComponent, Component origComponent, ComponentInstance componentInstance) {
-
- Either<ImmutablePair<Component, String>, StorageOperationStatus> result = null;
-
- CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "Going to update the metadata of the component instance {} belonging to container component {}. ", componentInstance.getName(), containerComponent.getName());
- componentInstance.setIcon(origComponent.getIcon());
- Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> updateResult = nodeTemplateOperation.updateComponentInstanceMetadataOfTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent),
- ModelConverter.convertToToscaElement(origComponent), componentInstance);
- if (updateResult.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the metadata of the component instance {} belonging to container component {}. ", componentInstance.getName(), containerComponent.getName());
- result = Either.right(updateResult.right().value());
- }
- if (result == null) {
- Component updatedComponent = ModelConverter.convertFromToscaElement(updateResult.left().value().getLeft());
- String createdInstanceId = updateResult.left().value().getRight();
- CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The metadata of the component instance {} has been updated to container component {}. ", createdInstanceId, updatedComponent.getName());
- result = Either.left(new ImmutablePair<>(updatedComponent, createdInstanceId));
- }
- return result;
- }
-
- public Either<Component, StorageOperationStatus> updateComponentInstanceMetadataOfTopologyTemplate(Component containerComponent) {
-
- Either<Component, StorageOperationStatus> result = null;
-
- CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "Going to update the metadata belonging to container component {}. ", containerComponent.getName());
-
- Either<TopologyTemplate, StorageOperationStatus> updateResult = nodeTemplateOperation.updateComponentInstanceMetadataOfTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent));
- if (updateResult.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the metadata belonging to container component {}. ", containerComponent.getName());
- result = Either.right(updateResult.right().value());
- }
- if (result == null) {
- Component updatedComponent = ModelConverter.convertFromToscaElement(updateResult.left().value());
- CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The metadata has been updated to container component {}. ", updatedComponent.getName());
- result = Either.left(updatedComponent);
- }
- return result;
- }
-
- public Either<ImmutablePair<Component, String>, StorageOperationStatus> deleteComponentInstanceFromTopologyTemplate(Component containerComponent, String resourceInstanceId) {
-
- Either<ImmutablePair<Component, String>, StorageOperationStatus> result = null;
-
- CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "Going to delete the component instance {} belonging to container component {}. ", resourceInstanceId, containerComponent.getName());
-
- Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> updateResult = nodeTemplateOperation.deleteComponentInstanceFromTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent), resourceInstanceId);
- if (updateResult.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to delete the component instance {} belonging to container component {}. ", resourceInstanceId, containerComponent.getName());
- result = Either.right(updateResult.right().value());
- }
- if (result == null) {
- Component updatedComponent = ModelConverter.convertFromToscaElement(updateResult.left().value().getLeft());
- String deletedInstanceId = updateResult.left().value().getRight();
- CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The component instance {} has been deleted from container component {}. ", deletedInstanceId, updatedComponent.getName());
- result = Either.left(new ImmutablePair<>(updatedComponent, deletedInstanceId));
- }
- return result;
- }
-
- private String getNextComponentInstanceCounter(Component containerComponent, String originResourceName) {
-
- Integer nextCounter = 0;
-
- if (CollectionUtils.isNotEmpty(containerComponent.getComponentInstances())) {
-
- String normalizedName = ValidationUtils.normalizeComponentInstanceName(originResourceName);
- Integer maxCounterFromNames = getMaxCounterFromNames(containerComponent, normalizedName);
- Integer maxCounterFromIds = getMaxCounterFromIds(containerComponent, normalizedName);
-
- if (maxCounterFromNames == null && maxCounterFromIds != null) {
- nextCounter = maxCounterFromIds + 1;
- } else if (maxCounterFromIds == null && maxCounterFromNames != null) {
- nextCounter = maxCounterFromNames + 1;
- } else if (maxCounterFromIds != null && maxCounterFromNames != null) {
- nextCounter = maxCounterFromNames > maxCounterFromIds ? maxCounterFromNames + 1 : maxCounterFromIds + 1;
- }
- }
- return nextCounter.toString();
- }
-
- private Integer getMaxCounterFromNames(Component containerComponent, String normalizedName) {
-
- Integer maxCounter = 0;
- List<String> countersStr = containerComponent.getComponentInstances().stream().filter(ci -> ci.getNormalizedName() != null && ci.getNormalizedName().startsWith(normalizedName)).map(ci -> ci.getNormalizedName().split(normalizedName)[1])
- .collect(Collectors.toList());
-
- if (CollectionUtils.isEmpty(countersStr)) {
- return null;
- }
- Integer currCounter = null;
- for (String counter : countersStr) {
- if (StringUtils.isEmpty(counter)) {
- continue;
- }
- try {
- currCounter = Integer.parseInt(counter);
- } catch (Exception e) {
- continue;
- }
- maxCounter = maxCounter < currCounter ? currCounter : maxCounter;
- }
- if (currCounter == null) {
- return null;
- }
- return maxCounter;
- }
-
- private Integer getMaxCounterFromIds(Component containerComponent, String normalizedName) {
-
- Integer maxCounter = 0;
- List<String> countersStr = containerComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId() != null && ci.getUniqueId().contains(normalizedName)).map(ci -> ci.getUniqueId().split(normalizedName)[1])
- .collect(Collectors.toList());
-
- if (CollectionUtils.isEmpty(countersStr)) {
- return null;
- }
- Integer currCounter = null;
- for (String counter : countersStr) {
- if (StringUtils.isEmpty(counter)) {
- continue;
- }
- try {
- currCounter = Integer.parseInt(counter);
- } catch (Exception e) {
- continue;
- }
- maxCounter = maxCounter < currCounter ? currCounter : maxCounter;
- }
- if (currCounter == null) {
- return null;
- }
- return maxCounter;
- }
-
- public Either<RequirementCapabilityRelDef, StorageOperationStatus> associateResourceInstances(String componentId, RequirementCapabilityRelDef requirementDef) {
- return nodeTemplateOperation.associateResourceInstances(componentId, requirementDef);
-
- }
-
- public Either<List<InputDefinition>, StorageOperationStatus> createAndAssociateInputs(Map<String, InputDefinition> inputs, String componentId) {
-
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
-
- }
-
- GraphVertex vertex = getVertexEither.left().value();
- Map<String, PropertyDataDefinition> inputsMap = inputs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new PropertyDataDefinition(e.getValue())));
-
- StorageOperationStatus status = topologyTemplateOperation.associateInputsToComponent(vertex, inputsMap, componentId);
-
- if (StorageOperationStatus.OK == status) {
- log.debug("Component created successfully!!!");
- List<InputDefinition> inputsResList = null;
- if (inputsMap != null && !inputsMap.isEmpty()) {
- inputsResList = inputsMap.values().stream().map(i -> new InputDefinition(i)).collect(Collectors.toList());
- }
- return Either.left(inputsResList);
- }
- return Either.right(status);
-
- }
-
- public Either<List<InputDefinition>, StorageOperationStatus> addInputsToComponent(Map<String, InputDefinition> inputs, String componentId) {
-
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
-
- }
-
- GraphVertex vertex = getVertexEither.left().value();
- Map<String, PropertyDataDefinition> inputsMap = inputs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new PropertyDataDefinition(e.getValue())));
-
- StorageOperationStatus status = topologyTemplateOperation.addToscaDataToToscaElement(vertex, EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, inputsMap, JsonPresentationFields.NAME);
-
- if (StorageOperationStatus.OK == status) {
- log.debug("Component created successfully!!!");
- List<InputDefinition> inputsResList = null;
- if (inputsMap != null && !inputsMap.isEmpty()) {
- inputsResList = inputsMap.values().stream().map(i -> new InputDefinition(i)).collect(Collectors.toList());
- }
- return Either.left(inputsResList);
- }
- return Either.right(status);
-
- }
-
- public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> associateComponentInstancePropertiesToComponent(Map<String, List<ComponentInstanceProperty>> instProperties, String componentId) {
-
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
-
- }
-
- GraphVertex vertex = getVertexEither.left().value();
- Map<String, MapPropertiesDataDefinition> instPropsMap = new HashMap<>();
- if (instProperties != null) {
-
- MapPropertiesDataDefinition propertiesMap;
- for (Entry<String, List<ComponentInstanceProperty>> entry : instProperties.entrySet()) {
- propertiesMap = new MapPropertiesDataDefinition();
-
- propertiesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
-
- instPropsMap.put(entry.getKey(), propertiesMap);
- }
- }
-
- StorageOperationStatus status = topologyTemplateOperation.associateInstPropertiesToComponent(vertex, instPropsMap);
-
- if (StorageOperationStatus.OK == status) {
- log.debug("Component created successfully!!!");
- return Either.left(instProperties);
- }
- return Either.right(status);
+ // endregion
+ // region - Component Get By ..
+ private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName) {
+ return getLatestByName(property, nodeName, JsonParseFlagEnum.ParseMetadata);
+ }
+
+ public <T extends Component> Either<List<T>, StorageOperationStatus> getBySystemName(ComponentTypeEnum componentType, String systemName) {
+
+ Either<List<T>, StorageOperationStatus> result = null;
+ Either<T, StorageOperationStatus> getComponentRes;
+ List<T> components = new ArrayList<>();
+ List<GraphVertex> componentVertices;
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+
+ propertiesToMatch.put(GraphPropertyEnum.SYSTEM_NAME, systemName);
+ if (componentType != null)
+ propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+
+ Either<List<GraphVertex>, TitanOperationStatus> getComponentsRes = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
+ if (getComponentsRes.isRight()) {
+ TitanOperationStatus status = getComponentsRes.right().value();
+ log.debug("Failed to fetch the component with system name {}. Status is {} ", systemName, status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ if (result == null) {
+ componentVertices = getComponentsRes.left().value();
+ for (GraphVertex componentVertex : componentVertices) {
+ getComponentRes = getToscaElementByOperation(componentVertex);
+ if (getComponentRes.isRight()) {
+ log.debug("Failed to get the component {}. Status is {} ", componentVertex.getJsonMetadataField(JsonPresentationFields.NAME), getComponentRes.right().value());
+ result = Either.right(getComponentRes.right().value());
+ break;
+ }
+ T componentBySystemName = getComponentRes.left().value();
+ log.debug("Found component, id: {}", componentBySystemName.getUniqueId());
+ components.add(componentBySystemName);
+ }
+ }
+ if (result == null) {
+ result = Either.left(components);
+ }
+ return result;
+ }
+
+ public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVersion(ComponentTypeEnum componentType, String name, String version) {
+ return getComponentByNameAndVersion(componentType, name, version, JsonParseFlagEnum.ParseAll);
+ }
+
+ public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVersion(ComponentTypeEnum componentType, String name, String version, JsonParseFlagEnum parseFlag) {
+ Either<T, StorageOperationStatus> result;
+
+ Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
+
+ hasProperties.put(GraphPropertyEnum.NAME, name);
+ hasProperties.put(GraphPropertyEnum.VERSION, version);
+ hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true);
+ if (componentType != null) {
+ hasProperties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+ }
+ Either<List<GraphVertex>, TitanOperationStatus> getResourceRes = titanDao.getByCriteria(null, hasProperties, hasNotProperties, parseFlag);
+ if (getResourceRes.isRight()) {
+ TitanOperationStatus status = getResourceRes.right().value();
+ log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return result;
+ }
+ return getToscaElementByOperation(getResourceRes.left().value().get(0));
+ }
+
+ // endregion
+ public <T extends Component> Either<List<T>, StorageOperationStatus> getCatalogComponents(ComponentTypeEnum componentType, List<OriginTypeEnum> excludeTypes, boolean isHighestVersions) {
+ List<T> components = new ArrayList<>();
+ Either<List<ToscaElement>, StorageOperationStatus> catalogDataResult;
+ List<ToscaElement> toscaElements = new ArrayList<>();
+ List<ResourceTypeEnum> excludedResourceTypes = Optional.ofNullable(excludeTypes).orElse(Collections.emptyList()).stream().filter(type -> !type.equals(OriginTypeEnum.SERVICE)).map(type -> ResourceTypeEnum.getTypeByName(type.name()))
+ .collect(Collectors.toList());
+
+ switch (componentType) {
+ case RESOURCE:
+ catalogDataResult = nodeTypeOperation.getElementCatalogData(ComponentTypeEnum.RESOURCE, excludedResourceTypes, isHighestVersions);
+ if (catalogDataResult.isRight()) {
+ return Either.right(catalogDataResult.right().value());
+ }
+ toscaElements = catalogDataResult.left().value();
+ break;
+ case SERVICE:
+ if (excludeTypes != null && excludeTypes.contains(OriginTypeEnum.SERVICE)) {
+ break;
+ }
+ catalogDataResult = topologyTemplateOperation.getElementCatalogData(ComponentTypeEnum.SERVICE, null, isHighestVersions);
+ if (catalogDataResult.isRight()) {
+ return Either.right(catalogDataResult.right().value());
+ }
+ toscaElements = catalogDataResult.left().value();
+ break;
+ default:
+ log.debug("Not supported component type {}", componentType);
+ return Either.right(StorageOperationStatus.BAD_REQUEST);
+ }
+ toscaElements.forEach(te -> {
+ T component = ModelConverter.convertFromToscaElement(te);
+ components.add(component);
+ });
+ return Either.left(components);
+ }
+
+ public Either<List<String>, StorageOperationStatus> deleteMarkedElements(ComponentTypeEnum componentType) {
+ Either<List<GraphVertex>, StorageOperationStatus> allComponentsMarkedForDeletion;
+ List<String> deleted = new ArrayList<>();
+ switch (componentType) {
+ case RESOURCE:
+ allComponentsMarkedForDeletion = nodeTypeOperation.getAllComponentsMarkedForDeletion(componentType);
+ break;
+ case SERVICE:
+ case PRODUCT:
+ allComponentsMarkedForDeletion = topologyTemplateOperation.getAllComponentsMarkedForDeletion(componentType);
+ break;
+ default:
+ log.debug("Not supported component type {}", componentType);
+ return Either.right(StorageOperationStatus.BAD_REQUEST);
+ }
+ if (allComponentsMarkedForDeletion.isRight()) {
+ return Either.right(allComponentsMarkedForDeletion.right().value());
+ }
+ List<GraphVertex> allMarked = allComponentsMarkedForDeletion.left().value();
+
+ Either<List<GraphVertex>, TitanOperationStatus> allNotDeletedElements = topologyTemplateOperation.getAllNotDeletedElements();
+ if (allNotDeletedElements.isRight()) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(allNotDeletedElements.right().value()));
+ }
+ List<GraphVertex> allNonMarked = allNotDeletedElements.left().value();
+ for (GraphVertex elementV : allMarked) {
+ if (topologyTemplateOperation.isInUse(elementV, allNonMarked) == false) {
+ Either<ToscaElement, StorageOperationStatus> deleteToscaElement = deleteToscaElement(elementV);
+ if (deleteToscaElement.isRight()) {
+ log.debug("Failed to delete marked element {} error {}", elementV.getUniqueId(), deleteToscaElement.right().value());
+ }
+ } else {
+ deleted.add(elementV.getUniqueId());
+ log.debug("Marked element {} in use. don't delete it", elementV.getUniqueId());
+ }
+ }
+ return Either.left(deleted);
+ }
+
+ public Either<List<String>, StorageOperationStatus> getAllComponentsMarkedForDeletion(ComponentTypeEnum componentType) {
+ Either<List<GraphVertex>, StorageOperationStatus> allComponentsMarkedForDeletion;
+ switch (componentType) {
+ case RESOURCE:
+ allComponentsMarkedForDeletion = nodeTypeOperation.getAllComponentsMarkedForDeletion(componentType);
+ break;
+ case SERVICE:
+ case PRODUCT:
+ allComponentsMarkedForDeletion = topologyTemplateOperation.getAllComponentsMarkedForDeletion(componentType);
+ break;
+ default:
+ log.debug("Not supported component type {}", componentType);
+ return Either.right(StorageOperationStatus.BAD_REQUEST);
+ }
+ if (allComponentsMarkedForDeletion.isRight()) {
+ return Either.right(allComponentsMarkedForDeletion.right().value());
+ }
+ return Either.left(allComponentsMarkedForDeletion.left().value().stream().map(v -> v.getUniqueId()).collect(Collectors.toList()));
+ }
+
+ public Either<Boolean, StorageOperationStatus> isComponentInUse(String componentId) {
+ Either<Boolean, StorageOperationStatus> result;
+ Either<List<GraphVertex>, TitanOperationStatus> allNotDeletedElements = topologyTemplateOperation.getAllNotDeletedElements();
+ if (allNotDeletedElements.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(allNotDeletedElements.right().value()));
+ } else {
+ result = Either.left(topologyTemplateOperation.isInUse(componentId, allNotDeletedElements.left().value()));
+ }
+ return result;
+ }
+
+ // region - Component Update
+ public Either<ImmutablePair<Component, String>, StorageOperationStatus> addComponentInstanceToTopologyTemplate(Component containerComponent, Component origComponent, ComponentInstance componentInstance, boolean allowDeleted, User user) {
+
+ Either<ImmutablePair<Component, String>, StorageOperationStatus> result = null;
+ Either<ToscaElement, StorageOperationStatus> updateContainerComponentRes = null;
+ if (StringUtils.isEmpty(componentInstance.getIcon())) {
+ componentInstance.setIcon(origComponent.getIcon());
+ }
+ String nameToFindForCounter = componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy ? PROXY_SUFFIX : origComponent.getName();
+ String nextComponentInstanceCounter = getNextComponentInstanceCounter(containerComponent, nameToFindForCounter);
+ Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> addResult = nodeTemplateOperation.addComponentInstanceToTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent),
+ ModelConverter.convertToToscaElement(origComponent), nextComponentInstanceCounter, componentInstance, allowDeleted, user);
+
+ if (addResult.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the component instance {} to container component {}. ", componentInstance.getName(), containerComponent.getName());
+ result = Either.right(addResult.right().value());
+ }
+ if (result == null) {
+ updateContainerComponentRes = topologyTemplateOperation.getToscaElement(containerComponent.getUniqueId());
+ if (updateContainerComponentRes.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch updated topology template {} with updated component instance {}. ", containerComponent.getName(), componentInstance.getName());
+ result = Either.right(updateContainerComponentRes.right().value());
+ }
+ }
+ if (result == null) {
+ Component updatedComponent = ModelConverter.convertFromToscaElement(updateContainerComponentRes.left().value());
+ String createdInstanceId = addResult.left().value().getRight();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The component instance {} has been added to container component {}. ", createdInstanceId, updatedComponent.getName());
+ result = Either.left(new ImmutablePair<>(updatedComponent, createdInstanceId));
+ }
+ return result;
+ }
+
+ public StorageOperationStatus associateComponentInstancesToComponent(Component containerComponent, Map<ComponentInstance, Resource> resourcesInstancesMap, boolean allowDeleted) {
+
+ StorageOperationStatus result = null;
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Going to add component instances to component {}", containerComponent.getUniqueId());
+
+ Either<GraphVertex, TitanOperationStatus> metadataVertex = titanDao.getVertexById(containerComponent.getUniqueId(), JsonParseFlagEnum.ParseAll);
+ if (metadataVertex.isRight()) {
+ TitanOperationStatus status = metadataVertex.right().value();
+ if (status == TitanOperationStatus.NOT_FOUND) {
+ status = TitanOperationStatus.INVALID_ID;
+ }
+ result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
+ }
+ if (result == null) {
+ result = nodeTemplateOperation.associateComponentInstancesToComponent(containerComponent, resourcesInstancesMap, metadataVertex.left().value(), allowDeleted);
+ }
+ return result;
+ }
+
+ public Either<ImmutablePair<Component, String>, StorageOperationStatus> updateComponentInstanceMetadataOfTopologyTemplate(Component containerComponent, Component origComponent, ComponentInstance componentInstance) {
+
+ Either<ImmutablePair<Component, String>, StorageOperationStatus> result = null;
+
+ CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "Going to update the metadata of the component instance {} belonging to container component {}. ", componentInstance.getName(), containerComponent.getName());
+ componentInstance.setIcon(origComponent.getIcon());
+ Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> updateResult = nodeTemplateOperation.updateComponentInstanceMetadataOfTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent),
+ ModelConverter.convertToToscaElement(origComponent), componentInstance);
+ if (updateResult.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the metadata of the component instance {} belonging to container component {}. ", componentInstance.getName(), containerComponent.getName());
+ result = Either.right(updateResult.right().value());
+ }
+ if (result == null) {
+ Component updatedComponent = ModelConverter.convertFromToscaElement(updateResult.left().value().getLeft());
+ String createdInstanceId = updateResult.left().value().getRight();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The metadata of the component instance {} has been updated to container component {}. ", createdInstanceId, updatedComponent.getName());
+ result = Either.left(new ImmutablePair<>(updatedComponent, createdInstanceId));
+ }
+ return result;
+ }
+
+ public Either<Component, StorageOperationStatus> updateComponentInstanceMetadataOfTopologyTemplate(Component containerComponent) {
+ return updateComponentInstanceMetadataOfTopologyTemplate(containerComponent, new ComponentParametersView());
+ }
+
+ public Either<Component, StorageOperationStatus> updateComponentInstanceMetadataOfTopologyTemplate(Component containerComponent, ComponentParametersView filter) {
+
+ Either<Component, StorageOperationStatus> result = null;
+
+ CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "Going to update the metadata belonging to container component {}. ", containerComponent.getName());
+
+ Either<TopologyTemplate, StorageOperationStatus> updateResult = nodeTemplateOperation.updateComponentInstanceMetadataOfTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent), filter);
+ if (updateResult.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the metadata belonging to container component {}. ", containerComponent.getName());
+ result = Either.right(updateResult.right().value());
+ }
+ if (result == null) {
+ Component updatedComponent = ModelConverter.convertFromToscaElement(updateResult.left().value());
+ CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The metadata has been updated to container component {}. ", updatedComponent.getName());
+ result = Either.left(updatedComponent);
+ }
+ return result;
+ }
+ // endregion
+
+ public Either<ImmutablePair<Component, String>, StorageOperationStatus> deleteComponentInstanceFromTopologyTemplate(Component containerComponent, String resourceInstanceId) {
+
+ Either<ImmutablePair<Component, String>, StorageOperationStatus> result = null;
+
+ CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "Going to delete the component instance {} belonging to container component {}. ", resourceInstanceId, containerComponent.getName());
+
+ Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> updateResult = nodeTemplateOperation.deleteComponentInstanceFromTopologyTemplate(ModelConverter.convertToToscaElement(containerComponent), resourceInstanceId);
+ if (updateResult.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to delete the component instance {} belonging to container component {}. ", resourceInstanceId, containerComponent.getName());
+ result = Either.right(updateResult.right().value());
+ }
+ if (result == null) {
+ Component updatedComponent = ModelConverter.convertFromToscaElement(updateResult.left().value().getLeft());
+ String deletedInstanceId = updateResult.left().value().getRight();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.TRACE, "The component instance {} has been deleted from container component {}. ", deletedInstanceId, updatedComponent.getName());
+ result = Either.left(new ImmutablePair<>(updatedComponent, deletedInstanceId));
+ }
+ return result;
+ }
+
+ private String getNextComponentInstanceCounter(Component containerComponent, String originResourceName) {
+
+ Integer nextCounter = 0;
+
+ if (CollectionUtils.isNotEmpty(containerComponent.getComponentInstances())) {
+
+ String normalizedName = ValidationUtils.normalizeComponentInstanceName(originResourceName);
+ Integer maxCounterFromNames = getMaxCounterFromNames(containerComponent, normalizedName);
+ Integer maxCounterFromIds = getMaxCounterFromIds(containerComponent, normalizedName);
+
+ if (maxCounterFromNames == null && maxCounterFromIds != null) {
+ nextCounter = maxCounterFromIds + 1;
+ } else if (maxCounterFromIds == null && maxCounterFromNames != null) {
+ nextCounter = maxCounterFromNames + 1;
+ } else if (maxCounterFromIds != null && maxCounterFromNames != null) {
+ nextCounter = maxCounterFromNames > maxCounterFromIds ? maxCounterFromNames + 1 : maxCounterFromIds + 1;
+ }
+ }
+ return nextCounter.toString();
+ }
+
+ private Integer getMaxCounterFromNames(Component containerComponent, String normalizedName) {
+
+ Integer maxCounter = 0;
+ List<String> countersStr = containerComponent.getComponentInstances().stream().filter(ci -> ci.getNormalizedName() != null && ci.getNormalizedName().startsWith(normalizedName)).map(ci -> ci.getNormalizedName().split(normalizedName)[1])
+ .collect(Collectors.toList());
+
+ if (CollectionUtils.isEmpty(countersStr)) {
+ return null;
+ }
+ Integer currCounter = null;
+ for (String counter : countersStr) {
+ if (StringUtils.isEmpty(counter)) {
+ continue;
+ }
+ try {
+ currCounter = Integer.parseInt(counter);
+ } catch (Exception e) {
+ continue;
+ }
+ maxCounter = maxCounter < currCounter ? currCounter : maxCounter;
+ }
+ if (currCounter == null) {
+ return null;
+ }
+ return maxCounter;
+ }
+
+ private Integer getMaxCounterFromIds(Component containerComponent, String normalizedName) {
+
+ Integer maxCounter = 0;
+ List<String> countersStr = containerComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId() != null && ci.getUniqueId().contains(normalizedName)).map(ci -> ci.getUniqueId().split(normalizedName)[1])
+ .collect(Collectors.toList());
+
+ if (CollectionUtils.isEmpty(countersStr)) {
+ return null;
+ }
+ Integer currCounter = null;
+ for (String counter : countersStr) {
+ if (StringUtils.isEmpty(counter)) {
+ continue;
+ }
+ try {
+ currCounter = Integer.parseInt(counter);
+ } catch (Exception e) {
+ continue;
+ }
+ maxCounter = maxCounter < currCounter ? currCounter : maxCounter;
+ }
+ if (currCounter == null) {
+ return null;
+ }
+ return maxCounter;
+ }
+
+ public Either<RequirementCapabilityRelDef, StorageOperationStatus> associateResourceInstances(String componentId, RequirementCapabilityRelDef requirementDef) {
+ return nodeTemplateOperation.associateResourceInstances(componentId, requirementDef);
+
+ }
+
+ public Either<List<InputDefinition>, StorageOperationStatus> createAndAssociateInputs(Map<String, InputDefinition> inputs, String componentId) {
+
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+
+ }
+
+ GraphVertex vertex = getVertexEither.left().value();
+ Map<String, PropertyDataDefinition> inputsMap = inputs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new PropertyDataDefinition(e.getValue())));
+
+ StorageOperationStatus status = topologyTemplateOperation.associateInputsToComponent(vertex, inputsMap, componentId);
+
+ if (StorageOperationStatus.OK == status) {
+ log.debug("Component created successfully!!!");
+ List<InputDefinition> inputsResList = null;
+ if (inputsMap != null && !inputsMap.isEmpty()) {
+ inputsResList = inputsMap.values().stream().map(i -> new InputDefinition(i)).collect(Collectors.toList());
+ }
+ return Either.left(inputsResList);
+ }
+ return Either.right(status);
+
+ }
+
+ public Either<List<InputDefinition>, StorageOperationStatus> addInputsToComponent(Map<String, InputDefinition> inputs, String componentId) {
+
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+
+ }
+
+ GraphVertex vertex = getVertexEither.left().value();
+ Map<String, PropertyDataDefinition> inputsMap = inputs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new PropertyDataDefinition(e.getValue())));
+
+ StorageOperationStatus status = topologyTemplateOperation.addToscaDataToToscaElement(vertex, EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, inputsMap, JsonPresentationFields.NAME);
+
+ if (StorageOperationStatus.OK == status) {
+ log.debug("Component created successfully!!!");
+ List<InputDefinition> inputsResList = null;
+ if (inputsMap != null && !inputsMap.isEmpty()) {
+ inputsResList = inputsMap.values().stream().map(i -> new InputDefinition(i)).collect(Collectors.toList());
+ }
+ return Either.left(inputsResList);
+ }
+ return Either.right(status);
+
+ }
+
+ public Either<List<InputDefinition>, StorageOperationStatus> updateInputsToComponent(List<InputDefinition> inputs, String componentId) {
+
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+
+ }
+
+ GraphVertex vertex = getVertexEither.left().value();
+ List<PropertyDataDefinition> inputsAsDataDef = inputs.stream().map(PropertyDataDefinition::new).collect(Collectors.toList());
+
+ StorageOperationStatus status = topologyTemplateOperation.updateToscaDataOfToscaElement(vertex, EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, inputsAsDataDef, JsonPresentationFields.NAME);
+
+ if (StorageOperationStatus.OK == status) {
+ log.debug("Component created successfully!!!");
+ List<InputDefinition> inputsResList = null;
+ if (inputsAsDataDef != null && !inputsAsDataDef.isEmpty()) {
+ inputsResList = inputsAsDataDef.stream().map(InputDefinition::new).collect(Collectors.toList());
+ }
+ return Either.left(inputsResList);
+ }
+ return Either.right(status);
+
+ }
+
+ // region - ComponentInstance
+ public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> associateComponentInstancePropertiesToComponent(Map<String, List<ComponentInstanceProperty>> instProperties, String componentId) {
+
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+
+ }
+
+ GraphVertex vertex = getVertexEither.left().value();
+ Map<String, MapPropertiesDataDefinition> instPropsMap = new HashMap<>();
+ if (instProperties != null) {
+
+ MapPropertiesDataDefinition propertiesMap;
+ for (Entry<String, List<ComponentInstanceProperty>> entry : instProperties.entrySet()) {
+ propertiesMap = new MapPropertiesDataDefinition();
+
+ propertiesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
+
+ instPropsMap.put(entry.getKey(), propertiesMap);
+ }
+ }
+
+ StorageOperationStatus status = topologyTemplateOperation.associateInstPropertiesToComponent(vertex, instPropsMap);
+
+ if (StorageOperationStatus.OK == status) {
+ log.debug("Component created successfully!!!");
+ return Either.left(instProperties);
+ }
+ return Either.right(status);
+
+ }
+
+ /**
+ * saves the instInputs as the updated instance inputs of the component container in DB
+ * @param instInputs
+ * @param componentId
+ * @return
+ */
+ public Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> updateComponentInstanceInputsToComponent(Map<String, List<ComponentInstanceInput>> instInputs, String componentId) {
+ if (instInputs == null || instInputs.isEmpty()) {
+ return Either.left(instInputs);
+ }
+ StorageOperationStatus status;
+ for ( Entry<String, List<ComponentInstanceInput>> inputsPerIntance : instInputs.entrySet() ) {
+ List<ComponentInstanceInput> toscaDataListPerInst = inputsPerIntance.getValue();
+ List<String> pathKeysPerInst = new ArrayList<>();
+ pathKeysPerInst.add(inputsPerIntance.getKey());
+ status = topologyTemplateOperation.updateToscaDataDeepElementsOfToscaElement(componentId, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, toscaDataListPerInst, pathKeysPerInst, JsonPresentationFields.NAME);
+ if ( status != StorageOperationStatus.OK) {
+ log.debug("Failed to update component instance inputs for instance {} in component {} edge type {} error {}", inputsPerIntance.getKey(), componentId, EdgeLabelEnum.INST_INPUTS, status);
+ return Either.right(status);
+ }
+ }
+
+ return Either.left(instInputs);
+ }
+
+ /**
+ * saves the instProps as the updated instance properties of the component container in DB
+ * @param instProps
+ * @param componentId
+ * @return
+ */
+ public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> updateComponentInstancePropsToComponent(Map<String, List<ComponentInstanceProperty>> instProps, String componentId) {
+ if (instProps == null || instProps.isEmpty()) {
+ return Either.left(instProps);
+ }
+ StorageOperationStatus status;
+ for ( Entry<String, List<ComponentInstanceProperty>> propsPerIntance : instProps.entrySet() ) {
+ List<ComponentInstanceProperty> toscaDataListPerInst = propsPerIntance.getValue();
+ List<String> pathKeysPerInst = new ArrayList<>();
+ pathKeysPerInst.add(propsPerIntance.getKey());
+ status = topologyTemplateOperation.updateToscaDataDeepElementsOfToscaElement(componentId, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, toscaDataListPerInst, pathKeysPerInst, JsonPresentationFields.NAME);
+ if ( status != StorageOperationStatus.OK) {
+ log.debug("Failed to update component instance inputs for instance {} in component {} edge type {} error {}", propsPerIntance.getKey(), componentId, EdgeLabelEnum.INST_PROPERTIES, status);
+ return Either.right(status);
+ }
+ }
+
+ return Either.left(instProps);
+ }
- }
public Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> associateComponentInstanceInputsToComponent(Map<String, List<ComponentInstanceInput>> instInputs, String componentId) {
Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
@@ -1050,1205 +1186,1196 @@ public class ToscaOperationFacade {
return Either.right(status);
}
- public Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> addComponentInstanceInputsToComponent(Component containerComponent, Map<String, List<ComponentInstanceInput>> instProperties) {
-
- StorageOperationStatus status = StorageOperationStatus.OK;
- if (instProperties != null) {
-
- for (Entry<String, List<ComponentInstanceInput>> entry : instProperties.entrySet()) {
- List<ComponentInstanceInput> props = entry.getValue();
- String componentInstanseId = entry.getKey();
- if (props != null && !props.isEmpty()) {
- for (ComponentInstanceInput property : props) {
- List<ComponentInstanceInput> componentInstancesInputs = containerComponent.getComponentInstancesInputs().get(componentInstanseId);
- Optional<ComponentInstanceInput> instanceProperty = componentInstancesInputs.stream().filter(p -> p.getName().equals(property.getName())).findAny();
- if (instanceProperty.isPresent()) {
- status = updateComponentInstanceInput(containerComponent, componentInstanseId, property);
- } else {
- status = addComponentInstanceInput(containerComponent, componentInstanseId, property);
- }
- if (status != StorageOperationStatus.OK) {
- log.debug("Failed to update instance input {} for instance {} error {} ", property, componentInstanseId, status);
- return Either.right(status);
- } else {
- log.trace("instance input {} for instance {} updated", property, componentInstanseId);
- }
- }
- }
- }
- }
- return Either.left(instProperties);
- }
-
- public StorageOperationStatus deleteComponentInstanceInputsToComponent(Map<String, List<ComponentInstanceInput>> instProperties, String componentId) {
-
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
- }
+ public Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> addComponentInstanceInputsToComponent(Component containerComponent, Map<String, List<ComponentInstanceInput>> instProperties) {
+
+ StorageOperationStatus status = StorageOperationStatus.OK;
+ if (instProperties != null) {
+
+ for (Entry<String, List<ComponentInstanceInput>> entry : instProperties.entrySet()) {
+ List<ComponentInstanceInput> props = entry.getValue();
+ String componentInstanseId = entry.getKey();
+ if (props != null && !props.isEmpty()) {
+ for (ComponentInstanceInput property : props) {
+ List<ComponentInstanceInput> componentInstancesInputs = containerComponent.getComponentInstancesInputs().get(componentInstanseId);
+ Optional<ComponentInstanceInput> instanceProperty = componentInstancesInputs.stream().filter(p -> p.getName().equals(property.getName())).findAny();
+ if (instanceProperty.isPresent()) {
+ status = updateComponentInstanceInput(containerComponent, componentInstanseId, property);
+ } else {
+ status = addComponentInstanceInput(containerComponent, componentInstanseId, property);
+ }
+ if (status != StorageOperationStatus.OK) {
+ log.debug("Failed to update instance input {} for instance {} error {} ", property, componentInstanseId, status);
+ return Either.right(status);
+ } else {
+ log.trace("instance input {} for instance {} updated", property, componentInstanseId);
+ }
+ }
+ }
+ }
+ }
+ return Either.left(instProperties);
+ }
- GraphVertex vertex = getVertexEither.left().value();
- Map<String, MapPropertiesDataDefinition> instPropsMap = new HashMap<>();
- if (instProperties != null) {
+ public StorageOperationStatus deleteComponentInstanceInputsToComponent(Map<String, List<ComponentInstanceInput>> instProperties, String componentId) {
- MapPropertiesDataDefinition propertiesMap;
- for (Entry<String, List<ComponentInstanceInput>> entry : instProperties.entrySet()) {
- propertiesMap = new MapPropertiesDataDefinition();
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
- propertiesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
+ }
- instPropsMap.put(entry.getKey(), propertiesMap);
- }
- }
+ GraphVertex vertex = getVertexEither.left().value();
+ Map<String, MapPropertiesDataDefinition> instPropsMap = new HashMap<>();
+ if (instProperties != null) {
- return topologyTemplateOperation.deleteInstInputsToComponent(vertex, instPropsMap);
+ MapPropertiesDataDefinition propertiesMap;
+ for (Entry<String, List<ComponentInstanceInput>> entry : instProperties.entrySet()) {
+ propertiesMap = new MapPropertiesDataDefinition();
- }
+ propertiesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
- public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addComponentInstancePropertiesToComponent(Component containerComponent, Map<String, List<ComponentInstanceProperty>> instProperties, String componentId) {
+ instPropsMap.put(entry.getKey(), propertiesMap);
+ }
+ }
- StorageOperationStatus status = StorageOperationStatus.OK;
- if (instProperties != null) {
+ return topologyTemplateOperation.deleteInstInputsToComponent(vertex, instPropsMap);
- for (Entry<String, List<ComponentInstanceProperty>> entry : instProperties.entrySet()) {
- List<ComponentInstanceProperty> props = entry.getValue();
- String componentInstanseId = entry.getKey();
- List<ComponentInstanceProperty> instanceProperties = containerComponent.getComponentInstancesProperties().get(componentInstanseId);
- if (props != null && !props.isEmpty()) {
- for (ComponentInstanceProperty property : props) {
- Optional<ComponentInstanceProperty> instanceProperty = instanceProperties.stream().filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny();
- if (instanceProperty.isPresent()) {
- status = updateComponentInstanceProperty(containerComponent, componentInstanseId, property);
- } else {
- status = addComponentInstanceProperty(containerComponent, componentInstanseId, property);
- }
+ }
- }
- }
- }
- }
+ public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addComponentInstancePropertiesToComponent(Component containerComponent, Map<String, List<ComponentInstanceProperty>> instProperties, String componentId) {
- return Either.left(instProperties);
+ if (instProperties != null) {
- }
+ for (Entry<String, List<ComponentInstanceProperty>> entry : instProperties.entrySet()) {
+ List<ComponentInstanceProperty> props = entry.getValue();
+ String componentInstanseId = entry.getKey();
+ List<ComponentInstanceProperty> instanceProperties = containerComponent.getComponentInstancesProperties().get(componentInstanseId);
+ if (props != null && !props.isEmpty()) {
+ for (ComponentInstanceProperty property : props) {
+ Optional<ComponentInstanceProperty> instanceProperty = instanceProperties.stream().filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny();
+ if (instanceProperty.isPresent()) {
+ updateComponentInstanceProperty(containerComponent, componentInstanseId, property);
+ } else {
+ addComponentInstanceProperty(containerComponent, componentInstanseId, property);
+ }
- public StorageOperationStatus associateDeploymentArtifactsToInstances(Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts, String componentId, User user) {
+ }
+ }
+ }
+ }
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
+ return Either.left(instProperties);
- }
+ }
- GraphVertex vertex = getVertexEither.left().value();
- Map<String, MapArtifactDataDefinition> instArtMap = new HashMap<>();
- if (instDeploymentArtifacts != null) {
+ public StorageOperationStatus associateDeploymentArtifactsToInstances(Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts, String componentId, User user) {
- MapArtifactDataDefinition artifactsMap;
- for (Entry<String, Map<String, ArtifactDefinition>> entry : instDeploymentArtifacts.entrySet()) {
- Map<String, ArtifactDefinition> artList = entry.getValue();
- Map<String, ArtifactDataDefinition> artifacts = artList.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
- artifactsMap = nodeTemplateOperation.prepareInstDeploymentArtifactPerInstance(artifacts, entry.getKey(), user, NodeTemplateOperation.HEAT_VF_ENV_NAME);
-
- instArtMap.put(entry.getKey(), artifactsMap);
- }
- }
-
- return topologyTemplateOperation.associateInstDeploymentArtifactsToComponent(vertex, instArtMap);
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
- }
-
- public StorageOperationStatus associateArtifactsToInstances(Map<String, Map<String, ArtifactDefinition>> instArtifacts, String componentId, User user) {
+ }
+
+ GraphVertex vertex = getVertexEither.left().value();
+ Map<String, MapArtifactDataDefinition> instArtMap = new HashMap<>();
+ if (instDeploymentArtifacts != null) {
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
+ MapArtifactDataDefinition artifactsMap;
+ for (Entry<String, Map<String, ArtifactDefinition>> entry : instDeploymentArtifacts.entrySet()) {
+ Map<String, ArtifactDefinition> artList = entry.getValue();
+ Map<String, ArtifactDataDefinition> artifacts = artList.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
+ artifactsMap = nodeTemplateOperation.prepareInstDeploymentArtifactPerInstance(artifacts, entry.getKey(), user, NodeTemplateOperation.HEAT_VF_ENV_NAME);
- }
+ instArtMap.put(entry.getKey(), artifactsMap);
+ }
+ }
- GraphVertex vertex = getVertexEither.left().value();
- Map<String, MapArtifactDataDefinition> instArtMap = new HashMap<>();
- if (instArtifacts != null) {
+ return topologyTemplateOperation.associateInstDeploymentArtifactsToComponent(vertex, instArtMap);
- MapArtifactDataDefinition artifactsMap;
- for (Entry<String, Map<String, ArtifactDefinition>> entry : instArtifacts.entrySet()) {
- Map<String, ArtifactDefinition> artList = entry.getValue();
- Map<String, ArtifactDataDefinition> artifacts = artList.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
- artifactsMap = new MapArtifactDataDefinition(artifacts);
+ }
- instArtMap.put(entry.getKey(), artifactsMap);
- }
- }
+ public StorageOperationStatus associateArtifactsToInstances(Map<String, Map<String, ArtifactDefinition>> instArtifacts, String componentId, User user) {
- return topologyTemplateOperation.associateInstArtifactsToComponent(vertex, instArtMap);
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
- }
+ }
- public StorageOperationStatus associateInstAttributeToComponentToInstances(Map<String, List<PropertyDefinition>> instArttributes, String componentId) {
+ GraphVertex vertex = getVertexEither.left().value();
+ Map<String, MapArtifactDataDefinition> instArtMap = new HashMap<>();
+ if (instArtifacts != null) {
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
+ MapArtifactDataDefinition artifactsMap;
+ for (Entry<String, Map<String, ArtifactDefinition>> entry : instArtifacts.entrySet()) {
+ Map<String, ArtifactDefinition> artList = entry.getValue();
+ Map<String, ArtifactDataDefinition> artifacts = artList.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
+ artifactsMap = new MapArtifactDataDefinition(artifacts);
- }
+ instArtMap.put(entry.getKey(), artifactsMap);
+ }
+ }
- GraphVertex vertex = getVertexEither.left().value();
- Map<String, MapPropertiesDataDefinition> instAttr = new HashMap<>();
- if (instArttributes != null) {
+ return topologyTemplateOperation.associateInstArtifactsToComponent(vertex, instArtMap);
- MapPropertiesDataDefinition attributesMap;
- for (Entry<String, List<PropertyDefinition>> entry : instArttributes.entrySet()) {
- attributesMap = new MapPropertiesDataDefinition();
- attributesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
- instAttr.put(entry.getKey(), attributesMap);
- }
- }
+ }
- return topologyTemplateOperation.associateInstAttributeToComponent(vertex, instAttr);
+ public StorageOperationStatus associateInstAttributeToComponentToInstances(Map<String, List<PropertyDefinition>> instArttributes, String componentId) {
- }
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
- public StorageOperationStatus associateCalculatedCapReq(Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties, Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instReg, String componentId) {
- Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getVertexEither.isRight()) {
- log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
+ }
- }
+ GraphVertex vertex = getVertexEither.left().value();
+ Map<String, MapPropertiesDataDefinition> instAttr = new HashMap<>();
+ if (instArttributes != null) {
+
+ MapPropertiesDataDefinition attributesMap;
+ for (Entry<String, List<PropertyDefinition>> entry : instArttributes.entrySet()) {
+ attributesMap = new MapPropertiesDataDefinition();
+ attributesMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
+ instAttr.put(entry.getKey(), attributesMap);
+ }
+ }
- GraphVertex vertex = getVertexEither.left().value();
+ return topologyTemplateOperation.associateInstAttributeToComponent(vertex, instAttr);
- Map<String, MapListRequirementDataDefinition> calcRequirements = new HashMap<>();
+ }
+ // endregion
- Map<String, MapListCapabiltyDataDefinition> calcCapabilty = new HashMap<>();
- Map<String, MapCapabiltyProperty> calculatedCapabilitiesProperties = new HashMap<>();
- ;
- if (instCapabilties != null) {
- for (Entry<ComponentInstance, Map<String, List<CapabilityDefinition>>> entry : instCapabilties.entrySet()) {
+ public StorageOperationStatus associateCalculatedCapReq(Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties, Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instReg, String componentId) {
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
- Map<String, List<CapabilityDefinition>> caps = entry.getValue();
- Map<String, ListCapabilityDataDefinition> mapToscaDataDefinition = new HashMap<>();
- for (Entry<String, List<CapabilityDefinition>> instCapability : caps.entrySet()) {
- mapToscaDataDefinition.put(instCapability.getKey(), new ListCapabilityDataDefinition(instCapability.getValue().stream().map(iCap -> new CapabilityDataDefinition(iCap)).collect(Collectors.toList())));
- }
-
- ComponentInstanceDataDefinition componentInstance = new ComponentInstanceDataDefinition(entry.getKey());
- MapListCapabiltyDataDefinition capMap = nodeTemplateOperation.prepareCalculatedCapabiltyForNodeType(mapToscaDataDefinition, componentInstance);
+ }
- MapCapabiltyProperty mapCapabiltyProperty = ModelConverter.convertToMapOfMapCapabiltyProperties(caps, componentInstance.getUniqueId(), true);
-
- calcCapabilty.put(entry.getKey().getUniqueId(), capMap);
- calculatedCapabilitiesProperties.put(entry.getKey().getUniqueId(), mapCapabiltyProperty);
- }
- }
-
- if (instReg != null) {
- for (Entry<ComponentInstance, Map<String, List<RequirementDefinition>>> entry : instReg.entrySet()) {
-
- Map<String, List<RequirementDefinition>> req = entry.getValue();
- Map<String, ListRequirementDataDefinition> mapToscaDataDefinition = new HashMap<>();
- for (Entry<String, List<RequirementDefinition>> instReq : req.entrySet()) {
- mapToscaDataDefinition.put(instReq.getKey(), new ListRequirementDataDefinition(instReq.getValue().stream().map(iCap -> new RequirementDataDefinition(iCap)).collect(Collectors.toList())));
- }
-
- MapListRequirementDataDefinition capMap = nodeTemplateOperation.prepareCalculatedRequirementForNodeType(mapToscaDataDefinition, new ComponentInstanceDataDefinition(entry.getKey()));
-
- calcRequirements.put(entry.getKey().getUniqueId(), capMap);
- }
- }
-
- StorageOperationStatus status = topologyTemplateOperation.associateCalcCapReqToComponent(vertex, calcRequirements, calcCapabilty, calculatedCapabilitiesProperties);
-
- return status;
- }
-
- private Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType, VertexTypeEnum vertexType) {
-
- Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
- Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class);
-
- fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType);
-
- Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata);
- if (getRes.isRight()) {
- if (getRes.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- return Either.left(new ArrayList<>());
- } else {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
- }
- } else {
- List<Component> nonAbstractLatestComponents = new ArrayList<>();
- ComponentParametersView params = new ComponentParametersView(true);
- params.setIgnoreAllVersions(false);
- for (GraphVertex vertexComponent : getRes.left().value()) {
- Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation.getLightComponent(vertexComponent, componentTypeEnum, params);
- if (componentRes.isRight()) {
- log.debug("Failed to fetch ligth element for {} error {}", vertexComponent.getUniqueId(), componentRes.right().value());
- return Either.right(componentRes.right().value());
- } else {
- Component component = ModelConverter.convertFromToscaElement(componentRes.left().value());
-
- nonAbstractLatestComponents.add(component);
- }
- }
-
- return Either.left(nonAbstractLatestComponents);
- }
- }
-
- public Either<ComponentMetadataData, StorageOperationStatus> getLatestComponentMetadataByUuid(String componentUuid, JsonParseFlagEnum parseFlag, Boolean isHighest) {
-
- Either<ComponentMetadataData, StorageOperationStatus> result;
-
- Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
-
- hasProperties.put(GraphPropertyEnum.UUID, componentUuid);
- if (isHighest != null) {
- hasProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, isHighest.booleanValue());
- }
-
- Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
- propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
-
- Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(null, hasProperties, propertiesNotToMatch, parseFlag);
- if (getRes.isRight()) {
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
- } else {
- List<ComponentMetadataData> latestVersionList = getRes.left().value().stream().map(ModelConverter::convertToComponentMetadata).collect(Collectors.toList());
- ComponentMetadataData latestVersion = latestVersionList.size() == 1 ? latestVersionList.get(0)
- : latestVersionList.stream().max((c1, c2) -> Double.compare(Double.parseDouble(c1.getMetadataDataDefinition().getVersion()), Double.parseDouble(c2.getMetadataDataDefinition().getVersion()))).get();
- result = Either.left(latestVersion);
- }
- return result;
- }
-
- public Either<ComponentMetadataData, StorageOperationStatus> getComponentMetadata(String componentId) {
-
- Either<ComponentMetadataData, StorageOperationStatus> result;
- Either<GraphVertex, TitanOperationStatus> getRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseMetadata);
- if (getRes.isRight()) {
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
- } else {
- ComponentMetadataData componentMetadata = ModelConverter.convertToComponentMetadata(getRes.left().value());
- result = Either.left(componentMetadata);
- }
- return result;
- }
-
- private Map<String, ComponentMetadataData> findLatestVersion(List<ComponentMetadataData> resourceDataList) {
- Map<Pair<String, String>, ComponentMetadataData> latestVersionMap = new HashMap<Pair<String, String>, ComponentMetadataData>();
- for (ComponentMetadataData resourceData : resourceDataList) {
- ComponentMetadataData latestVersionData = resourceData;
-
- ComponentMetadataDataDefinition metadataDataDefinition = resourceData.getMetadataDataDefinition();
- Pair<String, String> pair = createKeyPair(latestVersionData);
- if (latestVersionMap.containsKey(pair)) {
- latestVersionData = latestVersionMap.get(pair);
- String currentVersion = latestVersionData.getMetadataDataDefinition().getVersion();
- String newVersion = metadataDataDefinition.getVersion();
- if (CommonBeUtils.compareAsdcComponentVersions(newVersion, currentVersion)) {
- latestVersionData = resourceData;
- }
- }
- if (log.isDebugEnabled())
- log.debug("last certified version of resource = {} version is {}", latestVersionData.getMetadataDataDefinition().getName(), latestVersionData.getMetadataDataDefinition().getVersion());
-
- latestVersionMap.put(pair, latestVersionData);
- }
-
- Map<String, ComponentMetadataData> resVersionMap = new HashMap<String, ComponentMetadataData>();
- for (ComponentMetadataData resourceData : latestVersionMap.values()) {
- ComponentMetadataData latestVersionData = resourceData;
- ComponentMetadataDataDefinition metadataDataDefinition = resourceData.getMetadataDataDefinition();
- if (resVersionMap.containsKey(metadataDataDefinition.getUUID())) {
- latestVersionData = resVersionMap.get(metadataDataDefinition.getUUID());
- String currentVersion = latestVersionData.getMetadataDataDefinition().getVersion();
- String newVersion = metadataDataDefinition.getVersion();
- if (CommonBeUtils.compareAsdcComponentVersions(newVersion, currentVersion)) {
- latestVersionData = resourceData;
- }
- }
- if (log.isDebugEnabled())
- log.debug("last uuid version of resource = {} version is {}", latestVersionData.getMetadataDataDefinition().getName(), latestVersionData.getMetadataDataDefinition().getVersion());
- resVersionMap.put(latestVersionData.getMetadataDataDefinition().getUUID(), latestVersionData);
- }
-
- return resVersionMap;
- }
-
- private Pair<String, String> createKeyPair(ComponentMetadataData metadataData) {
- Pair<String, String> pair;
- NodeTypeEnum label = NodeTypeEnum.getByName(metadataData.getLabel());
- switch (label) {
- case Resource:
- pair = new ImmutablePair<>(metadataData.getMetadataDataDefinition().getName(), ((ResourceMetadataDataDefinition) metadataData.getMetadataDataDefinition()).getResourceType().name());
- break;
- default:
- pair = new ImmutablePair<>(metadataData.getMetadataDataDefinition().getName(), metadataData.getLabel());
- break;
- }
-
- return pair;
- }
-
- public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractComponents(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType, List<String> componentUids) {
-
- Either<List<Component>, StorageOperationStatus> result = null;
- List<Component> components = new ArrayList<>();
- if (componentUids == null) {
- Either<List<String>, StorageOperationStatus> componentUidsRes = getComponentUids(isAbstract, isHighest, componentTypeEnum, internalComponentType, componentUids);
- if (componentUidsRes.isRight()) {
- result = Either.right(componentUidsRes.right().value());
- } else {
- componentUids = componentUidsRes.left().value();
- }
- }
- if (!componentUids.isEmpty()) {
- for (String componentUid : componentUids) {
- ComponentParametersView componentParametersView = buildComponentViewForNotAbstract();
- if (internalComponentType != null && "vl".equalsIgnoreCase(internalComponentType)) {
- componentParametersView.setIgnoreCapabilities(false);
- componentParametersView.setIgnoreRequirements(false);
- }
- Either<ToscaElement, StorageOperationStatus> getToscaElementRes = nodeTemplateOperation.getToscaElementOperation(componentTypeEnum).getLightComponent(componentUid, componentTypeEnum, componentParametersView);
- if (getToscaElementRes.isRight()) {
- if (log.isDebugEnabled())
- log.debug("Failed to fetch resource for error is {}", getToscaElementRes.right().value());
- result = Either.right(getToscaElementRes.right().value());
- break;
- }
- Component component = ModelConverter.convertFromToscaElement(getToscaElementRes.left().value());
- component.setContactId(null);
- component.setCreationDate(null);
- component.setCreatorUserId(null);
- component.setCreatorFullName(null);
- component.setLastUpdateDate(null);
- component.setLastUpdaterUserId(null);
- component.setLastUpdaterFullName(null);
- component.setNormalizedName(null);
- components.add(component);
- }
- }
- if (result == null) {
- result = Either.left(components);
- }
- return result;
- }
-
- private Either<List<String>, StorageOperationStatus> getComponentUids(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType, List<String> componentUids) {
-
- Either<List<String>, StorageOperationStatus> result = null;
- Either<List<Component>, StorageOperationStatus> getToscaElementsRes = getLatestVersionNotAbstractMetadataOnly(isAbstract, isHighest, componentTypeEnum, internalComponentType);
- if (getToscaElementsRes.isRight()) {
- result = Either.right(getToscaElementsRes.right().value());
- } else {
- List<Component> collection = getToscaElementsRes.left().value();
- if (collection == null) {
- componentUids = new ArrayList<>();
- } else {
- componentUids = collection.stream().map(p -> p.getUniqueId()).collect(Collectors.toList());
- }
- }
- if (result == null) {
- result = Either.left(componentUids);
- }
- return result;
- }
-
- private ComponentParametersView buildComponentViewForNotAbstract() {
- ComponentParametersView componentParametersView = new ComponentParametersView();
- componentParametersView.disableAll();
- componentParametersView.setIgnoreCategories(false);
- componentParametersView.setIgnoreAllVersions(false);
- return componentParametersView;
- }
-
- public Either<Boolean, StorageOperationStatus> validateComponentNameExists(String name, ResourceTypeEnum resourceType, ComponentTypeEnum componentType) {
- Either<Boolean, StorageOperationStatus> result = validateComponentNameUniqueness(name, resourceType, componentType);
- if (result.isLeft()) {
- result = Either.left(!result.left().value());
- }
- return result;
- }
-
- public Either<Boolean, StorageOperationStatus> validateComponentNameUniqueness(String name, ResourceTypeEnum resourceType, ComponentTypeEnum componentType) {
- VertexTypeEnum vertexType = ModelConverter.isAtomicComponent(resourceType) ? VertexTypeEnum.NODE_TYPE : VertexTypeEnum.TOPOLOGY_TEMPLATE;
- String normalizedName = ValidationUtils.normaliseComponentName(name);
- Map<GraphPropertyEnum, Object> properties = new EnumMap<>(GraphPropertyEnum.class);
- properties.put(GraphPropertyEnum.NORMALIZED_NAME, normalizedName);
- properties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
-
- Either<List<GraphVertex>, TitanOperationStatus> vertexEither = titanDao.getByCriteria(vertexType, properties, JsonParseFlagEnum.NoParse);
- if (vertexEither.isRight() && vertexEither.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("failed to get vertex from graph with property normalizedName: {}", normalizedName);
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexEither.right().value()));
- }
- List<GraphVertex> vertexList = vertexEither.isLeft() ? vertexEither.left().value() : null;
- if (vertexList != null && !vertexList.isEmpty()) {
- return Either.left(false);
- } else {
- return Either.left(true);
- }
- }
-
-
- private void fillNodeTypePropsMap(Map<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> hasNotProps, String internalComponentType) {
- switch (internalComponentType.toLowerCase()) {
- case "vf":
- case "cvfc":
- hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VFCMT.name());
- break;
- case "service":
- case "pnf" :
- hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, Arrays.asList(ResourceTypeEnum.VFC.name(), ResourceTypeEnum.VFCMT.name()));
- break;
- case "vl":
- hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VL.name());
- break;
- default:
- break;
- }
- }
-
+ GraphVertex vertex = getVertexEither.left().value();
+
+ Map<String, MapListRequirementDataDefinition> calcRequirements = new HashMap<>();
+
+ Map<String, MapListCapabiltyDataDefinition> calcCapabilty = new HashMap<>();
+ Map<String, MapCapabiltyProperty> calculatedCapabilitiesProperties = new HashMap<>();
+ ;
+ if (instCapabilties != null) {
+ for (Entry<ComponentInstance, Map<String, List<CapabilityDefinition>>> entry : instCapabilties.entrySet()) {
+
+ Map<String, List<CapabilityDefinition>> caps = entry.getValue();
+ Map<String, ListCapabilityDataDefinition> mapToscaDataDefinition = new HashMap<>();
+ for (Entry<String, List<CapabilityDefinition>> instCapability : caps.entrySet()) {
+ mapToscaDataDefinition.put(instCapability.getKey(), new ListCapabilityDataDefinition(instCapability.getValue().stream().map(iCap -> new CapabilityDataDefinition(iCap)).collect(Collectors.toList())));
+ }
+
+ ComponentInstanceDataDefinition componentInstance = new ComponentInstanceDataDefinition(entry.getKey());
+ MapListCapabiltyDataDefinition capMap = nodeTemplateOperation.prepareCalculatedCapabiltyForNodeType(mapToscaDataDefinition, componentInstance);
+
+ MapCapabiltyProperty mapCapabiltyProperty = ModelConverter.convertToMapOfMapCapabiltyProperties(caps, componentInstance.getUniqueId(), true);
+
+ calcCapabilty.put(entry.getKey().getUniqueId(), capMap);
+ calculatedCapabilitiesProperties.put(entry.getKey().getUniqueId(), mapCapabiltyProperty);
+ }
+ }
+
+ if (instReg != null) {
+ for (Entry<ComponentInstance, Map<String, List<RequirementDefinition>>> entry : instReg.entrySet()) {
+
+ Map<String, List<RequirementDefinition>> req = entry.getValue();
+ Map<String, ListRequirementDataDefinition> mapToscaDataDefinition = new HashMap<>();
+ for (Entry<String, List<RequirementDefinition>> instReq : req.entrySet()) {
+ mapToscaDataDefinition.put(instReq.getKey(), new ListRequirementDataDefinition(instReq.getValue().stream().map(iCap -> new RequirementDataDefinition(iCap)).collect(Collectors.toList())));
+ }
+
+ MapListRequirementDataDefinition capMap = nodeTemplateOperation.prepareCalculatedRequirementForNodeType(mapToscaDataDefinition, new ComponentInstanceDataDefinition(entry.getKey()));
+
+ calcRequirements.put(entry.getKey().getUniqueId(), capMap);
+ }
+ }
+
+ StorageOperationStatus status = topologyTemplateOperation.associateCalcCapReqToComponent(vertex, calcRequirements, calcCapabilty, calculatedCapabilitiesProperties);
+
+ return status;
+ }
+
+ private Either<List<Service>, StorageOperationStatus> getLatestVersionNonCheckoutServicesMetadataOnly(Map<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> hasNotProps) {
+ List<Service> services = new ArrayList<>();
+ List<LifecycleStateEnum> states = new ArrayList<>();
+ // include props
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ hasProps.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+
+ // exclude props
+ states.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ states.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ states.add(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ hasNotProps.put(GraphPropertyEnum.STATE, states);
+ hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
+ return fetchServicesByCriteria(services, hasProps, hasNotProps);
+ }
+
+ private Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType, VertexTypeEnum vertexType) {
+ List<Service> services = null;
+ Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class);
+ fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType);
+ Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata);
+ if (getRes.isRight()) {
+ if (getRes.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
+ return Either.left(new ArrayList<>());
+ } else {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
+ }
+ } else {
+ // region -> Fetch non checked-out services
+ if (internalComponentType != null && internalComponentType.toLowerCase().trim().equals("service") && VertexTypeEnum.NODE_TYPE == vertexType) { // and NODE_TYPE==vertextype
+ Either<List<Service>, StorageOperationStatus> result = getLatestVersionNonCheckoutServicesMetadataOnly(new EnumMap<>(GraphPropertyEnum.class), new EnumMap<>(GraphPropertyEnum.class));
+ if (result.isRight()) {
+ log.debug("Failed to fetch services for");
+ return Either.right(result.right().value());
+ }
+ services = result.left().value();
+ if (CollectionUtils.isEmpty(services) && log.isTraceEnabled())
+ log.trace("No relevant services available");
+ }
+ // endregion
+ List<Component> nonAbstractLatestComponents = new ArrayList<>();
+ ComponentParametersView params = new ComponentParametersView(true);
+ params.setIgnoreAllVersions(false);
+ for (GraphVertex vertexComponent : getRes.left().value()) {
+ Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation.getLightComponent(vertexComponent, componentTypeEnum, params);
+ if (componentRes.isRight()) {
+ log.debug("Failed to fetch ligth element for {} error {}", vertexComponent.getUniqueId(), componentRes.right().value());
+ return Either.right(componentRes.right().value());
+ } else {
+ Component component = ModelConverter.convertFromToscaElement(componentRes.left().value());
+ nonAbstractLatestComponents.add(component);
+ }
+ }
+ if (CollectionUtils.isNotEmpty(services))
+ nonAbstractLatestComponents.addAll(services);
+ return Either.left(nonAbstractLatestComponents);
+ }
+ }
+
+ public Either<ComponentMetadataData, StorageOperationStatus> getLatestComponentMetadataByUuid(String componentUuid, JsonParseFlagEnum parseFlag, Boolean isHighest) {
+
+ Either<ComponentMetadataData, StorageOperationStatus> result;
+
+ Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
+
+ hasProperties.put(GraphPropertyEnum.UUID, componentUuid);
+ if (isHighest != null) {
+ hasProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, isHighest.booleanValue());
+ }
+
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+
+ Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(null, hasProperties, propertiesNotToMatch, parseFlag);
+ if (getRes.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
+ } else {
+ List<ComponentMetadataData> latestVersionList = getRes.left().value().stream().map(ModelConverter::convertToComponentMetadata).collect(Collectors.toList());
+ ComponentMetadataData latestVersion = latestVersionList.size() == 1 ? latestVersionList.get(0)
+ : latestVersionList.stream().max((c1, c2) -> Double.compare(Double.parseDouble(c1.getMetadataDataDefinition().getVersion()), Double.parseDouble(c2.getMetadataDataDefinition().getVersion()))).get();
+ result = Either.left(latestVersion);
+ }
+ return result;
+ }
+
+ public Either<ComponentMetadataData, StorageOperationStatus> getComponentMetadata(String componentId) {
+
+ Either<ComponentMetadataData, StorageOperationStatus> result;
+ Either<GraphVertex, TitanOperationStatus> getRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseMetadata);
+ if (getRes.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
+ } else {
+ ComponentMetadataData componentMetadata = ModelConverter.convertToComponentMetadata(getRes.left().value());
+ result = Either.left(componentMetadata);
+ }
+ return result;
+ }
+
+ public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractComponents(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType, List<String> componentUids) {
- private void fillTopologyTemplatePropsMap(Map<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> hasNotProps, ComponentTypeEnum componentTypeEnum, String internalComponentType) {
- switch (componentTypeEnum) {
- case RESOURCE:
- hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
- break;
- case SERVICE:
- hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
- break;
- default:
- break;
- }
- switch (internalComponentType.toLowerCase()) {
- case "vf":
- case "cvfc":
- hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.CVFC.name());
- break;
- case "service":
- hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.CVFC.name());
- break;
- default:
- break;
- }
- }
-
- private void fillPropsMap(Map<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> hasNotProps, String internalComponentType, ComponentTypeEnum componentTypeEnum, boolean isAbstract, VertexTypeEnum internalVertexType) {
- hasNotProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
-
- hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
- hasProps.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- if (VertexTypeEnum.NODE_TYPE == internalVertexType) {
- hasProps.put(GraphPropertyEnum.IS_ABSTRACT, isAbstract);
- if (internalComponentType != null) {
- fillNodeTypePropsMap(hasProps, hasNotProps, internalComponentType);
- }
- } else {
- fillTopologyTemplatePropsMap(hasProps, hasNotProps, componentTypeEnum, internalComponentType);
- }
- }
-
- private List<VertexTypeEnum> getInternalVertexTypes(ComponentTypeEnum componentTypeEnum, String internalComponentType) {
- List<VertexTypeEnum> internalVertexTypes = new ArrayList<>();
- if (ComponentTypeEnum.RESOURCE == componentTypeEnum) {
- internalVertexTypes.add(VertexTypeEnum.NODE_TYPE);
- }
- if (ComponentTypeEnum.SERVICE == componentTypeEnum || "service".equalsIgnoreCase(internalComponentType) || "vf".equalsIgnoreCase(internalComponentType)) {
- internalVertexTypes.add(VertexTypeEnum.TOPOLOGY_TEMPLATE);
- }
- return internalVertexTypes;
- }
-
- public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractMetadataOnly(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType) {
- List<VertexTypeEnum> internalVertexTypes = getInternalVertexTypes(componentTypeEnum, internalComponentType);
- List<Component> result = new ArrayList<>();
- for (VertexTypeEnum vertexType : internalVertexTypes) {
- Either<List<Component>, StorageOperationStatus> listByVertexType = getLatestVersionNotAbstractToscaElementsMetadataOnly(isAbstract, isHighest, componentTypeEnum, internalComponentType, vertexType);
- if (listByVertexType.isRight()) {
- return listByVertexType;
- }
- result.addAll(listByVertexType.left().value());
- }
- return Either.left(result);
-
- }
-
- public Either<List<Component>, StorageOperationStatus> getLatestComponentListByUuid(String componentUuid) {
- Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
- propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ Either<List<Component>, StorageOperationStatus> result = null;
+ List<Component> components = new ArrayList<>();
+ if (componentUids == null) {
+ Either<List<String>, StorageOperationStatus> componentUidsRes = getComponentUids(isAbstract, isHighest, componentTypeEnum, internalComponentType, componentUids);
+ if (componentUidsRes.isRight()) {
+ result = Either.right(componentUidsRes.right().value());
+ } else {
+ componentUids = componentUidsRes.left().value();
+ }
+ }
+ if (!componentUids.isEmpty()) {
+ for (String componentUid : componentUids) {
+ ComponentParametersView componentParametersView = buildComponentViewForNotAbstract();
+ if (internalComponentType != null && "vl".equalsIgnoreCase(internalComponentType)) {
+ componentParametersView.setIgnoreCapabilities(false);
+ componentParametersView.setIgnoreRequirements(false);
+ }
+ Either<ToscaElement, StorageOperationStatus> getToscaElementRes = nodeTemplateOperation.getToscaElementOperation(componentTypeEnum).getLightComponent(componentUid, componentTypeEnum, componentParametersView);
+ if (getToscaElementRes.isRight()) {
+ if (log.isDebugEnabled())
+ log.debug("Failed to fetch resource for error is {}", getToscaElementRes.right().value());
+ result = Either.right(getToscaElementRes.right().value());
+ break;
+ }
+ Component component = ModelConverter.convertFromToscaElement(getToscaElementRes.left().value());
+ component.setContactId(null);
+ component.setCreationDate(null);
+ component.setCreatorUserId(null);
+ component.setCreatorFullName(null);
+ component.setLastUpdateDate(null);
+ component.setLastUpdaterUserId(null);
+ component.setLastUpdaterFullName(null);
+ component.setNormalizedName(null);
+ components.add(component);
+ }
+ }
+ if (result == null) {
+ result = Either.left(components);
+ }
+ return result;
+ }
+
+ private Either<List<String>, StorageOperationStatus> getComponentUids(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType, List<String> componentUids) {
+
+ Either<List<String>, StorageOperationStatus> result = null;
+ Either<List<Component>, StorageOperationStatus> getToscaElementsRes = getLatestVersionNotAbstractMetadataOnly(isAbstract, isHighest, componentTypeEnum, internalComponentType);
+ if (getToscaElementsRes.isRight()) {
+ result = Either.right(getToscaElementsRes.right().value());
+ } else {
+ List<Component> collection = getToscaElementsRes.left().value();
+ if (collection == null) {
+ componentUids = new ArrayList<>();
+ } else {
+ componentUids = collection.stream().map(p -> p.getUniqueId()).collect(Collectors.toList());
+ }
+ }
+ if (result == null) {
+ result = Either.left(componentUids);
+ }
+ return result;
+ }
+
+ private ComponentParametersView buildComponentViewForNotAbstract() {
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreCategories(false);
+ componentParametersView.setIgnoreAllVersions(false);
+ return componentParametersView;
+ }
+
+ public Either<Boolean, StorageOperationStatus> validateComponentNameExists(String name, ResourceTypeEnum resourceType, ComponentTypeEnum componentType) {
+ Either<Boolean, StorageOperationStatus> result = validateComponentNameUniqueness(name, resourceType, componentType);
+ if (result.isLeft()) {
+ result = Either.left(!result.left().value());
+ }
+ return result;
+ }
+
+ public Either<Boolean, StorageOperationStatus> validateComponentNameUniqueness(String name, ResourceTypeEnum resourceType, ComponentTypeEnum componentType) {
+ VertexTypeEnum vertexType = ModelConverter.isAtomicComponent(resourceType) ? VertexTypeEnum.NODE_TYPE : VertexTypeEnum.TOPOLOGY_TEMPLATE;
+ String normalizedName = ValidationUtils.normaliseComponentName(name);
+ Map<GraphPropertyEnum, Object> properties = new EnumMap<>(GraphPropertyEnum.class);
+ properties.put(GraphPropertyEnum.NORMALIZED_NAME, normalizedName);
+ properties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+
+ Either<List<GraphVertex>, TitanOperationStatus> vertexEither = titanDao.getByCriteria(vertexType, properties, JsonParseFlagEnum.NoParse);
+ if (vertexEither.isRight() && vertexEither.right().value() != TitanOperationStatus.NOT_FOUND) {
+ log.debug("failed to get vertex from graph with property normalizedName: {}", normalizedName);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexEither.right().value()));
+ }
+ List<GraphVertex> vertexList = vertexEither.isLeft() ? vertexEither.left().value() : null;
+ if (vertexList != null && !vertexList.isEmpty()) {
+ return Either.left(false);
+ } else {
+ return Either.left(true);
+ }
+ }
+
+ private void fillNodeTypePropsMap(Map<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> hasNotProps, String internalComponentType) {
+ switch (internalComponentType.toLowerCase()) {
+ case "vf":
+ case "cvfc":
+ hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, Arrays.asList(ResourceTypeEnum.VFCMT.name(), ResourceTypeEnum.Configuration.name()));
+ break;
+ case "service":
+ case "pnf":
+ hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, Arrays.asList(ResourceTypeEnum.VFC.name(), ResourceTypeEnum.VFCMT.name()));
+ break;
+ case "vl":
+ hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VL.name());
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void fillTopologyTemplatePropsMap(Map<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> hasNotProps, ComponentTypeEnum componentTypeEnum, String internalComponentType) {
+ switch (componentTypeEnum) {
+ case RESOURCE:
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ break;
+ case SERVICE:
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ break;
+ default:
+ break;
+ }
+ switch (internalComponentType.toLowerCase()) {
+ case "vf":
+ case "cvfc":
+ hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.CVFC.name());
+ break;
+ case "service":
+ hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.CVFC.name());
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void fillPropsMap(Map<GraphPropertyEnum, Object> hasProps, Map<GraphPropertyEnum, Object> hasNotProps, String internalComponentType, ComponentTypeEnum componentTypeEnum, boolean isAbstract, VertexTypeEnum internalVertexType) {
+ hasNotProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+
+ hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
+ hasProps.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ if (VertexTypeEnum.NODE_TYPE == internalVertexType) {
+ hasProps.put(GraphPropertyEnum.IS_ABSTRACT, isAbstract);
+ if (internalComponentType != null) {
+ fillNodeTypePropsMap(hasProps, hasNotProps, internalComponentType);
+ }
+ } else {
+ fillTopologyTemplatePropsMap(hasProps, hasNotProps, componentTypeEnum, internalComponentType);
+ }
+ }
+
+ private List<VertexTypeEnum> getInternalVertexTypes(ComponentTypeEnum componentTypeEnum, String internalComponentType) {
+ List<VertexTypeEnum> internalVertexTypes = new ArrayList<>();
+ if (ComponentTypeEnum.RESOURCE == componentTypeEnum) {
+ internalVertexTypes.add(VertexTypeEnum.NODE_TYPE);
+ }
+ if (ComponentTypeEnum.SERVICE == componentTypeEnum || "service".equalsIgnoreCase(internalComponentType) || "vf".equalsIgnoreCase(internalComponentType)) {
+ internalVertexTypes.add(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ }
+ return internalVertexTypes;
+ }
+
+ public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractMetadataOnly(boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType) {
+ List<VertexTypeEnum> internalVertexTypes = getInternalVertexTypes(componentTypeEnum, internalComponentType);
+ List<Component> result = new ArrayList<>();
+ for (VertexTypeEnum vertexType : internalVertexTypes) {
+ Either<List<Component>, StorageOperationStatus> listByVertexType = getLatestVersionNotAbstractToscaElementsMetadataOnly(isAbstract, isHighest, componentTypeEnum, internalComponentType, vertexType);
+ if (listByVertexType.isRight()) {
+ return listByVertexType;
+ }
+ result.addAll(listByVertexType.left().value());
+ }
+ return Either.left(result);
+
+ }
+
+ public Either<List<Component>, StorageOperationStatus> getLatestComponentListByUuid(String componentUuid) {
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
Either<List<Component>, StorageOperationStatus> componentListByUuid = getComponentListByUuid(componentUuid, propertiesToMatch);
return componentListByUuid;
- }
+ }
- public Either<List<Component>, StorageOperationStatus> getComponentListByUuid(String componentUuid, Map<GraphPropertyEnum, Object> additionalPropertiesToMatch) {
+ public Either<List<Component>, StorageOperationStatus> getComponentListByUuid(String componentUuid, Map<GraphPropertyEnum, Object> additionalPropertiesToMatch) {
- Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
- if (additionalPropertiesToMatch != null) {
- propertiesToMatch.putAll(additionalPropertiesToMatch);
- }
+ if (additionalPropertiesToMatch != null) {
+ propertiesToMatch.putAll(additionalPropertiesToMatch);
+ }
- propertiesToMatch.put(GraphPropertyEnum.UUID, componentUuid);
+ propertiesToMatch.put(GraphPropertyEnum.UUID, componentUuid);
- Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
- propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
- Either<List<GraphVertex>, TitanOperationStatus> vertexEither = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
+ Either<List<GraphVertex>, TitanOperationStatus> vertexEither = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
- if (vertexEither.isRight()) {
- log.debug("Couldn't fetch metadata for component with type {} and uuid {}, error: {}", componentUuid, vertexEither.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexEither.right().value()));
- }
- List<GraphVertex> vertexList = vertexEither.isLeft() ? vertexEither.left().value() : null;
+ if (vertexEither.isRight()) {
+ log.debug("Couldn't fetch metadata for component with type {} and uuid {}, error: {}", componentUuid, vertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexEither.right().value()));
+ }
+ List<GraphVertex> vertexList = vertexEither.isLeft() ? vertexEither.left().value() : null;
- if (vertexList == null || vertexList.isEmpty()) {
- log.debug("Component with uuid {} was not found", componentUuid);
- return Either.right(StorageOperationStatus.NOT_FOUND);
- }
+ if (vertexList == null || vertexList.isEmpty()) {
+ log.debug("Component with uuid {} was not found", componentUuid);
+ return Either.right(StorageOperationStatus.NOT_FOUND);
+ }
ArrayList<Component> latestComponents = new ArrayList<>();
- for (GraphVertex vertex : vertexList) {
+ for (GraphVertex vertex : vertexList) {
Either<Component, StorageOperationStatus> toscaElementByOperation = getToscaElementByOperation(vertex);
-
- if(toscaElementByOperation.isRight()){
+
+ if (toscaElementByOperation.isRight()) {
log.debug("Could not fetch the following Component by UUID {}", vertex.getUniqueId());
return Either.right(toscaElementByOperation.right().value());
}
-
+
latestComponents.add(toscaElementByOperation.left().value());
}
-
- if(latestComponents.size() > 1) {
+
+ if (latestComponents.size() > 1) {
for (Component component : latestComponents) {
- if(component.isHighestVersion()){
+ if (component.isHighestVersion()) {
LinkedList<Component> highestComponent = new LinkedList<>();
highestComponent.add(component);
return Either.left(highestComponent);
}
}
- }
-
- return Either.left(latestComponents);
- }
-
- public Either<Component, StorageOperationStatus> getLatestComponentByUuid(String componentUuid) {
-
- Either<List<Component>, StorageOperationStatus> latestVersionListEither = getLatestComponentListByUuid(componentUuid);
-
- if (latestVersionListEither.isRight()) {
- return Either.right(latestVersionListEither.right().value());
- }
-
- List<Component> latestVersionList = latestVersionListEither.left().value();
-
- if (latestVersionList.isEmpty()) {
- return Either.right(StorageOperationStatus.NOT_FOUND);
- }
- Component component = latestVersionList.size() == 1 ? latestVersionList.get(0) : latestVersionList.stream().max((c1, c2) -> Double.compare(Double.parseDouble(c1.getVersion()), Double.parseDouble(c2.getVersion()))).get();
-
- return Either.left(component);
- }
-
- public Either<List<Resource>, StorageOperationStatus> getAllCertifiedResources(boolean isAbstract, Boolean isHighest) {
-
- List<Resource> resources = new ArrayList<>();
- Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
- Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
-
- propertiesToMatch.put(GraphPropertyEnum.IS_ABSTRACT, isAbstract);
- if (isHighest != null) {
- propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, isHighest.booleanValue());
- }
- propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
- propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
-
- Either<List<GraphVertex>, TitanOperationStatus> getResourcesRes = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
-
- if (getResourcesRes.isRight()) {
- log.debug("Failed to fetch all certified resources. Status is {}", getResourcesRes.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getResourcesRes.right().value()));
- }
- List<GraphVertex> resourceVerticies = getResourcesRes.left().value();
- for (GraphVertex resourceV : resourceVerticies) {
- Either<Resource, StorageOperationStatus> getResourceRes = getToscaElement(resourceV);
- if (getResourceRes.isRight()) {
- return Either.right(getResourceRes.right().value());
- }
- resources.add(getResourceRes.left().value());
- }
- return Either.left(resources);
- }
-
- public <T extends Component> Either<T, StorageOperationStatus> getLatestByNameAndVersion(String name, String version, JsonParseFlagEnum parseFlag) {
- Either<T, StorageOperationStatus> result;
-
- Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
- Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
-
- hasProperties.put(GraphPropertyEnum.NAME, name);
- hasProperties.put(GraphPropertyEnum.VERSION, version);
- hasProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
-
- hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true);
-
- Either<List<GraphVertex>, TitanOperationStatus> getResourceRes = titanDao.getByCriteria(null, hasProperties, hasNotProperties, parseFlag);
- if (getResourceRes.isRight()) {
- TitanOperationStatus status = getResourceRes.right().value();
- log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- return result;
- }
- return getToscaElementByOperation(getResourceRes.left().value().get(0));
- }
-
- public Either<Resource, StorageOperationStatus> getLatestComponentByCsarOrName(ComponentTypeEnum componentType, String csarUUID, String systemName) {
- return getLatestComponentByCsarOrName(componentType, csarUUID, systemName, false, JsonParseFlagEnum.ParseAll);
- }
-
- public Either<Resource, StorageOperationStatus> getLatestComponentByCsarOrName(ComponentTypeEnum componentType, String csarUUID, String systemName, boolean allowDeleted, JsonParseFlagEnum parseFlag) {
- Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
- props.put(GraphPropertyEnum.CSAR_UUID, csarUUID);
- props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- if (componentType != null) {
- props.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
- }
- Map<GraphPropertyEnum, Object> propsHasNot = new EnumMap<>(GraphPropertyEnum.class);
- propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
-
- GraphVertex resourceMetadataData = null;
- List<GraphVertex> resourceMetadataDataList = null;
- Either<List<GraphVertex>, TitanOperationStatus> byCsar = titanDao.getByCriteria(null, props, propsHasNot, JsonParseFlagEnum.ParseMetadata);
- if (byCsar.isRight()) {
- if (TitanOperationStatus.NOT_FOUND == byCsar.right().value()) {
- // Fix Defect DE256036
- if (StringUtils.isEmpty(systemName)) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.NOT_FOUND));
- }
-
- props.clear();
- props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- props.put(GraphPropertyEnum.SYSTEM_NAME, systemName);
- Either<List<GraphVertex>, TitanOperationStatus> bySystemname = titanDao.getByCriteria(null, props, JsonParseFlagEnum.ParseMetadata);
- if (bySystemname.isRight()) {
- log.debug("getLatestResourceByCsarOrName - Failed to find by system name {} error {} ", systemName, bySystemname.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(bySystemname.right().value()));
- }
- if (bySystemname.left().value().size() > 2) {
- log.debug("getLatestResourceByCsarOrName - getByCriteria(by system name) must return only 2 latest version, but was returned - {}", bySystemname.left().value().size());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- resourceMetadataDataList = bySystemname.left().value();
- if (resourceMetadataDataList.size() == 1) {
- resourceMetadataData = resourceMetadataDataList.get(0);
- } else {
- for (GraphVertex curResource : resourceMetadataDataList) {
- if (!((String) curResource.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals("CERTIFIED")) {
- resourceMetadataData = curResource;
- break;
- }
- }
- }
- if (resourceMetadataData == null) {
- log.debug("getLatestResourceByCsarOrName - getByCriteria(by system name) returned 2 latest CERTIFIED versions");
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- if (resourceMetadataData.getJsonMetadataField(JsonPresentationFields.CSAR_UUID) != null && !((String) resourceMetadataData.getJsonMetadataField(JsonPresentationFields.CSAR_UUID)).equals(csarUUID)) {
- log.debug("getLatestResourceByCsarOrName - same system name {} but different csarUUID. exist {} and new {} ", systemName, resourceMetadataData.getJsonMetadataField(JsonPresentationFields.CSAR_UUID), csarUUID);
- // correct error will be returned from create flow. with all
- // correct audit records!!!!!
- return Either.right(StorageOperationStatus.NOT_FOUND);
- }
- Either<Resource, StorageOperationStatus> resource = getToscaElement((String) resourceMetadataData.getUniqueId());
- return resource;
- }
- } else {
- resourceMetadataDataList = byCsar.left().value();
- if (resourceMetadataDataList.size() > 2) {
- log.debug("getLatestResourceByCsarOrName - getByCriteria(by csar) must return only 2 latest version, but was returned - {}", byCsar.left().value().size());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- if (resourceMetadataDataList.size() == 1) {
- resourceMetadataData = resourceMetadataDataList.get(0);
- } else {
- for (GraphVertex curResource : resourceMetadataDataList) {
- if (!((String) curResource.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals("CERTIFIED")) {
- resourceMetadataData = curResource;
- break;
- }
- }
- }
- if (resourceMetadataData == null) {
- log.debug("getLatestResourceByCsarOrName - getByCriteria(by csar) returned 2 latest CERTIFIED versions");
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- Either<Resource, StorageOperationStatus> resource = getToscaElement((String) resourceMetadataData.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID), parseFlag);
- return resource;
- }
- return null;
- }
-
- public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExtends(String templateNameCurrent, String templateNameExtends) {
-
- String currentTemplateNameChecked = templateNameExtends;
-
- while (currentTemplateNameChecked != null && !currentTemplateNameChecked.equalsIgnoreCase(templateNameCurrent)) {
- Either<Resource, StorageOperationStatus> latestByToscaResourceName = getLatestByToscaResourceName(currentTemplateNameChecked);
-
- if (latestByToscaResourceName.isRight()) {
- return latestByToscaResourceName.right().value() == StorageOperationStatus.NOT_FOUND ? Either.left(false) : Either.right(latestByToscaResourceName.right().value());
- }
-
- Resource value = latestByToscaResourceName.left().value();
-
- if (value.getDerivedFrom() != null) {
- currentTemplateNameChecked = value.getDerivedFrom().get(0);
- } else {
- currentTemplateNameChecked = null;
- }
- }
-
- return (currentTemplateNameChecked != null && currentTemplateNameChecked.equalsIgnoreCase(templateNameCurrent)) ? Either.left(true) : Either.left(false);
- }
-
- public Either<List<Component>, StorageOperationStatus> fetchMetaDataByResourceType(String resourceType, ComponentParametersView filterBy) {
- Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
- props.put(GraphPropertyEnum.RESOURCE_TYPE, resourceType);
- props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- Either<List<GraphVertex>, TitanOperationStatus> resourcesByTypeEither = titanDao.getByCriteria(null, props, JsonParseFlagEnum.ParseMetadata);
-
- if (resourcesByTypeEither.isRight()) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resourcesByTypeEither.right().value()));
- }
-
- List<GraphVertex> vertexList = resourcesByTypeEither.left().value();
- List<Component> components = new ArrayList<>();
-
- for (GraphVertex vertex : vertexList) {
- components.add(getToscaElementByOperation(vertex, filterBy).left().value());
- }
-
- return Either.left(components);
- }
-
- public void commit() {
- titanDao.commit();
- }
-
- public Either<Service, StorageOperationStatus> updateDistributionStatus(Service service, User user, DistributionStatusEnum distributionStatus) {
- Either<GraphVertex, StorageOperationStatus> updateDistributionStatus = topologyTemplateOperation.updateDistributionStatus(service.getUniqueId(), user, distributionStatus);
- if (updateDistributionStatus.isRight()) {
- return Either.right(updateDistributionStatus.right().value());
- }
- GraphVertex serviceV = updateDistributionStatus.left().value();
- service.setDistributionStatus(distributionStatus);
- service.setLastUpdateDate((Long) serviceV.getJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE));
- return Either.left(service);
- }
-
- public Either<ComponentMetadataData, StorageOperationStatus> updateComponentLastUpdateDateOnGraph(Component component, Long modificationTime) {
-
- Either<ComponentMetadataData, StorageOperationStatus> result = null;
- GraphVertex serviceVertex;
- Either<GraphVertex, TitanOperationStatus> updateRes = null;
- Either<GraphVertex, TitanOperationStatus> getRes = titanDao.getVertexById(component.getUniqueId(), JsonParseFlagEnum.ParseMetadata);
- if (getRes.isRight()) {
- TitanOperationStatus status = getRes.right().value();
- log.error("Failed to fetch component {}. status is {}", component.getUniqueId(), status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- if (result == null) {
- serviceVertex = getRes.left().value();
- long lastUpdateDate = System.currentTimeMillis();
- serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
- component.setLastUpdateDate(lastUpdateDate);
- updateRes = titanDao.updateVertex(serviceVertex);
- if (updateRes.isRight()) {
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
- }
- }
- if (result == null) {
- result = Either.left(ModelConverter.convertToComponentMetadata(updateRes.left().value()));
- }
- return result;
- }
-
- public TitanDao getTitanDao() {
- return titanDao;
- }
-
- public Either<List<Service>, StorageOperationStatus> getCertifiedServicesWithDistStatus(Set<DistributionStatusEnum> distStatus) {
- Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
- propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
-
- return getServicesWithDistStatus(distStatus, propertiesToMatch);
- }
-
- public Either<List<Service>, StorageOperationStatus> getServicesWithDistStatus(Set<DistributionStatusEnum> distStatus, Map<GraphPropertyEnum, Object> additionalPropertiesToMatch) {
-
- List<Service> servicesAll = new ArrayList<>();
-
- Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
- Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
-
- if (additionalPropertiesToMatch != null && !additionalPropertiesToMatch.isEmpty()) {
- propertiesToMatch.putAll(additionalPropertiesToMatch);
- }
-
- propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
-
- propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
-
- if (distStatus != null && !distStatus.isEmpty()) {
- for (DistributionStatusEnum state : distStatus) {
- propertiesToMatch.put(GraphPropertyEnum.DISTRIBUTION_STATUS, state.name());
- Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria = fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch);
- if (fetchServicesByCriteria.isRight()) {
- return fetchServicesByCriteria;
- } else {
- servicesAll = fetchServicesByCriteria.left().value();
- }
- }
- return Either.left(servicesAll);
- } else {
- return fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch);
- }
- }
-
- // private Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria(List<Service> servicesAll, Map<GraphPropertyEnum, Object> propertiesToMatch, Map<GraphPropertyEnum, Object> propertiesNotToMatch) {
- // Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
- // if (getRes.isRight()) {
- // if (getRes.right().value() != TitanOperationStatus.NOT_FOUND) {
- // CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified services by match properties {} not match properties {} . Status is {}. ", propertiesToMatch, propertiesNotToMatch, getRes.right().value());
- // return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
- // }
- // } else {
- // for (GraphVertex vertex : getRes.left().value()) {
- // Either<Component, StorageOperationStatus> getServiceRes = getToscaElementByOperation(vertex);
- // if (getServiceRes.isRight()) {
- // CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified service {}. Status is {}. ", vertex.getJsonMetadataField(JsonPresentationFields.NAME), getServiceRes.right().value());
- // return Either.right(getServiceRes.right().value());
- // } else {
- // servicesAll.add((Service) getToscaElementByOperation(vertex).left().value());
- // }
- // }
- // }
- // return Either.left(servicesAll);
- // }
-
- private Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria(List<Service> servicesAll, Map<GraphPropertyEnum, Object> propertiesToMatch, Map<GraphPropertyEnum, Object> propertiesNotToMatch) {
- Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
- if (getRes.isRight()) {
- if (getRes.right().value() != TitanOperationStatus.NOT_FOUND) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified services by match properties {} not match properties {} . Status is {}. ", propertiesToMatch, propertiesNotToMatch, getRes.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
- }
- } else {
- for (GraphVertex vertex : getRes.left().value()) {
- // Either<Component, StorageOperationStatus> getServiceRes = getToscaElementByOperation(vertex);
- Either<ToscaElement, StorageOperationStatus> getServiceRes = topologyTemplateOperation.getLightComponent(vertex, ComponentTypeEnum.SERVICE, new ComponentParametersView(true));
-
- if (getServiceRes.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified service {}. Status is {}. ", vertex.getJsonMetadataField(JsonPresentationFields.NAME), getServiceRes.right().value());
- return Either.right(getServiceRes.right().value());
- } else {
- servicesAll.add(ModelConverter.convertFromToscaElement(getServiceRes.left().value()));
- }
- }
- }
- return Either.left(servicesAll);
- }
-
- public void rollback() {
- titanDao.rollback();
- }
-
- public StorageOperationStatus addDeploymentArtifactsToInstance(String componentId, ComponentInstance componentInstance, Map<String, ArtifactDefinition> finalDeploymentArtifacts) {
- Map<String, ArtifactDataDefinition> instDeplArtifacts = finalDeploymentArtifacts.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
-
- return nodeTemplateOperation.addDeploymentArtifactsToInstance(componentId, componentInstance.getUniqueId(), instDeplArtifacts);
- }
-
- public StorageOperationStatus addInformationalArtifactsToInstance(String componentId, ComponentInstance componentInstance, Map<String, ArtifactDefinition> artifacts) {
- StorageOperationStatus status = StorageOperationStatus.OK;
- if(MapUtils.isNotEmpty(artifacts)){
- Map<String, ArtifactDataDefinition> instDeplArtifacts = artifacts.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
- status= nodeTemplateOperation.addInformationalArtifactsToInstance(componentId, componentInstance.getUniqueId(), instDeplArtifacts);
- }
- return status;
- }
-
- public StorageOperationStatus generateCustomizationUUIDOnInstance(String componentId, String instanceId) {
- return nodeTemplateOperation.generateCustomizationUUIDOnInstance(componentId, instanceId);
- }
-
- public StorageOperationStatus generateCustomizationUUIDOnInstanceGroup(String componentId, String instanceId, List<String> groupInstances) {
- return nodeTemplateOperation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances);
- }
-
- public Either<PropertyDefinition, StorageOperationStatus> addPropertyToResource(String propertyName, PropertyDefinition newPropertyDefinition, Resource resource) {
-
- Either<PropertyDefinition, StorageOperationStatus> result = null;
- Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
- newPropertyDefinition.setName(propertyName);
- newPropertyDefinition.setParentUniqueId(resource.getUniqueId());
- StorageOperationStatus status = getToscaElementOperation(resource).addToscaDataToToscaElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME);
- if (status != StorageOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", propertyName, resource.getName(), status);
- result = Either.right(status);
- }
- if (result == null) {
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreProperties(false);
- getUpdatedComponentRes = getToscaElement(resource.getUniqueId(), filter);
- if (getUpdatedComponentRes.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", resource.getUniqueId(), getUpdatedComponentRes.right().value());
- result = Either.right(status);
- }
- }
- if (result == null) {
- PropertyDefinition newProperty = null;
- List<PropertyDefinition> properties = ((Resource) getUpdatedComponentRes.left().value()).getProperties();
- if (CollectionUtils.isNotEmpty(properties)) {
- Optional<PropertyDefinition> newPropertyOptional = properties.stream().filter(p -> p.getName().equals(propertyName)).findAny();
- if (newPropertyOptional.isPresent()) {
- newProperty = newPropertyOptional.get();
- }
- }
- if (newProperty == null) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", propertyName, resource.getUniqueId(), StorageOperationStatus.NOT_FOUND);
- result = Either.right(StorageOperationStatus.NOT_FOUND);
- } else {
- result = Either.left(newProperty);
- }
- }
- return result;
- }
-
- public StorageOperationStatus deletePropertyOfResource(Resource resource, String propertyName) {
- return getToscaElementOperation(resource).deleteToscaDataElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, propertyName, JsonPresentationFields.NAME);
- }
-
- public StorageOperationStatus deleteAttributeOfResource(Component component, String attributeName) {
- return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, attributeName, JsonPresentationFields.NAME);
- }
-
- public StorageOperationStatus deleteInputOfResource(Component resource, String inputName) {
- return getToscaElementOperation(resource).deleteToscaDataElement(resource.getUniqueId(), EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, inputName, JsonPresentationFields.NAME);
- }
-
- public Either<PropertyDefinition, StorageOperationStatus> updatePropertyOfResource(Resource resource, PropertyDefinition newPropertyDefinition) {
-
- Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
- Either<PropertyDefinition, StorageOperationStatus> result = null;
- StorageOperationStatus status = getToscaElementOperation(resource).updateToscaDataOfToscaElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME);
- if (status != StorageOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newPropertyDefinition.getName(), resource.getName(), status);
- result = Either.right(status);
- }
- if (result == null) {
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreProperties(false);
- getUpdatedComponentRes = getToscaElement(resource.getUniqueId(), filter);
- if (getUpdatedComponentRes.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", resource.getUniqueId(), getUpdatedComponentRes.right().value());
- result = Either.right(status);
- }
- }
- if (result == null) {
- Optional<PropertyDefinition> newProperty = ((Resource) getUpdatedComponentRes.left().value()).getProperties().stream().filter(p -> p.getName().equals(newPropertyDefinition.getName())).findAny();
- if (newProperty.isPresent()) {
- result = Either.left(newProperty.get());
- } else {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newPropertyDefinition.getName(), resource.getUniqueId(), StorageOperationStatus.NOT_FOUND);
- result = Either.right(StorageOperationStatus.NOT_FOUND);
- }
- }
- return result;
- }
-
- public Either<PropertyDefinition, StorageOperationStatus> addAttributeOfResource(Component component, PropertyDefinition newAttributeDef) {
-
- Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
- Either<PropertyDefinition, StorageOperationStatus> result = null;
- if (newAttributeDef.getUniqueId() == null || newAttributeDef.getUniqueId().isEmpty()) {
- String attUniqueId = UniqueIdBuilder.buildAttributeUid(component.getUniqueId(), newAttributeDef.getName());
- newAttributeDef.setUniqueId(attUniqueId);
- }
-
- StorageOperationStatus status = getToscaElementOperation(component).addToscaDataToToscaElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, newAttributeDef, JsonPresentationFields.NAME);
- if (status != StorageOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newAttributeDef.getName(), component.getName(), status);
- result = Either.right(status);
- }
- if (result == null) {
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreAttributesFrom(false);
- getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
- if (getUpdatedComponentRes.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
- result = Either.right(status);
- }
- }
- if (result == null) {
- Optional<PropertyDefinition> newAttribute = ((Resource) getUpdatedComponentRes.left().value()).getAttributes().stream().filter(p -> p.getName().equals(newAttributeDef.getName())).findAny();
- if (newAttribute.isPresent()) {
- result = Either.left(newAttribute.get());
- } else {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newAttributeDef.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
- result = Either.right(StorageOperationStatus.NOT_FOUND);
- }
- }
- return result;
- }
-
- public Either<PropertyDefinition, StorageOperationStatus> updateAttributeOfResource(Component component, PropertyDefinition newAttributeDef) {
-
- Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
- Either<PropertyDefinition, StorageOperationStatus> result = null;
- StorageOperationStatus status = getToscaElementOperation(component).updateToscaDataOfToscaElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, newAttributeDef, JsonPresentationFields.NAME);
- if (status != StorageOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newAttributeDef.getName(), component.getName(), status);
- result = Either.right(status);
- }
- if (result == null) {
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreAttributesFrom(false);
- getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
- if (getUpdatedComponentRes.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
- result = Either.right(status);
- }
- }
- if (result == null) {
- Optional<PropertyDefinition> newProperty = ((Resource) getUpdatedComponentRes.left().value()).getAttributes().stream().filter(p -> p.getName().equals(newAttributeDef.getName())).findAny();
- if (newProperty.isPresent()) {
- result = Either.left(newProperty.get());
- } else {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newAttributeDef.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
- result = Either.right(StorageOperationStatus.NOT_FOUND);
- }
- }
- return result;
- }
-
- public Either<InputDefinition, StorageOperationStatus> updateInputOfComponent(Component component, InputDefinition newInputDefinition) {
-
- Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
- Either<InputDefinition, StorageOperationStatus> result = null;
- StorageOperationStatus status = getToscaElementOperation(component).updateToscaDataOfToscaElement(component.getUniqueId(), EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, newInputDefinition, JsonPresentationFields.NAME);
- if (status != StorageOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the input {} to the component {}. Status is {}. ", newInputDefinition.getName(), component.getName(), status);
- result = Either.right(status);
- }
- if (result == null) {
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreInputs(false);
- getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
- if (getUpdatedComponentRes.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
- result = Either.right(status);
- }
- }
- if (result == null) {
- Optional<InputDefinition> updatedInput = getUpdatedComponentRes.left().value().getInputs().stream().filter(p -> p.getName().equals(newInputDefinition.getName())).findAny();
- if (updatedInput.isPresent()) {
- result = Either.left(updatedInput.get());
- } else {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently updated inputs {} on the resource {}. Status is {}. ", newInputDefinition.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
- result = Either.right(StorageOperationStatus.NOT_FOUND);
- }
- }
- return result;
- }
-
- /**
- * method - ename the group instances after referenced container name renamed
- * flow - VF rename -(triggers)-> Group rename
- *
- * @param containerComponent - container such as service
- * @param componentInstance - context component
- * @param componentInstanceId - id
- *
- * @return - successfull/failed status
- * **/
- public Either<StorageOperationStatus,StorageOperationStatus> cleanAndAddGroupInstancesToComponentInstance(Component containerComponent, ComponentInstance componentInstance, String componentInstanceId){
- String uniqueId = componentInstance.getUniqueId();
- StorageOperationStatus status = nodeTemplateOperation.deleteToscaDataDeepElementsBlockToToscaElement( containerComponent.getUniqueId(), EdgeLabelEnum.INST_GROUPS, VertexTypeEnum.INST_GROUPS, uniqueId );
- if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to delete group instances for container {}. error {] ", componentInstanceId, status);
- return Either.right(status);
- }
- if(componentInstance.getGroupInstances() != null){
- status = addGroupInstancesToComponentInstance( containerComponent , componentInstance, componentInstance.getGroupInstances() );
- if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add group instances for container {}. error {] ", componentInstanceId, status);
- return Either.right(status);
- }
- }
- return Either.left(status);
- }
-
- public StorageOperationStatus addGroupInstancesToComponentInstance(Component containerComponent, ComponentInstance componentInstance, List<GroupDefinition> groups, Map<String, List<ArtifactDefinition>> groupInstancesArtifacts) {
- return nodeTemplateOperation.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groups, groupInstancesArtifacts);
- }
-
- public Either<List<GroupDefinition>, StorageOperationStatus> updateGroupsOnComponent(Component component, ComponentTypeEnum componentType, List<GroupDataDefinition> updatedGroups) {
- return groupsOperation.updateGroups(component, componentType, updatedGroups);
- }
-
- public Either<List<GroupInstance>, StorageOperationStatus> updateGroupInstancesOnComponent(Component component, ComponentTypeEnum componentType, String instanceId, List<GroupInstance> updatedGroupInstances) {
- return groupsOperation.updateGroupInstances(component, componentType, instanceId, updatedGroupInstances);
- }
-
- public StorageOperationStatus addGroupInstancesToComponentInstance(Component containerComponent, ComponentInstance componentInstance, List<GroupInstance> groupInstances) {
- return nodeTemplateOperation.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groupInstances);
- }
-
- public StorageOperationStatus addDeploymentArtifactsToComponentInstance(Component containerComponent, ComponentInstance componentInstance, Map<String, ArtifactDefinition> deploymentArtifacts) {
- return nodeTemplateOperation.addDeploymentArtifactsToComponentInstance(containerComponent, componentInstance, deploymentArtifacts);
- }
-
- public StorageOperationStatus updateComponentInstanceProperty(Component containerComponent, String componentInstanceId, ComponentInstanceProperty property) {
- return nodeTemplateOperation.updateComponentInstanceProperty(containerComponent, componentInstanceId, property);
- }
-
- public StorageOperationStatus addComponentInstanceProperty(Component containerComponent, String componentInstanceId, ComponentInstanceProperty property) {
- return nodeTemplateOperation.addComponentInstanceProperty(containerComponent, componentInstanceId, property);
- }
-
- public StorageOperationStatus updateComponentInstanceInput(Component containerComponent, String componentInstanceId, ComponentInstanceInput property) {
- return nodeTemplateOperation.updateComponentInstanceInput(containerComponent, componentInstanceId, property);
- }
-
- public StorageOperationStatus addComponentInstanceInput(Component containerComponent, String componentInstanceId, ComponentInstanceInput property) {
- return nodeTemplateOperation.addComponentInstanceInput(containerComponent, componentInstanceId, property);
- }
-
- public void setNodeTypeOperation(NodeTypeOperation nodeTypeOperation) {
- this.nodeTypeOperation = nodeTypeOperation;
- }
-
- public void setTopologyTemplateOperation(TopologyTemplateOperation topologyTemplateOperation) {
- this.topologyTemplateOperation = topologyTemplateOperation;
- }
+ }
+
+ return Either.left(latestComponents);
+ }
+
+ public Either<Component, StorageOperationStatus> getLatestComponentByUuid(String componentUuid) {
+
+ Either<List<Component>, StorageOperationStatus> latestVersionListEither = getLatestComponentListByUuid(componentUuid);
+
+ if (latestVersionListEither.isRight()) {
+ return Either.right(latestVersionListEither.right().value());
+ }
+
+ List<Component> latestVersionList = latestVersionListEither.left().value();
+
+ if (latestVersionList.isEmpty()) {
+ return Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ Component component = latestVersionList.size() == 1 ? latestVersionList.get(0) : latestVersionList.stream().max((c1, c2) -> Double.compare(Double.parseDouble(c1.getVersion()), Double.parseDouble(c2.getVersion()))).get();
+
+ return Either.left(component);
+ }
+
+ public Either<List<Resource>, StorageOperationStatus> getAllCertifiedResources(boolean isAbstract, Boolean isHighest) {
+
+ List<Resource> resources = new ArrayList<>();
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+
+ propertiesToMatch.put(GraphPropertyEnum.IS_ABSTRACT, isAbstract);
+ if (isHighest != null) {
+ propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, isHighest.booleanValue());
+ }
+ propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+
+ Either<List<GraphVertex>, TitanOperationStatus> getResourcesRes = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
+
+ if (getResourcesRes.isRight()) {
+ log.debug("Failed to fetch all certified resources. Status is {}", getResourcesRes.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getResourcesRes.right().value()));
+ }
+ List<GraphVertex> resourceVerticies = getResourcesRes.left().value();
+ for (GraphVertex resourceV : resourceVerticies) {
+ Either<Resource, StorageOperationStatus> getResourceRes = getToscaElement(resourceV);
+ if (getResourceRes.isRight()) {
+ return Either.right(getResourceRes.right().value());
+ }
+ resources.add(getResourceRes.left().value());
+ }
+ return Either.left(resources);
+ }
+
+ public <T extends Component> Either<T, StorageOperationStatus> getLatestByNameAndVersion(String name, String version, JsonParseFlagEnum parseFlag) {
+ Either<T, StorageOperationStatus> result;
+
+ Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
+
+ hasProperties.put(GraphPropertyEnum.NAME, name);
+ hasProperties.put(GraphPropertyEnum.VERSION, version);
+ hasProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+
+ hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true);
+
+ Either<List<GraphVertex>, TitanOperationStatus> getResourceRes = titanDao.getByCriteria(null, hasProperties, hasNotProperties, parseFlag);
+ if (getResourceRes.isRight()) {
+ TitanOperationStatus status = getResourceRes.right().value();
+ log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return result;
+ }
+ return getToscaElementByOperation(getResourceRes.left().value().get(0));
+ }
+
+ public Either<Resource, StorageOperationStatus> getLatestComponentByCsarOrName(ComponentTypeEnum componentType, String csarUUID, String systemName) {
+ return getLatestComponentByCsarOrName(componentType, csarUUID, systemName, false, JsonParseFlagEnum.ParseAll);
+ }
+
+ public Either<Resource, StorageOperationStatus> getLatestComponentByCsarOrName(ComponentTypeEnum componentType, String csarUUID, String systemName, boolean allowDeleted, JsonParseFlagEnum parseFlag) {
+ Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
+ props.put(GraphPropertyEnum.CSAR_UUID, csarUUID);
+ props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ if (componentType != null) {
+ props.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+ }
+ Map<GraphPropertyEnum, Object> propsHasNot = new EnumMap<>(GraphPropertyEnum.class);
+ propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
+
+ GraphVertex resourceMetadataData = null;
+ List<GraphVertex> resourceMetadataDataList = null;
+ Either<List<GraphVertex>, TitanOperationStatus> byCsar = titanDao.getByCriteria(null, props, propsHasNot, JsonParseFlagEnum.ParseMetadata);
+ if (byCsar.isRight()) {
+ if (TitanOperationStatus.NOT_FOUND == byCsar.right().value()) {
+ // Fix Defect DE256036
+ if (StringUtils.isEmpty(systemName)) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.NOT_FOUND));
+ }
+
+ props.clear();
+ props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ props.put(GraphPropertyEnum.SYSTEM_NAME, systemName);
+ Either<List<GraphVertex>, TitanOperationStatus> bySystemname = titanDao.getByCriteria(null, props, JsonParseFlagEnum.ParseMetadata);
+ if (bySystemname.isRight()) {
+ log.debug("getLatestResourceByCsarOrName - Failed to find by system name {} error {} ", systemName, bySystemname.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(bySystemname.right().value()));
+ }
+ if (bySystemname.left().value().size() > 2) {
+ log.debug("getLatestResourceByCsarOrName - getByCriteria(by system name) must return only 2 latest version, but was returned - {}", bySystemname.left().value().size());
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ resourceMetadataDataList = bySystemname.left().value();
+ if (resourceMetadataDataList.size() == 1) {
+ resourceMetadataData = resourceMetadataDataList.get(0);
+ } else {
+ for (GraphVertex curResource : resourceMetadataDataList) {
+ if (!((String) curResource.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals("CERTIFIED")) {
+ resourceMetadataData = curResource;
+ break;
+ }
+ }
+ }
+ if (resourceMetadataData == null) {
+ log.debug("getLatestResourceByCsarOrName - getByCriteria(by system name) returned 2 latest CERTIFIED versions");
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ if (resourceMetadataData.getJsonMetadataField(JsonPresentationFields.CSAR_UUID) != null && !((String) resourceMetadataData.getJsonMetadataField(JsonPresentationFields.CSAR_UUID)).equals(csarUUID)) {
+ log.debug("getLatestResourceByCsarOrName - same system name {} but different csarUUID. exist {} and new {} ", systemName, resourceMetadataData.getJsonMetadataField(JsonPresentationFields.CSAR_UUID), csarUUID);
+ // correct error will be returned from create flow. with all
+ // correct audit records!!!!!
+ return Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ Either<Resource, StorageOperationStatus> resource = getToscaElement((String) resourceMetadataData.getUniqueId());
+ return resource;
+ }
+ } else {
+ resourceMetadataDataList = byCsar.left().value();
+ if (resourceMetadataDataList.size() > 2) {
+ log.debug("getLatestResourceByCsarOrName - getByCriteria(by csar) must return only 2 latest version, but was returned - {}", byCsar.left().value().size());
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ if (resourceMetadataDataList.size() == 1) {
+ resourceMetadataData = resourceMetadataDataList.get(0);
+ } else {
+ for (GraphVertex curResource : resourceMetadataDataList) {
+ if (!((String) curResource.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals("CERTIFIED")) {
+ resourceMetadataData = curResource;
+ break;
+ }
+ }
+ }
+ if (resourceMetadataData == null) {
+ log.debug("getLatestResourceByCsarOrName - getByCriteria(by csar) returned 2 latest CERTIFIED versions");
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ Either<Resource, StorageOperationStatus> resource = getToscaElement((String) resourceMetadataData.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID), parseFlag);
+ return resource;
+ }
+ return null;
+ }
+
+ public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExtends(String templateNameCurrent, String templateNameExtends) {
+
+ String currentTemplateNameChecked = templateNameExtends;
+
+ while (currentTemplateNameChecked != null && !currentTemplateNameChecked.equalsIgnoreCase(templateNameCurrent)) {
+ Either<Resource, StorageOperationStatus> latestByToscaResourceName = getLatestByToscaResourceName(currentTemplateNameChecked);
+
+ if (latestByToscaResourceName.isRight()) {
+ return latestByToscaResourceName.right().value() == StorageOperationStatus.NOT_FOUND ? Either.left(false) : Either.right(latestByToscaResourceName.right().value());
+ }
+
+ Resource value = latestByToscaResourceName.left().value();
+
+ if (value.getDerivedFrom() != null) {
+ currentTemplateNameChecked = value.getDerivedFrom().get(0);
+ } else {
+ currentTemplateNameChecked = null;
+ }
+ }
+
+ return (currentTemplateNameChecked != null && currentTemplateNameChecked.equalsIgnoreCase(templateNameCurrent)) ? Either.left(true) : Either.left(false);
+ }
+
+ public Either<List<Component>, StorageOperationStatus> fetchMetaDataByResourceType(String resourceType, ComponentParametersView filterBy) {
+ Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
+ props.put(GraphPropertyEnum.RESOURCE_TYPE, resourceType);
+ props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ Either<List<GraphVertex>, TitanOperationStatus> resourcesByTypeEither = titanDao.getByCriteria(null, props, JsonParseFlagEnum.ParseMetadata);
+
+ if (resourcesByTypeEither.isRight()) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resourcesByTypeEither.right().value()));
+ }
+
+ List<GraphVertex> vertexList = resourcesByTypeEither.left().value();
+ List<Component> components = new ArrayList<>();
+
+ for (GraphVertex vertex : vertexList) {
+ components.add(getToscaElementByOperation(vertex, filterBy).left().value());
+ }
+
+ return Either.left(components);
+ }
+
+ public void commit() {
+ titanDao.commit();
+ }
+
+ public Either<Service, StorageOperationStatus> updateDistributionStatus(Service service, User user, DistributionStatusEnum distributionStatus) {
+ Either<GraphVertex, StorageOperationStatus> updateDistributionStatus = topologyTemplateOperation.updateDistributionStatus(service.getUniqueId(), user, distributionStatus);
+ if (updateDistributionStatus.isRight()) {
+ return Either.right(updateDistributionStatus.right().value());
+ }
+ GraphVertex serviceV = updateDistributionStatus.left().value();
+ service.setDistributionStatus(distributionStatus);
+ service.setLastUpdateDate((Long) serviceV.getJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE));
+ return Either.left(service);
+ }
+
+ public Either<ComponentMetadataData, StorageOperationStatus> updateComponentLastUpdateDateOnGraph(Component component, Long modificationTime) {
+
+ Either<ComponentMetadataData, StorageOperationStatus> result = null;
+ GraphVertex serviceVertex;
+ Either<GraphVertex, TitanOperationStatus> updateRes = null;
+ Either<GraphVertex, TitanOperationStatus> getRes = titanDao.getVertexById(component.getUniqueId(), JsonParseFlagEnum.ParseMetadata);
+ if (getRes.isRight()) {
+ TitanOperationStatus status = getRes.right().value();
+ log.error("Failed to fetch component {}. status is {}", component.getUniqueId(), status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ if (result == null) {
+ serviceVertex = getRes.left().value();
+ long lastUpdateDate = System.currentTimeMillis();
+ serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
+ component.setLastUpdateDate(lastUpdateDate);
+ updateRes = titanDao.updateVertex(serviceVertex);
+ if (updateRes.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
+ }
+ }
+ if (result == null) {
+ result = Either.left(ModelConverter.convertToComponentMetadata(updateRes.left().value()));
+ }
+ return result;
+ }
+
+ public TitanDao getTitanDao() {
+ return titanDao;
+ }
+
+ public Either<List<Service>, StorageOperationStatus> getCertifiedServicesWithDistStatus(Set<DistributionStatusEnum> distStatus) {
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+
+ return getServicesWithDistStatus(distStatus, propertiesToMatch);
+ }
+
+ public Either<List<Service>, StorageOperationStatus> getServicesWithDistStatus(Set<DistributionStatusEnum> distStatus, Map<GraphPropertyEnum, Object> additionalPropertiesToMatch) {
+
+ List<Service> servicesAll = new ArrayList<>();
+
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+
+ if (additionalPropertiesToMatch != null && !additionalPropertiesToMatch.isEmpty()) {
+ propertiesToMatch.putAll(additionalPropertiesToMatch);
+ }
+
+ propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+
+ if (distStatus != null && !distStatus.isEmpty()) {
+ for (DistributionStatusEnum state : distStatus) {
+ propertiesToMatch.put(GraphPropertyEnum.DISTRIBUTION_STATUS, state.name());
+ Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria = fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch);
+ if (fetchServicesByCriteria.isRight()) {
+ return fetchServicesByCriteria;
+ } else {
+ servicesAll = fetchServicesByCriteria.left().value();
+ }
+ }
+ return Either.left(servicesAll);
+ } else {
+ return fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch);
+ }
+ }
+
+ // private Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria(List<Service> servicesAll, Map<GraphPropertyEnum, Object> propertiesToMatch, Map<GraphPropertyEnum, Object> propertiesNotToMatch) {
+ // Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
+ // if (getRes.isRight()) {
+ // if (getRes.right().value() != TitanOperationStatus.NOT_FOUND) {
+ // CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified services by match properties {} not match properties {} . Status is {}. ", propertiesToMatch, propertiesNotToMatch, getRes.right().value());
+ // return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
+ // }
+ // } else {
+ // for (GraphVertex vertex : getRes.left().value()) {
+ // Either<Component, StorageOperationStatus> getServiceRes = getToscaElementByOperation(vertex);
+ // if (getServiceRes.isRight()) {
+ // CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified service {}. Status is {}. ", vertex.getJsonMetadataField(JsonPresentationFields.NAME), getServiceRes.right().value());
+ // return Either.right(getServiceRes.right().value());
+ // } else {
+ // servicesAll.add((Service) getToscaElementByOperation(vertex).left().value());
+ // }
+ // }
+ // }
+ // return Either.left(servicesAll);
+ // }
+
+ private Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria(List<Service> servicesAll, Map<GraphPropertyEnum, Object> propertiesToMatch, Map<GraphPropertyEnum, Object> propertiesNotToMatch) {
+ Either<List<GraphVertex>, TitanOperationStatus> getRes = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
+ if (getRes.isRight()) {
+ if (getRes.right().value() != TitanOperationStatus.NOT_FOUND) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified services by match properties {} not match properties {} . Status is {}. ", propertiesToMatch, propertiesNotToMatch, getRes.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getRes.right().value()));
+ }
+ } else {
+ for (GraphVertex vertex : getRes.left().value()) {
+ // Either<Component, StorageOperationStatus> getServiceRes = getToscaElementByOperation(vertex);
+ Either<ToscaElement, StorageOperationStatus> getServiceRes = topologyTemplateOperation.getLightComponent(vertex, ComponentTypeEnum.SERVICE, new ComponentParametersView(true));
+
+ if (getServiceRes.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch certified service {}. Status is {}. ", vertex.getJsonMetadataField(JsonPresentationFields.NAME), getServiceRes.right().value());
+ return Either.right(getServiceRes.right().value());
+ } else {
+ servicesAll.add(ModelConverter.convertFromToscaElement(getServiceRes.left().value()));
+ }
+ }
+ }
+ return Either.left(servicesAll);
+ }
+
+ public void rollback() {
+ titanDao.rollback();
+ }
+
+ public StorageOperationStatus addDeploymentArtifactsToInstance(String componentId, ComponentInstance componentInstance, Map<String, ArtifactDefinition> finalDeploymentArtifacts) {
+ Map<String, ArtifactDataDefinition> instDeplArtifacts = finalDeploymentArtifacts.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
+
+ return nodeTemplateOperation.addDeploymentArtifactsToInstance(componentId, componentInstance.getUniqueId(), instDeplArtifacts);
+ }
+
+ public StorageOperationStatus addInformationalArtifactsToInstance(String componentId, ComponentInstance componentInstance, Map<String, ArtifactDefinition> artifacts) {
+ StorageOperationStatus status = StorageOperationStatus.OK;
+ if (MapUtils.isNotEmpty(artifacts)) {
+ Map<String, ArtifactDataDefinition> instDeplArtifacts = artifacts.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
+ status = nodeTemplateOperation.addInformationalArtifactsToInstance(componentId, componentInstance.getUniqueId(), instDeplArtifacts);
+ }
+ return status;
+ }
+
+ public StorageOperationStatus generateCustomizationUUIDOnInstance(String componentId, String instanceId) {
+ return nodeTemplateOperation.generateCustomizationUUIDOnInstance(componentId, instanceId);
+ }
+
+ public StorageOperationStatus generateCustomizationUUIDOnInstanceGroup(String componentId, String instanceId, List<String> groupInstances) {
+ return nodeTemplateOperation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances);
+ }
+
+ /*
+ * adds property to a resource
+ * @warn this method has SIDE EFFECT on ownerId ,use it with caution
+ * */
+ public Either<PropertyDefinition, StorageOperationStatus> addPropertyToResource(String propertyName, PropertyDefinition newPropertyDefinition, Resource resource) {
+
+ Either<PropertyDefinition, StorageOperationStatus> result = null;
+ Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
+ newPropertyDefinition.setName(propertyName);
+ // newPropertyDefinition.setParentUniqueId(resource.getUniqueId()); //todo- DELETE me after 10.18, ownerId==null => current resource is the owner. ownerId should be null since coming for the servlet => changing self resource property, assigning a null value actually means that the property has no assigned owner ,therfor current resource is the owner
+ StorageOperationStatus status = getToscaElementOperation(resource).addToscaDataToToscaElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME);
+ if (status != StorageOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", propertyName, resource.getName(), status);
+ result = Either.right(status);
+ }
+ if (result == null) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreProperties(false);
+ getUpdatedComponentRes = getToscaElement(resource.getUniqueId(), filter);
+ if (getUpdatedComponentRes.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", resource.getUniqueId(), getUpdatedComponentRes.right().value());
+ result = Either.right(status);
+ }
+ }
+ if (result == null) {
+ PropertyDefinition newProperty = null;
+ List<PropertyDefinition> properties = ((Resource) getUpdatedComponentRes.left().value()).getProperties();
+ if (CollectionUtils.isNotEmpty(properties)) {
+ Optional<PropertyDefinition> newPropertyOptional = properties.stream().filter(p -> p.getName().equals(propertyName)).findAny();
+ if (newPropertyOptional.isPresent()) {
+ newProperty = newPropertyOptional.get();
+ }
+ }
+ if (newProperty == null) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", propertyName, resource.getUniqueId(), StorageOperationStatus.NOT_FOUND);
+ result = Either.right(StorageOperationStatus.NOT_FOUND);
+ } else {
+ result = Either.left(newProperty);
+ }
+ }
+ return result;
+ }
+
+ public StorageOperationStatus deletePropertyOfResource(Resource resource, String propertyName) {
+ return getToscaElementOperation(resource).deleteToscaDataElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, propertyName, JsonPresentationFields.NAME);
+ }
+
+ public StorageOperationStatus deleteAttributeOfResource(Component component, String attributeName) {
+ return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, attributeName, JsonPresentationFields.NAME);
+ }
+
+ public StorageOperationStatus deleteInputOfResource(Component resource, String inputName) {
+ return getToscaElementOperation(resource).deleteToscaDataElement(resource.getUniqueId(), EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, inputName, JsonPresentationFields.NAME);
+ }
+
+ public Either<PropertyDefinition, StorageOperationStatus> updatePropertyOfResource(Resource resource, PropertyDefinition newPropertyDefinition) {
+
+ Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
+ Either<PropertyDefinition, StorageOperationStatus> result = null;
+ StorageOperationStatus status = getToscaElementOperation(resource).updateToscaDataOfToscaElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME);
+ if (status != StorageOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newPropertyDefinition.getName(), resource.getName(), status);
+ result = Either.right(status);
+ }
+ if (result == null) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreProperties(false);
+ getUpdatedComponentRes = getToscaElement(resource.getUniqueId(), filter);
+ if (getUpdatedComponentRes.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", resource.getUniqueId(), getUpdatedComponentRes.right().value());
+ result = Either.right(status);
+ }
+ }
+ if (result == null) {
+ Optional<PropertyDefinition> newProperty = ((Resource) getUpdatedComponentRes.left().value()).getProperties().stream().filter(p -> p.getName().equals(newPropertyDefinition.getName())).findAny();
+ if (newProperty.isPresent()) {
+ result = Either.left(newProperty.get());
+ } else {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newPropertyDefinition.getName(), resource.getUniqueId(), StorageOperationStatus.NOT_FOUND);
+ result = Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ }
+ return result;
+ }
+
+ public Either<PropertyDefinition, StorageOperationStatus> addAttributeOfResource(Component component, PropertyDefinition newAttributeDef) {
+
+ Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
+ Either<PropertyDefinition, StorageOperationStatus> result = null;
+ if (newAttributeDef.getUniqueId() == null || newAttributeDef.getUniqueId().isEmpty()) {
+ String attUniqueId = UniqueIdBuilder.buildAttributeUid(component.getUniqueId(), newAttributeDef.getName());
+ newAttributeDef.setUniqueId(attUniqueId);
+ }
+
+ StorageOperationStatus status = getToscaElementOperation(component).addToscaDataToToscaElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, newAttributeDef, JsonPresentationFields.NAME);
+ if (status != StorageOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newAttributeDef.getName(), component.getName(), status);
+ result = Either.right(status);
+ }
+ if (result == null) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreAttributesFrom(false);
+ getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
+ if (getUpdatedComponentRes.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
+ result = Either.right(status);
+ }
+ }
+ if (result == null) {
+ Optional<PropertyDefinition> newAttribute = ((Resource) getUpdatedComponentRes.left().value()).getAttributes().stream().filter(p -> p.getName().equals(newAttributeDef.getName())).findAny();
+ if (newAttribute.isPresent()) {
+ result = Either.left(newAttribute.get());
+ } else {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newAttributeDef.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
+ result = Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ }
+ return result;
+ }
+
+ public Either<PropertyDefinition, StorageOperationStatus> updateAttributeOfResource(Component component, PropertyDefinition newAttributeDef) {
+
+ Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
+ Either<PropertyDefinition, StorageOperationStatus> result = null;
+ StorageOperationStatus status = getToscaElementOperation(component).updateToscaDataOfToscaElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, newAttributeDef, JsonPresentationFields.NAME);
+ if (status != StorageOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newAttributeDef.getName(), component.getName(), status);
+ result = Either.right(status);
+ }
+ if (result == null) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreAttributesFrom(false);
+ getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
+ if (getUpdatedComponentRes.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
+ result = Either.right(status);
+ }
+ }
+ if (result == null) {
+ Optional<PropertyDefinition> newProperty = ((Resource) getUpdatedComponentRes.left().value()).getAttributes().stream().filter(p -> p.getName().equals(newAttributeDef.getName())).findAny();
+ if (newProperty.isPresent()) {
+ result = Either.left(newProperty.get());
+ } else {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newAttributeDef.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
+ result = Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ }
+ return result;
+ }
+
+ public Either<InputDefinition, StorageOperationStatus> updateInputOfComponent(Component component, InputDefinition newInputDefinition) {
+
+ Either<Component, StorageOperationStatus> getUpdatedComponentRes = null;
+ Either<InputDefinition, StorageOperationStatus> result = null;
+ StorageOperationStatus status = getToscaElementOperation(component).updateToscaDataOfToscaElement(component.getUniqueId(), EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, newInputDefinition, JsonPresentationFields.NAME);
+ if (status != StorageOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the input {} to the component {}. Status is {}. ", newInputDefinition.getName(), component.getName(), status);
+ result = Either.right(status);
+ }
+ if (result == null) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreInputs(false);
+ getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter);
+ if (getUpdatedComponentRes.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value());
+ result = Either.right(status);
+ }
+ }
+ if (result == null) {
+ Optional<InputDefinition> updatedInput = getUpdatedComponentRes.left().value().getInputs().stream().filter(p -> p.getName().equals(newInputDefinition.getName())).findAny();
+ if (updatedInput.isPresent()) {
+ result = Either.left(updatedInput.get());
+ } else {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently updated inputs {} on the resource {}. Status is {}. ", newInputDefinition.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND);
+ result = Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * method - ename the group instances after referenced container name renamed flow - VF rename -(triggers)-> Group rename
+ *
+ * @param containerComponent
+ * - container such as service
+ * @param componentInstance
+ * - context component
+ * @param componentInstanceId
+ * - id
+ *
+ * @return - successfull/failed status
+ **/
+ public Either<StorageOperationStatus, StorageOperationStatus> cleanAndAddGroupInstancesToComponentInstance(Component containerComponent, ComponentInstance componentInstance, String componentInstanceId) {
+ String uniqueId = componentInstance.getUniqueId();
+ StorageOperationStatus status = nodeTemplateOperation.deleteToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_GROUPS, VertexTypeEnum.INST_GROUPS, uniqueId);
+ if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to delete group instances for container {}. error {] ", componentInstanceId, status);
+ return Either.right(status);
+ }
+ if (componentInstance.getGroupInstances() != null) {
+ status = addGroupInstancesToComponentInstance(containerComponent, componentInstance, componentInstance.getGroupInstances());
+ if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add group instances for container {}. error {] ", componentInstanceId, status);
+ return Either.right(status);
+ }
+ }
+ return Either.left(status);
+ }
+
+ public StorageOperationStatus addGroupInstancesToComponentInstance(Component containerComponent, ComponentInstance componentInstance, List<GroupDefinition> groups, Map<String, List<ArtifactDefinition>> groupInstancesArtifacts) {
+ return nodeTemplateOperation.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groups, groupInstancesArtifacts);
+ }
+
+ public Either<List<GroupDefinition>, StorageOperationStatus> updateGroupsOnComponent(Component component, ComponentTypeEnum componentType, List<GroupDataDefinition> updatedGroups) {
+ return groupsOperation.updateGroups(component, componentType, updatedGroups);
+ }
+
+ public Either<List<GroupInstance>, StorageOperationStatus> updateGroupInstancesOnComponent(Component component, ComponentTypeEnum componentType, String instanceId, List<GroupInstance> updatedGroupInstances) {
+ return groupsOperation.updateGroupInstances(component, componentType, instanceId, updatedGroupInstances);
+ }
+
+ public StorageOperationStatus addGroupInstancesToComponentInstance(Component containerComponent, ComponentInstance componentInstance, List<GroupInstance> groupInstances) {
+ return nodeTemplateOperation.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groupInstances);
+ }
+
+ public StorageOperationStatus addDeploymentArtifactsToComponentInstance(Component containerComponent, ComponentInstance componentInstance, Map<String, ArtifactDefinition> deploymentArtifacts) {
+ return nodeTemplateOperation.addDeploymentArtifactsToComponentInstance(containerComponent, componentInstance, deploymentArtifacts);
+ }
+
+ public StorageOperationStatus updateComponentInstanceProperty(Component containerComponent, String componentInstanceId, ComponentInstanceProperty property) {
+ return nodeTemplateOperation.updateComponentInstanceProperty(containerComponent, componentInstanceId, property);
+ }
+
+ public StorageOperationStatus updateComponentInstanceProperties(Component containerComponent, String componentInstanceId, List<ComponentInstanceProperty> properties) {
+ return nodeTemplateOperation.updateComponentInstanceProperties(containerComponent, componentInstanceId, properties);
+ }
+
+
+ public StorageOperationStatus addComponentInstanceProperty(Component containerComponent, String componentInstanceId, ComponentInstanceProperty property) {
+ return nodeTemplateOperation.addComponentInstanceProperty(containerComponent, componentInstanceId, property);
+ }
+
+ public StorageOperationStatus updateComponentInstanceInput(Component containerComponent, String componentInstanceId, ComponentInstanceInput property) {
+ return nodeTemplateOperation.updateComponentInstanceInput(containerComponent, componentInstanceId, property);
+ }
+
+ public StorageOperationStatus updateComponentInstanceInputs(Component containerComponent, String componentInstanceId, List<ComponentInstanceInput> instanceInputs) {
+ return nodeTemplateOperation.updateComponentInstanceInputs(containerComponent, componentInstanceId, instanceInputs);
+ }
+
+ public StorageOperationStatus addComponentInstanceInput(Component containerComponent, String componentInstanceId, ComponentInstanceInput property) {
+ return nodeTemplateOperation.addComponentInstanceInput(containerComponent, componentInstanceId, property);
+ }
+
+ public void setNodeTypeOperation(NodeTypeOperation nodeTypeOperation) {
+ this.nodeTypeOperation = nodeTypeOperation;
+ }
+
+ public void setTopologyTemplateOperation(TopologyTemplateOperation topologyTemplateOperation) {
+ this.topologyTemplateOperation = topologyTemplateOperation;
+ }
public StorageOperationStatus deleteComponentInstanceInputsFromTopologyTemplate(Component containerComponent, ComponentTypeEnum componentType, List<InputDefinition> inputsToDelete) {
return topologyTemplateOperation.deleteToscaDataElements(containerComponent.getUniqueId(), EdgeLabelEnum.INPUTS, inputsToDelete.stream().map(i -> i.getName()).collect(Collectors.toList()));
}
-
+
+ public StorageOperationStatus updateComponentInstanceCapabiltyProperty(Component containerComponent, String componentInstanceUniqueId, String capabilityUniqueId, ComponentInstanceProperty property) {
+ return nodeTemplateOperation.updateComponentInstanceCapabilityProperty(containerComponent, componentInstanceUniqueId, capabilityUniqueId, property);
+ }
+
public StorageOperationStatus deleteAllCalculatedCapabilitiesRequirements(String topologyTemplateId) {
StorageOperationStatus status = topologyTemplateOperation.removeToscaData(topologyTemplateId, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES);
- if(status == StorageOperationStatus.OK){
+ if (status == StorageOperationStatus.OK) {
status = topologyTemplateOperation.removeToscaData(topologyTemplateId, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS);
}
+ if(status == StorageOperationStatus.OK){
+ status = topologyTemplateOperation.removeToscaData(topologyTemplateId, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES);
+ }
return status;
}
@@ -2274,6 +2401,16 @@ public class ToscaOperationFacade {
}
return Either.left(clonedResource);
}
-
+ /**
+ * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name and type
+ * @param componentId
+ * @param instanceId
+ * @param capabilityName
+ * @param capabilityType
+ * @return
+ */
+ public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType) {
+ return topologyTemplateOperation.getComponentInstanceCapabilityProperties(componentId, instanceId, capabilityName, capabilityType);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java
index 973b0ce069..e89f63b12f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java
@@ -35,13 +35,32 @@ import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
-import org.openecomp.sdc.be.datatypes.elements.*;
+import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty;
+import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListCapabiltyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RelationshipInstDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
@@ -53,7 +72,7 @@ import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RelationshipImpl;
-import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
+import org.openecomp.sdc.be.model.RelationshipInfo;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
@@ -161,6 +180,7 @@ public class ModelConverter {
service.setDistributionStatus(DistributionStatusEnum.findState((String) toscaElement.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS)));
service.setEcompGeneratedNaming((Boolean) toscaElement.getMetadataValueOrDefault(JsonPresentationFields.ECOMP_GENERATED_NAMING, true));
service.setNamingPolicy((String) toscaElement.getMetadataValueOrDefault(JsonPresentationFields.NAMING_POLICY, StringUtils.EMPTY));
+ service.setEnvironmentContext((String) toscaElement.getMetadataValue(JsonPresentationFields.ENVIRONMENT_CONTEXT));
}
private static Resource convertToResource(ToscaElement toscaElement) {
@@ -309,10 +329,8 @@ public class ModelConverter {
RequirementCapabilityRelDef requirementCapabilityRelDef = new RequirementCapabilityRelDef();
requirementCapabilityRelDef.setFromNode(relation.getFromId());
requirementCapabilityRelDef.setToNode(relation.getToId());
- List<RequirementAndRelationshipPair> relationships = new ArrayList<>();
- RequirementAndRelationshipPair relationshipPair = new RequirementAndRelationshipPair();
+ RelationshipInfo relationshipPair = new RelationshipInfo();
relationshipPair.setId(relation.getUniqueId());
-
relationshipPair.setCapabilityOwnerId(relation.getCapabilityOwnerId());
relationshipPair.setCapabilityUid(relation.getCapabilityId());
relationshipPair.setCapability(relation.getCapability());
@@ -322,8 +340,10 @@ public class ModelConverter {
RelationshipImpl relationship = new RelationshipImpl();
relationship.setType(relation.getType());
relationshipPair.setRelationships(relationship);
-
- relationships.add(relationshipPair);
+ CapabilityRequirementRelationship rel = new CapabilityRequirementRelationship();
+ rel.setRelation(relationshipPair);
+ List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
+ relationships.add(rel);
requirementCapabilityRelDef.setRelationships(relationships);
return requirementCapabilityRelDef;
}
@@ -332,19 +352,19 @@ public class ModelConverter {
List<RelationshipInstDataDefinition> relationsList = new ArrayList<>();
- List<RequirementAndRelationshipPair> relationship = relation.getRelationships();
+ List<CapabilityRequirementRelationship> relationship = relation.getRelationships();
relationship.forEach(p -> {
RelationshipInstDataDefinition requirementCapabilityRelDef = new RelationshipInstDataDefinition();
requirementCapabilityRelDef.setFromId(relation.getFromNode());
requirementCapabilityRelDef.setToId(relation.getToNode());
- requirementCapabilityRelDef.setUniqueId(p.getId());
- requirementCapabilityRelDef.setCapabilityOwnerId(p.getCapabilityOwnerId());
- requirementCapabilityRelDef.setCapabilityId(p.getCapabilityUid());
- requirementCapabilityRelDef.setRequirementOwnerId(p.getRequirementOwnerId());
- requirementCapabilityRelDef.setRequirementId(p.getRequirementUid());
- requirementCapabilityRelDef.setRequirement(p.getRequirement());
- requirementCapabilityRelDef.setType(p.getRelationship().getType());
- requirementCapabilityRelDef.setCapability(p.getCapability());
+ requirementCapabilityRelDef.setUniqueId(p.getRelation().getId());
+ requirementCapabilityRelDef.setCapabilityOwnerId(p.getRelation().getCapabilityOwnerId());
+ requirementCapabilityRelDef.setCapabilityId(p.getRelation().getCapabilityUid());
+ requirementCapabilityRelDef.setRequirementOwnerId(p.getRelation().getRequirementOwnerId());
+ requirementCapabilityRelDef.setRequirementId(p.getRelation().getRequirementUid());
+ requirementCapabilityRelDef.setRequirement(p.getRelation().getRequirement());
+ requirementCapabilityRelDef.setType(p.getRelation().getRelationship().getType());
+ requirementCapabilityRelDef.setCapability(p.getRelation().getCapability());
relationsList.add(requirementCapabilityRelDef);
});
@@ -408,7 +428,7 @@ public class ModelConverter {
sb.append(cap.getOwnerId());
}
sb.append(CAP_PROP_DELIM).append(s).append(CAP_PROP_DELIM).append(cap.getName());
- toscaCapPropMap.put(sb.toString(), dataToCreate);
+ toscaCapPropMap.put(sb.toString(), new MapPropertiesDataDefinition(dataToCreate));
}
}
@@ -455,54 +475,6 @@ public class ModelConverter {
return new MapListRequirementDataDefinition(mapToscaDataDefinition);
}
- private static void convertRequirements(TopologyTemplate toscaElement, Component component) {
-
- if (CollectionUtils.isNotEmpty(component.getComponentInstances())) {
- for (ComponentInstance instance : component.getComponentInstances()) {
- Map<String, List<RequirementDefinition>> instanceRequirements = instance.getRequirements();
- if (MapUtils.isNotEmpty(instanceRequirements)) {
- addRequirementsByInstanceId(instance.getUniqueId(), instanceRequirements, component);
- }
- }
- }
- }
-
- private static void addRequirementsByInstanceId(String instanceId, Map<String, List<RequirementDefinition>> instanceRequirementsMap, Component component) {
-
- if (component.getCapabilities() == null) {
- component.setCapabilities(new HashMap<>());
- }
- List<RequirementDefinition> instanceRequirements = new ArrayList<>();
- for (List<RequirementDefinition> instRequirements : instanceRequirementsMap.values()) {
- instanceRequirements.addAll(instRequirements);
- }
- component.getRequirements().put(instanceId, instanceRequirements);
- }
-
- private static void convertCapabilities(TopologyTemplate toscaElement, Component component) {
-
- if (CollectionUtils.isNotEmpty(component.getComponentInstances())) {
- for (ComponentInstance instance : component.getComponentInstances()) {
- Map<String, List<CapabilityDefinition>> instanceCapabilities = instance.getCapabilities();
- if (MapUtils.isNotEmpty(instanceCapabilities)) {
- addCapabilitiesByInstanceId(instance.getUniqueId(), instanceCapabilities, component);
- }
- }
- }
- }
-
- private static void addCapabilitiesByInstanceId(String instanceId, Map<String, List<CapabilityDefinition>> instanceCapabilitiesMap, Component component) {
-
- if (component.getCapabilities() == null) {
- component.setCapabilities(new HashMap<>());
- }
- List<CapabilityDefinition> instanceCapabilities = new ArrayList<>();
- for (List<CapabilityDefinition> instCapabilitis : instanceCapabilitiesMap.values()) {
- instanceCapabilities.addAll(instCapabilitis);
- }
- component.getCapabilities().put(instanceId, instanceCapabilities);
- }
-
@SuppressWarnings("unchecked")
private static void convertComponentFields(Component component, ToscaElement toscaElement) {
component.setName(toscaElement.getName());
@@ -909,6 +881,7 @@ public class ModelConverter {
topologyTemplate.setMetadataValue(JsonPresentationFields.PROJECT_CODE, service.getProjectCode());
topologyTemplate.setMetadataValue(JsonPresentationFields.ECOMP_GENERATED_NAMING, service.isEcompGeneratedNaming());
topologyTemplate.setMetadataValue(JsonPresentationFields.NAMING_POLICY, service.getNamingPolicy());
+ topologyTemplate.setMetadataValue(JsonPresentationFields.ENVIRONMENT_CONTEXT, service.getEnvironmentContext());
}
@@ -1125,10 +1098,15 @@ public class ModelConverter {
} else {
instancesCapabilities.put(capabilityType, caps);
}
- if (MapUtils.isEmpty(instancesMap.get(instanceId).getCapabilities())) {
- instancesMap.get(instanceId).setCapabilities(new HashMap<>());
+ ComponentInstance instance = instancesMap.get(instanceId);
+ if (instance == null) {
+ log.error("instance is null for id {} entry {}", instanceId, entry.getValue().getToscaPresentationValue(JsonPresentationFields.NAME));
+ } else {
+ if (MapUtils.isEmpty(instance.getCapabilities())) {
+ instance.setCapabilities(new HashMap<>());
+ }
+ instance.getCapabilities().put(capabilityType, new ArrayList<>(caps));
}
- instancesMap.get(instanceId).getCapabilities().put(capabilityType, new ArrayList<>(caps));
}
}
component.setCapabilities(instancesCapabilities);
@@ -1303,11 +1281,6 @@ public class ModelConverter {
if (MapUtils.isNotEmpty(groups)) {
groupDefinitions = groups.values().stream().map(g -> new GroupDefinition(g)).collect(Collectors.toList());
}
- /*
- * if (CollectionUtils.isNotEmpty(groupDefinitions) && MapUtils.isNotEmpty(groupsProperties)) { for (GroupDefinition groupDefinition : groupDefinitions) { if (groupsProperties.containsKey(groupDefinition.getName())) { Map<String,
- * PropertyDataDefinition> properties = groupsProperties.get(groupDefinition.getName()).getMapToscaDataDefinition(); if (MapUtils.isNotEmpty(properties)) { groupDefinition.setProperties(properties.values().stream().map(p -> new
- * GroupProperty(p)).collect(Collectors.toList())); } } } }
- */
return groupDefinitions;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IAdditionalInformationOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IAdditionalInformationOperation.java
index eb6492fa84..9036c6275a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IAdditionalInformationOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IAdditionalInformationOperation.java
@@ -28,7 +28,6 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
import org.openecomp.sdc.be.resources.data.AdditionalInfoParameterData;
-import com.thinkaurelius.titan.core.TitanTransaction;
import com.thinkaurelius.titan.core.TitanVertex;
import fj.data.Either;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IArtifactOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IArtifactOperation.java
index 3d689a4f93..5393dbed6c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IArtifactOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IArtifactOperation.java
@@ -22,12 +22,8 @@ package org.openecomp.sdc.be.model.operations.api;
import java.util.Map;
-import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.resources.data.ArtifactData;
import com.thinkaurelius.titan.core.TitanVertex;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICacheMangerOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICacheMangerOperation.java
index 52586dad60..6b5a143be3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICacheMangerOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICacheMangerOperation.java
@@ -21,9 +21,6 @@
package org.openecomp.sdc.be.model.operations.api;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.cache.jobs.CheckAndUpdateJob;
-import org.openecomp.sdc.be.model.cache.jobs.StoreJob;
/**
* Created by mlando on 9/5/2016.
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICapabilityOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICapabilityOperation.java
index b90f31f731..96c0e7e5db 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICapabilityOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/ICapabilityOperation.java
@@ -23,16 +23,8 @@ package org.openecomp.sdc.be.model.operations.api;
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.resources.data.CapabilityData;
-import org.openecomp.sdc.be.resources.data.CapabilityTypeData;
-import org.openecomp.sdc.be.resources.data.PropertyData;
-
-import com.thinkaurelius.titan.core.TitanVertex;
import fj.data.Either;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IComponentInstanceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IComponentInstanceOperation.java
index d1a1b6ac7b..90e01c3980 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IComponentInstanceOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IComponentInstanceOperation.java
@@ -20,26 +20,12 @@
package org.openecomp.sdc.be.model.operations.api;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
-import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.AttributeValueData;
-import org.openecomp.sdc.be.resources.data.CapabilityData;
import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
-import org.openecomp.sdc.be.resources.data.RequirementData;
-import org.openecomp.sdc.exception.ResponseFormat;
import fj.data.Either;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IConsumerOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IConsumerOperation.java
index cab49fe47d..c9e6d69cc3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IConsumerOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IConsumerOperation.java
@@ -20,12 +20,12 @@
package org.openecomp.sdc.be.model.operations.api;
+import java.util.List;
+
import org.openecomp.sdc.be.resources.data.ConsumerData;
import fj.data.Either;
-import java.util.List;
-
public interface IConsumerOperation {
/**
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupInstanceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupInstanceOperation.java
index b55eff6684..6fe56d04b1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupInstanceOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupInstanceOperation.java
@@ -21,25 +21,12 @@
package org.openecomp.sdc.be.model.operations.api;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-
-import org.openecomp.sdc.be.model.ComponentInstance;
-
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupInstance;
-import org.openecomp.sdc.be.model.GroupInstanceProperty;
import org.openecomp.sdc.be.resources.data.ArtifactData;
-import org.openecomp.sdc.exception.ResponseFormat;
-
-import com.thinkaurelius.titan.core.TitanVertex;
import fj.data.Either;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupOperation.java
index 6dbbfb6b6e..0695346c5c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupOperation.java
@@ -25,10 +25,8 @@ import java.util.List;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupProperty;
import org.openecomp.sdc.be.resources.data.ArtifactData;
-import org.openecomp.sdc.be.resources.data.GroupData;
import fj.data.Either;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInputsOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInputsOperation.java
index 1cec537e3e..54405cf86c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInputsOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInputsOperation.java
@@ -20,16 +20,10 @@
package org.openecomp.sdc.be.model.operations.api;
-import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
-import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.resources.data.InputValueData;
-import org.openecomp.sdc.be.resources.data.InputsData;
-
-import java.util.List;
public interface IInputsOperation {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java
index c9a332f069..ca29ab0f6e 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java
@@ -22,13 +22,10 @@ package org.openecomp.sdc.be.model.operations.api;
import java.util.Map;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
-import com.thinkaurelius.titan.core.TitanVertex;
-
import fj.data.Either;
public interface IInterfaceLifecycleOperation {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IUserAdminOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IUserAdminOperation.java
index 3df954fc36..6f33643db5 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IUserAdminOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IUserAdminOperation.java
@@ -23,11 +23,8 @@ package org.openecomp.sdc.be.model.operations.api;
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.model.FunctionalMenuInfo;
import org.openecomp.sdc.be.model.User;
import fj.data.Either;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperation.java
index d9fe1eea92..9ef116d0c9 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperation.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.model.operations.impl;
-import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java
index cadcd32926..d677a7e257 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CacheMangerOperation.java
@@ -20,14 +20,28 @@
package org.openecomp.sdc.be.model.operations.impl;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.LinkedList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.cache.*;
-import org.openecomp.sdc.be.model.cache.jobs.*;
+import org.openecomp.sdc.be.model.cache.ComponentCache;
+import org.openecomp.sdc.be.model.cache.DaoInfo;
+import org.openecomp.sdc.be.model.cache.jobs.CheckAndUpdateJob;
+import org.openecomp.sdc.be.model.cache.jobs.DeleteJob;
+import org.openecomp.sdc.be.model.cache.jobs.Job;
+import org.openecomp.sdc.be.model.cache.jobs.OverrideJob;
+import org.openecomp.sdc.be.model.cache.jobs.StoreJob;
import org.openecomp.sdc.be.model.cache.workers.CacheWorker;
import org.openecomp.sdc.be.model.cache.workers.IWorker;
import org.openecomp.sdc.be.model.cache.workers.SyncWorker;
@@ -39,10 +53,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import java.util.LinkedList;
-import java.util.concurrent.*;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
/**
* Created by mlando on 9/5/2016. the class is responsible for handling all cache update operations asynchronously including sync between the graph and cache and on demand update requests
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityOperation.java
index a4be274781..175c695e73 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityOperation.java
@@ -20,49 +20,26 @@
package org.openecomp.sdc.be.model.operations.impl;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import java.util.stream.Collectors;
-import org.antlr.misc.Graph;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
-import org.openecomp.sdc.be.dao.graph.GraphElementFactory;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.operations.api.ICapabilityOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.resources.data.CapabilityData;
import org.openecomp.sdc.be.resources.data.CapabilityTypeData;
-import org.openecomp.sdc.be.resources.data.PropertyData;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.be.resources.data.UniqueIdData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.fasterxml.jackson.databind.annotation.JsonAppend.Prop;
-import com.thinkaurelius.titan.core.TitanVertex;
-
import fj.data.Either;
@Component("capability-operation")
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java
index 1ef64aed98..e67f9a4866 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ComponentInstanceOperation.java
@@ -20,9 +20,11 @@
package org.openecomp.sdc.be.model.operations.impl;
-import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.core.TitanVertex;
-import fj.data.Either;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Supplier;
+
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
@@ -59,10 +61,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import java.util.function.Supplier;
+import com.thinkaurelius.titan.core.TitanGraph;
+import com.thinkaurelius.titan.core.TitanVertex;
+
+import fj.data.Either;
@org.springframework.stereotype.Component("component-instance-operation")
public class ComponentInstanceOperation extends AbstractOperation implements IComponentInstanceOperation {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ConsumerOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ConsumerOperation.java
index a5a1348f21..198ad99ecb 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ConsumerOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ConsumerOperation.java
@@ -20,6 +20,9 @@
package org.openecomp.sdc.be.model.operations.impl;
+import java.util.Collections;
+import java.util.List;
+
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
@@ -34,9 +37,6 @@ import org.springframework.stereotype.Component;
import fj.data.Either;
-import java.util.Collections;
-import java.util.List;
-
@Component("consumer-operation")
public class ConsumerOperation implements IConsumerOperation {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java
index 815eb5be0e..88edb1fd9e 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java
@@ -35,6 +35,11 @@ import org.openecomp.sdc.common.util.ZipUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+
import fj.data.Either;
@org.springframework.stereotype.Component("csar-operation")
@@ -105,6 +110,41 @@ public class CsarOperation {
return result;
}
+
+ @SuppressWarnings("unchecked")
+ public Either<String, StorageOperationStatus> getCsarLatestVersion(String csarUuid, User user) {
+
+ Either<String, StorageOperationStatus> result = onboardingClient.getPackages(user.getUserId());
+
+ if (result.isRight()) {
+ log.debug("Cannot find version for package with Id {}. Status returned is {}", csarUuid, result.right().value());
+ } else {
+ String latestVersion = null;
+ JsonElement root = new JsonParser().parse(result.left().value());
+ JsonArray csarsInfo = root.getAsJsonObject().get("results").getAsJsonArray();
+ for (JsonElement csarInfo : csarsInfo) {
+ Map<String, String> csarInfoMap = new Gson().fromJson(csarInfo, Map.class);
+ if(csarInfoMap.get("packageId").equals(csarUuid)){
+ String curVersion = csarInfoMap.get("version");
+ if(latestVersion == null || isGreater(latestVersion, curVersion)){
+ latestVersion = curVersion;
+ }
+ }
+ }
+ if (latestVersion != null) {
+ result = Either.left(latestVersion);
+ } else {
+ log.debug("The returned packages are {}. Failed to find latest version for package with Id {}. ", result.left().value(), csarUuid);
+ result = Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ }
+
+ return result;
+ }
+
+ private boolean isGreater(String latestVersion, String currentVersion) {
+ return Double.parseDouble(latestVersion) < Double.parseDouble(currentVersion);
+ }
public OnboardingClient getOnboardingClient() {
return onboardingClient;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java
index ea42c6d76b..41f6ce9d00 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java
@@ -28,8 +28,8 @@ import java.util.Map;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.Configuration.ArtifactTypeConfig;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java
index 4ffea48dee..c4a5c5c586 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java
@@ -20,14 +20,17 @@
package org.openecomp.sdc.be.model.operations.impl;
-import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.core.TitanVertex;
-import fj.data.Either;
-import org.apache.commons.collections.CollectionUtils;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -65,14 +68,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
+import com.thinkaurelius.titan.core.TitanGraph;
+import com.thinkaurelius.titan.core.TitanVertex;
+
+import fj.data.Either;
@org.springframework.stereotype.Component("group-instance-operation")
public class GroupInstanceOperation extends AbstractOperation implements IGroupInstanceOperation {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java
index 02c5194da3..77e7ba1f2d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupOperation.java
@@ -24,44 +24,31 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
import java.util.stream.Collectors;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupProperty;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.ArtifactData;
import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
-import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
import org.openecomp.sdc.be.resources.data.GroupData;
import org.openecomp.sdc.be.resources.data.GroupTypeData;
import org.openecomp.sdc.be.resources.data.PropertyData;
import org.openecomp.sdc.be.resources.data.PropertyValueData;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.be.resources.data.ServiceMetadataData;
import org.openecomp.sdc.be.resources.data.UniqueIdData;
-import org.openecomp.sdc.common.datastructure.Wrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java
index ad56779a94..0a150ae7c3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java
@@ -25,7 +25,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import com.thinkaurelius.titan.core.TitanTransaction;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
@@ -36,7 +35,6 @@ import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.HeatParameterDefinition;
-import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.heat.HeatParameterType;
import org.openecomp.sdc.be.model.operations.api.IHeatParametersOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InputsOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InputsOperation.java
index 782c78715f..287a63ea3a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InputsOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InputsOperation.java
@@ -21,69 +21,31 @@
package org.openecomp.sdc.be.model.operations.impl;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
-import javax.json.Json;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.tinkerpop.gremlin.process.traversal.Order;
-import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.ParseException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
-import org.openecomp.sdc.be.dao.graph.GraphElementFactory;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
-
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.ComponentInstInputsMap;
-import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
-import org.openecomp.sdc.be.model.ComponentInstancePropInput;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.PropertyConstraint;
-import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.operations.api.IInputsOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.resources.data.AttributeData;
import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
-import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
import org.openecomp.sdc.be.resources.data.InputValueData;
import org.openecomp.sdc.be.resources.data.InputsData;
import org.openecomp.sdc.be.resources.data.PropertyData;
-import org.openecomp.sdc.be.resources.data.PropertyValueData;
import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.be.resources.data.UniqueIdData;
-import org.openecomp.sdc.common.datastructure.Wrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import org.yaml.snakeyaml.Yaml;
import com.google.gson.Gson;
-import com.thinkaurelius.titan.core.TitanEdge;
-import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.core.TitanVertex;
-import com.thinkaurelius.titan.core.TitanVertexQuery;
-import com.thinkaurelius.titan.core.attribute.Cmp;
import fj.data.Either;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java
index 1c03d579a0..b78ad02452 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java
@@ -29,7 +29,6 @@ import java.util.Set;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java
index 033d5c268b..9b6591ec08 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java
@@ -32,13 +32,14 @@ import javax.annotation.PostConstruct;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.http.HttpStatus;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.config.Configuration.OnboardingConfig;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.rest.HttpRestClient;
import org.openecomp.sdc.be.dao.rest.RestConfigurationInfo;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.rest.api.RestResponse;
import org.openecomp.sdc.common.rest.api.RestResponseAsByteArray;
import org.openecomp.sdc.common.util.ZipUtil;
import org.slf4j.Logger;
@@ -156,6 +157,41 @@ public class OnboardingClient {
}
}
+
+ public Either<String, StorageOperationStatus> getPackages(String userId) {
+
+ if (httpRestClient == null) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("RestClient", "Rest Client could not be initialized", ErrorSeverity.ERROR);
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+
+ String url = buildDownloadCsarUrl();
+
+ Properties headers = new Properties();
+ headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
+
+ if (userId != null) {
+ headers.put(Constants.USER_ID_HEADER, userId);
+ }
+
+ log.debug("Url for downloading packages is {}. Headers are {}", url, headers);
+
+ RestResponse restResponse = httpRestClient.doGET(url, headers);
+ log.debug("After fetching packages. Http return code is {}", restResponse.getHttpStatusCode());
+
+ switch (restResponse.getHttpStatusCode()) {
+ case HttpStatus.SC_OK:
+ String data = restResponse.getResponse();
+ return Either.left(data);
+
+ case HttpStatus.SC_NOT_FOUND:
+ return Either.right(StorageOperationStatus.CSAR_NOT_FOUND);
+
+ default:
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+
+ }
public HttpRestClient getHttpRestClient() {
return httpRestClient;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UserAdminOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UserAdminOperation.java
index 62ab886472..9aa231497d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UserAdminOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UserAdminOperation.java
@@ -20,9 +20,12 @@
package org.openecomp.sdc.be.model.operations.impl;
-import com.thinkaurelius.titan.core.TitanVertex;
-import fj.data.Either;
-import org.apache.commons.lang3.tuple.ImmutablePair;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -35,12 +38,10 @@ import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.FunctionalMenuInfo;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.UserData;
-import org.openecomp.sdc.be.resources.data.UserFunctionalMenuData;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
import org.slf4j.Logger;
@@ -48,11 +49,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import com.thinkaurelius.titan.core.TitanVertex;
+
+import fj.data.Either;
@Component("user-operation")
public class UserAdminOperation implements IUserAdminOperation {
@@ -98,7 +97,7 @@ public class UserAdminOperation implements IUserAdminOperation {
return resultWrapper.getInnerElement();
} finally {
- if (false == inTransaction) {
+ if (!inTransaction) {
titanGenericDao.commit();
}
log.debug("getUserData - end");
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtils.java
index 01c9eefb20..2c2d3e7598 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtils.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtils.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.model.operations.utils;
-import fj.data.Either;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
@@ -30,6 +29,8 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import fj.data.Either;
+
public class ComponentValidationUtils {
private static Logger log = LoggerFactory.getLogger(ComponentValidationUtils.class.getName());
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintFunctionalException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintFunctionalException.java
index 3fd165f41e..c4237e9bcb 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintFunctionalException.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintFunctionalException.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.model.tosca.constraints.exception;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil;
import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil.ConstraintInformation;
/**
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintRequiredParameterException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintRequiredParameterException.java
index 2416405de4..338e4aa51a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintRequiredParameterException.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintRequiredParameterException.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.model.tosca.constraints.exception;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil;
import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil.ConstraintInformation;
/**
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintValueDoNotMatchPropertyTypeException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintValueDoNotMatchPropertyTypeException.java
index 6ba0d9b864..10d4e44fe2 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintValueDoNotMatchPropertyTypeException.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintValueDoNotMatchPropertyTypeException.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.model.tosca.constraints.exception;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil;
import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil.ConstraintInformation;
/**
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintViolationException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintViolationException.java
index 7fce63841d..29db0aa1af 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintViolationException.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/exception/ConstraintViolationException.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.model.tosca.constraints.exception;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil;
import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil.ConstraintInformation;
/**
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
index f3b842e0cf..32929beb5f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
@@ -1,18 +1,19 @@
package org.openecomp.sdc.be.model.tosca.converters;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.common.util.JsonUtils;
+
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.common.util.JsonUtils;
-
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
public class DataTypePropertyConverter {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/JsonConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/JsonConverter.java
index 3879430e06..3472b6448c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/JsonConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/JsonConverter.java
@@ -28,7 +28,6 @@ import org.openecomp.sdc.common.util.GsonFactory;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java
index 159addcbc9..4aadaa0910 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java
@@ -1,9 +1,9 @@
package org.openecomp.sdc.be.model.tosca.converters;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
+import com.google.gson.JsonObject;
+
public class ToscaConverterUtils {
public static boolean isGetInputValue(JsonObject value) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java
index 3240ccc679..1466980156 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/DataTypeValidatorConverter.java
@@ -29,7 +29,6 @@ import java.util.Set;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java
index 164fe62792..6a1aff558f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/JsonValidator.java
@@ -23,17 +23,10 @@ package org.openecomp.sdc.be.model.tosca.validators;
import java.io.StringReader;
import java.util.Map;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
-import org.openecomp.sdc.common.util.GsonFactory;
-import org.openecomp.sdc.common.util.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.google.gson.stream.JsonReader;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java
index a096990ad7..dad3461c91 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/StringValidator.java
@@ -22,8 +22,8 @@ package org.openecomp.sdc.be.model.tosca.validators;
import java.util.Map;
-import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.Configuration.ToscaValidatorsConfig;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.slf4j.Logger;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
index 6ebb32e7f5..d699f28d07 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
@@ -23,7 +23,6 @@ package org.openecomp.sdc.be.ui.model;
import java.util.List;
import java.util.Map;
-import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
@@ -33,8 +32,6 @@ import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentMetadata.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentMetadata.java
index dfc4c8c994..0719655704 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentMetadata.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentMetadata.java
@@ -25,7 +25,6 @@ import java.util.Map;
import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
public abstract class UiComponentMetadata {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceMetadata.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceMetadata.java
index 68abb4d749..0923acb6d1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceMetadata.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceMetadata.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.ui.model;
import java.util.List;
+
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceMetadata.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceMetadata.java
index 9a79a26881..3ab45f2d0e 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceMetadata.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceMetadata.java
@@ -32,6 +32,7 @@ public class UiServiceMetadata extends UiComponentMetadata {
private String namingPolicy;
private String serviceType;
private String serviceRole;
+ private String environmentContext;
public UiServiceMetadata(List<CategoryDefinition> categories, ServiceMetadataDataDefinition metadata) {
super(categories, metadata);
@@ -40,6 +41,7 @@ public class UiServiceMetadata extends UiComponentMetadata {
this.namingPolicy = metadata.getNamingPolicy();
this.serviceType = metadata.getServiceType();
this.serviceRole = metadata.getServiceRole();
+ this.environmentContext = metadata.getEnvironmentContext();
}
public String getDistributionStatus() {
@@ -82,4 +84,7 @@ public class UiServiceMetadata extends UiComponentMetadata {
this.serviceRole = serviceRole;
}
+ public String getEnvironmentContext() { return environmentContext; }
+
+ public void setEnvironmentContext(String environmentContext) { this.environmentContext = environmentContext; }
}