diff options
author | Tal Gitelman <tg851x@intl.att.com> | 2017-06-29 19:30:00 +0300 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2017-06-29 21:32:19 +0300 |
commit | ed7e1c3dfe332abc67ed943717db2ee94406f95e (patch) | |
tree | e0f2f39596656456272900f59aadc3dff6c6e828 /asdctool/src/main/java/org/openecomp | |
parent | 68ccc45de18f41cddb79de33a245bceb3b063ffb (diff) |
[SDC] rebase code
Change-Id: I456ec65a233d277e6bae35e140f2e3da5765bae6
Signed-off-by: Tal Gitelman <tg851x@intl.att.com>
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'asdctool/src/main/java/org/openecomp')
5 files changed, 258 insertions, 42 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java index 6f645dc8dd..d8b2f62705 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java @@ -147,10 +147,9 @@ public class Migration1707ArtifactUuidFix { vfLst.add(resource); writeModuleResultToFile(writer, resource, null); writer.flush(); - break; } + titanDao.commit(); } - titanDao.commit(); } catch (Exception e) { log.info("Failed to fetch vf resources ", e); @@ -510,7 +509,7 @@ public class Migration1707ArtifactUuidFix { List<GroupDefinition> groupsList = resource.getGroups(); if (groupsList != null && artifactsMap != null) { for (GroupDefinition group : groupsList) { - if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) { + if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) && group.getArtifacts() != null) { log.debug("Migration1707ArtifactUuidFix fix group: resource id {}, group name {} ", resource.getUniqueId(), group.getName()); List<String> groupArtifacts = new ArrayList<String>(group.getArtifacts()); group.getArtifacts().clear(); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java index 09e52619f0..555a54d038 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java @@ -72,7 +72,8 @@ public class ToscaTemplateRegeneration implements Migration1707Task { private boolean regenerateToscaTemplateArtifacts(List<GraphVertex> components) { boolean result = true; for(GraphVertex componentV : components){ - Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentsRes = toscaOperationFacade.getToscaElement(componentV); + String componentId = componentV.getUniqueId(); + Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentsRes = toscaOperationFacade.getToscaElement(componentId); if (getComponentsRes.isRight()) { result = false; break; @@ -135,7 +136,7 @@ public class ToscaTemplateRegeneration implements Migration1707Task { Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); List<GraphVertex> components = null; - Either<List<GraphVertex>, TitanOperationStatus> getVerticiesRes = toscaOperationFacade.getTitanDao().getByCriteria(null, propertiesToMatch,JsonParseFlagEnum.ParseMetadata); + Either<List<GraphVertex>, TitanOperationStatus> getVerticiesRes = toscaOperationFacade.getTitanDao().getByCriteria(null, propertiesToMatch,JsonParseFlagEnum.NoParse); if (getVerticiesRes.isRight() && getVerticiesRes.right().value() != TitanOperationStatus.NOT_FOUND) { LOGGER.debug("Failed to fetch all certified components. Status is {}", getVerticiesRes.right().value()); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java index 30d14e686b..51e51d4c02 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java @@ -4,18 +4,24 @@ import fj.data.Either; import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations.RequirementsCapabilitiesMigrationService; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; +import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.GroupInstance; import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.migration.MigrationMalformedDataLogger; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; +import org.openecomp.sdc.common.api.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -83,12 +89,21 @@ public abstract class ComponentMigration <T extends Component> extends JsonModel protected void setMissingTemplateInfo(List<T> components) { Map<String, ToscaElement> origCompMap = new HashMap<>(); for (T component : components) { - for (ComponentInstance instance : component.getComponentInstances()){ - nodeTemplateMissingDataResolver.resolveNodeTemplateInfo(instance, origCompMap, component); - } + List<ComponentInstance> instances = component.getComponentInstances(); + if(null != instances) { + for (ComponentInstance instance : instances) { + nodeTemplateMissingDataResolver.resolveNodeTemplateInfo(instance, origCompMap, component); + nodeTemplateMissingDataResolver.fixVFGroupInstances(component, instance); + } + } + nodeTemplateMissingDataResolver.fixVFGroups(component); } } + + + + diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java index 275d499bae..f0763a138c 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java @@ -1,29 +1,34 @@ package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.annotation.Resource; - +import fj.data.Either; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; +import org.openecomp.sdc.be.model.ArtifactDefinition; 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.GroupDefinition; +import org.openecomp.sdc.be.model.GroupInstance; 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.operations.TopologyTemplateOperation; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; +import org.openecomp.sdc.common.api.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import fj.data.Either; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; public class NodeTemplateMissingDataResolver <T extends Component> { @@ -38,8 +43,10 @@ public class NodeTemplateMissingDataResolver <T extends Component> { public void resolveNodeTemplateInfo(ComponentInstanceDataDefinition vfInst, Map<String, ToscaElement> origCompMap, T component) { lifecycleOperation.resolveToscaComponentName(vfInst, origCompMap); - if(OriginTypeEnum.VF == vfInst.getOriginType()) - collectVFInstanceInputs(component.getComponentInstancesInputs(), origCompMap, vfInst); + if(OriginTypeEnum.VF == vfInst.getOriginType()) { + Map<String, List<ComponentInstanceInput>> componentInstancesInputs = Optional.ofNullable(component.getComponentInstancesInputs()).orElse(new HashMap<>()); + collectVFInstanceInputs(componentInstancesInputs, origCompMap, vfInst); + } } private void collectVFInstanceInputs(Map<String, List<ComponentInstanceInput>> instInputs, Map<String, ToscaElement> origCompMap, ComponentInstanceDataDefinition vfInst) { @@ -51,7 +58,7 @@ public class NodeTemplateMissingDataResolver <T extends Component> { Map<String, PropertyDataDefinition> origVFInputs = ((TopologyTemplate)origComp.left().value()).getInputs(); if (origVFInputs != null && !origVFInputs.isEmpty()) { Map<String, ComponentInstanceInput> collectedVFInputs = origVFInputs.values().stream() - .collect(Collectors.toMap(p -> p.getName(), p -> new ComponentInstanceInput(p))); + .collect(Collectors.toMap(PropertyDataDefinition::getName, ComponentInstanceInput::new)); List<ComponentInstanceInput> instInputList = instInputs.get(ciUid); Map<String, ComponentInstanceInput> existingInstInputs = ToscaDataDefinition.listToMapByName(instInputList); collectedVFInputs.putAll(existingInstInputs); @@ -72,4 +79,198 @@ public class NodeTemplateMissingDataResolver <T extends Component> { } return Either.left(origCompMap.get(origCompUid)); } + + protected boolean isProblematicGroup(GroupDefinition gr, String resourceName, Map<String, ArtifactDefinition> deploymentArtifacts) { + List<String> artifacts = gr.getArtifacts(); + List<String> artifactsUuid = gr.getArtifactsUuid(); + + if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) { + LOGGER.debug("No groups in resource {} ", resourceName); + return false; + } + if (artifacts.size() < artifactsUuid.size()) { + LOGGER.debug(" artifacts.size() < artifactsUuid.size() group {} in resource {} ", gr.getName(), resourceName); + return true; + } + if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) { + LOGGER.debug(" artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() group {} in resource {} ", gr.getName(), resourceName); + return true; + } + if (artifactsUuid.contains(null)) { + LOGGER.debug(" artifactsUuid.contains(null) group {} in resource {} ", gr.getName(), resourceName); + return true; + } + + for (String artifactId : artifacts) { + String artifactlabel = findArtifactLabelFromArtifactId(artifactId); + ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactlabel); + if (artifactDefinition == null) { + LOGGER.debug(" artifactDefinition == null label {} group {} in resource {} ", artifactlabel, gr.getName(), resourceName); + return true; + } + ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactDefinition.getArtifactType()); + if (artifactType != ArtifactTypeEnum.HEAT_ENV) { + if (!artifactId.equals(artifactDefinition.getUniqueId())) { + LOGGER.debug(" !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} group {} in resource {} ", artifactlabel, artifactId, gr.getName(), resourceName); + return true; + } + if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) { + LOGGER.debug(" artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} group {} in resource {} ", artifactlabel, gr.getName(), resourceName); + return true; + } + } + } + return false; + } + + protected boolean isProblematicGroupInstance(GroupInstance gi, String instName, String servicename, Map<String, ArtifactDefinition> deploymentArtifacts) { + List<String> artifacts = gi.getArtifacts(); + List<String> artifactsUuid = gi.getArtifactsUuid(); + List<String> instArtifactsUuid = gi.getGroupInstanceArtifactsUuid(); + + if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) { + LOGGER.debug("No instance groups for instance {} in service {} ", instName, servicename); + return false; + } + if (artifacts.size() < artifactsUuid.size()) { + LOGGER.debug(" artifacts.size() < artifactsUuid.size() inst {} in service {} ", instName, servicename); + return true; + } + if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) { + LOGGER.debug(" artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() inst {} in service {} ", instName, servicename); + return true; + } + if (artifactsUuid.contains(null)) { + LOGGER.debug(" artifactsUuid.contains(null) inst {} in service {} ", instName, servicename); + return true; + } + + for (String artifactId : artifacts) { + String artifactlabel = findArtifactLabelFromArtifactId(artifactId); + ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactlabel); + if (artifactDefinition == null) { + LOGGER.debug(" artifactDefinition == null label {} inst {} in service {} ", artifactlabel, instName, servicename); + return true; + } + ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactDefinition.getArtifactType()); + if (artifactType != ArtifactTypeEnum.HEAT_ENV) { + if (!artifactId.equals(artifactDefinition.getUniqueId())) { + LOGGER.debug(" !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} inst {} in service {} ", artifactlabel, artifactId, instName, servicename); + return true; + } + if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) { + LOGGER.debug(" artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ", artifactlabel, instName, servicename); + return true; + } + } else { + if (!instArtifactsUuid.contains(artifactDefinition.getArtifactUUID())) { + LOGGER.debug(" instArtifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ", artifactlabel, instName, servicename); + return true; + } + } + } + return false; + } + + private String findArtifactLabelFromArtifactId(String artifactId) { + String artifactLabel = ""; + + int index = artifactId.lastIndexOf("."); + if (index > 0 && index + 1 < artifactId.length()) + artifactLabel = artifactId.substring(index + 1); + return artifactLabel; + } + + protected boolean fixVFGroups(Component component){ + boolean res = true; + + Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts(); + List<GroupDefinition> groups = component.getGroups(); + if (groups == null || groups.isEmpty()) { + LOGGER.debug("No groups in component {} id {} ", component.getName(), component.getUniqueId()); + return res; + } + + for (GroupDefinition group : groups) { + if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) && deploymentArtifacts != null) { + if (isProblematicGroup(group, component.getName(), deploymentArtifacts)) { + List<String> groupArtifacts = new ArrayList<String>(group.getArtifacts()); + group.getArtifacts().clear(); + group.getArtifactsUuid().clear(); + for (String artifactId : groupArtifacts) { + String artifactlabel = findArtifactLabelFromArtifactId(artifactId); + LOGGER.debug("fix group: group name {} artifactId for fix {} artifactlabel {} ", group.getName(), artifactId, artifactlabel); + if (!artifactlabel.isEmpty() && deploymentArtifacts.containsKey(artifactlabel)) { + ArtifactDefinition artifact = deploymentArtifacts.get(artifactlabel); + String correctArtifactId = artifact.getUniqueId(); + String correctArtifactUUID = artifact.getArtifactUUID(); + LOGGER.debug(" fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID); + group.getArtifacts().add(correctArtifactId); + if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) { + group.getArtifactsUuid().add(correctArtifactUUID); + } + + } + } + } + } + + } + + return res; + } + + protected boolean fixVFGroupInstances(Component component, ComponentInstance instance){ + boolean res = true; + + Map<String, ArtifactDefinition> deploymentArtifacts = instance.getDeploymentArtifacts(); + List<GroupInstance> groupInstances = instance.getGroupInstances(); + if (groupInstances == null || groupInstances.isEmpty()) { + LOGGER.debug("No instance groups for instance {} in service {} id {} ", instance.getName(), component.getName(), component.getUniqueId()); + return res; + } + for (GroupInstance group : groupInstances) { + if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) { + if (isProblematicGroupInstance(group, instance.getName(), component.getName(), deploymentArtifacts)) { + + LOGGER.debug("Migration1707ArtifactUuidFix fix group: resource id {}, group name {} ", component.getUniqueId(), group.getName()); + List<String> groupArtifacts = Optional.ofNullable(group.getArtifacts()).orElse(new ArrayList<>()); + + group.setArtifacts(new ArrayList<>()); + group.setArtifactsUuid(new ArrayList<>()); + group.setGroupInstanceArtifacts(new ArrayList<>()); + group.setGroupInstanceArtifactsUuid(new ArrayList<>()); + + for (String artifactId : groupArtifacts) { + String artifactlabel = findArtifactLabelFromArtifactId(artifactId); + LOGGER.debug("Migration1707ArtifactUuidFix fix group: group name {} artifactId for fix {} artifactlabel {} ", group.getName(), artifactId, artifactlabel); + if (!artifactlabel.isEmpty() && deploymentArtifacts.containsKey(artifactlabel)) { + ArtifactDefinition artifact = deploymentArtifacts.get(artifactlabel); + ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType()); + String correctArtifactId = artifact.getUniqueId(); + String correctArtifactUUID = artifact.getArtifactUUID(); + if (artifactType != ArtifactTypeEnum.HEAT_ENV) { + + LOGGER.debug("Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID); + group.getArtifacts().add(correctArtifactId); + if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) { + group.getArtifactsUuid().add(correctArtifactUUID); + } + } else { + LOGGER.debug("Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID); + group.getGroupInstanceArtifacts().add(correctArtifactId); + if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) { + group.getGroupInstanceArtifactsUuid().add(correctArtifactUUID); + } + } + } + } + + } + } + } + + return res; + } + } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java index cfb1ec0b27..0c06052654 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java @@ -246,30 +246,30 @@ public class MigrationMenu { break; case MIGRATION_1702_1707://this migration is currently not needed, but will be commented out for production env - log.info("Start ASDC migration from 1702 to 1707"); - Migration1707 migration1707 = (Migration1707) context.getBean(operationEnum.getBeanName()); - isSuccessful = migration1707.migrate(); - if (isSuccessful) { - log.info("SDC migration from 1702 to 1707 was finished successfully"); - System.exit(0); - } else{ - log.info("SDC migration from 1702 to 1707 has failed"); - System.exit(2); - } - //System.exit(0); +// log.info("Start ASDC migration from 1702 to 1707"); +// Migration1707 migration1707 = (Migration1707) context.getBean(operationEnum.getBeanName()); +// isSuccessful = migration1707.migrate(); +// if (isSuccessful) { +// log.info("SDC migration from 1702 to 1707 was finished successfully"); +// System.exit(0); +// } else{ +// log.info("SDC migration from 1702 to 1707 has failed"); +// System.exit(2); +// } + System.exit(0); break; case VFMODULES_PROPERTIES_ADDING://this migration is currently not needed, but will be commented out for production env - log.info("Start adding new properties to vfModules"); - VfModulesPropertiesAdding migrationVfModulesProperties = (VfModulesPropertiesAdding) context.getBean(operationEnum.getBeanName()); - isSuccessful = migrationVfModulesProperties.migrate(args[1]); - if (isSuccessful) { - log.info("Adding new properties to vfModules was finished successfully"); - System.exit(0); - } else{ - log.info("Adding new properties to vfModules has failed"); - System.exit(2); - } - //System.exit(0); +// log.info("Start adding new properties to vfModules"); +// VfModulesPropertiesAdding migrationVfModulesProperties = (VfModulesPropertiesAdding) context.getBean(operationEnum.getBeanName()); +// isSuccessful = migrationVfModulesProperties.migrate(args[1]); +// if (isSuccessful) { +// log.info("Adding new properties to vfModules was finished successfully"); +// System.exit(0); +// } else{ +// log.info("Adding new properties to vfModules has failed"); +// System.exit(2); +// } + System.exit(0); break; case MIGRATION_1707_UUID_FIX: if (args == null || args.length < 5) { |