From 0953785bfd6a3af5e506f8a55a8520c0fb7ef358 Mon Sep 17 00:00:00 2001 From: Talio Date: Thu, 31 Jan 2019 18:00:36 +0200 Subject: Add property mapping feature to ONAP Add service property assignment Change-Id: I29748ce12bacab06b8bc27f8875b39d80ffe5af7 Issue-ID: SDC-1988 Signed-off-by: Talio --- .../java/org/openecomp/sdc/be/model/Component.java | 211 ++++++++------- .../sdc/be/model/ComponentInstInputsMap.java | 13 + .../openecomp/sdc/be/model/ComponentInstance.java | 28 ++ .../sdc/be/model/ComponentInstanceInterface.java | 53 ++++ .../sdc/be/model/InterfaceInstanceDefinition.java | 39 +++ .../sdc/be/model/MapInterfaceDataDefinition.java | 42 +++ .../model/MapInterfaceInstanceDataDefinition.java | 43 +++ .../openecomp/sdc/be/model/OperationInstance.java | 63 +++++ .../java/org/openecomp/sdc/be/model/Resource.java | 33 ++- .../java/org/openecomp/sdc/be/model/Service.java | 5 +- .../jsontitan/datamodel/TopologyTemplate.java | 41 +++ .../jsontitan/operations/ToscaOperationFacade.java | 300 ++++++++++++++------- .../be/model/jsontitan/utils/ModelConverter.java | 232 ++++++++-------- .../operations/api/StorageOperationStatus.java | 3 +- 14 files changed, 798 insertions(+), 308 deletions(-) create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInterface.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceInstanceDefinition.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/MapInterfaceDataDefinition.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/MapInterfaceInstanceDataDefinition.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/OperationInstance.java (limited to 'catalog-model/src') 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 7c5368887b..24386bc42e 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 @@ -25,17 +25,19 @@ import com.google.common.collect.Maps; import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.utils.MapUtil; +import org.openecomp.sdc.be.datatypes.elements.*; 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 static java.util.Collections.emptyList; -import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType; -import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; -import java.util.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -45,37 +47,38 @@ import static java.util.stream.Collectors.toMap; import static org.apache.commons.collections.CollectionUtils.isEmpty; import static org.apache.commons.collections.MapUtils.isEmpty; -public abstract class Component { - - private ComponentMetadataDefinition componentMetadataDefinition; - private Map artifacts; - private Map deploymentArtifacts; - private Map toscaArtifacts; - private List categories; - private List componentInstances; - private List componentInstancesRelations; - private Map> componentInstancesInputs; - private Map> componentInstancesProperties; - private Map> componentInstancesAttributes; - private Map> capabilities; - private Map> requirements; - private List inputs; - private List groups; - private Map policies; - private String derivedFromGenericType; - private String derivedFromGenericVersion; - private String toscaType; - protected List additionalInformation; - protected List properties; - private Map interfaces; - - public Map getInterfaces() { - return interfaces; - } - - public void setInterfaces(Map interfaces) { - this.interfaces = interfaces; - } +public abstract class Component implements PropertiesOwner { + + private ComponentMetadataDefinition componentMetadataDefinition; + private Map artifacts; + private Map deploymentArtifacts; + private Map toscaArtifacts; + private List categories; + private List componentInstances; + private List componentInstancesRelations; + private Map> componentInstancesInputs; + private Map> componentInstancesProperties; + private Map> componentInstancesAttributes; + private Map> capabilities; + private Map> requirements; + private Map> componentInstancesInterfaces; + private List inputs; + private List groups; + private Map policies; + private String derivedFromGenericType; + private String derivedFromGenericVersion; + private String toscaType; + protected List additionalInformation; + protected List properties; + private Map interfaces; + + public Map getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map interfaces) { + this.interfaces = interfaces; + } public Component(ComponentMetadataDefinition componentMetadataDefinition) { this.componentMetadataDefinition = componentMetadataDefinition; @@ -119,9 +122,10 @@ public abstract class Component { this.toscaArtifacts = toscaArtifacts; } - public String getUniqueId() { - return componentMetadataDefinition.getMetadataDataDefinition().getUniqueId(); - } + @Override + public String getUniqueId() { + return componentMetadataDefinition.getMetadataDataDefinition().getUniqueId(); + } public void setUniqueId(String uniqueId) { componentMetadataDefinition.getMetadataDataDefinition().setUniqueId(uniqueId); @@ -203,9 +207,10 @@ public abstract class Component { this.componentMetadataDefinition.getMetadataDataDefinition().setLastUpdaterFullName(lastUpdaterFullName); } - public String getName() { - return componentMetadataDefinition.getMetadataDataDefinition().getName(); - } + @Override + public String getName() { + return componentMetadataDefinition.getMetadataDataDefinition().getName(); + } public String getVersion() { return componentMetadataDefinition.getMetadataDataDefinition().getVersion(); @@ -317,9 +322,10 @@ public abstract class Component { this.categories = categories; } - public String getNormalizedName() { - return componentMetadataDefinition.getMetadataDataDefinition().getNormalizedName(); - } + @Override + public String getNormalizedName() { + return componentMetadataDefinition.getMetadataDataDefinition().getNormalizedName(); + } public void setNormalizedName(String normalizedName) { componentMetadataDefinition.getMetadataDataDefinition().setNormalizedName(normalizedName); @@ -355,7 +361,7 @@ public abstract class Component { public List getComponentInstances() { return componentInstances; } - + public List safeGetComponentInstances() { if(componentInstances != null) { return componentInstances; @@ -418,10 +424,14 @@ public abstract class Component { return this.safeGetComponentInstanceEntity(comptInstanceId, this.componentInstancesInputs); } - public void setComponentInstancesProperties( - Map> resourceInstancesProperties) { - this.componentInstancesProperties = resourceInstancesProperties; - } + public List safeGetComponentInstanceInterfaces(String cmptInstacneId) { + return this.safeGetComponentInstanceEntity(cmptInstacneId, this.componentInstancesInterfaces); + } + + public void setComponentInstancesProperties( + Map> resourceInstancesProperties) { + this.componentInstancesProperties = resourceInstancesProperties; + } public Boolean getIsDeleted() { return componentMetadataDefinition.getMetadataDataDefinition().isDeleted(); @@ -515,58 +525,69 @@ public abstract class Component { .findAny(); } - public void setGroups(List groups) { - this.groups = groups; - } + public Map> getComponentInstancesInterfaces() { + return componentInstancesInterfaces; + } - public void addGroups(List groupsToAdd) { - if (groups == null) { - groups = new ArrayList<>(); - } - groups.addAll(groupsToAdd); - } + public void setComponentInstancesInterfaces(Map> componentInstancesInterfaces) { + this.componentInstancesInterfaces = componentInstancesInterfaces; + } - public Map getPolicies() { - return policies; - } + public void setGroups(List groups) { + this.groups = groups; + } - public void setPolicies(Map policies) { - this.policies = policies; + public void addGroups(List groupsToAdd) { + if (groups == null) { + groups = new ArrayList<>(); } + groups.addAll(groupsToAdd); + } - public List getProperties() { - return properties; - } + public Map getPolicies() { + return policies; + } - public void setProperties(List properties) { - this.properties = properties; + public void setPolicies(Map policies) { + this.policies = policies; } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((artifacts == null) ? 0 : artifacts.hashCode()); - result = prime * result + ((categories == null) ? 0 : categories.hashCode()); - result = prime * result + ((componentMetadataDefinition == null) ? 0 : componentMetadataDefinition.hashCode()); - result = prime * result + ((deploymentArtifacts == null) ? 0 : deploymentArtifacts.hashCode()); - result = prime * result + ((capabilities == null) ? 0 : capabilities.hashCode()); - result = prime * result + ((requirements == null) ? 0 : requirements.hashCode()); - result = prime * result + ((componentInstances == null) ? 0 : componentInstances.hashCode()); - result = prime * result - + ((componentInstancesProperties == null) ? 0 : componentInstancesProperties.hashCode()); - result = prime * result - + ((componentInstancesAttributes == null) ? 0 : componentInstancesAttributes.hashCode()); - 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()); - result = prime * result + ((interfaces == null) ? 0 : interfaces.hashCode()); - result = prime * result + ((properties == null) ? 0 : properties.hashCode()); - return result; - } + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((artifacts == null) ? 0 : artifacts.hashCode()); + result = prime * result + ((categories == null) ? 0 : categories.hashCode()); + result = prime * result + ((componentMetadataDefinition == null) ? 0 : componentMetadataDefinition.hashCode()); +// result = prime * result + ((creatorUserId == null) ? 0 : creatorUserId.hashCode()); +// result = prime * result + ((creatorFullName == null) ? 0 : creatorFullName.hashCode()); + result = prime * result + ((deploymentArtifacts == null) ? 0 : deploymentArtifacts.hashCode()); +// result = prime * result + ((lastUpdaterUserId == null) ? 0 : lastUpdaterUserId.hashCode()); +// result = prime * result + ((lastUpdaterFullName == null) ? 0 : lastUpdaterFullName.hashCode()); + result = prime * result + ((capabilities == null) ? 0 : capabilities.hashCode()); + result = prime * result + ((requirements == null) ? 0 : requirements.hashCode()); + result = prime * result + ((componentInstances == null) ? 0 : componentInstances.hashCode()); + result = prime * result + + ((componentInstancesProperties == null) ? 0 : componentInstancesProperties.hashCode()); + result = prime * result + + ((componentInstancesAttributes == null) ? 0 : componentInstancesAttributes.hashCode()); + 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()); + result = prime * result + ((interfaces == null) ? 0 : interfaces.hashCode()); + return result; + } @Override public boolean equals(Object obj) { 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 306992d2fc..9d0877d8f9 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 @@ -31,6 +31,7 @@ public class ComponentInstInputsMap { private Map> componentInstanceInputsMap; private Map> componentInstanceProperties; + private Map> serviceProperties; private Map> policyProperties; private Map> groupProperties; @@ -44,6 +45,9 @@ public class ComponentInstInputsMap { if (isNotEmpty(policyProperties)) { return singleMapEntry(policyProperties); } + if(isNotEmpty(serviceProperties)) { + return singleMapEntry(serviceProperties); + } if (isNotEmpty(groupProperties)) { return singleMapEntry(groupProperties); } @@ -79,6 +83,15 @@ public class ComponentInstInputsMap { this.policyProperties = policyProperties; } + public Map> getServiceProperties() { + return serviceProperties; + } + + public void setServiceProperties( + Map> serviceProperties) { + this.serviceProperties = serviceProperties; + } + public Map> getGroupProperties() { return groupProperties; } 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 ef9b409735..0d18676acc 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 @@ -20,12 +20,14 @@ package org.openecomp.sdc.be.model; +import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,6 +38,8 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement private Map deploymentArtifacts; private Map artifacts; private List groupInstances; + private Map interfaces; + private List properties; private CINodeFilterDataDefinition nodeFilter; public ComponentInstance() { @@ -109,6 +113,30 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement return safeGetInformationalArtifacts().get(artifactLabel) != null; } + public Map getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map interfaces) { + this.interfaces = interfaces; + } + + public void addInterface(String interfaceName, Object interfaceDefinition) { + if(MapUtils.isEmpty(this.interfaces)) { + this.interfaces = new HashMap<>(); + } + + this.interfaces.put(interfaceName, interfaceDefinition); + } + + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } + public CINodeFilterDataDefinition getNodeFilter() { return nodeFilter; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInterface.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInterface.java new file mode 100644 index 0000000000..5482a51d7a --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInterface.java @@ -0,0 +1,53 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.model; + +import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition; + +public class ComponentInstanceInterface extends InterfaceDefinition { + private String interfaceId; + private InterfaceInstanceDataDefinition interfaceInstanceDataDefinition; + + public ComponentInstanceInterface(String interfaceId, + InterfaceInstanceDataDefinition interfaceInstanceDataDefinition) { + this.interfaceId = interfaceId; + this.interfaceInstanceDataDefinition = interfaceInstanceDataDefinition; + } + + public ComponentInstanceInterface(String interfaceId, InterfaceDataDefinition interfaceDataDefinition) { + super(interfaceDataDefinition); + this.interfaceId = interfaceId; + } + + public String getInterfaceId() { + return interfaceId; + } + + public void setInterfaceId(String interfaceId) { + this.interfaceId = interfaceId; + } + + public InterfaceInstanceDataDefinition getInterfaceInstanceDataDefinition() { + return interfaceInstanceDataDefinition; + } + + public void setInterfaceInstanceDataDefinition( + InterfaceInstanceDataDefinition interfaceInstanceDataDefinition) { + this.interfaceInstanceDataDefinition = interfaceInstanceDataDefinition; + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceInstanceDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceInstanceDefinition.java new file mode 100644 index 0000000000..d16370d151 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceInstanceDefinition.java @@ -0,0 +1,39 @@ +package org.openecomp.sdc.be.model; + +import org.apache.commons.collections.MapUtils; +import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationInstance; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class InterfaceInstanceDefinition extends InterfaceInstanceDataDefinition { + + public InterfaceInstanceDefinition(InterfaceInstanceDataDefinition inter) { + super(inter); + } + + public InterfaceInstanceDefinition(){} + + public Map getInputs() { + return this.inputs; + } + + public void setInputs( + Map inputs) { + this.inputs = inputs; + } + + public Map getOperations() { + return operations; + } + + public void addInstanceOperation(String operationName, OperationInstance operation) { + if(MapUtils.isEmpty(this.operations)) { + this.operations = new HashMap<>(); + } + + this.operations.put(operationName, operation); + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/MapInterfaceDataDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/MapInterfaceDataDefinition.java new file mode 100644 index 0000000000..c58131f542 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/MapInterfaceDataDefinition.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition; + +import java.util.Map; + +public class MapInterfaceDataDefinition extends MapDataDefinition { + + public MapInterfaceDataDefinition() { + + } + + @JsonCreator + public MapInterfaceDataDefinition(Map mapToscaDataDefinition) { + super(mapToscaDataDefinition); + } + + @JsonValue + @Override + public Map getMapToscaDataDefinition() { + return mapToscaDataDefinition; + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/MapInterfaceInstanceDataDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/MapInterfaceInstanceDataDefinition.java new file mode 100644 index 0000000000..6efa0ed404 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/MapInterfaceInstanceDataDefinition.java @@ -0,0 +1,43 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition; + +import java.util.Map; + +public class MapInterfaceInstanceDataDefinition extends + MapDataDefinition { + + public MapInterfaceInstanceDataDefinition() { + + } + + @JsonCreator + public MapInterfaceInstanceDataDefinition(Map mapToscaDataDefinition) { + super(mapToscaDataDefinition); + } + + @JsonValue + @Override + public Map getMapToscaDataDefinition() { + return mapToscaDataDefinition; + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/OperationInstance.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/OperationInstance.java new file mode 100644 index 0000000000..fb958eb7b6 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/OperationInstance.java @@ -0,0 +1,63 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.model; + +import org.openecomp.sdc.be.datatypes.elements.OperationImplementation; + +import java.util.Map; +import java.util.Objects; + +public class OperationInstance/* extends Operation*/ { + private OperationImplementation implementation; + private Map inputs; + + + public OperationImplementation getImplementation() { + return implementation; + } + + public void setImplementation(OperationImplementation implementation) { + this.implementation = implementation; + } + + public Map getInputs() { + return inputs; + } + + public void setInputs(Map inputs) { + this.inputs = inputs; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof OperationInstance)) { + return false; + } + OperationInstance that = (OperationInstance) o; + return Objects.equals(implementation, that.implementation) && + Objects.equals(inputs, that.inputs); + } + + @Override + public int hashCode() { + + return Objects.hash(implementation, inputs); + } +} 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 f3996ed42b..0603538833 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 @@ -42,12 +42,15 @@ public class Resource extends Component { private List attributes; - private List defaultCapabilities; - - public Resource() { - super(new ResourceMetadataDefinition()); - this.getComponentMetadataDefinition().getMetadataDataDefinition().setComponentType(ComponentTypeEnum.RESOURCE); - } + private Map instInterfaces; + + private List defaultCapabilities; + + public Resource() { + super(new ResourceMetadataDefinition()); + this.getComponentMetadataDefinition().getMetadataDataDefinition() + .setComponentType(ComponentTypeEnum.RESOURCE); + } public Resource(ComponentMetadataDefinition componentMetadataDefinition) { super(componentMetadataDefinition); @@ -101,10 +104,20 @@ public class Resource extends Component { this.attributes = attributes; } - public Boolean isAbstract() { - return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .isAbstract(); - } + public Map getInstInterfaces() { + return instInterfaces; + } + + public void setInstInterfaces( + Map instInterfaces) { + this.instInterfaces = instInterfaces; + } + + public Boolean isAbstract() { + return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition() + .getMetadataDataDefinition()) + .isAbstract(); + } public void setAbstract(Boolean isAbstract) { ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) 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 823ababcc0..3c1ca26879 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 @@ -22,6 +22,10 @@ package org.openecomp.sdc.be.model; import org.apache.commons.lang.StringUtils; import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition; +import java.util.HashMap; +import java.util.List; +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; @@ -51,7 +55,6 @@ public class Service extends Component { private Map serviceApiArtifacts; private Map forwardingPaths; - public Map getServiceApiArtifacts() { return serviceApiArtifacts; } 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 0d7b14abd1..ac9f196a92 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 @@ -25,6 +25,8 @@ import org.openecomp.sdc.be.datatypes.elements.*; import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty; import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; +import org.openecomp.sdc.be.model.MapInterfaceDataDefinition; +import org.openecomp.sdc.be.model.MapInterfaceInstanceDataDefinition; import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum; import java.util.HashMap; @@ -54,6 +56,8 @@ public class TopologyTemplate extends ToscaElement{ private Map instDeploymentArtifacts; private Map instanceArtifacts; private Map interfaces; + private Map instInterfaces; + private Map componentInstInterfaces; //Component Instances External References (instanceId -> ExternalRefsMap) //----------------------------------------------------------------------- @@ -76,6 +80,43 @@ public class TopologyTemplate extends ToscaElement{ this.interfaces = interfaces; } + public Map getInstInterfaces() { + return instInterfaces; + } + + public void setInstInterfaces( + Map instInterfaces) { + this.instInterfaces = instInterfaces; + } + + public void addInstInterface(String compId, MapInterfaceInstanceDataDefinition + mapInterfaceInstanceDataDefinition) { + if(MapUtils.isEmpty(this.instInterfaces)) { + this.instInterfaces = new HashMap<>(); + } + + this.instInterfaces.put(compId, mapInterfaceInstanceDataDefinition); + } + + public Map getComponentInstInterfaces() { + return componentInstInterfaces; + } + + public void setComponentInstInterfaces( + Map componentInstInterfaces) { + this.componentInstInterfaces = componentInstInterfaces; + } + + public void addComponentInstanceInterfaceMap(String componentInstanceId, MapInterfaceDataDefinition + mapInterfaceDataDefinition) { + if(MapUtils.isEmpty(this.componentInstInterfaces)) { + this.componentInstInterfaces = new HashMap<>(); + } + + this.componentInstInterfaces.put(componentInstanceId, mapInterfaceDataDefinition); + } + + public Map getInputs() { return inputs; } 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 5c06e97bf3..d8a4fc4af1 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 @@ -25,6 +25,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; @@ -35,8 +36,6 @@ import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; import org.openecomp.sdc.be.datatypes.elements.*; import org.openecomp.sdc.be.datatypes.enums.*; import org.openecomp.sdc.be.model.*; -import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty; -import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition; 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; @@ -971,7 +970,35 @@ public class ToscaOperationFacade { } - public Either, StorageOperationStatus> updateInputsToComponent(List inputs, String componentId) { + public Either, StorageOperationStatus> getComponentInputs(String componentId) { + + Either getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); + if (getVertexEither.isRight()) { + log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value()); + return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value())); + + } + + Either toscaElement = + topologyTemplateOperation.getToscaElement(componentId); + if(toscaElement.isRight()) { + return Either.right(toscaElement.right().value()); + } + + TopologyTemplate topologyTemplate = (TopologyTemplate) toscaElement.left().value(); + + Map inputsMap = topologyTemplate.getInputs(); + + List inputs = new ArrayList<>(); + if(MapUtils.isNotEmpty(inputsMap)) { + inputs = + inputsMap.values().stream().map(p -> new InputDefinition(p)).collect(Collectors.toList()); + } + + return Either.left(inputs); + } + + public Either, StorageOperationStatus> updateInputsToComponent(List inputs, String componentId) { Either getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); if (getVertexEither.isRight()) { @@ -1135,7 +1162,7 @@ public class ToscaOperationFacade { } return Either.left(instProperties); } - + public Either>, StorageOperationStatus> addComponentInstancePropertiesToComponent(Component containerComponent, Map> instProperties) { requireNonNull(instProperties); StorageOperationStatus status; @@ -1984,91 +2011,97 @@ public class ToscaOperationFacade { return nodeTemplateOperation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances); } - /* - * adds property to a resource - * @warn this method has SIDE EFFECT on ownerId ,use it with caution - * */ - public Either addPropertyToResource(String propertyName, PropertyDefinition newPropertyDefinition, Resource resource) { - - Either result = null; - Either getUpdatedComponentRes = null; - newPropertyDefinition.setName(propertyName); - StorageOperationStatus status = getToscaElementOperation(resource).addToscaDataToToscaElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME); - if (status != StorageOperationStatus.OK) { - CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_ADD_THE_PROPERTY_TO_THE_RESOURCE_STATUS_IS, propertyName, resource.getName(), status); - result = Either.right(status); - } - if (result == null) { - ComponentParametersView filter = new ComponentParametersView(true); - filter.setIgnoreProperties(false); - getUpdatedComponentRes = getToscaElement(resource.getUniqueId(), filter); - if (getUpdatedComponentRes.isRight()) { - CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_GET_UPDATED_RESOURCE_STATUS_IS, resource.getUniqueId(), getUpdatedComponentRes.right().value()); - result = Either.right(status); - } - } - if (result == null) { - PropertyDefinition newProperty = null; - List properties = ((Resource) getUpdatedComponentRes.left().value()).getProperties(); - if (CollectionUtils.isNotEmpty(properties)) { - Optional newPropertyOptional = properties.stream().filter(p -> p.getName().equals(propertyName)).findAny(); - if (newPropertyOptional.isPresent()) { - newProperty = newPropertyOptional.get(); - } - } - if (newProperty == null) { - CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_FIND_RECENTLY_ADDED_PROPERTY_ON_THE_RESOURCE_STATUS_IS, propertyName, resource.getUniqueId(), StorageOperationStatus.NOT_FOUND); - result = Either.right(StorageOperationStatus.NOT_FOUND); - } else { - result = Either.left(newProperty); - } - } - return result; - } - - public StorageOperationStatus deletePropertyOfResource(Resource resource, String propertyName) { - return getToscaElementOperation(resource).deleteToscaDataElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, propertyName, JsonPresentationFields.NAME); - } - - public StorageOperationStatus deleteAttributeOfResource(Component component, String attributeName) { - return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, attributeName, JsonPresentationFields.NAME); - } + public Either addPropertyToComponent(String propertyName, + PropertyDefinition newPropertyDefinition, + Component component) { + + Either result = null; + Either getUpdatedComponentRes = null; + newPropertyDefinition.setName(propertyName); + + StorageOperationStatus status = getToscaElementOperation(component) + .addToscaDataToToscaElement(component.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME); + if (status != StorageOperationStatus.OK) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the component {}. Status is {}. ", propertyName, component.getName(), status); + result = Either.right(status); + } + if (result == null) { + ComponentParametersView filter = new ComponentParametersView(true); + filter.setIgnoreProperties(false); + filter.setIgnoreInputs(false); + getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter); + if (getUpdatedComponentRes.isRight()) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated component {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value()); + result = Either.right(status); + } + } + if (result == null) { + PropertyDefinition newProperty = null; + List properties = + (getUpdatedComponentRes.left().value()).getProperties(); + if (CollectionUtils.isNotEmpty(properties)) { + Optional propertyOptional = properties.stream().filter( + propertyEntry -> propertyEntry.getName().equals(propertyName)).findAny(); + if (propertyOptional.isPresent()) { + newProperty = propertyOptional.get(); + } + } + if (newProperty == null) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the component {}. Status is {}. ", propertyName, component.getUniqueId(), StorageOperationStatus.NOT_FOUND); + result = Either.right(StorageOperationStatus.NOT_FOUND); + } else { + result = Either.left(newProperty); + } + } + return result; + } + public StorageOperationStatus deletePropertyOfComponent(Component component, String propertyName) { + return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, propertyName, JsonPresentationFields.NAME); + } + + public StorageOperationStatus deleteAttributeOfResource(Component component, String attributeName) { + return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.ATTRIBUTES, VertexTypeEnum.ATTRIBUTES, attributeName, JsonPresentationFields.NAME); + } public StorageOperationStatus deleteInputOfResource(Component resource, String inputName) { return getToscaElementOperation(resource).deleteToscaDataElement(resource.getUniqueId(), EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, inputName, JsonPresentationFields.NAME); } - public Either updatePropertyOfResource(Resource resource, PropertyDefinition newPropertyDefinition) { - - Either getUpdatedComponentRes = null; - Either result = null; - StorageOperationStatus status = getToscaElementOperation(resource).updateToscaDataOfToscaElement(resource.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME); - if (status != StorageOperationStatus.OK) { - CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_ADD_THE_PROPERTY_TO_THE_RESOURCE_STATUS_IS, newPropertyDefinition.getName(), resource.getName(), status); - result = Either.right(status); - } - if (result == null) { - ComponentParametersView filter = new ComponentParametersView(true); - filter.setIgnoreProperties(false); - getUpdatedComponentRes = getToscaElement(resource.getUniqueId(), filter); - if (getUpdatedComponentRes.isRight()) { - CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_GET_UPDATED_RESOURCE_STATUS_IS, resource.getUniqueId(), getUpdatedComponentRes.right().value()); - result = Either.right(status); - } - } - if (result == null) { - Optional newProperty = ((Resource) getUpdatedComponentRes.left().value()).getProperties().stream().filter(p -> p.getName().equals(newPropertyDefinition.getName())).findAny(); - if (newProperty.isPresent()) { - result = Either.left(newProperty.get()); - } else { - CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_FIND_RECENTLY_ADDED_PROPERTY_ON_THE_RESOURCE_STATUS_IS, newPropertyDefinition.getName(), resource.getUniqueId(), StorageOperationStatus.NOT_FOUND); - result = Either.right(StorageOperationStatus.NOT_FOUND); - } - } - return result; - } - - public Either addAttributeOfResource(Component component, PropertyDefinition newAttributeDef) { + public Either updatePropertyOfComponent(Component component, + PropertyDefinition newPropertyDefinition) { + + Either getUpdatedComponentRes = null; + Either result = null; + StorageOperationStatus status = getToscaElementOperation(component).updateToscaDataOfToscaElement(component.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME); + if (status != StorageOperationStatus.OK) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the resource {}. Status is {}. ", newPropertyDefinition.getName(), component.getName(), status); + result = Either.right(status); + } + if (result == null) { + ComponentParametersView filter = new ComponentParametersView(true); + filter.setIgnoreProperties(false); + getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter); + if (getUpdatedComponentRes.isRight()) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated resource {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value()); + result = Either.right(status); + } + } + if (result == null) { + Optional newProperty = (getUpdatedComponentRes.left().value()) + .getProperties().stream().filter(p -> p.getName().equals(newPropertyDefinition.getName())).findAny(); + if (newProperty.isPresent()) { + result = Either.left(newProperty.get()); + } else { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the resource {}. Status is {}. ", newPropertyDefinition.getName(), component.getUniqueId(), StorageOperationStatus.NOT_FOUND); + result = Either.right(StorageOperationStatus.NOT_FOUND); + } + } + return result; + } + + + + public Either addAttributeOfResource(Component component, PropertyDefinition newAttributeDef) { Either getUpdatedComponentRes = null; Either result = null; @@ -2263,10 +2296,11 @@ public class ToscaOperationFacade { .orElse(StorageOperationStatus.NOT_FOUND); } - public StorageOperationStatus updateComponentCalculatedCapabilitiesProperties(Component containerComponent) { - Map MapCapabilityPropertyMap = convertComponentCapabilitiesProperties(containerComponent); - return nodeTemplateOperation.overrideComponentCapabilitiesProperties(containerComponent, MapCapabilityPropertyMap); - } + public StorageOperationStatus updateComponentCalculatedCapabilitiesProperties(Component containerComponent) { + Map mapCapabiltyPropertyMap = + convertComponentCapabilitiesProperties(containerComponent); + return nodeTemplateOperation.overrideComponentCapabilitiesProperties(containerComponent, mapCapabiltyPropertyMap); + } public StorageOperationStatus deleteAllCalculatedCapabilitiesRequirements(String topologyTemplateId) { StorageOperationStatus status = topologyTemplateOperation.removeToscaData(topologyTemplateId, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES); @@ -2309,11 +2343,24 @@ public class ToscaOperationFacade { return topologyTemplateOperation.getComponentInstanceCapabilityProperties(componentId, instanceId, capabilityName, capabilityType, ownerId); } - private Map convertComponentCapabilitiesProperties(Component currComponent) { - Map map = ModelConverter.extractCapabilityPropertiesFromGroups(currComponent.getGroups(), true); - map.putAll(ModelConverter.extractCapabilityProperteisFromInstances(currComponent.getComponentInstances(), true)); - return map; - } + private MapInterfaceDataDefinition convertComponentInstanceInterfaces(Component currComponent, + String componentInstanceId) { + MapInterfaceDataDefinition mapInterfaceDataDefinition = new MapInterfaceDataDefinition(); + List componentInterface = currComponent.getComponentInstancesInterfaces().get(componentInstanceId); + + if(CollectionUtils.isNotEmpty(componentInterface)) { + componentInterface.stream().forEach(interfaceDef -> mapInterfaceDataDefinition.put + (interfaceDef.getUniqueId(), interfaceDef)); + } + + return mapInterfaceDataDefinition; + } + + private Map convertComponentCapabilitiesProperties(Component currComponent) { + Map map = ModelConverter.extractCapabilityPropertiesFromGroups(currComponent.getGroups(), true); + map.putAll(ModelConverter.extractCapabilityProperteisFromInstances(currComponent.getComponentInstances(), true)); + return map; + } private Optional convertComponentInstanceProperties(Component component, String instanceId) { return component.fetchInstanceById(instanceId) @@ -2433,4 +2480,71 @@ public class ToscaOperationFacade { throw new StorageException(status); } + public Either isComponentInUse(String componentId) { + final List forbiddenEdgeLabelEnums = Arrays.asList(EdgeLabelEnum.INSTANCE_OF, EdgeLabelEnum.PROXY_OF, EdgeLabelEnum.ALLOTTED_OF); + Either vertexById = titanDao.getVertexById(componentId); + if (vertexById.isLeft()) { + for (EdgeLabelEnum edgeLabelEnum : forbiddenEdgeLabelEnums) { + Iterator edgeItr = vertexById.left().value().getVertex().edges(Direction.IN, edgeLabelEnum.name()); + if(edgeItr != null && edgeItr.hasNext()){ + return Either.left(true); + } + } + } + return Either.left(false); + } + + public Either, StorageOperationStatus> getComponentListByInvariantUuid + (String componentInvariantUuid, Map additionalPropertiesToMatch) { + + Map propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); + if (MapUtils.isNotEmpty(additionalPropertiesToMatch)) { + propertiesToMatch.putAll(additionalPropertiesToMatch); + } + propertiesToMatch.put(GraphPropertyEnum.INVARIANT_UUID, componentInvariantUuid); + + Either, TitanOperationStatus> vertexEither = titanDao.getByCriteria(null, propertiesToMatch, JsonParseFlagEnum.ParseMetadata); + + if (vertexEither.isRight()) { + log.debug("Couldn't fetch metadata for component with type {} and invariantUUId {}, error: {}", componentInvariantUuid, vertexEither.right().value()); + return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexEither.right().value())); + } + List vertexList = vertexEither.isLeft() ? vertexEither.left().value() : null; + + if (vertexList == null || vertexList.isEmpty()) { + log.debug("Component with invariantUUId {} was not found", componentInvariantUuid); + return Either.right(StorageOperationStatus.NOT_FOUND); + } + + ArrayList components = new ArrayList<>(); + for (GraphVertex vertex : vertexList) { + Either toscaElementByOperation = getToscaElementByOperation(vertex); + if (toscaElementByOperation.isRight()) { + log.debug("Could not fetch the following Component by Invariant UUID {}", vertex.getUniqueId()); + return Either.right(toscaElementByOperation.right().value()); + } + components.add(toscaElementByOperation.left().value()); + } + + return Either.left(components); + } + + public Either, StorageOperationStatus> getParentComponents(String componentId) { + List parentComponents = new ArrayList<>(); + final List relationEdgeLabelEnums = Arrays.asList(EdgeLabelEnum.INSTANCE_OF, EdgeLabelEnum.PROXY_OF); + Either vertexById = titanDao.getVertexById(componentId); + if (vertexById.isLeft()) { + for (EdgeLabelEnum edgeLabelEnum : relationEdgeLabelEnums) { + Either parentVertexEither = titanDao.getParentVertex(vertexById.left().value(), edgeLabelEnum, JsonParseFlagEnum.ParseJson); + if(parentVertexEither.isLeft()){ + Either componentEither = getToscaElement(parentVertexEither.left().value().getUniqueId()); + if(componentEither.isLeft()){ + parentComponents.add(componentEither.left().value()); + } + } + } + } + return Either.left(parentComponents); + } + } 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 569491cef6..6a49509d6f 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 @@ -22,68 +22,17 @@ package org.openecomp.sdc.be.model.jsontitan.utils; import com.google.common.collect.Lists; import com.google.common.collect.Maps; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; - import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.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; -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.MapCapabilityProperty; -import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition; -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.elements.*; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; -import org.openecomp.sdc.be.model.AdditionalInformationDefinition; -import org.openecomp.sdc.be.model.ArtifactDefinition; -import org.openecomp.sdc.be.model.CapabilityDefinition; -import org.openecomp.sdc.be.model.CapabilityRequirementRelationship; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.ComponentInstance; -import org.openecomp.sdc.be.model.ComponentInstanceInput; -import org.openecomp.sdc.be.model.ComponentInstanceProperty; -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.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; -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.*; 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; @@ -95,6 +44,11 @@ import org.openecomp.sdc.be.resources.data.ResourceMetadataData; import org.openecomp.sdc.be.resources.data.ServiceMetadataData; import org.openecomp.sdc.common.log.wrappers.Logger; +import java.util.*; +import java.util.Map.Entry; +import java.util.function.Function; +import java.util.stream.Collectors; + public class ModelConverter { public static final String CAP_PROP_DELIM = "#"; private static final Logger log = Logger.getLogger(ModelConverter.class); @@ -171,7 +125,11 @@ public class ModelConverter { convertComponentInstances(topologyTemplate, service); - convertInputs(topologyTemplate, service); + convertInputs(topologyTemplate, service); + + convertProperties(topologyTemplate, service); + + convertPolicies(topologyTemplate, service); convertGroups(topologyTemplate, service); @@ -591,8 +549,14 @@ public class ModelConverter { component.setDerivedFromGenericType(toscaElement.getDerivedFromGenericType()); component.setDerivedFromGenericVersion(toscaElement.getDerivedFromGenericVersion()); - //archive - component.setArchived(toscaElement.isArchived() == null ? false : toscaElement.isArchived()); + Map properties = toscaElement.getProperties(); + if(MapUtils.isNotEmpty(properties)) { + List propertiesMap = properties.values().stream().map(x -> new PropertyDefinition(x)).collect(Collectors.toList()); + component.setProperties(propertiesMap); + } + + //archive + component.setArchived(toscaElement.isArchived() == null ? false : toscaElement.isArchived()); //component.setArchiveTime(toscaElement.getArchiveTime() == null ? 0L : toscaElement.getArchiveTime()); @@ -632,14 +596,6 @@ public class ModelConverter { component.setContactId((String) toscaElement.getMetadataValue(JsonPresentationFields.CONTACT_ID)); component.setUUID((String) toscaElement.getMetadataValue(JsonPresentationFields.UUID)); component.setIsDeleted((Boolean) toscaElement.getMetadataValue(JsonPresentationFields.IS_DELETED)); - - - Map properties = toscaElement.getProperties(); - if (properties != null && !properties.isEmpty()) { - List propertiesMap = properties.values().stream().map(PropertyDefinition::new).collect(Collectors.toList()); - ((Resource) component).setProperties(propertiesMap); - } - component.setToscaType(toscaElement.getToscaType().getValue()); } @@ -944,34 +900,35 @@ public class ModelConverter { ComponentTypeEnum componentType = component.getComponentType(); topologyTemplate = new TopologyTemplate(); - if (componentType == ComponentTypeEnum.RESOURCE) { - Resource resource = (Resource) component; - topologyTemplate.setResourceType(resource.getResourceType()); - topologyTemplate.setMetadataValue(JsonPresentationFields.CSAR_UUID, resource.getCsarUUID()); - topologyTemplate.setMetadataValue(JsonPresentationFields.CSAR_VERSION, resource.getCsarVersion()); - topologyTemplate.setMetadataValue(JsonPresentationFields.IMPORTED_TOSCA_CHECKSUM, resource.getImportedToscaChecksum()); - convertInterfaces(resource, topologyTemplate); - } - if (componentType == ComponentTypeEnum.SERVICE) { - convertServiceSpecificEntities((Service) component, topologyTemplate); - } - convertCommonToscaData(component, topologyTemplate); - convertArtifacts(component, topologyTemplate); + if (componentType == ComponentTypeEnum.RESOURCE) { + Resource resource = (Resource) component; + topologyTemplate.setResourceType(resource.getResourceType()); + topologyTemplate.setMetadataValue(JsonPresentationFields.CSAR_UUID, resource.getCsarUUID()); + topologyTemplate.setMetadataValue(JsonPresentationFields.CSAR_VERSION, resource.getCsarVersion()); + topologyTemplate.setMetadataValue(JsonPresentationFields.IMPORTED_TOSCA_CHECKSUM, resource.getImportedToscaChecksum()); + convertTopologyTemplateInterfaces(resource, topologyTemplate); + } + if (componentType == ComponentTypeEnum.SERVICE) { + convertServiceSpecificEntities((Service) component, topologyTemplate); + } + convertCommonToscaData(component, topologyTemplate); + convertArtifacts(component, topologyTemplate); convertAdditionalInformation(component, topologyTemplate); convertComponentInstances(component, topologyTemplate); - convertInputs(component, topologyTemplate); - convertCapabilities(component, topologyTemplate); - convertGroups(component, topologyTemplate); - convertPolicies(component, topologyTemplate); - convertRequirements(component, topologyTemplate); - convertRelationsToComposition(component, topologyTemplate); + convertInputs(component, topologyTemplate); + convertProperties(component, topologyTemplate); + convertCapabilities(component, topologyTemplate); + convertGroups(component, topologyTemplate); + convertPolicies(component, topologyTemplate); + convertRequirements(component, topologyTemplate); + convertRelationsToComposition(component, topologyTemplate); return topologyTemplate; } - private static void convertInterfaces(Resource resource, TopologyTemplate topologyTemplate) { + private static void convertTopologyTemplateInterfaces(Resource resource, TopologyTemplate topologyTemplate) { Map interfaces = resource.getInterfaces(); if (interfaces != null && !interfaces.isEmpty()) { Map copy = interfaces.entrySet().stream() @@ -1047,17 +1004,36 @@ public class ModelConverter { } - private static void convertInputs(TopologyTemplate topologyTemplate, Component component) { - Map inputsMap = topologyTemplate.getInputs(); - if (inputsMap != null && !inputsMap.isEmpty()) { - List inputsList = inputsMap.values() - .stream() - .map(InputDefinition::new) - .collect(Collectors.toList()); - component.setInputs(inputsList); - } + private static void convertInputs(TopologyTemplate topologyTemplate, Component component) { + Map inputsMap = topologyTemplate.getInputs(); + if (inputsMap != null && !inputsMap.isEmpty()) { + List inputsList = inputsMap.values() + .stream() + .map(InputDefinition::new) + .collect(Collectors.toList()); + component.setInputs(inputsList); + } + } + + private static void convertProperties(Component component, TopologyTemplate topologyTemplate) { + List propertiesList = component.getProperties(); + if (propertiesList != null && !propertiesList.isEmpty()) { + Map propertiesMap = propertiesList.stream().map(i -> new PropertyDataDefinition(i)).collect(Collectors.toMap(i -> i.getName(), i -> i)); + topologyTemplate.setProperties(propertiesMap); + } + + } + + private static void convertProperties(TopologyTemplate topologyTemplate, Component component) { + Map proeprtiesMap = topologyTemplate.getProperties(); + if (proeprtiesMap != null && !proeprtiesMap.isEmpty()) { + Map copy = proeprtiesMap.entrySet().stream() + .collect(Collectors.toMap(entry -> entry.getKey(), entry -> new PropertyDefinition + (entry.getValue()))); + component.setProperties(new ArrayList<>(copy.values())); + } + } - } private static void convertCommonToscaData(Component component, ToscaElement toscaElement) { toscaElement.setUUID(component.getUUID()); @@ -1131,6 +1107,14 @@ public class ModelConverter { List groupInstances = topologyTemplate.getInstGroups().get(key).getMapToscaDataDefinition().entrySet().stream().map(e -> new GroupInstance(e.getValue())).collect(Collectors.toList()); currComponentInstance.setGroupInstances(groupInstances); } + if(topologyTemplate.getInstProperties() != null && topologyTemplate.getInstProperties().containsKey(key) && topologyTemplate.getInstProperties().get(key) != null ){ + List instanceProps = topologyTemplate.getInstProperties().get(key).getMapToscaDataDefinition().entrySet().stream().map(e -> new PropertyDefinition(e.getValue())).collect(Collectors.toList()); + currComponentInstance.setProperties(instanceProps); + } + if(topologyTemplate.getComponentInstInterfaces() != null && topologyTemplate.getComponentInstInterfaces().containsKey(key) && topologyTemplate.getComponentInstInterfaces().get(key) != null ){ + Map interfacesMap = topologyTemplate.getComponentInstInterfaces().get(key).getMapToscaDataDefinition().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + currComponentInstance.setInterfaces(interfacesMap); + } componentInstances.add(currComponentInstance); } component.setComponentInstances(componentInstances); @@ -1165,20 +1149,52 @@ public class ModelConverter { } } - private static void setComponentInstancesAttributesToComponent(TopologyTemplate topologyTemplate, Component component) { - if (topologyTemplate.getInstAttributes() != null) { - Map> attributes = new HashMap<>(); - for (Map.Entry entry : topologyTemplate.getInstAttributes().entrySet()) { - if (entry.getValue() != null && entry.getValue().getMapToscaDataDefinition() != null) { - String key = entry.getKey(); - List componentInstanceAttributes = entry.getValue().getMapToscaDataDefinition().entrySet().stream().map(e -> new ComponentInstanceProperty(new ComponentInstanceProperty(e.getValue()))) - .collect(Collectors.toList()); - attributes.put(key, componentInstanceAttributes); - } - } - component.setComponentInstancesAttributes(attributes); - } - } + private static void setComponentInstancesInterfacesToComponent(TopologyTemplate topologyTemplate, Component component) { + if (topologyTemplate.getInstInterfaces() != null) { + Map> interfaces = new HashMap<>(); + for (Entry entry : topologyTemplate.getInstInterfaces().entrySet()) { + if (entry.getValue() != null && entry.getValue().getMapToscaDataDefinition() != null) { + String key = entry.getKey(); + List componentInstanceInterfaces = entry.getValue() + .getMapToscaDataDefinition().entrySet().stream().map(e -> new + ComponentInstanceInterface(e.getKey(), e.getValue())) + .collect(Collectors.toList()); + interfaces.put(key, componentInstanceInterfaces); + } + } + component.setComponentInstancesInterfaces(interfaces); + } + else if (topologyTemplate.getComponentInstInterfaces() != null) { + Map> interfaces = new HashMap<>(); + for (Entry entry : topologyTemplate.getComponentInstInterfaces().entrySet()) { + if (entry.getValue() != null && entry.getValue().getMapToscaDataDefinition() != null) { + String key = entry.getKey(); + List componentInstanceInterfaces = entry.getValue() + .getMapToscaDataDefinition().entrySet().stream().map(e -> new + ComponentInstanceInterface(e.getKey(), e.getValue())) + .collect(Collectors.toList()); + interfaces.put(key, componentInstanceInterfaces); + } + } + component.setComponentInstancesInterfaces(interfaces); + } + + } + + private static void setComponentInstancesAttributesToComponent(TopologyTemplate topologyTemplate, Component component) { + if (topologyTemplate.getInstAttributes() != null) { + Map> attributes = new HashMap<>(); + for (Map.Entry entry : topologyTemplate.getInstAttributes().entrySet()) { + if (entry.getValue() != null && entry.getValue().getMapToscaDataDefinition() != null) { + String key = entry.getKey(); + List componentInstanceAttributes = entry.getValue().getMapToscaDataDefinition().entrySet().stream().map(e -> new ComponentInstanceProperty(new ComponentInstanceProperty(e.getValue()))) + .collect(Collectors.toList()); + attributes.put(key, componentInstanceAttributes); + } + } + component.setComponentInstancesAttributes(attributes); + } + } private static void setComponentInstancesRequirementsToComponent(TopologyTemplate topologyTemplate, Component component) { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/StorageOperationStatus.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/StorageOperationStatus.java index ca700b03d5..bb1096a900 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/StorageOperationStatus.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/StorageOperationStatus.java @@ -62,6 +62,7 @@ public enum StorageOperationStatus { CANNOT_UPDATE_EXISTING_ENTITY, PROPERTY_NAME_ALREADY_EXISTS, INVALID_PROPERTY, - COMPONENT_IS_ARCHIVED; + COMPONENT_IS_ARCHIVED, + DECLARED_INPUT_USED_BY_OPERATION; } -- cgit 1.2.3-korg