aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2018-03-04 14:53:33 +0200
committerMichael Lando <ml636r@att.com>2018-03-07 13:19:05 +0000
commita5445100050e49e83f73424198d73cd72d672a4d (patch)
treecacf4df817df31be23e4e790d1dda857bdae061e /catalog-model/src/main
parent51157f92c21976cba4914c378aaa3cba49826931 (diff)
Sync Integ to Master
Change-Id: I71e3acc26fa612127756ac04073a522b9cc6cd74 Issue-ID: SDC-977 Signed-off-by: Gitelman, Tal (tg851x) <tg851x@intl.att.com>
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java109
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java84
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java170
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java53
-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/GroupInstance.java79
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java11
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java113
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyDefinition.java66
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTargetDTO.java31
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java43
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java18
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/TargetCapabilityRelDef.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java129
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ComponentCache.java34
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/catalog/CatalogComponent.java107
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java50
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java146
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java63
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ExternalReferencesOperation.java261
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ForwardingPathOperation.java122
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/GroupsOperation.java40
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java72
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperation.java63
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java222
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java172
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java2380
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java229
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/IdMapper.java54
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java71
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/StorageException.java17
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/DerivedFromOperation.java36
-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/IGroupTypeOperation.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java16
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AdditionalInformationOperation.java10
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperation.java7
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java16
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CsarOperation.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DefaultDerivedFromOperation.java67
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java662
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OnboardingClient.java128
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java437
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java171
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java10
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverter.java43
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java67
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/SerializedHashMap.java11
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java306
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceDataTransfer.java14
54 files changed, 4454 insertions, 2613 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java
new file mode 100644
index 0000000000..1dcbfbf1e9
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java
@@ -0,0 +1,13 @@
+package org.openecomp.sdc.be.config;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ComponentScan({"org.openecomp.sdc.be.model.operations.impl",
+ "org.openecomp.sdc.be.model.cache",
+ "org.openecomp.sdc.be.model.jsontitan.operations"
+
+})
+public class CatalogModelSpringConfig {
+}
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 5760e0b11b..d3bdfede42 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
@@ -20,23 +20,25 @@
package org.openecomp.sdc.be.model;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-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 com.fasterxml.jackson.annotation.JsonIgnore;
import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.utils.MapUtil;
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.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import java.util.stream.Collectors;
+import static java.util.Collections.emptyList;
+import org.openecomp.sdc.be.dao.utils.MapUtil;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+
+import java.io.Serializable;
+import java.util.*;
+import java.util.stream.Collectors;
+
public abstract class Component implements Serializable {
/**
@@ -48,27 +50,17 @@ public abstract class Component implements Serializable {
private Map<String, ArtifactDefinition> artifacts;
private Map<String, ArtifactDefinition> deploymentArtifacts;
private Map<String, ArtifactDefinition> toscaArtifacts;
-
private List<CategoryDefinition> categories;
-
private List<ComponentInstance> componentInstances;
-
private List<RequirementCapabilityRelDef> componentInstancesRelations;
-
private Map<String, List<ComponentInstanceInput>> componentInstancesInputs;
-
private Map<String, List<ComponentInstanceProperty>> componentInstancesProperties;
-
private Map<String, List<ComponentInstanceProperty>> componentInstancesAttributes;
-
private Map<String, List<CapabilityDefinition>> capabilities;
-
private Map<String, List<RequirementDefinition>> requirements;
-
private List<InputDefinition> inputs;
-
private List<GroupDefinition> groups;
-
+ private Map<String, PolicyDefinition> policies;
private String derivedFromGenericType;
private String derivedFromGenericVersion;
private String toscaType;
@@ -344,16 +336,22 @@ public abstract class Component implements Serializable {
return componentInstances;
}
+ public Optional<ComponentInstance> fetchInstanceById(String instanceId) {
+ return Optional.ofNullable(MapUtil.toMap(componentInstances, ComponentInstance::getUniqueId).get(instanceId));
+ }
+
+ @SuppressWarnings("unchecked")
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;
+ return instanceDeploymentArtifacts != null ? instanceDeploymentArtifacts : Collections.emptyMap();
}
+ @SuppressWarnings("unchecked")
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;
+ return instanceInformationalArtifacts != null ? instanceInformationalArtifacts : Collections.emptyMap();
}
public List<ArtifactDefinition> safeGetComponentInstanceHeatArtifacts(String componentInstanceId) {
@@ -362,7 +360,7 @@ public abstract class Component implements Serializable {
.stream()
.filter(artifact -> artifact.getArtifactType() != null && artifact.getArtifactType().equals(ArtifactTypeEnum.HEAT_ENV.name()))
.collect(Collectors.toList());
- return instanceHeatEnvArtifacts == null ? Collections.EMPTY_LIST : instanceHeatEnvArtifacts;
+ return instanceHeatEnvArtifacts == null ? emptyList() : instanceHeatEnvArtifacts;
}
public void setComponentInstances(List<ComponentInstance> resourceInstances) {
@@ -443,16 +441,31 @@ public abstract class Component implements Serializable {
}
public Optional<ComponentInstance> getComponentInstanceById(String id) {
+ if (componentInstances == null) {
+ return Optional.empty();
+ }
return componentInstances.stream().filter(instance -> id.equals(instance.getUniqueId())).findFirst();
}
public List<GroupDefinition> getGroups() {
return groups;
}
+ public Optional<GroupDefinition> getGroupById(String id){
+ return groups.stream().filter(g -> g.getUniqueId().equals(id)).findAny();
+
+ }
public void setGroups(List<GroupDefinition> groups) {
this.groups = groups;
}
+
+ public Map<String, PolicyDefinition> getPolicies() {
+ return policies;
+ }
+
+ public void setPolicies(Map<String, PolicyDefinition> policies) {
+ this.policies = policies;
+ }
@Override
public int hashCode() {
@@ -476,6 +489,7 @@ public abstract class Component implements Serializable {
result = prime * result + ((componentInstancesInputs == null) ? 0 : componentInstancesInputs.hashCode());
result = prime * result + ((componentInstancesRelations == null) ? 0 : componentInstancesRelations.hashCode());
result = prime * result + ((groups == null) ? 0 : groups.hashCode());
+ result = prime * result + ((policies == null) ? 0 : policies.hashCode());
result = prime * result + ((derivedFromGenericType == null) ? 0 : derivedFromGenericType.hashCode());
result = prime * result + ((derivedFromGenericVersion == null) ? 0 : derivedFromGenericVersion.hashCode());
return result;
@@ -567,6 +581,11 @@ public abstract class Component implements Serializable {
return false;
} else if (!groups.equals(other.groups))
return false;
+ if (policies == null) {
+ if (other.policies != null)
+ return false;
+ } else if (!policies.equals(other.policies))
+ return false;
if (derivedFromGenericType == null) {
if (other.derivedFromGenericType != null)
return false;
@@ -668,7 +687,7 @@ public abstract class Component implements Serializable {
}
public List<ComponentInstanceInput> safeGetComponentInstanceInputsByName(String cmptInstanceName) {
- List<ComponentInstanceInput> emptyPropsList = Collections.emptyList();
+ List<ComponentInstanceInput> emptyPropsList = emptyList();
if (this.componentInstancesInputs == null) {
return emptyPropsList;
}
@@ -681,7 +700,7 @@ public abstract class Component implements Serializable {
}
private <T> List<T> safeGetComponentInstanceEntity(String cmptInstanceId, Map<String, List<T>> instanceEntities) {
- List<T> emptyPropsList = Collections.emptyList();
+ List<T> emptyPropsList = emptyList();
if (instanceEntities == null) {
return emptyPropsList;
}
@@ -728,6 +747,10 @@ public abstract class Component implements Serializable {
derivedFromGenericVersion = genericType.getVersion();
}
+ public boolean isTopologyTemplate() {
+ return ToscaElementTypeEnum.TopologyTemplate.getValue().equals(toscaType);
+ }
+
public String getToscaType() {
return toscaType;
}
@@ -735,6 +758,7 @@ public abstract class Component implements Serializable {
public void setToscaType(String toscaType) {
this.toscaType = toscaType;
}
+
public List<AdditionalInformationDefinition> getAdditionalInformation() {
return additionalInformation;
}
@@ -742,5 +766,34 @@ public abstract class Component implements Serializable {
public void setAdditionalInformation(List<AdditionalInformationDefinition> additionalInformation) {
this.additionalInformation = additionalInformation;
}
-
+
+ public PolicyDefinition getPolicyById(String id) {
+ return policies != null ? policies.get(id) : null;
+ }
+
+ public List<PolicyDefinition> resolvePoliciesList() {
+ if (policies == null) {
+ return emptyList();
+ }
+ return new ArrayList<>(policies.values());
+ }
+
+ public List<PolicyDefinition> resolvePoliciesByComponentInstanceTarget(String instanceId) {
+ if (policies == null) {
+ return emptyList();
+ }
+ return policies.values().stream()
+ .filter(policy -> policy.containsCmptInstanceAsTarget(instanceId))
+ .collect(Collectors.toList());
+ }
+
+ public List<GroupDefinition> resolveGroupsByMember(String instanceId) {
+ if (groups == null) {
+ return emptyList();
+ }
+ return groups.stream()
+ .filter(group -> group.containsInstanceAsMember(instanceId))
+ .collect(Collectors.toList());
+ }
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java
index e436548f60..19653e3847 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstInputsMap.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,33 +20,63 @@
package org.openecomp.sdc.be.model;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.tuple.Pair;
+
import java.io.Serializable;
import java.util.List;
import java.util.Map;
-public class ComponentInstInputsMap implements Serializable{
-
- /**
- *
- */
- private static final long serialVersionUID = 1136631343963488131L;
-
- Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap;
- Map<String, List<ComponentInstancePropInput>> componentInstanceProperties;
-
- public Map<String, List<ComponentInstancePropInput>> getComponentInstanceInputsMap() {
- return componentInstanceInputsMap;
- }
-
- public void setComponentInstanceInputsMap(Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap) {
- this.componentInstanceInputsMap = componentInstanceInputsMap;
- }
-
- public Map<String, List<ComponentInstancePropInput>> getComponentInstanceProperties() {
- return componentInstanceProperties;
- }
-
- public void setComponentInstancePropInput(Map<String, List<ComponentInstancePropInput>> componentInstanceProperties) {
- this.componentInstanceProperties = componentInstanceProperties;
- }
+public class ComponentInstInputsMap implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1136631343963488131L;
+
+ private Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap;
+ private Map<String, List<ComponentInstancePropInput>> componentInstanceProperties;
+ private Map<String, List<ComponentInstancePropInput>> policyProperties;
+
+ public Pair<String, List<ComponentInstancePropInput>> resolvePropertiesToDeclare() {
+ if (!MapUtils.isEmpty(componentInstanceInputsMap)) {
+ return singleMapEntry(componentInstanceInputsMap);
+ }
+ if (!MapUtils.isEmpty(componentInstanceProperties)) {
+ return singleMapEntry(componentInstanceProperties);
+ }
+ if (!MapUtils.isEmpty(policyProperties)) {
+ return singleMapEntry(policyProperties);
+ }
+ throw new IllegalStateException("there are no properties selected for deceleration");
+ }
+
+ private Pair<String, List<ComponentInstancePropInput>> singleMapEntry(Map<String, List<ComponentInstancePropInput>> propertiesMap) {
+ Map.Entry<String, List<ComponentInstancePropInput>> singleEntry = propertiesMap.entrySet().iterator().next();
+ return Pair.of(singleEntry.getKey(), singleEntry.getValue());
+ }
+
+ public Map<String, List<ComponentInstancePropInput>> getComponentInstanceInputsMap() {
+ return componentInstanceInputsMap;
+ }
+
+ public void setComponentInstanceInputsMap(Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap) {
+ this.componentInstanceInputsMap = componentInstanceInputsMap;
+ }
+
+ public Map<String, List<ComponentInstancePropInput>> getComponentInstanceProperties() {
+ return componentInstanceProperties;
+ }
+
+ public void setComponentInstancePropInput(Map<String, List<ComponentInstancePropInput>> componentInstanceProperties) {
+ this.componentInstanceProperties = componentInstanceProperties;
+ }
+
+ public Map<String, List<ComponentInstancePropInput>> getPolicyProperties() {
+ return policyProperties;
+ }
+
+ public void setPolicyProperties(Map<String, List<ComponentInstancePropInput>> policyProperties) {
+ this.policyProperties = policyProperties;
+ }
}
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 8ed256c555..a45e3d2bd7 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,88 +20,96 @@
package org.openecomp.sdc.be.model;
+import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
-
-public class ComponentInstance extends ComponentInstanceDataDefinition implements Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 6721465693884621223L;
-
- private Map<String, List<CapabilityDefinition>> capabilities;
- private Map<String, List<RequirementDefinition>> requirements;
- private Map<String, ArtifactDefinition> deploymentArtifacts;
- private Map<String, ArtifactDefinition> artifacts;
- private List<GroupInstance> groupInstances;
-
- public ComponentInstance() {
- super();
- }
-
- public ComponentInstance(ComponentInstanceDataDefinition r) {
- super(r);
- }
-
- public Map<String, List<CapabilityDefinition>> getCapabilities() {
- return capabilities;
- }
-
- public void setCapabilities(Map<String, List<CapabilityDefinition>> capabilities) {
- this.capabilities = capabilities;
- }
-
- public Map<String, List<RequirementDefinition>> getRequirements() {
- return requirements;
- }
-
- public void setRequirements(Map<String, List<RequirementDefinition>> requirements) {
- this.requirements = requirements;
- }
-
- public Map<String, ArtifactDefinition> getDeploymentArtifacts() {
- 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;
- }
-
- public Map<String, ArtifactDefinition> getArtifacts() {
- return artifacts;
- }
-
- public Map<String, ArtifactDefinition> safeGetArtifacts() {
- return artifacts == null ? Collections.EMPTY_MAP : artifacts;
- }
-
- public void setArtifacts(Map<String, ArtifactDefinition> artifacts) {
- this.artifacts = artifacts;
- }
-
- public List<GroupInstance> getGroupInstances() {
- return groupInstances;
- }
-
- public void setGroupInstances(List<GroupInstance> groupInstances) {
- this.groupInstances = groupInstances;
- }
-
- public String getActualComponentUid() {
- return getIsProxy() ? getSourceModelUid() : getComponentUid();
- }
-
+public class ComponentInstance extends ComponentInstanceDataDefinition implements Serializable, PropertiesOwner {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6721465693884621223L;
+
+ private Map<String, List<CapabilityDefinition>> capabilities;
+ private Map<String, List<RequirementDefinition>> requirements;
+ private Map<String, ArtifactDefinition> deploymentArtifacts;
+ private Map<String, ArtifactDefinition> artifacts;
+ private List<GroupInstance> groupInstances;
+
+ public ComponentInstance() {
+ super();
+ }
+
+ public ComponentInstance(ComponentInstanceDataDefinition r) {
+ super(r);
+ }
+
+ public Map<String, List<CapabilityDefinition>> getCapabilities() {
+ return capabilities;
+ }
+
+ public void setCapabilities(Map<String, List<CapabilityDefinition>> capabilities) {
+ this.capabilities = capabilities;
+ }
+
+ public Map<String, List<RequirementDefinition>> getRequirements() {
+ return requirements;
+ }
+
+ public void setRequirements(Map<String, List<RequirementDefinition>> requirements) {
+ this.requirements = requirements;
+ }
+
+ public Map<String, ArtifactDefinition> getDeploymentArtifacts() {
+ return deploymentArtifacts;
+ }
+
+ public Map<String, ArtifactDefinition> safeGetDeploymentArtifacts() {
+ return deploymentArtifacts == null ? Collections.emptyMap() : deploymentArtifacts;
+ }
+
+ public Map<String, ArtifactDefinition> safeGetInformationalArtifacts() {
+ return artifacts == null ? Collections.emptyMap() : deploymentArtifacts;
+ }
+
+ public void setDeploymentArtifacts(Map<String, ArtifactDefinition> deploymentArtifacts) {
+ this.deploymentArtifacts = deploymentArtifacts;
+ }
+
+ public Map<String, ArtifactDefinition> getArtifacts() {
+ return artifacts;
+ }
+
+ public Map<String, ArtifactDefinition> safeGetArtifacts() {
+ return artifacts == null ? Collections.emptyMap() : artifacts;
+ }
+
+ public void setArtifacts(Map<String, ArtifactDefinition> artifacts) {
+ this.artifacts = artifacts;
+ }
+
+ public List<GroupInstance> getGroupInstances() {
+ return groupInstances;
+ }
+
+ public void setGroupInstances(List<GroupInstance> groupInstances) {
+ this.groupInstances = groupInstances;
+ }
+
+ public String getActualComponentUid() {
+ return getIsProxy() ? getSourceModelUid() : getComponentUid();
+ }
+
+ public boolean isArtifactExists(ArtifactGroupTypeEnum groupType, String artifactLabel) {
+ if (ArtifactGroupTypeEnum.DEPLOYMENT == groupType) {
+ return safeGetDeploymentArtifacts().get(artifactLabel) != null;
+ }
+ return safeGetInformationalArtifacts().get(artifactLabel) != null;
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
index 4078a47f86..9bd66006e7 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
@@ -20,12 +20,12 @@
package org.openecomp.sdc.be.model;
-import java.util.List;
-
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import java.util.List;
+
public class ComponentParametersView {
boolean ignoreUsers = false;
@@ -46,10 +46,12 @@ public class ComponentParametersView {
boolean ignoreInputs = false;
boolean ignoreComponentInstancesInputs = false;
boolean ignoreCapabiltyProperties = true;
-
+ boolean ignoreServicePath = true;
+ boolean ignorePolicies = false;
+
public ComponentParametersView() {
}
-
+
public ComponentParametersView(boolean setAllToIgnore) {
this();
if(setAllToIgnore){
@@ -59,9 +61,9 @@ public class ComponentParametersView {
public ComponentParametersView(List<String> filters) {
this(true);
-
+
for(String fieldName: filters) {
- switch (ComponentFieldsEnum.findByValue(fieldName)) {
+ switch (ComponentFieldsEnum.findByValue(fieldName)) {
case PROPERTIES:
this.setIgnoreProperties(false);
break;
@@ -89,11 +91,11 @@ public class ComponentParametersView {
this.setIgnoreRequirements(false);
break;
case COMPONENT_INSTANCES_PROPERTIES:
- this.setIgnoreComponentInstances(false); //we need this in order to get the calculate capabilities requirements
+ this.setIgnoreComponentInstances(false); //we need this in order to get the calculate capabilities requirements
this.setIgnoreComponentInstancesProperties(false);
break;
case CAPABILITIES:
- this.setIgnoreComponentInstances(false);//we need this in order to get the calculate capabilities requirements
+ this.setIgnoreComponentInstances(false);//we need this in order to get the calculate capabilities requirements
this.setIgnoreCapabilities(false);
break;
case REQUIREMENTS:
@@ -132,10 +134,16 @@ public class ComponentParametersView {
case INSTANCE_CAPABILTY_PROPERTIES:
this.setIgnoreCapabiltyProperties(false);
break;
+ case FORWARDING_PATHS:
+ this.setIgnoreForwardingPath(false);
+ break;
+ case POLICIES:
+ this.setIgnorePolicies(false);
+ break;
default:
break;
}
-
+
}
}
@@ -249,6 +257,16 @@ public class ComponentParametersView {
if (ignoreComponentInstancesInputs) {
component.setComponentInstancesInputs(null);
}
+
+ if (ignoreServicePath){
+ switch (componentType) {
+ case SERVICE:
+ ((Service) component).setForwardingPaths(null);
+ break;
+ default:
+ break;
+ }
+ }
return component;
}
@@ -272,6 +290,7 @@ public class ComponentParametersView {
ignoreComponentInstancesAttributesFrom = true;
ignoreComponentInstancesInputs = true;
ignoreCapabiltyProperties = true;
+ ignoreServicePath = true;
}
public boolean isIgnoreGroups() {
@@ -418,6 +437,22 @@ public class ComponentParametersView {
this.ignoreCapabiltyProperties = ignoreCapabiltyProperties;
}
+ public boolean isIgnoreForwardingPath() {
+ return ignoreServicePath;
+ }
+
+ public void setIgnoreForwardingPath(boolean ignoreServicePath) {
+ this.ignoreServicePath = ignoreServicePath;
+ }
+
+ public boolean isIgnorePolicies() {
+ return ignorePolicies;
+ }
+
+ public void setIgnorePolicies(boolean ignorePolicies) {
+ this.ignorePolicies = ignorePolicies;
+ }
+
public JsonParseFlagEnum detectParseFlag() {
JsonParseFlagEnum parseFlag;
if(isIgnoreComponentInstances()){
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 a9cc32d9b0..c5f4cf923c 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
@@ -26,8 +26,6 @@ import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
public class DataTypeDefinition extends DataTypeDataDefinition {
- // @JsonIgnore
- // @org.codehaus.jackson.annotate.JsonIgnore
private DataTypeDefinition derivedFrom;
private List<PropertyConstraint> constraints;
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 e7d7c69efc..4ffa843463 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
@@ -21,11 +21,18 @@
package org.openecomp.sdc.be.model;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
public class GroupInstance extends GroupInstanceDataDefinition implements Serializable {
@@ -38,7 +45,10 @@ public class GroupInstance extends GroupInstanceDataDefinition implements Serial
public GroupInstance(GroupInstanceDataDefinition r) {
super(r);
}
-
+ /**
+ * Converts contained list of PropertyDataDefinitions to list of GroupInstanceProperties
+ * @return
+ */
public List<GroupInstanceProperty> convertToGroupInstancesProperties() {
List<GroupInstanceProperty> groupInstancesProperties = null;
List<PropertyDataDefinition> propertiesList = super.getProperties();
@@ -47,12 +57,77 @@ public class GroupInstance extends GroupInstanceDataDefinition implements Serial
}
return groupInstancesProperties;
}
-
+ /**
+ * Converts received list of GroupInstanceProperties to the list of PropertyDataDefinitions and sets It into the GroupInstanceDataDefinition as properties
+ * @param groupInstancesProperties
+ */
public void convertFromGroupInstancesProperties(List<GroupInstanceProperty> groupInstancesProperties) {
if(groupInstancesProperties != null && !groupInstancesProperties .isEmpty()){
List<PropertyDataDefinition> propList = groupInstancesProperties.stream().map(p -> new PropertyDataDefinition(p)).collect(Collectors.toList());
super.setProperties(propList);
}
}
+
+ private void removeArtifactsDuplicates() {
+ List<String> artifacts = getArtifacts();
+ Set<String> artifactsSet = new HashSet<>();
+ artifactsSet.addAll(artifacts);
+ artifacts.clear();
+ artifacts.addAll(artifactsSet);
+
+ List<String> giArtifacts = getGroupInstanceArtifacts();
+ Set<String> giArtifactsSet = new HashSet<>();
+ giArtifactsSet.addAll(giArtifacts);
+ giArtifacts.clear();
+ giArtifacts.addAll(giArtifactsSet);
+ }
+
+ private void clearArtifactsUuid() {
+ List<String> artifactsUuid = getArtifactsUuid();
+ if(CollectionUtils.isNotEmpty(artifactsUuid)){
+ artifactsUuid.clear();
+ } else if (artifactsUuid == null){
+ setArtifactsUuid(new ArrayList<>());
+ }
+
+ List<String> giartifactsUuid = this.getGroupInstanceArtifactsUuid();
+ if(CollectionUtils.isNotEmpty(giartifactsUuid)){
+ giartifactsUuid.clear();
+ } else if (giartifactsUuid == null){
+ setGroupInstanceArtifactsUuid(new ArrayList<>());
+ }
+ }
+
+ /**
+ * Aligns the list of artifacts UUIDs of group instance according to received deployment artifacts
+ * @param deploymentArtifacts
+ */
+ public void alignArtifactsUuid(Map<String, ArtifactDefinition> deploymentArtifacts) {
+ List<String> artifactIds = getArtifacts();
+ if(CollectionUtils.isNotEmpty(artifactIds)){
+ removeArtifactsDuplicates();
+ clearArtifactsUuid();
+ List<String> artifactUuids = getArtifactsUuid();
+ List<String> giArtifactUuids = getGroupInstanceArtifactsUuid();
+ for(String artifactId : artifactIds){
+ String label = artifactId.substring(artifactId.lastIndexOf('.') + 1);
+ ArtifactDefinition artifact = deploymentArtifacts.get(label);
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
+ if (artifactType != ArtifactTypeEnum.HEAT_ENV){
+ addArtifactsIdToCollection(artifactUuids, artifact);
+ }else{
+ addArtifactsIdToCollection(giArtifactUuids, artifact);
+ }
+ }
+
+ }
+ }
+
+ private void addArtifactsIdToCollection(List<String> artifactUuids, ArtifactDefinition artifact) {
+ if(!artifactUuids.contains(artifact.getArtifactUUID()) && StringUtils.isNotEmpty(artifact.getArtifactUUID())){
+ artifactUuids.add(artifact.getArtifactUUID());
+
+ }
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java
index cd7fd6401b..5263fcf96e 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java
@@ -36,6 +36,7 @@ public class GroupTypeDefinition extends GroupTypeDataDefinition implements Seri
private static final long serialVersionUID = -1597773317924162703L;
private List<PropertyDefinition> properties;
+ private List<CapabilityTypeDefinition> capabilityTypes;
public List<PropertyDefinition> getProperties() {
return properties;
@@ -53,9 +54,17 @@ public class GroupTypeDefinition extends GroupTypeDataDefinition implements Seri
super(p);
}
+ public List<CapabilityTypeDefinition> getCapabilityTypes() {
+ return capabilityTypes;
+ }
+
+ public void setCapabilityTypes(List<CapabilityTypeDefinition> capabilityTypes) {
+ this.capabilityTypes = capabilityTypes;
+ }
+
@Override
public String toString() {
- return super.toString() + " [ properties=" + properties + " ]";
+ return super.toString() + " [properties=" + properties + ", capabilityTypes=" + capabilityTypes + "]";
}
}
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 5eb5e8c05c..78b5a82468 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,67 +20,74 @@
package org.openecomp.sdc.be.model;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+
import java.io.Serializable;
import java.util.Map;
import java.util.stream.Collectors;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
-
/**
* Definition of the operations that can be performed on (instances of) a Node
* Type.
- *
+ *
* @author esofer
*/
public class InterfaceDefinition extends InterfaceDataDefinition implements IOperationParameter, Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 8220887972866354746L;
-
-
-
- private boolean definition;
-
- public InterfaceDefinition() {
- super();
- }
-
- public InterfaceDefinition(String type, String description, Map<String, Operation> operations) {
- super(type, description);
- setOperationsMap(operations);
- }
-
- public InterfaceDefinition(InterfaceDataDefinition p) {
- super(p);
- }
-
- @Override
- public boolean isDefinition() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void setDefinition(boolean definition) {
- this.definition = definition;
- }
- @JsonIgnore
- public Map<String, Operation> getOperationsMap() {
- Map<String, Operation> convertedOperation = getOperations().entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> new Operation(e.getValue())));
- return convertedOperation;
- }
- @JsonIgnore
- public void setOperationsMap(Map<String, Operation> operations) {
- Map<String, OperationDataDefinition> convertedOperation = operations.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> new OperationDataDefinition(e.getValue())));
- setOperations(convertedOperation);
- }
-
- @Override
- public String toString() {
- return "InterfaceDefinition [definition=" + definition + "]";
- }
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8220887972866354746L;
+
+
+ private boolean definition;
+
+ public InterfaceDefinition() {
+ super();
+ }
+
+ public InterfaceDefinition(String type, String description, Map<String, Operation> operations) {
+ super(type, description);
+ setOperationsMap(operations);
+ }
+
+ public InterfaceDefinition(InterfaceDataDefinition p) {
+ super(p);
+ }
+
+ @Override
+ public boolean isDefinition() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setDefinition(boolean definition) {
+ this.definition = definition;
+ }
+
+ @JsonIgnore
+ public Map<String, Operation> getOperationsMap() {
+ Map<String, Operation> convertedOperation = getOperations().entrySet()
+ .stream()
+ .collect(Collectors.toMap(e -> e.getKey(), e -> new Operation(e
+ .getValue())));
+ return convertedOperation;
+ }
+
+ @JsonIgnore
+ public void setOperationsMap(Map<String, Operation> operations) {
+ Map<String, OperationDataDefinition> convertedOperation = operations.entrySet()
+ .stream()
+ .collect(Collectors.toMap(e -> e.getKey(), e -> new OperationDataDefinition(e
+ .getValue())));
+ setOperations(convertedOperation);
+ }
+
+ @Override
+ public String toString() {
+ return "InterfaceDefinition [definition=" + definition + "]";
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyDefinition.java
new file mode 100644
index 0000000000..dc742cb163
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyDefinition.java
@@ -0,0 +1,66 @@
+package org.openecomp.sdc.be.model;
+
+import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+/**
+ * public class representing the component policy
+ */
+public class PolicyDefinition extends PolicyDataDefinition implements Serializable, PropertiesOwner {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8433981810801300209L;
+
+ /**
+ * public constructor by default
+ */
+ public PolicyDefinition() {
+ super();
+ }
+
+ /**
+ * public constructor from superclass
+ * @param policy
+ */
+ public PolicyDefinition(Map<String, Object> policy) {
+ super(policy);
+ }
+
+ /**
+ * public copy constructor
+ * @param other
+ */
+ public PolicyDefinition(PolicyDataDefinition other) {
+ super(other);
+ }
+
+ /**
+ * public converter constructor
+ * builds PolicyDefinition object based on received PolicyTypeDefinition object
+ * @param policyType
+ */
+ public PolicyDefinition(PolicyTypeDefinition policyType) {
+ this.setPolicyTypeName(policyType.getType());
+ this.setPolicyTypeUid(policyType.getUniqueId());
+ this.setDerivedFrom(policyType.getDerivedFrom());
+ this.setDescription(policyType.getDescription());
+ this.setVersion(policyType.getVersion());
+ if (policyType.getProperties() != null) {
+ this.setProperties(policyType.getProperties().stream().map(PropertyDataDefinition::new).collect(Collectors.toList()));
+ }
+ this.setTargets(new HashMap<>());
+
+ }
+
+ @Override
+ public String getNormalizedName() {
+ return getName();
+ }
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTargetDTO.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTargetDTO.java
new file mode 100644
index 0000000000..33a32d2624
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTargetDTO.java
@@ -0,0 +1,31 @@
+package org.openecomp.sdc.be.model;
+
+import java.util.List;
+
+public class PolicyTargetDTO {
+
+
+ private String type;
+ private List<String> uniqueIds;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public List<String> getUniqueIds() {
+ return uniqueIds;
+ }
+
+ public void setUniqueIds(List<String> ids) {
+ this.uniqueIds = ids;
+ }
+
+
+
+
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java
index 9b3e72ccc6..0cfdf196e1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,36 +20,35 @@
package org.openecomp.sdc.be.model;
-import java.util.List;
-
import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition;
+import java.util.List;
+
/**
* Specifies the policy type that the Node Type exposes.
*/
public class PolicyTypeDefinition extends PolicyTypeDataDefinition {
- private List<PropertyDefinition> properties;
-
- public List<PropertyDefinition> getProperties() {
- return properties;
- }
+ private List<PropertyDefinition> properties;
- public void setProperties(List<PropertyDefinition> properties) {
- this.properties = properties;
- }
+ public List<PropertyDefinition> getProperties() {
+ return properties;
+ }
- public PolicyTypeDefinition() {
- super();
- }
+ public void setProperties(List<PropertyDefinition> properties) {
+ this.properties = properties;
+ }
- public PolicyTypeDefinition(PolicyTypeDataDefinition p) {
- super(p);
- }
+ public PolicyTypeDefinition() {
+ super();
+ }
- @Override
- public String toString() {
- return super.toString() + " [ properties=" + properties + " ]";
- }
+ public PolicyTypeDefinition(PolicyTypeDataDefinition p) {
+ super(p);
+ }
+ @Override
+ public String toString() {
+ return super.toString() + " [ properties=" + properties + " ]";
+ }
}
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 786c11f636..5310d5a00c 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
@@ -28,8 +28,10 @@ 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.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.datatypes.elements.WorkflowOperationDataDefinition;
+import static java.util.stream.Collectors.groupingBy;
public class Resource extends Component implements Serializable {
private static final long serialVersionUID = -6811540567661368482L;
@@ -306,7 +308,7 @@ public class Resource extends Component implements Serializable {
@Override
public boolean shouldGenerateInputs(){
//TODO add complex VFC condition when supported
- return ResourceTypeEnum.VF == this.getResourceType() || ResourceTypeEnum.CVFC == this.getResourceType() || ResourceTypeEnum.PNF == this.getResourceType();
+ return !(this.getResourceType().isAtomicType());
}
@Override
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 563030e147..c3852e060b 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
@@ -20,9 +20,11 @@
package org.openecomp.sdc.be.model;
+import java.util.HashMap;
import java.util.Map;
import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
@@ -43,6 +45,7 @@ public class Service extends Component {
}
private Map<String, ArtifactDefinition> serviceApiArtifacts;
+ private Map<String, ForwardingPathDataDefinition> forwardingPaths;
public Map<String, ArtifactDefinition> getServiceApiArtifacts() {
@@ -57,6 +60,21 @@ public class Service extends Component {
return getServiceMetadataDefinition().getProjectCode();
}
+ public Map<String, ForwardingPathDataDefinition> getForwardingPaths() {
+ return forwardingPaths;
+ }
+
+ public void setForwardingPaths(Map<String, ForwardingPathDataDefinition> forwardingPaths) {
+ this.forwardingPaths = forwardingPaths;
+ }
+
+ public ForwardingPathDataDefinition addForwardingPath(ForwardingPathDataDefinition forwardingPathDataDefinition){
+ if(forwardingPaths == null){
+ forwardingPaths = new HashMap<>();
+ }
+ return forwardingPaths.put(forwardingPathDataDefinition.getUniqueId(),forwardingPathDataDefinition);
+ }
+
public void setProjectCode(String projectName) {
getServiceMetadataDefinition().setProjectCode(projectName);
}
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 6a1fcac7e8..8da4c113a2 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
@@ -65,8 +65,7 @@ public class TargetCapabilityRelDef implements Serializable {
return relationships;
}
-
- public CapabilityRequirementRelationship getSingleRelationship() {//currently only single relationship is supported
+ public CapabilityRequirementRelationship resolveSingleRelationship() {//currently only single relationship is supported
return relationships == null || relationships.isEmpty() ? null : relationships.get(0);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java
index 385b15c728..36ac871cab 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadResourceInfo.java
@@ -29,13 +29,23 @@ import org.openecomp.sdc.common.api.UploadArtifactInfo;
public class UploadResourceInfo {
+ private String payloadData;
+ private String payloadName;
+ private String description;
+ private List<String> tags;
+ private List<CategoryDefinition> categories;
+
+ private List<UploadArtifactInfo> artifactList;
+ private String contactId, name, resourceIconPath, icon, vendorName, vendorRelease, resourceVendorModelNumber;
+
+ private String resourceType = "VFC";
+
public UploadResourceInfo(String payload, String payloadName, String description, String category,
- List<String> tags, List<UploadArtifactInfo> artifactsList) {
+ List<String> tags, List<UploadArtifactInfo> artifactsList) {
super();
this.payloadData = payload;
this.payloadName = payloadName;
this.description = description;
- // this.category = category;
this.tags = tags;
this.artifactList = artifactsList;
if (category != null) {
@@ -55,17 +65,6 @@ public class UploadResourceInfo {
public UploadResourceInfo() {
}
- private String payloadData;
- private String payloadName;
- private String description;
- // private String category;
- private List<String> tags;
- private List<CategoryDefinition> categories;
-
- private List<UploadArtifactInfo> artifactList;
- private String contactId, name, resourceIconPath, icon, vendorName, vendorRelease;
-
- private String resourceType = "VFC";
public String getPayloadData() {
return payloadData;
@@ -91,12 +90,6 @@ public class UploadResourceInfo {
this.description = description;
}
- // public String getCategory() {
- // return category;
- // }
- // public void setCategory(String category) {
- // this.category = category;
- // }
public List<String> getTags() {
return tags;
}
@@ -119,8 +112,6 @@ public class UploadResourceInfo {
int result = 1;
result = prime * result + ((artifactList == null) ? 0 : artifactList.hashCode());
result = prime * result + ((contactId == null) ? 0 : contactId.hashCode());
- // result = prime * result + ((category == null) ? 0 :
- // category.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((icon == null) ? 0 : icon.hashCode());
result = prime * result + ((payloadData == null) ? 0 : payloadData.hashCode());
@@ -130,78 +121,106 @@ public class UploadResourceInfo {
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
result = prime * result + ((vendorName == null) ? 0 : vendorName.hashCode());
result = prime * result + ((vendorRelease == null) ? 0 : vendorRelease.hashCode());
+ result = prime * result + ((resourceVendorModelNumber == null) ? 0 : resourceVendorModelNumber.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
UploadResourceInfo other = (UploadResourceInfo) obj;
if (artifactList == null) {
- if (other.artifactList != null)
+ if (other.artifactList != null) {
return false;
- } else if (!artifactList.equals(other.artifactList))
+ }
+ } else if (!artifactList.equals(other.artifactList)) {
return false;
+ }
if (contactId == null) {
- if (other.contactId != null)
+ if (other.contactId != null) {
return false;
- } else if (!contactId.equals(other.contactId))
+ }
+ } else if (!contactId.equals(other.contactId)) {
return false;
- // if (category == null) {
- // if (other.category != null)
- // return false;
- // } else if (!category.equals(other.category))
- // return false;
+ }
if (description == null) {
- if (other.description != null)
+ if (other.description != null) {
return false;
- } else if (!description.equals(other.description))
+ }
+ } else if (!description.equals(other.description)) {
return false;
+ }
if (icon == null) {
- if (other.icon != null)
+ if (other.icon != null) {
return false;
- } else if (!icon.equals(other.icon))
+ }
+ } else if (!icon.equals(other.icon)) {
return false;
+ }
if (payloadData == null) {
- if (other.payloadData != null)
+ if (other.payloadData != null) {
return false;
- } else if (!payloadData.equals(other.payloadData))
+ }
+ } else if (!payloadData.equals(other.payloadData)) {
return false;
+ }
if (payloadName == null) {
- if (other.payloadName != null)
+ if (other.payloadName != null) {
return false;
- } else if (!payloadName.equals(other.payloadName))
+ }
+ } else if (!payloadName.equals(other.payloadName)) {
return false;
+ }
if (resourceIconPath == null) {
- if (other.resourceIconPath != null)
+ if (other.resourceIconPath != null) {
return false;
- } else if (!resourceIconPath.equals(other.resourceIconPath))
+ }
+ } else if (!resourceIconPath.equals(other.resourceIconPath)) {
return false;
+ }
if (name == null) {
- if (other.name != null)
+ if (other.name != null) {
return false;
- } else if (!name.equals(other.name))
+ }
+ } else if (!name.equals(other.name)) {
return false;
+ }
if (tags == null) {
- if (other.tags != null)
+ if (other.tags != null) {
return false;
- } else if (!tags.equals(other.tags))
+ }
+ } else if (!tags.equals(other.tags)) {
return false;
+ }
if (vendorName == null) {
- if (other.vendorName != null)
+ if (other.vendorName != null) {
return false;
- } else if (!vendorName.equals(other.vendorName))
+ }
+ } else if (!vendorName.equals(other.vendorName)) {
return false;
+ }
+ if (resourceVendorModelNumber == null) {
+ if (other.resourceVendorModelNumber != null) {
+ return false;
+ }
+ } else if (!resourceVendorModelNumber.equals(other.resourceVendorModelNumber)) {
+ return false;
+ }
if (vendorRelease == null) {
- if (other.vendorRelease != null)
+ if (other.vendorRelease != null) {
return false;
- } else if (!vendorRelease.equals(other.vendorRelease))
+ }
+ } else if (!vendorRelease.equals(other.vendorRelease)) {
return false;
+ }
return true;
}
@@ -246,6 +265,14 @@ public class UploadResourceInfo {
this.vendorRelease = vendorRelease;
}
+ public String getResourceVendorModelNumber() {
+ return resourceVendorModelNumber;
+ }
+
+ public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
+ this.resourceVendorModelNumber = resourceVendorModelNumber;
+ }
+
public void setIcon(String icon) {
this.icon = icon;
}
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 22b46a0458..f969bbd18f 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
@@ -20,22 +20,7 @@
package org.openecomp.sdc.be.model.cache;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
-import javax.annotation.PostConstruct;
-
+import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -65,14 +50,27 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import fj.data.Either;
+import javax.annotation.PostConstruct;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Function;
+import java.util.stream.Collectors;
@org.springframework.stereotype.Component("component-cache")
public class ComponentCache {
private static Logger logger = LoggerFactory.getLogger(ComponentCache.class.getName());
- @javax.annotation.Resource
+ @Autowired
ComponentCassandraDao componentCassandraDao;
@Autowired
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/catalog/CatalogComponent.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/catalog/CatalogComponent.java
new file mode 100644
index 0000000000..d051e0ae79
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/catalog/CatalogComponent.java
@@ -0,0 +1,107 @@
+package org.openecomp.sdc.be.model.catalog;
+
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+
+public class CatalogComponent {
+
+ private String version;
+ private ComponentTypeEnum componentType;
+ private String icon;
+ private String uniqueId;
+ private String lifecycleState;
+ private long lastUpdateDate;
+ private String name;
+ private String resourceType;
+ private String categoryNormalizedName;
+ private String subCategoryNormalizedName;
+ private String distributionStatus;
+
+ public String getCategoryNormalizedName() {
+ return categoryNormalizedName;
+ }
+
+ public void setCategoryNormalizedName(String categoryNormalizedName) {
+ this.categoryNormalizedName = categoryNormalizedName;
+ }
+
+ public String getSubCategoryNormalizedName() {
+ return subCategoryNormalizedName;
+ }
+
+ public void setSubCategoryNormalizedName(String subCategoryNormalizedName) {
+ this.subCategoryNormalizedName = subCategoryNormalizedName;
+ }
+
+ public String getResourceType() {
+ return resourceType;
+ }
+
+ public void setResourceType(String resourceType) {
+ this.resourceType = resourceType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public long getLastUpdateDate() {
+ return lastUpdateDate;
+ }
+
+ public void setLastUpdateDate(long lastUpdateDate) {
+ this.lastUpdateDate = lastUpdateDate;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public void setComponentType(ComponentTypeEnum componentType) {
+ this.componentType = componentType;
+ }
+
+ public void setIcon(String icon) {
+ this.icon = icon;
+ }
+
+ public void setUniqueId(String uniqueId) {
+ this.uniqueId = uniqueId;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public ComponentTypeEnum getComponentType() {
+ return componentType;
+ }
+
+ public String getIcon() {
+ return icon;
+ }
+
+ public String getUniqueId() {
+ return uniqueId;
+ }
+
+ public String getLifecycleState() {
+ return lifecycleState;
+ }
+
+ public void setLifecycleState(String lifecycleState) {
+ this.lifecycleState = lifecycleState;
+ }
+
+ public String getDistributionStatus() {
+ return distributionStatus;
+ }
+
+ public void setDistributionStatus(String distributionStatus) {
+ this.distributionStatus = distributionStatus;
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java
index 663b5bf6df..6b5f1157fc 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java
@@ -20,24 +20,14 @@
package org.openecomp.sdc.be.model.jsontitan.datamodel;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.commons.collections.MapUtils;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
-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.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.*;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
+import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
+
+import java.util.HashMap;
+import java.util.Map;
public class TopologyTemplate extends ToscaElement{
@@ -50,8 +40,10 @@ public class TopologyTemplate extends ToscaElement{
private Map<String, MapPropertiesDataDefinition> instAttributes;
private Map<String, MapPropertiesDataDefinition> instProperties;
private Map<String, GroupDataDefinition> groups;
+ private Map<String, PolicyDataDefinition> policies;
private Map<String, MapGroupsDataDefinition> instGroups;
private Map<String, ArtifactDataDefinition> serviceApiArtifacts;
+ private Map<String, ForwardingPathDataDefinition> forwardingPaths;
private Map<String, CompositionDataDefinition> compositions;
private Map<String, MapListCapabiltyDataDefinition> calculatedCapabilities;
@@ -64,7 +56,18 @@ public class TopologyTemplate extends ToscaElement{
private Map<String, MapArtifactDataDefinition> instDeploymentArtifacts;
private Map<String, MapArtifactDataDefinition> instanceArtifacts;
-
+ //Component Instances External References (instanceId -> ExternalRefsMap)
+ //-----------------------------------------------------------------------
+ private Map<String, MapComponentInstanceExternalRefs> mapComponentInstancesExternalRefs;
+ public Map<String, MapComponentInstanceExternalRefs> getMapComponentInstancesExternalRefs() {
+ return this.mapComponentInstancesExternalRefs;
+ }
+ public void setComponentInstancesExternalRefs(Map<String, MapComponentInstanceExternalRefs> mapComponentInstancesExternalRefs) {
+ this.mapComponentInstancesExternalRefs = mapComponentInstancesExternalRefs;
+ }
+ //-----------------------------------------------------------------------
+
+
public Map<String, PropertyDataDefinition> getInputs() {
return inputs;
}
@@ -101,6 +104,12 @@ public class TopologyTemplate extends ToscaElement{
public void setGroups(Map<String, GroupDataDefinition> groups) {
this.groups = groups;
}
+ public Map<String, PolicyDataDefinition> getPolicies() {
+ return policies;
+ }
+ public void setPolicies(Map<String, PolicyDataDefinition> policies) {
+ this.policies = policies;
+ }
public Map<String, MapGroupsDataDefinition> getInstGroups() {
return instGroups;
}
@@ -164,6 +173,15 @@ public class TopologyTemplate extends ToscaElement{
public void setInstanceArtifacts(Map<String, MapArtifactDataDefinition> instanceArtifacts) {
this.instanceArtifacts = instanceArtifacts;
}
+
+ public Map<String, ForwardingPathDataDefinition> getForwardingPaths() {
+ return forwardingPaths;
+ }
+
+ public void setForwardingPaths(Map<String, ForwardingPathDataDefinition> forwardingPaths) {
+ this.forwardingPaths = forwardingPaths;
+ }
+
/**
* Adds component instance to composition of topology template
* Note that component instance will be overrided in case if the topology template already contains a component instance with the same name
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 706007bdd7..cbd612d024 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
@@ -68,7 +68,7 @@ public class ArtifactsOperations extends BaseOperation {
public Either<ArtifactDefinition, StorageOperationStatus> addArifactToComponent(ArtifactDefinition artifactInfo, String parentId, NodeTypeEnum type, boolean failIfExist, String instanceId) {
String artifactId = artifactInfo.getUniqueId();
- if (artifactId == null && artifactInfo.getEsId()!=null) {
+ if (artifactId == null && artifactInfo.getEsId() != null) {
artifactId = artifactInfo.getEsId();
}
Either<ArtifactDataDefinition, StorageOperationStatus> status = updateArtifactOnGraph(parentId, artifactInfo, type, artifactId, instanceId, false, false);
@@ -186,8 +186,7 @@ public class ArtifactsOperations extends BaseOperation {
}
/**
- *
- * @param parentId the id of the instance container
+ * @param parentId the id of the instance container
* @param instanceId the id of the instance of which to return its artifacts
* @return instance and instance deployment artifacts mapped by artifact label name
*/
@@ -267,27 +266,27 @@ public class ArtifactsOperations extends BaseOperation {
if (isUpdate) {
ArtifactTypeEnum type = ArtifactTypeEnum.findType(artifactData.getArtifactType());
switch (type) {
- case HEAT_ENV:
- if (edgeLabel == EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS) {
- generateUUID(artifactData, oldVesrion);
- } else {
- updateVersionAndDate(artifactData, oldVesrion);
- }
- break;
- case HEAT:
- case HEAT_NET:
- case HEAT_VOL:
- generateUUID(artifactData, oldVesrion);
- break;
- default:
- if (oldChecksum == null || oldChecksum.isEmpty()) {
- if (currentChecksum != null) {
+ case HEAT_ENV:
+ if (edgeLabel == EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS) {
generateUUID(artifactData, oldVesrion);
+ } else {
+ updateVersionAndDate(artifactData, oldVesrion);
}
- } else if ((currentChecksum != null && !currentChecksum.isEmpty()) && !oldChecksum.equals(currentChecksum)) {
+ break;
+ case HEAT:
+ case HEAT_NET:
+ case HEAT_VOL:
generateUUID(artifactData, oldVesrion);
- }
- break;
+ break;
+ default:
+ if (oldChecksum == null || oldChecksum.isEmpty()) {
+ if (currentChecksum != null) {
+ generateUUID(artifactData, oldVesrion);
+ }
+ } else if ((currentChecksum != null && !currentChecksum.isEmpty()) && !oldChecksum.equals(currentChecksum)) {
+ generateUUID(artifactData, oldVesrion);
+ }
+ break;
}
} else {
if (oldChecksum == null || oldChecksum.isEmpty()) {
@@ -315,11 +314,11 @@ public class ArtifactsOperations extends BaseOperation {
String id = heatEnv.getGeneratedFromId();
ComponentTypeEnum compType;
switch (parentType) {
- case ResourceInstance:
- compType = ComponentTypeEnum.RESOURCE_INSTANCE;
- break;
- default:
- compType = componentType;
+ case ResourceInstance:
+ compType = ComponentTypeEnum.RESOURCE_INSTANCE;
+ break;
+ default:
+ compType = componentType;
}
return getArtifactById(parentId, id, compType, containerId);
}
@@ -430,7 +429,7 @@ public class ArtifactsOperations extends BaseOperation {
return artMap;
}
- private Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> getInstanceArtifactsByLabel(String parentId, String instanceId, EdgeLabelEnum edgeLabelEnum) {
+ private Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> getInstanceArtifactsByLabel(String parentId, String instanceId, EdgeLabelEnum edgeLabelEnum) {
Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultEither = getDataFromGraph(parentId, edgeLabelEnum);
if (resultEither.isRight()) {
log.debug("failed to fetch {} for tosca element with id {}, error {}", edgeLabelEnum, parentId, resultEither.right().value());
@@ -449,34 +448,34 @@ public class ArtifactsOperations extends BaseOperation {
* if (nodeType == NodeTypeEnum.ResourceInstance) { edgeLabelEnum = EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS; vertexTypeEnum = VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS; isDeepElement = true; } else {
*/
switch (groupType) {
- case TOSCA:
- edgeLabelEnum = EdgeLabelEnum.TOSCA_ARTIFACTS;
- vertexTypeEnum = VertexTypeEnum.TOSCA_ARTIFACTS;
- break;
- case DEPLOYMENT:
- if (nodeType == NodeTypeEnum.ResourceInstance) {
- edgeLabelEnum = EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS;
- vertexTypeEnum = VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS;
- isDeepElement = true;
- } else {
- edgeLabelEnum = EdgeLabelEnum.DEPLOYMENT_ARTIFACTS;
- vertexTypeEnum = VertexTypeEnum.DEPLOYMENT_ARTIFACTS;
- }
- break;
- case SERVICE_API:
- edgeLabelEnum = EdgeLabelEnum.SERVICE_API_ARTIFACTS;
- vertexTypeEnum = VertexTypeEnum.SERVICE_API_ARTIFACTS;
- break;
- default:
- if (nodeType == NodeTypeEnum.ResourceInstance) {
- edgeLabelEnum = EdgeLabelEnum.INSTANCE_ARTIFACTS;
- vertexTypeEnum = VertexTypeEnum.INSTANCE_ARTIFACTS;
- isDeepElement = true;
- } else {
- edgeLabelEnum = EdgeLabelEnum.ARTIFACTS;
- vertexTypeEnum = VertexTypeEnum.ARTIFACTS;
- }
- break;
+ case TOSCA:
+ edgeLabelEnum = EdgeLabelEnum.TOSCA_ARTIFACTS;
+ vertexTypeEnum = VertexTypeEnum.TOSCA_ARTIFACTS;
+ break;
+ case DEPLOYMENT:
+ if (nodeType == NodeTypeEnum.ResourceInstance) {
+ edgeLabelEnum = EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS;
+ vertexTypeEnum = VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS;
+ isDeepElement = true;
+ } else {
+ edgeLabelEnum = EdgeLabelEnum.DEPLOYMENT_ARTIFACTS;
+ vertexTypeEnum = VertexTypeEnum.DEPLOYMENT_ARTIFACTS;
+ }
+ break;
+ case SERVICE_API:
+ edgeLabelEnum = EdgeLabelEnum.SERVICE_API_ARTIFACTS;
+ vertexTypeEnum = VertexTypeEnum.SERVICE_API_ARTIFACTS;
+ break;
+ default:
+ if (nodeType == NodeTypeEnum.ResourceInstance) {
+ edgeLabelEnum = EdgeLabelEnum.INSTANCE_ARTIFACTS;
+ vertexTypeEnum = VertexTypeEnum.INSTANCE_ARTIFACTS;
+ isDeepElement = true;
+ } else {
+ edgeLabelEnum = EdgeLabelEnum.ARTIFACTS;
+ vertexTypeEnum = VertexTypeEnum.ARTIFACTS;
+ }
+ break;
}
// }
return new ImmutableTriple<EdgeLabelEnum, Boolean, VertexTypeEnum>(edgeLabelEnum, isDeepElement, vertexTypeEnum);
@@ -505,10 +504,10 @@ public class ArtifactsOperations extends BaseOperation {
if (edgeLabelEnum != EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS && edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) {
uniqueId = UniqueIdBuilder.buildPropertyUniqueId(componentId, artifactToUpdate.getArtifactLabel());
} else {
- uniqueId = UniqueIdBuilder.buildPropertyUniqueId(instanceId, artifactToUpdate.getArtifactLabel());
+ uniqueId = UniqueIdBuilder.buildInstanceArtifactUniqueId(componentId, instanceId, artifactToUpdate.getArtifactLabel());
}
artifactToUpdate.setUniqueId(uniqueId);
- if(!isDeletePlaceholder)
+ if (!isDeletePlaceholder)
artifactToUpdate.setEsId(uniqueId);
} else
artifactToUpdate.setUniqueId(artifactId);
@@ -547,15 +546,19 @@ public class ArtifactsOperations extends BaseOperation {
oldVersion = oldArtifactData.getArtifactVersion();
//duplicated flag didn't receive from UI, take from DB
artifactToUpdate.setDuplicated(oldArtifactData.getDuplicated());
-
+
if (isNeedToClone)
artifactToUpdate.setDuplicated(Boolean.FALSE);
else {
if (artifactToUpdate.getDuplicated()) {
- String id = type != NodeTypeEnum.ResourceInstance ? componentId : instanceId;
- String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(id, artifactToUpdate.getArtifactLabel());
+ String uniqueId = "";
+ if(type != NodeTypeEnum.ResourceInstance)
+ uniqueId = UniqueIdBuilder.buildPropertyUniqueId(componentId, artifactToUpdate.getArtifactLabel());
+ else
+ uniqueId = UniqueIdBuilder.buildInstanceArtifactUniqueId(componentId, instanceId, artifactToUpdate.getArtifactLabel());
+
artifactToUpdate.setUniqueId(uniqueId);
- if(!isDeletePlaceholder)
+ if (!isDeletePlaceholder)
artifactToUpdate.setEsId(uniqueId);
artifactToUpdate.setDuplicated(Boolean.FALSE);
}
@@ -594,12 +597,12 @@ public class ArtifactsOperations extends BaseOperation {
artifacts.put(artifactToUpdate.getArtifactLabel(), artifactToUpdate);
}
- for ( Entry<String, MapArtifactDataDefinition> e : artifactInst.entrySet() ) {
+ for (Entry<String, MapArtifactDataDefinition> e : artifactInst.entrySet()) {
List<ArtifactDataDefinition> toscaDataListPerInst = e.getValue().getMapToscaDataDefinition().values().stream().collect(Collectors.toList());
List<String> pathKeysPerInst = new ArrayList<>();
pathKeysPerInst.add(e.getKey());
status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataListPerInst, pathKeysPerInst, JsonPresentationFields.ARTIFACT_LABEL);
- if ( status != StorageOperationStatus.OK) {
+ if (status != StorageOperationStatus.OK) {
log.debug("Failed to update atifacts group for instance {} in component {} edge type {} error {}", instanceId, componentId, edgeLabelEnum, status);
res = Either.right(status);
break;
@@ -637,14 +640,14 @@ public class ArtifactsOperations extends BaseOperation {
private boolean validateParentType(NodeTypeEnum type) {
boolean isValid = false;
switch (type) {
- case Resource:
- case InterfaceOperation:
- case Service:
- case ResourceInstance:
- isValid = true;
- break;
- default:
- log.debug("Not supported node type for artifact relation : {} ", type);
+ case Resource:
+ case InterfaceOperation:
+ case Service:
+ case ResourceInstance:
+ isValid = true;
+ break;
+ default:
+ log.debug("Not supported node type for artifact relation : {} ", type);
}
return isValid;
}
@@ -727,4 +730,5 @@ public class ArtifactsOperations extends BaseOperation {
}
return result;
}
+
}
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 537198d395..3b64a6b208 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
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -54,6 +55,8 @@ 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.Component;
+import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -549,6 +552,27 @@ public abstract class BaseOperation {
return statusRes;
}
+ StorageOperationStatus overrideToscaDataOfToscaElement(String toscaElementUid, EdgeLabelEnum edgeLabel, Map<String, ? extends ToscaDataDefinition> toscaData) {
+ return titanDao.getVertexById(toscaElementUid, JsonParseFlagEnum.NoParse)
+ .left()
+ .bind(graphVertex -> overrideToscaElementData(graphVertex, toscaData, edgeLabel))
+ .either(graphVertex -> StorageOperationStatus.OK,
+ DaoStatusConverter::convertTitanStatusToStorageStatus);
+ }
+
+ private Either<GraphVertex, TitanOperationStatus> overrideToscaElementData(GraphVertex toscaElement, Map<String, ? extends ToscaDataDefinition> toscaData, EdgeLabelEnum edgeLabelEnum) {
+ return titanDao.getChildVertex(toscaElement, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
+ .left()
+ .bind(dataVertex -> overrideToscaElementData(dataVertex, toscaElement, toscaData, edgeLabelEnum))
+ .right()
+ .map(err -> logAndReturn(err, "failed to override tosca data for element {} of type {}. status: {}", toscaElement.getUniqueId(), edgeLabelEnum, err));
+ }
+
+ private Either<GraphVertex, TitanOperationStatus> overrideToscaElementData(GraphVertex dataElement, GraphVertex toscaElement, Map<String, ? extends ToscaDataDefinition> toscaData, EdgeLabelEnum edgeLabelEnum) {
+ dataElement.setJson(toscaData);
+ return updateOrCopyOnUpdate(dataElement, toscaElement, edgeLabelEnum);
+ }
+
/**
* Adds list of tosca data deep elements to tosca element with specified uid according received labels
*
@@ -693,6 +717,36 @@ public abstract class BaseOperation {
}
/**
+ *
+ * @param toscaElementId the id of the tosca element data container
+ * @param edgeLabel the edge label of the data type to update
+ * @param toscaDataMap the data to update
+ * @param key the key in the json object where the map object block resides
+ * @return the status of the update operation
+ */
+ public <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataDeepElementsBlockToToscaElement(String toscaElementId, EdgeLabelEnum edgeLabel, MapDataDefinition<T> toscaDataMap, String key) {
+ return titanDao.getVertexById(toscaElementId, JsonParseFlagEnum.NoParse)
+ .either(toscaElement -> updateToscaDataDeepElementsBlockToToscaElement(toscaElement, edgeLabel, toscaDataMap, key),
+ DaoStatusConverter::convertTitanStatusToStorageStatus);
+ }
+
+ private <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataDeepElementsBlockToToscaElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, MapDataDefinition<T> toscaDataMap, String key) {
+ return titanDao.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson)
+ .left()
+ .bind(dataVertex -> updateToscaDataDeepElementsBlockToToscaElement(toscaElement, dataVertex, edgeLabel, toscaDataMap, key))
+ .either(updatedVertex -> StorageOperationStatus.OK,
+ DaoStatusConverter::convertTitanStatusToStorageStatus);
+ }
+
+ private <T extends ToscaDataDefinition> Either<GraphVertex, TitanOperationStatus> updateToscaDataDeepElementsBlockToToscaElement(GraphVertex toscaElement, GraphVertex dataElement, EdgeLabelEnum edgeLabel, MapDataDefinition<T> toscaDataMap, String key) {
+ Map<String, T> mapToscaDataDefinition = toscaDataMap.getMapToscaDataDefinition();
+ updateDeepElements(dataElement, mapToscaDataDefinition, Collections.singletonList(key));
+ return updateOrCopyOnUpdate(dataElement, toscaElement, edgeLabel)
+ .right()
+ .map(err -> logAndReturn(err, "failed while trying to update data vertex from tosca element {}, of type {} . status {}", toscaElement.getUniqueId(), edgeLabel, err));
+ }
+
+ /**
* Updates tosca data element of tosca element by specified uid according received labels
*
* @param toscaElementUid
@@ -833,7 +887,7 @@ public abstract class BaseOperation {
existingToscaDataMap = (Map<String, T>) toscaDataVertex.getJson();
}
- validateRes = validateMergeToscaData(toscaElement, toscaDataList, mapKeyField, existingToscaDataMap, isUpdate);
+ validateRes = validateMergeToscaData(toscaElement, toscaDataList, mapKeyField, existingToscaDataMap, isUpdate);
if (validateRes.isRight()) {
result = validateRes.right().value();
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed validate tosca data upon adding to tosca element {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, result);
@@ -1389,7 +1443,7 @@ public abstract class BaseOperation {
protected String buildGroupInstanceName(String instanceName, String groupName) {
return ValidationUtils.normalizeComponentInstanceName(instanceName) + ".." + groupName;
}
-
+
protected String generateCustomizationUUID() {
return UUID.randomUUID().toString();
}
@@ -1398,4 +1452,9 @@ public abstract class BaseOperation {
properties.forEach(p -> p.convertPropertyDataToInstancePropertyData());
}
+ private TitanOperationStatus logAndReturn(TitanOperationStatus titanOperationStatus, String logMsg, Object ... logParams) {
+ logger.debug(logMsg, logParams);
+ return titanOperationStatus;
+ }
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ExternalReferencesOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ExternalReferencesOperation.java
new file mode 100644
index 0000000000..76fb0a9151
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ExternalReferencesOperation.java
@@ -0,0 +1,261 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+import fj.data.Either;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+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.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.MapComponentInstanceExternalRefs;
+import org.openecomp.sdc.be.model.jsontitan.utils.IdMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.*;
+
+/**
+ * Created by yavivi on 26/01/2018.
+ */
+@Component
+public class ExternalReferencesOperation extends BaseOperation {
+
+ private static final Logger log = LoggerFactory.getLogger(ExternalReferencesOperation.class);
+
+ public IdMapper getIdMapper() {
+ return idMapper;
+ }
+
+ public void setIdMapper(IdMapper idMapper) {
+ this.idMapper = idMapper;
+ }
+
+ @Autowired
+ protected IdMapper idMapper;
+
+ /**
+ * Constructor
+ */
+ public ExternalReferencesOperation(TitanDao titanDao, NodeTypeOperation nto, TopologyTemplateOperation tto, IdMapper idMapper){
+ this.titanDao = titanDao;
+ this.topologyTemplateOperation = tto;
+ this.nodeTypeOperation = nto;
+ this.idMapper = idMapper;
+ }
+
+ public Either<String, ActionStatus> addExternalReferenceWithCommit(String serviceUuid, String componentInstanceName, String objectType, String reference) {
+ Either<String, ActionStatus> addResult = this.addExternalReference(serviceUuid, componentInstanceName, objectType, reference);
+ this.titanDao.commit();
+ return addResult;
+ }
+
+ public Either<String, ActionStatus> deleteExternalReferenceWithCommit(String serviceUuid, String componentInstanceName, String objectType, String reference) {
+ Either<String, ActionStatus> result = this.deleteExternalReference(serviceUuid, componentInstanceName, objectType, reference);
+ this.titanDao.commit();
+ return result;
+ }
+
+ public Either<String, ActionStatus> updateExternalReferenceWithCommit(String serviceVertexUuid, String componentInstanceName, String objectType, String oldRef, String newRef) {
+ Either<String, ActionStatus> updateResult = this.updateExternalReference(serviceVertexUuid, componentInstanceName, objectType, oldRef, newRef);
+ this.titanDao.commit();
+ return updateResult;
+ }
+
+ public Either<String, ActionStatus> addExternalReference(String assetUuid, String componentInstanceName, String objectType, String reference) {
+
+ //Get Service vertex
+ Either<GraphVertex, TitanOperationStatus> vertexById = this.titanDao.getVertexById(assetUuid);
+ if (vertexById.isRight()){
+ return Either.right(ActionStatus.RESOURCE_NOT_FOUND);
+ }
+
+ GraphVertex serviceVertex = vertexById.left().value();
+
+ final String compInstanceUniqueId = idMapper.mapComponentNameToUniqueId(componentInstanceName, serviceVertex);
+ if (compInstanceUniqueId == null) {
+ return Either.right(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND);
+ }
+
+ //Get the external references map vertex
+ final Either<GraphVertex, TitanOperationStatus> dataVertexResult = this.getDataVertex(serviceVertex, EdgeLabelEnum.EXTERNAL_REFS);
+
+ //Check whether data vertex found
+ GraphVertex externalRefsVertex = dataVertexResult.isLeft() ? dataVertexResult.left().value() : null;
+
+ //instanceId -> externalRefsMap
+ Map<String, MapComponentInstanceExternalRefs> externalReferencesFullData = null;
+ if (externalRefsVertex == null) {
+ //External Refs vertext does not exist, create its map.
+ externalReferencesFullData = new HashMap<String, MapComponentInstanceExternalRefs>() {
+ {
+ MapComponentInstanceExternalRefs externalRefsMap = new MapComponentInstanceExternalRefs();
+ put(compInstanceUniqueId, externalRefsMap);
+ }
+ };
+ } else {
+ externalReferencesFullData = (Map<String, MapComponentInstanceExternalRefs>) externalRefsVertex.getJson();
+ if (externalReferencesFullData.get(compInstanceUniqueId) == null){
+ externalReferencesFullData.put(compInstanceUniqueId, new MapComponentInstanceExternalRefs());
+ }
+ }
+
+ boolean isAdded = this.addExternalRef(externalReferencesFullData, compInstanceUniqueId, objectType, reference);
+ this.updateFullToscaData(serviceVertex, EdgeLabelEnum.EXTERNAL_REFS, VertexTypeEnum.EXTERNAL_REF, externalReferencesFullData);
+
+ return isAdded ? Either.left(reference) : Either.right(ActionStatus.EXT_REF_ALREADY_EXIST);
+ }
+
+ public Either<String, ActionStatus> deleteExternalReference(String assetUuid, String componentInstanceName, String objectType, String reference){
+ //Get Service vertex
+ Either<GraphVertex, TitanOperationStatus> vertexById = this.titanDao.getVertexById(assetUuid);
+ if (vertexById.isRight()){
+ return Either.right(ActionStatus.RESOURCE_NOT_FOUND);
+ }
+ GraphVertex serviceVertex = vertexById.left().value();
+
+ final String compInstanceUniqueId = idMapper.mapComponentNameToUniqueId(componentInstanceName, serviceVertex);
+ if (compInstanceUniqueId == null) {
+ return Either.right(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND);
+ }
+
+ //Get the external references map vertex
+ final Either<GraphVertex, TitanOperationStatus> dataVertexResult = this.getDataVertex(serviceVertex, EdgeLabelEnum.EXTERNAL_REFS);
+
+ //Check whether data vertex found
+ GraphVertex externalRefsVertex = dataVertexResult.isLeft() ? dataVertexResult.left().value() : null;
+ boolean refDeleted = false;
+ if (externalRefsVertex != null) {
+ Map<String, MapComponentInstanceExternalRefs> externalReferencesFullData = (Map<String, MapComponentInstanceExternalRefs>) externalRefsVertex.getJson();
+ if (externalReferencesFullData != null) {
+ refDeleted = this.deleteExternalRef(externalReferencesFullData, compInstanceUniqueId, objectType, reference);
+ this.updateFullToscaData(serviceVertex, EdgeLabelEnum.EXTERNAL_REFS, VertexTypeEnum.EXTERNAL_REF, externalReferencesFullData); //@ TODO if ref deleted
+ }
+ }
+
+ if (refDeleted) {
+ return Either.left(reference);
+ } else {
+ return Either.right(ActionStatus.EXT_REF_NOT_FOUND);
+ }
+ }
+
+ public Either<String, ActionStatus> updateExternalReference(String assetUuid, String componentInstanceName, String objectType, String oldRef, String newRef) {
+ //Get Service vertex
+ Either<GraphVertex, TitanOperationStatus> vertexById = this.titanDao.getVertexById(assetUuid);
+ if (vertexById.isRight()){
+ return Either.right(ActionStatus.RESOURCE_NOT_FOUND);
+ }
+
+ GraphVertex serviceVertex = vertexById.left().value();
+
+ //Map instance_name -> uuid
+ final String compInstanceUniqueId = idMapper.mapComponentNameToUniqueId(componentInstanceName, serviceVertex);
+ if (compInstanceUniqueId == null) {
+ return Either.right(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND);
+ }
+
+ //Get the external references map vertex
+ final Either<GraphVertex, TitanOperationStatus> dataVertexResult = this.getDataVertex(serviceVertex, EdgeLabelEnum.EXTERNAL_REFS);
+
+ //Check whether data vertex found
+ GraphVertex externalRefsVertex = dataVertexResult.isLeft() ? dataVertexResult.left().value() : null;
+ boolean refReplaced = false;
+ if (externalRefsVertex != null) {
+ Map<String, MapComponentInstanceExternalRefs> externalReferencesFullData = (Map<String, MapComponentInstanceExternalRefs>) externalRefsVertex.getJson();
+ if (externalReferencesFullData != null) {
+ refReplaced = this.updateExternalRef(externalReferencesFullData, compInstanceUniqueId, objectType, oldRef, newRef);
+ this.updateFullToscaData(serviceVertex, EdgeLabelEnum.EXTERNAL_REFS, VertexTypeEnum.EXTERNAL_REF, externalReferencesFullData);
+ }
+ }
+ if (refReplaced) {
+ return Either.left(newRef);
+ } else {
+ return Either.right(ActionStatus.EXT_REF_NOT_FOUND);
+ }
+ }
+
+ public Either<Map<String, List<String>>, ActionStatus> getExternalReferences(String assetUuid, String objectType) {
+ //Get Service vertex
+ Either<GraphVertex, TitanOperationStatus> vertexById = this.titanDao.getVertexById(assetUuid);
+ if (vertexById.isRight()){
+ return Either.right(ActionStatus.RESOURCE_NOT_FOUND);
+ }
+
+ GraphVertex serviceVertex = vertexById.left().value();
+
+ Map<String, List<String>> result = new HashMap();
+
+ //Get the external references map vertex
+ final Either<GraphVertex, TitanOperationStatus> dataVertexResult = this.getDataVertex(serviceVertex, EdgeLabelEnum.EXTERNAL_REFS);
+ //Check whether data vertex found
+ GraphVertex externalRefsVertex = dataVertexResult.isLeft() ? dataVertexResult.left().value() : null;
+ if (externalRefsVertex != null) {
+ Map<String, MapComponentInstanceExternalRefs> externalReferencesFullData = (Map<String, MapComponentInstanceExternalRefs>) externalRefsVertex.getJson();
+ if (externalReferencesFullData != null) {
+ externalReferencesFullData.entrySet().forEach(
+ s -> {
+ List<String> externalRefsByObjectType = externalReferencesFullData.get(s.getKey()).getExternalRefsByObjectType(objectType);
+ List<String> refList = externalRefsByObjectType == null ? new ArrayList<>() : externalRefsByObjectType;
+ String key = idMapper.mapUniqueIdToComponentNameTo(s.getKey(), serviceVertex);
+ result.put(key, refList);
+ }
+ );
+ return Either.left(result);
+ }
+ }
+ //No external References Node found on this asset
+ return Either.left(new HashMap<>());
+ }
+
+ public Either<List<String>, ActionStatus> getExternalReferences(String assetUuid, String componentInstanceName, String objectType) {
+ //Get Service vertex
+ Either<GraphVertex, TitanOperationStatus> vertexById = this.titanDao.getVertexById(assetUuid);
+ if (vertexById.isRight()){
+ return Either.right(ActionStatus.RESOURCE_NOT_FOUND);
+ }
+
+ GraphVertex serviceVertex = vertexById.left().value();
+ final String compInstanceUniqueId = idMapper.mapComponentNameToUniqueId(componentInstanceName, serviceVertex);
+ if (compInstanceUniqueId == null) {
+ return Either.right(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND);
+ }
+
+ //Get the external references map vertex
+ final Either<GraphVertex, TitanOperationStatus> dataVertexResult = this.getDataVertex(serviceVertex, EdgeLabelEnum.EXTERNAL_REFS);
+
+ //Check whether data vertex found
+ GraphVertex externalRefsVertex = dataVertexResult.isLeft() ? dataVertexResult.left().value() : null;
+ if (externalRefsVertex != null) {
+ Map<String, MapComponentInstanceExternalRefs> externalReferencesFullData = (Map<String, MapComponentInstanceExternalRefs>) externalRefsVertex.getJson();
+ if (externalReferencesFullData != null) {
+ return Either.left(this.getExternalReferencesByObjectId(externalReferencesFullData, compInstanceUniqueId, objectType));
+ }
+ }
+
+ //No external References Node found on this asset
+ return Either.left(new LinkedList());
+ }
+
+ private List<String> getExternalReferencesByObjectId(Map<String, MapComponentInstanceExternalRefs> externalReferencesFullData, String componentInstanceId, String objectType) {
+ MapComponentInstanceExternalRefs externalRefsMap = externalReferencesFullData.get(componentInstanceId);
+ List<String> externalRefsByObjectType = externalRefsMap.getExternalRefsByObjectType(objectType);
+ return externalRefsByObjectType != null ? externalRefsByObjectType : new LinkedList<String>();
+ }
+
+ private boolean updateExternalRef(Map<String, MapComponentInstanceExternalRefs> externalReferencesFullData, String componentInstanceId, String objectType, String oldRef, String newRef) {
+ MapComponentInstanceExternalRefs externalRefsMap = externalReferencesFullData.get(componentInstanceId);
+ return externalRefsMap.replaceExternalRef(objectType, oldRef, newRef);
+ }
+
+ private boolean deleteExternalRef(Map<String, MapComponentInstanceExternalRefs> externalReferencesFullData, String componentInstanceId, String objectType, String reference) {
+ MapComponentInstanceExternalRefs externalRefsMap = externalReferencesFullData.get(componentInstanceId);
+ return externalRefsMap.deleteExternalRef(objectType, reference);
+ }
+
+ private boolean addExternalRef(Map<String, MapComponentInstanceExternalRefs> externalReferencesFullData, String componentInstanceId, String objectType, String reference) {
+ MapComponentInstanceExternalRefs externalRefsMap = externalReferencesFullData.get(componentInstanceId);
+ return externalRefsMap.addExternalRef(objectType, reference);
+ }
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ForwardingPathOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ForwardingPathOperation.java
new file mode 100644
index 0000000000..ad4c1fb4f3
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ForwardingPathOperation.java
@@ -0,0 +1,122 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+import fj.data.Either;
+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;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+@org.springframework.stereotype.Component("forwarding-paths-operations")
+public class ForwardingPathOperation extends BaseOperation {
+ private static Logger logger = LoggerFactory.getLogger(ForwardingPathOperation.class.getName());
+
+
+ public Either<Set<String>, StorageOperationStatus> deleteForwardingPath(Service service, Set<String> forwardingPathsToDelete) {
+ Either<Set<String>, StorageOperationStatus> result = null;
+ Either<GraphVertex, TitanOperationStatus> getComponentVertex;
+ StorageOperationStatus status = null;
+
+ if (result == null) {
+ getComponentVertex = titanDao.getVertexById(service.getUniqueId(), JsonParseFlagEnum.NoParse);
+ if (getComponentVertex.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getComponentVertex.right().value()));
+ }
+ }
+ if (result == null) {
+
+ status = deleteToscaDataElements(service.getUniqueId(), EdgeLabelEnum.FORWARDING_PATH,new ArrayList<>(forwardingPathsToDelete));
+
+ if (status != StorageOperationStatus.OK) {
+ result = Either.right(status);
+ }
+ }
+
+ if (result == null) {
+ result = Either.left(forwardingPathsToDelete);
+ }
+ return result;
+ }
+
+ public Either<ForwardingPathDataDefinition, StorageOperationStatus> addForwardingPath(String serviceId, ForwardingPathDataDefinition currentPath) {
+ return addOrUpdateForwardingPath(false, serviceId, currentPath);
+ }
+
+ public Either<ForwardingPathDataDefinition, StorageOperationStatus> updateForwardingPath(String serviceId, ForwardingPathDataDefinition currentPath) {
+ return addOrUpdateForwardingPath(true, serviceId, currentPath);
+ }
+
+ private Either<ForwardingPathDataDefinition, StorageOperationStatus> addOrUpdateForwardingPath(boolean isUpdateAction, String serviceId, ForwardingPathDataDefinition currentPath) {
+
+ StorageOperationStatus statusRes;
+ Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
+
+ getToscaElementRes = titanDao.getVertexById(serviceId, JsonParseFlagEnum.NoParse);
+ if (getToscaElementRes.isRight()) {
+ TitanOperationStatus status = getToscaElementRes.right().value();
+ CommonUtility.addRecordToLog(logger, CommonUtility.LogLevelEnum.DEBUG, "Failed to get tosca element {} upon adding the properties. Status is {}. ", serviceId, status);
+ statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
+ return Either.right(statusRes);
+ }
+ GraphVertex serviceVertex = getToscaElementRes.left().value();
+ if (!isUpdateAction){
+ currentPath.setUniqueId(UUID.randomUUID().toString());
+ }
+ statusRes = performUpdateToscaAction(isUpdateAction, serviceVertex, Arrays.asList(currentPath), JsonPresentationFields.FORWARDING_PATH);
+ {
+ if (!statusRes.equals(StorageOperationStatus.OK)) {
+ logger.error("Failed to find the parent capability of capability type {}. status is {}", serviceId, statusRes);
+ return Either.right(statusRes);
+ }
+ return Either.left(currentPath);
+ }
+
+ }
+
+
+ private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex, List<ForwardingPathDataDefinition> toscaDataList, JsonPresentationFields mapKeyField) {
+ if (isUpdate) {
+ return updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.FORWARDING_PATH, VertexTypeEnum.FORWARDING_PATH, toscaDataList, JsonPresentationFields.UNIQUE_ID);
+ } else {
+ return addToscaDataToToscaElement(graphVertex, EdgeLabelEnum.FORWARDING_PATH, VertexTypeEnum.FORWARDING_PATH, toscaDataList, JsonPresentationFields.UNIQUE_ID);
+ }
+ }
+
+}
+
+
+
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 87053ff454..668a6d973a 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
@@ -34,14 +34,12 @@ import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.model.Component;
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.model.GroupProperty;
-import org.openecomp.sdc.be.model.User;
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;
@@ -56,9 +54,9 @@ import fj.data.Either;
@org.springframework.stereotype.Component("groups-operation")
public class GroupsOperation extends BaseOperation {
- private static Logger logger = LoggerFactory.getLogger(GroupsOperation.class.getName());
+ private static final Logger log = LoggerFactory.getLogger(GroupsOperation.class);
- public Either<List<GroupDefinition>, StorageOperationStatus> createGroups(Component component, User user, ComponentTypeEnum componentType, Map<String, GroupDataDefinition> groups) {
+ public Either<List<GroupDefinition>, StorageOperationStatus> createGroups(Component component, Map<String, GroupDataDefinition> groups) {
Either<List<GroupDefinition>, StorageOperationStatus> result = null;
Either<GraphVertex, TitanOperationStatus> getComponentVertex = null;
@@ -76,20 +74,13 @@ public class GroupsOperation extends BaseOperation {
result = Either.right(status);
}
}
- /* if (result == null) {
- status = topologyTemplateOperation.associateGroupsPropertiesToComponent(getComponentVertex.left().value(), groupsProperties);
- if (status != StorageOperationStatus.OK) {
- result = Either.right(status);
- }
- }*/
if (result == null) {
result = Either.left(ModelConverter.convertToGroupDefinitions(groups));
}
return result;
}
- public Either<List<GroupDefinition>, StorageOperationStatus> addGroups(Component component, User user, ComponentTypeEnum componentType, List<GroupDataDefinition> groups) {
- // TODO Auto-generated method stub
+ public Either<List<GroupDefinition>, StorageOperationStatus> addGroups(Component component, List<GroupDataDefinition> groups) {
Either<List<GroupDefinition>, StorageOperationStatus> result = null;
Either<GraphVertex, TitanOperationStatus> getComponentVertex = null;
StorageOperationStatus status = null;
@@ -115,8 +106,7 @@ public class GroupsOperation extends BaseOperation {
return result;
}
- public Either<List<GroupDefinition>, StorageOperationStatus> deleteGroups(Component component, User user, ComponentTypeEnum componentType, List<GroupDataDefinition> groups) {
- // TODO Auto-generated method stub
+ public Either<List<GroupDefinition>, StorageOperationStatus> deleteGroups(Component component, List<GroupDataDefinition> groups) {
Either<List<GroupDefinition>, StorageOperationStatus> result = null;
Either<GraphVertex, TitanOperationStatus> getComponentVertex = null;
StorageOperationStatus status = null;
@@ -143,8 +133,7 @@ public class GroupsOperation extends BaseOperation {
return result;
}
- public Either<List<GroupDefinition>, StorageOperationStatus> updateGroups(Component component, ComponentTypeEnum componentType, List<GroupDataDefinition> groups) {
- // TODO Auto-generated method stub
+ public <T extends GroupDataDefinition> Either<List<GroupDefinition>, StorageOperationStatus> updateGroups(Component component, List<T> groups) {
Either<List<GroupDefinition>, StorageOperationStatus> result = null;
Either<GraphVertex, TitanOperationStatus> getComponentVertex = null;
StorageOperationStatus status = null;
@@ -184,12 +173,11 @@ public class GroupsOperation extends BaseOperation {
Either<List<GroupProperty>,StorageOperationStatus> result = null;
Either<GraphVertex, TitanOperationStatus> getComponentVertex = null;
GraphVertex componentVertex = null;
- StorageOperationStatus status = null;
if (result == null) {
getComponentVertex = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseMetadata);
if (getComponentVertex.isRight()) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch component {}. Status is {} ", componentId);
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch component {}. Status is {} ", componentId);
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getComponentVertex.right().value()));
}
}
@@ -206,7 +194,7 @@ public class GroupsOperation extends BaseOperation {
StorageOperationStatus updateDataRes = updateToscaDataOfToscaElement(componentVertex, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, group, JsonPresentationFields.NAME);
if ( updateDataRes != StorageOperationStatus.OK ){
- logger.debug("Failed to update properties for group {} error {}", group.getName(), updateDataRes);
+ log.debug("Failed to update properties for group {} error {}", group.getName(), updateDataRes);
result = Either.right(updateDataRes);
}
}
@@ -214,7 +202,7 @@ public class GroupsOperation extends BaseOperation {
componentVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, System.currentTimeMillis());
Either<GraphVertex, TitanOperationStatus> updateRes = titanDao.updateVertex(componentVertex);
if (updateRes.isRight()) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to update the component {}. Status is {} ", componentId, updateRes.right().value());
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the component {}. Status is {} ", componentId, updateRes.right().value());
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
}
}
@@ -241,7 +229,7 @@ public class GroupsOperation extends BaseOperation {
}
- public Either<List<GroupInstance>, StorageOperationStatus> updateGroupInstances(Component component, ComponentTypeEnum componentType, String instanceId, List<GroupInstance> updatedGroupInstances) {
+ public Either<List<GroupInstance>, StorageOperationStatus> updateGroupInstances(Component component, String instanceId, List<GroupInstance> updatedGroupInstances) {
Either<List<GroupInstance>, StorageOperationStatus> result = null;
StorageOperationStatus status = null;
@@ -267,7 +255,7 @@ public class GroupsOperation extends BaseOperation {
public Either<GroupDefinition, StorageOperationStatus> updateGroup(Component component, GroupDefinition currentGroup) {
StorageOperationStatus status = updateToscaDataOfToscaElement(component.getUniqueId(), EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, currentGroup, JsonPresentationFields.NAME);
if(status != StorageOperationStatus.OK){
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to update group {} of component {}. The status is}. ", currentGroup.getName(), component.getName(), status);
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update group {} of component {}. The status is}. ", currentGroup.getName(), component.getName(), status);
return Either.right(status);
}
return Either.left(currentGroup);
@@ -276,7 +264,7 @@ public class GroupsOperation extends BaseOperation {
public StorageOperationStatus deleteGroup(Component component, String currentGroupName) {
StorageOperationStatus status = deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, currentGroupName, JsonPresentationFields.NAME);
if(status != StorageOperationStatus.OK){
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete group {} of component {}. The status is}. ", currentGroupName, component.getName(), status);
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to delete group {} of component {}. The status is}. ", currentGroupName, component.getName(), status);
}
return status;
}
@@ -284,7 +272,7 @@ public class GroupsOperation extends BaseOperation {
public Either<GroupDefinition, StorageOperationStatus> addGroup(Component component, GroupDefinition currentGroup) {
StorageOperationStatus status = addToscaDataToToscaElement(component.getUniqueId(), EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, currentGroup, JsonPresentationFields.NAME);
if(status != StorageOperationStatus.OK){
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to update group {} of component {}. The status is}. ", currentGroup.getName(), component.getName(), status);
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update group {} of component {}. The status is}. ", currentGroup.getName(), component.getName(), status);
return Either.right(status);
}
return Either.left(currentGroup);
@@ -294,7 +282,7 @@ public class GroupsOperation extends BaseOperation {
Either<GraphVertex, TitanOperationStatus> getComponentVertex = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseMetadata);
if (getComponentVertex.isRight()) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch component {}. Status is {} ", componentId);
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch component {}. Status is {} ", componentId);
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getComponentVertex.right().value()));
}
@@ -310,7 +298,7 @@ public class GroupsOperation extends BaseOperation {
pathKeys.add(instanceId);
StorageOperationStatus updateDataRes = updateToscaDataDeepElementOfToscaElement(componentId, EdgeLabelEnum.INST_GROUPS, VertexTypeEnum.INST_GROUPS, groupInstanceDataDefinition, pathKeys, JsonPresentationFields.NAME);
if (updateDataRes != StorageOperationStatus.OK) {
- logger.debug("Failed to update properties for group instance {} error {}", oldGroupInstance.getName(), updateDataRes);
+ log.debug("Failed to update properties for group instance {} error {}", oldGroupInstance.getName(), updateDataRes);
return Either.right(updateDataRes);
}
return Either.left(oldGroupInstance);
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 f59f097bdb..3dc39b3a99 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
@@ -28,11 +28,11 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.function.BiConsumer;
+import java.util.function.BiPredicate;
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;
@@ -69,22 +69,7 @@ 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.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.*;
import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
@@ -539,6 +524,7 @@ public class NodeTemplateOperation extends BaseOperation {
}
}
}
+ return updateAllAndCalculatedCapReqOnGraph(container.getUniqueId(), containerV, capResult, capFullResult, reqResult, reqFullResult);
}
}
return StorageOperationStatus.OK;
@@ -1000,35 +986,7 @@ public class NodeTemplateOperation extends BaseOperation {
dataDefinition.setToscaComponentName((String) originToscaElement.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
if (dataDefinition.getOriginType() == null && originToscaElement != null) {
ResourceTypeEnum resourceType = originToscaElement.getResourceType();
- OriginTypeEnum originType = null;
- switch (resourceType) {
- case VF:
- originType = OriginTypeEnum.VF;
- break;
- case VFC:
- originType = OriginTypeEnum.VFC;
- break;
- case CVFC:
- originType = OriginTypeEnum.CVFC;
- break;
- case VL:
- originType = OriginTypeEnum.VL;
- break;
- case CP:
- originType = OriginTypeEnum.CP;
- break;
- case PNF:
- originType = OriginTypeEnum.PNF;
- break;
- case ServiceProxy:
- originType = OriginTypeEnum.ServiceProxy;
- break;
- case Configuration:
- originType = OriginTypeEnum.Configuration;
- break;
- default:
- break;
- }
+ OriginTypeEnum originType = OriginTypeEnum.findByValue(resourceType.name());
dataDefinition.setOriginType(originType);
}
if(dataDefinition.getOriginType() == OriginTypeEnum.ServiceProxy)
@@ -1340,7 +1298,7 @@ public class NodeTemplateOperation extends BaseOperation {
Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> reqFullResult = null;
MapListRequirementDataDefinition reqMapOfLists = null;
Optional<RequirementDataDefinition> foundRequirement;
- RelationshipInfo relationshipInfo = foundRelation.getSingleRelationship().getRelation();
+ RelationshipInfo relationshipInfo = foundRelation.resolveSingleRelationship().getRelation();
Either<GraphVertex, TitanOperationStatus> containerVEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
if (containerVEither.isRight()) {
TitanOperationStatus error = containerVEither.right().value();
@@ -1387,7 +1345,7 @@ public class NodeTemplateOperation extends BaseOperation {
MapListCapabiltyDataDefinition capMapOfLists = null;
Optional<CapabilityDataDefinition> foundRequirement;
- RelationshipInfo relationshipInfo = foundRelation.getSingleRelationship().getRelation();
+ RelationshipInfo relationshipInfo = foundRelation.resolveSingleRelationship().getRelation();
Either<GraphVertex, TitanOperationStatus> containerVEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
if (containerVEither.isRight()) {
TitanOperationStatus error = containerVEither.right().value();
@@ -1526,7 +1484,8 @@ public class NodeTemplateOperation extends BaseOperation {
mapListCapaDataDef.put(hereIsTheKey, findByKey);
}
findByKey.add(cap);
- relationship.setCapability(cap);
+ if(relationship!= null)
+ relationship.setCapability(cap);
break;
}
}
@@ -1574,7 +1533,8 @@ public class NodeTemplateOperation extends BaseOperation {
mapListReqDataDef.put(hereIsTheKey, findByKey);
}
findByKey.add(req);
- relationship.setRequirement(req);
+ if(relationship!= null)
+ relationship.setRequirement(req);
break;
}
}
@@ -1770,8 +1730,12 @@ public class NodeTemplateOperation extends BaseOperation {
}
}
}
+ if (requirementForRelation == null) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch requirement for type {} for instance {} in container {}.", type, toInstId, containerId);
+ return Either.right(StorageOperationStatus.MATCH_NOT_FOUND);
+ }
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,
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "No macth for capability from type {} and requirement {} from {} to {} in container {}.", capabilityForRelation.getType(), requirementForRelation.getCapability(), fromInstId,
toInstId, containerId);
return Either.right(StorageOperationStatus.MATCH_NOT_FOUND);
}
@@ -1985,6 +1949,10 @@ public class NodeTemplateOperation extends BaseOperation {
return updateToscaDataDeepElementOfToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, property, pathKeys, JsonPresentationFields.NAME);
}
+ public StorageOperationStatus overrideComponentCapabilitiesProperties(Component containerComponent, Map<String, MapCapabiltyProperty> capabilityPropertyMap) {
+ return overrideToscaDataOfToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, capabilityPropertyMap);
+ }
+
public StorageOperationStatus addComponentInstanceProperty(Component containerComponent, String componentInstanceId, ComponentInstanceProperty property) {
List<String> pathKeys = new ArrayList<>();
pathKeys.add(componentInstanceId);
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 d46743cfa9..59f4745537 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
@@ -41,6 +41,7 @@ import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperation.java
new file mode 100644
index 0000000000..06770318aa
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/PolicyOperation.java
@@ -0,0 +1,63 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+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;
+import org.openecomp.sdc.be.dao.utils.MapUtil;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@org.springframework.stereotype.Component
+public class PolicyOperation {
+
+ private static final Logger log = LoggerFactory.getLogger(PolicyOperation.class);
+ private TopologyTemplateOperation topologyTemplateOperation;
+ private TitanDao titanDao;
+
+ public PolicyOperation(TopologyTemplateOperation topologyTemplateOperation, TitanDao titanDao) {
+ this.topologyTemplateOperation = topologyTemplateOperation;
+ this.titanDao = titanDao;
+ }
+
+ /**
+ * updates a list of policy properties by overriding the existing ones with the same name
+ * @param containerComponent the container of the policy of which its properties are to be updated
+ * @param policyId the id of the policy of which its properties are to be updated
+ * @param propertiesToUpdate the policy properties to update
+ * @return the update operation status
+ */
+ public StorageOperationStatus updatePolicyProperties(Component containerComponent, String policyId, List<PropertyDataDefinition> propertiesToUpdate) {
+ log.debug("#updatePolicyProperties - updating the properties of policy {} in component {}", policyId, containerComponent.getUniqueId());
+ PolicyDefinition policy = containerComponent.getPolicyById(policyId);
+ return titanDao.getVertexById(containerComponent.getUniqueId(), JsonParseFlagEnum.NoParse)
+ .either(containerVertex -> updatePolicyProperties(containerVertex, policy, propertiesToUpdate),
+ DaoStatusConverter::convertTitanStatusToStorageStatus);
+ }
+
+ private StorageOperationStatus updatePolicyProperties(GraphVertex container, PolicyDefinition policy, List<PropertyDataDefinition> propertiesToUpdate) {
+ List<PropertyDataDefinition> policyProperties = policy.getProperties();
+ List<PropertyDataDefinition> updatedPolicyProperties = updatePolicyProperties(policyProperties, propertiesToUpdate);
+ policy.setProperties(updatedPolicyProperties);
+ return topologyTemplateOperation.updatePolicyOfToscaElement(container, policy);
+ }
+
+ private List<PropertyDataDefinition> updatePolicyProperties(List<PropertyDataDefinition> currentPolicyProperties, List<PropertyDataDefinition> toBeUpdatedProperties) {
+ Map<String, PropertyDataDefinition> currPropsByName = MapUtil.toMap(currentPolicyProperties, PropertyDataDefinition::getName);
+ overrideCurrentPropertiesWithUpdatedProperties(currPropsByName, toBeUpdatedProperties);
+ return new ArrayList<>(currPropsByName.values());
+ }
+
+ private void overrideCurrentPropertiesWithUpdatedProperties(Map<String, PropertyDataDefinition> currPropsByName, List<PropertyDataDefinition> toBeUpdatedProperties) {
+ toBeUpdatedProperties.forEach(prop -> currPropsByName.put(prop.getName(), prop));
+ }
+
+}
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 b1d4f151d8..9ad3053d66 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
@@ -20,15 +20,8 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
-import java.lang.reflect.Type;
-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 com.google.gson.reflect.TypeToken;
+import fj.data.Either;
import org.apache.commons.collections.MapUtils;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
@@ -37,24 +30,15 @@ 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.elements.AdditionalInfoParameterDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
-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.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.*;
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.model.Component;
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.PolicyDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
@@ -65,19 +49,31 @@ 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;
+import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-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.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
@org.springframework.stereotype.Component("topology-template-operation")
public class TopologyTemplateOperation extends ToscaElementOperation {
+
private static Logger log = LoggerFactory.getLogger(TopologyTemplateOperation.class.getName());
+ @Override
+ public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId) {
+ return super.getToscaElement(uniqueId);
+ }
+
public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
Either<TopologyTemplate, StorageOperationStatus> result = null;
@@ -125,6 +121,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
result = Either.right(associateGroups);
return result;
}
+ StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
+ if (associatePolicies != StorageOperationStatus.OK) {
+ result = Either.right(associatePolicies);
+ return result;
+ }
StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
if (associateInstAttr != StorageOperationStatus.OK) {
result = Either.right(associateInstAttr);
@@ -174,10 +175,40 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
result = Either.right(associateCapProperties);
return result;
}
+ StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
+ if (associateCapProperties != StorageOperationStatus.OK) {
+ result = Either.right(associatePathProperties);
+ return result;
+ }
+
+
return Either.left(topologyTemplate);
}
+ private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
+ return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
+ }
+
+ private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
+ if (policies != null && !policies.isEmpty()) {
+ policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
+ String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
+ p.setUniqueId(uid);
+ });
+ Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
+ if (assosiateElementToData.isRight()) {
+ return assosiateElementToData.right().value();
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
+ Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
+ return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
+ }
+
private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
Map<String, MapCapabiltyProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
if (calculatedCapProperties != null && !calculatedCapProperties.isEmpty()) {
@@ -405,6 +436,16 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
}
+ public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
+ if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
+ Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
+ if (assosiateElementToData.isRight()) {
+ return assosiateElementToData.right().value();
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
if (instAttr != null && !instAttr.isEmpty()) {
Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
@@ -509,8 +550,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
TopologyTemplate toscaElement;
toscaElement = convertToTopologyTemplate(componentV);
- TitanOperationStatus status = null;
- if (false == componentParametersView.isIgnoreUsers()) {
+ TitanOperationStatus status;
+ if (!componentParametersView.isIgnoreUsers()) {
status = setCreatorFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
@@ -521,72 +562,79 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreCategories()) {
+ if (!componentParametersView.isIgnoreCategories()) {
status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreArtifacts()) {
+ if (!componentParametersView.isIgnoreArtifacts()) {
TitanOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
if (storageStatus != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
}
}
- if (false == componentParametersView.isIgnoreComponentInstancesProperties()) {
+ if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreCapabilities()) {
+ if (!componentParametersView.isIgnoreCapabilities()) {
status = setCapabilitiesFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreRequirements()) {
+ if (!componentParametersView.isIgnoreRequirements()) {
status = setRequirementsFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreAllVersions()) {
+ if (!componentParametersView.isIgnoreAllVersions()) {
status = setAllVersions(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreAdditionalInformation()) {
+ if (!componentParametersView.isIgnoreAdditionalInformation()) {
status = setAdditionalInformationFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreGroups()) {
+ if (!componentParametersView.isIgnoreGroups()) {
status = setGroupsFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreComponentInstances()) {
+ if (!componentParametersView.isIgnorePolicies()) {
+ status = setPoliciesFromGraph(componentV, toscaElement);
+ if (status != TitanOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+
+ }
+ if (!componentParametersView.isIgnoreComponentInstances()) {
status = setInstGroupsFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreInputs()) {
+ if (!componentParametersView.isIgnoreInputs()) {
status = setInputsFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
- if (false == componentParametersView.isIgnoreProperties()) {
+ if (!componentParametersView.isIgnoreProperties()) {
status = setPropertiesFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
@@ -594,7 +642,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
- if (false == componentParametersView.isIgnoreComponentInstancesInputs()) {
+ if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
@@ -602,16 +650,49 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
}
- if (false == componentParametersView.isIgnoreCapabiltyProperties()) {
+ if (!componentParametersView.isIgnoreCapabiltyProperties()) {
status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
if (status != TitanOperationStatus.OK) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
+
+ if (!componentParametersView.isIgnoreForwardingPath()) {
+ status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
+ if (status != TitanOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+
+ }
+ }
return Either.left(toscaElement);
}
+ private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
+ Either<Map<String, PolicyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
+ if (result.isLeft()) {
+ toscaElement.setPolicies(result.left().value());
+ } else {
+ if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
+ return result.right().value();
+ }
+ }
+ return TitanOperationStatus.OK;
+ }
+
+ private TitanOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
+ Either<Map<String, ForwardingPathDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
+ if (result.isLeft()) {
+ topologyTemplate.setForwardingPaths(result.left().value());
+ } else {
+ if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
+ return result.right().value();
+ }
+ }
+ return TitanOperationStatus.OK;
+ }
+
+
private TitanOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
Either<Map<String, MapCapabiltyProperty>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
if (result.isLeft()) {
@@ -808,6 +889,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return TitanOperationStatus.OK;
}
+ @SuppressWarnings("unchecked")
private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
@@ -901,6 +983,12 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
+ Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+
status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
toscaElementVertex.getVertex().remove();
log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
@@ -984,6 +1072,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return Either.left(byCriteria.left().value());
}
+ @SuppressWarnings("unchecked")
public boolean isInUse(GraphVertex elementV, List<GraphVertex> allNonDeleted) {
for (GraphVertex containerV : allNonDeleted) {
Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
@@ -1004,6 +1093,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return false;
}
+ @SuppressWarnings("unchecked")
public boolean isInUse(String componentId, List<GraphVertex> allNonDeleted) {
for (GraphVertex containerV : allNonDeleted) {
Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
@@ -1074,14 +1164,15 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return result;
}
/**
- * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name and type
+ * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
* @param componentId
* @param instanceId
* @param capabilityName
* @param capabilityType
+ * @param ownerId
* @return
*/
- public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType) {
+ public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
Map<String, MapCapabiltyProperty> mapPropertiesDataDefinition = null;
@@ -1098,21 +1189,26 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
}
if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
- result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
+ result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
}
- return result;
+ return result;
+ }
+
+ public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabiltyProperty instanceProperties) {
+ return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
}
+
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) {
+ private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
List<ComponentInstanceProperty> capPropsList = null;
for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
- if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, capProp)) {
+ if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, 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());
@@ -1126,16 +1222,48 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return capPropsList;
}
- private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, Entry<String, MapPropertiesDataDefinition> capProp) {
+ private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, 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 path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
}
return false;
}
+ public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
+ fillPolicyDefinition(componentV, policyDefinition, counter);
+ return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
+ }
+
+ public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
+ return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
+ }
+
+ public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
+ return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
+ }
+
+ public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
+ return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
+ }
+
+ private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
+ String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
+ policyDefinition.setName(policyName);
+ policyDefinition.setInvariantName(policyName);
+ policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
+ policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
+ policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
+ policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
+ }
+
+ public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
+ String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
+ return componentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
+ }
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java
index f34975b073..86415de635 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java
@@ -76,6 +76,8 @@ import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.thinkaurelius.titan.core.TitanVertex;
+
import fj.data.Either;
@org.springframework.stereotype.Component("tosca-element-lifecycle-operation")
@@ -223,29 +225,43 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
Either<GraphVertex, TitanOperationStatus> getToscaElementRes = null;
Iterator<Edge> nextVersionComponentIter = null;
ToscaElementOperation operation;
+ Vertex preVersionVertex = null;
try {
getToscaElementRes = titanDao.getVertexById(toscaElementId, JsonParseFlagEnum.ParseMetadata);
if (getToscaElementRes.isRight()) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, FAILED_TO_GET_VERTICES, toscaElementId);
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getToscaElementRes.right().value()));
}
- if (result == null && hasPreviousVersion(getToscaElementRes.left().value())) {
+ GraphVertex currVersionV = getToscaElementRes.left().value();
+ if (result == null && hasPreviousVersion(currVersionV)) {
// find previous version
- nextVersionComponentIter = getToscaElementRes.left().value().getVertex().edges(Direction.IN, EdgeLabelEnum.VERSION.name());
+ nextVersionComponentIter = currVersionV.getVertex().edges(Direction.IN, EdgeLabelEnum.VERSION.name());
if (nextVersionComponentIter == null || !nextVersionComponentIter.hasNext()) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch previous version of tosca element with name {}. ", getToscaElementRes.left().value().getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME).toString());
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch previous version of tosca element with name {}. ", currVersionV.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME).toString());
result = Either.right(StorageOperationStatus.NOT_FOUND);
}
if (result == null) {
- StorageOperationStatus updateOldResourceResult = updateOldToscaElementBeforeUndoCheckout(nextVersionComponentIter.next().outVertex());
+ preVersionVertex = nextVersionComponentIter.next().outVertex();
+ StorageOperationStatus updateOldResourceResult = updateOldToscaElementBeforeUndoCheckout(preVersionVertex);
if (updateOldResourceResult != StorageOperationStatus.OK) {
result = Either.right(updateOldResourceResult);
}
}
}
if (result == null) {
- operation = getToscaElementOperation(getToscaElementRes.left().value().getLabel());
- result = operation.deleteToscaElement(getToscaElementRes.left().value());
+ GraphVertex prevVersionV = null;
+ if (preVersionVertex != null) {
+ prevVersionV = new GraphVertex();
+ prevVersionV.setVertex((TitanVertex) preVersionVertex);
+ String uniqueIdPreVer = (String) titanDao.getProperty((TitanVertex) preVersionVertex, GraphPropertyEnum.UNIQUE_ID.getProperty());
+ prevVersionV.setUniqueId(uniqueIdPreVer);
+ }
+ StorageOperationStatus updateCatalogRes = updateEdgeToCatalogRoot(prevVersionV, currVersionV);
+ if (updateCatalogRes != StorageOperationStatus.OK) {
+ return Either.right(updateCatalogRes);
+ }
+ operation = getToscaElementOperation(currVersionV.getLabel());
+ result = operation.deleteToscaElement(currVersionV);
}
} catch (Exception e) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during undo checkout tosca element {}. {}", toscaElementId, e.getMessage());
@@ -539,11 +555,12 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
if (result == null) {
TitanOperationStatus createVersionEdgeStatus = titanDao.createEdge(toscaElement, certifiedToscaElement, EdgeLabelEnum.VERSION, new HashMap<>());
if (createVersionEdgeStatus != TitanOperationStatus.OK) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to create version edge from last element {} to new certified element {}. status=", toscaElement.getUniqueId(),certifiedToscaElement.getUniqueId(), createVersionEdgeStatus);
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to create version edge from last element {} to new certified element {}. status=", toscaElement.getUniqueId(), certifiedToscaElement.getUniqueId(),
+ createVersionEdgeStatus);
result = DaoStatusConverter.convertTitanStatusToStorageStatus(createVersionEdgeStatus);
}
}
- if(result == null){
+ if (result == null) {
while (certReqUserEdgeIter.hasNext()) {
Edge edge = certReqUserEdgeIter.next();
@@ -698,6 +715,14 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to set highest version of tosca element {} to [{}]. Status is {}", toscaElement.getUniqueId(), false, status);
result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
}
+ // remove previous certified version from the catalog
+ GraphVertex lastCertifiedV = new GraphVertex();
+ lastCertifiedV.setVertex((TitanVertex) lastCertifiedVertex);
+ lastCertifiedV.setUniqueId((String) titanDao.getProperty((TitanVertex) lastCertifiedVertex, GraphPropertyEnum.UNIQUE_ID.getProperty()));
+ StorageOperationStatus res = updateEdgeToCatalogRoot(null, lastCertifiedV);
+ if (res != StorageOperationStatus.OK) {
+ return res;
+ }
}
}
if (result == null) {
@@ -811,9 +836,9 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
Map<String, Object> propertiesToUpdate = new HashMap<>();
propertiesToUpdate.put(GraphPropertyEnum.IS_HIGHEST_VERSION.getProperty(), true);
- Map<String, Object> jsonMetadataMap = JsonParserUtils.parseToJson((String) previousVersionToscaElement.property(GraphPropertyEnum.METADATA.getProperty()).value());
+ Map<String, Object> jsonMetadataMap = JsonParserUtils.toMap((String) previousVersionToscaElement.property(GraphPropertyEnum.METADATA.getProperty()).value());
jsonMetadataMap.put(GraphPropertyEnum.IS_HIGHEST_VERSION.getProperty(), true);
- propertiesToUpdate.put(GraphPropertyEnum.METADATA.getProperty(), JsonParserUtils.jsonToString(jsonMetadataMap));
+ propertiesToUpdate.put(GraphPropertyEnum.METADATA.getProperty(), JsonParserUtils.toJson(jsonMetadataMap));
titanDao.setVertexProperties(previousVersionToscaElement, propertiesToUpdate);
@@ -832,6 +857,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
result = DaoStatusConverter.convertTitanStatusToStorageStatus(replaceRes);
}
}
+
}
} catch (Exception e) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during update previous tosca element {} before undo checkout. {} ", e.getMessage());
@@ -888,9 +914,9 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
// check if component with the next version doesn't exist.
Iterator<Edge> nextVersionComponentIter = toscaElementVertex.getVertex().edges(Direction.OUT, EdgeLabelEnum.VERSION.name());
if (nextVersionComponentIter != null && nextVersionComponentIter.hasNext()) {
- Vertex nextVersionVertex = nextVersionComponentIter.next().inVertex();
+ Vertex nextVersionVertex = nextVersionComponentIter.next().inVertex();
String fetchedVersion = (String) nextVersionVertex.property(GraphPropertyEnum.VERSION.getProperty()).value();
- String fetchedName = (String)nextVersionVertex.property(GraphPropertyEnum.NORMALIZED_NAME.getProperty()).value();
+ String fetchedName = (String) nextVersionVertex.property(GraphPropertyEnum.NORMALIZED_NAME.getProperty()).value();
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to checkout component {} with version {}. The component with name {} and version {} was fetched from graph as existing following version. ",
toscaElementVertex.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME).toString(), toscaElementVertex.getMetadataProperty(GraphPropertyEnum.VERSION).toString(), fetchedName, fetchedVersion);
result = Either.right(StorageOperationStatus.ENTITY_ALREADY_EXISTS);
@@ -912,16 +938,22 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
}
}
if (result == null) {
+ Boolean isHighest = (Boolean) toscaElementVertex.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION);
+ GraphVertex prevVersionInCatalog = (isHighest != null && isHighest) ? null : toscaElementVertex;
+ StorageOperationStatus updateCatalogRes = updateEdgeToCatalogRoot(clonedVertex, prevVersionInCatalog);
+ if (updateCatalogRes != StorageOperationStatus.OK) {
+ return Either.right(updateCatalogRes);
+ }
result = operation.getToscaElement(cloneResult.left().value().getUniqueId());
if (result.isRight()) {
return result;
}
-
ToscaElement toscaElement = result.left().value();
if (toscaElement.getToscaType() == ToscaElementTypeEnum.TopologyTemplate) {
result = handleFixTopologyTemplate(toscaElementVertex, result, operation, clonedVertex, toscaElement);
}
}
+
return result;
}
@@ -952,7 +984,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
collectInstanceInputAndGroups(instInputs, instGroups, instArtifactsMap, origCompMap, isAddInstGroup, vfInst, clonedVertex);
}
needUpdateComposition = needUpdateComposition || fixToscaComponentName(vfInst, origCompMap);
- if(needUpdateComposition){
+ if (needUpdateComposition) {
instancesMap.put(vfInst.getUniqueId(), vfInst);
}
}
@@ -1010,8 +1042,8 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
}
return result;
}
-
- //TODO remove after jsonModelMigration
+
+ // TODO remove after jsonModelMigration
public boolean resolveToscaComponentName(ComponentInstanceDataDefinition vfInst, Map<String, ToscaElement> origCompMap) {
return fixToscaComponentName(vfInst, origCompMap);
}
@@ -1026,7 +1058,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
Either<ToscaElement, StorageOperationStatus> origCompEither;
if (vfInst.getOriginType() == null || vfInst.getOriginType().name().equals(OriginTypeEnum.VF.name())) {
origCompEither = topologyTemplateOperation.getToscaElement(origCompUid);
- }else{
+ } else {
origCompEither = nodeTypeOperation.getToscaElement(origCompUid);
}
if (origCompEither.isRight()) {
@@ -1088,7 +1120,6 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "before create group instance. ");
List<GroupDataDefinition> filteredGroups = null;
-
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "check vf groups before filter. Size is {} ", filteredGroups == null ? 0 : filteredGroups.size());
if (origComp.getGroups() != null && !origComp.getGroups().isEmpty()) {
filteredGroups = origComp.getGroups().values().stream().filter(g -> g.getType().equals(VF_MODULE)).collect(Collectors.toList());
@@ -1097,39 +1128,38 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "check vf groups after filter. Size is {} ", filteredGroups == null ? 0 : filteredGroups.size());
if (CollectionUtils.isNotEmpty(filteredGroups)) {
MapArtifactDataDefinition instArifacts = null;
- if(!instArtifactsMap.containsKey(ciUid)){
-
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "istance artifacts not found ");
-
- Map<String, ArtifactDataDefinition> deploymentArtifacts = origComp.getDeploymentArtifacts();
-
-
- instArifacts = new MapArtifactDataDefinition(deploymentArtifacts);
- addToscaDataDeepElementsBlockToToscaElement(clonedVertex, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, instArifacts, ciUid);
-
- instArtifactsMap.put(ciUid, instArifacts);
-
- }else{
+ if (!instArtifactsMap.containsKey(ciUid)) {
+
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "istance artifacts not found ");
+
+ Map<String, ArtifactDataDefinition> deploymentArtifacts = origComp.getDeploymentArtifacts();
+
+ instArifacts = new MapArtifactDataDefinition(deploymentArtifacts);
+ addToscaDataDeepElementsBlockToToscaElement(clonedVertex, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, instArifacts, ciUid);
+
+ instArtifactsMap.put(ciUid, instArifacts);
+
+ } else {
instArifacts = instArtifactsMap.get(ciUid);
}
-
- if(instArifacts != null){
+
+ if (instArifacts != null) {
Map<String, ArtifactDataDefinition> instDeplArtifMap = instArifacts.getMapToscaDataDefinition();
-
+
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "check group dep artifacts. Size is {} ", instDeplArtifMap == null ? 0 : instDeplArtifMap.values().size());
Map<String, GroupInstanceDataDefinition> groupInstanceToCreate = new HashMap<>();
- for(GroupDataDefinition group:filteredGroups){
+ for (GroupDataDefinition group : filteredGroups) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "create new groupInstance {} ", group.getName());
GroupInstanceDataDefinition groupInstance = buildGroupInstanceDataDefinition(group, vfInst, instDeplArtifMap);
List<String> artifactsUid = new ArrayList<>();
List<String> artifactsId = new ArrayList<>();
for (ArtifactDataDefinition artifact : instDeplArtifMap.values()) {
- //CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "create new groupInstance {} ", artifact.getA);
+ // CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "create new groupInstance {} ", artifact.getA);
Optional<String> op = group.getArtifacts().stream().filter(p -> p.equals(artifact.getGeneratedFromId())).findAny();
if (op.isPresent()) {
artifactsUid.add(artifact.getArtifactUUID());
artifactsId.add(artifact.getUniqueId());
-
+
}
}
groupInstance.setGroupInstanceArtifacts(artifactsId);
@@ -1138,7 +1168,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
}
if (MapUtils.isNotEmpty(groupInstanceToCreate)) {
instGroups.put(vfInst.getUniqueId(), new MapGroupsDataDefinition(groupInstanceToCreate));
-
+
}
}
}
@@ -1195,6 +1225,10 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to clone tosca element {} for certification. Sattus is {}. ", toscaElementVertex.getUniqueId(), result.right().value());
} else {
clonedToscaElement = result.left().value();
+ StorageOperationStatus updateEdgeToCatalog = updateEdgeToCatalogRoot(clonedToscaElement, toscaElementVertex);
+ if (updateEdgeToCatalog != StorageOperationStatus.OK) {
+ return Either.right(updateEdgeToCatalog);
+ }
deleteResult = deleteAllPreviousNotCertifiedVersions(toscaElementVertex);
if (deleteResult.isRight()) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete all previous npt certified versions of tosca element {}. Status is {}. ", toscaElementVertex.getUniqueId(), deleteResult.right().value());
@@ -1229,6 +1263,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
}
+
}
if (result == null) {
result = Either.left(clonedToscaElement);
@@ -1436,13 +1471,12 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
return verticesToGetParameters;
}
-
private String getNextCertifiedVersion(String version) {
String[] versionParts = version.split(VERSION_DELIMETER_REGEXP);
Integer nextMajorVersion = Integer.parseInt(versionParts[0]) + 1;
return nextMajorVersion + VERSION_DELIMETER + "0";
}
-
+
private String getNextVersion(String currVersion) {
String[] versionParts = currVersion.split(VERSION_DELIMETER_REGEXP);
Integer minorVersion = Integer.parseInt(versionParts[1]) + 1;
@@ -1466,7 +1500,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
return false;
}
- public Either<ToscaElement,StorageOperationStatus> forceCerificationOfToscaElement(String toscaElementId, String modifierId, String ownerId, String currVersion) {
+ public Either<ToscaElement, StorageOperationStatus> forceCerificationOfToscaElement(String toscaElementId, String modifierId, String ownerId, String currVersion) {
Either<GraphVertex, StorageOperationStatus> resultUpdate = null;
Either<ToscaElement, StorageOperationStatus> result = null;
GraphVertex toscaElement = null;
@@ -1514,23 +1548,55 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
private StorageOperationStatus handleRelationsUponForceCertification(GraphVertex toscaElement, GraphVertex modifier, GraphVertex owner) {
- StorageOperationStatus result = null;
- TitanOperationStatus status = titanDao.replaceEdgeLabel(owner.getVertex(), toscaElement.getVertex(), EdgeLabelEnum.STATE, EdgeLabelEnum.LAST_STATE);
+ StorageOperationStatus result = null;
+ TitanOperationStatus status = titanDao.replaceEdgeLabel(owner.getVertex(), toscaElement.getVertex(), EdgeLabelEnum.STATE, EdgeLabelEnum.LAST_STATE);
+ if (status != TitanOperationStatus.OK) {
+ result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
+ }
+ if (result == null) {
+ Map<EdgePropertyEnum, Object> properties = new EnumMap<>(EdgePropertyEnum.class);
+ properties.put(EdgePropertyEnum.STATE, LifecycleStateEnum.CERTIFIED);
+ status = titanDao.createEdge(modifier, toscaElement, EdgeLabelEnum.STATE, properties);
if (status != TitanOperationStatus.OK) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "failed to create edge. Status is {}", status);
result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
}
- if (result == null) {
- Map<EdgePropertyEnum, Object> properties = new EnumMap<>(EdgePropertyEnum.class);
- properties.put(EdgePropertyEnum.STATE, LifecycleStateEnum.CERTIFIED);
- status = titanDao.createEdge(modifier, toscaElement, EdgeLabelEnum.STATE, properties);
- if (status != TitanOperationStatus.OK) {
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "failed to create edge. Status is {}", status);
- result = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
+ }
+ if (result == null) {
+ result = StorageOperationStatus.OK;
+ }
+ return result;
+ }
+
+ private StorageOperationStatus updateEdgeToCatalogRoot(GraphVertex newVersionV, GraphVertex prevVersionV) {
+ Either<GraphVertex, TitanOperationStatus> catalog = titanDao.getVertexByLabel(VertexTypeEnum.CATALOG_ROOT);
+ if (catalog.isRight()) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to fetch catalog vertex. error {}", catalog.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(catalog.right().value());
+ }
+ GraphVertex catalogV = catalog.left().value();
+ if (newVersionV != null) {
+ Boolean isAbstract = (Boolean) newVersionV.getMetadataProperty(GraphPropertyEnum.IS_ABSTRACT);
+ if (isAbstract == null || !isAbstract) {
+ // no new vertex, only delete previous
+ TitanOperationStatus result = titanDao.createEdge(catalogV, newVersionV, EdgeLabelEnum.CATALOG_ELEMENT, null);
+ if (result != TitanOperationStatus.OK) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to create edge from {} to catalog vertex. error {}", newVersionV.getUniqueId(), result);
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
}
}
- if (result == null) {
- result = StorageOperationStatus.OK;
+ }
+ if (prevVersionV != null) {
+ Boolean isAbstract = (Boolean) prevVersionV.getMetadataProperty(GraphPropertyEnum.IS_ABSTRACT);
+ if (isAbstract == null || !isAbstract) {
+ // if prev == null -> new resource was added
+ Either<Edge, TitanOperationStatus> deleteResult = titanDao.deleteEdge(catalogV, prevVersionV, EdgeLabelEnum.CATALOG_ELEMENT);
+ if (deleteResult.isRight()) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete edge from {} to catalog vertex. error {}", prevVersionV.getUniqueId(), deleteResult.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(deleteResult.right().value());
+ }
}
- return result;
+ }
+ return StorageOperationStatus.OK;
}
}
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 ec55ddaf3b..0cb71eeab3 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
@@ -33,12 +33,15 @@ 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;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.openecomp.sdc.be.config.ConfigurationManager;
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.EdgePropertyEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
@@ -50,6 +53,7 @@ import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.catalog.CatalogComponent;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
@@ -65,6 +69,7 @@ import org.openecomp.sdc.common.util.ValidationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StopWatch;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@@ -72,1143 +77,1244 @@ 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());
-
- private static final Gson gson = new Gson();
-
- protected Gson getGson() {
- return gson;
- }
-
- @Autowired
- protected CategoryOperation categoryOperation;
-
- protected Either<GraphVertex, StorageOperationStatus> getComponentByLabelAndId(String uniqueId, ToscaElementTypeEnum nodeType, JsonParseFlagEnum parseFlag) {
-
- Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<GraphPropertyEnum, Object>();
- propertiesToMatch.put(GraphPropertyEnum.UNIQUE_ID, uniqueId);
-
- VertexTypeEnum vertexType = ToscaElementTypeEnum.getVertexTypeByToscaType(nodeType);
- Either<List<GraphVertex>, TitanOperationStatus> getResponse = titanDao.getByCriteria(vertexType, propertiesToMatch, parseFlag);
- if (getResponse.isRight()) {
- log.debug("Couldn't fetch component with type {} and unique id {}, error: {}", vertexType, uniqueId, getResponse.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getResponse.right().value()));
-
- }
- List<GraphVertex> componentList = getResponse.left().value();
- if (componentList.isEmpty()) {
- log.debug("Component with type {} and unique id {} was not found", vertexType, uniqueId);
- return Either.right(StorageOperationStatus.NOT_FOUND);
- }
- GraphVertex vertexG = componentList.get(0);
- return Either.left(vertexG);
- }
-
- public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId) {
- return getToscaElement(uniqueId, new ComponentParametersView());
- }
-
- public Either<GraphVertex, StorageOperationStatus> markComponentToDelete(GraphVertex componentToDelete) {
- Either<GraphVertex, StorageOperationStatus> result = null;
-
- Boolean isDeleted = (Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
- if (isDeleted != null && isDeleted && !(Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION)) {
- // component already marked for delete
- result = Either.left(componentToDelete);
- return result;
- } else {
-
- componentToDelete.addMetadataProperty(GraphPropertyEnum.IS_DELETED, Boolean.TRUE);
- componentToDelete.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, System.currentTimeMillis());
-
- Either<GraphVertex, TitanOperationStatus> updateNode = titanDao.updateVertex(componentToDelete);
-
- StorageOperationStatus updateComponent;
- if (updateNode.isRight()) {
- log.debug("Failed to update component {}. status is {}", componentToDelete.getUniqueId(), updateNode.right().value());
- updateComponent = DaoStatusConverter.convertTitanStatusToStorageStatus(updateNode.right().value());
- result = Either.right(updateComponent);
- return result;
- }
-
- result = Either.left(componentToDelete);
- return result;
- }
- }
-
- /**
- * Performs a shadow clone of previousToscaElement
- *
- * @param previousToscaElement
- * @param nextToscaElement
- * @param user
- * @return
- */
- public Either<GraphVertex, StorageOperationStatus> cloneToscaElement(GraphVertex previousToscaElement, GraphVertex nextToscaElement, GraphVertex user) {
-
- Either<GraphVertex, StorageOperationStatus> result = null;
- GraphVertex createdToscaElementVertex = null;
- TitanOperationStatus status;
-
- Either<GraphVertex, TitanOperationStatus> createNextVersionRes = titanDao.createVertex(nextToscaElement);
- if (createNextVersionRes.isRight()) {
- status = createNextVersionRes.right().value();
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create tosca element vertex {} with version {} on graph. Status is {}. ", previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME),
- previousToscaElement.getMetadataProperty(GraphPropertyEnum.VERSION), status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- if (result == null) {
- createdToscaElementVertex = createNextVersionRes.left().value();
- Map<EdgePropertyEnum, Object> properties = new HashMap<EdgePropertyEnum, Object>();
- properties.put(EdgePropertyEnum.STATE, createdToscaElementVertex.getMetadataProperty(GraphPropertyEnum.STATE));
- status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.STATE, properties);
- if (status != TitanOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from user vertex {} to tosca element vertex {} on graph. Status is {}. ", EdgeLabelEnum.STATE, user.getUniqueId(),
- previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- }
- if (result == null) {
- status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>());
- if (status != TitanOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from user vertex {} to tosca element vertex {} on graph. Status is {}. ", EdgeLabelEnum.LAST_MODIFIER, user.getUniqueId(),
- nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- }
- if (result == null) {
- status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.CREATOR, new HashMap<>());
- if (status != TitanOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from user vertex {} to tosca element vertex {} on graph. Status is {}. ", EdgeLabelEnum.CREATOR, user.getUniqueId(),
- nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- }
- if (result == null) {
- Iterator<Edge> edgesToCopyIter = previousToscaElement.getVertex().edges(Direction.OUT);
- while (edgesToCopyIter.hasNext()) {
- Edge currEdge = edgesToCopyIter.next();
- Vertex currVertex = currEdge.inVertex();
- // if(EdgeLabelEnum.getEdgeLabelEnum(currEdge.label()).equals(EdgeLabelEnum.VERSION)){
- // continue;
- // }
- status = titanDao.createEdge(createdToscaElementVertex.getVertex(), currVertex, EdgeLabelEnum.getEdgeLabelEnum(currEdge.label()), currEdge);
- if (status != TitanOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from tosca element vertex {} to vertex with label {} on graph. Status is {}. ", currEdge.label(), createdToscaElementVertex.getUniqueId(),
- currVertex.property(GraphPropertyEnum.LABEL.getProperty()), status);
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- break;
- }
- }
- }
-
- if (result == null) {
- result = Either.left(createdToscaElementVertex);
- } else {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to clone tosca element {} with the name {}. ", previousToscaElement.getUniqueId(), previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME));
- }
- return result;
- }
-
- protected TitanOperationStatus setLastModifierFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
- Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(componentV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
- if (parentVertex.isRight()) {
- log.debug("Failed to fetch last modifier for tosca element with id {} error {}", componentV.getUniqueId(), parentVertex.right().value());
- return parentVertex.right().value();
- }
- GraphVertex userV = parentVertex.left().value();
- String userId = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
- toscaElement.setLastUpdaterUserId(userId);
- toscaElement.setLastUpdaterFullName(buildFullName(userV));
- return TitanOperationStatus.OK;
- }
-
- public String buildFullName(GraphVertex userV) {
-
- String fullName = (String) userV.getMetadataProperty(GraphPropertyEnum.FIRST_NAME);
- if (fullName == null) {
- fullName = "";
- } else {
- fullName = fullName + " ";
- }
- String lastName = (String) userV.getMetadataProperty(GraphPropertyEnum.LAST_NAME);
- if (lastName != null) {
- fullName += lastName;
- }
- return fullName;
- }
-
- protected TitanOperationStatus setCreatorFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
- Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(componentV, EdgeLabelEnum.CREATOR, JsonParseFlagEnum.NoParse);
- if (parentVertex.isRight()) {
- log.debug("Failed to fetch creator for tosca element with id {} error {}", componentV.getUniqueId(), parentVertex.right().value());
- return parentVertex.right().value();
- }
- GraphVertex userV = parentVertex.left().value();
- String creatorUserId = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
- toscaElement.setCreatorUserId(creatorUserId);
- toscaElement.setCreatorFullName(buildFullName(userV));
-
- return TitanOperationStatus.OK;
- }
-
- protected <T extends ToscaElement> T getResourceMetaDataFromResource(T toscaElement) {
- if (toscaElement.getNormalizedName() == null || toscaElement.getNormalizedName().isEmpty()) {
- toscaElement.setNormalizedName(ValidationUtils.normaliseComponentName(toscaElement.getName()));
- }
- if (toscaElement.getSystemName() == null || toscaElement.getSystemName().isEmpty()) {
- toscaElement.setSystemName(ValidationUtils.convertToSystemName(toscaElement.getName()));
- }
-
- LifecycleStateEnum lifecycleStateEnum = toscaElement.getLifecycleState();
- if (lifecycleStateEnum == null) {
- toscaElement.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- }
- long currentDate = System.currentTimeMillis();
- if (toscaElement.getCreationDate() == null) {
- toscaElement.setCreationDate(currentDate);
- }
- toscaElement.setLastUpdateDate(currentDate);
-
- return toscaElement;
- }
-
- protected void fillCommonMetadata(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
- if (toscaElement.isHighestVersion() == null) {
- toscaElement.setHighestVersion(true);
- }
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_DELETED, toscaElement.getMetadataValue(JsonPresentationFields.IS_DELETED));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION, toscaElement.getMetadataValueOrDefault(JsonPresentationFields.HIGHEST_VERSION, Boolean.TRUE));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.STATE, toscaElement.getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.RESOURCE_TYPE, toscaElement.getMetadataValue(JsonPresentationFields.RESOURCE_TYPE));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.VERSION, toscaElement.getMetadataValue(JsonPresentationFields.VERSION));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME, toscaElement.getMetadataValue(JsonPresentationFields.NORMALIZED_NAME));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, toscaElement.getMetadataValue(JsonPresentationFields.UNIQUE_ID));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaElement.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.UUID, toscaElement.getMetadataValue(JsonPresentationFields.UUID));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_ABSTRACT, toscaElement.getMetadataValue(JsonPresentationFields.IS_ABSTRACT));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.INVARIANT_UUID, toscaElement.getMetadataValue(JsonPresentationFields.INVARIANT_UUID));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.NAME, toscaElement.getMetadataValue(JsonPresentationFields.NAME));
- nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.SYSTEM_NAME, toscaElement.getMetadataValue(JsonPresentationFields.SYSTEM_NAME));
- toscaElement.getMetadata().entrySet().stream().filter(e -> e.getValue() != null).forEach(e -> nodeTypeVertex.setJsonMetadataField(JsonPresentationFields.getByPresentation(e.getKey()), e.getValue()));
-
- nodeTypeVertex.setUniqueId(toscaElement.getUniqueId());
- nodeTypeVertex.setType(toscaElement.getComponentType());
-
- }
-
- protected StorageOperationStatus assosiateToUsers(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
- // handle user
- String userId = toscaElement.getCreatorUserId();
-
- Either<GraphVertex, TitanOperationStatus> findUser = findUserVertex(userId);
-
- if (findUser.isRight()) {
- TitanOperationStatus status = findUser.right().value();
- log.error("Cannot find user {} in the graph. status is {}", userId, status);
- return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
-
- }
- GraphVertex creatorVertex = findUser.left().value();
- GraphVertex updaterVertex = creatorVertex;
- String updaterId = toscaElement.getLastUpdaterUserId();
- if (updaterId != null && !updaterId.equals(userId)) {
- findUser = findUserVertex(updaterId);
- if (findUser.isRight()) {
- TitanOperationStatus status = findUser.right().value();
- log.error("Cannot find user {} in the graph. status is {}", userId, status);
- return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
- } else {
- updaterVertex = findUser.left().value();
- }
- }
- Map<EdgePropertyEnum, Object> props = new HashMap<EdgePropertyEnum, Object>();
- props.put(EdgePropertyEnum.STATE, (String) toscaElement.getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
-
- TitanOperationStatus result = titanDao.createEdge(updaterVertex, nodeTypeVertex, EdgeLabelEnum.STATE, props);
- log.debug("After associating user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.STATE);
- if (TitanOperationStatus.OK != result) {
- return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
- }
- result = titanDao.createEdge(updaterVertex, nodeTypeVertex, EdgeLabelEnum.LAST_MODIFIER, null);
- log.debug("After associating user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.LAST_MODIFIER);
- if (!result.equals(TitanOperationStatus.OK)) {
- log.error("Failed to associate user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.LAST_MODIFIER);
- return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
- }
-
- toscaElement.setLastUpdaterUserId(toscaElement.getCreatorUserId());
- toscaElement.setLastUpdaterFullName(toscaElement.getCreatorFullName());
-
- result = titanDao.createEdge(creatorVertex, nodeTypeVertex, EdgeLabelEnum.CREATOR, null);
- log.debug("After associating user {} to resource {}. Edge type is {} ", creatorVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.CREATOR);
- if (!result.equals(TitanOperationStatus.OK)) {
- log.error("Failed to associate user {} to resource {}. Edge type is {} ", creatorVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.CREATOR);
- return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
- }
- return StorageOperationStatus.OK;
- }
-
- protected StorageOperationStatus assosiateResourceMetadataToCategory(GraphVertex nodeTypeVertex, ToscaElement nodeType) {
- String subcategoryName = nodeType.getCategories().get(0).getSubcategories().get(0).getName();
- String categoryName = nodeType.getCategories().get(0).getName();
- Either<GraphVertex, StorageOperationStatus> getCategoryVertex = getResourceCategoryVertex(nodeType.getUniqueId(), subcategoryName, categoryName);
-
- if (getCategoryVertex.isRight()) {
- return getCategoryVertex.right().value();
- }
-
- GraphVertex subCategoryV = getCategoryVertex.left().value();
-
- TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, subCategoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
- if (createEdge != TitanOperationStatus.OK) {
- log.trace("Failed to associate resource {} to category {} with id {}", nodeType.getUniqueId(), subcategoryName, subCategoryV.getUniqueId());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
- }
- return StorageOperationStatus.OK;
- }
-
- protected Either<GraphVertex, StorageOperationStatus> getResourceCategoryVertex(String elementId, String subcategoryName, String categoryName) {
- Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
- if (category.isRight()) {
- log.trace("Failed to fetch category {} for resource {} error {}", categoryName, elementId, category.right().value());
- return Either.right(category.right().value());
- }
- GraphVertex categoryV = category.left().value();
-
- if (subcategoryName != null) {
- Either<GraphVertex, StorageOperationStatus> subCategory = categoryOperation.getSubCategoryForCategory(categoryV, subcategoryName);
- if (subCategory.isRight()) {
- log.trace("Failed to fetch subcategory {} of category for resource {} error {}", subcategoryName, categoryName, elementId, subCategory.right().value());
- return Either.right(subCategory.right().value());
- }
-
- GraphVertex subCategoryV = subCategory.left().value();
- return Either.left(subCategoryV);
- }
- return Either.left(categoryV);
- }
-
- private StorageOperationStatus associateArtifactsToResource(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
- Map<String, ArtifactDataDefinition> artifacts = toscaElement.getArtifacts();
- Either<GraphVertex, StorageOperationStatus> status;
- if (artifacts != null) {
- artifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
- String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
- a.setUniqueId(uniqueId);
- });
- status = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.ARTIFACTS, EdgeLabelEnum.ARTIFACTS, artifacts);
- if (status.isRight()) {
- return status.right().value();
- }
- }
- Map<String, ArtifactDataDefinition> toscaArtifacts = toscaElement.getToscaArtifacts();
- if (toscaArtifacts != null) {
- toscaArtifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
- String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
- a.setUniqueId(uniqueId);
- });
- status = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.TOSCA_ARTIFACTS, EdgeLabelEnum.TOSCA_ARTIFACTS, toscaArtifacts);
- if (status.isRight()) {
- return status.right().value();
- }
- }
- Map<String, ArtifactDataDefinition> deploymentArtifacts = toscaElement.getDeploymentArtifacts();
- if (deploymentArtifacts != null) {
- deploymentArtifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
- String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
- a.setUniqueId(uniqueId);
- });
- status = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS, deploymentArtifacts);
- if (status.isRight()) {
- return status.right().value();
- }
- }
- return StorageOperationStatus.OK;
- }
-
- protected TitanOperationStatus disassociateAndDeleteCommonElements(GraphVertex toscaElementVertex) {
- TitanOperationStatus status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ARTIFACTS);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disaccociate artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
- return status;
- }
- status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.TOSCA_ARTIFACTS);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disaccociate tosca artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
- return status;
- }
- status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to deployment artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
- return status;
- }
- status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.PROPERTIES);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disaccociate properties for {} error {}", toscaElementVertex.getUniqueId(), status);
- return status;
- }
- status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ATTRIBUTES);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disaccociate attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
- return status;
- }
- status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ADDITIONAL_INFORMATION);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disaccociate additional information for {} error {}", toscaElementVertex.getUniqueId(), status);
- return status;
- }
- status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disaccociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
- return status;
- }
- status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.REQUIREMENTS);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disaccociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
- return status;
- }
- return TitanOperationStatus.OK;
- }
-
- protected StorageOperationStatus assosiateCommonForToscaElement(GraphVertex nodeTypeVertex, ToscaElement toscaElement, List<GraphVertex> derivedResources) {
-
- StorageOperationStatus associateUsers = assosiateToUsers(nodeTypeVertex, toscaElement);
- if (associateUsers != StorageOperationStatus.OK) {
- return associateUsers;
- }
- StorageOperationStatus associateArtifacts = associateArtifactsToResource(nodeTypeVertex, toscaElement);
- if (associateArtifacts != StorageOperationStatus.OK) {
- return associateArtifacts;
- }
- StorageOperationStatus associateProperties = associatePropertiesToResource(nodeTypeVertex, toscaElement, derivedResources);
- if (associateProperties != StorageOperationStatus.OK) {
- return associateProperties;
- }
- StorageOperationStatus associateAdditionaInfo = associateAdditionalInfoToResource(nodeTypeVertex, toscaElement);
- if (associateAdditionaInfo != StorageOperationStatus.OK) {
- return associateAdditionaInfo;
- }
-
- return StorageOperationStatus.OK;
- }
-
- protected StorageOperationStatus associatePropertiesToResource(GraphVertex nodeTypeVertex, ToscaElement nodeType, List<GraphVertex> derivedResources) {
- // Note : currently only one derived supported!!!!
- Either<Map<String, PropertyDataDefinition>, StorageOperationStatus> dataFromDerived = getDataFromDerived(derivedResources, EdgeLabelEnum.PROPERTIES);
- if (dataFromDerived.isRight()) {
- return dataFromDerived.right().value();
- }
- Map<String, PropertyDataDefinition> propertiesAll = dataFromDerived.left().value();
-
- Map<String, PropertyDataDefinition> properties = nodeType.getProperties();
-
- if (properties != null) {
- properties.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
- String uid = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId(), p.getName());
- p.setUniqueId(uid);
- });
-
- Either<Map<String, PropertyDataDefinition>, String> eitherMerged = ToscaDataDefinition.mergeDataMaps(propertiesAll, properties);
- if (eitherMerged.isRight()) {
- // TODO re-factor error handling - moving BL to operation resulted in loss of info about the invalid property
- log.debug("property {} cannot be overriden", eitherMerged.right().value());
- return StorageOperationStatus.INVALID_PROPERTY;
- }
- }
- if (!propertiesAll.isEmpty()) {
- Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.PROPERTIES, EdgeLabelEnum.PROPERTIES, propertiesAll);
- if (assosiateElementToData.isRight()) {
- return assosiateElementToData.right().value();
- }
- }
- return StorageOperationStatus.OK;
- }
-
- private StorageOperationStatus associateAdditionalInfoToResource(GraphVertex nodeTypeVertex, ToscaElement nodeType) {
- Map<String, AdditionalInfoParameterDataDefinition> additionalInformation = nodeType.getAdditionalInformation();
- if (additionalInformation != null) {
- Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, additionalInformation);
- if (assosiateElementToData.isRight()) {
- return assosiateElementToData.right().value();
- }
- }
- return StorageOperationStatus.OK;
- }
-
- protected <T extends ToscaDataDefinition> Either<Map<String, T>, StorageOperationStatus> getDataFromDerived(List<GraphVertex> derivedResources, EdgeLabelEnum edge) {
- Map<String, T> propertiesAll = new HashMap<>();
-
- if (derivedResources != null && !derivedResources.isEmpty()) {
- for (GraphVertex derived : derivedResources) {
- Either<List<GraphVertex>, TitanOperationStatus> derivedProperties = titanDao.getChildrenVertecies(derived, edge, JsonParseFlagEnum.ParseJson);
- if (derivedProperties.isRight()) {
- if (derivedProperties.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Failed to get properties for derived from {} error {}", derived.getUniqueId(), derivedProperties.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(derivedProperties.right().value()));
- } else {
- continue;
- }
- }
- List<GraphVertex> propList = derivedProperties.left().value();
- for (GraphVertex propV : propList) {
- Map<String, T> propertiesFromDerived = (Map<String, T>) propV.getJson();
- if (propertiesFromDerived != null) {
- propertiesFromDerived.entrySet().forEach(x -> x.getValue().setOwnerIdIfEmpty(derived.getUniqueId()));
- propertiesAll.putAll(propertiesFromDerived);
- }
- }
- }
- }
- return Either.left(propertiesAll);
- }
-
- protected TitanOperationStatus setArtifactsFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
- Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.ARTIFACTS);
- if (result.isLeft()) {
- toscaElement.setArtifacts(result.left().value());
- } else {
- if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
- return result.right().value();
- }
- }
- result = getDataFromGraph(componentV, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
- if (result.isLeft()) {
- toscaElement.setDeploymentArtifacts(result.left().value());
- } else {
- if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
- return result.right().value();
- }
- }
- result = getDataFromGraph(componentV, EdgeLabelEnum.TOSCA_ARTIFACTS);
- if (result.isLeft()) {
- toscaElement.setToscaArtifacts(result.left().value());
- } else {
- if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
- return result.right().value();
- }
- }
- return TitanOperationStatus.OK;
- }
-
- protected TitanOperationStatus setAllVersions(GraphVertex componentV, ToscaElement toscaElement) {
- Map<String, String> allVersion = new HashMap<>();
-
- allVersion.put((String) componentV.getMetadataProperty(GraphPropertyEnum.VERSION), componentV.getUniqueId());
- ArrayList<GraphVertex> allChildrenAndParants = new ArrayList<GraphVertex>();
- Either<GraphVertex, TitanOperationStatus> childResourceRes = titanDao.getChildVertex(componentV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
- while (childResourceRes.isLeft()) {
- GraphVertex child = childResourceRes.left().value();
- allChildrenAndParants.add(child);
- childResourceRes = titanDao.getChildVertex(child, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
- }
- TitanOperationStatus operationStatus = childResourceRes.right().value();
-
- if (operationStatus != TitanOperationStatus.NOT_FOUND) {
- return operationStatus;
- } else {
- Either<GraphVertex, TitanOperationStatus> parentResourceRes = titanDao.getParentVertex(componentV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
- while (parentResourceRes.isLeft()) {
- GraphVertex parent = parentResourceRes.left().value();
- allChildrenAndParants.add(parent);
- parentResourceRes = titanDao.getParentVertex(parent, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
- }
- operationStatus = parentResourceRes.right().value();
- if (operationStatus != TitanOperationStatus.NOT_FOUND) {
- return operationStatus;
- } else {
- allChildrenAndParants.stream().filter(vertex -> {
- Boolean isDeleted = (Boolean) vertex.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
- return (isDeleted == null || isDeleted == false);
- }).forEach(vertex -> allVersion.put((String) vertex.getMetadataProperty(GraphPropertyEnum.VERSION), vertex.getUniqueId()));
-
- toscaElement.setAllVersions(allVersion);
- return TitanOperationStatus.OK;
- }
- }
- }
-
- protected <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getFollowedComponent(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates, ComponentTypeEnum neededType) {
-
- Either<List<T>, StorageOperationStatus> result = null;
-
- Map<GraphPropertyEnum, Object> props = null;
-
- if (userId != null) {
- props = new HashMap<>();
- // for Designer retrieve specific user
- props.put(GraphPropertyEnum.USERID, userId);
- }
- // in case of user id == null -> get all users by label
- // for Tester and Admin retrieve all users
- Either<List<GraphVertex>, TitanOperationStatus> usersByCriteria = titanDao.getByCriteria(VertexTypeEnum.USER, props, JsonParseFlagEnum.NoParse);
- if (usersByCriteria.isRight()) {
- log.debug("Failed to fetch users by criteria {} error {}", props, usersByCriteria.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(usersByCriteria.right().value()));
- }
- List<GraphVertex> users = usersByCriteria.left().value();
-
- List<T> components = new ArrayList<>();
- List<T> componentsPerUser;
- for (GraphVertex userV : users) {
-
- HashSet<String> ids = new HashSet<String>();
- Either<List<GraphVertex>, TitanOperationStatus> childrenVertecies = titanDao.getChildrenVertecies(userV, EdgeLabelEnum.STATE, JsonParseFlagEnum.NoParse);
- if (childrenVertecies.isRight() && childrenVertecies.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.STATE, childrenVertecies.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childrenVertecies.right().value()));
- }
-
- // get all resource with current state
- if (childrenVertecies.isLeft()) {
- componentsPerUser = fetchComponents(lifecycleStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.STATE);
-
- if (componentsPerUser != null) {
- for (T comp : componentsPerUser) {
- ids.add(comp.getUniqueId());
- components.add(comp);
- }
- }
- }
- if (lastStateStates != null && !lastStateStates.isEmpty()) {
- // get all resource with last state
- childrenVertecies = titanDao.getChildrenVertecies(userV, EdgeLabelEnum.LAST_STATE, JsonParseFlagEnum.NoParse);
- if (childrenVertecies.isRight() && childrenVertecies.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.LAST_STATE, childrenVertecies.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childrenVertecies.right().value()));
- }
- if (childrenVertecies.isLeft()) {
- boolean isFirst;
- componentsPerUser = fetchComponents(lastStateStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.LAST_STATE);
- if (componentsPerUser != null) {
- for (T comp : componentsPerUser) {
- isFirst = true;
-
- if (ids.contains(comp.getUniqueId())) {
- isFirst = false;
- }
- if (isFirst == true) {
- components.add(comp);
- }
-
- }
- }
- }
- }
-
- } // whlile users
- ;
- result = Either.left(components);
- return result;
-
- }
-
- private <T extends ToscaElement> List<T> fetchComponents(Set<LifecycleStateEnum> lifecycleStates, List<GraphVertex> vertices, ComponentTypeEnum neededType, EdgeLabelEnum edgelabel) {
- List<T> components = new ArrayList<>();
- for (GraphVertex node : vertices) {
-
- Iterator<Edge> edges = node.getVertex().edges(Direction.IN, edgelabel.name());
- while (edges.hasNext()) {
- Edge edge = edges.next();
- String stateStr = (String) titanDao.getProperty(edge, EdgePropertyEnum.STATE);
-
- LifecycleStateEnum nodeState = LifecycleStateEnum.findState(stateStr);
- if (nodeState == null) {
- log.debug("no supported STATE {} for element {}", stateStr, node.getUniqueId());
- continue;
- }
- if (lifecycleStates != null && lifecycleStates.contains(nodeState)) {
-
- Boolean isDeleted = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
- if (isDeleted != null && isDeleted) {
- log.trace("Deleted element {}, discard", node.getUniqueId());
- continue;
- }
-
- Boolean isHighest = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION);
- if (isHighest) {
-
- ComponentTypeEnum componentType = node.getType();
- // get only latest versions
-
- if (componentType == null) {
- log.debug("No supported type {} for vertex {}", componentType, node.getUniqueId());
- continue;
- }
- if (neededType == componentType) {
- switch (componentType) {
- case SERVICE:
- case PRODUCT:
- handleNode(components, node, componentType);
- break;
- case RESOURCE:
- Boolean isAbtract = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_ABSTRACT);
- if (isAbtract == null || false == isAbtract) {
- handleNode(components, node, componentType);
- } // if not abstract
- break;
- default:
- log.debug("not supported node type {}", componentType);
- break;
- }// case
- } // needed type
- }
- } // if
- } // while edges
- } // while resources
- return components;
- }
-
- protected <T extends ToscaElement> void handleNode(List<T> components, GraphVertex vertexComponent, ComponentTypeEnum nodeType) {
-
- Either<T, StorageOperationStatus> component = getLightComponent(vertexComponent, nodeType, new ComponentParametersView(true));
- if (component.isRight()) {
- log.debug("Failed to get component for id = {} error : {} skip resource", vertexComponent.getUniqueId(), component.right().value());
- } else {
- components.add(component.left().value());
- }
- }
-
- protected <T extends ToscaElement> Either<T, StorageOperationStatus> getLightComponent(String componentUid, ComponentTypeEnum nodeType, ComponentParametersView parametersFilter) {
- Either<GraphVertex, TitanOperationStatus> getVertexRes = titanDao.getVertexById(componentUid);
- if (getVertexRes.isRight()) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexRes.right().value()));
- }
- return getLightComponent(getVertexRes.left().value(), nodeType, parametersFilter);
- }
-
- protected <T extends ToscaElement> Either<T, StorageOperationStatus> getLightComponent(GraphVertex vertexComponent, ComponentTypeEnum nodeType, ComponentParametersView parametersFilter) {
-
- log.trace("Starting to build light component of type {}, id {}", nodeType, vertexComponent.getUniqueId());
-
- titanDao.parseVertexProperties(vertexComponent, JsonParseFlagEnum.ParseMetadata);
-
- T toscaElement = convertToComponent(vertexComponent);
-
- TitanOperationStatus status = setCreatorFromGraph(vertexComponent, toscaElement);
- if (status != TitanOperationStatus.OK) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
-
- status = setLastModifierFromGraph(vertexComponent, toscaElement);
- if (status != TitanOperationStatus.OK) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- status = setCategoriesFromGraph(vertexComponent, toscaElement);
- if (status != TitanOperationStatus.OK) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- if (!parametersFilter.isIgnoreAllVersions()) {
- status = setAllVersions(vertexComponent, toscaElement);
- if (status != TitanOperationStatus.OK) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- }
- if (!parametersFilter.isIgnoreCapabilities()) {
- status = setCapabilitiesFromGraph(vertexComponent, toscaElement);
- if (status != TitanOperationStatus.OK) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- }
- if (!parametersFilter.isIgnoreRequirements()) {
- status = setRequirementsFromGraph(vertexComponent, toscaElement);
- if (status != TitanOperationStatus.OK) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- }
- log.debug("Ended to build light component of type {}, id {}", nodeType, vertexComponent.getUniqueId());
- return Either.left(toscaElement);
- }
-
- @SuppressWarnings("unchecked")
- protected <T extends ToscaElement> T convertToComponent(GraphVertex componentV) {
- ToscaElement toscaElement = null;
- VertexTypeEnum label = componentV.getLabel();
- switch (label) {
- case NODE_TYPE:
- toscaElement = new NodeType();
- break;
- case TOPOLOGY_TEMPLATE:
- toscaElement = new TopologyTemplate();
- break;
- default:
- log.debug("Not supported tosca type {}", label);
- break;
- }
-
- Map<String, Object> jsonMetada = componentV.getMetadataJson();
- if (toscaElement != null) {
- toscaElement.setMetadata(jsonMetada);
- }
- return (T) toscaElement;
- }
-
- protected TitanOperationStatus setResourceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
- List<CategoryDefinition> categories = new ArrayList<>();
- SubCategoryDefinition subcategory;
-
- Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
- if (childVertex.isRight()) {
- log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
- return childVertex.right().value();
- }
- GraphVertex subCategoryV = childVertex.left().value();
- Map<GraphPropertyEnum, Object> metadataProperties = subCategoryV.getMetadataProperties();
- subcategory = new SubCategoryDefinition();
- subcategory.setUniqueId(subCategoryV.getUniqueId());
- subcategory.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
- subcategory.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
-
- Type listTypeSubcat = new TypeToken<List<String>>() {
- }.getType();
- List<String> iconsfromJsonSubcat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS), listTypeSubcat);
- subcategory.setIcons(iconsfromJsonSubcat);
-
- Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
- if (parentVertex.isRight()) {
- log.debug("failed to fetch {} for category with id {}, error {}", EdgeLabelEnum.SUB_CATEGORY, subCategoryV.getUniqueId(), parentVertex.right().value());
- return childVertex.right().value();
- }
- GraphVertex categoryV = parentVertex.left().value();
- metadataProperties = categoryV.getMetadataProperties();
-
- CategoryDefinition category = new CategoryDefinition();
- category.setUniqueId(categoryV.getUniqueId());
- category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
- category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
-
- Type listTypeCat = new TypeToken<List<String>>() {
- }.getType();
- List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS), listTypeCat);
- category.setIcons(iconsfromJsonCat);
-
- category.addSubCategory(subcategory);
- categories.add(category);
- toscaElement.setCategories(categories);
-
- return TitanOperationStatus.OK;
- }
-
- public <T extends ToscaElement> Either<T, StorageOperationStatus> updateToscaElement(T toscaElementToUpdate, GraphVertex elementV, ComponentParametersView filterResult) {
- Either<T, StorageOperationStatus> result = null;
-
- log.debug("In updateToscaElement. received component uid = {}", (toscaElementToUpdate == null ? null : toscaElementToUpdate.getUniqueId()));
- if (toscaElementToUpdate == null) {
- log.error("Service object is null");
- result = Either.right(StorageOperationStatus.BAD_REQUEST);
- return result;
- }
-
- String modifierUserId = toscaElementToUpdate.getLastUpdaterUserId();
- if (modifierUserId == null || modifierUserId.isEmpty()) {
- log.error("UserId is missing in the request.");
- result = Either.right(StorageOperationStatus.BAD_REQUEST);
- return result;
- }
- Either<GraphVertex, TitanOperationStatus> findUser = findUserVertex(modifierUserId);
-
- if (findUser.isRight()) {
- TitanOperationStatus status = findUser.right().value();
- log.error("Cannot find user {} in the graph. status is {}", modifierUserId, status);
- return result;
- }
-
- GraphVertex modifierV = findUser.left().value();
- // UserData modifierUserData = findUser.left().value();
- String toscaElementId = toscaElementToUpdate.getUniqueId();
-
- Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(elementV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
- if (parentVertex.isRight()) {
- log.debug("Failed to fetch last modifier for tosca element with id {} error {}", toscaElementId, parentVertex.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(parentVertex.right().value()));
- }
- GraphVertex userV = parentVertex.left().value();
- String currentModifier = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
-
- String prevSystemName = (String) elementV.getMetadataProperty(GraphPropertyEnum.SYSTEM_NAME);
-
- if (currentModifier.equals(modifierUserId)) {
- log.debug("Graph LAST MODIFIER edge should not be changed since the modifier is the same as the last modifier.");
- } else {
- log.debug("Going to update the last modifier user of the resource from {} to {}", currentModifier, modifierUserId);
- StorageOperationStatus status = moveLastModifierEdge(elementV, modifierV);
- log.debug("Finish to update the last modifier user of the resource from {} to {}. status is {}", currentModifier, modifierUserId, status);
- if (status != StorageOperationStatus.OK) {
- result = Either.right(status);
- return result;
- }
- }
-
- final long currentTimeMillis = System.currentTimeMillis();
- log.debug("Going to update the last Update Date of the resource from {} to {}", elementV.getJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE), currentTimeMillis);
- elementV.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, currentTimeMillis);
-
- StorageOperationStatus checkCategories = validateCategories(toscaElementToUpdate, elementV);
- if (checkCategories != StorageOperationStatus.OK) {
- result = Either.right(checkCategories);
- return result;
- }
-
- // update all data on vertex
- fillToscaElementVertexData(elementV, toscaElementToUpdate, JsonParseFlagEnum.ParseMetadata);
-
- Either<GraphVertex, TitanOperationStatus> updateElement = titanDao.updateVertex(elementV);
-
- if (updateElement.isRight()) {
- log.error("Failed to update resource {}. status is {}", toscaElementId, updateElement.right().value());
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateElement.right().value()));
- return result;
- }
- GraphVertex updateElementV = updateElement.left().value();
-
- // DE230195 in case resource name changed update TOSCA artifacts
- // file names accordingly
- String newSystemName = (String) updateElementV.getMetadataProperty(GraphPropertyEnum.SYSTEM_NAME);
- if (newSystemName != null && !newSystemName.equals(prevSystemName)) {
- Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> resultToscaArt = getDataFromGraph(updateElementV, EdgeLabelEnum.TOSCA_ARTIFACTS);
- if (resultToscaArt.isRight()) {
- log.debug("Failed to get tosca artifact from graph for tosca element {} error {}", toscaElementId, resultToscaArt.right().value());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resultToscaArt.right().value()));
- }
-
- Map<String, ArtifactDataDefinition> toscaArtifacts = resultToscaArt.left().value();
- if (toscaArtifacts != null) {
- for (Entry<String, ArtifactDataDefinition> artifact : toscaArtifacts.entrySet()) {
- generateNewToscaFileName(toscaElementToUpdate.getComponentType().getValue().toLowerCase(), newSystemName, artifact.getValue());
- }
- // TODO call to new Artifact operation in order to update list of artifacts
-
- }
- // US833308 VLI in service - specific network_role property value logic
- if (ComponentTypeEnum.SERVICE == toscaElementToUpdate.getComponentType()) {
- // update method logs success/error and returns boolean (true if nothing fails)
- // TODO!!!!
- // updateServiceNameInVLIsNetworkRolePropertyValues(component, prevSystemName, newSystemName);
- }
- }
-
- if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.RESOURCE) {
- StorageOperationStatus resultDerived = updateDerived(toscaElementToUpdate, updateElementV);
- if (resultDerived != StorageOperationStatus.OK) {
- log.debug("Failed to update from derived data for element {} error {}", toscaElementId, resultDerived);
- return Either.right(resultDerived);
- }
- }
-
- Either<T, StorageOperationStatus> updatedResource = getToscaElement(updateElementV, filterResult);
- if (updatedResource.isRight()) {
- log.error("Failed to fetch tosca element {} after update , error {}", toscaElementId, updatedResource.right().value());
- result = Either.right(StorageOperationStatus.BAD_REQUEST);
- return result;
- }
-
- T updatedResourceValue = updatedResource.left().value();
- result = Either.left(updatedResourceValue);
-
- return result;
- }
-
- protected StorageOperationStatus moveLastModifierEdge(GraphVertex elementV, GraphVertex modifierV) {
- return DaoStatusConverter.convertTitanStatusToStorageStatus(titanDao.moveEdge(elementV, modifierV, EdgeLabelEnum.LAST_MODIFIER, Direction.IN));
- }
-
- protected StorageOperationStatus moveCategoryEdge(GraphVertex elementV, GraphVertex categoryV) {
- return DaoStatusConverter.convertTitanStatusToStorageStatus(titanDao.moveEdge(elementV, categoryV, EdgeLabelEnum.CATEGORY, Direction.OUT));
- }
-
- private void generateNewToscaFileName(String componentType, String componentName, ArtifactDataDefinition artifactInfo) {
- Map<String, Object> getConfig = (Map<String, Object>) ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts().entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel()))
- .findAny().get().getValue();
- artifactInfo.setArtifactName(componentType + "-" + componentName + getConfig.get("artifactName"));
- }
-
- protected <T extends ToscaElement> StorageOperationStatus validateResourceCategory(T toscaElementToUpdate, GraphVertex elementV) {
- StorageOperationStatus status = StorageOperationStatus.OK;
- List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
- CategoryDefinition newCategory = newCategoryList.get(0);
-
- Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
- if (childVertex.isRight()) {
- log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
- }
- GraphVertex subCategoryV = childVertex.left().value();
- Map<GraphPropertyEnum, Object> metadataProperties = subCategoryV.getMetadataProperties();
- String subCategoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
-
- Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
- if (parentVertex.isRight()) {
- log.debug("failed to fetch {} for category with id {}, error {}", EdgeLabelEnum.SUB_CATEGORY, subCategoryV.getUniqueId(), parentVertex.right().value());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
- }
- GraphVertex categoryV = parentVertex.left().value();
- metadataProperties = categoryV.getMetadataProperties();
- String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
-
- boolean categoryWasChanged = false;
-
- String newCategoryName = newCategory.getName();
- SubCategoryDefinition newSubcategory = newCategory.getSubcategories().get(0);
- String newSubCategoryName = newSubcategory.getName();
- if (newCategoryName != null && false == newCategoryName.equals(categoryNameCurrent)) {
- // the category was changed
- categoryWasChanged = true;
- } else {
- // the sub-category was changed
- if (newSubCategoryName != null && false == newSubCategoryName.equals(subCategoryNameCurrent)) {
- log.debug("Going to update the category of the resource from {} to {}", categoryNameCurrent, newCategory);
- categoryWasChanged = true;
- }
- }
- if (categoryWasChanged) {
- Either<GraphVertex, StorageOperationStatus> getCategoryVertex = getResourceCategoryVertex(elementV.getUniqueId(), newSubCategoryName, newCategoryName);
-
- if (getCategoryVertex.isRight()) {
- return getCategoryVertex.right().value();
- }
- GraphVertex newCategoryV = getCategoryVertex.left().value();
- status = moveCategoryEdge(elementV, newCategoryV);
- log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
- }
- return status;
- }
-
- public <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getElementCatalogData(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes, boolean isHighestVersions) {
- Either<List<GraphVertex>, TitanOperationStatus> listOfComponents;
- if (isHighestVersions) {
- listOfComponents = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.NoParse);
- }
- else {
- listOfComponents = getListOfHighestAndAllCertifiedComponents(componentType, excludeTypes);
- }
-
- if (listOfComponents.isRight() && listOfComponents.right().value() != TitanOperationStatus.NOT_FOUND) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(listOfComponents.right().value()));
- }
- List<T> result = new ArrayList<>();
- if (listOfComponents.isLeft()) {
- List<GraphVertex> highestAndAllCertified = listOfComponents.left().value();
- if (highestAndAllCertified != null && false == highestAndAllCertified.isEmpty()) {
- for (GraphVertex vertexComponent : highestAndAllCertified) {
- Either<T, StorageOperationStatus> component = getLightComponent(vertexComponent, componentType, new ComponentParametersView(true));
- if (component.isRight()) {
- log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), component.right().value());
- return Either.right(component.right().value());
- } else {
- result.add(component.left().value());
- }
- }
- }
- }
- return Either.left(result);
- }
-
- private Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes, JsonParseFlagEnum parseFlag) {
- Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<>();
- Map<GraphPropertyEnum, Object> propertiesHasNotToMatch = new HashMap<>();
- propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
- propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
-
- if (componentType == ComponentTypeEnum.RESOURCE) {
- propertiesToMatch.put(GraphPropertyEnum.IS_ABSTRACT, false);
- propertiesHasNotToMatch.put(GraphPropertyEnum.RESOURCE_TYPE, excludeTypes);
- }
- propertiesHasNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
-
- return titanDao.getByCriteria(null, propertiesToMatch, propertiesHasNotToMatch, parseFlag);
- }
-
- // highest + (certified && !highest)
- public Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestAndAllCertifiedComponents(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes) {
- long startFetchAllStates = System.currentTimeMillis();
- Either<List<GraphVertex>, TitanOperationStatus> highestNodes = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.ParseMetadata);
-
- Map<GraphPropertyEnum, Object> propertiesToMatchCertified = new HashMap<>();
- Map<GraphPropertyEnum, Object> propertiesHasNotToMatchCertified = new HashMap<>();
- propertiesToMatchCertified.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- propertiesToMatchCertified.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
- if (componentType == ComponentTypeEnum.RESOURCE) {
- propertiesToMatchCertified.put(GraphPropertyEnum.IS_ABSTRACT, false);
- propertiesHasNotToMatchCertified.put(GraphPropertyEnum.RESOURCE_TYPE, excludeTypes);
- }
-
- propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_DELETED, true);
- propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
-
- Either<List<GraphVertex>, TitanOperationStatus> certifiedNotHighestNodes = titanDao.getByCriteria(null, propertiesToMatchCertified, propertiesHasNotToMatchCertified,
- JsonParseFlagEnum.ParseMetadata);
- if (certifiedNotHighestNodes.isRight() && certifiedNotHighestNodes.right().value() != TitanOperationStatus.NOT_FOUND) {
- return Either.right(certifiedNotHighestNodes.right().value());
- }
-
- long endFetchAllStates = System.currentTimeMillis();
-
- List<GraphVertex> allNodes = new ArrayList<>();
-
- if (certifiedNotHighestNodes.isLeft()) {
- allNodes.addAll(certifiedNotHighestNodes.left().value());
- }
- if (highestNodes.isLeft()) {
- allNodes.addAll(highestNodes.left().value());
- }
-
- log.debug("Fetch catalog {}s all states from graph took {} ms", componentType, endFetchAllStates - startFetchAllStates);
- return Either.left(allNodes);
- }
-
- protected Either<List<GraphVertex>, StorageOperationStatus> getAllComponentsMarkedForDeletion(ComponentTypeEnum componentType) {
-
- // get all components marked for delete
- Map<GraphPropertyEnum, Object> props = new HashMap<GraphPropertyEnum, Object>();
- props.put(GraphPropertyEnum.IS_DELETED, true);
- props.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
-
- Either<List<GraphVertex>, TitanOperationStatus> componentsToDelete = titanDao.getByCriteria(null, props, JsonParseFlagEnum.NoParse);
-
- if (componentsToDelete.isRight()) {
- TitanOperationStatus error = componentsToDelete.right().value();
- if (error.equals(TitanOperationStatus.NOT_FOUND)) {
- log.trace("no components to delete");
- return Either.left(new ArrayList<>());
- } else {
- log.info("failed to find components to delete. error : {}", error.name());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(error));
- }
- }
- return Either.left(componentsToDelete.left().value());
- }
-
- protected TitanOperationStatus setAdditionalInformationFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
- Either<Map<String, AdditionalInfoParameterDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.ADDITIONAL_INFORMATION);
- if (result.isLeft()) {
- toscaElement.setAdditionalInformation(result.left().value());
- } else {
- if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
- return result.right().value();
- }
- }
- return TitanOperationStatus.OK;
- }
-
- // --------------------------------------------
- public abstract <T extends ToscaElement> Either<T, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView);
-
- public abstract <T extends ToscaElement> Either<T, StorageOperationStatus> getToscaElement(GraphVertex toscaElementVertex, ComponentParametersView componentParametersView);
-
- public abstract <T extends ToscaElement> Either<T, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex);
-
- public abstract <T extends ToscaElement> Either<T, StorageOperationStatus> createToscaElement(ToscaElement toscaElement);
-
- protected abstract <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement);
-
- protected abstract <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement);
-
- protected abstract <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement);
-
- protected abstract <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV);
-
- protected abstract <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV);
+ private static Logger log = LoggerFactory.getLogger(ToscaElementOperation.class.getName());
+
+ private static final Gson gson = new Gson();
+
+ protected Gson getGson() {
+ return gson;
+ }
+
+ @Autowired
+ protected CategoryOperation categoryOperation;
+
+ protected Either<GraphVertex, StorageOperationStatus> getComponentByLabelAndId(String uniqueId, ToscaElementTypeEnum nodeType, JsonParseFlagEnum parseFlag) {
+
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<GraphPropertyEnum, Object>();
+ propertiesToMatch.put(GraphPropertyEnum.UNIQUE_ID, uniqueId);
+
+ VertexTypeEnum vertexType = ToscaElementTypeEnum.getVertexTypeByToscaType(nodeType);
+ Either<List<GraphVertex>, TitanOperationStatus> getResponse = titanDao.getByCriteria(vertexType, propertiesToMatch, parseFlag);
+ if (getResponse.isRight()) {
+ log.debug("Couldn't fetch component with type {} and unique id {}, error: {}", vertexType, uniqueId, getResponse.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getResponse.right().value()));
+
+ }
+ List<GraphVertex> componentList = getResponse.left().value();
+ if (componentList.isEmpty()) {
+ log.debug("Component with type {} and unique id {} was not found", vertexType, uniqueId);
+ return Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+ GraphVertex vertexG = componentList.get(0);
+ return Either.left(vertexG);
+ }
+
+ public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId) {
+ return getToscaElement(uniqueId, new ComponentParametersView());
+ }
+
+ public Either<GraphVertex, StorageOperationStatus> markComponentToDelete(GraphVertex componentToDelete) {
+ Either<GraphVertex, StorageOperationStatus> result = null;
+
+ Boolean isDeleted = (Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
+ if (isDeleted != null && isDeleted && !(Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION)) {
+ // component already marked for delete
+ result = Either.left(componentToDelete);
+ return result;
+ } else {
+
+ componentToDelete.addMetadataProperty(GraphPropertyEnum.IS_DELETED, Boolean.TRUE);
+ componentToDelete.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, System.currentTimeMillis());
+
+ Either<GraphVertex, TitanOperationStatus> updateNode = titanDao.updateVertex(componentToDelete);
+
+ StorageOperationStatus updateComponent;
+ if (updateNode.isRight()) {
+ log.debug("Failed to update component {}. status is {}", componentToDelete.getUniqueId(), updateNode.right().value());
+ updateComponent = DaoStatusConverter.convertTitanStatusToStorageStatus(updateNode.right().value());
+ result = Either.right(updateComponent);
+ return result;
+ }
+
+ result = Either.left(componentToDelete);
+ return result;
+ }
+ }
+
+ /**
+ * Performs a shadow clone of previousToscaElement
+ *
+ * @param previousToscaElement
+ * @param nextToscaElement
+ * @param user
+ * @return
+ */
+ public Either<GraphVertex, StorageOperationStatus> cloneToscaElement(GraphVertex previousToscaElement, GraphVertex nextToscaElement, GraphVertex user) {
+
+ Either<GraphVertex, StorageOperationStatus> result = null;
+ GraphVertex createdToscaElementVertex = null;
+ TitanOperationStatus status;
+
+ Either<GraphVertex, TitanOperationStatus> createNextVersionRes = titanDao.createVertex(nextToscaElement);
+ if (createNextVersionRes.isRight()) {
+ status = createNextVersionRes.right().value();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create tosca element vertex {} with version {} on graph. Status is {}. ", previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME),
+ previousToscaElement.getMetadataProperty(GraphPropertyEnum.VERSION), status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ if (result == null) {
+ createdToscaElementVertex = createNextVersionRes.left().value();
+ Map<EdgePropertyEnum, Object> properties = new HashMap<EdgePropertyEnum, Object>();
+ properties.put(EdgePropertyEnum.STATE, createdToscaElementVertex.getMetadataProperty(GraphPropertyEnum.STATE));
+ status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.STATE, properties);
+ if (status != TitanOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from user vertex {} to tosca element vertex {} on graph. Status is {}. ", EdgeLabelEnum.STATE, user.getUniqueId(),
+ previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ }
+ if (result == null) {
+ status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>());
+ if (status != TitanOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from user vertex {} to tosca element vertex {} on graph. Status is {}. ", EdgeLabelEnum.LAST_MODIFIER, user.getUniqueId(),
+ nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ }
+ if (result == null) {
+ status = titanDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.CREATOR, new HashMap<>());
+ if (status != TitanOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from user vertex {} to tosca element vertex {} on graph. Status is {}. ", EdgeLabelEnum.CREATOR, user.getUniqueId(),
+ nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ }
+ if (result == null) {
+ Iterator<Edge> edgesToCopyIter = previousToscaElement.getVertex().edges(Direction.OUT);
+ while (edgesToCopyIter.hasNext()) {
+ Edge currEdge = edgesToCopyIter.next();
+ Vertex currVertex = currEdge.inVertex();
+ // if(EdgeLabelEnum.getEdgeLabelEnum(currEdge.label()).equals(EdgeLabelEnum.VERSION)){
+ // continue;
+ // }
+ status = titanDao.createEdge(createdToscaElementVertex.getVertex(), currVertex, EdgeLabelEnum.getEdgeLabelEnum(currEdge.label()), currEdge);
+ if (status != TitanOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to create edge with label {} from tosca element vertex {} to vertex with label {} on graph. Status is {}. ", currEdge.label(), createdToscaElementVertex.getUniqueId(),
+ currVertex.property(GraphPropertyEnum.LABEL.getProperty()), status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ break;
+ }
+ }
+ }
+
+ if (result == null) {
+ result = Either.left(createdToscaElementVertex);
+ } else {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to clone tosca element {} with the name {}. ", previousToscaElement.getUniqueId(), previousToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME));
+ }
+ return result;
+ }
+
+ protected TitanOperationStatus setLastModifierFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
+ Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(componentV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
+ if (parentVertex.isRight()) {
+ log.debug("Failed to fetch last modifier for tosca element with id {} error {}", componentV.getUniqueId(), parentVertex.right().value());
+ return parentVertex.right().value();
+ }
+ GraphVertex userV = parentVertex.left().value();
+ String userId = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
+ toscaElement.setLastUpdaterUserId(userId);
+ toscaElement.setLastUpdaterFullName(buildFullName(userV));
+ return TitanOperationStatus.OK;
+ }
+
+ public String buildFullName(GraphVertex userV) {
+
+ String fullName = (String) userV.getMetadataProperty(GraphPropertyEnum.FIRST_NAME);
+ if (fullName == null) {
+ fullName = "";
+ } else {
+ fullName = fullName + " ";
+ }
+ String lastName = (String) userV.getMetadataProperty(GraphPropertyEnum.LAST_NAME);
+ if (lastName != null) {
+ fullName += lastName;
+ }
+ return fullName;
+ }
+
+ protected TitanOperationStatus setCreatorFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
+ Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(componentV, EdgeLabelEnum.CREATOR, JsonParseFlagEnum.NoParse);
+ if (parentVertex.isRight()) {
+ log.debug("Failed to fetch creator for tosca element with id {} error {}", componentV.getUniqueId(), parentVertex.right().value());
+ return parentVertex.right().value();
+ }
+ GraphVertex userV = parentVertex.left().value();
+ String creatorUserId = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
+ toscaElement.setCreatorUserId(creatorUserId);
+ toscaElement.setCreatorFullName(buildFullName(userV));
+
+ return TitanOperationStatus.OK;
+ }
+
+ protected <T extends ToscaElement> T getResourceMetaDataFromResource(T toscaElement) {
+ if (toscaElement.getNormalizedName() == null || toscaElement.getNormalizedName().isEmpty()) {
+ toscaElement.setNormalizedName(ValidationUtils.normaliseComponentName(toscaElement.getName()));
+ }
+ if (toscaElement.getSystemName() == null || toscaElement.getSystemName().isEmpty()) {
+ toscaElement.setSystemName(ValidationUtils.convertToSystemName(toscaElement.getName()));
+ }
+
+ LifecycleStateEnum lifecycleStateEnum = toscaElement.getLifecycleState();
+ if (lifecycleStateEnum == null) {
+ toscaElement.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ }
+ long currentDate = System.currentTimeMillis();
+ if (toscaElement.getCreationDate() == null) {
+ toscaElement.setCreationDate(currentDate);
+ }
+ toscaElement.setLastUpdateDate(currentDate);
+
+ return toscaElement;
+ }
+
+ protected void fillCommonMetadata(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
+ if (toscaElement.isHighestVersion() == null) {
+ toscaElement.setHighestVersion(true);
+ }
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_DELETED, toscaElement.getMetadataValue(JsonPresentationFields.IS_DELETED));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION, toscaElement.getMetadataValueOrDefault(JsonPresentationFields.HIGHEST_VERSION, Boolean.TRUE));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.STATE, toscaElement.getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.RESOURCE_TYPE, toscaElement.getMetadataValue(JsonPresentationFields.RESOURCE_TYPE));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.VERSION, toscaElement.getMetadataValue(JsonPresentationFields.VERSION));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME, toscaElement.getMetadataValue(JsonPresentationFields.NORMALIZED_NAME));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, toscaElement.getMetadataValue(JsonPresentationFields.UNIQUE_ID));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaElement.getMetadataValue(JsonPresentationFields.TOSCA_RESOURCE_NAME));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.UUID, toscaElement.getMetadataValue(JsonPresentationFields.UUID));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_ABSTRACT, toscaElement.getMetadataValue(JsonPresentationFields.IS_ABSTRACT));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.INVARIANT_UUID, toscaElement.getMetadataValue(JsonPresentationFields.INVARIANT_UUID));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.NAME, toscaElement.getMetadataValue(JsonPresentationFields.NAME));
+ nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.SYSTEM_NAME, toscaElement.getMetadataValue(JsonPresentationFields.SYSTEM_NAME));
+ toscaElement.getMetadata().entrySet().stream().filter(e -> e.getValue() != null).forEach(e -> nodeTypeVertex.setJsonMetadataField(JsonPresentationFields.getByPresentation(e.getKey()), e.getValue()));
+
+ nodeTypeVertex.setUniqueId(toscaElement.getUniqueId());
+ nodeTypeVertex.setType(toscaElement.getComponentType());
+
+ }
+
+ protected StorageOperationStatus assosiateToUsers(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
+ // handle user
+ String userId = toscaElement.getCreatorUserId();
+
+ Either<GraphVertex, TitanOperationStatus> findUser = findUserVertex(userId);
+
+ if (findUser.isRight()) {
+ TitanOperationStatus status = findUser.right().value();
+ log.error("Cannot find user {} in the graph. status is {}", userId, status);
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
+
+ }
+ GraphVertex creatorVertex = findUser.left().value();
+ GraphVertex updaterVertex = creatorVertex;
+ String updaterId = toscaElement.getLastUpdaterUserId();
+ if (updaterId != null && !updaterId.equals(userId)) {
+ findUser = findUserVertex(updaterId);
+ if (findUser.isRight()) {
+ TitanOperationStatus status = findUser.right().value();
+ log.error("Cannot find user {} in the graph. status is {}", userId, status);
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
+ } else {
+ updaterVertex = findUser.left().value();
+ }
+ }
+ Map<EdgePropertyEnum, Object> props = new HashMap<EdgePropertyEnum, Object>();
+ props.put(EdgePropertyEnum.STATE, (String) toscaElement.getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
+
+ TitanOperationStatus result = titanDao.createEdge(updaterVertex, nodeTypeVertex, EdgeLabelEnum.STATE, props);
+ log.debug("After associating user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.STATE);
+ if (TitanOperationStatus.OK != result) {
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
+ }
+ result = titanDao.createEdge(updaterVertex, nodeTypeVertex, EdgeLabelEnum.LAST_MODIFIER, null);
+ log.debug("After associating user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.LAST_MODIFIER);
+ if (!result.equals(TitanOperationStatus.OK)) {
+ log.error("Failed to associate user {} to resource {}. Edge type is {}", updaterVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.LAST_MODIFIER);
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
+ }
+
+ toscaElement.setLastUpdaterUserId(toscaElement.getCreatorUserId());
+ toscaElement.setLastUpdaterFullName(toscaElement.getCreatorFullName());
+
+ result = titanDao.createEdge(creatorVertex, nodeTypeVertex, EdgeLabelEnum.CREATOR, null);
+ log.debug("After associating user {} to resource {}. Edge type is {} ", creatorVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.CREATOR);
+ if (!result.equals(TitanOperationStatus.OK)) {
+ log.error("Failed to associate user {} to resource {}. Edge type is {} ", creatorVertex, nodeTypeVertex.getUniqueId(), EdgeLabelEnum.CREATOR);
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(result);
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ protected StorageOperationStatus assosiateResourceMetadataToCategory(GraphVertex nodeTypeVertex, ToscaElement nodeType) {
+ String subcategoryName = nodeType.getCategories().get(0).getSubcategories().get(0).getName();
+ String categoryName = nodeType.getCategories().get(0).getName();
+ Either<GraphVertex, StorageOperationStatus> getCategoryVertex = getResourceCategoryVertex(nodeType.getUniqueId(), subcategoryName, categoryName);
+
+ if (getCategoryVertex.isRight()) {
+ return getCategoryVertex.right().value();
+ }
+
+ GraphVertex subCategoryV = getCategoryVertex.left().value();
+
+ TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, subCategoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
+ if (createEdge != TitanOperationStatus.OK) {
+ log.trace("Failed to associate resource {} to category {} with id {}", nodeType.getUniqueId(), subcategoryName, subCategoryV.getUniqueId());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ protected Either<GraphVertex, StorageOperationStatus> getResourceCategoryVertex(String elementId, String subcategoryName, String categoryName) {
+ Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
+ if (category.isRight()) {
+ log.trace("Failed to fetch category {} for resource {} error {}", categoryName, elementId, category.right().value());
+ return Either.right(category.right().value());
+ }
+ GraphVertex categoryV = category.left().value();
+
+ if (subcategoryName != null) {
+ Either<GraphVertex, StorageOperationStatus> subCategory = categoryOperation.getSubCategoryForCategory(categoryV, subcategoryName);
+ if (subCategory.isRight()) {
+ log.trace("Failed to fetch subcategory {} of category for resource {} error {}", subcategoryName, categoryName, elementId, subCategory.right().value());
+ return Either.right(subCategory.right().value());
+ }
+
+ GraphVertex subCategoryV = subCategory.left().value();
+ return Either.left(subCategoryV);
+ }
+ return Either.left(categoryV);
+ }
+
+ private StorageOperationStatus associateArtifactsToResource(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
+ Map<String, ArtifactDataDefinition> artifacts = toscaElement.getArtifacts();
+ Either<GraphVertex, StorageOperationStatus> status;
+ if (artifacts != null) {
+ artifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
+ String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
+ a.setUniqueId(uniqueId);
+ });
+ status = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.ARTIFACTS, EdgeLabelEnum.ARTIFACTS, artifacts);
+ if (status.isRight()) {
+ return status.right().value();
+ }
+ }
+ Map<String, ArtifactDataDefinition> toscaArtifacts = toscaElement.getToscaArtifacts();
+ if (toscaArtifacts != null) {
+ toscaArtifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
+ String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
+ a.setUniqueId(uniqueId);
+ });
+ status = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.TOSCA_ARTIFACTS, EdgeLabelEnum.TOSCA_ARTIFACTS, toscaArtifacts);
+ if (status.isRight()) {
+ return status.right().value();
+ }
+ }
+ Map<String, ArtifactDataDefinition> deploymentArtifacts = toscaElement.getDeploymentArtifacts();
+ if (deploymentArtifacts != null) {
+ deploymentArtifacts.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
+ String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
+ a.setUniqueId(uniqueId);
+ });
+ status = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS, deploymentArtifacts);
+ if (status.isRight()) {
+ return status.right().value();
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ protected TitanOperationStatus disassociateAndDeleteCommonElements(GraphVertex toscaElementVertex) {
+ TitanOperationStatus status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ARTIFACTS);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disaccociate artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return status;
+ }
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.TOSCA_ARTIFACTS);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disaccociate tosca artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return status;
+ }
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to deployment artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return status;
+ }
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.PROPERTIES);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disaccociate properties for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return status;
+ }
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ATTRIBUTES);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disaccociate attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return status;
+ }
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.ADDITIONAL_INFORMATION);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disaccociate additional information for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return status;
+ }
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disaccociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return status;
+ }
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.REQUIREMENTS);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disaccociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return status;
+ }
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disaccociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
+ return status;
+ }
+ return TitanOperationStatus.OK;
+ }
+
+ protected StorageOperationStatus assosiateCommonForToscaElement(GraphVertex nodeTypeVertex, ToscaElement toscaElement, List<GraphVertex> derivedResources) {
+
+ StorageOperationStatus associateUsers = assosiateToUsers(nodeTypeVertex, toscaElement);
+ if (associateUsers != StorageOperationStatus.OK) {
+ return associateUsers;
+ }
+ StorageOperationStatus associateArtifacts = associateArtifactsToResource(nodeTypeVertex, toscaElement);
+ if (associateArtifacts != StorageOperationStatus.OK) {
+ return associateArtifacts;
+ }
+ StorageOperationStatus associateProperties = associatePropertiesToResource(nodeTypeVertex, toscaElement, derivedResources);
+ if (associateProperties != StorageOperationStatus.OK) {
+ return associateProperties;
+ }
+ StorageOperationStatus associateAdditionaInfo = associateAdditionalInfoToResource(nodeTypeVertex, toscaElement);
+ if (associateAdditionaInfo != StorageOperationStatus.OK) {
+ return associateAdditionaInfo;
+ }
+ if (needConnectToCatalog(toscaElement)) {
+ StorageOperationStatus associateToCatalog = associateToCatalogRoot(nodeTypeVertex);
+ if (associateToCatalog != StorageOperationStatus.OK) {
+ return associateToCatalog;
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ private boolean needConnectToCatalog(ToscaElement toscaElement) {
+ Boolean isAbstract = (Boolean) toscaElement.getMetadataValue(JsonPresentationFields.IS_ABSTRACT);
+ if (isAbstract != null && isAbstract) {
+ return false;
+ }
+ return toscaElement.isHighestVersion();
+ }
+
+ private StorageOperationStatus associateToCatalogRoot(GraphVertex nodeTypeVertex) {
+ Either<GraphVertex, TitanOperationStatus> catalog = titanDao.getVertexByLabel(VertexTypeEnum.CATALOG_ROOT);
+ if (catalog.isRight()) {
+ log.debug("Failed to fetch catalog vertex. error {}", catalog.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(catalog.right().value());
+ }
+ TitanOperationStatus createEdge = titanDao.createEdge(catalog.left().value(), nodeTypeVertex, EdgeLabelEnum.CATALOG_ELEMENT, null);
+
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
+ }
+
+ protected StorageOperationStatus associatePropertiesToResource(GraphVertex nodeTypeVertex, ToscaElement nodeType, List<GraphVertex> derivedResources) {
+ // Note : currently only one derived supported!!!!
+ Either<Map<String, PropertyDataDefinition>, StorageOperationStatus> dataFromDerived = getDataFromDerived(derivedResources, EdgeLabelEnum.PROPERTIES);
+ if (dataFromDerived.isRight()) {
+ return dataFromDerived.right().value();
+ }
+ Map<String, PropertyDataDefinition> propertiesAll = dataFromDerived.left().value();
+
+ Map<String, PropertyDataDefinition> properties = nodeType.getProperties();
+
+ if (properties != null) {
+ properties.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
+ String uid = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId(), p.getName());
+ p.setUniqueId(uid);
+ });
+
+ Either<Map<String, PropertyDataDefinition>, String> eitherMerged = ToscaDataDefinition.mergeDataMaps(propertiesAll, properties);
+ if (eitherMerged.isRight()) {
+ // TODO re-factor error handling - moving BL to operation resulted in loss of info about the invalid property
+ log.debug("property {} cannot be overriden", eitherMerged.right().value());
+ return StorageOperationStatus.INVALID_PROPERTY;
+ }
+ }
+ if (!propertiesAll.isEmpty()) {
+ Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.PROPERTIES, EdgeLabelEnum.PROPERTIES, propertiesAll);
+ if (assosiateElementToData.isRight()) {
+ return assosiateElementToData.right().value();
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ private StorageOperationStatus associateAdditionalInfoToResource(GraphVertex nodeTypeVertex, ToscaElement nodeType) {
+ Map<String, AdditionalInfoParameterDataDefinition> additionalInformation = nodeType.getAdditionalInformation();
+ if (additionalInformation != null) {
+ Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, additionalInformation);
+ if (assosiateElementToData.isRight()) {
+ return assosiateElementToData.right().value();
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ protected <T extends ToscaDataDefinition> Either<Map<String, T>, StorageOperationStatus> getDataFromDerived(List<GraphVertex> derivedResources, EdgeLabelEnum edge) {
+ Map<String, T> propertiesAll = new HashMap<>();
+
+ if (derivedResources != null && !derivedResources.isEmpty()) {
+ for (GraphVertex derived : derivedResources) {
+ Either<List<GraphVertex>, TitanOperationStatus> derivedProperties = titanDao.getChildrenVertecies(derived, edge, JsonParseFlagEnum.ParseJson);
+ if (derivedProperties.isRight()) {
+ if (derivedProperties.right().value() != TitanOperationStatus.NOT_FOUND) {
+ log.debug("Failed to get properties for derived from {} error {}", derived.getUniqueId(), derivedProperties.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(derivedProperties.right().value()));
+ } else {
+ continue;
+ }
+ }
+ List<GraphVertex> propList = derivedProperties.left().value();
+ for (GraphVertex propV : propList) {
+ Map<String, T> propertiesFromDerived = (Map<String, T>) propV.getJson();
+ if (propertiesFromDerived != null) {
+ propertiesFromDerived.entrySet().forEach(x -> x.getValue().setOwnerIdIfEmpty(derived.getUniqueId()));
+ propertiesAll.putAll(propertiesFromDerived);
+ }
+ }
+ }
+ }
+ return Either.left(propertiesAll);
+ }
+
+ protected TitanOperationStatus setArtifactsFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
+ Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.ARTIFACTS);
+ if (result.isLeft()) {
+ toscaElement.setArtifacts(result.left().value());
+ } else {
+ if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
+ return result.right().value();
+ }
+ }
+ result = getDataFromGraph(componentV, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
+ if (result.isLeft()) {
+ toscaElement.setDeploymentArtifacts(result.left().value());
+ } else {
+ if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
+ return result.right().value();
+ }
+ }
+ result = getDataFromGraph(componentV, EdgeLabelEnum.TOSCA_ARTIFACTS);
+ if (result.isLeft()) {
+ toscaElement.setToscaArtifacts(result.left().value());
+ } else {
+ if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
+ return result.right().value();
+ }
+ }
+ return TitanOperationStatus.OK;
+ }
+
+ protected TitanOperationStatus setAllVersions(GraphVertex componentV, ToscaElement toscaElement) {
+ Map<String, String> allVersion = new HashMap<>();
+
+ allVersion.put((String) componentV.getMetadataProperty(GraphPropertyEnum.VERSION), componentV.getUniqueId());
+ ArrayList<GraphVertex> allChildrenAndParants = new ArrayList<GraphVertex>();
+ Either<GraphVertex, TitanOperationStatus> childResourceRes = titanDao.getChildVertex(componentV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+ while (childResourceRes.isLeft()) {
+ GraphVertex child = childResourceRes.left().value();
+ allChildrenAndParants.add(child);
+ childResourceRes = titanDao.getChildVertex(child, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+ }
+ TitanOperationStatus operationStatus = childResourceRes.right().value();
+
+ if (operationStatus != TitanOperationStatus.NOT_FOUND) {
+ return operationStatus;
+ } else {
+ Either<GraphVertex, TitanOperationStatus> parentResourceRes = titanDao.getParentVertex(componentV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+ while (parentResourceRes.isLeft()) {
+ GraphVertex parent = parentResourceRes.left().value();
+ allChildrenAndParants.add(parent);
+ parentResourceRes = titanDao.getParentVertex(parent, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+ }
+ operationStatus = parentResourceRes.right().value();
+ if (operationStatus != TitanOperationStatus.NOT_FOUND) {
+ return operationStatus;
+ } else {
+ allChildrenAndParants.stream().filter(vertex -> {
+ Boolean isDeleted = (Boolean) vertex.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
+ return (isDeleted == null || isDeleted == false);
+ }).forEach(vertex -> allVersion.put((String) vertex.getMetadataProperty(GraphPropertyEnum.VERSION), vertex.getUniqueId()));
+
+ toscaElement.setAllVersions(allVersion);
+ return TitanOperationStatus.OK;
+ }
+ }
+ }
+
+ protected <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getFollowedComponent(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates, ComponentTypeEnum neededType) {
+
+ Either<List<T>, StorageOperationStatus> result = null;
+
+ Map<GraphPropertyEnum, Object> props = null;
+
+ if (userId != null) {
+ props = new HashMap<>();
+ // for Designer retrieve specific user
+ props.put(GraphPropertyEnum.USERID, userId);
+ }
+ // in case of user id == null -> get all users by label
+ // for Tester and Admin retrieve all users
+ Either<List<GraphVertex>, TitanOperationStatus> usersByCriteria = titanDao.getByCriteria(VertexTypeEnum.USER, props, JsonParseFlagEnum.NoParse);
+ if (usersByCriteria.isRight()) {
+ log.debug("Failed to fetch users by criteria {} error {}", props, usersByCriteria.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(usersByCriteria.right().value()));
+ }
+ List<GraphVertex> users = usersByCriteria.left().value();
+
+ List<T> components = new ArrayList<>();
+ List<T> componentsPerUser;
+ for (GraphVertex userV : users) {
+
+ HashSet<String> ids = new HashSet<String>();
+ Either<List<GraphVertex>, TitanOperationStatus> childrenVertecies = titanDao.getChildrenVertecies(userV, EdgeLabelEnum.STATE, JsonParseFlagEnum.NoParse);
+ if (childrenVertecies.isRight() && childrenVertecies.right().value() != TitanOperationStatus.NOT_FOUND) {
+ log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.STATE, childrenVertecies.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childrenVertecies.right().value()));
+ }
+
+ // get all resource with current state
+ if (childrenVertecies.isLeft()) {
+ componentsPerUser = fetchComponents(lifecycleStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.STATE);
+
+ if (componentsPerUser != null) {
+ for (T comp : componentsPerUser) {
+ ids.add(comp.getUniqueId());
+ components.add(comp);
+ }
+ }
+ }
+ if (lastStateStates != null && !lastStateStates.isEmpty()) {
+ // get all resource with last state
+ childrenVertecies = titanDao.getChildrenVertecies(userV, EdgeLabelEnum.LAST_STATE, JsonParseFlagEnum.NoParse);
+ if (childrenVertecies.isRight() && childrenVertecies.right().value() != TitanOperationStatus.NOT_FOUND) {
+ log.debug("Failed to fetch children vertices for user {} by edge {} error {}", userV.getMetadataProperty(GraphPropertyEnum.USERID), EdgeLabelEnum.LAST_STATE, childrenVertecies.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childrenVertecies.right().value()));
+ }
+ if (childrenVertecies.isLeft()) {
+ boolean isFirst;
+ componentsPerUser = fetchComponents(lastStateStates, childrenVertecies.left().value(), neededType, EdgeLabelEnum.LAST_STATE);
+ if (componentsPerUser != null) {
+ for (T comp : componentsPerUser) {
+ isFirst = true;
+
+ if (ids.contains(comp.getUniqueId())) {
+ isFirst = false;
+ }
+ if (isFirst == true) {
+ components.add(comp);
+ }
+
+ }
+ }
+ }
+ }
+
+ } // whlile users
+ ;
+ result = Either.left(components);
+ return result;
+
+ }
+
+ private <T extends ToscaElement> List<T> fetchComponents(Set<LifecycleStateEnum> lifecycleStates, List<GraphVertex> vertices, ComponentTypeEnum neededType, EdgeLabelEnum edgelabel) {
+ List<T> components = new ArrayList<>();
+ for (GraphVertex node : vertices) {
+
+ Iterator<Edge> edges = node.getVertex().edges(Direction.IN, edgelabel.name());
+ while (edges.hasNext()) {
+ Edge edge = edges.next();
+ String stateStr = (String) titanDao.getProperty(edge, EdgePropertyEnum.STATE);
+
+ LifecycleStateEnum nodeState = LifecycleStateEnum.findState(stateStr);
+ if (nodeState == null) {
+ log.debug("no supported STATE {} for element {}", stateStr, node.getUniqueId());
+ continue;
+ }
+ if (lifecycleStates != null && lifecycleStates.contains(nodeState)) {
+
+ Boolean isDeleted = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
+ if (isDeleted != null && isDeleted) {
+ log.trace("Deleted element {}, discard", node.getUniqueId());
+ continue;
+ }
+
+ Boolean isHighest = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION);
+ if (isHighest) {
+
+ ComponentTypeEnum componentType = node.getType();
+ // get only latest versions
+
+ if (componentType == null) {
+ log.debug("No supported type {} for vertex {}", componentType, node.getUniqueId());
+ continue;
+ }
+ if (neededType == componentType) {
+ switch (componentType) {
+ case SERVICE:
+ case PRODUCT:
+ handleNode(components, node, componentType);
+ break;
+ case RESOURCE:
+ Boolean isAbtract = (Boolean) node.getMetadataProperty(GraphPropertyEnum.IS_ABSTRACT);
+ if (isAbtract == null || false == isAbtract) {
+ handleNode(components, node, componentType);
+ } // if not abstract
+ break;
+ default:
+ log.debug("not supported node type {}", componentType);
+ break;
+ }// case
+ } // needed type
+ }
+ } // if
+ } // while edges
+ } // while resources
+ return components;
+ }
+
+ protected <T extends ToscaElement> void handleNode(List<T> components, GraphVertex vertexComponent, ComponentTypeEnum nodeType) {
+
+ Either<T, StorageOperationStatus> component = getLightComponent(vertexComponent, nodeType, new ComponentParametersView(true));
+ if (component.isRight()) {
+ log.debug("Failed to get component for id = {} error : {} skip resource", vertexComponent.getUniqueId(), component.right().value());
+ } else {
+ components.add(component.left().value());
+ }
+ }
+
+ protected <T extends ToscaElement> Either<T, StorageOperationStatus> getLightComponent(String componentUid, ComponentTypeEnum nodeType, ComponentParametersView parametersFilter) {
+ Either<GraphVertex, TitanOperationStatus> getVertexRes = titanDao.getVertexById(componentUid);
+ if (getVertexRes.isRight()) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexRes.right().value()));
+ }
+ return getLightComponent(getVertexRes.left().value(), nodeType, parametersFilter);
+ }
+
+ protected <T extends ToscaElement> Either<T, StorageOperationStatus> getLightComponent(GraphVertex vertexComponent, ComponentTypeEnum nodeType, ComponentParametersView parametersFilter) {
+
+ log.trace("Starting to build light component of type {}, id {}", nodeType, vertexComponent.getUniqueId());
+
+ titanDao.parseVertexProperties(vertexComponent, JsonParseFlagEnum.ParseMetadata);
+
+ T toscaElement = convertToComponent(vertexComponent);
+
+ TitanOperationStatus status = setCreatorFromGraph(vertexComponent, toscaElement);
+ if (status != TitanOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+
+ status = setLastModifierFromGraph(vertexComponent, toscaElement);
+ if (status != TitanOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ status = setCategoriesFromGraph(vertexComponent, toscaElement);
+ if (status != TitanOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ if (!parametersFilter.isIgnoreAllVersions()) {
+ status = setAllVersions(vertexComponent, toscaElement);
+ if (status != TitanOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ }
+ if (!parametersFilter.isIgnoreCapabilities()) {
+ status = setCapabilitiesFromGraph(vertexComponent, toscaElement);
+ if (status != TitanOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ }
+ if (!parametersFilter.isIgnoreRequirements()) {
+ status = setRequirementsFromGraph(vertexComponent, toscaElement);
+ if (status != TitanOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ }
+ log.debug("Ended to build light component of type {}, id {}", nodeType, vertexComponent.getUniqueId());
+ return Either.left(toscaElement);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T extends ToscaElement> T convertToComponent(GraphVertex componentV) {
+ ToscaElement toscaElement = null;
+ VertexTypeEnum label = componentV.getLabel();
+ switch (label) {
+ case NODE_TYPE:
+ toscaElement = new NodeType();
+ break;
+ case TOPOLOGY_TEMPLATE:
+ toscaElement = new TopologyTemplate();
+ break;
+ default:
+ log.debug("Not supported tosca type {}", label);
+ break;
+ }
+
+ Map<String, Object> jsonMetada = componentV.getMetadataJson();
+ if (toscaElement != null) {
+ toscaElement.setMetadata(jsonMetada);
+ }
+ return (T) toscaElement;
+ }
+
+ protected TitanOperationStatus setServiceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
+ Either<Vertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
+ if (childVertex.isRight()) {
+ log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(), childVertex.right().value());
+ return childVertex.right().value();
+ }
+ Vertex categoryV = childVertex.left().value();
+ catalogComponent.setCategoryNormalizedName((String) categoryV.property(JsonPresentationFields.NORMALIZED_NAME.getPresentation()).value());
+
+ return TitanOperationStatus.OK;
+ }
+
+ protected TitanOperationStatus setResourceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
+
+ Either<Vertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
+ if (childVertex.isRight()) {
+ log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(), childVertex.right().value());
+ return childVertex.right().value();
+ }
+ Vertex subCategoryV = childVertex.left().value();
+ catalogComponent.setSubCategoryNormalizedName((String) subCategoryV.property(JsonPresentationFields.NORMALIZED_NAME.getPresentation()).value());
+ Either<Vertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
+ Vertex categoryV = parentVertex.left().value();
+ catalogComponent.setCategoryNormalizedName((String) categoryV.property(JsonPresentationFields.NORMALIZED_NAME.getPresentation()).value());
+
+ return TitanOperationStatus.OK;
+ }
+
+ protected TitanOperationStatus setResourceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
+ List<CategoryDefinition> categories = new ArrayList<>();
+ SubCategoryDefinition subcategory;
+
+ Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
+ if (childVertex.isRight()) {
+ log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
+ return childVertex.right().value();
+ }
+ GraphVertex subCategoryV = childVertex.left().value();
+ Map<GraphPropertyEnum, Object> metadataProperties = subCategoryV.getMetadataProperties();
+ subcategory = new SubCategoryDefinition();
+ subcategory.setUniqueId(subCategoryV.getUniqueId());
+ subcategory.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
+ subcategory.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
+
+ Type listTypeSubcat = new TypeToken<List<String>>() {
+ }.getType();
+ List<String> iconsfromJsonSubcat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS), listTypeSubcat);
+ subcategory.setIcons(iconsfromJsonSubcat);
+
+ Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
+ if (parentVertex.isRight()) {
+ log.debug("failed to fetch {} for category with id {}, error {}", EdgeLabelEnum.SUB_CATEGORY, subCategoryV.getUniqueId(), parentVertex.right().value());
+ return childVertex.right().value();
+ }
+ GraphVertex categoryV = parentVertex.left().value();
+ metadataProperties = categoryV.getMetadataProperties();
+
+ CategoryDefinition category = new CategoryDefinition();
+ category.setUniqueId(categoryV.getUniqueId());
+ category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
+ category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
+
+ Type listTypeCat = new TypeToken<List<String>>() {
+ }.getType();
+ List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS), listTypeCat);
+ category.setIcons(iconsfromJsonCat);
+
+ category.addSubCategory(subcategory);
+ categories.add(category);
+ toscaElement.setCategories(categories);
+
+ return TitanOperationStatus.OK;
+ }
+
+ public <T extends ToscaElement> Either<T, StorageOperationStatus> updateToscaElement(T toscaElementToUpdate, GraphVertex elementV, ComponentParametersView filterResult) {
+ Either<T, StorageOperationStatus> result = null;
+
+ log.debug("In updateToscaElement. received component uid = {}", (toscaElementToUpdate == null ? null : toscaElementToUpdate.getUniqueId()));
+ if (toscaElementToUpdate == null) {
+ log.error("Service object is null");
+ result = Either.right(StorageOperationStatus.BAD_REQUEST);
+ return result;
+ }
+
+ String modifierUserId = toscaElementToUpdate.getLastUpdaterUserId();
+ if (modifierUserId == null || modifierUserId.isEmpty()) {
+ log.error("UserId is missing in the request.");
+ result = Either.right(StorageOperationStatus.BAD_REQUEST);
+ return result;
+ }
+ Either<GraphVertex, TitanOperationStatus> findUser = findUserVertex(modifierUserId);
+
+ if (findUser.isRight()) {
+ TitanOperationStatus status = findUser.right().value();
+ log.error("Cannot find user {} in the graph. status is {}", modifierUserId, status);
+ return result;
+ }
+
+ GraphVertex modifierV = findUser.left().value();
+ // UserData modifierUserData = findUser.left().value();
+ String toscaElementId = toscaElementToUpdate.getUniqueId();
+
+ Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(elementV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
+ if (parentVertex.isRight()) {
+ log.debug("Failed to fetch last modifier for tosca element with id {} error {}", toscaElementId, parentVertex.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(parentVertex.right().value()));
+ }
+ GraphVertex userV = parentVertex.left().value();
+ String currentModifier = (String) userV.getMetadataProperty(GraphPropertyEnum.USERID);
+
+ String prevSystemName = (String) elementV.getMetadataProperty(GraphPropertyEnum.SYSTEM_NAME);
+
+ if (currentModifier.equals(modifierUserId)) {
+ log.debug("Graph LAST MODIFIER edge should not be changed since the modifier is the same as the last modifier.");
+ } else {
+ log.debug("Going to update the last modifier user of the resource from {} to {}", currentModifier, modifierUserId);
+ StorageOperationStatus status = moveLastModifierEdge(elementV, modifierV);
+ log.debug("Finish to update the last modifier user of the resource from {} to {}. status is {}", currentModifier, modifierUserId, status);
+ if (status != StorageOperationStatus.OK) {
+ result = Either.right(status);
+ return result;
+ }
+ }
+
+ final long currentTimeMillis = System.currentTimeMillis();
+ log.debug("Going to update the last Update Date of the resource from {} to {}", elementV.getJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE), currentTimeMillis);
+ elementV.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, currentTimeMillis);
+
+ StorageOperationStatus checkCategories = validateCategories(toscaElementToUpdate, elementV);
+ if (checkCategories != StorageOperationStatus.OK) {
+ result = Either.right(checkCategories);
+ return result;
+ }
+
+ // update all data on vertex
+ fillToscaElementVertexData(elementV, toscaElementToUpdate, JsonParseFlagEnum.ParseMetadata);
+
+ Either<GraphVertex, TitanOperationStatus> updateElement = titanDao.updateVertex(elementV);
+
+ if (updateElement.isRight()) {
+ log.error("Failed to update resource {}. status is {}", toscaElementId, updateElement.right().value());
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateElement.right().value()));
+ return result;
+ }
+ GraphVertex updateElementV = updateElement.left().value();
+
+ // DE230195 in case resource name changed update TOSCA artifacts
+ // file names accordingly
+ String newSystemName = (String) updateElementV.getMetadataProperty(GraphPropertyEnum.SYSTEM_NAME);
+ if (newSystemName != null && !newSystemName.equals(prevSystemName)) {
+ Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> resultToscaArt = getDataFromGraph(updateElementV, EdgeLabelEnum.TOSCA_ARTIFACTS);
+ if (resultToscaArt.isRight()) {
+ log.debug("Failed to get tosca artifact from graph for tosca element {} error {}", toscaElementId, resultToscaArt.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resultToscaArt.right().value()));
+ }
+
+ Map<String, ArtifactDataDefinition> toscaArtifacts = resultToscaArt.left().value();
+ if (toscaArtifacts != null) {
+ for (Entry<String, ArtifactDataDefinition> artifact : toscaArtifacts.entrySet()) {
+ generateNewToscaFileName(toscaElementToUpdate.getComponentType().getValue().toLowerCase(), newSystemName, artifact.getValue());
+ }
+ // TODO call to new Artifact operation in order to update list of artifacts
+
+ }
+ // US833308 VLI in service - specific network_role property value logic
+ if (ComponentTypeEnum.SERVICE == toscaElementToUpdate.getComponentType()) {
+ // update method logs success/error and returns boolean (true if nothing fails)
+ // TODO!!!!
+ // updateServiceNameInVLIsNetworkRolePropertyValues(component, prevSystemName, newSystemName);
+ }
+ }
+
+ if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.RESOURCE) {
+ StorageOperationStatus resultDerived = updateDerived(toscaElementToUpdate, updateElementV);
+ if (resultDerived != StorageOperationStatus.OK) {
+ log.debug("Failed to update from derived data for element {} error {}", toscaElementId, resultDerived);
+ return Either.right(resultDerived);
+ }
+ }
+
+ Either<T, StorageOperationStatus> updatedResource = getToscaElement(updateElementV, filterResult);
+ if (updatedResource.isRight()) {
+ log.error("Failed to fetch tosca element {} after update , error {}", toscaElementId, updatedResource.right().value());
+ result = Either.right(StorageOperationStatus.BAD_REQUEST);
+ return result;
+ }
+
+ T updatedResourceValue = updatedResource.left().value();
+ result = Either.left(updatedResourceValue);
+
+ return result;
+ }
+
+ protected StorageOperationStatus moveLastModifierEdge(GraphVertex elementV, GraphVertex modifierV) {
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(titanDao.moveEdge(elementV, modifierV, EdgeLabelEnum.LAST_MODIFIER, Direction.IN));
+ }
+
+ protected StorageOperationStatus moveCategoryEdge(GraphVertex elementV, GraphVertex categoryV) {
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(titanDao.moveEdge(elementV, categoryV, EdgeLabelEnum.CATEGORY, Direction.OUT));
+ }
+
+ private void generateNewToscaFileName(String componentType, String componentName, ArtifactDataDefinition artifactInfo) {
+ Map<String, Object> getConfig = (Map<String, Object>) ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts().entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel()))
+ .findAny().get().getValue();
+ artifactInfo.setArtifactName(componentType + "-" + componentName + getConfig.get("artifactName"));
+ }
+
+ protected <T extends ToscaElement> StorageOperationStatus validateResourceCategory(T toscaElementToUpdate, GraphVertex elementV) {
+ StorageOperationStatus status = StorageOperationStatus.OK;
+ List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
+ CategoryDefinition newCategory = newCategoryList.get(0);
+
+ Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
+ if (childVertex.isRight()) {
+ log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
+ }
+ GraphVertex subCategoryV = childVertex.left().value();
+ Map<GraphPropertyEnum, Object> metadataProperties = subCategoryV.getMetadataProperties();
+ String subCategoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
+
+ Either<GraphVertex, TitanOperationStatus> parentVertex = titanDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
+ if (parentVertex.isRight()) {
+ log.debug("failed to fetch {} for category with id {}, error {}", EdgeLabelEnum.SUB_CATEGORY, subCategoryV.getUniqueId(), parentVertex.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
+ }
+ GraphVertex categoryV = parentVertex.left().value();
+ metadataProperties = categoryV.getMetadataProperties();
+ String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
+
+ boolean categoryWasChanged = false;
+
+ String newCategoryName = newCategory.getName();
+ SubCategoryDefinition newSubcategory = newCategory.getSubcategories().get(0);
+ String newSubCategoryName = newSubcategory.getName();
+ if (newCategoryName != null && false == newCategoryName.equals(categoryNameCurrent)) {
+ // the category was changed
+ categoryWasChanged = true;
+ } else {
+ // the sub-category was changed
+ if (newSubCategoryName != null && false == newSubCategoryName.equals(subCategoryNameCurrent)) {
+ log.debug("Going to update the category of the resource from {} to {}", categoryNameCurrent, newCategory);
+ categoryWasChanged = true;
+ }
+ }
+ if (categoryWasChanged) {
+ Either<GraphVertex, StorageOperationStatus> getCategoryVertex = getResourceCategoryVertex(elementV.getUniqueId(), newSubCategoryName, newCategoryName);
+
+ if (getCategoryVertex.isRight()) {
+ return getCategoryVertex.right().value();
+ }
+ GraphVertex newCategoryV = getCategoryVertex.left().value();
+ status = moveCategoryEdge(elementV, newCategoryV);
+ log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
+ }
+ return status;
+ }
+
+ public <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getElementCatalogData(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes, boolean isHighestVersions) {
+ Either<List<GraphVertex>, TitanOperationStatus> listOfComponents;
+ if (isHighestVersions) {
+ listOfComponents = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.NoParse);
+ } else {
+ listOfComponents = getListOfHighestAndAllCertifiedComponents(componentType, excludeTypes);
+ }
+
+ if (listOfComponents.isRight() && listOfComponents.right().value() != TitanOperationStatus.NOT_FOUND) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(listOfComponents.right().value()));
+ }
+ List<T> result = new ArrayList<>();
+ if (listOfComponents.isLeft()) {
+ List<GraphVertex> highestAndAllCertified = listOfComponents.left().value();
+ if (highestAndAllCertified != null && false == highestAndAllCertified.isEmpty()) {
+ for (GraphVertex vertexComponent : highestAndAllCertified) {
+ Either<T, StorageOperationStatus> component = getLightComponent(vertexComponent, componentType, new ComponentParametersView(true));
+ if (component.isRight()) {
+ log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), component.right().value());
+ return Either.right(component.right().value());
+ } else {
+ result.add(component.left().value());
+ }
+ }
+ }
+ }
+ return Either.left(result);
+ }
+
+ public Either<List<CatalogComponent>, StorageOperationStatus> getElementCatalogData() {
+ List<CatalogComponent> results = new ArrayList<>();
+ StopWatch stopWatch = new StopWatch();
+ stopWatch.start();
+
+ Either<Iterator<Vertex>, TitanOperationStatus> verticesEither = titanDao.getCatalogVerticies();
+ if (verticesEither.isRight()) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(verticesEither.right().value()));
+ }
+ Iterator<Vertex> vertices = verticesEither.left().value();
+ while (vertices.hasNext()) {
+ Vertex vertex = vertices.next();
+ VertexProperty<Object> property = vertex.property(GraphPropertiesDictionary.METADATA.getProperty());
+ String json = (String) property.value();
+
+ CatalogComponent catalogComponent = new CatalogComponent();
+ Map<String, Object> metadatObj = JsonParserUtils.toMap(json);
+
+ catalogComponent.setComponentType(ComponentTypeEnum.valueOf((String) metadatObj.get(JsonPresentationFields.COMPONENT_TYPE.getPresentation())));
+ catalogComponent.setVersion((String) metadatObj.get(JsonPresentationFields.VERSION.getPresentation()));
+ catalogComponent.setName((String) metadatObj.get(JsonPresentationFields.NAME.getPresentation()));
+ catalogComponent.setIcon((String) metadatObj.get(JsonPresentationFields.ICON.getPresentation()));
+ catalogComponent.setUniqueId((String) metadatObj.get(JsonPresentationFields.UNIQUE_ID.getPresentation()));
+ catalogComponent.setLifecycleState((String) metadatObj.get(JsonPresentationFields.LIFECYCLE_STATE.getPresentation()));
+ catalogComponent.setLastUpdateDate((Long) metadatObj.get(JsonPresentationFields.LAST_UPDATE_DATE.getPresentation()));
+ catalogComponent.setDistributionStatus((String) metadatObj.get(JsonPresentationFields.DISTRIBUTION_STATUS.getPresentation()));
+ Object resourceType = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
+ if (resourceType != null) {
+ catalogComponent.setResourceType((String) resourceType);
+ }
+
+ if (catalogComponent.getComponentType() == ComponentTypeEnum.SERVICE) {
+ setServiceCategoryFromGraphV(vertex, catalogComponent);
+
+ } else {
+ setResourceCategoryFromGraphV(vertex, catalogComponent);
+ }
+ results.add(catalogComponent);
+
+ }
+ stopWatch.stop();
+ String timeToFetchElements = stopWatch.prettyPrint();
+ log.info("time to fetch all catalog elements: {}", timeToFetchElements);
+ return Either.left(results);
+ }
+
+ public Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes, JsonParseFlagEnum parseFlag) {
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<>();
+ Map<GraphPropertyEnum, Object> propertiesHasNotToMatch = new HashMap<>();
+ propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+ propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+
+ if (componentType == ComponentTypeEnum.RESOURCE) {
+ propertiesToMatch.put(GraphPropertyEnum.IS_ABSTRACT, false);
+ propertiesHasNotToMatch.put(GraphPropertyEnum.RESOURCE_TYPE, excludeTypes);
+ }
+ propertiesHasNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+
+ return titanDao.getByCriteria(null, propertiesToMatch, propertiesHasNotToMatch, parseFlag);
+ }
+
+ // highest + (certified && !highest)
+ public Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestAndAllCertifiedComponents(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes) {
+ long startFetchAllStates = System.currentTimeMillis();
+ Either<List<GraphVertex>, TitanOperationStatus> highestNodes = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.ParseMetadata);
+
+ Map<GraphPropertyEnum, Object> propertiesToMatchCertified = new HashMap<>();
+ Map<GraphPropertyEnum, Object> propertiesHasNotToMatchCertified = new HashMap<>();
+ propertiesToMatchCertified.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ propertiesToMatchCertified.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+ if (componentType == ComponentTypeEnum.RESOURCE) {
+ propertiesToMatchCertified.put(GraphPropertyEnum.IS_ABSTRACT, false);
+ propertiesHasNotToMatchCertified.put(GraphPropertyEnum.RESOURCE_TYPE, excludeTypes);
+ }
+
+ propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_DELETED, true);
+ propertiesHasNotToMatchCertified.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+
+ Either<List<GraphVertex>, TitanOperationStatus> certifiedNotHighestNodes = titanDao.getByCriteria(null, propertiesToMatchCertified, propertiesHasNotToMatchCertified, JsonParseFlagEnum.ParseMetadata);
+ if (certifiedNotHighestNodes.isRight() && certifiedNotHighestNodes.right().value() != TitanOperationStatus.NOT_FOUND) {
+ return Either.right(certifiedNotHighestNodes.right().value());
+ }
+
+ long endFetchAllStates = System.currentTimeMillis();
+
+ List<GraphVertex> allNodes = new ArrayList<>();
+
+ if (certifiedNotHighestNodes.isLeft()) {
+ allNodes.addAll(certifiedNotHighestNodes.left().value());
+ }
+ if (highestNodes.isLeft()) {
+ allNodes.addAll(highestNodes.left().value());
+ }
+
+ log.debug("Fetch catalog {}s all states from graph took {} ms", componentType, endFetchAllStates - startFetchAllStates);
+ return Either.left(allNodes);
+ }
+
+ protected Either<List<GraphVertex>, StorageOperationStatus> getAllComponentsMarkedForDeletion(ComponentTypeEnum componentType) {
+
+ // get all components marked for delete
+ Map<GraphPropertyEnum, Object> props = new HashMap<GraphPropertyEnum, Object>();
+ props.put(GraphPropertyEnum.IS_DELETED, true);
+ props.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+
+ Either<List<GraphVertex>, TitanOperationStatus> componentsToDelete = titanDao.getByCriteria(null, props, JsonParseFlagEnum.NoParse);
+
+ if (componentsToDelete.isRight()) {
+ TitanOperationStatus error = componentsToDelete.right().value();
+ if (error.equals(TitanOperationStatus.NOT_FOUND)) {
+ log.trace("no components to delete");
+ return Either.left(new ArrayList<>());
+ } else {
+ log.info("failed to find components to delete. error : {}", error.name());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(error));
+ }
+ }
+ return Either.left(componentsToDelete.left().value());
+ }
+
+ protected TitanOperationStatus setAdditionalInformationFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
+ Either<Map<String, AdditionalInfoParameterDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.ADDITIONAL_INFORMATION);
+ if (result.isLeft()) {
+ toscaElement.setAdditionalInformation(result.left().value());
+ } else {
+ if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
+ return result.right().value();
+ }
+ }
+ return TitanOperationStatus.OK;
+ }
+
+ // --------------------------------------------
+ public abstract <T extends ToscaElement> Either<T, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView);
+
+ public abstract <T extends ToscaElement> Either<T, StorageOperationStatus> getToscaElement(GraphVertex toscaElementVertex, ComponentParametersView componentParametersView);
+
+ public abstract <T extends ToscaElement> Either<T, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex);
+
+ public abstract <T extends ToscaElement> Either<T, StorageOperationStatus> createToscaElement(ToscaElement toscaElement);
+
+ protected abstract <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement);
+
+ protected abstract <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement);
+
+ protected abstract <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement);
+
+ protected abstract <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV);
+
+ protected abstract <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV);
- public abstract <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag);
+ public abstract <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag);
}
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 15fb63f14c..647234d892 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,21 +20,7 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
-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 fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
@@ -45,43 +31,14 @@ 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.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.elements.*;
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.*;
+import org.openecomp.sdc.be.model.catalog.CatalogComponent;
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;
@@ -96,7 +53,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import fj.data.Either;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.function.BiPredicate;
+import java.util.stream.Collectors;
@org.springframework.stereotype.Component("tosca-operation-facade")
public class ToscaOperationFacade {
@@ -128,7 +88,7 @@ public class ToscaOperationFacade {
public <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement(String componentId) {
ComponentParametersView filters = new ComponentParametersView();
filters.setIgnoreCapabiltyProperties(false);
-
+ filters.setIgnoreForwardingPath(false);
return getToscaElement(componentId, filters);
}
@@ -202,7 +162,7 @@ public class ToscaOperationFacade {
String componentId = componentV.getUniqueId();
if (toscaOperation != null) {
log.debug("Need to fetch tosca element for id {}", componentId);
- toscaElement = toscaOperation.getToscaElement(componentV, filters);
+ toscaElement = toscaOperation.getToscaElement(componentV, filters);
} else {
log.debug("not supported tosca type {} for id {}", label, componentId);
toscaElement = Either.right(StorageOperationStatus.BAD_REQUEST);
@@ -328,7 +288,10 @@ public class ToscaOperationFacade {
}
public <T extends Component> Either<T, StorageOperationStatus> getFullLatestComponentByToscaResourceName(String toscaResourceName) {
- return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, JsonParseFlagEnum.ParseAll);
+ ComponentParametersView fetchAllFilter = new ComponentParametersView();
+ fetchAllFilter.setIgnoreForwardingPath(true);
+ fetchAllFilter.setIgnoreCapabiltyProperties(false);
+ return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, JsonParseFlagEnum.ParseAll, fetchAllFilter);
}
public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName) {
@@ -448,7 +411,7 @@ public class ToscaOperationFacade {
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()) {
@@ -495,7 +458,7 @@ public class ToscaOperationFacade {
*
* @param newComponent
* @param oldComponent
- * @return
+ * @return vendor
*/
public Either<Resource, StorageOperationStatus> overrideComponent(Resource newComponent, Resource oldComponent) {
@@ -504,8 +467,6 @@ public class ToscaOperationFacade {
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);
@@ -584,6 +545,10 @@ public class ToscaOperationFacade {
}
private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName, JsonParseFlagEnum parseFlag) {
+ return getLatestByName(property, nodeName, parseFlag, new ComponentParametersView());
+ }
+
+ private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName, JsonParseFlagEnum parseFlag, ComponentParametersView filter) {
Either<T, StorageOperationStatus> result;
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
@@ -613,7 +578,7 @@ public class ToscaOperationFacade {
highestResource = vertex;
}
}
- return getToscaElementByOperation(highestResource);
+ return getToscaElementByOperation(highestResource, filter);
}
// endregion
@@ -688,6 +653,9 @@ public class ToscaOperationFacade {
}
return getToscaElementByOperation(getResourceRes.left().value().get(0));
}
+ public Either<List<CatalogComponent>, StorageOperationStatus> getCatalogComponents() {
+ return topologyTemplateOperation.getElementCatalogData();
+ }
// endregion
public <T extends Component> Either<List<T>, StorageOperationStatus> getCatalogComponents(ComponentTypeEnum componentType, List<OriginTypeEnum> excludeTypes, boolean isHighestVersions) {
@@ -804,7 +772,7 @@ public class ToscaOperationFacade {
if (StringUtils.isEmpty(componentInstance.getIcon())) {
componentInstance.setIcon(origComponent.getIcon());
}
- String nameToFindForCounter = componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy ? PROXY_SUFFIX : origComponent.getName();
+ String nameToFindForCounter = componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy ? componentInstance.getSourceModelName() + 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);
@@ -1413,8 +1381,6 @@ public class ToscaOperationFacade {
// 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);
@@ -1611,6 +1577,7 @@ public class ToscaOperationFacade {
break;
case "service":
case "pnf":
+ case "cr":
hasNotProps.put(GraphPropertyEnum.RESOURCE_TYPE, Arrays.asList(ResourceTypeEnum.VFC.name(), ResourceTypeEnum.VFCMT.name()));
break;
case "vl":
@@ -1685,13 +1652,37 @@ public class ToscaOperationFacade {
}
- public Either<List<Component>, StorageOperationStatus> getLatestComponentListByUuid(String componentUuid) {
+ private Either<List<Component>, StorageOperationStatus> getLatestComponentListByUuid(String componentUuid, Map<GraphPropertyEnum, Object> additionalPropertiesToMatch) {
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ if (additionalPropertiesToMatch != null) {
+ propertiesToMatch.putAll(additionalPropertiesToMatch);
+ }
propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
Either<List<Component>, StorageOperationStatus> componentListByUuid = getComponentListByUuid(componentUuid, propertiesToMatch);
return componentListByUuid;
}
+ public Either<Component, StorageOperationStatus> getComponentByUuidAndVersion(String componentUuid, String version) {
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+
+ propertiesToMatch.put(GraphPropertyEnum.UUID, componentUuid);
+ propertiesToMatch.put(GraphPropertyEnum.VERSION, version);
+
+ 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);
+ if (vertexEither.isRight()) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexEither.right().value()));
+ }
+
+ List<GraphVertex> vertexList = vertexEither.isLeft() ? vertexEither.left().value() : null;
+ if (vertexList == null || vertexList.isEmpty() || vertexList.size() > 1) {
+ return Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+
+ return getToscaElementByOperation(vertexList.get(0));
+ }
+
public Either<List<Component>, StorageOperationStatus> getComponentListByUuid(String componentUuid, Map<GraphPropertyEnum, Object> additionalPropertiesToMatch) {
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
@@ -1743,9 +1734,19 @@ public class ToscaOperationFacade {
return Either.left(latestComponents);
}
+ public Either<Component, StorageOperationStatus> getLatestServiceByUuid(String serviceUuid) {
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<>();
+ propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ return getLatestComponentByUuid(serviceUuid, propertiesToMatch);
+ }
+
public Either<Component, StorageOperationStatus> getLatestComponentByUuid(String componentUuid) {
+ return getLatestComponentByUuid(componentUuid, null);
+ }
+
+ public Either<Component, StorageOperationStatus> getLatestComponentByUuid(String componentUuid, Map<GraphPropertyEnum, Object> propertiesToMatch) {
- Either<List<Component>, StorageOperationStatus> latestVersionListEither = getLatestComponentListByUuid(componentUuid);
+ Either<List<Component>, StorageOperationStatus> latestVersionListEither = getLatestComponentListByUuid(componentUuid, propertiesToMatch);
if (latestVersionListEither.isRight()) {
return Either.right(latestVersionListEither.right().value());
@@ -1927,7 +1928,9 @@ public class ToscaOperationFacade {
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);
+ Map<GraphPropertyEnum, Object> propsHasNotToMatch = new HashMap<>();
+ propsHasNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+ Either<List<GraphVertex>, TitanOperationStatus> resourcesByTypeEither = titanDao.getByCriteria(null, props, propsHasNotToMatch, JsonParseFlagEnum.ParseMetadata);
if (resourcesByTypeEither.isRight()) {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(resourcesByTypeEither.right().value()));
@@ -2311,12 +2314,12 @@ public class ToscaOperationFacade {
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<GroupDefinition>, StorageOperationStatus> updateGroupsOnComponent(Component component, List<GroupDataDefinition> updatedGroups) {
+ return groupsOperation.updateGroups(component, updatedGroups);
}
public Either<List<GroupInstance>, StorageOperationStatus> updateGroupInstancesOnComponent(Component component, ComponentTypeEnum componentType, String instanceId, List<GroupInstance> updatedGroupInstances) {
- return groupsOperation.updateGroupInstances(component, componentType, instanceId, updatedGroupInstances);
+ return groupsOperation.updateGroupInstances(component, instanceId, updatedGroupInstances);
}
public StorageOperationStatus addGroupInstancesToComponentInstance(Component containerComponent, ComponentInstance componentInstance, List<GroupInstance> groupInstances) {
@@ -2368,6 +2371,17 @@ public class ToscaOperationFacade {
return nodeTemplateOperation.updateComponentInstanceCapabilityProperty(containerComponent, componentInstanceUniqueId, capabilityUniqueId, property);
}
+ public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceUniqueId) {
+ return convertComponentInstanceProperties(containerComponent, componentInstanceUniqueId)
+ .map(instanceCapProps -> topologyTemplateOperation.updateComponentInstanceCapabilityProperties(containerComponent, componentInstanceUniqueId, instanceCapProps))
+ .orElse(StorageOperationStatus.NOT_FOUND);
+ }
+
+ public StorageOperationStatus updateComponentCalculatedCapabilitiesProperties(Component containerComponent) {
+ Map<String, MapCapabiltyProperty> mapCapabiltyPropertyMap = convertComponentCapabilitiesProperties(containerComponent);
+ return nodeTemplateOperation.overrideComponentCapabilitiesProperties(containerComponent, mapCapabiltyPropertyMap);
+ }
+
public StorageOperationStatus deleteAllCalculatedCapabilitiesRequirements(String topologyTemplateId) {
StorageOperationStatus status = topologyTemplateOperation.removeToscaData(topologyTemplateId, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES);
if (status == StorageOperationStatus.OK) {
@@ -2402,15 +2416,94 @@ public class ToscaOperationFacade {
return Either.left(clonedResource);
}
/**
- * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name and type
+ * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
* @param componentId
* @param instanceId
* @param capabilityName
* @param capabilityType
+ * @param ownerId
* @return
*/
- public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType) {
- return topologyTemplateOperation.getComponentInstanceCapabilityProperties(componentId, instanceId, capabilityName, capabilityType);
+ public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
+ return topologyTemplateOperation.getComponentInstanceCapabilityProperties(componentId, instanceId, capabilityName, capabilityType, ownerId);
+ }
+
+ private Map<String, MapCapabiltyProperty> convertComponentCapabilitiesProperties(Component currComponent) {
+ return currComponent.getComponentInstances()
+ .stream()
+ .collect(Collectors.toMap(ComponentInstanceDataDefinition::getUniqueId,
+ ci -> ModelConverter.convertToMapOfMapCapabiltyProperties(ci.getCapabilities(), ci.getUniqueId(), true)));
+ }
+
+ private Optional<MapCapabiltyProperty> convertComponentInstanceProperties(Component component, String instanceId) {
+ return component.fetchInstanceById(instanceId)
+ .map(ci -> ModelConverter.convertToMapOfMapCapabiltyProperties(ci.getCapabilities(),instanceId));
}
+ public Either<PolicyDefinition, StorageOperationStatus> associatePolicyToComponent(String componentId, PolicyDefinition policyDefinition, int counter) {
+ Either<PolicyDefinition, StorageOperationStatus> result = null;
+ Either<GraphVertex, TitanOperationStatus> getVertexEither;
+ getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.ParseMetadata);
+ if (getVertexEither.isRight()) {
+ log.error("Couldn't fetch a component with and UniqueId {}, error: {}", componentId, getVertexEither.right().value());
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+ } else {
+ if(getVertexEither.left().value().getLabel() != VertexTypeEnum.TOPOLOGY_TEMPLATE){
+ log.error("Policy association to component of Tosca type {} is not allowed. ", getVertexEither.left().value().getLabel());
+ result = Either.right(StorageOperationStatus.BAD_REQUEST);
+ }
+ }
+ if(result == null){
+ StorageOperationStatus status = topologyTemplateOperation.addPolicyToToscaElement(getVertexEither.left().value(), policyDefinition, counter);
+ if(status != StorageOperationStatus.OK){
+ return Either.right(status);
+ }
+ }
+ if(result == null){
+ result = Either.left(policyDefinition);
+ }
+ return result;
+ }
+
+ public Either<PolicyDefinition, StorageOperationStatus> updatePolicyOfComponent(String componentId, PolicyDefinition policyDefinition) {
+ Either<PolicyDefinition, StorageOperationStatus> result = null;
+ Either<GraphVertex, TitanOperationStatus> getVertexEither;
+ getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.error("Couldn't fetch a component with and UniqueId {}, error: {}", componentId, getVertexEither.right().value());
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+ }
+ if(result == null){
+ StorageOperationStatus status = topologyTemplateOperation.updatePolicyOfToscaElement(getVertexEither.left().value(), policyDefinition);
+ if(status != StorageOperationStatus.OK){
+ return Either.right(status);
+ }
+ }
+ if(result == null){
+ result = Either.left(policyDefinition);
+ }
+ return result;
+ }
+
+ public StorageOperationStatus updatePoliciesOfComponent(String componentId, List<PolicyDefinition> policyDefinition) {
+ log.debug("#updatePoliciesOfComponent - updating policies for component {}", componentId);
+ return titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
+ .right()
+ .map(DaoStatusConverter::convertTitanStatusToStorageStatus)
+ .either(containerVertex -> topologyTemplateOperation.updatePoliciesOfToscaElement(containerVertex, policyDefinition),
+ err -> err);
+ }
+
+ public StorageOperationStatus removePolicyFromComponent(String componentId, String policyId) {
+ StorageOperationStatus status = null;
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.error("Couldn't fetch a component with and UniqueId {}, error: {}", componentId, getVertexEither.right().value());
+ status = DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
+ }
+ if(status == null){
+ status = topologyTemplateOperation.removePolicyFromToscaElement(getVertexEither.left().value(), policyId);
+ }
+ return status;
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/IdMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/IdMapper.java
new file mode 100644
index 0000000000..8c9d025a7b
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/IdMapper.java
@@ -0,0 +1,54 @@
+package org.openecomp.sdc.be.model.jsontitan.utils;
+
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
+import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
+import org.openecomp.sdc.be.model.jsontitan.operations.ExternalReferencesOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Created by yavivi on 12/02/2018.
+ */
+@Component
+public class IdMapper {
+
+ private static final Logger log = LoggerFactory.getLogger(ExternalReferencesOperation.class);
+
+ public String mapComponentNameToUniqueId(String componentInstanceName, GraphVertex serviceVertex) {
+ return map(componentInstanceName, serviceVertex, true);
+ }
+
+ public String mapUniqueIdToComponentNameTo(String compUniqueId, GraphVertex serviceVertex) {
+ return map(compUniqueId, serviceVertex, false);
+ }
+
+ private String map(String componentUniqueIdOrName, GraphVertex serviceVertex, boolean fromCompName) {
+ String result = null;
+ try {
+ Map<String, CompositionDataDefinition> jsonComposition = (Map<String, CompositionDataDefinition>) serviceVertex.getJson();
+ CompositionDataDefinition compositionDataDefinition = jsonComposition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
+
+ Optional<ComponentInstanceDataDefinition> componentInstanceDataDefinitionOptional = null;
+ if (fromCompName) {
+ componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values().stream().filter(c -> c.getNormalizedName().equals(componentUniqueIdOrName)).findAny();
+ result = componentInstanceDataDefinitionOptional.get().getUniqueId();
+ log.debug("Compponent Instance Unique Id = {}", result);
+ } else {
+ componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values().stream().filter(c -> c.getUniqueId().equals(componentUniqueIdOrName)).findAny();
+ result = componentInstanceDataDefinitionOptional.get().getNormalizedName();
+ log.debug("Compponent Instance Normalized Name = {}", result);
+ }
+
+ } catch (Exception e) {
+ log.error("Failed to map UUID or Normalized name of " + componentUniqueIdOrName, e);
+ }
+ return result;
+ }
+
+}
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 e89f63b12f..71f0b77902 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
@@ -40,6 +40,7 @@ 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.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
@@ -51,11 +52,13 @@ 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.PolicyDataDefinition;
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.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
@@ -70,6 +73,7 @@ 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.InterfaceDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RelationshipImpl;
import org.openecomp.sdc.be.model.RelationshipInfo;
@@ -82,6 +86,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.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
import org.openecomp.sdc.be.resources.data.ProductMetadataData;
import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
@@ -125,9 +130,10 @@ public class ModelConverter {
}
public static boolean isAtomicComponent(ResourceTypeEnum resourceType) {
- if (resourceType == null || resourceType == ResourceTypeEnum.VF || resourceType == ResourceTypeEnum.PNF || resourceType == ResourceTypeEnum.CVFC)
+ if (resourceType == null) {
return false;
- return true;
+ }
+ return resourceType.isAtomicType();
}
// **********************************************************
@@ -165,6 +171,16 @@ public class ModelConverter {
convertComponentInstances(topologyTemplate, service);
convertInputs(topologyTemplate, service);
+
+ convertPolicies(topologyTemplate, service);
+
+ convertGroups(topologyTemplate, service);
+
+ convertPolicies(topologyTemplate, service);
+
+ convertGroups(topologyTemplate, service);
+
+ convertPolicies(topologyTemplate, service);
convertRelations(topologyTemplate, service);
@@ -172,6 +188,8 @@ public class ModelConverter {
convertServiceApiArtifacts(topologyTemplate, service);
+ convertServicePaths(topologyTemplate, service);
+
return service;
}
@@ -210,6 +228,7 @@ public class ModelConverter {
convertRelations(topologyTemplate, resource);
convertInputs(topologyTemplate, resource);
convertGroups(topologyTemplate, resource);
+ convertPolicies(topologyTemplate, resource);
}
convertArtifacts(toscaElement, resource);
convertAdditionalInformation(toscaElement, resource);
@@ -505,19 +524,19 @@ public class ModelConverter {
resource.setVendorRelease((String) toscaElement.getMetadataValue(JsonPresentationFields.VENDOR_RELEASE));
// field isn't mandatory , but shouldn't be null(should be an empty string instead)
if (((String) toscaElement.getMetadataValue(JsonPresentationFields.RESOURCE_VENDOR_MODEL_NUMBER)) != null){
- resource.setResourceVendorModelNumber(((String) toscaElement.getMetadataValue(JsonPresentationFields.RESOURCE_VENDOR_MODEL_NUMBER)));
+ resource.setResourceVendorModelNumber((String) toscaElement.getMetadataValue(JsonPresentationFields.RESOURCE_VENDOR_MODEL_NUMBER));
} else {
resource.setResourceVendorModelNumber("");
}
} else if (component.getComponentType() == ComponentTypeEnum.SERVICE) {
Service service = (Service) component;
if (((String) toscaElement.getMetadataValue(JsonPresentationFields.SERVICE_TYPE)) != null){
- service.setServiceType(((String) toscaElement.getMetadataValue(JsonPresentationFields.SERVICE_TYPE)));
+ service.setServiceType((String) toscaElement.getMetadataValue(JsonPresentationFields.SERVICE_TYPE));
} else {
service.setServiceType("");
}
if (((String) toscaElement.getMetadataValue(JsonPresentationFields.SERVICE_ROLE)) != null){
- service.setServiceRole(((String) toscaElement.getMetadataValue(JsonPresentationFields.SERVICE_ROLE)));
+ service.setServiceRole((String) toscaElement.getMetadataValue(JsonPresentationFields.SERVICE_ROLE));
} else {
service.setServiceRole("");
}
@@ -633,6 +652,17 @@ public class ModelConverter {
}
service.setServiceApiArtifacts(copy);
}
+ private static void convertServicePaths(TopologyTemplate topologyTemplate, Service service) {
+ Map<String, ForwardingPathDataDefinition> servicePaths = topologyTemplate.getForwardingPaths();
+ Map<String, ForwardingPathDataDefinition> copy;
+ if (servicePaths != null) {
+ copy = servicePaths.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ForwardingPathDataDefinition(e.getValue())));
+
+ } else {
+ copy = new HashMap<>();
+ }
+ service.setForwardingPaths(copy);
+ }
private static void convertArtifacts(Component component, ToscaElement toscaElement) {
Map<String, ArtifactDefinition> artifacts = component.getArtifacts();
@@ -801,16 +831,33 @@ public class ModelConverter {
}
component.setGroups(groupDefinitions);
}
+
+ private static void convertPolicies(TopologyTemplate toscaElement, Component component) {
+ Map<String, PolicyDataDefinition> policies = toscaElement.getPolicies();
+ Map<String, PolicyDefinition> policyDefinitions = null;
+ if (MapUtils.isNotEmpty(policies)) {
+ policyDefinitions = policies.values().stream().map(p -> new PolicyDefinition(p)).collect(Collectors.toMap(p->p.getUniqueId(), p->p));
+ }
+ component.setPolicies(policyDefinitions);
+ }
private static void convertGroups(Component component, TopologyTemplate toscaElement) {
List<GroupDefinition> groupDefinitions = component.getGroups();
Map<String, GroupDataDefinition> groups = new HashMap<>();
if (groupDefinitions != null && groups.isEmpty()) {
- groups = groupDefinitions.stream().collect((Collectors.toMap(pr -> pr.getName(), pr -> new GroupDataDefinition(pr))));
+ groups = groupDefinitions.stream().collect(Collectors.toMap(pr -> pr.getName(), pr -> new GroupDataDefinition(pr)));
}
toscaElement.setGroups(groups);
-
+ }
+
+ private static void convertPolicies(Component component, TopologyTemplate toscaElement) {
+ Map<String, PolicyDefinition> policyDefinitions = component.getPolicies();
+ Map<String, PolicyDataDefinition> policies = new HashMap<>();
+ if (MapUtils.isNotEmpty(policyDefinitions)) {
+ policies = policyDefinitions.values().stream().collect((Collectors.toMap(p -> p.getUniqueId(), p -> new PolicyDataDefinition(p))));
+ }
+ toscaElement.setPolicies(policies);
}
private static void convertRequirements(NodeType toscaElement, Component component) {
@@ -863,6 +910,7 @@ public class ModelConverter {
convertInputs(component, topologyTemplate);
convertCapabilities(component, topologyTemplate);
convertGroups(component, topologyTemplate);
+ convertPolicies(component, topologyTemplate);
convertRequirements(component, topologyTemplate);
convertRelationsToComposition(component, topologyTemplate);
@@ -872,6 +920,15 @@ public class ModelConverter {
private static void convertServiceSpecificEntities(Service service, TopologyTemplate topologyTemplate) {
convertServiceMetaData(service, topologyTemplate);
convertServiceApiArtifacts(service, topologyTemplate);
+ convertServicePaths(service,topologyTemplate);
+ }
+
+ private static void convertServicePaths(Service service, TopologyTemplate topologyTemplate) {
+ Map<String, ForwardingPathDataDefinition> servicePaths = service.getForwardingPaths();
+ if (servicePaths != null && !servicePaths.isEmpty()) {
+ Map<String, ForwardingPathDataDefinition> copy = servicePaths.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ForwardingPathDataDefinition(e.getValue())));
+ topologyTemplate.setForwardingPaths(copy);
+ }
}
private static void convertServiceMetaData(Service service, TopologyTemplate topologyTemplate) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/StorageException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/StorageException.java
new file mode 100644
index 0000000000..de52101ec1
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/StorageException.java
@@ -0,0 +1,17 @@
+package org.openecomp.sdc.be.model.operations;
+
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+public class StorageException extends RuntimeException{
+
+ private final StorageOperationStatus storageOperationStatus;
+
+ public StorageException(StorageOperationStatus storageOperationStatus) {
+ super();
+ this.storageOperationStatus = storageOperationStatus;
+ }
+
+ public StorageOperationStatus getStorageOperationStatus() {
+ return storageOperationStatus;
+ }
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/DerivedFromOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/DerivedFromOperation.java
new file mode 100644
index 0000000000..0dc03ad363
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/DerivedFromOperation.java
@@ -0,0 +1,36 @@
+package org.openecomp.sdc.be.model.operations.api;
+
+import fj.data.Either;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+
+public interface DerivedFromOperation {
+
+ /**
+ *
+ * @param parentUniqueId the unique id of the object which is the parent of the derived from object
+ * @param derivedFromUniqueId the unique id of the derived from object
+ * @param nodeType the type of the derived from and its parent objects
+ * @return the status of the operation
+ */
+ Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(String parentUniqueId, String derivedFromUniqueId, NodeTypeEnum nodeType);
+
+ /**
+ *
+ * @param uniqueId the id of the entity of which to fetch its derived from object
+ * @param nodeType the type of the derived from object
+ * @param clazz the class which represent the derived from object
+ * @return the derived from object or error status of operation failed
+ */
+ <T extends GraphNode> Either<T, StorageOperationStatus> getDerivedFromChild(String uniqueId, NodeTypeEnum nodeType, Class<T> clazz);
+
+ /**
+ *
+ * @param uniqueId the id of the entity of which to remove its derived from object
+ * @param derivedFromUniqueId the unique id of the derived from object
+ * @param nodeType the type of the derived from and its parent objects
+ * @return the status of the remove operation. if no derived from relation exists the operation is successful.
+ */
+ StorageOperationStatus removeDerivedFromRelation(String uniqueId, String derivedFromUniqueId, NodeTypeEnum nodeType);
+}
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 90e01c3980..d4e5939173 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,12 +20,26 @@
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.RelationshipInfo;
+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/IGroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java
index 87a0dccfab..0fe50ff17a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java
@@ -35,6 +35,10 @@ public interface IGroupTypeOperation {
public Either<GroupTypeDefinition, StorageOperationStatus> addGroupType(GroupTypeDefinition groupTypeDefinition);
public Either<GroupTypeDefinition, StorageOperationStatus> addGroupType(GroupTypeDefinition groupTypeDefinition, boolean inTransaction);
+
+ public Either<GroupTypeDefinition, StorageOperationStatus> upgradeGroupType(GroupTypeDefinition groupTypeDefinitionNew, GroupTypeDefinition groupTypeDefinitionOld);
+
+ public Either<GroupTypeDefinition, StorageOperationStatus> upgradeGroupType(GroupTypeDefinition groupTypeDefinitionNew, GroupTypeDefinition groupTypeDefinitionOld, boolean inTransaction);
/**
* @param uniqueId
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
index d25d11331d..526cbd282d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,18 +20,20 @@
package org.openecomp.sdc.be.model.operations.api;
+import fj.data.Either;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
-import fj.data.Either;
+import java.util.List;
+import java.util.Set;
public interface IPolicyTypeOperation {
- Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String policyTypeName);
+ Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String policyTypeName);
- Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType(PolicyTypeDefinition policyType);
+ Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType(PolicyTypeDefinition policyType);
- Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyType(String uniqueId, boolean inTransaction);
+ Either<PolicyTypeDefinition, StorageOperationStatus> updatePolicyType(PolicyTypeDefinition updatedPolicyType, PolicyTypeDefinition currPolicyType);
- Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType(PolicyTypeDefinition policyType, boolean inTransaction);
+ Either<List<PolicyTypeDefinition>, StorageOperationStatus> getAllPolicyTypes(Set<String> excludedPolicyTypes);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java
index 3dd49f1aee..d1a51677fe 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java
@@ -20,15 +20,14 @@
package org.openecomp.sdc.be.model.operations.api;
-import java.util.Map;
-
+import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.IComplexDefaultValue;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import fj.data.Either;
+import java.util.Map;
public interface IPropertyOperation {
@@ -41,6 +40,14 @@ public interface IPropertyOperation {
*/
public Either<Map<String, PropertyDefinition>, StorageOperationStatus> deleteAllPropertiesAssociatedToNode(NodeTypeEnum nodeType, String uniqueId);
+ /**
+ * same as deleteAllPropertiesAssociatedToNode but returns empty map if node has no properties
+ * @param nodeType
+ * @param uniqueId
+ * @return
+ */
+ Either<Map<String, PropertyDefinition>, StorageOperationStatus> deletePropertiesAssociatedToNode(NodeTypeEnum nodeType, String uniqueId);
+
public boolean isPropertyDefaultValueValid(IComplexDefaultValue propertyDefinition, Map<String, DataTypeDefinition> dataTypes);
public boolean isPropertyTypeValid(IComplexDefaultValue propertyDefinition);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AdditionalInformationOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AdditionalInformationOperation.java
index b9a67e5dc6..24e4b48793 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AdditionalInformationOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AdditionalInformationOperation.java
@@ -116,7 +116,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
if (updateNode.isRight()) {
TitanOperationStatus status = updateNode.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedUpdateNodeError, "UpdateAdditionalInformationParameter", "additional information of " + nodeType.getName() + " " + componentId, String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedUpdateNodeError("UpdateAdditionalInformationParameter", "additional information of " + nodeType.getName() + " " + componentId, String.valueOf(status));
return Either.right(status);
}
@@ -168,7 +167,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
if (updateNode.isRight()) {
TitanOperationStatus status = updateNode.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedUpdateNodeError, "UpdateAdditionalInformationParameter", "additional information of resource " + componentId, String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedUpdateNodeError("UpdateAdditionalInformationParameter", "additional information of resource " + componentId, String.valueOf(status));
return Either.right(status);
}
@@ -213,7 +211,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
if (updateNode.isRight()) {
TitanOperationStatus status = updateNode.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedUpdateNodeError, "DeleteAdditionalInformationParameter", "additional information of " + nodeType.getName() + " " + componentId, String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedUpdateNodeError("DeleteAdditionalInformationParameter", "additional information of " + nodeType.getName() + " " + componentId, String.valueOf(status));
return Either.right(status);
}
@@ -266,7 +263,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
Either<AdditionalInfoParameterData, TitanOperationStatus> createNode = titanGenericDao.createNode(additionalInfoParameterData, AdditionalInfoParameterData.class);
if (createNode.isRight()) {
TitanOperationStatus status = createNode.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedCreateNodeError, "AddAdditionalInformationNode", "additional information to " + nodeType.getName() + " " + componentId, String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedCreateNodeError("AddAdditionalInformationNode", uniqueId, String.valueOf(status));
return Either.right(status);
}
@@ -294,7 +290,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
Either<TitanVertex, TitanOperationStatus> createNode = titanGenericDao.createNode(additionalInfoParameterData);
if (createNode.isRight()) {
TitanOperationStatus status = createNode.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedCreateNodeError, "AddAdditionalInformationNode", "additional information to " + nodeType.getName() + " " + componentId, String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedCreateNodeError("AddAdditionalInformationNode", uniqueId, String.valueOf(status));
return Either.right(status);
}
@@ -498,7 +493,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
if (either.isRight()) {
TitanOperationStatus status = either.right().value();
log.debug("Failed to add additional information property {} to component {}. Status is {}", key, resourceId, status);
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedUpdateNodeError, "additional information of " + nodeType.getName() + " " + resourceId, String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedUpdateNodeError("CreateAdditionalInformationParameter", "additional information of " + nodeType.getName() + " " + resourceId, String.valueOf(status));
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
} else {
@@ -654,7 +648,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
if (updateNode.isRight()) {
TitanOperationStatus status = updateNode.right().value();
if (status != TitanOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedRetrieveNodeError, "GetAdditionnalInformationParameter", "additional information of " + nodeType.getName() + " " + componentId, String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedRetrieveNodeError("GetAdditionnalInformationParameter", "additional information of " + nodeType.getName() + " " + componentId, String.valueOf(status));
}
return Either.right(status);
@@ -682,7 +675,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
if (getResult.isRight()) {
TitanOperationStatus status = getResult.right().value();
if (status != TitanOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedRetrieveNodeError, "GetAdditionnalInformationParameters", "additional information of " + nodeType.getName() + " " + componentId, String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedRetrieveNodeError("GetAdditionnalInformationParameters", "additional information of " + nodeType.getName() + " " + componentId, String.valueOf(status));
}
return Either.right(status);
@@ -789,7 +781,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
if (status == TitanOperationStatus.NOT_FOUND) {
return Either.right(StorageOperationStatus.OK);
} else {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedDeleteNodeError, "DeleteAdditionalInformationNode", "additional information of " + nodeType.getName() + " " + resourceId, String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedDeleteNodeError("DeleteAdditionalInformationNode", "additional information of " + nodeType.getName() + " " + resourceId, String.valueOf(status));
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
@@ -802,7 +793,6 @@ public class AdditionalInformationOperation implements IAdditionalInformationOpe
Either<AdditionalInfoParameterData, TitanOperationStatus> deleteNodeRes = titanGenericDao.deleteNode(parameterData, AdditionalInfoParameterData.class);
if (deleteNodeRes.isRight()) {
TitanOperationStatus status = getResult.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedDeleteNodeError, "DeleteAdditionalInformationNode", (String) parameterData.getUniqueId(), String.valueOf(status));
BeEcompErrorManager.getInstance().logBeFailedDeleteNodeError("DeleteAdditionalInformationNode", (String) parameterData.getUniqueId(), String.valueOf(status));
result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
return result;
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 9ef116d0c9..10cd30cbe5 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
@@ -165,8 +165,6 @@ public class ArtifactOperation implements IArtifactOperation {
if (createNodeResult.isRight()) {
TitanOperationStatus operationStatus = createNodeResult.right().value();
log.debug("Failed to add artifact {} to graph. status is {}", artifactData.getArtifactDataDefinition().getArtifactName(), operationStatus);
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedCreateNodeError, "Failed to add artifact " + artifactData.getArtifactDataDefinition().getArtifactName() + " to graph. status is " + operationStatus,
- artifactData.getArtifactDataDefinition().getArtifactName(), String.valueOf(operationStatus));
BeEcompErrorManager.getInstance().logBeFailedCreateNodeError("Add artifact", artifactData.getArtifactDataDefinition().getArtifactName(), String.valueOf(operationStatus));
return DaoStatusConverter.convertTitanStatusToStorageStatus(operationStatus);
}
@@ -229,8 +227,6 @@ public class ArtifactOperation implements IArtifactOperation {
if (createNodeResult.isRight()) {
TitanOperationStatus operationStatus = createNodeResult.right().value();
log.debug("Failed to add artifact {} to graph. status is {}", artifactData.getArtifactDataDefinition().getArtifactName(), operationStatus);
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedCreateNodeError, "Failed to add artifact " + artifactData.getArtifactDataDefinition().getArtifactName() + " to graph. status is " + operationStatus,
- artifactData.getArtifactDataDefinition().getArtifactName(), String.valueOf(operationStatus));
BeEcompErrorManager.getInstance().logBeFailedCreateNodeError("Add artifact", artifactData.getArtifactDataDefinition().getArtifactName(), String.valueOf(operationStatus));
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(operationStatus));
}
@@ -309,8 +305,6 @@ public class ArtifactOperation implements IArtifactOperation {
titanGenericDao.rollback();
}
log.debug("Failed to update artifact {} of {} {}. status is {}", artifactId, type.getName(), id, status.right().value());
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedUpdateNodeError, "Failed to update artifact " + artifactId + " of " + type.getName() + " " + id + ". status is" + status.right().value(), artifactId,
- String.valueOf(status.right().value()));
BeEcompErrorManager.getInstance().logBeFailedUpdateNodeError("Update Artifact", artifactId, String.valueOf(status.right().value()));
return Either.right(status.right().value());
} else {
@@ -335,7 +329,6 @@ public class ArtifactOperation implements IArtifactOperation {
}
log.debug("Failed to delete artifact {} of resource {}", artifactId, id);
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedDeleteNodeError, "Failed to delete artifact " + artifactId + " of resource " + id, artifactId, String.valueOf(status.right().value()));
BeEcompErrorManager.getInstance().logBeFailedDeleteNodeError("Delete Artifact", artifactId, String.valueOf(status.right().value()));
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status.right().value()));
} else {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java
index 203135b31e..9b31c71787 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java
@@ -32,6 +32,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
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.enums.NodeTypeEnum;
@@ -253,6 +254,21 @@ public class CapabilityTypeOperation extends AbstractOperation implements ICapab
}
}
}
+
+
+ public Either<CapabilityTypeData, TitanOperationStatus> getCapabilityTypeByType(String capabilityType) {
+ Either<CapabilityTypeData, TitanOperationStatus> capabilityTypesRes = titanGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), capabilityType, CapabilityTypeData.class);
+
+ if (capabilityTypesRes.isRight()) {
+ TitanOperationStatus status = capabilityTypesRes.right().value();
+ log.debug("Capability type {} cannot be found in graph. status is {}", capabilityType, status);
+
+ return Either.right(status);
+ }
+
+ CapabilityTypeData ctData = capabilityTypesRes.left().value();
+ return Either.left(ctData);
+ }
/**
* Build Capability type object from graph by unique id
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 88edb1fd9e..e81264ab59 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
@@ -25,9 +25,9 @@ import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Map;
+import java.util.Map.Entry;
import javax.annotation.PostConstruct;
-
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import fj.data.Either;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DefaultDerivedFromOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DefaultDerivedFromOperation.java
new file mode 100644
index 0000000000..fc78ada054
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DefaultDerivedFromOperation.java
@@ -0,0 +1,67 @@
+package org.openecomp.sdc.be.model.operations.impl;
+
+import fj.data.Either;
+import org.apache.commons.lang3.tuple.Pair;
+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.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.UniqueIdData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DefaultDerivedFromOperation implements DerivedFromOperation {
+
+ private static final Logger log = LoggerFactory.getLogger(DefaultDerivedFromOperation.class);
+ private TitanGenericDao titanGenericDao;
+
+ public DefaultDerivedFromOperation(TitanGenericDao titanGenericDao) {
+ this.titanGenericDao = titanGenericDao;
+ }
+
+ @Override
+ public Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(String parentUniqueId, String derivedFromUniqueId, NodeTypeEnum nodeType) {
+ UniqueIdData from = new UniqueIdData(NodeTypeEnum.PolicyType, parentUniqueId);
+ UniqueIdData to = new UniqueIdData(NodeTypeEnum.PolicyType, derivedFromUniqueId);
+ return titanGenericDao.createRelation(from, to, GraphEdgeLabels.DERIVED_FROM, null)
+ .right()
+ .map(DaoStatusConverter::convertTitanStatusToStorageStatus);
+ }
+
+ @Override
+ public <T extends GraphNode> Either<T, StorageOperationStatus> getDerivedFromChild(String uniqueId, NodeTypeEnum nodeType, Class<T> clazz) {
+ log.debug("#getDerivedFromChild - fetching derived from entity for node type {} with id {}", nodeType, uniqueId);
+ return titanGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(nodeType), uniqueId, GraphEdgeLabels.DERIVED_FROM, nodeType, clazz)
+ .bimap(Pair::getKey,
+ DaoStatusConverter::convertTitanStatusToStorageStatus);
+ }
+
+ @Override
+ public StorageOperationStatus removeDerivedFromRelation(String uniqueId, String derivedFromUniqueId, NodeTypeEnum nodeType) {
+ UniqueIdData from = new UniqueIdData(NodeTypeEnum.PolicyType, uniqueId);
+ UniqueIdData to = new UniqueIdData(NodeTypeEnum.PolicyType, derivedFromUniqueId);
+ return isDerivedFromExists(from, to)
+ .either(isRelationExist -> isRelationExist ? deleteDerivedFrom(from, to) : StorageOperationStatus.OK,
+ DaoStatusConverter::convertTitanStatusToStorageStatus);
+
+
+ }
+
+ private StorageOperationStatus deleteDerivedFrom(UniqueIdData from, UniqueIdData to) {
+ return titanGenericDao.deleteRelation(from, to, GraphEdgeLabels.DERIVED_FROM)
+ .either(deletedRelation -> StorageOperationStatus.OK,
+ DaoStatusConverter::convertTitanStatusToStorageStatus);
+ }
+
+ private Either<Boolean, TitanOperationStatus> isDerivedFromExists(UniqueIdData from, UniqueIdData to) {
+ return titanGenericDao.isRelationExist(from, to, GraphEdgeLabels.DERIVED_FROM);
+ }
+
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
index 413ce4c2fa..e9236fc9af 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,15 +20,15 @@
package org.openecomp.sdc.be.model.operations.impl;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import com.google.common.base.Strings;
+import com.thinkaurelius.titan.graphdb.query.TitanPredicate;
+import fj.data.Either;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
+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;
@@ -38,318 +38,450 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.CapabilityTypeData;
import org.openecomp.sdc.be.resources.data.GroupTypeData;
import org.openecomp.sdc.be.resources.data.PropertyData;
+import org.openecomp.sdc.be.resources.data.UniqueIdData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
-import fj.data.Either;
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.dao.titan.TitanUtils.buildNotInPredicate;
@Component("group-type-operation")
public class GroupTypeOperation extends AbstractOperation implements IGroupTypeOperation {
+ @Resource
+ private CapabilityTypeOperation capabilityTypeOperation;
+
+ private static final Logger log = LoggerFactory.getLogger(GroupTypeOperation.class);
- String CREATE_FLOW_CONTEXT = "CreateGroupType";
- String GET_FLOW_CONTEXT = "GetGroupType";
+ private static final String CREATE_FLOW_CONTEXT = "CreateGroupType";
+ private static final String GET_FLOW_CONTEXT = "GetGroupType";
- private PropertyOperation propertyOperation;
-
- private TitanGenericDao titanGenericDao;
+ private PropertyOperation propertyOperation;
- public GroupTypeOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao, @Qualifier("property-operation")PropertyOperation propertyOperation) {
- super();
- this.propertyOperation = propertyOperation;
- this.titanGenericDao = titanGenericDao;
- }
+ private TitanGenericDao titanGenericDao;
- private static Logger log = LoggerFactory.getLogger(GroupTypeOperation.class.getName());
+ public GroupTypeOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao, @Qualifier("property-operation") PropertyOperation propertyOperation) {
+ super();
+ this.propertyOperation = propertyOperation;
+ this.titanGenericDao = titanGenericDao;
+ }
- /**
- * FOR TEST ONLY
- *
- * @param titanGenericDao
- */
- public void setTitanGenericDao(TitanGenericDao titanGenericDao) {
- this.titanGenericDao = titanGenericDao;
- }
+ /**
+ * FOR TEST ONLY
+ *
+ * @param titanGenericDao
+ */
+ public void setTitanGenericDao(TitanGenericDao titanGenericDao) {
+ this.titanGenericDao = titanGenericDao;
+ }
- @Override
- public Either<GroupTypeDefinition, StorageOperationStatus> addGroupType(GroupTypeDefinition groupTypeDefinition) {
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> addGroupType(GroupTypeDefinition groupTypeDefinition) {
- return addGroupType(groupTypeDefinition, false);
- }
+ return addGroupType(groupTypeDefinition, false);
+ }
- @Override
- public Either<GroupTypeDefinition, StorageOperationStatus> addGroupType(GroupTypeDefinition groupTypeDefinition, boolean inTransaction) {
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> addGroupType(GroupTypeDefinition groupTypeDefinition, boolean inTransaction) {
- Either<GroupTypeDefinition, StorageOperationStatus> result = null;
+ Either<GroupTypeDefinition, StorageOperationStatus> result = null;
- try {
+ try {
- Either<GroupTypeData, TitanOperationStatus> eitherStatus = addGroupTypeToGraph(groupTypeDefinition);
+ Either<GroupTypeData, TitanOperationStatus> eitherStatus = addGroupTypeToGraph(groupTypeDefinition);
- if (eitherStatus.isRight()) {
- BeEcompErrorManager.getInstance().logBeFailedCreateNodeError(CREATE_FLOW_CONTEXT, groupTypeDefinition.getType(), eitherStatus.right().value().name());
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(eitherStatus.right().value()));
+ if (eitherStatus.isRight()) {
+ BeEcompErrorManager.getInstance().logBeFailedCreateNodeError(CREATE_FLOW_CONTEXT, groupTypeDefinition.getType(), eitherStatus.right().value().name());
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(eitherStatus.right().value()));
- } else {
- GroupTypeData groupTypeData = eitherStatus.left().value();
+ } else {
+ GroupTypeData groupTypeData = eitherStatus.left().value();
- String uniqueId = groupTypeData.getUniqueId();
- Either<GroupTypeDefinition, StorageOperationStatus> groupTypeRes = this.getGroupType(uniqueId, true);
+ String uniqueId = groupTypeData.getUniqueId();
+ Either<GroupTypeDefinition, StorageOperationStatus> groupTypeRes = this.getGroupType(uniqueId, true);
- if (groupTypeRes.isRight()) {
- BeEcompErrorManager.getInstance().logBeFailedRetrieveNodeError(GET_FLOW_CONTEXT, groupTypeDefinition.getType(), eitherStatus.right().value().name());
- }
+ if (groupTypeRes.isRight()) {
+ BeEcompErrorManager.getInstance().logBeFailedRetrieveNodeError(GET_FLOW_CONTEXT, groupTypeDefinition.getType(), eitherStatus.right().value().name());
+ } else {
+ List<CapabilityTypeDefinition> groupCapTypes = groupTypeDefinition.getCapabilityTypes();
+ if (!CollectionUtils.isEmpty(groupCapTypes)) {
+ Optional<TitanOperationStatus> firstFailure = connectToCapabilityType(groupTypeData, groupCapTypes);
+ if (firstFailure.isPresent()) {
+ groupTypeRes = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(firstFailure.get()));
+ }
+ }
+ }
- result = groupTypeRes;
+ result = groupTypeRes;
- }
+ }
- return result;
+ return result;
- } finally {
- handleTransactionCommitRollback(inTransaction, result);
- }
+ } finally {
+ handleTransactionCommitRollback(inTransaction, result);
+ }
- }
+ }
- public Either<GroupTypeDefinition, TitanOperationStatus> getGroupTypeByUid(String uniqueId) {
- Either<GroupTypeDefinition, TitanOperationStatus> result = null;
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> upgradeGroupType(GroupTypeDefinition groupTypeDefinitionNew, GroupTypeDefinition groupTypeDefinitionOld) {
+ return upgradeGroupType(groupTypeDefinitionOld, groupTypeDefinitionNew, false);
+ }
- Either<GroupTypeData, TitanOperationStatus> groupTypesRes = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.GroupType), uniqueId, GroupTypeData.class);
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> upgradeGroupType(GroupTypeDefinition groupTypeDefinitionNew, GroupTypeDefinition groupTypeDefinitionOld, boolean inTransaction) {
+ Either<GroupTypeDefinition, StorageOperationStatus> result = Either.left(groupTypeDefinitionNew);
- if (groupTypesRes.isRight()) {
- TitanOperationStatus status = groupTypesRes.right().value();
- log.debug("Group type {} cannot be found in graph. status is {}", uniqueId, status);
- return Either.right(status);
- }
+ try {
+ // dr2032:
+ // Right now upgrade Group is used only to ensure that already existing group type is connected by DERRIVED_FROM edge with it's parent
+ // We don't need to use for a while new node definition since following group type upgrade is not supported.
+ if (!Strings.isNullOrEmpty(groupTypeDefinitionOld.getDerivedFrom())) {
+ result = ensureExsitanceDerivedFromEdge(groupTypeDefinitionOld);
+ }
+ } finally {
+ handleTransactionCommitRollback(inTransaction, result);
+ }
- GroupTypeData gtData = groupTypesRes.left().value();
- GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(gtData.getGroupTypeDataDefinition());
+ return result;
+ }
- TitanOperationStatus propertiesStatus = propertyOperation.fillProperties(uniqueId, properList -> groupTypeDefinition.setProperties(properList));
+ private Optional<TitanOperationStatus> connectToCapabilityType(GroupTypeData groupTypeData, List<CapabilityTypeDefinition> groupCapTypes) {
+ return groupCapTypes.stream()
+ .map(groupCapTypeDef -> connectTo(groupTypeData, groupCapTypeDef))
+ .filter(Either::isRight)
+ .findFirst()
+ .map(either -> either.right().value());
+ }
- if (propertiesStatus != TitanOperationStatus.OK) {
- log.error("Failed to fetch properties of capability type {}", uniqueId);
- return Either.right(propertiesStatus);
- }
+ private Either<GraphRelation, TitanOperationStatus> connectTo(GroupTypeData groupTypeData, CapabilityTypeDefinition groupCapTypeDef) {
+ Either<CapabilityTypeData, TitanOperationStatus> eitherCapData = capabilityTypeOperation.getCapabilityTypeByType(groupCapTypeDef.getType());
+ if (eitherCapData.isLeft()) {
+ return titanGenericDao.createRelation(groupTypeData, eitherCapData.left().value(), GraphEdgeLabels.GROUP_TYPE_CAPABILITY_TYPE, null);
+ }
- result = Either.left(groupTypeDefinition);
+ return Either.right(eitherCapData.right().value());
+ }
- return result;
- }
+ public List<GroupTypeDefinition> getAllGroupTypes(Set<String> excludedGroupTypes) {
+ Map<String, Map.Entry<TitanPredicate, Object>> predicateCriteria = buildNotInPredicate(GraphPropertiesDictionary.TYPE.getProperty(), excludedGroupTypes);
+ List<GroupTypeData> groupTypes = titanGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.GroupType, predicateCriteria, GroupTypeData.class)
+ .left()
+ .on(this::onTitanAccessError);
- @Override
- public Either<GroupTypeDefinition, StorageOperationStatus> getGroupType(String uniqueId) {
+ return convertGroupTypesToDefinition(groupTypes);
+ }
- return getGroupType(uniqueId, false);
- }
+ private List<GroupTypeDefinition> convertGroupTypesToDefinition(List<GroupTypeData> groupTypes) {
+ return groupTypes.stream()
+ .map(type -> new GroupTypeDefinition(type.getGroupTypeDataDefinition()))
+ .collect(Collectors.toList());
+ }
- @Override
- public Either<GroupTypeDefinition, StorageOperationStatus> getGroupType(String uniqueId, boolean inTransaction) {
- return getElementType(this::getGroupTypeByUid, uniqueId, inTransaction);
- }
+ private List<GroupTypeData> onTitanAccessError(TitanOperationStatus toe) {
+ throw new StorageException(
+ DaoStatusConverter.convertTitanStatusToStorageStatus(toe));
+ }
- @Override
- public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type) {
- return getLatestGroupTypeByType(type, false);
- }
- @Override
- public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type, boolean inTransaction) {
- Map<String, Object> mapCriteria = new HashMap<>();
- mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
- mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
+ public Either<GroupTypeDefinition, TitanOperationStatus> getGroupTypeByUid(String uniqueId) {
+
+ Either<GroupTypeDefinition, TitanOperationStatus> result = null;
+
+ Either<GroupTypeData, TitanOperationStatus> groupTypesRes = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.GroupType), uniqueId, GroupTypeData.class);
+
+ if (groupTypesRes.isRight()) {
+ TitanOperationStatus status = groupTypesRes.right().value();
+ log.debug("Group type {} cannot be found in graph. status is {}", uniqueId, status);
+ return Either.right(status);
+ }
+
+ GroupTypeData gtData = groupTypesRes.left().value();
+ GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(gtData.getGroupTypeDataDefinition());
+
+ TitanOperationStatus propertiesStatus = propertyOperation.fillProperties(uniqueId, NodeTypeEnum.GroupType, properList -> groupTypeDefinition.setProperties(properList));
+
+ if (propertiesStatus != TitanOperationStatus.OK) {
+ log.error("Failed to fetch properties of capability type {}", uniqueId);
+ return Either.right(propertiesStatus);
+ }
- return getGroupTypeByCriteria(type, mapCriteria, inTransaction);
+ result = Either.left(groupTypeDefinition);
- }
+ return result;
+ }
- public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByCriteria(String type, Map<String, Object> properties, boolean inTransaction) {
- Either<GroupTypeDefinition, StorageOperationStatus> result = null;
- try {
- if (type == null || type.isEmpty()) {
- log.error("type is empty");
- result = Either.right(StorageOperationStatus.INVALID_ID);
- return result;
- }
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> getGroupType(String uniqueId) {
+
+ return getGroupType(uniqueId, false);
+
+ }
+
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> getGroupType(String uniqueId, boolean inTransaction) {
+ return getElementType(this::getGroupTypeByUid, uniqueId, inTransaction);
+ }
+
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type) {
+ return getLatestGroupTypeByType(type, false);
+ }
+
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type, boolean inTransaction) {
+ Map<String, Object> mapCriteria = new HashMap<>();
+ mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
+ mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
+
+ return getGroupTypeByCriteria(type, mapCriteria, inTransaction);
+
+ }
- Either<List<GroupTypeData>, TitanOperationStatus> groupTypeEither = titanGenericDao.getByCriteria(NodeTypeEnum.GroupType, properties, GroupTypeData.class);
- if (groupTypeEither.isRight()) {
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(groupTypeEither.right().value()));
- } else {
- GroupTypeDataDefinition dataDefinition = groupTypeEither.left().value().stream().map(e -> e.getGroupTypeDataDefinition()).findFirst().get();
- result = getGroupType(dataDefinition.getUniqueId(), inTransaction);
- }
+ public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByCriteria(String type, Map<String, Object> properties, boolean inTransaction) {
+ Either<GroupTypeDefinition, StorageOperationStatus> result = null;
+ try {
+ if (type == null || type.isEmpty()) {
+ log.error("type is empty");
+ result = Either.right(StorageOperationStatus.INVALID_ID);
+ return result;
+ }
+
+ Either<List<GroupTypeData>, TitanOperationStatus> groupTypeEither = titanGenericDao.getByCriteria(NodeTypeEnum.GroupType, properties, GroupTypeData.class);
+ if (groupTypeEither.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(groupTypeEither.right().value()));
+ } else {
+ GroupTypeDataDefinition dataDefinition = groupTypeEither.left().value().stream().map(e -> e.getGroupTypeDataDefinition()).findFirst().get();
+ result = getGroupType(dataDefinition.getUniqueId(), inTransaction);
+ }
- return result;
+ return result;
- } finally {
- handleTransactionCommitRollback(inTransaction, result);
- }
- }
+ } finally {
+ handleTransactionCommitRollback(inTransaction, result);
+ }
+ }
- @Override
- public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version) {
- return getGroupTypeByTypeAndVersion(type, version, false);
- }
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version) {
+ return getGroupTypeByTypeAndVersion(type, version, false);
+ }
- @Override
- public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version, boolean inTransaction) {
- Map<String, Object> mapCriteria = new HashMap<>();
- mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
- mapCriteria.put(GraphPropertiesDictionary.VERSION.getProperty(), version);
-
- return getGroupTypeByCriteria(type, mapCriteria, inTransaction);
- }
-
- /**
- *
- * Add group type to graph.
- *
- * 1. Add group type node
- *
- * 2. Add edge between the former node to its parent(if exists)
- *
- * 3. Add property node and associate it to the node created at #1. (per property & if exists)
- *
- * @param groupTypeDefinition
- * @return
- */
- private Either<GroupTypeData, TitanOperationStatus> addGroupTypeToGraph(GroupTypeDefinition groupTypeDefinition) {
-
- log.debug("Got group type {}", groupTypeDefinition);
-
- String ctUniqueId = UniqueIdBuilder.buildGroupTypeUid(groupTypeDefinition.getType(), groupTypeDefinition.getVersion());
- // capabilityTypeDefinition.setUniqueId(ctUniqueId);
-
- GroupTypeData groupTypeData = buildGroupTypeData(groupTypeDefinition, ctUniqueId);
-
- log.debug("Before adding group type to graph. groupTypeData = {}", groupTypeData);
-
- Either<GroupTypeData, TitanOperationStatus> createGTResult = titanGenericDao.createNode(groupTypeData, GroupTypeData.class);
- log.debug("After adding group type to graph. status is = {}", createGTResult);
-
- if (createGTResult.isRight()) {
- TitanOperationStatus operationStatus = createGTResult.right().value();
- log.error("Failed to add group type {} to graph. status is {}", groupTypeDefinition.getType(), operationStatus);
- return Either.right(operationStatus);
- }
-
- GroupTypeData resultCTD = createGTResult.left().value();
- List<PropertyDefinition> properties = groupTypeDefinition.getProperties();
- Either<Map<String, PropertyData>, TitanOperationStatus> addPropertiesToCapablityType = propertyOperation.addPropertiesToElementType(resultCTD.getUniqueId(), NodeTypeEnum.GroupType, properties);
- if (addPropertiesToCapablityType.isRight()) {
- log.error("Failed add properties {} to capability {}", properties, groupTypeDefinition.getType());
- return Either.right(addPropertiesToCapablityType.right().value());
- }
-
- String derivedFrom = groupTypeDefinition.getDerivedFrom();
- if (derivedFrom != null) {
-
- // TODO: Need to find the parent. need to take the latest one since
- // we may have many versions of the same type
- /*
- * log.debug("Before creating relation between group type {} to its parent {}", ctUniqueId, derivedFrom); UniqueIdData from = new UniqueIdData(NodeTypeEnum.CapabilityType, ctUniqueId); UniqueIdData to = new
- * UniqueIdData(NodeTypeEnum.CapabilityType, derivedFrom); Either<GraphRelation, TitanOperationStatus> createRelation = titanGenericDao .createRelation(from, to, GraphEdgeLabels.DERIVED_FROM, null);
- * log.debug("After create relation between capability type {} to its parent {}. status is {}", ctUniqueId, derivedFrom, createRelation); if (createRelation.isRight()) { return Either.right(createRelation.right().value()); }
- *
- */
- }
-
- return Either.left(createGTResult.left().value());
-
- }
-
- /**
- *
- * convert between graph Node object to Java object
- *
- * @param capabilityTypeData
- * @return
- */
- protected CapabilityTypeDefinition convertCTDataToCTDefinition(CapabilityTypeData capabilityTypeData) {
- log.debug("The object returned after create capability is {}", capabilityTypeData);
-
- CapabilityTypeDefinition capabilityTypeDefResult = new CapabilityTypeDefinition(capabilityTypeData.getCapabilityTypeDataDefinition());
-
- return capabilityTypeDefResult;
- }
-
- private GroupTypeData buildGroupTypeData(GroupTypeDefinition groupTypeDefinition, String ctUniqueId) {
-
- GroupTypeData groupTypeData = new GroupTypeData(groupTypeDefinition);
-
- groupTypeData.getGroupTypeDataDefinition().setUniqueId(ctUniqueId);
- Long creationDate = groupTypeData.getGroupTypeDataDefinition().getCreationTime();
- if (creationDate == null) {
- creationDate = System.currentTimeMillis();
- }
- groupTypeData.getGroupTypeDataDefinition().setCreationTime(creationDate);
- groupTypeData.getGroupTypeDataDefinition().setModificationTime(creationDate);
-
- return groupTypeData;
- }
-
- public Either<Boolean, StorageOperationStatus> isCapabilityTypeDerivedFrom(String childCandidateType, String parentCandidateType) {
- Map<String, Object> propertiesToMatch = new HashMap<String, Object>();
- propertiesToMatch.put(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.CapabilityType), childCandidateType);
- Either<List<CapabilityTypeData>, TitanOperationStatus> getResponse = titanGenericDao.getByCriteria(NodeTypeEnum.CapabilityType, propertiesToMatch, CapabilityTypeData.class);
- if (getResponse.isRight()) {
- TitanOperationStatus titanOperationStatus = getResponse.right().value();
- log.debug("Couldn't fetch capability type {}, error: {}", childCandidateType, titanOperationStatus);
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(titanOperationStatus));
- }
- String childUniqueId = getResponse.left().value().get(0).getUniqueId();
- Set<String> travelledTypes = new HashSet<>();
- do {
- travelledTypes.add(childUniqueId);
- Either<List<ImmutablePair<CapabilityTypeData, GraphEdge>>, TitanOperationStatus> childrenNodes = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.CapabilityType), childUniqueId, GraphEdgeLabels.DERIVED_FROM,
- NodeTypeEnum.CapabilityType, CapabilityTypeData.class);
- if (childrenNodes.isRight()) {
- if (childrenNodes.right().value() != TitanOperationStatus.NOT_FOUND) {
- TitanOperationStatus titanOperationStatus = getResponse.right().value();
- log.debug("Couldn't fetch derived from node for capability type {}, error: {}", childCandidateType, titanOperationStatus);
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(titanOperationStatus));
- } else {
- log.debug("Derived from node is not found for type {} - this is OK for root capability.");
- return Either.left(false);
- }
- }
- String derivedFromUniqueId = childrenNodes.left().value().get(0).getLeft().getUniqueId();
- if (derivedFromUniqueId.equals(parentCandidateType)) {
- log.debug("Verified that capability type {} derives from capability type {}", childCandidateType, parentCandidateType);
- return Either.left(true);
- }
- childUniqueId = derivedFromUniqueId;
- } while (!travelledTypes.contains(childUniqueId));
- // this stop condition should never be used, if we use it, we have an
- // illegal cycle in graph - "derived from" hierarchy cannot be cycled.
- // It's here just to avoid infinite loop in case we have such cycle.
- log.error("Detected a cycle of \"derived from\" edges starting at capability type node {}", childUniqueId);
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
-
- /**
- * FOR TEST ONLY
- *
- * @param propertyOperation
- */
- public void setPropertyOperation(PropertyOperation propertyOperation) {
- this.propertyOperation = propertyOperation;
- }
-
- @Override
- public Either<GroupTypeData, TitanOperationStatus> getLatestGroupTypeByNameFromGraph(String name) {
-
- return null;
- }
+ @Override
+ public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version, boolean inTransaction) {
+ Map<String, Object> mapCriteria = new HashMap<>();
+ mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
+ mapCriteria.put(GraphPropertiesDictionary.VERSION.getProperty(), version);
+
+ return getGroupTypeByCriteria(type, mapCriteria, inTransaction);
+ }
+
+ /**
+ * Add group type to graph.
+ * <p>
+ * 1. Add group type node
+ * <p>
+ * 2. Add edge between the former node to its parent(if exists)
+ * <p>
+ * 3. Add property node and associate it to the node created at #1. (per property & if exists)
+ *
+ * @param groupTypeDefinition
+ * @return
+ */
+ private Either<GroupTypeData, TitanOperationStatus> addGroupTypeToGraph(GroupTypeDefinition groupTypeDefinition) {
+
+ log.debug("Got group type {}", groupTypeDefinition);
+
+ String ctUniqueId = UniqueIdBuilder.buildGroupTypeUid(groupTypeDefinition.getType(), groupTypeDefinition.getVersion());
+
+ GroupTypeData groupTypeData = buildGroupTypeData(groupTypeDefinition, ctUniqueId);
+
+ log.debug("Before adding group type to graph. groupTypeData = {}", groupTypeData);
+
+ Either<GroupTypeData, TitanOperationStatus> createGTResult = titanGenericDao.createNode(groupTypeData, GroupTypeData.class);
+ log.debug("After adding group type to graph. status is = {}", createGTResult);
+
+ if (createGTResult.isRight()) {
+ TitanOperationStatus operationStatus = createGTResult.right().value();
+ log.error("Failed to add group type {} to graph. status is {}", groupTypeDefinition.getType(), operationStatus);
+ return Either.right(operationStatus);
+ }
+
+ GroupTypeData resultCTD = createGTResult.left().value();
+ List<PropertyDefinition> properties = groupTypeDefinition.getProperties();
+ Either<Map<String, PropertyData>, TitanOperationStatus> addPropertiesToCapablityType = propertyOperation.addPropertiesToElementType(resultCTD.getUniqueId(), NodeTypeEnum.GroupType, properties);
+ if (addPropertiesToCapablityType.isRight()) {
+ log.error("Failed add properties {} to capability {}", properties, groupTypeDefinition.getType());
+ return Either.right(addPropertiesToCapablityType.right().value());
+ }
+
+ String derivedFrom = groupTypeDefinition.getDerivedFrom();
+ if (derivedFrom != null) {
+ Either<GraphRelation, TitanOperationStatus> createRelation = connectToDerivedFrom(ctUniqueId, derivedFrom);
+ if (createRelation.isRight()) {
+ return Either.right(createRelation.right().value());
+ }
+ }
+
+ return Either.left(createGTResult.left().value());
+
+ }
+
+
+ private Either<GraphRelation, TitanOperationStatus> connectToDerivedFrom(String ctUniqueId, String derivedFrom) {
+ log.debug("Before creating relation between Group Type with id {} to its parent {}", ctUniqueId, derivedFrom);
+
+ Either<GroupTypeData, TitanOperationStatus> derivedFromGroupTypeResult =
+ titanGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), derivedFrom, GroupTypeData.class);
+
+ if (derivedFromGroupTypeResult.isLeft()) {
+ UniqueIdData from = new UniqueIdData(NodeTypeEnum.GroupType, ctUniqueId);
+ GroupTypeData to = derivedFromGroupTypeResult.left().value();
+
+ Either<GraphRelation, TitanOperationStatus> createRelation = titanGenericDao.createRelation(from, to, GraphEdgeLabels.DERIVED_FROM, null);
+ log.debug("After create relation between Group Type with id {} to its parent {}, status is {}.", ctUniqueId, derivedFrom, createRelation);
+ return createRelation;
+ } else {
+ TitanOperationStatus status = derivedFromGroupTypeResult.right().value();
+ log.debug("Failed to found parent Group Type {}, stauts is {}.", derivedFrom, status);
+ return Either.right(status);
+ }
+ }
+
+
+ private Either<GroupTypeDefinition, StorageOperationStatus> ensureExsitanceDerivedFromEdge(GroupTypeDefinition groupTypeDefinition) {
+ Either<GroupTypeDefinition, StorageOperationStatus> result = Either.left(groupTypeDefinition);
+
+ GroupTypeData childGroupType = null;
+ GroupTypeData parentGroupType = null;
+
+ Either<GroupTypeData, TitanOperationStatus> childGroupTypeResult =
+ titanGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), groupTypeDefinition.getType(), GroupTypeData.class);
+ if (childGroupTypeResult.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(childGroupTypeResult.right().value()));
+ log.debug("Filed to find GroupType with type {}, status is {}.", groupTypeDefinition.getType(), childGroupTypeResult);
+ } else {
+ childGroupType = childGroupTypeResult.left().value();
+ }
+
+
+ if (result.isLeft()) {
+ Either<GroupTypeData, TitanOperationStatus> parentGroupTypeResult =
+ titanGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), groupTypeDefinition.getDerivedFrom(), GroupTypeData.class);
+ if (parentGroupTypeResult.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(parentGroupTypeResult.right().value()));
+ log.debug("Filed to find GroupType with type {}, status is {}.", groupTypeDefinition.getDerivedFrom(), parentGroupTypeResult);
+ } else {
+ parentGroupType = parentGroupTypeResult.left().value();
+ }
+ }
+
+
+ if (childGroupType != null && parentGroupType != null) {
+ Either<Edge, TitanOperationStatus> edgeDerivedFromResult = titanGenericDao.getEdgeByNodes(childGroupType, parentGroupType, GraphEdgeLabels.DERIVED_FROM);
+ if (edgeDerivedFromResult.isLeft()) {
+ log.debug("It was found relation {}. Don't need to create the edge.", edgeDerivedFromResult.left().value());
+ } else {
+ Either<GraphRelation, TitanOperationStatus> createRelationResult = titanGenericDao.createRelation(childGroupType, parentGroupType, GraphEdgeLabels.DERIVED_FROM, null);
+ log.debug("After create relation between Group Type with id {} to its parent with id {}, status is {}.",
+ childGroupType.getKeyValueId().getValue(), parentGroupType.getKeyValueId().getValue(), createRelationResult);
+ if (createRelationResult.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(createRelationResult.right().value()));
+ }
+ }
+
+ }
+
+
+ return result;
+ }
+
+
+ private GroupTypeData buildGroupTypeData(GroupTypeDefinition groupTypeDefinition, String ctUniqueId) {
+
+ GroupTypeData groupTypeData = new GroupTypeData(groupTypeDefinition);
+
+ groupTypeData.getGroupTypeDataDefinition().setUniqueId(ctUniqueId);
+ Long creationDate = groupTypeData.getGroupTypeDataDefinition().getCreationTime();
+ if (creationDate == null) {
+ creationDate = System.currentTimeMillis();
+ }
+ groupTypeData.getGroupTypeDataDefinition().setCreationTime(creationDate);
+ groupTypeData.getGroupTypeDataDefinition().setModificationTime(creationDate);
+
+ return groupTypeData;
+ }
+
+ public Either<Boolean, StorageOperationStatus> isCapabilityTypeDerivedFrom(String childCandidateType, String parentCandidateType) {
+ Map<String, Object> propertiesToMatch = new HashMap<String, Object>();
+ propertiesToMatch.put(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.CapabilityType), childCandidateType);
+ Either<List<CapabilityTypeData>, TitanOperationStatus> getResponse = titanGenericDao.getByCriteria(NodeTypeEnum.CapabilityType, propertiesToMatch, CapabilityTypeData.class);
+ if (getResponse.isRight()) {
+ TitanOperationStatus titanOperationStatus = getResponse.right().value();
+ log.debug("Couldn't fetch capability type {}, error: {}", childCandidateType, titanOperationStatus);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(titanOperationStatus));
+ }
+ String childUniqueId = getResponse.left().value().get(0).getUniqueId();
+ Set<String> travelledTypes = new HashSet<>();
+ do {
+ travelledTypes.add(childUniqueId);
+ Either<List<ImmutablePair<CapabilityTypeData, GraphEdge>>, TitanOperationStatus> childrenNodes = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.CapabilityType), childUniqueId, GraphEdgeLabels.DERIVED_FROM,
+ NodeTypeEnum.CapabilityType, CapabilityTypeData.class);
+ if (childrenNodes.isRight()) {
+ if (childrenNodes.right().value() != TitanOperationStatus.NOT_FOUND) {
+ TitanOperationStatus titanOperationStatus = getResponse.right().value();
+ log.debug("Couldn't fetch derived from node for capability type {}, error: {}", childCandidateType, titanOperationStatus);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(titanOperationStatus));
+ } else {
+ log.debug("Derived from node is not found for type {} - this is OK for root capability.");
+ return Either.left(false);
+ }
+ }
+ String derivedFromUniqueId = childrenNodes.left().value().get(0).getLeft().getUniqueId();
+ if (derivedFromUniqueId.equals(parentCandidateType)) {
+ log.debug("Verified that capability type {} derives from capability type {}", childCandidateType, parentCandidateType);
+ return Either.left(true);
+ }
+ childUniqueId = derivedFromUniqueId;
+ } while (!travelledTypes.contains(childUniqueId));
+ // this stop condition should never be used, if we use it, we have an
+ // illegal cycle in graph - "derived from" hierarchy cannot be cycled.
+ // It's here just to avoid infinite loop in case we have such cycle.
+ log.error("Detected a cycle of \"derived from\" edges starting at capability type node {}", childUniqueId);
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+
+ /**
+ * FOR TEST ONLY
+ *
+ * @param propertyOperation
+ */
+ public void setPropertyOperation(PropertyOperation propertyOperation) {
+ this.propertyOperation = propertyOperation;
+ }
+
+ @Override
+ public Either<GroupTypeData, TitanOperationStatus> getLatestGroupTypeByNameFromGraph(String name) {
+
+ return null;
+ }
}
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 9b6591ec08..7d299c85d1 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
@@ -27,20 +27,14 @@ import java.nio.file.Files;
import java.util.Map;
import java.util.Properties;
-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.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.http.client.api.HttpRequest;
+import org.openecomp.sdc.common.http.client.api.HttpResponse;
import org.openecomp.sdc.common.util.ZipUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,8 +46,6 @@ public class OnboardingClient {
private static Logger log = LoggerFactory.getLogger(OnboardingClient.class.getName());
- private HttpRestClient httpRestClient = null;
-
private static Properties downloadCsarHeaders = new Properties();
static {
@@ -67,7 +59,6 @@ public class OnboardingClient {
public static void main(String[] args) {
OnboardingClient csarOperation = new OnboardingClient();
- csarOperation.init();
String csarUuid = "70025CF6081B489CA7B1CBA583D5278D";
Either<Map<String, byte[]>, StorageOperationStatus> csar = csarOperation.getCsar(csarUuid, null);
@@ -75,23 +66,6 @@ public class OnboardingClient {
}
- @PostConstruct
- public void init() {
-
- // TODO: read connection configuration from OnboardingConfig
- // onboardingConfig =
- // ConfigurationManager.getConfigurationManager().getConfiguration().getOnboarding();
-
- RestConfigurationInfo restConfigurationInfo = new RestConfigurationInfo();
- httpRestClient = new HttpRestClient(restConfigurationInfo);
-
- if (false == httpRestClient.isInitialized()) {
- BeEcompErrorManager.getInstance().logInternalFlowError("InitializeRestClient", "Failed to initialize rest client", ErrorSeverity.FATAL);
- httpRestClient = null;
- }
-
- }
-
public Either<Map<String, byte[]>, StorageOperationStatus> getMockCsar(String csarUuid) {
File dir = new File("/var/tmp/mockCsar");
FileFilter fileFilter = new WildcardFileFilter("*.csar");
@@ -116,12 +90,6 @@ public class OnboardingClient {
}
public Either<Map<String, byte[]>, StorageOperationStatus> getCsar(String csarUuid, 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() + "/" + csarUuid;
Properties headers = new Properties();
@@ -135,36 +103,35 @@ public class OnboardingClient {
log.debug("Url for downloading csar is {}. Headers are {}", url, headers);
- RestResponseAsByteArray restResponse = httpRestClient.doGetAsByteArray(url, headers);
- log.debug("After fetching csar {}. Http return code is {}", csarUuid, restResponse.getHttpStatusCode());
-
- switch (restResponse.getHttpStatusCode()) {
- case HttpStatus.SC_OK:
- byte[] data = restResponse.getResponse();
- if (data != null && data.length > 0) {
- Map<String, byte[]> readZip = ZipUtil.readZip(data);
- return Either.left(readZip);
- } else {
- log.debug("Data received from rest is null or empty");
- return Either.right(StorageOperationStatus.NOT_FOUND);
- }
-
- case HttpStatus.SC_NOT_FOUND:
- return Either.right(StorageOperationStatus.CSAR_NOT_FOUND);
-
- default:
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ try {
+ HttpResponse<byte []> httpResponse = HttpRequest.getAsByteArray(url, headers);
+ log.debug("After fetching csar {}. Http return code is {}", csarUuid, httpResponse.getStatusCode());
+
+ switch (httpResponse.getStatusCode()) {
+ case HttpStatus.SC_OK:
+ byte[] data = httpResponse.getResponse();
+ if (data != null && data.length > 0) {
+ Map<String, byte[]> readZip = ZipUtil.readZip(data);
+ return Either.left(readZip);
+ } else {
+ log.debug("Data received from rest is null or empty");
+ return Either.right(StorageOperationStatus.NOT_FOUND);
+ }
+
+ case HttpStatus.SC_NOT_FOUND:
+ return Either.right(StorageOperationStatus.CSAR_NOT_FOUND);
+
+ default:
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ }
+ catch(Exception e) {
+ log.debug("Request failed with exception {}", e);
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
}
-
}
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();
@@ -176,29 +143,26 @@ public class OnboardingClient {
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);
+ try {
+ HttpResponse<String> httpResposne = HttpRequest.get(url, headers);
+ log.debug("After fetching packages. Http return code is {}", httpResposne.getStatusCode());
+
+ switch (httpResposne.getStatusCode()) {
+ case HttpStatus.SC_OK:
+ String data = httpResposne.getResponse();
+ return Either.left(data);
+
+ case HttpStatus.SC_NOT_FOUND:
+ return Either.right(StorageOperationStatus.CSAR_NOT_FOUND);
+
+ default:
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ }
+ catch(Exception e) {
+ log.debug("Request failed with exception {}", e);
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
}
-
- }
-
- public HttpRestClient getHttpRestClient() {
- return httpRestClient;
- }
-
- public void setHttpRestClient(HttpRestClient httpRestClient) {
- this.httpRestClient = httpRestClient;
}
/**
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
index 70efe12b86..799c01692d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,193 +20,288 @@
package org.openecomp.sdc.be.model.operations.impl;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
+import com.thinkaurelius.titan.graphdb.query.TitanPredicate;
+import fj.data.Either;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation;
import org.openecomp.sdc.be.model.operations.api.IPolicyTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.PolicyTypeData;
import org.openecomp.sdc.be.resources.data.PropertyData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.dao.titan.TitanUtils.buildNotInPredicate;
@Component("policy-type-operation")
public class PolicyTypeOperation extends AbstractOperation implements IPolicyTypeOperation {
- private static final String CREATE_FLOW_CONTEXT = "CreatePolicyType";
- private static final String GET_FLOW_CONTEXT = "GetPolicyType";
-
- @Resource
- private PropertyOperation propertyOperation;
-
- public PolicyTypeOperation() {
- super();
- }
-
- private static Logger log = LoggerFactory.getLogger(PolicyTypeOperation.class.getName());
-
- @Override
- public Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String policyTypeName) {
- return getLatestPolicyTypeByType(policyTypeName, false);
- }
-
- private Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String type, boolean inTransaction) {
- Map<String, Object> mapCriteria = new HashMap<>();
- mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
- mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
-
- return getPolicyTypeByCriteria(type, mapCriteria, inTransaction);
- }
-
- @Override
- public Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType(PolicyTypeDefinition policyType) {
- return addPolicyType(policyType, false);
- }
-
- @Override
- public Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType(PolicyTypeDefinition policyTypeDef, boolean inTransaction) {
-
- Either<PolicyTypeDefinition, StorageOperationStatus> result = null;
-
- try {
-
- Either<PolicyTypeData, TitanOperationStatus> eitherStatus = addPolicyTypeToGraph(policyTypeDef);
-
- if (eitherStatus.isRight()) {
- BeEcompErrorManager.getInstance().logBeFailedCreateNodeError(CREATE_FLOW_CONTEXT, policyTypeDef.getType(), eitherStatus.right().value().name());
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(eitherStatus.right().value()));
-
- } else {
- PolicyTypeData policyTypeData = eitherStatus.left().value();
-
- String uniqueId = policyTypeData.getUniqueId();
- Either<PolicyTypeDefinition, StorageOperationStatus> policyTypeRes = this.getPolicyType(uniqueId, true);
-
- if (policyTypeRes.isRight()) {
- BeEcompErrorManager.getInstance().logBeFailedRetrieveNodeError(GET_FLOW_CONTEXT, policyTypeDef.getType(), eitherStatus.right().value().name());
- }
-
- result = policyTypeRes;
-
- }
-
- return result;
-
- } finally {
- handleTransactionCommitRollback(inTransaction, result);
- }
-
- }
-
- private Either<PolicyTypeData, TitanOperationStatus> addPolicyTypeToGraph(PolicyTypeDefinition policyTypeDef) {
- log.debug("Got policy type {}", policyTypeDef);
-
- String ptUniqueId = UniqueIdBuilder.buildPolicyTypeUid(policyTypeDef.getType(), policyTypeDef.getVersion());
-
- PolicyTypeData policyTypeData = buildPolicyTypeData(policyTypeDef, ptUniqueId);
-
- log.debug("Before adding policy type to graph. policyTypeData = {}", policyTypeData);
-
- Either<PolicyTypeData, TitanOperationStatus> eitherPolicyTypeData = titanGenericDao.createNode(policyTypeData, PolicyTypeData.class);
- log.debug("After adding policy type to graph. status is = {}", eitherPolicyTypeData);
-
- if (eitherPolicyTypeData.isRight()) {
- TitanOperationStatus operationStatus = eitherPolicyTypeData.right().value();
- log.error("Failed to add policy type {} to graph. status is {}", policyTypeDef.getType(), operationStatus);
- return Either.right(operationStatus);
- }
-
- PolicyTypeData resultCTD = eitherPolicyTypeData.left().value();
- List<PropertyDefinition> properties = policyTypeDef.getProperties();
- Either<Map<String, PropertyData>, TitanOperationStatus> addPropertiesToPolicyType = propertyOperation.addPropertiesToElementType(resultCTD.getUniqueId(), NodeTypeEnum.PolicyType, properties);
- if (addPropertiesToPolicyType.isRight()) {
- log.error("Failed add properties {} to policy {}", properties, policyTypeDef.getType());
- return Either.right(addPropertiesToPolicyType.right().value());
- }
-
- return Either.left(eitherPolicyTypeData.left().value());
- }
-
- public Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeByCriteria(String type, Map<String, Object> properties, boolean inTransaction) {
- Either<PolicyTypeDefinition, StorageOperationStatus> result = null;
- try {
- if (type == null || type.isEmpty()) {
- log.error("type is empty");
- result = Either.right(StorageOperationStatus.INVALID_ID);
- return result;
- }
-
- Either<List<PolicyTypeData>, TitanOperationStatus> eitherPolicyData = titanGenericDao.getByCriteria(NodeTypeEnum.PolicyType, properties, PolicyTypeData.class);
- if (eitherPolicyData.isRight()) {
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(eitherPolicyData.right().value()));
- } else {
- PolicyTypeDataDefinition dataDefinition = eitherPolicyData.left().value().stream().map(e -> e.getPolicyTypeDataDefinition()).findFirst().get();
- result = getPolicyType(dataDefinition.getUniqueId(), inTransaction);
- }
-
- return result;
-
- } finally {
- handleTransactionCommitRollback(inTransaction, result);
- }
- }
-
- @Override
- public Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyType(String uniqueId, boolean inTransaction) {
- return getElementType(this::getPolicyTypeByUid, uniqueId, inTransaction);
- }
-
- private Either<PolicyTypeDefinition, TitanOperationStatus> getPolicyTypeByUid(String uniqueId) {
- Either<PolicyTypeDefinition, TitanOperationStatus> result = null;
-
- Either<PolicyTypeData, TitanOperationStatus> eitherPolicyTypeData = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), uniqueId, PolicyTypeData.class);
-
- if (eitherPolicyTypeData.isRight()) {
- TitanOperationStatus status = eitherPolicyTypeData.right().value();
- log.debug("Policy type {} cannot be found in graph. status is {}", uniqueId, status);
- return Either.right(status);
- }
-
- PolicyTypeData policyTypeData = eitherPolicyTypeData.left().value();
- PolicyTypeDefinition policyTypeDefinition = new PolicyTypeDefinition(policyTypeData.getPolicyTypeDataDefinition());
-
- TitanOperationStatus propertiesStatus = propertyOperation.fillProperties(uniqueId, propList -> policyTypeDefinition.setProperties(propList));
- if (propertiesStatus != TitanOperationStatus.OK) {
- log.error("Failed to fetch properties of policy type {}", uniqueId);
- return Either.right(propertiesStatus);
- }
-
- result = Either.left(policyTypeDefinition);
-
- return result;
- }
-
- private PolicyTypeData buildPolicyTypeData(PolicyTypeDefinition policyTypeDefinition, String ptUniqueId) {
-
- PolicyTypeData policyTypeData = new PolicyTypeData(policyTypeDefinition);
-
- policyTypeData.getPolicyTypeDataDefinition().setUniqueId(ptUniqueId);
- Long creationDate = policyTypeData.getPolicyTypeDataDefinition().getCreationTime();
- if (creationDate == null) {
- creationDate = System.currentTimeMillis();
- }
-
- policyTypeData.getPolicyTypeDataDefinition().setCreationTime(creationDate);
- policyTypeData.getPolicyTypeDataDefinition().setModificationTime(creationDate);
- return policyTypeData;
- }
+ private static final Logger log = LoggerFactory.getLogger(PolicyTypeOperation.class.getName());
+ private static final String CREATE_FLOW_CONTEXT = "CreatePolicyType";
+ private static final String GET_FLOW_CONTEXT = "GetPolicyType";
+
+ @Autowired
+ private PropertyOperation propertyOperation;
+ @Autowired
+ private DerivedFromOperation derivedFromOperation;
+
+ @Override
+ public Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String type) {
+ Map<String, Object> mapCriteria = new HashMap<>();
+ mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
+ mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
+ return getPolicyTypeByCriteria(type, mapCriteria);
+ }
+
+ @Override
+ public Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType(PolicyTypeDefinition policyTypeDef) {
+ Either<PolicyTypeDefinition, StorageOperationStatus> result;
+ Either<PolicyTypeData, StorageOperationStatus> eitherStatus = addPolicyTypeToGraph(policyTypeDef);
+ if (eitherStatus.isRight()) {
+ BeEcompErrorManager.getInstance().logBeFailedCreateNodeError(CREATE_FLOW_CONTEXT, policyTypeDef.getType(), eitherStatus.right().value().name());
+ result = Either.right(eitherStatus.right().value());
+ } else {
+ PolicyTypeData policyTypeData = eitherStatus.left().value();
+ String uniqueId = policyTypeData.getUniqueId();
+ Either<PolicyTypeDefinition, StorageOperationStatus> policyTypeRes = this.getPolicyTypeByUid(uniqueId);
+
+ if (policyTypeRes.isRight()) {
+ BeEcompErrorManager.getInstance().logBeFailedRetrieveNodeError(GET_FLOW_CONTEXT, policyTypeDef.getType(), eitherStatus.right().value().name());
+ }
+ result = policyTypeRes;
+ }
+ return result;
+ }
+
+ @Override
+ public Either<PolicyTypeDefinition, StorageOperationStatus> updatePolicyType(PolicyTypeDefinition updatedPolicyType, PolicyTypeDefinition currPolicyType) {
+ log.debug("updating policy type {}", updatedPolicyType.getType());
+ updatePolicyTypeData(updatedPolicyType, currPolicyType);
+ return updatePolicyTypeOnGraph(updatedPolicyType, currPolicyType);
+ }
+
+ @Override
+ public Either<List<PolicyTypeDefinition>, StorageOperationStatus> getAllPolicyTypes(Set<String> excludedPolicyTypes) {
+ Map<String, Map.Entry<TitanPredicate, Object>> predicateCriteria = buildNotInPredicate(GraphPropertiesDictionary.TYPE.getProperty(), excludedPolicyTypes);
+ return titanGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.PolicyType, predicateCriteria, PolicyTypeData.class)
+ .left()
+ .map(this::convertPolicyTypesToDefinition)
+ .right()
+ .map(DaoStatusConverter::convertTitanStatusToStorageStatus);
+ }
+
+ private List<PolicyTypeDefinition> convertPolicyTypesToDefinition(List<PolicyTypeData> policiesTypes) {
+ return policiesTypes.stream().map(type -> new PolicyTypeDefinition(type.getPolicyTypeDataDefinition())).collect(Collectors.toList());
+ }
+
+
+ private Either<PolicyTypeData, StorageOperationStatus> addPolicyTypeToGraph(PolicyTypeDefinition policyTypeDef) {
+ log.debug("Got policy type {}", policyTypeDef);
+
+ String ptUniqueId = UniqueIdBuilder.buildPolicyTypeUid(policyTypeDef.getType(), policyTypeDef.getVersion());
+ PolicyTypeData policyTypeData = buildPolicyTypeData(policyTypeDef, ptUniqueId);
+ log.debug("Before adding policy type to graph. policyTypeData = {}", policyTypeData);
+ Either<PolicyTypeData, TitanOperationStatus> eitherPolicyTypeData = titanGenericDao.createNode(policyTypeData, PolicyTypeData.class);
+ log.debug("After adding policy type to graph. status is = {}", eitherPolicyTypeData);
+ if (eitherPolicyTypeData.isRight()) {
+ TitanOperationStatus operationStatus = eitherPolicyTypeData.right().value();
+ log.error("Failed to add policy type {} to graph. status is {}", policyTypeDef.getType(), operationStatus);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(operationStatus));
+ }
+ List<PropertyDefinition> properties = policyTypeDef.getProperties();
+ Either<Map<String, PropertyData>, TitanOperationStatus> addPropertiesToPolicyType = propertyOperation.addPropertiesToElementType(ptUniqueId, NodeTypeEnum.PolicyType, properties);
+ if (addPropertiesToPolicyType.isRight()) {
+ log.error("Failed add properties {} to policy {}", properties, policyTypeDef.getType());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(addPropertiesToPolicyType.right().value()));
+ }
+ return addDerivedFromRelation(policyTypeDef, ptUniqueId)
+ .left()
+ .map(updatedDerivedFrom -> eitherPolicyTypeData.left().value());
+ }
+
+ private Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeByCriteria(String type, Map<String, Object> properties) {
+ Either<PolicyTypeDefinition, StorageOperationStatus> result;
+ if (type == null || type.isEmpty()) {
+ log.error("type is empty");
+ result = Either.right(StorageOperationStatus.INVALID_ID);
+ return result;
+ }
+
+ Either<List<PolicyTypeData>, TitanOperationStatus> eitherPolicyData = titanGenericDao.getByCriteria(NodeTypeEnum.PolicyType, properties, PolicyTypeData.class);
+ if (eitherPolicyData.isRight()) {
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(eitherPolicyData.right().value()));
+ } else {
+ PolicyTypeDataDefinition dataDefinition = eitherPolicyData.left().value().stream().map(PolicyTypeData::getPolicyTypeDataDefinition).findFirst().get();
+ result = getPolicyTypeByUid(dataDefinition.getUniqueId());
+ }
+ return result;
+
+ }
+
+ private Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeByUid(String uniqueId) {
+ log.debug("#getPolicyTypeByUid - fetching policy type with id {}", uniqueId);
+ return titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), uniqueId, PolicyTypeData.class)
+ .right()
+ .map(DaoStatusConverter::convertTitanStatusToStorageStatus)
+ .left()
+ .bind(policyType -> createPolicyTypeDefinition(uniqueId, policyType));
+ }
+
+ private Either<PolicyTypeDefinition, StorageOperationStatus> createPolicyTypeDefinition(String uniqueId, PolicyTypeData policyTypeNode) {
+ PolicyTypeDefinition policyType = new PolicyTypeDefinition(policyTypeNode.getPolicyTypeDataDefinition());
+ return fillDerivedFrom(uniqueId, policyType)
+ .left()
+ .map(derivedFrom -> fillProperties(uniqueId, policyType, derivedFrom))
+ .left()
+ .map(props -> policyType);
+ }
+
+ private Either<List<PropertyDefinition>, StorageOperationStatus> fillProperties(String uniqueId, PolicyTypeDefinition policyType, PolicyTypeData derivedFromNode) {
+ log.debug("#fillProperties - fetching all properties for policy type {}", policyType.getType());
+ return propertyOperation.findPropertiesOfNode(NodeTypeEnum.PolicyType, uniqueId)
+ .right()
+ .bind(this::handlePolicyTypeHasNoProperties)
+ .left()
+ .bind(propsMap -> fillDerivedFromProperties(policyType, derivedFromNode, new ArrayList<>(propsMap.values())));
+ }
+
+ private Either<List<PropertyDefinition>, StorageOperationStatus> fillDerivedFromProperties(PolicyTypeDefinition policyType, PolicyTypeData derivedFromNode, List<PropertyDefinition> policyTypeDirectProperties) {
+ if (derivedFromNode == null) {
+ policyType.setProperties(policyTypeDirectProperties);
+ return Either.left(policyTypeDirectProperties);
+ }
+ log.debug("#fillDerivedFromProperties - fetching all properties of derived from chain for policy type {}", policyType.getType());
+ return propertyOperation.getAllPropertiesRec(derivedFromNode.getUniqueId(), NodeTypeEnum.PolicyType, PolicyTypeData.class)
+ .left()
+ .map(derivedFromProps -> {policyTypeDirectProperties.addAll(derivedFromProps); return policyTypeDirectProperties;})
+ .left()
+ .map(allProps -> {policyType.setProperties(allProps);return allProps;});
+ }
+
+ private Either<PolicyTypeData, StorageOperationStatus> fillDerivedFrom(String uniqueId, PolicyTypeDefinition policyType) {
+ log.debug("#fillDerivedFrom - fetching policy type {} derived node", policyType.getType());
+ return derivedFromOperation.getDerivedFromChild(uniqueId, NodeTypeEnum.PolicyType, PolicyTypeData.class)
+ .right()
+ .bind(this::handleDerivedFromNotExist)
+ .left()
+ .map(derivedFrom -> setDerivedFrom(policyType, derivedFrom));
+
+ }
+
+ private Either<PolicyTypeData, StorageOperationStatus> handleDerivedFromNotExist(StorageOperationStatus err) {
+ if (err == StorageOperationStatus.NOT_FOUND) {
+ return Either.left(null);
+ }
+ return Either.right(err);
+ }
+
+ Either<Map<String, PropertyDefinition>, StorageOperationStatus> handlePolicyTypeHasNoProperties(TitanOperationStatus err) {
+ if (err == TitanOperationStatus.NOT_FOUND) {
+ return Either.left(new HashMap<>());
+ }
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(err));
+ }
+
+ private PolicyTypeData setDerivedFrom(PolicyTypeDefinition policyTypeDefinition, PolicyTypeData derivedFrom) {
+ if (derivedFrom != null) {
+ policyTypeDefinition.setDerivedFrom(derivedFrom.getPolicyTypeDataDefinition().getType());
+ }
+ return derivedFrom;
+ }
+
+ private PolicyTypeData buildPolicyTypeData(PolicyTypeDefinition policyTypeDefinition, String ptUniqueId) {
+
+ PolicyTypeData policyTypeData = new PolicyTypeData(policyTypeDefinition);
+
+ policyTypeData.getPolicyTypeDataDefinition().setUniqueId(ptUniqueId);
+ Long creationDate = policyTypeData.getPolicyTypeDataDefinition().getCreationTime();
+ if (creationDate == null) {
+ creationDate = System.currentTimeMillis();
+ }
+
+ policyTypeData.getPolicyTypeDataDefinition().setCreationTime(creationDate);
+ policyTypeData.getPolicyTypeDataDefinition().setModificationTime(creationDate);
+ return policyTypeData;
+ }
+
+ private Either<PolicyTypeDefinition, StorageOperationStatus> updatePolicyTypeOnGraph(PolicyTypeDefinition updatedPolicyType, PolicyTypeDefinition currPolicyType) {
+ updatePolicyTypeData(updatedPolicyType, currPolicyType);
+ return titanGenericDao.updateNode(new PolicyTypeData(updatedPolicyType), PolicyTypeData.class)
+ .right()
+ .map(DaoStatusConverter::convertTitanStatusToStorageStatus)
+ .left()
+ .bind(updatedNode -> updatePolicyProperties(updatedPolicyType.getUniqueId(), updatedPolicyType.getProperties()))
+ .left()
+ .bind(updatedProperties -> updatePolicyDerivedFrom(updatedPolicyType, currPolicyType.getDerivedFrom()))
+ .left()
+ .map(updatedDerivedFrom -> updatedPolicyType);
+ }
+
+ private Either<Map<String, PropertyData>, StorageOperationStatus> updatePolicyProperties(String policyId, List<PropertyDefinition> properties) {
+ log.debug("#updatePolicyProperties - updating policy type properties for policy type with id {}", policyId);
+ return propertyOperation.deletePropertiesAssociatedToNode(NodeTypeEnum.PolicyType, policyId)
+ .left()
+ .bind(deleteProps -> addPropertiesToPolicy(policyId, properties));
+ }
+
+ private Either<GraphRelation, StorageOperationStatus> updatePolicyDerivedFrom(PolicyTypeDefinition updatedPolicyType, String currDerivedFromPolicyType) {
+ String policyTypeId = updatedPolicyType.getUniqueId();
+ log.debug("#updatePolicyDerivedFrom - updating policy derived from relation for policy type with id {}. old derived type {}. new derived type {}", policyTypeId, currDerivedFromPolicyType, updatedPolicyType.getDerivedFrom());
+ StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromPolicyType(policyTypeId, currDerivedFromPolicyType);
+ if (deleteDerivedRelationStatus != StorageOperationStatus.OK) {
+ return Either.right(deleteDerivedRelationStatus);
+ }
+ return addDerivedFromRelation(updatedPolicyType, policyTypeId);
+ }
+
+ private Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(PolicyTypeDataDefinition policyTypeDef, String ptUniqueId) {
+ String derivedFrom = policyTypeDef.getDerivedFrom();
+ if (derivedFrom == null) {
+ return Either.left(null);
+ }
+ log.debug("#addDerivedFromRelationBefore - adding derived from relation between policy type {} to its parent {}", policyTypeDef.getType(), derivedFrom);
+ return this.getLatestPolicyTypeByType(derivedFrom)
+ .left()
+ .bind(derivedFromPolicy -> derivedFromOperation.addDerivedFromRelation(ptUniqueId, derivedFromPolicy.getUniqueId(), NodeTypeEnum.PolicyType));
+ }
+
+ private StorageOperationStatus deleteDerivedFromPolicyType(String policyTypeId, String derivedFromType) {
+ if (derivedFromType == null) {
+ return StorageOperationStatus.OK;
+ }
+ log.debug("#deleteDerivedFromPolicyType - deleting derivedFrom relation for policy type with id {} and its derived type {}", policyTypeId, derivedFromType);
+ return getLatestPolicyTypeByType(derivedFromType)
+ .either(derivedFromNode -> derivedFromOperation.removeDerivedFromRelation(policyTypeId, derivedFromNode.getUniqueId(), NodeTypeEnum.PolicyType),
+ err -> err);
+ }
+
+ private Either<Map<String, PropertyData>, StorageOperationStatus> addPropertiesToPolicy(String policyTypeId, List<PropertyDefinition> properties) {
+ log.debug("#addPropertiesToPolicy - adding policy type properties for policy type with id {}", policyTypeId);
+ return propertyOperation.addPropertiesToElementType(policyTypeId, NodeTypeEnum.PolicyType, properties)
+ .right()
+ .map(DaoStatusConverter::convertTitanStatusToStorageStatus);
+ }
+
+ private void updatePolicyTypeData(PolicyTypeDefinition updatedTypeDefinition, PolicyTypeDefinition currTypeDefinition) {
+ updatedTypeDefinition.setUniqueId(currTypeDefinition.getUniqueId());
+ updatedTypeDefinition.setCreationTime(currTypeDefinition.getCreationTime());
+ updatedTypeDefinition.setModificationTime(System.currentTimeMillis());
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index 6835e813ee..99e95e6653 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -20,34 +20,29 @@
package org.openecomp.sdc.be.model.operations.impl;
-import java.io.IOException;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.StringJoiner;
-import java.util.function.Consumer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import com.thinkaurelius.titan.core.TitanVertex;
+import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.codehaus.jackson.JsonNode;
-import org.codehaus.jackson.JsonProcessingException;
-import org.codehaus.jackson.ObjectCodec;
-import org.codehaus.jackson.map.DeserializationContext;
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.GraphPropertiesDictionary;
@@ -62,6 +57,7 @@ import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.IComplexDefaultValue;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
@@ -83,26 +79,30 @@ 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.Qualifier;
import org.springframework.stereotype.Component;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-import com.thinkaurelius.titan.core.TitanVertex;
-
-import fj.data.Either;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.StringJoiner;
+import java.util.function.Consumer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
@Component("property-operation")
public class PropertyOperation extends AbstractOperation implements IPropertyOperation {
private TitanGenericDao titanGenericDao;
+ private DerivedFromOperation derivedFromOperation;
public static void main(String[] args) {
@@ -119,9 +119,9 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
- public PropertyOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
- super();
+ public PropertyOperation(TitanGenericDao titanGenericDao, DerivedFromOperation derivedFromOperation) {
this.titanGenericDao = titanGenericDao;
+ this.derivedFromOperation = derivedFromOperation;
}
private static Logger log = LoggerFactory.getLogger(PropertyOperation.class.getName());
@@ -790,6 +790,12 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return Either.left(resourceProps);
}
+ public Either<Map<String, PropertyDefinition>, StorageOperationStatus> deletePropertiesAssociatedToNode(NodeTypeEnum nodeType, String uniqueId) {
+ return deleteAllPropertiesAssociatedToNode(nodeType, uniqueId)
+ .right()
+ .bind(err -> err == StorageOperationStatus.OK ? Either.left(Collections.emptyMap()) : Either.right(err));
+ }
+
public Either<Map<String, PropertyDefinition>, StorageOperationStatus> deleteAllPropertiesAssociatedToNode(NodeTypeEnum nodeType, String uniqueId) {
Either<Map<String, PropertyDefinition>, TitanOperationStatus> propertiesOfNodeRes = findPropertiesOfNode(nodeType, uniqueId);
@@ -823,18 +829,6 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
/**
- * fetch all properties under a given resource(includes its parents' resources)
- *
- * @param resourceId
- * @param properties
- * @return
- */
- public TitanOperationStatus findAllResourcePropertiesRecursively(String resourceId, List<PropertyDefinition> properties) {
- final NodeElementFetcher<PropertyDefinition> singleNodeFetcher = (resourceIdParam, attributesParam) -> findPropertiesOfNode(NodeTypeEnum.Resource, resourceIdParam, attributesParam);
- return findAllResourceElementsDefinitionRecursively(resourceId, properties, singleNodeFetcher);
- }
-
- /**
*
*
* @param nodeType
@@ -1323,11 +1317,11 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return instanceProperty;
}
- public static class PropertyConstraintJacksonDeserialiser extends org.codehaus.jackson.map.JsonDeserializer<PropertyConstraint> {
- @Override
- public PropertyConstraint deserialize(org.codehaus.jackson.JsonParser json, DeserializationContext context) throws IOException, JsonProcessingException {
+ public static class PropertyConstraintJacksonDeserializer extends com.fasterxml.jackson.databind.JsonDeserializer<PropertyConstraint> {
+ @Override
+ public PropertyConstraint deserialize(com.fasterxml.jackson.core.JsonParser json, DeserializationContext context) throws IOException {
ObjectCodec oc = json.getCodec();
JsonNode node = oc.readTree(json);
return null;
@@ -2147,13 +2141,6 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return Either.left(dataTypeDefinition);
}
- public Either<DataTypeDefinition, TitanOperationStatus> getDataTypeByNameWithoutDerivedDataTypes(String name) {
-
- String uid = UniqueIdBuilder.buildDataTypeUid(name);
- return getDataTypeByUidWithoutDerivedDataTypes(uid);
-
- }
-
/**
*
* convert between graph Node object to Java object
@@ -2271,7 +2258,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
* @param uniqueId
* @return
*/
- public Either<DataTypeDefinition, TitanOperationStatus> getAndAddDataTypeByUid(String uniqueId, Map<String, DataTypeDefinition> allDataTypes) {
+ private Either<DataTypeDefinition, TitanOperationStatus> getAndAddDataTypeByUid(String uniqueId, Map<String, DataTypeDefinition> allDataTypes) {
Either<DataTypeDefinition, TitanOperationStatus> result = null;
@@ -2339,13 +2326,9 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return result;
}
- public Either<DataTypeDefinition, TitanOperationStatus> getDataTypeUsingName(String name) {
-
+ private Either<DataTypeDefinition, TitanOperationStatus> getDataTypeUsingName(String name) {
String uid = UniqueIdBuilder.buildDataTypeUid(name);
-
- Either<DataTypeDefinition, TitanOperationStatus> dataTypeByUid = getDataTypeByUid(uid);
-
- return dataTypeByUid;
+ return getDataTypeByUid(uid);
}
public Either<String, TitanOperationStatus> checkInnerType(PropertyDataDefinition propDataDef) {
@@ -2354,9 +2337,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
- Either<String, TitanOperationStatus> result = getInnerType(type, () -> propDataDef.getSchema());
-
- return result;
+ return getInnerType(type, () -> propDataDef.getSchema());
}
public Either<List<DataTypeData>, TitanOperationStatus> getAllDataTypeNodes() {
@@ -2380,7 +2361,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
if (type == null) {
DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
ImmutablePair<JsonElement, Boolean> validateResult = dataTypeValidatorConverter.validateAndUpdate(value, dataTypeDefinition, dataTypes);
- if (validateResult.right.booleanValue() == false) {
+ if (Boolean.FALSE.equals(validateResult.right)) {
log.debug("The value {} of property from type {} is invalid", value, propertyType);
return Either.right(false);
}
@@ -2390,13 +2371,13 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
log.trace("before validating property type {}", propertyType);
boolean isValidProperty = isValidValue(type, value, innerType, dataTypes);
- if (false == isValidProperty) {
+ if (!isValidProperty) {
log.debug("The value {} of property from type {} is invalid", value, type);
return Either.right(false);
}
}
Object convertedValue = value;
- if (false == isEmptyValue(value) && isValidate) {
+ if (!isEmptyValue(value) && isValidate) {
PropertyValueConverter converter = type.getConverter();
convertedValue = converter.convert(value, innerType, dataTypes);
}
@@ -2407,11 +2388,46 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return validateAndUpdatePropertyValue(propertyType, value, true, innerType, dataTypes);
}
+ public <T extends GraphNode> Either<List<PropertyDefinition>, StorageOperationStatus> getAllPropertiesRec(String uniqueId, NodeTypeEnum nodeType, Class<T> clazz) {
+ return this.findPropertiesOfNode(nodeType, uniqueId)
+ .right()
+ .bind(this::handleNotFoundProperties)
+ .left()
+ .bind(props -> getAllDerivedFromChainProperties(uniqueId, nodeType, clazz, props.values()));
+ }
+
+ private Either<Map<String, PropertyDefinition>, StorageOperationStatus> handleNotFoundProperties(TitanOperationStatus titanOperationStatus) {
+ if (titanOperationStatus == TitanOperationStatus.NOT_FOUND) {
+ return Either.left(new HashMap<>());
+ }
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(titanOperationStatus));
+ }
+
+ private <T extends GraphNode> Either<List<PropertyDefinition>, StorageOperationStatus> getAllDerivedFromChainProperties(String uniqueId, NodeTypeEnum nodeType, Class<T> clazz, Collection<PropertyDefinition> nodeProps) {
+ List<PropertyDefinition> accumulatedProps = new ArrayList<>(nodeProps);
+ String currentNodeUid = uniqueId;
+ Either<T, StorageOperationStatus> derivedFrom;
+ while ((derivedFrom = derivedFromOperation.getDerivedFromChild(currentNodeUid, nodeType, clazz)).isLeft()) {
+ currentNodeUid = derivedFrom.left().value().getUniqueId();
+ TitanOperationStatus titanOperationStatus = fillProperties(currentNodeUid, nodeType, accumulatedProps::addAll);
+ if (titanOperationStatus != TitanOperationStatus.OK) {
+ log.debug("failed to fetch properties for type {} with id {}", nodeType, currentNodeUid);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(titanOperationStatus));
+ }
+ }
+ StorageOperationStatus getDerivedResult = derivedFrom.right().value();
+ return isReachedEndOfDerivedFromChain(getDerivedResult) ? Either.left(accumulatedProps) : Either.right(getDerivedResult);
+ }
+
+ private boolean isReachedEndOfDerivedFromChain(StorageOperationStatus getDerivedResult) {
+ return getDerivedResult == StorageOperationStatus.NOT_FOUND;
+ }
+
/*
* @Override public PropertyOperation getPropertyOperation() { return this; }
*/
- protected TitanOperationStatus fillProperties(String uniqueId, Consumer<List<PropertyDefinition>> propertySetter) {
- Either<Map<String, PropertyDefinition>, TitanOperationStatus> findPropertiesOfNode = this.findPropertiesOfNode(NodeTypeEnum.GroupType, uniqueId);
+ protected TitanOperationStatus fillProperties(String uniqueId, NodeTypeEnum nodeType, Consumer<List<PropertyDefinition>> propertySetter) {
+ Either<Map<String, PropertyDefinition>, TitanOperationStatus> findPropertiesOfNode = this.findPropertiesOfNode(nodeType, uniqueId);
if (findPropertiesOfNode.isRight()) {
TitanOperationStatus titanOperationStatus = findPropertiesOfNode.right().value();
log.debug("After looking for properties of vertex {}. status is {}", uniqueId, titanOperationStatus);
@@ -2498,17 +2514,6 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return addPropertiesToElementType(uniqueId, elementType, propMap);
}
- public TitanOperationStatus addPropertiesToElementType(TitanVertex elementVertex, String uniqueId, NodeTypeEnum elementType, List<PropertyDefinition> properties) {
-
- Map<String, PropertyDefinition> propMap;
- if (properties == null) {
- propMap = null;
- } else {
- propMap = properties.stream().collect(Collectors.toMap(propDef -> propDef.getName(), propDef -> propDef));
- }
- return addPropertiesToElementType(uniqueId, elementType, propMap, elementVertex);
- }
-
@Override
public Either<DataTypeDefinition, StorageOperationStatus> updateDataType(DataTypeDefinition newDataTypeDefinition, DataTypeDefinition oldDataTypeDefinition) {
return updateDataType(newDataTypeDefinition, oldDataTypeDefinition, true);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
index eb5d8f6797..4cdb21a908 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
@@ -31,6 +31,7 @@ import org.openecomp.sdc.be.resources.data.ResourceCategoryData;
import org.openecomp.sdc.be.resources.data.ServiceCategoryData;
import org.openecomp.sdc.be.resources.data.TagData;
import org.openecomp.sdc.be.resources.data.UserData;
+import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.util.ValidationUtils;
public class UniqueIdBuilder {
@@ -134,6 +135,11 @@ public class UniqueIdBuilder {
return resourceId + DOT + interfaceName + DOT + operation + DOT + artifactLabel;
}
+
+ public static String buildInstanceArtifactUniqueId(String parentId, String instanceId, String artifactLabel) {
+
+ return parentId + DOT + instanceId + DOT + artifactLabel;
+ }
// public static String
// buildArtifactByInterfaceUniqueIdAndRsrcNameVersion(String
@@ -240,6 +246,10 @@ public class UniqueIdBuilder {
public static String buildGroupUniqueId(String componentId, String name) {
return componentId + DOT + name + DOT + "group";
}
+
+ public static String buildPolicyUniqueId(String componentId, String name) {
+ return componentId + DOT + name + Constants.POLICY_UID_POSTFIX;
+ }
public static String buildGroupPropertyValueUid(String groupUniqueId, Integer index) {
return groupUniqueId + DOT + "property" + DOT + index;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverter.java
index 5d7f98e438..ba765c92a0 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaFloatConverter.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,28 +23,29 @@ package org.openecomp.sdc.be.model.tosca.converters;
import java.math.BigDecimal;
import java.util.Map;
+import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.model.DataTypeDefinition;
public class ToscaFloatConverter implements PropertyValueConverter {
- private static ToscaFloatConverter numberConverter = new ToscaFloatConverter();
-
- public static ToscaFloatConverter getInstance() {
- return numberConverter;
- }
-
- private ToscaFloatConverter() {
-
- }
-
- @Override
- public String convert(String original, String innerType, Map<String, DataTypeDefinition> dataTypes) {
- if (original == null) {
- return null;
- }
- if (original.contains("f") || original.contains("F"))
- original = original.toLowerCase().replaceFirst("f", "");
- return new BigDecimal(original).toPlainString();
- }
+ private static ToscaFloatConverter numberConverter = new ToscaFloatConverter();
+
+ private ToscaFloatConverter() {}
+
+ public static ToscaFloatConverter getInstance() {
+ return numberConverter;
+ }
+
+ @Override
+ public String convert(String original, String innerType, Map<String, DataTypeDefinition> dataTypes) {
+ if (StringUtils.isEmpty(original)) {
+ return null;
+ }
+ String convertedValue = original;
+ if (original.endsWith("f") || original.endsWith("F")) {
+ convertedValue = StringUtils.removeEndIgnoreCase(original, "f");
+ }
+ return new BigDecimal(convertedValue).toPlainString();
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java
index 7c86b6da1b..862766b6fa 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/MapValidator.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,6 +24,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
@@ -31,7 +32,6 @@ import org.openecomp.sdc.common.util.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@@ -50,16 +50,14 @@ when written line by line :
key1 : val1
key2 : val2
key1 and val does not need " " , even if val1 is a string.
-
when written as one line : {"key1":val1 , "key2":val2}
Keys always need " " around them.
- */
+*/
public class MapValidator implements PropertyTypeValidator {
private static MapValidator mapValidator = new MapValidator();
- private static Logger log = LoggerFactory.getLogger(MapValidator.class.getName());
- Gson gson = new Gson();
+ private static final Logger LOGGER = LoggerFactory.getLogger(MapValidator.class.getName());
private static DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
@@ -72,7 +70,7 @@ public class MapValidator implements PropertyTypeValidator {
@Override
public boolean isValid(String value, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- if (value == null || value == "") {
+ if (StringUtils.isEmpty(value)) {
return true;
}
if (innerType == null) {
@@ -101,39 +99,28 @@ public class MapValidator implements PropertyTypeValidator {
innerValidator = ToscaPropertyType.JSON.getValidator();
break;
default:
- log.debug("inner Tosca Type is unknown. {}", innerToscaType);
+ LOGGER.debug("inner Tosca Type is unknown. {}", innerToscaType);
return false;
}
} else {
- log.debug("inner Tosca Type is: {}", innerType);
+ LOGGER.debug("inner Tosca Type is: {}", innerType);
boolean isValid = validateComplexInnerType(value, innerType, allDataTypes);
- log.debug("Finish to validate value {} of map with inner type {}. result is {}",value,innerType,isValid);
+ LOGGER.debug("Finish to validate value {} of map with inner type {}. result is {}",value,innerType,isValid);
return isValid;
}
try {
JsonElement jsonObject = jsonParser.parse(value);
- JsonObject asJsonObject = jsonObject.getAsJsonObject();
- Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
- for (Entry<String, JsonElement> entry : entrySet) {
- String currentKey = entry.getKey();
- JsonElement jsonValue = entry.getValue();
-
- String element = JsonUtils.toString(jsonValue);
-
- if (!innerValidator.isValid(element, null, allDataTypes)
- || !keyValidator.isValid(entry.getKey(), null, allDataTypes)) {
- log.debug("validation of key : {}, element : {} failed", currentKey, entry.getValue());
- return false;
- }
- }
-
- return true;
+ if (!jsonObject.isJsonObject()) {
+ return false;
+ }
+ JsonObject valueAsJson = jsonObject.getAsJsonObject();
+ return validateJsonObject(allDataTypes, innerValidator, keyValidator, valueAsJson);
} catch (JsonSyntaxException e) {
- log.debug("Failed to parse json : {}", value, e);
+ LOGGER.debug("Failed to parse json : {}", value, e);
BeEcompErrorManager.getInstance().logBeInvalidJsonInput("Map Validator");
}
@@ -141,12 +128,30 @@ public class MapValidator implements PropertyTypeValidator {
}
+ private boolean validateJsonObject(Map<String, DataTypeDefinition> allDataTypes, PropertyTypeValidator innerValidator, PropertyTypeValidator keyValidator, JsonObject asJsonObject) {
+ Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
+ for (Entry<String, JsonElement> entry : entrySet) {
+ String currentKey = entry.getKey();
+ JsonElement jsonValue = entry.getValue();
+
+ String element = JsonUtils.toString(jsonValue);
+
+ if (!innerValidator.isValid(element, null, allDataTypes)
+ || !keyValidator.isValid(entry.getKey(), null, allDataTypes)) {
+ LOGGER.debug("validation of key : {}, element : {} failed", currentKey, entry.getValue());
+ return false;
+ }
+ }
+
+ return true;
+ }
+
private boolean validateComplexInnerType(String value, String innerType,
Map<String, DataTypeDefinition> allDataTypes) {
DataTypeDefinition innerDataTypeDefinition = allDataTypes.get(innerType);
if (innerDataTypeDefinition == null) {
- log.debug("Data type {} cannot be found in our data types.", innerType);
+ LOGGER.debug("Data type {} cannot be found in our data types.", innerType);
return false;
}
@@ -163,14 +168,14 @@ public class MapValidator implements PropertyTypeValidator {
boolean isValid = dataTypeValidatorConverter.isValid(element, innerDataTypeDefinition,
allDataTypes);
if (!isValid) {
- log.debug("Cannot parse value {} from type {} of key {}",currentValue,innerType,currentKey);
+ LOGGER.debug("Cannot parse value {} from type {} of key {}",currentValue,innerType,currentKey);
return false;
}
}
}
} catch (Exception e) {
- log.debug("Cannot parse value {} of map from inner type {}", value, innerType, e);
+ LOGGER.debug("Cannot parse value {} of map from inner type {}", value, innerType, e);
return false;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/SerializedHashMap.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/SerializedHashMap.java
new file mode 100644
index 0000000000..36777f0982
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/SerializedHashMap.java
@@ -0,0 +1,11 @@
+package org.openecomp.sdc.be.ui.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+public class SerializedHashMap<T,R> extends java.util.HashMap<T,R> {
+
+ @JsonIgnore
+ @Override
+ public boolean isEmpty() {
+ return super.isEmpty();
+ }
+}
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 d699f28d07..f324cf83ad 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,251 +20,251 @@
package org.openecomp.sdc.be.ui.model;
-import java.util.List;
-import java.util.Map;
-
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-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.ComponentInstance;
-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.RequirementCapabilityRelDef;
-import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import java.util.List;
+import java.util.Map;
+
public class UiComponentDataTransfer {
+ private Map<String, ArtifactDefinition> artifacts;
+ private Map<String, ArtifactDefinition> deploymentArtifacts;
+ private Map<String, ArtifactDefinition> toscaArtifacts;
+
+ private List<CategoryDefinition> categories;
+
+ // User
+ private String creatorUserId;
+ private String creatorFullName;
+ private String lastUpdaterUserId;
+ private String lastUpdaterFullName;
+
+ protected ComponentTypeEnum componentType;
+ private List<ComponentInstance> componentInstances;
- private Map<String, ArtifactDefinition> artifacts;
- private Map<String, ArtifactDefinition> deploymentArtifacts;
- private Map<String, ArtifactDefinition> toscaArtifacts;
+ private List<RequirementCapabilityRelDef> componentInstancesRelations;
- private List<CategoryDefinition> categories;
+ private Map<String, List<ComponentInstanceInput>> componentInstancesInputs;
- // User
- private String creatorUserId;
- private String creatorFullName;
- private String lastUpdaterUserId;
- private String lastUpdaterFullName;
+ private Map<String, List<ComponentInstanceProperty>> componentInstancesProperties;
- protected ComponentTypeEnum componentType;
+ private Map<String, List<ComponentInstanceProperty>> componentInstancesAttributes;
- private List<ComponentInstance> componentInstances;
+ private Map<String, List<CapabilityDefinition>> capabilities;
- private List<RequirementCapabilityRelDef> componentInstancesRelations;
+ private List<PolicyDefinition> policies;
- private Map<String, List<ComponentInstanceInput>> componentInstancesInputs;
+ private Map<String, List<RequirementDefinition>> requirements;
- private Map<String, List<ComponentInstanceProperty>> componentInstancesProperties;
+ private List<InputDefinition> inputs;
- private Map<String, List<ComponentInstanceProperty>> componentInstancesAttributes;
+ private List<GroupDefinition> groups;
- private Map<String, List<CapabilityDefinition>> capabilities;
+ protected List<AdditionalInformationDefinition> additionalInformation;
- private Map<String, List<RequirementDefinition>> requirements;
+ public UiComponentDataTransfer() {
+ }
- private List<InputDefinition> inputs;
+ public Map<String, ArtifactDefinition> getArtifacts() {
+ return artifacts;
+ }
- private List<GroupDefinition> groups;
-
- protected List<AdditionalInformationDefinition> additionalInformation;
- public UiComponentDataTransfer(){}
+ public void setArtifacts(Map<String, ArtifactDefinition> artifacts) {
+ this.artifacts = artifacts;
+ }
- public Map<String, ArtifactDefinition> getArtifacts() {
- return artifacts;
- }
+ public Map<String, ArtifactDefinition> getDeploymentArtifacts() {
+ return deploymentArtifacts;
+ }
- public void setArtifacts(Map<String, ArtifactDefinition> artifacts) {
- this.artifacts = artifacts;
- }
+ public void setDeploymentArtifacts(Map<String, ArtifactDefinition> deploymentArtifacts) {
+ this.deploymentArtifacts = deploymentArtifacts;
+ }
- public Map<String, ArtifactDefinition> getDeploymentArtifacts() {
- return deploymentArtifacts;
- }
+ public Map<String, ArtifactDefinition> getToscaArtifacts() {
+ return toscaArtifacts;
+ }
- public void setDeploymentArtifacts(Map<String, ArtifactDefinition> deploymentArtifacts) {
- this.deploymentArtifacts = deploymentArtifacts;
- }
+ public void setToscaArtifacts(Map<String, ArtifactDefinition> toscaArtifacts) {
+ this.toscaArtifacts = toscaArtifacts;
+ }
- public Map<String, ArtifactDefinition> getToscaArtifacts() {
- return toscaArtifacts;
- }
+ public List<CategoryDefinition> getCategories() {
+ return categories;
+ }
- public void setToscaArtifacts(Map<String, ArtifactDefinition> toscaArtifacts) {
- this.toscaArtifacts = toscaArtifacts;
- }
+ public void setCategories(List<CategoryDefinition> categories) {
+ this.categories = categories;
+ }
- public List<CategoryDefinition> getCategories() {
- return categories;
- }
+ public String getCreatorUserId() {
+ return creatorUserId;
+ }
- public void setCategories(List<CategoryDefinition> categories) {
- this.categories = categories;
- }
+ public void setCreatorUserId(String creatorUserId) {
+ this.creatorUserId = creatorUserId;
+ }
- public String getCreatorUserId() {
- return creatorUserId;
- }
+ public String getCreatorFullName() {
+ return creatorFullName;
+ }
- public void setCreatorUserId(String creatorUserId) {
- this.creatorUserId = creatorUserId;
- }
+ public void setCreatorFullName(String creatorFullName) {
+ this.creatorFullName = creatorFullName;
+ }
- public String getCreatorFullName() {
- return creatorFullName;
- }
+ public String getLastUpdaterUserId() {
+ return lastUpdaterUserId;
+ }
- public void setCreatorFullName(String creatorFullName) {
- this.creatorFullName = creatorFullName;
- }
+ public void setLastUpdaterUserId(String lastUpdaterUserId) {
+ this.lastUpdaterUserId = lastUpdaterUserId;
+ }
- public String getLastUpdaterUserId() {
- return lastUpdaterUserId;
- }
+ public String getLastUpdaterFullName() {
+ return lastUpdaterFullName;
+ }
- public void setLastUpdaterUserId(String lastUpdaterUserId) {
- this.lastUpdaterUserId = lastUpdaterUserId;
- }
+ public void setLastUpdaterFullName(String lastUpdaterFullName) {
+ this.lastUpdaterFullName = lastUpdaterFullName;
+ }
- public String getLastUpdaterFullName() {
- return lastUpdaterFullName;
- }
+ public ComponentTypeEnum getComponentType() {
+ return componentType;
+ }
- public void setLastUpdaterFullName(String lastUpdaterFullName) {
- this.lastUpdaterFullName = lastUpdaterFullName;
- }
+ public void setComponentType(ComponentTypeEnum componentType) {
+ this.componentType = componentType;
+ }
- public ComponentTypeEnum getComponentType() {
- return componentType;
- }
+ public List<ComponentInstance> getComponentInstances() {
+ return componentInstances;
+ }
- public void setComponentType(ComponentTypeEnum componentType) {
- this.componentType = componentType;
- }
+ public void setComponentInstances(List<ComponentInstance> componentInstances) {
+ this.componentInstances = componentInstances;
+ }
- public List<ComponentInstance> getComponentInstances() {
- return componentInstances;
- }
+ public List<RequirementCapabilityRelDef> getComponentInstancesRelations() {
+ return componentInstancesRelations;
+ }
- public void setComponentInstances(List<ComponentInstance> componentInstances) {
- this.componentInstances = componentInstances;
- }
+ public void setComponentInstancesRelations(List<RequirementCapabilityRelDef> componentInstancesRelations) {
+ this.componentInstancesRelations = componentInstancesRelations;
+ }
- public List<RequirementCapabilityRelDef> getComponentInstancesRelations() {
- return componentInstancesRelations;
- }
+ public Map<String, List<ComponentInstanceInput>> getComponentInstancesInputs() {
+ return componentInstancesInputs;
+ }
- public void setComponentInstancesRelations(List<RequirementCapabilityRelDef> componentInstancesRelations) {
- this.componentInstancesRelations = componentInstancesRelations;
- }
+ public void setComponentInstancesInputs(Map<String, List<ComponentInstanceInput>> componentInstancesInputs) {
+ this.componentInstancesInputs = componentInstancesInputs;
+ }
- public Map<String, List<ComponentInstanceInput>> getComponentInstancesInputs() {
- return componentInstancesInputs;
- }
+ public Map<String, List<ComponentInstanceProperty>> getComponentInstancesProperties() {
+ return componentInstancesProperties;
+ }
- public void setComponentInstancesInputs(Map<String, List<ComponentInstanceInput>> componentInstancesInputs) {
- this.componentInstancesInputs = componentInstancesInputs;
- }
+ public void setComponentInstancesProperties(Map<String, List<ComponentInstanceProperty>> componentInstancesProperties) {
+ this.componentInstancesProperties = componentInstancesProperties;
+ }
- public Map<String, List<ComponentInstanceProperty>> getComponentInstancesProperties() {
- return componentInstancesProperties;
- }
+ public Map<String, List<ComponentInstanceProperty>> getComponentInstancesAttributes() {
+ return componentInstancesAttributes;
+ }
- public void setComponentInstancesProperties(Map<String, List<ComponentInstanceProperty>> componentInstancesProperties) {
- this.componentInstancesProperties = componentInstancesProperties;
- }
+ public void setComponentInstancesAttributes(
+ Map<String, List<ComponentInstanceProperty>> componentInstancesAttributes) {
+ this.componentInstancesAttributes = componentInstancesAttributes;
+ }
- public Map<String, List<ComponentInstanceProperty>> getComponentInstancesAttributes() {
- return componentInstancesAttributes;
- }
+ public Map<String, List<CapabilityDefinition>> getCapabilities() {
+ return capabilities;
+ }
- public void setComponentInstancesAttributes(
- Map<String, List<ComponentInstanceProperty>> componentInstancesAttributes) {
- this.componentInstancesAttributes = componentInstancesAttributes;
- }
+ public void setCapabilities(Map<String, List<CapabilityDefinition>> capabilities) {
+ this.capabilities = capabilities;
+ }
- public Map<String, List<CapabilityDefinition>> getCapabilities() {
- return capabilities;
- }
+ public Map<String, List<RequirementDefinition>> getRequirements() {
+ return requirements;
+ }
- public void setCapabilities(Map<String, List<CapabilityDefinition>> capabilities) {
- this.capabilities = capabilities;
- }
+ public void setRequirements(Map<String, List<RequirementDefinition>> requirements) {
+ this.requirements = requirements;
+ }
- public Map<String, List<RequirementDefinition>> getRequirements() {
- return requirements;
- }
+ public List<InputDefinition> getInputs() {
+ return inputs;
+ }
- public void setRequirements(Map<String, List<RequirementDefinition>> requirements) {
- this.requirements = requirements;
- }
+ public void setInputs(List<InputDefinition> inputs) {
+ this.inputs = inputs;
+ }
- public List<InputDefinition> getInputs() {
- return inputs;
- }
+ public List<GroupDefinition> getGroups() {
+ return groups;
+ }
- public void setInputs(List<InputDefinition> inputs) {
- this.inputs = inputs;
- }
+ public void setGroups(List<GroupDefinition> groups) {
+ this.groups = groups;
+ }
- public List<GroupDefinition> getGroups() {
- return groups;
- }
+ public List<AdditionalInformationDefinition> getAdditionalInformation() {
+ return additionalInformation;
+ }
- public void setGroups(List<GroupDefinition> groups) {
- this.groups = groups;
- }
+ public void setAdditionalInformation(List<AdditionalInformationDefinition> additionalInformation) {
+ this.additionalInformation = additionalInformation;
+ }
- public List<AdditionalInformationDefinition> getAdditionalInformation() {
- return additionalInformation;
- }
+ public List<PolicyDefinition> getPolicies() {
+ return policies;
+ }
+ public void setPolicies(List<PolicyDefinition> policies) {
+ this.policies = policies;
+ }
- public void setAdditionalInformation(List<AdditionalInformationDefinition> additionalInformation) {
- this.additionalInformation = additionalInformation;
- }
-
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceDataTransfer.java
index 757dccf5d9..c784a598ab 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceDataTransfer.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiServiceDataTransfer.java
@@ -20,15 +20,15 @@
package org.openecomp.sdc.be.ui.model;
-import java.util.Map;
-
+import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
+import java.util.Map;
public class UiServiceDataTransfer extends UiComponentDataTransfer {
private Map<String, ArtifactDefinition> serviceApiArtifacts;
-
+ private Map<String, ForwardingPathDataDefinition> forwardingPaths;
private UiServiceMetadata metadata;
public UiServiceMetadata getMetadata() {
@@ -46,4 +46,12 @@ public class UiServiceDataTransfer extends UiComponentDataTransfer {
public void setServiceApiArtifacts(Map<String, ArtifactDefinition> serviceApiArtifacts) {
this.serviceApiArtifacts = serviceApiArtifacts;
}
+
+ public java.util.Map<String, org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition> getForwardingPaths() {
+ return forwardingPaths;
+ }
+
+ public void setForwardingPaths(java.util.Map<String, org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition> forwardingPaths) {
+ this.forwardingPaths = forwardingPaths;
+ }
}