From ed7e1c3dfe332abc67ed943717db2ee94406f95e Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Thu, 29 Jun 2017 19:30:00 +0300 Subject: [SDC] rebase code Change-Id: I456ec65a233d277e6bae35e140f2e3da5765bae6 Signed-off-by: Tal Gitelman Signed-off-by: Michael Lando --- .../sdc/be/model/ComponentInstanceInput.java | 14 +--- .../sdc/be/model/GroupInstanceProperty.java | 1 + .../jsontitan/operations/ArtifactsOperations.java | 84 +++++++++++++++------- .../model/jsontitan/operations/BaseOperation.java | 6 ++ .../operations/NodeTemplateOperation.java | 16 +++-- .../jsontitan/operations/ToscaOperationFacade.java | 13 +--- 6 files changed, 80 insertions(+), 54 deletions(-) (limited to 'catalog-model/src') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInput.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInput.java index 9347f326d1..abcac352cc 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInput.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstanceInput.java @@ -38,8 +38,6 @@ public class ComponentInstanceInput extends InputDefinition implements IComponen */ private String valueUniqueUid; - private String inputId; - private List path = null; private List rules = null; @@ -53,7 +51,7 @@ public class ComponentInstanceInput extends InputDefinition implements IComponen public ComponentInstanceInput(PropertyDataDefinition curPropertyDef, String inputId, String value, String valueUniqueUid) { super(curPropertyDef); - this.inputId = inputId; + setInputId(inputId); setValue(value); this.valueUniqueUid = valueUniqueUid; } @@ -68,7 +66,7 @@ public class ComponentInstanceInput extends InputDefinition implements IComponen public ComponentInstanceInput(PropertyDataDefinition propertyDefinition) { super(propertyDefinition); if(propertyDefinition.getGetInputValues() != null && !propertyDefinition.getGetInputValues().isEmpty()){ - this.inputId = propertyDefinition.getGetInputValues().get(0).getInputId(); + setInputId(propertyDefinition.getGetInputValues().get(0).getInputId()); } } @@ -88,14 +86,6 @@ public class ComponentInstanceInput extends InputDefinition implements IComponen this.componentInstanceId = componentInstanceId; } - public String getInputId() { - return inputId; - } - - public void setInputId(String inputId) { - this.inputId = inputId; - } - public String getValueUniqueUid() { return valueUniqueUid; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstanceProperty.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstanceProperty.java index e1e51729e0..683a2f2428 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstanceProperty.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupInstanceProperty.java @@ -48,6 +48,7 @@ public class GroupInstanceProperty extends GroupProperty { public GroupInstanceProperty(PropertyDataDefinition propertyDataDefinition) { super(propertyDataDefinition); + parentValue = getDefaultValue(); } public String getParentValue() { 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 4d9ec8c2fe..224697246d 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 @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -98,7 +99,7 @@ public class ArtifactsOperations extends BaseOperation { ArtifactDataDefinition foundArtifact = null; if (componentType != null && componentType == ComponentTypeEnum.RESOURCE_INSTANCE) { foundArtifact = getInstanceArtifactByLabelAndId(parentId, id, containerId, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); - if ( foundArtifact == null ){ + if (foundArtifact == null) { foundArtifact = getInstanceArtifactByLabelAndId(parentId, id, containerId, EdgeLabelEnum.INSTANCE_ARTIFACTS); } } @@ -217,14 +218,14 @@ public class ArtifactsOperations extends BaseOperation { oldVesrion = "0"; String currentChecksum = artifactData.getArtifactChecksum(); - - if ( isUpdate ){ + + if (isUpdate) { ArtifactTypeEnum type = ArtifactTypeEnum.findType(artifactData.getArtifactType()); - switch ( type ){ - case HEAT_ENV: - if ( edgeLabel == EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS ){ + switch (type) { + case HEAT_ENV: + if (edgeLabel == EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS) { generateUUID(artifactData, oldVesrion); - }else{ + } else { updateVersionAndDate(artifactData, oldVesrion); } break; @@ -243,7 +244,7 @@ public class ArtifactsOperations extends BaseOperation { } break; } - }else{ + } else { if (oldChecksum == null || oldChecksum.isEmpty()) { if (currentChecksum != null) { generateUUID(artifactData, oldVesrion); @@ -287,7 +288,7 @@ public class ArtifactsOperations extends BaseOperation { } Map artifacts = artifactsEither.left().value(); - List envList = artifacts.values().stream().filter(a -> a.getGeneratedFromId()!= null && a.getGeneratedFromId().equals(artifactId)).collect(Collectors.toList()); + List envList = artifacts.values().stream().filter(a -> a.getGeneratedFromId() != null && a.getGeneratedFromId().equals(artifactId)).collect(Collectors.toList()); if (envList != null && !envList.isEmpty()) { envList.forEach(a -> { a.setGeneratedFromId(newArtifactId); @@ -366,7 +367,7 @@ public class ArtifactsOperations extends BaseOperation { Map artMap = null; Map artifactDataMap = null; - + if (edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) { Either, TitanOperationStatus> resultEither = getDataFromGraph(parentId, edgeLabelEnum); if (resultEither.isRight()) { @@ -374,7 +375,7 @@ public class ArtifactsOperations extends BaseOperation { return Either.right(resultEither.right().value()); } artifactDataMap = resultEither.left().value(); - }else{ + } else { Either, TitanOperationStatus> resultEither = getDataFromGraph(parentId, edgeLabelEnum); if (resultEither.isRight()) { log.debug("failed to fetch {} for tosca element with id {}, error {}", edgeLabelEnum, parentId, resultEither.right().value()); @@ -382,13 +383,13 @@ public class ArtifactsOperations extends BaseOperation { } Map mapArtifacts = resultEither.left().value(); MapArtifactDataDefinition artifactPerInstance = mapArtifacts.get(instanceId); - if ( artifactPerInstance != null ){ + if (artifactPerInstance != null) { artifactDataMap = artifactPerInstance.getMapToscaDataDefinition(); } } if (artifactDataMap != null && !artifactDataMap.isEmpty()) { artMap = artifactDataMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> convertArtifactDataToArtifactDefinition(null, e.getValue()))); - }else{ + } else { artMap = new HashMap<>(); } return Either.left(artMap); @@ -462,26 +463,28 @@ public class ArtifactsOperations extends BaseOperation { uniqueId = UniqueIdBuilder.buildPropertyUniqueId(instanceId, artifactToUpdate.getArtifactLabel()); } artifactToUpdate.setUniqueId(uniqueId); - + artifactToUpdate.setEsId(uniqueId); } else artifactToUpdate.setUniqueId(artifactId); - Map artifacts = null; + Map artifacts = new HashMap<>(); + Map artifactInst = null; if (edgeLabelEnum != EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS && edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) { Either, TitanOperationStatus> artifactsEither = this.getDataFromGraph(componentId, edgeLabelEnum); if (artifactsEither.isLeft() && artifactsEither.left().value() != null && !artifactsEither.left().value().isEmpty()) { artifacts = artifactsEither.left().value(); - if (isNeedToClone) { + if (isNeedToClone && artifacts != null) { artifacts.values().stream().forEach(a -> a.setDuplicated(Boolean.TRUE)); } } } else { + Either, TitanOperationStatus> artifactsEither = this.getDataFromGraph(componentId, edgeLabelEnum); if (artifactsEither.isLeft()) { - Map artifactInst = artifactsEither.left().value(); - if (isNeedToClone) { + artifactInst = artifactsEither.left().value(); + if (isNeedToClone && artifactInst != null) { artifactInst.values().forEach(ma -> ma.getMapToscaDataDefinition().values().forEach(a -> a.setDuplicated(Boolean.TRUE))); } MapArtifactDataDefinition artifatcsOnInstance = artifactInst.get(instanceId); @@ -496,6 +499,9 @@ public class ArtifactsOperations extends BaseOperation { ArtifactDataDefinition oldArtifactData = artifacts.get(artifactInfo.getArtifactLabel()); oldChecksum = oldArtifactData.getArtifactChecksum(); oldVersion = oldArtifactData.getArtifactVersion(); + //duplicated flag didn't receive from UI, take from DB + artifactToUpdate.setDuplicated(oldArtifactData.getDuplicated()); + if (isNeedToClone) artifactToUpdate.setDuplicated(Boolean.FALSE); else { @@ -503,11 +509,12 @@ public class ArtifactsOperations extends BaseOperation { String id = type != NodeTypeEnum.ResourceInstance ? componentId : instanceId; String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(id, artifactToUpdate.getArtifactLabel()); artifactToUpdate.setUniqueId(uniqueId); - artifactToUpdate.setDuplicated(Boolean.TRUE); + artifactToUpdate.setEsId(uniqueId); + artifactToUpdate.setDuplicated(Boolean.FALSE); } } } - updateUUID(artifactToUpdate, oldChecksum, oldVersion, isUpdate, edgeLabelEnum ); + updateUUID(artifactToUpdate, oldChecksum, oldVersion, isUpdate, edgeLabelEnum); if (artifactInfo.getPayloadData() == null) { if (!artifactToUpdate.getMandatory() || artifactToUpdate.getEsId() != null) { @@ -516,19 +523,44 @@ public class ArtifactsOperations extends BaseOperation { } else { if (artifactToUpdate.getEsId() == null) { artifactToUpdate.setEsId(artifactToUpdate.getUniqueId()); - } } - StorageOperationStatus status; + StorageOperationStatus status = StorageOperationStatus.OK; if (edgeLabelEnum != EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS && edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) { - status = updateToscaDataOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, artifactToUpdate, JsonPresentationFields.ARTIFACT_LABEL); + List toscaDataList = new ArrayList<>(); + toscaDataList.add(artifactToUpdate); + + if (isNeedToClone && artifacts != null) { + artifacts.values().stream().filter(a -> !a.getArtifactLabel().equals(artifactToUpdate.getArtifactLabel())).forEach(a -> toscaDataList.add(a)); + } + status = updateToscaDataOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataList, JsonPresentationFields.ARTIFACT_LABEL); } else { - List pathKeys = new ArrayList<>(); - pathKeys.add(instanceId); List toscaDataList = new ArrayList<>(); toscaDataList.add(artifactToUpdate); - status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataList, pathKeys, JsonPresentationFields.ARTIFACT_LABEL); + List pathKeys = new ArrayList<>(); + pathKeys.add(instanceId); + if (isNeedToClone) { + MapArtifactDataDefinition artifatcsOnInstance = artifactInst.get(instanceId); + if (artifatcsOnInstance != null) { + artifacts = artifatcsOnInstance.getMapToscaDataDefinition(); + artifacts.put(artifactToUpdate.getArtifactLabel(), artifactToUpdate); + } + + for ( Entry e : artifactInst.entrySet() ) { + List toscaDataListPerInst = e.getValue().getMapToscaDataDefinition().values().stream().collect(Collectors.toList()); + List pathKeysPerInst = new ArrayList<>(); + pathKeysPerInst.add(e.getKey()); + status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataListPerInst, pathKeysPerInst, JsonPresentationFields.ARTIFACT_LABEL); + 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; + } + } + } else { + status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataList, pathKeys, JsonPresentationFields.ARTIFACT_LABEL); + } } if (status == StorageOperationStatus.OK) res = Either.left(artifactToUpdate); 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 ed8846010b..407d711ed1 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 @@ -28,6 +28,7 @@ import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; @@ -1340,6 +1341,7 @@ public abstract class BaseOperation { groupInstance.setArtifacts(group.getArtifacts()); groupInstance.setArtifactsUuid(group.getArtifactsUuid()); groupInstance.setProperties(group.getProperties()); + convertPropertiesToInstanceProperties(groupInstance.getProperties()); groupInstance.setInvariantUUID(group.getInvariantUUID()); groupInstance.setGroupUUID(group.getGroupUUID()); groupInstance.setVersion(group.getVersion()); @@ -1354,5 +1356,9 @@ public abstract class BaseOperation { protected String generateCustomizationUUID() { return UUID.randomUUID().toString(); } + + protected void convertPropertiesToInstanceProperties(List properties){ + properties.forEach(p -> p.convertPropertyDataToInstancePropertyData()); + } } 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 58ee914046..0bb5476f1d 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 @@ -602,18 +602,18 @@ public class NodeTemplateOperation extends BaseOperation { public MapArtifactDataDefinition prepareInstDeploymentArtifactPerInstance(Map deploymentArtifacts, String componentInstanceId, User user, String envType) { if (deploymentArtifacts != null && envType.equals(HEAT_VF_ENV_NAME)) { - Map instDeploymentArtifacts = new HashMap<>(); + deploymentArtifacts.entrySet().forEach(e -> { ArtifactDataDefinition artifact = e.getValue(); String type = artifact.getArtifactType(); - if (!(type.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType()))) { - instDeploymentArtifacts.put(e.getKey(), artifact); + if (type.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) { + //instDeploymentArtifacts.put(e.getKey(), artifact); ArtifactDataDefinition artifactEnv = createArtifactPlaceHolderInfo(artifact, componentInstanceId, user, envType); - instDeploymentArtifacts.put(artifactEnv.getArtifactLabel(), artifactEnv); + deploymentArtifacts.put(artifactEnv.getArtifactLabel(), artifactEnv); } }); - MapArtifactDataDefinition instArtifacts = new MapArtifactDataDefinition(instDeploymentArtifacts); + MapArtifactDataDefinition instArtifacts = new MapArtifactDataDefinition(deploymentArtifacts); return instArtifacts; } return null; @@ -820,12 +820,16 @@ public class NodeTemplateOperation extends BaseOperation { ComponentInstanceDataDefinition dataDefinition = new ComponentInstanceDataDefinition(resourceInstance); Long creationDate = resourceInstance.getCreationTime(); + Long modificationTime; if (creationDate == null) { creationDate = System.currentTimeMillis(); + modificationTime = creationDate; + } else { + modificationTime = System.currentTimeMillis(); } dataDefinition.setComponentUid(ciOriginComponentUid); dataDefinition.setCreationTime(creationDate); - dataDefinition.setModificationTime(creationDate); + dataDefinition.setModificationTime(modificationTime); if (StringUtils.isNotEmpty(instanceNewName)) { dataDefinition.setName(instanceNewName); resourceInstance.setName(instanceNewName); 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 e078f8eb86..58b7d30252 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 @@ -1,14 +1,7 @@ package org.openecomp.sdc.be.model.jsontitan.operations; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; @@ -359,7 +352,7 @@ public class ToscaOperationFacade { } - public Either, StorageOperationStatus> getFollowed(String userId, Set lifecycleStates, Set lastStateStates, ComponentTypeEnum componentType) { + public Either, StorageOperationStatus> getFollowed(String userId, Set lifecycleStates, Set lastStateStates, ComponentTypeEnum componentType) { Either, StorageOperationStatus> followedResources; if (componentType == ComponentTypeEnum.RESOURCE) { followedResources = nodeTypeOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType); @@ -367,7 +360,7 @@ public class ToscaOperationFacade { followedResources = topologyTemplateOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType); } - List components = new ArrayList<>(); + Set components = new HashSet<>(); if (followedResources.isRight() && followedResources.right().value() != StorageOperationStatus.NOT_FOUND) { return Either.right(followedResources.right().value()); } -- cgit 1.2.3-korg