aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'asdctool/src/main/java')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/configuration/ArtifactUUIDFixConfiguration.java327
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/configuration/ConfigurationUploader.java28
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java1202
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java38
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java12
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java18
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java145
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecuter.java9
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuter.java41
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutor.java39
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutor.java43
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java2
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactUUIDFixMenu.java45
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactValidatorTool.java46
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/UpdateIsVnfMenu.java1
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java2
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java309
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationTool.java10
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java4
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutor.java4
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java8
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/IMigrationStage.java20
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/Migration.java16
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/PostMigration.java19
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDao.java20
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/main/MigrationMenu.java13
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/MigrationResolver.java6
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolver.java29
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java4
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/OutputHandler.java9
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/XlsOutputHandler.java66
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java739
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java4
33 files changed, 3207 insertions, 71 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/configuration/ArtifactUUIDFixConfiguration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/configuration/ArtifactUUIDFixConfiguration.java
new file mode 100644
index 0000000000..f14196681e
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/configuration/ArtifactUUIDFixConfiguration.java
@@ -0,0 +1,327 @@
+package org.openecomp.sdc.asdctool.configuration;
+
+import org.openecomp.sdc.asdctool.impl.ArtifactUuidFix;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.ArtifactsResolver;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngine;
+import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
+import org.openecomp.sdc.be.components.impl.AdditionalInformationBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ArtifactResolverImpl;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.CompositionBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
+import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.VFComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.merge.heat.HeatEnvArtifactsMergeBusinessLogic;
+import org.openecomp.sdc.be.components.merge.input.InputsValuesMergingBusinessLogic;
+import org.openecomp.sdc.be.components.merge.instance.ComponentInstanceMergeDataBusinessLogic;
+import org.openecomp.sdc.be.components.merge.property.DataDefinitionsValuesMergingBusinessLogic;
+import org.openecomp.sdc.be.dao.DAOTitanStrategy;
+import org.openecomp.sdc.be.dao.TitanClientStrategy;
+import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraClient;
+import org.openecomp.sdc.be.dao.config.DAOSpringConfig;
+import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
+import org.openecomp.sdc.be.dao.impl.AuditingDao;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.cache.ComponentCache;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
+import org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation;
+import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
+import org.openecomp.sdc.be.model.operations.impl.ElementOperation;
+import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupInstanceOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.tosca.CsarUtils;
+import org.openecomp.sdc.be.tosca.ToscaExportHandler;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.config.PropertiesFactoryBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.core.io.FileSystemResource;
+
+@Configuration
+@Import(DAOSpringConfig.class)
+@ComponentScan({
+ "org.openecomp.sdc.be.model.operations.impl",
+ "org.openecomp.sdc.be.model.cache",
+ "org.openecomp.sdc.be.dao.titan",
+ "org.openecomp.sdc.be.dao.cassandra",
+ "org.openecomp.sdc.be.model.jsontitan.operations",
+ "org.openecomp.sdc.be.dao.jsongraph",
+ "org.openecomp.sdc.be.tosca",
+ "org.openecomp.sdc.be.components.merge",
+ })
+public class ArtifactUUIDFixConfiguration {
+
+ @Bean
+ public ArtifactUuidFix artifactUuidFix() {
+ return new ArtifactUuidFix();
+ }
+
+ @Bean(name = "cassandra-client")
+ public CassandraClient cassandraClient() {
+ return new CassandraClient();
+ }
+
+
+ @Bean(name = "dao-titan-strategy")
+ public TitanClientStrategy daoStrategy() {
+ return new DAOTitanStrategy();
+ }
+
+ @Bean(name = "titan-dao")
+ public TitanDao titanDao(@Qualifier("titan-client") TitanGraphClient titanGraphClient) {
+ return new TitanDao(titanGraphClient);
+ }
+
+ @Bean(name = "titan-client", initMethod = "createGraph")
+ public TitanGraphClient titanClient(@Qualifier("dao-titan-strategy") TitanClientStrategy titanClientStrategy) {
+ return new TitanGraphClient(titanClientStrategy);
+ }
+
+ @Bean(name = "resource-business-logic")
+ public ResourceBusinessLogic resourceBusinessLogic() {
+ return new ResourceBusinessLogic();
+ }
+
+// @Bean(name = "healthCheckBusinessLogic")
+// public HealthCheckBusinessLogic healthCheckBusinessLogic() {
+// return new HealthCheckBusinessLogic();
+// }
+//
+// @Bean(name = "distribution-engine-cluster-health")
+// public DistributionEngineClusterHealth distributionEngineClusterHealth() {
+// return new DistributionEngineClusterHealth();
+// }
+//
+// @Bean(name = "cassandra-health-check")
+// public CassandraHealthCheck cassandraHealthCheck() {
+// return new CassandraHealthCheck();
+// }
+
+// @Bean(name = "switchover-detector")
+// public SwitchoverDetector switchoverDetector() {
+// return new SwitchoverDetector();
+// }
+
+ @Bean(name = "service-business-logic")
+ public ServiceBusinessLogic serviceBusinessLogic() {
+ return new ServiceBusinessLogic();
+ }
+
+ @Bean(name = "capability-type-operation")
+ public CapabilityTypeOperation CapabilityTypeOperation() {
+ return new CapabilityTypeOperation();
+ }
+
+ @Bean(name = "lifecycle-business-logic")
+ public LifecycleBusinessLogic lifecycleBusinessLogic() {
+ return new LifecycleBusinessLogic();
+ }
+
+ @Bean(name = "property-operation")
+ public PropertyOperation propertyOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
+ return new PropertyOperation(titanGenericDao);
+ }
+
+ @Bean(name = "csar-operation")
+ public CsarOperation csarOperation() {
+ return new CsarOperation();
+ }
+
+ @Bean(name = "vf-component-instance-business-logic")
+ public VFComponentInstanceBusinessLogic vFComponentInstanceBusinessLogic() {
+ return new VFComponentInstanceBusinessLogic();
+ }
+
+ @Bean(name = "resource-import-manager")
+ public ResourceImportManager resourceImportManager() {
+ return new ResourceImportManager();
+ }
+
+ @Bean(name = "group-business-logic")
+ public GroupBusinessLogic groupBusinessLogic() {
+ return new GroupBusinessLogic();
+ }
+
+ @Bean(name = "inputs-business-logic")
+ public InputsBusinessLogic inputsBusinessLogic() {
+ return new InputsBusinessLogic();
+ }
+
+ @Bean(name = "composition-business-logic")
+ public CompositionBusinessLogic compositionBusinessLogic() {
+ return new CompositionBusinessLogic();
+ }
+
+ @Bean(name = "artifacts-business-logic")
+ public ArtifactsBusinessLogic artifactsBusinessLogic() {
+ return new ArtifactsBusinessLogic();
+ }
+
+ @Bean(name = "component-cache")
+ public ComponentCache componentCache() {
+ return new ComponentCache();
+ }
+
+ @Bean(name = "componentUtils")
+ public ComponentsUtils componentsUtils() {
+ return new ComponentsUtils();
+ }
+
+ @Bean(name = "user-business-logic")
+ public UserBusinessLogic userBusinessLogic() {
+ return new UserBusinessLogic();
+ }
+
+ @Bean(name = "graph-lock-operation")
+ public GraphLockOperation graphLockOperation() {
+ return new GraphLockOperation();
+ }
+
+ @Bean(name = "titan-generic-dao")
+ public TitanGenericDao titanGenericDao(@Qualifier("titan-client") TitanGraphClient titanGraphClient) {
+ return new TitanGenericDao(titanGraphClient);
+ }
+
+ @Bean(name = "element-operation")
+ public ElementOperation elementOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
+ return new ElementOperation(titanGenericDao);
+ }
+
+ @Bean(name = "group-operation")
+ public GroupOperation groupOperation() {
+ return new GroupOperation();
+ }
+
+ @Bean(name = "group-instance-operation")
+ public GroupInstanceOperation groupInstanceOperation() {
+ return new GroupInstanceOperation();
+ }
+
+ @Bean(name = "group-type-operation")
+ public GroupTypeOperation groupTypeOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao, @Qualifier("property-operation") PropertyOperation propertyOperation) {
+ return new GroupTypeOperation(titanGenericDao, propertyOperation);
+ }
+
+ @Bean(name = "tosca-operation-facade")
+ public ToscaOperationFacade toscaOperationFacade() {
+ return new ToscaOperationFacade();
+ }
+
+ @Bean(name = "distribution-engine")
+ public DistributionEngine distributionEngine() {
+ return null;
+ }
+
+ @Bean(name = "audit-cassandra-dao")
+ public AuditCassandraDao auditCassandraDao() {
+ return new AuditCassandraDao();
+ }
+
+ @Bean(name = "service-component-instance-business-logic")
+ public ServiceComponentInstanceBusinessLogic serviceComponentInstanceBusinessLogic() {
+ return new ServiceComponentInstanceBusinessLogic();
+ }
+
+ @Bean("tosca-export-handler")
+ public ToscaExportHandler toscaExportHandler() {
+ return new ToscaExportHandler();
+ }
+
+ @Bean(name = "component-instance-operation")
+ public ComponentInstanceOperation componentInstanceOperation() {
+ return new ComponentInstanceOperation();
+ }
+
+ @Bean(name = "additional-information-business-logic")
+ public AdditionalInformationBusinessLogic additionalInformationBusinessLogic() {
+ return new AdditionalInformationBusinessLogic();
+ }
+
+ @Bean(name = "auditing-manager")
+ public AuditingManager auditingManager() {
+ return new AuditingManager();
+ }
+
+ @Bean(name = "auditing-dao")
+ public AuditingDao auditingDao() {
+ return new AuditingDao();
+ }
+
+ @Bean(name = "elasticsearch-client", initMethod = "initialize")
+ public ElasticSearchClient elasticSearchClient() {
+ return new ElasticSearchClient();
+ }
+
+ @Bean(name = "csar-utils")
+ public CsarUtils csarUtils() {
+ return new CsarUtils();
+ }
+
+ @Bean(name = "service-distribution-artifacts-builder")
+ public ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder() {
+ return new ServiceDistributionArtifactsBuilder();
+ }
+
+ @Bean(name = "product-business-logic")
+ public ProductBusinessLogic productBusinessLogic() {
+ return null;
+ }
+
+ @Bean(name = "dataDefinitionsValuesMergingBusinessLogic")
+ public DataDefinitionsValuesMergingBusinessLogic dataDefinitionsValuesMergingBusinessLogic() {
+ return new DataDefinitionsValuesMergingBusinessLogic();
+ }
+
+ @Bean(name = "artifacts-resolver")
+ public ArtifactsResolver artifactsResolver() {
+ return new ArtifactResolverImpl();
+ }
+
+ @Bean(name = "InputsValuesMergingBusinessLogic")
+ public InputsValuesMergingBusinessLogic InputsValuesMergingBusinessLogic(){
+ return new InputsValuesMergingBusinessLogic();
+ }
+
+ @Bean(name = "GenericTypeBusinessLogic")
+ public GenericTypeBusinessLogic genericTypeBusinessLogic(){
+ return new GenericTypeBusinessLogic();
+ }
+
+ @Bean(name ="componentInstanceMergeDataBusinessLogic")
+ public ComponentInstanceMergeDataBusinessLogic componentInstanceMergeDataBusinessLogic(){
+ return new ComponentInstanceMergeDataBusinessLogic();
+ }
+
+ @Bean(name ="heatEnvArtifactsMergeBusinessLogic")
+ public HeatEnvArtifactsMergeBusinessLogic heatEnvArtifactsMergeBusinessLogic(){
+ return new HeatEnvArtifactsMergeBusinessLogic();
+ }
+
+ @Bean(name = "elasticsearchConfig")
+ public PropertiesFactoryBean mapper() {
+ String configHome = System.getProperty("config.home");
+ PropertiesFactoryBean bean = new PropertiesFactoryBean();
+ bean.setLocation(new FileSystemResource(configHome + "/elasticsearch.yml"));
+ return bean;
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/configuration/ConfigurationUploader.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/configuration/ConfigurationUploader.java
new file mode 100644
index 0000000000..267f20904c
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/configuration/ConfigurationUploader.java
@@ -0,0 +1,28 @@
+package org.openecomp.sdc.asdctool.configuration;
+
+import java.io.File;
+
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+
+public class ConfigurationUploader {
+
+ public static void uploadConfigurationFiles(String appConfigDir) {
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ new ConfigurationManager(configurationSource);
+ ExternalConfiguration.setAppVersion(ConfigurationManager.getConfigurationManager().getConfiguration().getAppVersion());
+ System.setProperty("config.home", appConfigDir);
+ System.setProperty("artifactgenerator.config", buildArtifactGeneratorPath(appConfigDir));
+ }
+
+ private static String buildArtifactGeneratorPath(String appConfigDir) {
+ StringBuilder artifactGeneratorPath = new StringBuilder(appConfigDir);
+ if(!appConfigDir.endsWith(File.separator)){
+ artifactGeneratorPath.append(File.separator);
+ }
+ artifactGeneratorPath.append(ConfigurationManager.getConfigurationManager().getConfiguration().getArtifactGeneratorConfig());
+ return artifactGeneratorPath.toString();
+ }
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java
new file mode 100644
index 0000000000..1328f3f51b
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java
@@ -0,0 +1,1202 @@
+package org.openecomp.sdc.asdctool.impl;
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.openecomp.sdc.be.components.distribution.engine.VfModuleArtifactPayload;
+import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+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.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.tosca.CsarUtils;
+import org.openecomp.sdc.be.tosca.ToscaError;
+import org.openecomp.sdc.be.tosca.ToscaExportHandler;
+import org.openecomp.sdc.be.tosca.ToscaRepresentation;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("artifactUuidFix")
+public class ArtifactUuidFix {
+
+ @Autowired
+ private TitanDao titanDao;
+
+ @Autowired
+ private ToscaOperationFacade toscaOperationFacade;
+ @Autowired
+ private ToscaExportHandler toscaExportUtils;
+ @Autowired
+ private ArtifactCassandraDao artifactCassandraDao;
+
+ @Autowired
+ private CsarUtils csarUtils;
+
+ private static Logger log = LoggerFactory.getLogger(ArtifactUuidFix.class.getName());
+
+ public boolean doFix(String fixComponent, String runMode) {
+ List<Resource> vfLst = new ArrayList<>();
+ List<Service> serviceList = new ArrayList<>();
+ Map<String, List<Component>> nodeToFixTosca = new HashMap<>();
+ Map<String, List<Component>> vfToFixTosca = new HashMap<>();
+ Map<String, List<Component>> serviceToFixTosca = new HashMap<>();
+
+ long time = System.currentTimeMillis();
+
+ doFixTosca(nodeToFixTosca, vfToFixTosca, serviceToFixTosca);
+
+ if (fixComponent.equals("vf_only")) {
+ if (fetchFaultVf(fixComponent, vfLst, time) == false) {
+ return false;
+ }
+ } else {
+ if (fetchServices(fixComponent, serviceList, time) == false) {
+ return false;
+ }
+ }
+ if (runMode.equals("service_vf") || runMode.equals("fix")) {
+ log.info("Mode {}. Find problem VFs", runMode);
+ if (fetchVf(serviceList, vfLst, time) == false) {
+ log.info("Mode {}. Find problem VFs finished with failure", runMode);
+ return false;
+ }
+ log.info("Mode {}. Find problem VFs finished with success", runMode);
+ }
+ if (runMode.equals("fix") || runMode.equals("fix_only_services")) {
+ log.info("Mode {}. Start fix", runMode);
+ if (fix(vfLst, serviceList, nodeToFixTosca, vfToFixTosca, serviceToFixTosca) == false) {
+ log.info("Mode {}. Fix finished with failure", runMode);
+ return false;
+ }
+ log.info("Mode {}. Fix finished with success", runMode);
+ }
+
+ return true;
+ }
+
+ private boolean fetchFaultVf(String fixComponent, List<Resource> vfLst, long time) {
+ log.info("Find fault VF ");
+ Writer writer = null;
+ try {
+ String fileName = "fault_" + time + ".csv";
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
+ writer.write("vf name, vf id, state, version\n");
+
+ Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF.name());
+
+ Map<GraphPropertyEnum, Object> hasNotProps = new HashMap<>();
+ hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
+ log.info("Try to fetch resources with properties {} and not {}", hasProps, hasNotProps);
+
+ Either<List<GraphVertex>, TitanOperationStatus> servicesByCriteria = titanDao
+ .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, hasNotProps, JsonParseFlagEnum.ParseAll);
+ if (servicesByCriteria.isRight()) {
+ log.info("Failed to fetch resources {}", servicesByCriteria.right().value());
+ return false;
+ }
+ List<GraphVertex> resources = servicesByCriteria.left().value();
+ for (GraphVertex gv : resources) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreComponentInstances(false);
+ filter.setIgnoreArtifacts(false);
+ filter.setIgnoreGroups(false);
+
+ Either<Resource, StorageOperationStatus> toscaElement = toscaOperationFacade
+ .getToscaElement(gv.getUniqueId());
+ if (toscaElement.isRight()) {
+ log.info("Failed to fetch resources {} {}", gv.getUniqueId(), toscaElement.right().value());
+ return false;
+ }
+
+ Resource resource = toscaElement.left().value();
+ String resourceName = resource.getName();
+ Map<String, ArtifactDefinition> deploymentArtifacts = resource.getDeploymentArtifacts();
+ List<GroupDefinition> groups = resource.getGroups();
+ if (groups == null || groups.isEmpty()) {
+ log.info("No groups for resource {} id {} ", resourceName, gv.getUniqueId());
+ continue;
+ }
+ boolean isProblematic = false;
+ for (GroupDefinition gr : groups) {
+ if (gr.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
+ if (isProblematicGroup(gr, resourceName, deploymentArtifacts)) {
+ isProblematic = true;
+ break;
+ }
+ }
+ }
+ if (isProblematic) {
+ vfLst.add(resource);
+ writeModuleResultToFile(writer, resource, null);
+ writer.flush();
+ }
+ titanDao.commit();
+ }
+
+ } catch (Exception e) {
+ log.info("Failed to fetch vf resources ", e);
+ return false;
+ } finally {
+ titanDao.commit();
+ try {
+ writer.flush();
+ writer.close();
+ } catch (Exception ex) {
+ /* ignore */
+ }
+ }
+ return true;
+ }
+
+ private boolean fetchVf(List<Service> serviceList, List<Resource> vfLst, long time) {
+ log.info("Find problem VF ");
+ if (serviceList.isEmpty()) {
+ log.info("No services as input");
+ return true;
+ }
+ Writer writer = null;
+ try {
+ String fileName = "problemVf_" + time + ".csv";
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
+ writer.write("vf name, vf id, state, version, example service name\n");
+ Set<String> vfIds = new HashSet<>();
+ for (Service service : serviceList) {
+ List<ComponentInstance> componentInstances = service.getComponentInstances().stream()
+ .filter(ci -> ci.getOriginType().equals(OriginTypeEnum.VF)).collect(Collectors.toList());
+ for (ComponentInstance ci : componentInstances) {
+ if (!vfIds.contains(ci.getComponentUid())) {
+ vfIds.add(ci.getComponentUid());
+ Either<Resource, StorageOperationStatus> toscaElement = toscaOperationFacade
+ .getToscaElement(ci.getComponentUid());
+ if (toscaElement.isRight()) {
+ log.info("Failed to fetch resource {} {}", ci.getComponentUid(),
+ toscaElement.right().value());
+ return false;
+ }
+ Resource resource = toscaElement.left().value();
+ if (resource.getResourceType().equals(ResourceTypeEnum.VF)) {
+ vfLst.add(resource);
+ writeModuleResultToFile(writer, resource, service);
+ writer.flush();
+ titanDao.commit();
+ }
+ }
+ }
+ }
+ log.info("output file with list of Vf : {}", fileName);
+ } catch (Exception e) {
+ log.info("Failed to fetch services ", e);
+ return false;
+ } finally {
+ titanDao.commit();
+ try {
+ writer.flush();
+ writer.close();
+ } catch (Exception ex) {
+ /* ignore */
+ }
+ }
+ return true;
+ }
+
+ private boolean fetchServices(String fixServices, List<Service> serviceList, long time) {
+ log.info("Find problem Services {}", fixServices);
+ Writer writer = null;
+
+ try {
+ String fileName = "problemService_" + time + ".csv";
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
+ writer.write("service name, service id, state, version\n");
+
+ Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ if (fixServices.equals("distributed_only")) {
+ hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ hasProps.put(GraphPropertyEnum.DISTRIBUTION_STATUS, DistributionStatusEnum.DISTRIBUTED.name());
+ }
+
+ Map<GraphPropertyEnum, Object> hasNotProps = new HashMap<>();
+ hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
+ log.info("Try to fetch services with properties {} and not {}", hasProps, hasNotProps);
+
+ Either<List<GraphVertex>, TitanOperationStatus> servicesByCriteria = titanDao
+ .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, hasNotProps, JsonParseFlagEnum.ParseAll);
+ if (servicesByCriteria.isRight()) {
+ log.info("Failed to fetch services {}", servicesByCriteria.right().value());
+ return false;
+ }
+ List<GraphVertex> services = servicesByCriteria.left().value();
+ for (GraphVertex gv : services) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreComponentInstances(false);
+ filter.setIgnoreArtifacts(false);
+ filter.setIgnoreGroups(false);
+
+ Either<Service, StorageOperationStatus> toscaElement = toscaOperationFacade
+ .getToscaElement(gv.getUniqueId());
+ if (toscaElement.isRight()) {
+ log.info("Failed to fetch service {} {}", gv.getUniqueId(), toscaElement.right().value());
+ continue;
+ }
+ Service service = toscaElement.left().value();
+ List<ComponentInstance> componentInstances = service.getComponentInstances();
+ boolean isProblematic = false;
+ if (componentInstances == null) {
+ log.info("No instances for service {} ", gv.getUniqueId());
+ continue;
+ }
+ String serviceName = (String) gv.getMetadataProperty(GraphPropertyEnum.NAME);
+
+ for (ComponentInstance ci : componentInstances) {
+ Map<String, ArtifactDefinition> deploymentArtifacts = ci.getDeploymentArtifacts();
+ List<GroupInstance> groupInstances = ci.getGroupInstances();
+ if (groupInstances == null || groupInstances.isEmpty()) {
+ log.info("No instance groups for instance {} in service {} id {} ", ci.getName(), serviceName,
+ gv.getUniqueId());
+ continue;
+ }
+
+ for (GroupInstance gi : groupInstances) {
+ if (gi.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
+ if (isProblematicGroupInstance(gi, ci.getName(), serviceName, deploymentArtifacts)) {
+ isProblematic = true;
+ break;
+ }
+ }
+ }
+ if (isProblematic) {
+ serviceList.add(service);
+ writeModuleResultToFile(writer, service, null);
+ writer.flush();
+ break;
+ }
+ }
+ titanDao.commit();
+ }
+ log.info("output file with list of services : {}", fileName);
+ } catch (Exception e) {
+ log.info("Failed to fetch services ", e);
+ return false;
+ } finally {
+ titanDao.commit();
+ try {
+ writer.flush();
+ writer.close();
+ } catch (Exception ex) {
+ /* ignore */
+ }
+ }
+ return true;
+ }
+
+ private boolean isProblematicGroup(GroupDefinition gr, String resourceName,
+ Map<String, ArtifactDefinition> deploymentArtifacts) {
+ List<String> artifacts = gr.getArtifacts();
+ List<String> artifactsUuid = gr.getArtifactsUuid();
+ Set<String> artifactsSet = new HashSet<>();
+
+ if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) {
+ log.info("No groups in resource {} ", resourceName);
+ return true;
+ }
+ artifactsSet.addAll(artifacts);
+ if (artifactsSet.size() < artifacts.size()) {
+ log.info(" artifactsSet.size() < artifacts.size() group {} in resource {} ", gr.getName(), resourceName);
+ return true;
+ }
+
+ if (artifacts.size() < artifactsUuid.size()) {
+ log.info(" artifacts.size() < artifactsUuid.size() group {} in resource {} ", gr.getName(), resourceName);
+ return true;
+ }
+ if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) {
+ log.info(
+ " artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() group {} in resource {} ",
+ gr.getName(), resourceName);
+ return true;
+ }
+ if (artifactsUuid.contains(null)) {
+ log.info(" 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) {
+ log.info(" 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())) {
+ log.info(
+ " !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} group {} in resource {} ",
+ artifactlabel, artifactId, gr.getName(), resourceName);
+ return true;
+ }
+ if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
+ log.info(
+ " artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} group {} in resource {} ",
+ artifactlabel, gr.getName(), resourceName);
+ return true;
+ }
+ }
+ }
+ for (String artifactUUID : artifactsUuid) {
+ String label = findArtifactLabelFromArtifactId(artifactUUID);
+ if (label != null && !label.isEmpty() && !label.equals("")) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private 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();
+ List<String> instArtifactsId = gi.getGroupInstanceArtifacts();
+ Set<String> instArtifatIdSet = new HashSet<>();
+ Set<String> artifactsSet = new HashSet<>();
+
+ if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) {
+ log.info("No instance groups for instance {} in service {} ", instName, servicename);
+ return true;
+ }
+ artifactsSet.addAll(artifacts);
+ if (artifactsSet.size() < artifacts.size()) {
+ log.info(" artifactsSet.size() < artifacts.size() group {} in resource {} ", instName, servicename);
+ return true;
+ }
+
+ if (instArtifactsId != null && !instArtifactsId.isEmpty()) {
+ instArtifatIdSet.addAll(instArtifactsId);
+ }
+
+ if (artifacts.size() < artifactsUuid.size()) {
+ log.info(" artifacts.size() < artifactsUuid.size() inst {} in service {} ", instName, servicename);
+ return true;
+ }
+ if (!artifacts.isEmpty() && (artifactsUuid == null || artifactsUuid.isEmpty())) {
+ log.info(
+ " artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() inst {} in service {} ",
+ instName, servicename);
+ return true;
+ }
+ if (artifactsUuid.contains(null)) {
+ log.info(" artifactsUuid.contains(null) inst {} in service {} ", instName, servicename);
+ return true;
+ }
+ if (instArtifactsId != null && instArtifatIdSet.size() < instArtifactsId.size()) {
+ log.info(" instArtifatIdSet.size() < instArtifactsId.size() inst {} in service {} ", instName, servicename);
+ return true;
+ }
+
+ if ((instArtifactsId != null && instArtifactsUuid != null)
+ && instArtifactsId.size() != instArtifactsUuid.size()) {
+ log.info(" instArtifactsId.size() != instArtifactsUuid.size() inst {} in service {} ", instName,
+ servicename);
+ return true;
+ }
+
+ for (String artifactId : artifacts) {
+ String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
+ ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactlabel);
+ if (artifactDefinition == null) {
+ log.info(" 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())) {
+ log.info(
+ " !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} inst {} in service {} ",
+ artifactlabel, artifactId, instName, servicename);
+ return true;
+ }
+ if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
+ log.info(
+ " artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ",
+ artifactlabel, instName, servicename);
+ return true;
+ }
+ } else {
+ if (instArtifactsUuid == null || instArtifactsUuid.isEmpty()) {
+ log.info(" instArtifactsUuid empty. label {} inst {} in service {} ", artifactlabel, instName,
+ servicename);
+ return true;
+ }
+ if (!instArtifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
+ log.info(
+ " instArtifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ",
+ artifactlabel, instName, servicename);
+ return true;
+ }
+ }
+ }
+ for (String artifactUUID : artifactsUuid) {
+ String label = findArtifactLabelFromArtifactId(artifactUUID);
+ if (label != null && !label.isEmpty() && !label.equals("")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean fix(List<Resource> vfLst, List<Service> serviceList, Map<String, List<Component>> nodesToFixTosca,
+ Map<String, List<Component>> vfToFixTosca, Map<String, List<Component>> servicesToFixTosca) {
+ boolean res = true;
+ log.info(" Fix started ***** ");
+ if (vfLst != null && !vfLst.isEmpty()) {
+ res = fixVf(vfLst);
+
+ }
+
+ if (res && serviceList != null && !serviceList.isEmpty()) {
+ res = fixServices(serviceList);
+
+ }
+
+ Set<String> fixedIds = new HashSet<>();
+ if (res && nodesToFixTosca != null && !nodesToFixTosca.isEmpty()) {
+
+ generateAndSaveToscaArtifacts(nodesToFixTosca, fixedIds, null);
+
+ for (Map.Entry<String, List<Component>> entry : nodesToFixTosca.entrySet()) {
+ List<Component> components = entry.getValue();
+ for (Component c : components) {
+
+ ToscaElement topologyTemplate = ModelConverter.convertToToscaElement(c);
+ Map<String, ArtifactDataDefinition> arifacts = topologyTemplate.getToscaArtifacts();
+ res = fixDataOnGraph(c.getUniqueId(), VertexTypeEnum.TOSCA_ARTIFACTS, EdgeLabelEnum.TOSCA_ARTIFACTS,
+ arifacts);
+ titanDao.commit();
+ }
+ }
+
+ }
+ if (res && vfToFixTosca != null && !vfToFixTosca.isEmpty()) {
+
+ generateAndSaveToscaArtifacts(vfToFixTosca, fixedIds, vfLst);
+
+ for (Map.Entry<String, List<Component>> entry : vfToFixTosca.entrySet()) {
+ List<Component> components = entry.getValue();
+ for (Component c : components) {
+ TopologyTemplate topologyTemplate = ModelConverter.convertToToscaElement(c);
+ Map<String, ArtifactDataDefinition> arifacts = topologyTemplate.getToscaArtifacts();
+ res = fixDataOnGraph(c.getUniqueId(), VertexTypeEnum.TOSCA_ARTIFACTS, EdgeLabelEnum.TOSCA_ARTIFACTS,
+ arifacts);
+ titanDao.commit();
+ }
+ }
+
+ }
+
+ if (res && servicesToFixTosca != null && !servicesToFixTosca.isEmpty()) {
+ generateAndSaveToscaArtifacts(servicesToFixTosca, fixedIds, serviceList);
+
+ for (Map.Entry<String, List<Component>> entry : servicesToFixTosca.entrySet()) {
+ List<Component> components = entry.getValue();
+ for (Component c : components) {
+ TopologyTemplate topologyTemplate = ModelConverter.convertToToscaElement(c);
+ Map<String, ArtifactDataDefinition> arifacts = topologyTemplate.getToscaArtifacts();
+ res = fixDataOnGraph(c.getUniqueId(), VertexTypeEnum.TOSCA_ARTIFACTS, EdgeLabelEnum.TOSCA_ARTIFACTS,
+ arifacts);
+ titanDao.commit();
+ }
+ }
+
+ }
+
+ if (res) {
+
+ for (Component component : vfLst) {
+ generateToscaPerComponent(fixedIds, component);
+
+ TopologyTemplate topologyTemplate = ModelConverter.convertToToscaElement(component);
+ Map<String, GroupDataDefinition> groups = topologyTemplate.getGroups();
+ res = fixDataOnGraph(component.getUniqueId(), VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
+ if (res) {
+ Map<String, ArtifactDataDefinition> arifacts = topologyTemplate.getDeploymentArtifacts();
+ res = fixDataOnGraph(component.getUniqueId(), VertexTypeEnum.DEPLOYMENT_ARTIFACTS,
+ EdgeLabelEnum.DEPLOYMENT_ARTIFACTS, arifacts);
+ }
+ if (res) {
+ Map<String, ArtifactDataDefinition> arifacts = topologyTemplate.getToscaArtifacts();
+ res = fixDataOnGraph(component.getUniqueId(), VertexTypeEnum.TOSCA_ARTIFACTS,
+ EdgeLabelEnum.TOSCA_ARTIFACTS, arifacts);
+ }
+ titanDao.commit();
+ }
+ }
+
+ if (res) {
+
+ for (Component component : serviceList) {
+ generateToscaPerComponent(fixedIds, component);
+
+ TopologyTemplate topologyTemplate = ModelConverter.convertToToscaElement(component);
+ Map<String, MapGroupsDataDefinition> groups = topologyTemplate.getInstGroups();
+ res = fixDataOnGraph(component.getUniqueId(), VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS,
+ groups);
+
+ if (res) {
+ Map<String, MapArtifactDataDefinition> artifacts = topologyTemplate.getInstDeploymentArtifacts();
+ res = fixDataOnGraph(component.getUniqueId(), VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS,
+ EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, artifacts);
+ }
+ if (res) {
+ Map<String, ArtifactDataDefinition> arifacts = topologyTemplate.getToscaArtifacts();
+ res = fixDataOnGraph(component.getUniqueId(), VertexTypeEnum.TOSCA_ARTIFACTS,
+ EdgeLabelEnum.TOSCA_ARTIFACTS, arifacts);
+ }
+ titanDao.commit();
+ }
+
+ }
+ log.info(" Fix finished with res {} ***** ", res);
+ return res;
+ }
+
+ private boolean generateAndSaveToscaArtifacts(Map<String, List<Component>> nodesToFixTosca, Set<String> fixedIds,
+ List<? extends Component> componentsWithFailedGroups) {
+ boolean res = true;
+ log.debug("Migration1707ArtifactUuidFix generateAndSaveToscaArtifacts started ");
+ for (Map.Entry<String, List<Component>> entry : nodesToFixTosca.entrySet()) {
+
+ List<Component> component = entry.getValue();
+ for (Component c : component) {
+ log.debug("Migration1707ArtifactUuidFix fix tosca on component : id {}, name {} ", c.getUniqueId(),
+ c.getName());
+ if (componentsWithFailedGroups != null) {
+ Optional<Component> op = (Optional<Component>) componentsWithFailedGroups.stream()
+ .filter(cg -> cg.getUniqueId().equals(c.getUniqueId())).findAny();
+ if (!op.isPresent())
+ res = generateToscaPerComponent(fixedIds, c);
+ } else
+ res = generateToscaPerComponent(fixedIds, c);
+ }
+ }
+ log.debug("Migration1707ArtifactUuidFix generateAndSaveToscaArtifacts finished with res {} ", res);
+ return res;
+ }
+
+ private boolean generateToscaPerComponent(Set<String> fixedIds, Component c) {
+ boolean res = true;
+ log.debug("Migration1707ArtifactUuidFix generateToscaPerComponent started component name {} id {}",
+ c.getName(), c.getUniqueId());
+ try {
+ Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade
+ .getToscaFullElement(c.getUniqueId());
+ if (toscaElement.isRight()) {
+ log.info("Failed to fetch resources {} {}", c.getUniqueId(), toscaElement.right().value());
+ return false;
+ }
+ Component toscaElementFull = toscaElement.left().value();
+ toscaElementFull.setGroups(c.getGroups());
+ List<ComponentInstance> ciListFull = toscaElementFull.getComponentInstances();
+ List<ComponentInstance> ciList = c.getComponentInstances();
+ if (ciListFull != null && !ciListFull.isEmpty()) {
+ ciListFull.forEach(ciFull -> {
+ ComponentInstance compInst = ciList.stream()
+ .filter(ci -> ci.getUniqueId().equals(ciFull.getUniqueId())).findAny().get();
+ ciFull.setGroupInstances(compInst.getGroupInstances());
+ });
+ }
+
+ Map<String, ArtifactDefinition> toscaArtifacts = c.getToscaArtifacts();
+ log.debug("Migration1707ArtifactUuidFix generateToscaPerComponent tocsa artifacts size {}",
+ toscaArtifacts.size());
+
+ Either<ArtifactDefinition, ToscaError> either = Either.right(ToscaError.GENERAL_ERROR);
+ ArtifactDefinition toscaArtifact = null;
+ Optional<ArtifactDefinition> op = toscaArtifacts.values().stream()
+ .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_TEMPLATE.getType())).findAny();
+
+ if (op.isPresent()) {
+ toscaArtifact = op.get();
+ }
+
+ if (toscaArtifact != null) {
+ log.debug("Migration1707ArtifactUuidFix generateToscaPerComponent artifact name {} id {} esId {}",
+ toscaArtifact.getArtifactName(), toscaArtifact.getUniqueId(), toscaArtifact.getEsId());
+ either = generateToscaArtifact(toscaElementFull, toscaArtifact);
+ if (either.isRight()) {
+ log.error("Couldn't generate and save tosca template component unique id {}, name {} error: {}",
+ toscaElementFull.getUniqueId(), toscaElementFull.getName(), either.right().value());
+ res = false;
+
+ }
+ }
+ if (res) {
+
+ ArtifactDefinition csarArtifact = null;
+ op = toscaArtifacts.values().stream()
+ .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny();
+
+ if (op.isPresent()) {
+ csarArtifact = op.get();
+ }
+
+ if (csarArtifact != null) {
+ log.debug("Migration1707ArtifactUuidFix generateToscaPerComponent artifact name {} id {} esId {}",
+ csarArtifact.getArtifactName(), csarArtifact.getUniqueId(), csarArtifact.getEsId());
+ either = generateToscaArtifact(toscaElementFull, csarArtifact);
+ if (either.isRight()) {
+ log.error("Couldn't generate and save tosca csar for component uuid {}, id {}, name {}. error: {}",
+ toscaElementFull.getUUID(), toscaElementFull.getUniqueId(), toscaElementFull.getName(), either.right().value());
+ res = false;
+
+ }
+ }
+ }
+ c.setToscaArtifacts(toscaArtifacts);
+
+ if (res) {
+ fixedIds.add(toscaElementFull.getUniqueId());
+ }
+ } finally {
+ titanDao.commit();
+ }
+ log.debug("Migration1707ArtifactUuidFix generateToscaPerComponent finished component name {} id {} res {}",
+ c.getName(), c.getUniqueId(), res);
+ return res;
+ }
+
+ private <T extends ToscaDataDefinition> boolean fixDataOnGraph(String componentId, VertexTypeEnum vertexTypeEnum,
+ EdgeLabelEnum edgeLabelEnum, Map<String, T> groups) {
+ log.debug("amount groups to update: VertexTypeEnum {} EdgeLabelEnum {} data size {}", vertexTypeEnum.getName(),
+ edgeLabelEnum, groups.size());
+ boolean res = true;
+ Either<GraphVertex, TitanOperationStatus> getResponse = titanDao.getVertexById(componentId,
+ JsonParseFlagEnum.NoParse);
+ if (getResponse.isRight()) {
+ log.debug("Couldn't fetch component unique id {}, error: {}", componentId, getResponse.right().value());
+ res = false;
+
+ }
+ if (res) {
+ GraphVertex componentVertex = getResponse.left().value();
+
+ GraphVertex toscaDataVertex = null;
+ Either<GraphVertex, TitanOperationStatus> groupVertexEither = titanDao.getChildVertex(componentVertex,
+ edgeLabelEnum, JsonParseFlagEnum.ParseJson);
+ if (groupVertexEither.isRight() && groupVertexEither.right().value() == TitanOperationStatus.NOT_FOUND) {
+ log.debug("no child {} vertex for component unique id {}, error: {}", edgeLabelEnum, componentId,
+ groupVertexEither.right().value());
+ return true;
+ }
+ if (groupVertexEither.isRight()) {
+ res = false;
+ log.debug("failed to get child {} vertex for component unique id {}, error: {}", edgeLabelEnum,
+ componentId, groupVertexEither.right().value());
+ }
+ if (res) {
+ toscaDataVertex = groupVertexEither.left().value();
+ toscaDataVertex.setJson(groups);
+ Either<GraphVertex, TitanOperationStatus> updatevertexEither = titanDao.updateVertex(toscaDataVertex);
+ if (updatevertexEither.isRight()) {
+ log.debug("failed to update vertex for component unique id {}, error: {}", componentId,
+ updatevertexEither.right().value());
+ titanDao.rollback();
+ return false;
+ }
+ }
+ }
+ log.debug("Fix data on graph finished: VertexTypeEnum {} EdgeLabelEnum {} res {}", vertexTypeEnum.getName(),
+ res);
+ return res;
+ }
+
+ private boolean fixServices(List<Service> serviceList) {
+ for (Service service : serviceList) {
+ log.debug("Migration1707ArtifactUuidFix fix service: id {}, name {} ", service.getUniqueId(),
+ service.getName());
+ List<ComponentInstance> instances = service.getComponentInstances();
+ for (ComponentInstance instance : instances) {
+ fixComponentInstances(service, instance);
+ }
+
+ }
+ return true;
+
+ }
+
+ private void fixComponentInstances(Service service, ComponentInstance instance) {
+ Map<String, ArtifactDefinition> artifactsMap = instance.getDeploymentArtifacts();
+ List<GroupInstance> groupsList = instance.getGroupInstances();
+ if (groupsList != null && artifactsMap != null) {
+ List<GroupInstance> groupsToDelete = new ArrayList<>();
+ for (GroupInstance group : groupsList) {
+ fixGroupInstances(service, artifactsMap, groupsToDelete, group);
+
+ }
+
+ if (!groupsToDelete.isEmpty()) {
+ log.debug("Migration1707ArtifactUuidFix delete group: resource id {}, group instance to delete {} ",
+ service.getUniqueId(), groupsToDelete);
+ groupsList.removeAll(groupsToDelete);
+
+ }
+
+ Optional<ArtifactDefinition> optionalVfModuleArtifact = artifactsMap.values().stream()
+ .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA.name())).findAny();
+ if (optionalVfModuleArtifact.isPresent()) {
+ ArtifactDefinition vfModuleAertifact = optionalVfModuleArtifact.get();
+ fillVfModuleInstHeatEnvPayload(groupsList, vfModuleAertifact);
+ }
+ }
+ }
+
+ private void fixGroupInstances(Service service, Map<String, ArtifactDefinition> artifactsMap,
+ List<GroupInstance> groupsToDelete, GroupInstance group) {
+ if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
+ log.debug("Migration1707ArtifactUuidFix fix group: resource id {}, group name {} ", service.getUniqueId(),
+ group.getName());
+ List<String> groupArtifacts = new ArrayList<String>(group.getArtifacts());
+
+ group.getArtifacts().clear();
+ group.getArtifactsUuid().clear();
+ group.getGroupInstanceArtifacts().clear();
+ group.getGroupInstanceArtifactsUuid().clear();
+
+ for (String artifactId : groupArtifacts) {
+ fixArtifactUndergroupInstances(artifactsMap, group, groupArtifacts, artifactId);
+ }
+ if (group.getArtifacts() == null || group.getArtifacts().isEmpty()) {
+ log.debug(
+ "Migration1707ArtifactUuidFix fix groupInstance add to delete list: resource id {} name {} , group name {} ",
+ service.getUniqueId(), service.getName(), group.getName());
+ groupsToDelete.add(group);
+ }
+ }
+ }
+
+ private void fixArtifactUndergroupInstances(Map<String, ArtifactDefinition> artifactsMap, GroupInstance group,
+ List<String> groupArtifacts, String artifactId) {
+ String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
+ log.debug("Migration1707ArtifactUuidFix fix group: group name {} artifactId for fix {} artifactlabel {} ",
+ group.getName(), artifactId, artifactlabel);
+ if (!artifactlabel.isEmpty() && artifactsMap.containsKey(artifactlabel)) {
+ ArtifactDefinition artifact = artifactsMap.get(artifactlabel);
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
+ String correctArtifactId = artifact.getUniqueId();
+ String correctArtifactUUID = artifact.getArtifactUUID();
+ if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
+ boolean isAddToGroup = true;
+ if (groupArtifacts.size() == 1) {
+
+ if (artifactType == ArtifactTypeEnum.HEAT_ARTIFACT) {
+ isAddToGroup = false;
+ artifact.setArtifactType(ArtifactTypeEnum.OTHER.getType());
+ }
+ }
+ if (isAddToGroup) {
+ log.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 {
+ log.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);
+ }
+ }
+ }
+ }
+
+ private boolean fixVf(List<Resource> vfLst) {
+ for (Resource resource : vfLst) {
+ log.debug("Migration1707ArtifactUuidFix fix resource: id {}, name {} ", resource.getUniqueId(),
+ resource.getName());
+ Map<String, ArtifactDefinition> artifactsMap = resource.getDeploymentArtifacts();
+ List<GroupDefinition> groupsList = resource.getGroups();
+ List<GroupDefinition> groupsToDelete = new ArrayList<>();
+ if (groupsList != null && artifactsMap != null) {
+ for (GroupDefinition group : groupsList) {
+ if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) && group.getArtifacts() != null) {
+ fixVfGroup(resource, artifactsMap, group);
+ }
+ if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)
+ && (group.getArtifacts() == null || group.getArtifacts().isEmpty())) {
+ log.debug(
+ "Migration1707ArtifactUuidFix add group to delete list fix resource: id {}, name {} ",
+ resource.getUniqueId(), resource.getName(), group.getName());
+ groupsToDelete.add(group);
+ }
+ }
+
+ if (!groupsToDelete.isEmpty()) {
+ groupsList.removeAll(groupsToDelete);
+
+ }
+ }
+
+ }
+
+ return true;
+ }
+
+ private void fixVfGroup(Resource resource, Map<String, ArtifactDefinition> artifactsMap, GroupDefinition group) {
+ log.debug("Migration1707ArtifactUuidFix fix group: resource id {}, group name {} ", resource.getUniqueId(),
+ group.getName());
+ List<String> groupArtifacts = new ArrayList<>(group.getArtifacts());
+
+ for (String artifactId : groupArtifacts) {
+ fixArtifactUnderGroup(artifactsMap, group, groupArtifacts, artifactId);
+ }
+ }
+
+ private void fixArtifactUnderGroup(Map<String, ArtifactDefinition> artifactsMap, GroupDefinition group,
+ List<String> groupArtifacts, String artifactId) {
+ group.getArtifacts().clear();
+ group.getArtifactsUuid().clear();
+ String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
+ log.debug("Migration1707ArtifactUuidFix fix group: group name {} artifactId for fix {} artifactlabel {} ",
+ group.getName(), artifactId, artifactlabel);
+ if (!artifactlabel.isEmpty() && artifactsMap.containsKey(artifactlabel)) {
+ ArtifactDefinition artifact = artifactsMap.get(artifactlabel);
+ String correctArtifactId = artifact.getUniqueId();
+ String correctArtifactUUID = artifact.getArtifactUUID();
+ boolean isAddToGroup = true;
+ if (groupArtifacts.size() == 1) {
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
+ if (artifactType == ArtifactTypeEnum.HEAT_ARTIFACT) {
+ isAddToGroup = false;
+ artifact.setArtifactType(ArtifactTypeEnum.OTHER.getType());
+ }
+ }
+ if (isAddToGroup) {
+ log.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);
+ }
+ }
+
+ }
+ }
+
+ 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;
+ }
+
+ private void writeModuleResultToFile(Writer writer, org.openecomp.sdc.be.model.Component component,
+ Service service) {
+ try {
+ // "service name, service id, state, version
+ StringBuilder sb = new StringBuilder(component.getName());
+ sb.append(",").append(component.getUniqueId()).append(",").append(component.getLifecycleState()).append(",")
+ .append(component.getVersion());
+ if (service != null) {
+ sb.append(",").append(service.getName());
+ }
+ sb.append("\n");
+ writer.write(sb.toString());
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ }
+ }
+
+ private void writeModuleResultToFile(Writer writer, List<Component> components) {
+ try {
+ // "service name, service id, state, version
+ for (Component component : components) {
+ StringBuilder sb = new StringBuilder(component.getName());
+ sb.append(",").append(component.getUniqueId()).append(",").append(component.getInvariantUUID())
+ .append(",").append(component.getLifecycleState()).append(",").append(component.getVersion());
+
+ sb.append("\n");
+ writer.write(sb.toString());
+ }
+ } catch (IOException e) {
+
+ log.error(e.getMessage());
+ }
+ }
+
+ public boolean doFixTosca(Map<String, List<Component>> nodeToFix, Map<String, List<Component>> vfToFix,
+ Map<String, List<Component>> serviceToFix) {
+
+ Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+
+ Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.NODE_TYPE, hasProps);
+ boolean result = validateTosca(vertices, nodeToFix, "RESOURCE_TOSCA_ARTIFACTS");//
+
+ hasProps.clear();
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
+ hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+
+ vertices = getVerticesToValidate(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps);
+ result = validateTosca(vertices, vfToFix, "VF_TOSCA_ARTIFACTS");
+
+ hasProps.clear();
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+
+ vertices = getVerticesToValidate(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps);
+ result = validateTosca(vertices, serviceToFix, "SERVICE_TOSCA_ARTIFACTS");
+
+ return result;
+ }
+
+ public Map<String, List<Component>> getVerticesToValidate(VertexTypeEnum type,
+ Map<GraphPropertyEnum, Object> hasProps) {
+
+ Map<String, List<Component>> result = new HashMap<>();
+ try {
+
+ Either<List<GraphVertex>, TitanOperationStatus> resultsEither = titanDao.getByCriteria(type, hasProps);
+ if (resultsEither.isRight()) {
+ System.out.println("getVerticesToValidate failed " + resultsEither.right().value());
+ return result;
+ }
+ System.out.println("getVerticesToValidate: " + resultsEither.left().value().size() + " vertices to scan");
+ List<GraphVertex> componentsList = resultsEither.left().value();
+ componentsList.forEach(vertex -> {
+ String ivariantUuid = (String) vertex.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID);
+ if (!result.containsKey(ivariantUuid)) {
+ List<Component> compList = new ArrayList<Component>();
+ result.put(ivariantUuid, compList);
+ }
+ List<Component> compList = result.get(ivariantUuid);
+
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreArtifacts(false);
+
+ Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade
+ .getToscaElement(vertex.getUniqueId(), filter);
+ if (toscaElement.isRight()) {
+ System.out.println("getVerticesToValidate: failed to find element" + vertex.getUniqueId()
+ + " staus is" + toscaElement.right().value());
+ } else {
+ compList.add(toscaElement.left().value());
+ }
+ titanDao.commit();
+
+ });
+
+ } catch (Exception e) {
+ log.info("Failed to fetch vf resources ", e);
+
+ } finally {
+ titanDao.commit();
+
+ }
+ return result;
+ }
+
+ public boolean validateTosca(Map<String, List<Component>> vertices, Map<String, List<Component>> compToFix,
+ String name) {
+ boolean result = true;
+ long time = System.currentTimeMillis();
+ String fileName = name + "_" + time + ".csv";
+ Writer writer = null;
+ try {
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
+ writer.write("name, UUID, invariantUUID, state, version\n");
+ for (Map.Entry<String, List<Component>> entry : vertices.entrySet()) {
+ List<Component> compList = entry.getValue();
+ Set<String> artifactEsId = new HashSet<>();
+ for (Component component : compList) {
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ Optional<ArtifactDefinition> op = toscaArtifacts.values().stream()
+ .filter(a -> artifactEsId.contains(a.getEsId()) && a.getEsId() != null).findAny();
+ if (op.isPresent()) {
+ result = false;
+ writeModuleResultToFile(writer, compList);
+ writer.flush();
+ break;
+ } else {
+ artifactEsId.addAll(toscaArtifacts.values().stream().map(ArtifactDefinition::getEsId)
+ .collect(Collectors.toList()));
+ }
+ }
+ if (!result) {
+ List<Component> compListfull = new ArrayList<>();
+ for (Component c : compList) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreComponentInstances(false);
+ filter.setIgnoreArtifacts(false);
+ filter.setIgnoreGroups(false);
+
+ Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade
+ .getToscaElement(c.getUniqueId(), filter);
+ if (toscaElement.isRight()) {
+ System.out.println("getVerticesToValidate: failed to find element" + c.getUniqueId()
+ + " staus is" + toscaElement.right().value());
+ } else {
+ compListfull.add(toscaElement.left().value());
+ }
+ this.titanDao.commit();
+ }
+
+ compToFix.put(entry.getKey(), compListfull);
+ result = true;
+ }
+
+ }
+
+ } catch (Exception e) {
+ log.info("Failed to fetch vf resources ", e);
+ return false;
+ } finally {
+ titanDao.commit();
+ try {
+ writer.flush();
+ writer.close();
+ } catch (Exception ex) {
+ /* ignore */}
+ }
+ return result;
+ }
+
+ private Either<ArtifactDefinition, ToscaError> generateToscaArtifact(Component parent,
+ ArtifactDefinition artifactInfo) {
+ log.debug("tosca artifact generation");
+ try {
+ if (artifactInfo.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())) {
+ Either<byte[], ResponseFormat> generated = csarUtils.createCsar(parent, true, true);
+
+ if (generated.isRight()) {
+ log.debug("Failed to export tosca csar for component {} error {}", parent.getUniqueId(),
+ generated.right().value());
+
+ return Either.right(ToscaError.GENERAL_ERROR);
+ }
+ byte[] value = generated.left().value();
+ artifactInfo.setPayload(value);
+
+ } else {
+ Either<ToscaRepresentation, ToscaError> exportComponent = toscaExportUtils.exportComponent(parent);
+ if (exportComponent.isRight()) {
+ log.debug("Failed export tosca yaml for component {} error {}", parent.getUniqueId(),
+ exportComponent.right().value());
+
+ return Either.right(exportComponent.right().value());
+ }
+ log.debug("Tosca yaml exported for component {} ", parent.getUniqueId());
+ String payload = exportComponent.left().value().getMainYaml();
+
+ artifactInfo.setPayloadData(payload);
+ }
+
+ byte[] decodedPayload = artifactInfo.getPayloadData();
+ artifactInfo.setEsId(artifactInfo.getUniqueId());
+ artifactInfo.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(decodedPayload));
+ ESArtifactData artifactData = new ESArtifactData(artifactInfo.getEsId(), decodedPayload);
+ artifactCassandraDao.saveArtifact(artifactData);
+ log.debug("Tosca yaml artifact esId ", artifactInfo.getEsId());
+ } catch (Exception ex) {
+ log.error("Failed to generate tosca atifact id {} component id {} component name {} error {}",artifactInfo.getUniqueId(),
+ parent.getUniqueId(), parent.getName(), ex.getMessage() );
+
+ return Either.right(ToscaError.GENERAL_ERROR);
+ }
+
+ return Either.left(artifactInfo);
+ }
+
+ private void fillVfModuleInstHeatEnvPayload(List<GroupInstance> groupsForCurrVF,
+ ArtifactDefinition vfModuleArtifact) {
+
+ List<VfModuleArtifactPayload> vfModulePayloadForCurrVF = new ArrayList<VfModuleArtifactPayload>();
+ if (groupsForCurrVF != null) {
+ for (GroupInstance groupInstance : groupsForCurrVF) {
+ VfModuleArtifactPayload modulePayload = new VfModuleArtifactPayload(groupInstance);
+ vfModulePayloadForCurrVF.add(modulePayload);
+ }
+ Collections.sort(vfModulePayloadForCurrVF,
+ (art1, art2) -> VfModuleArtifactPayload.compareByGroupName(art1, art2));
+
+ final Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ String vfModulePayloadString = gson.toJson(vfModulePayloadForCurrVF);
+ if (vfModulePayloadString != null) {
+ String newCheckSum = GeneralUtility
+ .calculateMD5Base64EncodedByByteArray(vfModulePayloadString.getBytes());
+ vfModuleArtifact.setArtifactChecksum(newCheckSum);
+
+ ESArtifactData artifactData = new ESArtifactData(vfModuleArtifact.getEsId(),
+ vfModulePayloadString.getBytes());
+ artifactCassandraDao.saveArtifact(artifactData);
+
+ }
+
+ }
+
+ }
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java
new file mode 100644
index 0000000000..556d7e0eee
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java
@@ -0,0 +1,38 @@
+package org.openecomp.sdc.asdctool.impl.validator;
+
+import java.util.List;
+
+import org.openecomp.sdc.asdctool.impl.validator.executers.IArtifactValidatorExecuter;
+import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class ArtifactToolBL {
+
+ private static Logger log = LoggerFactory.getLogger(ValidationToolBL.class.getName());
+
+ @Autowired
+ protected List<IArtifactValidatorExecuter> validators;
+
+ @Autowired
+ protected ReportManager reportManager;
+
+ private boolean allValid = true;
+
+
+ public boolean validateAll() {
+ for (IArtifactValidatorExecuter validatorExec: validators) {
+ System.out.println("ValidatorExecuter "+validatorExec.getName()+" started");
+ if (!validatorExec.executeValidations()) {
+ allValid = false;
+ System.out.println("ValidatorExecuter "+validatorExec.getName()+" finished with warnings");
+ }
+ else {
+ System.out.println("ValidatorExecuter "+validatorExec.getName()+" finished successfully");
+ }
+ }
+ return allValid;
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java
index 79b36f0004..90d850686b 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java
@@ -11,16 +11,22 @@ import java.util.Properties;
public class ValidationConfigManager {
private static Properties prop = new Properties();
+ private static String outputFullFilePath;
+ private static String outputFilePath;
+ public static String getOutputFullFilePath() {
+ return outputFullFilePath;
+ }
public static String getOutputFilePath() {
return outputFilePath;
}
- public static void setOutputFilePath(String outputPath) {
- ValidationConfigManager.outputFilePath = outputPath+ "/reportOutput.txt";
+ public static void setOutputFullFilePath(String outputPath) {
+ ValidationConfigManager.outputFilePath = outputPath;
+ ValidationConfigManager.outputFullFilePath = outputPath+ "/reportOutput.txt";
}
- private static String outputFilePath;
+
public static String getCsvReportFilePath() {
return csvReportFilePath;
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java
index 3b81ba81e4..63e95d568b 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java
@@ -1,7 +1,11 @@
package org.openecomp.sdc.asdctool.impl.validator.config;
+import org.openecomp.sdc.asdctool.impl.validator.ArtifactToolBL;
import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL;
+import org.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecuter;
+import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceToscaArtifactsValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecuter;
+import org.openecomp.sdc.asdctool.impl.validator.executers.VFToscaArtifactValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.executers.VfValidatorExecuter;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ArtifactValidationUtils;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ServiceArtifactValidationTask;
@@ -37,6 +41,15 @@ public class ValidationToolConfiguration {
@Bean
public ServiceValidatorExecuter basicServiceValidator() { return new ServiceValidatorExecuter();}
+
+ @Bean
+ public NodeToscaArtifactsValidatorExecuter NodeToscaArtifactsValidatorValidator() { return new NodeToscaArtifactsValidatorExecuter();}
+
+ @Bean
+ public ServiceToscaArtifactsValidatorExecutor ServiceToscaArtifactsValidator() { return new ServiceToscaArtifactsValidatorExecutor();}
+
+ @Bean
+ public VFToscaArtifactValidatorExecutor VFToscaArtifactValidator() { return new VFToscaArtifactValidatorExecutor();}
@Bean
public VfArtifactValidationTask vfArtifactValidationTask() { return new VfArtifactValidationTask(); }
@@ -51,6 +64,11 @@ public class ValidationToolConfiguration {
public ValidationToolBL validationToolBL() {
return new ValidationToolBL();
}
+
+ @Bean
+ public ArtifactToolBL artifactToolBL() {
+ return new ArtifactToolBL();
+ }
@Bean
public VfValidatorExecuter basicVfValidator() { return new VfValidatorExecuter();}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
new file mode 100644
index 0000000000..4b9764d2d5
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
@@ -0,0 +1,145 @@
+package org.openecomp.sdc.asdctool.impl.validator.executers;
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import fj.data.Either;
+
+public class ArtifactValidatorExecuter{
+
+ @Autowired
+ protected TitanDao titanDao;
+
+ @Autowired
+ private ToscaOperationFacade toscaOperationFacade;
+ private static Logger log = LoggerFactory.getLogger(ArtifactValidatorExecuter.class.getName());
+
+ protected String name;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+
+
+ public Map<String, List<Component>> getVerticesToValidate(VertexTypeEnum type, Map<GraphPropertyEnum, Object> hasProps){
+ Map<String, List<Component>> result = new HashMap<>();
+ Either<List<GraphVertex>, TitanOperationStatus> resultsEither = titanDao.getByCriteria(type, hasProps);
+ if (resultsEither.isRight()) {
+ System.out.println("getVerticesToValidate failed "+ resultsEither.right().value());
+ return result;
+ }
+ System.out.println("getVerticesToValidate: "+resultsEither.left().value().size()+" vertices to scan");
+ List<GraphVertex> componentsList = resultsEither.left().value();
+ componentsList.forEach(vertex -> {
+ String ivariantUuid = (String)vertex.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID);
+ if(!result.containsKey(ivariantUuid)){
+ List<Component> compList = new ArrayList<Component>();
+ result.put(ivariantUuid, compList);
+ }
+ List<Component> compList = result.get(ivariantUuid);
+
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreArtifacts(false);
+
+ Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(vertex.getUniqueId(), filter);
+ if (toscaElement.isRight()) {
+ System.out.println("getVerticesToValidate: failed to find element"+ vertex.getUniqueId()+" staus is" + toscaElement.right().value());
+ }else{
+ compList.add(toscaElement.left().value());
+ }
+
+ });
+
+ return result;
+ }
+
+ public boolean validate( Map<String, List<Component>> vertices) {
+ boolean result = true;
+ long time = System.currentTimeMillis();
+ String fileName = ValidationConfigManager.getOutputFilePath() + this.getName() + "_"+ time + ".csv";
+ Writer writer = null;
+ try {
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
+ writer.write("name, UUID, invariantUUID, state, version\n");
+ Collection<List<Component>> collection = vertices.values();
+ for(List<Component> compList: collection ){
+ Set<String> artifactEsId = new HashSet<>();
+ for(Component component: compList ){
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ Optional<ArtifactDefinition> op = toscaArtifacts.values().
+ stream().filter(a -> artifactEsId.contains(a.getEsId())).findAny();
+ if(op.isPresent()){
+ result = false;
+ writeModuleResultToFile(writer, compList);
+ writer.flush();
+ break;
+ }else{
+ artifactEsId.addAll(toscaArtifacts.values().stream().map(ArtifactDefinition::getEsId).collect(Collectors.toList())) ;
+ }
+ }
+
+ }
+
+ } catch (Exception e) {
+ log.info("Failed to fetch vf resources ", e);
+ return false;
+ } finally {
+ titanDao.commit();
+ try {
+ writer.flush();
+ writer.close();
+ } catch (Exception ex) {
+ /* ignore */}
+ }
+ return result;
+ }
+
+ private void writeModuleResultToFile(Writer writer, List<Component> components) {
+ try {
+ // "service name, service id, state, version
+ for(Component component: components ){
+ StringBuffer sb = new StringBuffer(component.getName());
+ sb.append(",").append(component.getUniqueId()).append(",").append(component.getInvariantUUID()).append(",").append(component.getLifecycleState()).append(",").append(component.getVersion());
+
+ sb.append("\n");
+ writer.write(sb.toString());
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecuter.java
new file mode 100644
index 0000000000..6f9405f992
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecuter.java
@@ -0,0 +1,9 @@
+package org.openecomp.sdc.asdctool.impl.validator.executers;
+
+public interface IArtifactValidatorExecuter {
+ boolean executeValidations();
+ String getName();
+
+
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuter.java
new file mode 100644
index 0000000000..6715c8a955
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuter.java
@@ -0,0 +1,41 @@
+package org.openecomp.sdc.asdctool.impl.validator.executers;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+
+public class NodeToscaArtifactsValidatorExecuter extends ArtifactValidatorExecuter implements IArtifactValidatorExecuter{
+ protected String name;
+
+ public NodeToscaArtifactsValidatorExecuter() {
+ setName("RESOURCE_TOSCA_ARTIFACTS");
+ }
+ @Override
+ public boolean executeValidations() {
+
+ Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+
+ Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.NODE_TYPE, hasProps);
+ return validate(vertices);
+
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutor.java
new file mode 100644
index 0000000000..2fe5abef3c
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutor.java
@@ -0,0 +1,39 @@
+package org.openecomp.sdc.asdctool.impl.validator.executers;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+
+public class ServiceToscaArtifactsValidatorExecutor extends ArtifactValidatorExecuter implements IArtifactValidatorExecuter{
+
+
+ public ServiceToscaArtifactsValidatorExecutor() {
+ setName("SERVICE_TOSCA_ARTIFACTS");
+ }
+ @Override
+ public boolean executeValidations() {
+ Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+
+ Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps);
+ return validate(vertices);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutor.java
new file mode 100644
index 0000000000..bc22f2e424
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutor.java
@@ -0,0 +1,43 @@
+package org.openecomp.sdc.asdctool.impl.validator.executers;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+
+public class VFToscaArtifactValidatorExecutor extends ArtifactValidatorExecuter implements IArtifactValidatorExecuter{
+
+ public VFToscaArtifactValidatorExecutor() {
+ setName("VF_TOSCA_ARTIFACTS");
+ }
+ @Override
+ public boolean executeValidations() {
+
+ Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+ hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
+ hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+
+ Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps);
+ return validate( vertices);
+
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
index 4a4af15fdf..a19a98ed27 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
@@ -34,7 +34,7 @@ public class ReportManager {
}
private void initReportFile() throws IOException {
- reportOutputFilePath = ValidationConfigManager.getOutputFilePath();
+ reportOutputFilePath = ValidationConfigManager.getOutputFullFilePath();
StrBuilder sb = new StrBuilder();
sb.appendln("-----------------------Validation Tool Results:-------------------------");
Files.write(Paths.get(reportOutputFilePath), sb.toString().getBytes());
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactUUIDFixMenu.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactUUIDFixMenu.java
new file mode 100644
index 0000000000..5ca8e55412
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactUUIDFixMenu.java
@@ -0,0 +1,45 @@
+package org.openecomp.sdc.asdctool.main;
+
+import org.openecomp.sdc.asdctool.configuration.ArtifactUUIDFixConfiguration;
+import org.openecomp.sdc.asdctool.configuration.ConfigurationUploader;
+import org.openecomp.sdc.asdctool.impl.ArtifactUuidFix;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+public class ArtifactUUIDFixMenu {
+
+ private static Logger log = LoggerFactory.getLogger(ArtifactUUIDFixMenu.class);
+
+ public static void main(String[] args) {
+ if (args == null || args.length < 3) {
+ System.out.println("Usage: <configuration dir> <all/distributed_only> <services/service_vf/fix/fix_only_services>");
+ System.exit(1);
+ }
+ String fixServices = args[1];
+ String runMode = args[2];
+ // String fixTosca = args[3];
+ log.info("Start fixing artifact UUID after 1707 migration with arguments run with configuration [{}] , for [{}] services", runMode, fixServices);
+ String appConfigDir = args[0];
+ ConfigurationUploader.uploadConfigurationFiles(appConfigDir);
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ArtifactUUIDFixConfiguration.class);
+ ArtifactUuidFix artifactUuidFix = context.getBean(ArtifactUuidFix.class);
+ boolean isSuccessful = artifactUuidFix.doFix(fixServices, runMode);
+ if (isSuccessful) {
+ log.info("Fixing artifacts UUID for 1707 was finished successfully");
+ /* isSuccessful = artifactUuidFix.doFixTosca(fixTosca, fixServices, runMode);
+ if (isSuccessful) {
+ log.info("Fixing tosca artifacts was finished successfully");
+ isSuccessful = artifactUuidFix.doFixTosca(fixTosca, fixServices, runMode);
+ } else{
+ log.info("Fixing tosca artifacts has failed");
+ System.exit(2);
+ }*/
+ } else{
+ log.info("Fixing artifacts UUID for 1707 has failed");
+ System.exit(2);
+ }
+ System.exit(0);
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactValidatorTool.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactValidatorTool.java
new file mode 100644
index 0000000000..f7e8f1fa8b
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactValidatorTool.java
@@ -0,0 +1,46 @@
+package org.openecomp.sdc.asdctool.main;
+
+import org.openecomp.sdc.asdctool.impl.validator.ArtifactToolBL;
+import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager;
+import org.openecomp.sdc.asdctool.impl.validator.config.ValidationToolConfiguration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+public class ArtifactValidatorTool {
+ private static Logger log = LoggerFactory.getLogger(ValidationTool.class.getName());
+
+ public static void main(String[] args) throws Exception {
+
+ String outputPath = args[0];
+ ValidationConfigManager.setOutputFullFilePath(outputPath);
+ ValidationConfigManager.setCsvReportFilePath(outputPath);
+
+ String appConfigDir = args[1];
+ AnnotationConfigApplicationContext context = initContext(appConfigDir);
+ ArtifactToolBL validationToolBL = context.getBean(ArtifactToolBL.class);
+
+ System.out.println("Start ArtifactValidation Tool");
+ Boolean result = validationToolBL.validateAll();
+ // ReportManager.reportEndOfToolRun();
+ if (result) {
+ System.out.println("ArtifactValidation finished successfully");
+ System.exit(0);
+ } else {
+ System.out.println("ArtifactValidation finished with warnings");
+ System.exit(2);
+ }
+ }
+
+ private static AnnotationConfigApplicationContext initContext(String appConfigDir) {
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ValidationToolConfiguration.class);
+ return context;
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/UpdateIsVnfMenu.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/UpdateIsVnfMenu.java
index 73b7306de4..dce9f9c072 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/UpdateIsVnfMenu.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/UpdateIsVnfMenu.java
@@ -25,7 +25,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.asdctool.impl.UpdatePropertyOnVertex;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
index 1ee006a49f..51e2d500da 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
@@ -22,7 +22,7 @@ public class ValidationTool {
public static void main(String[] args) throws Exception {
String outputPath = args[0];
- ValidationConfigManager.setOutputFilePath(outputPath);
+ ValidationConfigManager.setOutputFullFilePath(outputPath);
ValidationConfigManager.setCsvReportFilePath(outputPath);
String appConfigDir = args[1];
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java
index 4d52347788..19651ec45a 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/MigrationSpringConfig.java
@@ -1,21 +1,70 @@
package org.openecomp.sdc.asdctool.migration.config;
+import java.util.ArrayList;
+import java.util.List;
+
import org.openecomp.sdc.asdctool.migration.core.SdcMigrationTool;
import org.openecomp.sdc.asdctool.migration.core.task.Migration;
+import org.openecomp.sdc.asdctool.migration.core.task.PostMigration;
+import org.openecomp.sdc.asdctool.migration.dao.MigrationTasksDao;
import org.openecomp.sdc.asdctool.migration.resolver.MigrationResolver;
import org.openecomp.sdc.asdctool.migration.resolver.SpringBeansMigrationResolver;
import org.openecomp.sdc.asdctool.migration.service.SdcRepoService;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.ArtifactsResolver;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngine;
+import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
+import org.openecomp.sdc.be.components.impl.AdditionalInformationBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ArtifactResolverImpl;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.CompositionBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
+import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.VFComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.merge.heat.HeatEnvArtifactsMergeBusinessLogic;
+import org.openecomp.sdc.be.components.merge.input.InputsValuesMergingBusinessLogic;
+import org.openecomp.sdc.be.components.merge.instance.ComponentInstanceMergeDataBusinessLogic;
+import org.openecomp.sdc.be.components.merge.property.DataDefinitionsValuesMergingBusinessLogic;
+import org.openecomp.sdc.be.dao.DAOTitanStrategy;
+import org.openecomp.sdc.be.dao.TitanClientStrategy;
+import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraClient;
-import org.openecomp.sdc.asdctool.migration.dao.MigrationTasksDao;
import org.openecomp.sdc.be.dao.config.DAOSpringConfig;
+import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
+import org.openecomp.sdc.be.dao.impl.AuditingDao;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.cache.ComponentCache;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
+import org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation;
+import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
+import org.openecomp.sdc.be.model.operations.impl.ElementOperation;
+import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupInstanceOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.tosca.CsarUtils;
+import org.openecomp.sdc.be.tosca.ToscaExportHandler;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
-
-import java.util.ArrayList;
-import java.util.List;
+import org.springframework.core.io.FileSystemResource;
@Configuration
@Import(DAOSpringConfig.class)
@@ -23,13 +72,19 @@ import java.util.List;
"org.openecomp.sdc.be.model.operations.impl",
"org.openecomp.sdc.be.model.cache",
"org.openecomp.sdc.be.dao.titan",
+ "org.openecomp.sdc.be.components.validation",
"org.openecomp.sdc.be.dao.cassandra",
"org.openecomp.sdc.be.model.jsontitan.operations",
- "org.openecomp.sdc.be.dao.jsongraph"})
+ "org.openecomp.sdc.be.dao.jsongraph",
+ "org.openecomp.sdc.be.components.merge",
+ "org.openecomp.sdc.be.impl"})
public class MigrationSpringConfig {
@Autowired(required=false)
private List<Migration> migrations = new ArrayList<>();
+
+ @Autowired(required=false)
+ private List<PostMigration> postMigrations = new ArrayList<>();
@Bean(name = "sdc-migration-tool")
public SdcMigrationTool sdcMigrationTool(MigrationResolver migrationResolver, SdcRepoService sdcRepoService) {
@@ -38,7 +93,7 @@ public class MigrationSpringConfig {
@Bean(name = "spring-migrations-resolver")
public SpringBeansMigrationResolver migrationResolver(SdcRepoService sdcRepoService) {
- return new SpringBeansMigrationResolver(migrations, sdcRepoService);
+ return new SpringBeansMigrationResolver(migrations, postMigrations, sdcRepoService);
}
@Bean(name = "sdc-repo-service")
@@ -57,5 +112,247 @@ public class MigrationSpringConfig {
}
+ @Bean(name = "dao-titan-strategy")
+ public TitanClientStrategy daoStrategy() {
+ return new DAOTitanStrategy();
+ }
+
+ @Bean(name = "titan-dao")
+ public TitanDao titanDao(@Qualifier("titan-client") TitanGraphClient titanGraphClient) {
+ return new TitanDao(titanGraphClient);
+ }
+
+ @Bean(name = "titan-client", initMethod = "createGraph")
+ public TitanGraphClient titanClient(@Qualifier("dao-titan-strategy") TitanClientStrategy titanClientStrategy) {
+ return new TitanGraphClient(titanClientStrategy);
+ }
+
+ @Bean(name = "resource-business-logic")
+ public ResourceBusinessLogic resourceBusinessLogic() {
+ return new ResourceBusinessLogic();
+ }
+
+// @Bean(name = "healthCheckBusinessLogic")
+// public HealthCheckBusinessLogic healthCheckBusinessLogic() {
+// return new HealthCheckBusinessLogic();
+// }
+//
+// @Bean(name = "distribution-engine-cluster-health")
+// public DistributionEngineClusterHealth distributionEngineClusterHealth() {
+// return new DistributionEngineClusterHealth();
+// }
+//
+// @Bean(name = "cassandra-health-check")
+// public CassandraHealthCheck cassandraHealthCheck() {
+// return new CassandraHealthCheck();
+// }
+
+// @Bean(name = "switchover-detector")
+// public SwitchoverDetector switchoverDetector() {
+// return new SwitchoverDetector();
+// }
+
+ @Bean(name = "service-business-logic")
+ public ServiceBusinessLogic serviceBusinessLogic() {
+ return new ServiceBusinessLogic();
+ }
+
+ @Bean(name = "capability-type-operation")
+ public CapabilityTypeOperation CapabilityTypeOperation() {
+ return new CapabilityTypeOperation();
+ }
+
+ @Bean(name = "lifecycle-business-logic")
+ public LifecycleBusinessLogic lifecycleBusinessLogic() {
+ return new LifecycleBusinessLogic();
+ }
+
+ @Bean(name = "property-operation")
+ public PropertyOperation propertyOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
+ return new PropertyOperation(titanGenericDao);
+ }
+
+ @Bean(name = "csar-operation")
+ public CsarOperation csarOperation() {
+ return new CsarOperation();
+ }
+
+ @Bean(name = "vf-component-instance-business-logic")
+ public VFComponentInstanceBusinessLogic vFComponentInstanceBusinessLogic() {
+ return new VFComponentInstanceBusinessLogic();
+ }
+
+ @Bean(name = "resource-import-manager")
+ public ResourceImportManager resourceImportManager() {
+ return new ResourceImportManager();
+ }
+
+ @Bean(name = "group-business-logic")
+ public GroupBusinessLogic groupBusinessLogic() {
+ return new GroupBusinessLogic();
+ }
+
+ @Bean(name = "inputs-business-logic")
+ public InputsBusinessLogic inputsBusinessLogic() {
+ return new InputsBusinessLogic();
+ }
+
+ @Bean(name = "composition-business-logic")
+ public CompositionBusinessLogic compositionBusinessLogic() {
+ return new CompositionBusinessLogic();
+ }
+
+ @Bean(name = "artifacts-business-logic")
+ public ArtifactsBusinessLogic artifactsBusinessLogic() {
+ return new ArtifactsBusinessLogic();
+ }
+
+ @Bean(name = "component-cache")
+ public ComponentCache componentCache() {
+ return new ComponentCache();
+ }
+
+ @Bean(name = "componentUtils")
+ public ComponentsUtils componentsUtils() {
+ return new ComponentsUtils();
+ }
+
+ @Bean(name = "user-business-logic")
+ public UserBusinessLogic userBusinessLogic() {
+ return new UserBusinessLogic();
+ }
+
+ @Bean(name = "graph-lock-operation")
+ public GraphLockOperation graphLockOperation() {
+ return new GraphLockOperation();
+ }
+
+ @Bean(name = "titan-generic-dao")
+ public TitanGenericDao titanGenericDao(@Qualifier("titan-client") TitanGraphClient titanGraphClient) {
+ return new TitanGenericDao(titanGraphClient);
+ }
+
+ @Bean(name = "element-operation")
+ public ElementOperation elementOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
+ return new ElementOperation(titanGenericDao);
+ }
+
+ @Bean(name = "group-operation")
+ public GroupOperation groupOperation() {
+ return new GroupOperation();
+ }
+
+ @Bean(name = "group-instance-operation")
+ public GroupInstanceOperation groupInstanceOperation() {
+ return new GroupInstanceOperation();
+ }
+
+ @Bean(name = "group-type-operation")
+ public GroupTypeOperation groupTypeOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao, @Qualifier("property-operation") PropertyOperation propertyOperation) {
+ return new GroupTypeOperation(titanGenericDao, propertyOperation);
+ }
+
+ @Bean(name = "tosca-operation-facade")
+ public ToscaOperationFacade toscaOperationFacade() {
+ return new ToscaOperationFacade();
+ }
+
+ @Bean(name = "distribution-engine")
+ public DistributionEngine distributionEngine() {
+ return null;
+ }
+
+ @Bean(name = "audit-cassandra-dao")
+ public AuditCassandraDao auditCassandraDao() {
+ return new AuditCassandraDao();
+ }
+
+ @Bean(name = "service-component-instance-business-logic")
+ public ServiceComponentInstanceBusinessLogic serviceComponentInstanceBusinessLogic() {
+ return new ServiceComponentInstanceBusinessLogic();
+ }
+
+ @Bean("tosca-export-handler")
+ public ToscaExportHandler toscaExportHandler() {
+ return new ToscaExportHandler();
+ }
+
+ @Bean(name = "component-instance-operation")
+ public ComponentInstanceOperation componentInstanceOperation() {
+ return new ComponentInstanceOperation();
+ }
+
+ @Bean(name = "additional-information-business-logic")
+ public AdditionalInformationBusinessLogic additionalInformationBusinessLogic() {
+ return new AdditionalInformationBusinessLogic();
+ }
+
+ @Bean(name = "auditing-manager")
+ public AuditingManager auditingManager() {
+ return new AuditingManager();
+ }
+
+ @Bean(name = "auditing-dao")
+ public AuditingDao auditingDao() {
+ return new AuditingDao();
+ }
+
+ @Bean(name = "elasticsearch-client", initMethod = "initialize")
+ public ElasticSearchClient elasticSearchClient() {
+ return new ElasticSearchClient();
+ }
+
+ @Bean(name = "csar-utils")
+ public CsarUtils csarUtils() {
+ return new CsarUtils();
+ }
+
+ @Bean(name = "service-distribution-artifacts-builder")
+ public ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder() {
+ return new ServiceDistributionArtifactsBuilder();
+ }
+
+ @Bean(name = "product-business-logic")
+ public ProductBusinessLogic productBusinessLogic() {
+ return null;
+ }
+
+ @Bean(name = "dataDefinitionsValuesMergingBusinessLogic")
+ public DataDefinitionsValuesMergingBusinessLogic dataDefinitionsValuesMergingBusinessLogic() {
+ return new DataDefinitionsValuesMergingBusinessLogic();
+ }
+
+ @Bean(name = "artifacts-resolver")
+ public ArtifactsResolver artifactsResolver() {
+ return new ArtifactResolverImpl();
+ }
+
+ @Bean(name = "InputsValuesMergingBusinessLogic")
+ public InputsValuesMergingBusinessLogic InputsValuesMergingBusinessLogic(){
+ return new InputsValuesMergingBusinessLogic();
+ }
+
+ @Bean(name = "GenericTypeBusinessLogic")
+ public GenericTypeBusinessLogic genericTypeBusinessLogic(){
+ return new GenericTypeBusinessLogic();
+ }
+
+ @Bean(name ="componentInstanceMergeDataBusinessLogic")
+ public ComponentInstanceMergeDataBusinessLogic componentInstanceMergeDataBusinessLogic(){
+ return new ComponentInstanceMergeDataBusinessLogic();
+ }
+
+ @Bean(name ="heatEnvArtifactsMergeBusinessLogic")
+ public HeatEnvArtifactsMergeBusinessLogic heatEnvArtifactsMergeBusinessLogic(){
+ return new HeatEnvArtifactsMergeBusinessLogic();
+ }
+
+ @Bean(name = "elasticsearchConfig")
+ public PropertiesFactoryBean mapper() {
+ String configHome = System.getProperty("config.home");
+ PropertiesFactoryBean bean = new PropertiesFactoryBean();
+ bean.setLocation(new FileSystemResource(configHome + "/elasticsearch.yml"));
+ return bean;
+ }
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationTool.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationTool.java
index 21671a67a9..b8e2347970 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationTool.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationTool.java
@@ -4,7 +4,8 @@ import java.util.List;
import org.openecomp.sdc.asdctool.migration.core.execution.MigrationExecutionResult;
import org.openecomp.sdc.asdctool.migration.core.execution.MigrationExecutorImpl;
-import org.openecomp.sdc.asdctool.migration.core.task.Migration;
+import org.openecomp.sdc.asdctool.migration.core.task.IMigrationStage;
+import org.openecomp.sdc.asdctool.migration.core.task.IMigrationStage.AspectMigrationEnum;
import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
import org.openecomp.sdc.asdctool.migration.resolver.MigrationResolver;
import org.openecomp.sdc.asdctool.migration.service.SdcRepoService;
@@ -30,16 +31,17 @@ public class SdcMigrationTool {
public boolean migrate(boolean enforceAll) {
LOGGER.info("starting migration process");
handleEnforceMigrationFlag(enforceAll);
- List<Migration> migrations = migrationsResolver.resolveMigrations();
+ List<IMigrationStage> migrations = migrationsResolver.resolveMigrations();
LOGGER.info("there are {} migrations task to execute", migrations.size());
- for (Migration migration : migrations) {
+ for (IMigrationStage migration : migrations) {
try {
MigrationExecutionResult executionResult = new MigrationExecutorImpl().execute(migration);
if (migrationHasFailed(executionResult)) {
LOGGER.error("migration {} with version {} has failed. error msg: {}", migration.getClass().getName(), migration.getVersion().toString(), executionResult.getMsg());
return false;
}
- sdcRepoService.createMigrationTask(executionResult.toMigrationTaskEntry());
+ if(migration.getAspectMigration() == AspectMigrationEnum.MIGRATION)
+ sdcRepoService.createMigrationTask(executionResult.toMigrationTaskEntry());
} catch (RuntimeException e) {
LOGGER.error("migration {} with version {} has failed. error msg: {}", migration.getClass().getName(), migration.getVersion().toString(), e);
return false;
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java
index accd9eca53..aa871914d6 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutionResult.java
@@ -1,11 +1,11 @@
package org.openecomp.sdc.asdctool.migration.core.execution;
+import java.util.Date;
+
import org.openecomp.sdc.asdctool.migration.core.DBVersion;
import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
import org.openecomp.sdc.be.resources.data.MigrationTaskEntry;
-import java.util.Date;
-
public class MigrationExecutionResult {
private MigrationResult.MigrationStatus migrationStatus;
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutor.java
index aba5056b48..cf3e50a312 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutor.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutor.java
@@ -1,7 +1,7 @@
package org.openecomp.sdc.asdctool.migration.core.execution;
import org.openecomp.sdc.asdctool.migration.core.MigrationException;
-import org.openecomp.sdc.asdctool.migration.core.task.Migration;
+import org.openecomp.sdc.asdctool.migration.core.task.IMigrationStage;
public interface MigrationExecutor {
@@ -10,6 +10,6 @@ public interface MigrationExecutor {
* @return a {@link MigrationExecutionResult} with the relevant data on the current migration execution;
* @throws MigrationException in case there was an unexpected exception during migration
*/
- MigrationExecutionResult execute(Migration migration) throws MigrationException;
+ MigrationExecutionResult execute(IMigrationStage migration) throws MigrationException;
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java
index 39219aee23..2b3b28a737 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImpl.java
@@ -1,7 +1,7 @@
package org.openecomp.sdc.asdctool.migration.core.execution;
import org.openecomp.sdc.asdctool.migration.core.MigrationException;
-import org.openecomp.sdc.asdctool.migration.core.task.Migration;
+import org.openecomp.sdc.asdctool.migration.core.task.IMigrationStage;
import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,7 +13,7 @@ public class MigrationExecutorImpl implements MigrationExecutor {
private static final Logger LOGGER = LoggerFactory.getLogger(MigrationExecutorImpl.class);
@Override
- public MigrationExecutionResult execute(Migration migration) throws MigrationException {
+ public MigrationExecutionResult execute(IMigrationStage migration) throws MigrationException {
try {
LOGGER.info("starting migration {}. description: {}. version {}", migration.getClass().getName(), migration.description(), migration.getVersion().toString());
StopWatch stopWatch = new StopWatch();
@@ -29,12 +29,12 @@ public class MigrationExecutorImpl implements MigrationExecutor {
}
}
- private MigrationExecutionResult logAndCreateExecutionResult(Migration migration, MigrationResult migrationResult, double executionTime) {
+ private MigrationExecutionResult logAndCreateExecutionResult(IMigrationStage migration, MigrationResult migrationResult, double executionTime) {
LOGGER.info("finished migration {}. with version {}. migration status: {}, migration message: {}, execution time: {}", migration.getClass().getName(), migration.getVersion().toString(), migrationResult.getMigrationStatus().name(), migrationResult.getMsg(), executionTime);
return createMigrationTask(migration, migrationResult, executionTime);
}
- private MigrationExecutionResult createMigrationTask(Migration migration, MigrationResult migrationResult, double totalTimeSeconds) {
+ private MigrationExecutionResult createMigrationTask(IMigrationStage migration, MigrationResult migrationResult, double totalTimeSeconds) {
MigrationExecutionResult migrationExecutionResult = new MigrationExecutionResult();
migrationExecutionResult.setExecutionTime(totalTimeSeconds);
migrationExecutionResult.setMigrationStatus(migrationResult.getMigrationStatus());
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/IMigrationStage.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/IMigrationStage.java
new file mode 100644
index 0000000000..d58da7d784
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/IMigrationStage.java
@@ -0,0 +1,20 @@
+package org.openecomp.sdc.asdctool.migration.core.task;
+
+import org.openecomp.sdc.asdctool.migration.core.DBVersion;
+
+public interface IMigrationStage {
+
+ String description();
+
+ DBVersion getVersion();
+
+ MigrationResult migrate();
+
+ AspectMigrationEnum getAspectMigration();
+
+ public enum AspectMigrationEnum {
+ BEFORE_MIGRATION,
+ MIGRATION,
+ AFTER_MIGRATION;
+ }
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/Migration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/Migration.java
index 58f201acf5..6ec95dce8b 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/Migration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/Migration.java
@@ -1,14 +1,10 @@
package org.openecomp.sdc.asdctool.migration.core.task;
-
-import org.openecomp.sdc.asdctool.migration.core.DBVersion;
-
-public interface Migration {
-
- String description();
-
- DBVersion getVersion();
-
- MigrationResult migrate();
+public interface Migration extends IMigrationStage{
+ @Override
+ default
+ AspectMigrationEnum getAspectMigration(){
+ return AspectMigrationEnum.MIGRATION;
+ }
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/PostMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/PostMigration.java
new file mode 100644
index 0000000000..f20c36471d
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/core/task/PostMigration.java
@@ -0,0 +1,19 @@
+package org.openecomp.sdc.asdctool.migration.core.task;
+
+import org.openecomp.sdc.asdctool.migration.core.DBVersion;
+
+public interface PostMigration extends IMigrationStage {
+
+ @Override
+ default
+ public DBVersion getVersion() {
+ return DBVersion.CURRENT_VERSION;
+ }
+
+ @Override
+ default
+ AspectMigrationEnum getAspectMigration(){
+ return AspectMigrationEnum.AFTER_MIGRATION;
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDao.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDao.java
index 03fd8d1e7d..b0bfabb059 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDao.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDao.java
@@ -1,11 +1,9 @@
package org.openecomp.sdc.asdctool.migration.dao;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.mapping.Mapper;
-import com.datastax.driver.mapping.MappingManager;
-import fj.data.Either;
+import java.math.BigInteger;
+
+import javax.annotation.PostConstruct;
+
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.dao.cassandra.CassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
@@ -13,10 +11,14 @@ import org.openecomp.sdc.be.resources.data.MigrationTaskEntry;
import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
-import javax.annotation.PostConstruct;
-import java.math.BigInteger;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.Mapper;
+import com.datastax.driver.mapping.MappingManager;
+
+import fj.data.Either;
public class MigrationTasksDao extends CassandraDao {
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/main/MigrationMenu.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/main/MigrationMenu.java
index 1e8a533624..dc2114dcd7 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/main/MigrationMenu.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/main/MigrationMenu.java
@@ -7,12 +7,9 @@ import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.openecomp.sdc.asdctool.configuration.ConfigurationUploader;
import org.openecomp.sdc.asdctool.migration.config.MigrationSpringConfig;
import org.openecomp.sdc.asdctool.migration.core.SdcMigrationTool;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.common.api.ConfigurationSource;
-import org.openecomp.sdc.common.impl.ExternalConfiguration;
-import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -25,7 +22,7 @@ public class MigrationMenu {
CommandLine commandLine = initCmdLineOptions(args);
String appConfigDir = commandLine.getOptionValue("c");
boolean enforceAll = commandLine.hasOption("e");
- uploadConfiguration(appConfigDir);
+ ConfigurationUploader.uploadConfigurationFiles(appConfigDir);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MigrationSpringConfig.class);
doMigrate(enforceAll, context);
@@ -91,10 +88,4 @@ public class MigrationMenu {
.build();
}
- private static void uploadConfiguration(String appConfigDir) {
- ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
- ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
- }
-
-
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/MigrationResolver.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/MigrationResolver.java
index b272d45ff0..22add31eb4 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/MigrationResolver.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/MigrationResolver.java
@@ -1,16 +1,16 @@
package org.openecomp.sdc.asdctool.migration.resolver;
-import org.openecomp.sdc.asdctool.migration.core.task.Migration;
-
import java.util.List;
+import org.openecomp.sdc.asdctool.migration.core.task.IMigrationStage;
+
public interface MigrationResolver {
/**
*
* @return a list of {@code T}
*/
- List<Migration> resolveMigrations();
+ List<IMigrationStage> resolveMigrations();
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolver.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolver.java
index 4af5d76123..182996f5e4 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolver.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolver.java
@@ -1,38 +1,49 @@
package org.openecomp.sdc.asdctool.migration.resolver;
-import org.openecomp.sdc.asdctool.migration.core.DBVersion;
-import org.openecomp.sdc.asdctool.migration.core.task.Migration;
-import org.openecomp.sdc.asdctool.migration.service.SdcRepoService;
-
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
+import org.openecomp.sdc.asdctool.migration.core.DBVersion;
+import org.openecomp.sdc.asdctool.migration.core.task.IMigrationStage;
+import org.openecomp.sdc.asdctool.migration.core.task.Migration;
+import org.openecomp.sdc.asdctool.migration.core.task.PostMigration;
+import org.openecomp.sdc.asdctool.migration.service.SdcRepoService;
+
public class SpringBeansMigrationResolver implements MigrationResolver {
private List<Migration> migrations = new ArrayList<>();
-
+ private List<PostMigration> postMigrations = new ArrayList<>();
+
private SdcRepoService sdcRepoService;
- public SpringBeansMigrationResolver(List<Migration> migrations, SdcRepoService sdcRepoService) {
+ public SpringBeansMigrationResolver(List<Migration> migrations, List<PostMigration> postMigrations, SdcRepoService sdcRepoService) {
this.migrations = migrations;
+ this.postMigrations = postMigrations;
this.sdcRepoService = sdcRepoService;
}
@Override
- public List<Migration> resolveMigrations() {
+ public List<IMigrationStage> resolveMigrations() {
migrations.sort(Comparator.comparing(Migration::getVersion));
- return resolveNonExecutedMigrations();
+ List<IMigrationStage> allTasks = resolveNonExecutedMigrations();
+ allTasks.addAll(postMigrations);
+ return allTasks;
}
//package private for testing
void setMigrations(List<Migration> migrations) {
this.migrations = migrations;
}
+
+ //package private for testing
+ void setPostMigrations(List<PostMigration> postMigrations) {
+ this.postMigrations = postMigrations;
+ }
- private List<Migration> resolveNonExecutedMigrations() {
+ private List<IMigrationStage> resolveNonExecutedMigrations() {
DBVersion latestDBVersion = sdcRepoService.getLatestDBVersion();
return migrations.stream()
.filter(mig -> isMigrationVersionGreaterThanLatestVersion(latestDBVersion, mig))
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java
index 20451f2c63..cf4affb345 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoService.java
@@ -1,11 +1,11 @@
package org.openecomp.sdc.asdctool.migration.service;
+import java.math.BigInteger;
+
import org.openecomp.sdc.asdctool.migration.core.DBVersion;
import org.openecomp.sdc.asdctool.migration.dao.MigrationTasksDao;
import org.openecomp.sdc.be.resources.data.MigrationTaskEntry;
-import java.math.BigInteger;
-
public class SdcRepoService {
private MigrationTasksDao migrationTasksDao;
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/OutputHandler.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/OutputHandler.java
new file mode 100644
index 0000000000..59259219db
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/OutputHandler.java
@@ -0,0 +1,9 @@
+package org.openecomp.sdc.asdctool.migration.tasks.handlers;
+
+public interface OutputHandler {
+
+ public void initiate(Object... title);
+ public void addRecord(Object... record);
+ public boolean writeOutput();
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/XlsOutputHandler.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/XlsOutputHandler.java
new file mode 100644
index 0000000000..91eaed5429
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/XlsOutputHandler.java
@@ -0,0 +1,66 @@
+package org.openecomp.sdc.asdctool.migration.tasks.handlers;
+
+import java.io.FileOutputStream;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class XlsOutputHandler implements OutputHandler {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(XlsOutputHandler.class);
+
+ private Workbook workbook;
+ private Sheet activeSheet;
+ private Row currentRow;
+ int rowCount = 0;
+
+ public XlsOutputHandler(Object... title){
+ initiate(title);
+ }
+
+ @Override
+ public void initiate(Object... title) {
+ LOGGER.info("Starting to initiate xls output handler. ");
+ workbook = new HSSFWorkbook();
+ activeSheet = workbook.createSheet("Upgrade Migration 1710.0 results");
+ addRecord(title);
+ LOGGER.info("Xls output handler has been initiated. ");
+ }
+
+ @Override
+ public void addRecord(Object... record) {
+ LOGGER.debug("Going to add record {} to output. ", record);
+ currentRow = activeSheet.createRow(rowCount++);
+ LOGGER.debug("A new row has been created");
+ int columnCount = 0;
+ Cell cell;
+ for(Object cellValue : record){
+ cell = currentRow.createCell(columnCount++);
+ if(cellValue != null)
+ cell.setCellValue(cellValue.toString());
+ }
+ }
+
+ @Override
+ public boolean writeOutput() {
+ try {
+ DateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");
+ String fileName = "UpgradeMigration1710Results_" + df.format(System.currentTimeMillis()) + ".xls";
+ LOGGER.info("Going to write xls output file {}. ", fileName);
+ workbook.write(new FileOutputStream(fileName));
+ return true;
+ } catch (Exception e) {
+ LOGGER.error("Failed to write an output file upon Upgrade migration 1710. Exception {} occured. ", e.getMessage());
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java
new file mode 100644
index 0000000000..166512d5b4
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java
@@ -0,0 +1,739 @@
+package org.openecomp.sdc.asdctool.migration.tasks.mig1710;
+
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
+import org.openecomp.sdc.asdctool.migration.core.task.PostMigration;
+import org.openecomp.sdc.asdctool.migration.tasks.handlers.XlsOutputHandler;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
+import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import fj.data.Either;
+
+@Component
+public class UpgradeMigration1710 implements PostMigration {
+
+ private static final String UNKNOWN = "UNKNOWN";
+
+ private static final String CHECKOUT_MESSAGE = "checkout upon upgrade migration";
+
+ private static final String FAILED_TO_CHANGE_STATE_OF_COMPONENT = "Failed to change state of component with name {}, invariantUUID {}, version {} to {}. ";
+
+ private static final String FAILED_TO_UPGRADE_COMPONENT = "Failed to upgrade {} with name {}, invariantUUID {}, version {}. Operation {}. The reason for failure: {}. ";
+
+ private static final String UPGRADE_COMPONENT_SUCCEEDED = "Upgrade of {} with name {}, invariantUUID {}, version {} finished successfully. ";
+
+ private static final String UPGRADE_VFS_FAILED = "Upgrade VFs upon upgrade migration 1710 process failed. ";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(UpgradeMigration1710.class);
+
+ @Autowired
+ private TitanDao titanDao;
+
+ @Autowired
+ private ToscaOperationFacade toscaOperationFacade;
+
+ @Autowired
+ private LifecycleBusinessLogic lifecycleBusinessLogic;
+
+ @Autowired
+ private IUserAdminOperation userAdminOperation;
+
+ @Autowired
+ private ResourceBusinessLogic resourceBusinessLogic;
+
+ @Autowired
+ private CsarOperation csarOperation;
+
+ @Autowired
+ private ServiceComponentInstanceBusinessLogic componentInstanceBusinessLogic;
+
+ @Autowired
+ private ComponentsUtils componentsUtils;
+
+ private final XlsOutputHandler outputHandler = new XlsOutputHandler("COMPONENT TYPE", "COMPONENT NAME", "COMPONENT UUID", "COMPONENT UNIQUE_ID", "UPGRADE STATUS", "DESCRIPTION");
+
+ private User user = null;
+
+ private final LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction(CHECKOUT_MESSAGE, LifecycleChanceActionEnum.UPGRADE_MIGRATION);
+
+ private final Map<String,GraphVertex> latestGenericTypes = new HashMap<>();
+
+ private boolean isVfcUpgradeRequired = false;
+
+ private boolean skipIfUpgradeVfFailed = true;
+
+ /** below methods is defined on package level for testing
+ * where Spring object injection is not used **/
+ void setUserAdminOperation(IUserAdminOperation userAdminOperation) { this.userAdminOperation = userAdminOperation; }
+
+ void setTitanDao(TitanDao titanDao) { this.titanDao = titanDao; }
+
+ void setTosckaOperationFacade(ToscaOperationFacade toscaOperationFacade) { this.toscaOperationFacade = toscaOperationFacade; }
+
+ void setLifecycleBusinessLogic(LifecycleBusinessLogic lifecycleBusinessLogic) { this.lifecycleBusinessLogic = lifecycleBusinessLogic; }
+
+ void setComponentsUtils(ComponentsUtils componentsUtils) { this.componentsUtils = componentsUtils; }
+
+
+ /***********************************************/
+
+ @Override
+ public String description() {
+ return "Upgrade migration 1710 - post migration task, which is dedicated to upgrade all latest certified (and not checked out) Node types, VFs and Services. ";
+ }
+
+ private enum UpgradeStatus{
+ UPGRADED,
+ NOT_UPGRADED
+ }
+
+ @Override
+ public MigrationResult migrate() {
+ LOGGER.info("Starting upgrade migration 1710 process. ");
+ MigrationResult migrationResult = new MigrationResult();
+
+ try{
+ boolean result = true;
+
+ isVfcUpgradeRequired = !ConfigurationManager.getConfigurationManager().getConfiguration().getSkipUpgradeVSPsFlag();
+ skipIfUpgradeVfFailed = ConfigurationManager.getConfigurationManager().getConfiguration().getSkipUpgradeFailedVfs();
+ final String userId = ConfigurationManager.getConfigurationManager().getConfiguration().getAutoHealingOwner();
+
+ Either<User, ActionStatus> userReq = userAdminOperation.getUserData(userId, false);
+ if (userReq.isRight()) {
+ result = false;
+ LOGGER.error("Upgrade migration was failed. User {} resolve failed: {} ", userId, userReq.right().value());
+ }
+ else {
+ user = userReq.left().value();
+ LOGGER.info("User {} will perform upgrade operation", user.toString());
+ }
+
+ if(result){
+ result = upgradeNodeTypes();
+ }
+ if(result){
+ result = upgradeVFs();
+ }
+ if(result){
+ upgradeServices();
+ }
+ if(result){
+ LOGGER.info("Upgrade migration 1710 has been successfully finished. ");
+ titanDao.commit();
+ migrationResult.setMigrationStatus(MigrationResult.MigrationStatus.COMPLETED);
+ } else {
+ LOGGER.info("Upgrade migration 1710 was failed. ");
+ titanDao.rollback();
+ migrationResult.setMigrationStatus(MigrationResult.MigrationStatus.FAILED);
+ }
+ } catch(Exception e){
+ LOGGER.error("Upgrade migration 1710 was failed. ", e);
+ titanDao.rollback();
+ migrationResult.setMigrationStatus(MigrationResult.MigrationStatus.FAILED);
+ } finally {
+ outputHandler.writeOutput();
+ }
+ return migrationResult;
+ }
+
+ private StorageOperationStatus upgradeServices() {
+ LOGGER.info("Starting upgrade services upon upgrade migration 1710 process. ");
+ Map<String, String> latestOriginResourceVersions = new HashMap<>();
+ Either<List<String>, TitanOperationStatus> getServicesRes = getAllLatestCertifiedComponentUids(VertexTypeEnum.TOPOLOGY_TEMPLATE, ComponentTypeEnum.SERVICE);
+ if(getServicesRes.isRight()){
+ return StorageOperationStatus.GENERAL_ERROR;
+ }
+ for(String currUid : getServicesRes.left().value()){
+ try{
+ if(handleService(currUid, latestOriginResourceVersions)){
+ titanDao.commit();
+ } else {
+ processComponentUpgradeFailure(ComponentTypeEnum.SERVICE.name(), currUid, "");
+ }
+ } catch(Exception e){
+ processComponentUpgradeFailure(ComponentTypeEnum.SERVICE.name(), currUid, e.getMessage());
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
+ private void processComponentUpgradeFailure(final String name, final String currUid, final String reason) {
+ LOGGER.error("Failed to upgrade {} with uniqueId {} due to a reason {}. ", name, currUid, reason);
+ titanDao.rollback();
+ }
+
+ private boolean handleService(String uniqueId, Map<String, String> latestOriginResourceVersions) {
+ LOGGER.info("Starting upgrade Service with uniqueId {} upon upgrade migration 1710 process. ", uniqueId);
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getServiceRes = toscaOperationFacade.getToscaElement(uniqueId);
+ if(getServiceRes.isRight()){
+ LOGGER.error("Failed to upgrade service with uniqueId {} due to {}. ", uniqueId, getServiceRes.right().value());
+ outputHandler.addRecord(ComponentTypeEnum.SERVICE.name(), UNKNOWN, UNKNOWN, uniqueId, MigrationResult.MigrationStatus.FAILED.name(), getServiceRes.right().value());
+ return false;
+ }
+ String derivedFromGenericType = getServiceRes.left().value().getDerivedFromGenericType();
+ LOGGER.debug("derivedFromGenericType: {}", derivedFromGenericType );
+ if (derivedFromGenericType == null) {
+ //malformed field value, upgrade required
+ return upgradeService(getServiceRes.left().value());
+ }
+ if(!latestGenericTypes.containsKey(derivedFromGenericType)){
+ Either<List<GraphVertex>, TitanOperationStatus> getDerivedRes = findDerivedResources(derivedFromGenericType);
+ if(getDerivedRes.isRight()){
+ LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, getServiceRes.left().value().getComponentType().getValue(), getServiceRes.left().value().getName(), getServiceRes.left().value().getInvariantUUID(), getServiceRes.left().value().getVersion(), "findDerivedResources", getDerivedRes.right().value());
+ outputHandler.addRecord( getServiceRes.left().value().getComponentType().name(),getServiceRes.left().value().getName(), getServiceRes.left().value().getInvariantUUID(), getServiceRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), getDerivedRes.right().value());
+ return false;
+ }
+ latestGenericTypes.put(derivedFromGenericType, getDerivedRes.left().value().get(0));
+ }
+ if(latestVersionExists(latestGenericTypes.get(derivedFromGenericType), getServiceRes.left().value().getDerivedFromGenericVersion())){
+ return upgradeService(getServiceRes.left().value());
+ }
+ if(!collectLatestOriginResourceVersions(getServiceRes.left().value(), latestOriginResourceVersions)){
+ return false;
+ }
+ if(shouldUpgrade(getServiceRes.left().value(), latestOriginResourceVersions)){
+ return upgradeService(getServiceRes.left().value());
+ }
+ outputHandler.addRecord(getServiceRes.left().value().getComponentType().name(), getServiceRes.left().value().getName(), getServiceRes.left().value().getInvariantUUID(), getServiceRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.COMPLETED.name(), UpgradeStatus.NOT_UPGRADED);
+ return true;
+ }
+
+ private boolean collectLatestOriginResourceVersions(org.openecomp.sdc.be.model.Component component, Map<String, String> latestOriginResourceVersions) {
+ if(CollectionUtils.isNotEmpty(component.getComponentInstances())){
+ for(ComponentInstance instance : component.getComponentInstances()){
+ if(instance.getOriginType() != OriginTypeEnum.ServiceProxy && !latestOriginResourceVersions.containsKey(instance.getToscaComponentName())){
+ VertexTypeEnum vertexType = ModelConverter.getVertexType(instance.getOriginType().name());
+ Either<Resource, StorageOperationStatus> getOriginRes = toscaOperationFacade.getLatestCertifiedByToscaResourceName(instance.getToscaComponentName(), vertexType, JsonParseFlagEnum.ParseMetadata);
+ if(getOriginRes.isRight()){
+ LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, component.getComponentType().getValue(), component.getName(), component.getInvariantUUID(), component.getVersion(), "toscaOperationFacade.getLatestCertifiedByToscaResourceName", getOriginRes.right().value());
+ outputHandler.addRecord( component.getComponentType().name(), component.getName(), component.getInvariantUUID(), component.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), getOriginRes.right().value());
+ return false;
+ }
+ latestOriginResourceVersions.put(instance.getToscaComponentName(), getOriginRes.left().value().getVersion());
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean shouldUpgrade(org.openecomp.sdc.be.model.Component component, Map<String, String> latestOriginResources) {
+ boolean shouldUpgrade = false;
+ if(CollectionUtils.isNotEmpty(component.getComponentInstances())){
+ for(ComponentInstance instance : component.getComponentInstances()){
+ if(instance.getOriginType() == OriginTypeEnum.ServiceProxy){
+ LOGGER.info("The service with name {}, invariantUUID {}, version {}, contains Service proxy instance {}, than the service should be upgraded. ", component.getName(), component.getInvariantUUID(), component.getVersion(), instance.getName());
+ shouldUpgrade = true;
+ }
+ if(isGreater(latestOriginResources.get(instance.getToscaComponentName()), instance.getComponentVersion())){
+ LOGGER.info("The service with name {}, invariantUUID {}, version {}, contains instance {} from outdated version of origin {} {} , than the service should be upgraded. ", component.getName(), component.getInvariantUUID(), component.getVersion(), instance.getName(), instance.getComponentName(), instance.getComponentVersion());
+ shouldUpgrade = true;
+ }
+ }
+ }
+ return shouldUpgrade;
+ }
+
+ private boolean upgradeService(org.openecomp.sdc.be.model.Component service) {
+ String serviceName = service.getName();
+ String serviceUuid = service.getUUID();
+ LOGGER.info("Starting upgrade Service with name {}, invariantUUID {}, version {} upon upgrade migration 1710 process. ", serviceName, service.getInvariantUUID(), service.getVersion());
+ LOGGER.info("Starting to perform check out of service {}. ", serviceName);
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> checkouRes = lifecycleBusinessLogic.changeComponentState(service.getComponentType(), service.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT, changeInfo, true, false);
+ if(checkouRes.isRight()){
+ LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, service.getComponentType().getValue(), serviceName, service.getInvariantUUID(), service.getVersion(), "lifecycleBusinessLogic.changeComponentState", checkouRes.right().value().getFormattedMessage());
+ outputHandler.addRecord(service.getComponentType().name(), serviceName, serviceUuid, service.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), checkouRes.right().value().getFormattedMessage());
+ return false;
+ }
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> updateCompositionRes = updateComposition(checkouRes.left().value());
+ if(updateCompositionRes.isRight()){
+ LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, service.getComponentType().getValue(), serviceName, service.getInvariantUUID(), service.getVersion(), "updateComposition", updateCompositionRes.right().value().getFormattedMessage());
+ outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), updateCompositionRes.right().value().getFormattedMessage());
+ return false;
+ }
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> certifyRes = performFullCertification(checkouRes.left().value());
+ if(certifyRes.isRight()){
+ LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, service.getComponentType().getValue(), serviceName, service.getInvariantUUID(), service.getVersion(), "performFullCertification", certifyRes.right().value().getFormattedMessage());
+ outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), certifyRes.right().value().getFormattedMessage());
+ return false;
+ }
+ outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), serviceUuid, checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.COMPLETED.name(), UpgradeStatus.UPGRADED);
+ return true;
+ }
+
+ private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> updateComposition(org.openecomp.sdc.be.model.Component component) {
+ Either<ComponentInstance, ResponseFormat> upgradeInstanceRes;
+ for(ComponentInstance instance : component.getComponentInstances()){
+ upgradeInstanceRes = upgradeInstance(component, instance);
+ if(upgradeInstanceRes.isRight()) {
+ LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, component.getComponentType().getValue(), component.getName(), component.getInvariantUUID(), component.getVersion(), "upgradeInstance", upgradeInstanceRes.right().value().getFormattedMessage());
+ outputHandler.addRecord(component.getComponentType().name(), component.getName(), component.getUUID(), component.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), upgradeInstanceRes.right().value().getFormattedMessage());
+ return Either.right(upgradeInstanceRes.right().value());
+ }
+ }
+ return Either.left(component);
+ }
+
+ private Either<ComponentInstance, ResponseFormat> upgradeInstance(org.openecomp.sdc.be.model.Component component, ComponentInstance instance) {
+ LOGGER.info("Starting upgrade {} instance {} upon upgrade migration 1710 process. ", component.getComponentType().getValue(), instance.getName());
+ ComponentInstance newComponentInstance = new ComponentInstance(instance);
+ if(instance.getOriginType() == OriginTypeEnum.ServiceProxy){
+ return upgradeServiceProxyInstance(component, instance, newComponentInstance);
+ }
+ return upgradeResourceInstance(component, instance, newComponentInstance);
+ }
+
+ private Either<ComponentInstance, ResponseFormat> upgradeResourceInstance(org.openecomp.sdc.be.model.Component component,
+ ComponentInstance instance, ComponentInstance newComponentInstance) {
+ LOGGER.info("Starting upgrade {} instance {} upon upgrade migration 1710 process. ", component.getComponentType().getValue(), instance.getName());
+ VertexTypeEnum vertexType = ModelConverter.getVertexType(instance.getOriginType().name());
+ Either<Resource, StorageOperationStatus> getOriginRes = toscaOperationFacade.getLatestCertifiedByToscaResourceName(instance.getToscaComponentName(), vertexType, JsonParseFlagEnum.ParseMetadata);
+ if(getOriginRes.isRight()){
+ LOGGER.info("Upgrade of {} instance {} upon upgrade migration 1710 process failed due to a reason {}. ",
+ component.getComponentType().getValue(), instance.getName(), getOriginRes.right().value());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getOriginRes.right().value(), instance.getOriginType().getComponentType())));
+ }
+ newComponentInstance.setComponentName(getOriginRes.left().value().getName());
+ newComponentInstance.setComponentUid(getOriginRes.left().value().getUniqueId());
+ newComponentInstance.setComponentVersion(getOriginRes.left().value().getVersion());
+ newComponentInstance.setToscaComponentName(((Resource)getOriginRes.left().value()).getToscaResourceName());
+ if(isGreater(getOriginRes.left().value().getVersion(), instance.getComponentVersion())){
+ return changeAssetVersion(component, instance, newComponentInstance);
+ }
+
+ //upgrade nodes contained by CVFC
+ if(isVfcUpgradeRequired && newComponentInstance.getOriginType() == OriginTypeEnum.CVFC &&
+ !upgradeVf(getOriginRes.left().value().getUniqueId())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ LOGGER.info("Upgrade of {} instance {} upon upgrade migration 1710 process finished successfully. ",
+ component.getComponentType().getValue(), instance.getName());
+ return Either.left(instance);
+ }
+
+ private Either<ComponentInstance, ResponseFormat> upgradeServiceProxyInstance(org.openecomp.sdc.be.model.Component component, ComponentInstance instance, ComponentInstance newComponentInstance) {
+ Either<List<GraphVertex>, TitanOperationStatus> getLatestOriginServiceRes = getLatestCertifiedService(instance.getSourceModelInvariant());
+ if(getLatestOriginServiceRes.isRight()){
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(getLatestOriginServiceRes.right().value()), instance.getOriginType().getComponentType())));
+ }
+ newComponentInstance.setComponentVersion((String) getLatestOriginServiceRes.left().value().get(0).getJsonMetadataField(JsonPresentationFields.VERSION));
+ newComponentInstance.setSourceModelUid((String) getLatestOriginServiceRes.left().value().get(0).getJsonMetadataField(JsonPresentationFields.UNIQUE_ID));
+ newComponentInstance.setSourceModelName((String) getLatestOriginServiceRes.left().value().get(0).getJsonMetadataField(JsonPresentationFields.NAME));
+ newComponentInstance.setSourceModelUuid((String) getLatestOriginServiceRes.left().value().get(0).getJsonMetadataField(JsonPresentationFields.UUID));
+ return changeAssetVersion(component, instance, newComponentInstance);
+ }
+
+ private Either<List<GraphVertex>, TitanOperationStatus> getLatestCertifiedService(String invariantUUID) {
+
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ propertiesToMatch.put(GraphPropertyEnum.INVARIANT_UUID, invariantUUID);
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+ return titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata);
+ }
+
+ private Either<ComponentInstance, ResponseFormat> changeAssetVersion(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance instance, ComponentInstance newComponentInstance) {
+ return componentInstanceBusinessLogic.changeComponentInstanceVersion(ComponentTypeEnum.SERVICE_PARAM_NAME, containerComponent.getUniqueId(), instance.getUniqueId(), user.getUserId(), newComponentInstance);
+ }
+
+ private boolean upgradeNodeTypes() {
+ LOGGER.info("Starting upgrade node types upon upgrade migration 1710 process. ");
+ String toscaConformanceLevel = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel();
+ Map<String, List<String>> resourcesForUpgrade = ConfigurationManager.getConfigurationManager().getConfiguration().getResourcesForUpgrade();
+ Map<String, org.openecomp.sdc.be.model.Component> upgradedNodeTypesMap = new HashMap<> ();
+ List<String> nodeTypes;
+ if(resourcesForUpgrade.containsKey(toscaConformanceLevel)){
+ nodeTypes = resourcesForUpgrade.get(toscaConformanceLevel);
+ if(nodeTypes !=null && !nodeTypes.isEmpty()){
+ Either<List<String>, TitanOperationStatus> getRes = getAllLatestCertifiedComponentUids(VertexTypeEnum.NODE_TYPE, ComponentTypeEnum.RESOURCE);
+ if(getRes.isRight()){
+ return false;
+ }
+ List<String> allNodeTypes = getRes.left().value();
+
+ for(String toscaResourceName: nodeTypes){
+ Either<List<GraphVertex>, StorageOperationStatus> status = getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
+ if (status.isRight()) {
+ LOGGER.error("Failed to find node type {} ", toscaResourceName);
+ return false;
+ }
+ List<GraphVertex> vList = status.left().value();
+ for (GraphVertex vertex : vList) {
+ StorageOperationStatus updateRes = upgradeNodeType(vertex, upgradedNodeTypesMap, allNodeTypes, nodeTypes);
+ if (updateRes != StorageOperationStatus.OK) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean upgradeVFs() {
+ LOGGER.info("Starting upgrade VFs upon upgrade migration 1710 process. ");
+ Either<List<String>, TitanOperationStatus> getVfsRes = getAllLatestCertifiedComponentUids(VertexTypeEnum.TOPOLOGY_TEMPLATE, ComponentTypeEnum.RESOURCE);
+ if(getVfsRes.isRight()){
+ LOGGER.info(UPGRADE_VFS_FAILED);
+ return false;
+ }
+ for (String currUid : getVfsRes.left().value()) {
+ try {
+ if (!upgradeVf(currUid)) {
+ processComponentUpgradeFailure(ComponentTypeEnum.RESOURCE.name(), currUid, "");
+ if (!skipIfUpgradeVfFailed) {
+ LOGGER.info(UPGRADE_VFS_FAILED);
+ return false;
+ }
+ }
+ titanDao.commit();
+ } catch (Exception e) {
+ processComponentUpgradeFailure(ComponentTypeEnum.RESOURCE.name(), currUid, e.getMessage());
+ if (!skipIfUpgradeVfFailed) {
+ LOGGER.info(UPGRADE_VFS_FAILED);
+ return false;
+ }
+ }
+ }
+ LOGGER.info("Upgrade VFs upon upgrade migration 1710 process finished successfully. ");
+ return true;
+ }
+
+ private boolean upgradeVf(String uniqueId) {
+ LOGGER.info("Starting upgrade VF with uniqueId {} upon upgrade migration 1710 process. ", uniqueId);
+ Either<String, StorageOperationStatus> latestVersionRes;
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getRes = toscaOperationFacade.getToscaElement(uniqueId);
+ if(getRes.isRight()){
+ LOGGER.debug("Failed to fetch VF with uniqueId {} upon upgrade migration 1710 process. ", uniqueId);
+ outputHandler.addRecord(ComponentTypeEnum.RESOURCE.name(), UNKNOWN, UNKNOWN, uniqueId, MigrationResult.MigrationStatus.FAILED.name(), getRes.right().value());
+ return false;
+ }
+ if(StringUtils.isNotEmpty(getRes.left().value().getCsarUUID())){
+ LOGGER.info("Going to fetch the latest version of VSP with csarUUID {} upon upgrade migration 1710 process. ", getRes.left().value().getCsarUUID());
+ latestVersionRes = csarOperation.getCsarLatestVersion(getRes.left().value().getCsarUUID(), user);
+ if(latestVersionRes.isRight()){
+ LOGGER.debug("Failed to fetch the latest version of VSP with csarUUID {} upon upgrade migration 1710 process. ", getRes.left().value().getCsarUUID());
+ outputHandler.addRecord(getRes.left().value().getComponentType().name(), getRes.left().value().getName(), getRes.left().value().getUUID(), getRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(),latestVersionRes.right().value());
+ return false;
+ }
+ if(isGreater(latestVersionRes.left().value(), getRes.left().value().getCsarVersion())){
+ return upgradeVfWithLatestVsp(getRes.left().value(), latestVersionRes);
+ }
+ if (!isVfcUpgradeRequired){
+ LOGGER.warn("Warning: No need to upgrade VF with name {}, invariantUUID {}, version {} and VSP version {}. No new version of VSP. ", getRes.left().value().getName(), getRes.left().value().getInvariantUUID(), getRes.left().value().getVersion(), getRes.left().value().getCsarVersion());
+ }
+ }
+ return upgradeComponentWithLatestGeneric(getRes.left().value());
+ }
+
+ private boolean upgradeVfWithLatestVsp(org.openecomp.sdc.be.model.Component vf, Either<String, StorageOperationStatus> latestVersionRes) {
+ LOGGER.info("Starting upgrade vf with name {}, invariantUUID {}, version {} and latest VSP version {} upon upgrade migration 1710 process. ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersionRes.left().value());
+ LOGGER.info("Starting to perform check out of vf with name {}, invariantUUID {}, version {}. ", vf.getName(),vf.getInvariantUUID(), vf.getVersion());
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> checkouRes = lifecycleBusinessLogic.changeComponentState(vf.getComponentType(), vf.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT, changeInfo, true, false);
+ if(checkouRes.isRight()){
+ outputHandler.addRecord(vf.getComponentType().name(), vf.getName(), vf.getUUID(), vf.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), checkouRes.right().value().getFormattedMessage());
+ return false;
+ }
+ LOGGER.info("Starting update vf with name {}, invariantUUID {}, version {} and latest VSP {}. ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersionRes.left().value());
+ Resource resourceToUpdate = new Resource(((Resource) checkouRes.left().value()).getComponentMetadataDefinition());
+ resourceToUpdate.setDerivedFromGenericType(((Resource) checkouRes.left().value()).getDerivedFromGenericType());
+ resourceToUpdate.setDerivedFromGenericVersion(((Resource) checkouRes.left().value()).getDerivedFromGenericVersion());
+ resourceToUpdate.setCsarVersion(Double.toString(Double.parseDouble(latestVersionRes.left().value())));
+ Either<Resource, ResponseFormat> updateResourceFromCsarRes = resourceBusinessLogic.validateAndUpdateResourceFromCsar(resourceToUpdate, user, null, null, resourceToUpdate.getUniqueId());
+ if(updateResourceFromCsarRes.isRight()){
+ outputHandler.addRecord(resourceToUpdate.getComponentType().name(), resourceToUpdate.getName(), resourceToUpdate.getUUID(), resourceToUpdate.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), updateResourceFromCsarRes.right().value().getFormattedMessage());
+ LOGGER.info("Failed to update vf with name {}, invariantUUID {}, version {} and latest VSP {}. ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersionRes.left().value());
+ return false;
+ }
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> certifyRes = performFullCertification(checkouRes.left().value());
+ if(certifyRes.isRight()){
+ LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getVersion(), LifeCycleTransitionEnum.CERTIFY);
+ outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), certifyRes.right().value().getFormattedMessage());
+ return false;
+ }
+ LOGGER.info("Full certification of vf with name {}, invariantUUID {}, version {} finished . ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersionRes.left().value());
+ outputHandler.addRecord(certifyRes.left().value().getComponentType().name(), certifyRes.left().value().getName(), certifyRes.left().value().getUUID(), certifyRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.COMPLETED.name(), UpgradeStatus.UPGRADED);
+ return true;
+ }
+
+ private boolean upgradeComponentWithLatestGeneric(org.openecomp.sdc.be.model.Component component) {
+ String derivedFromGenericType = component.getDerivedFromGenericType();
+ String derivedFromGenericVersion = component.getDerivedFromGenericVersion();
+ org.openecomp.sdc.be.model.Component updatedComponent = component;
+ if(StringUtils.isNotEmpty(derivedFromGenericType) && !latestGenericTypes.containsKey(derivedFromGenericType)){
+ LOGGER.info("Starting upgrade vf with name {}, invariantUUID {}, version {}, latest derived from generic type {}, latest derived from generic version {}. ", component.getName(), component.getInvariantUUID(), component.getVersion(), derivedFromGenericType, derivedFromGenericVersion);
+ LOGGER.info("Starting to fetch latest generic node type {}. ", derivedFromGenericType);
+ Either<List<GraphVertex>, TitanOperationStatus> getDerivedRes = findDerivedResources(derivedFromGenericType);
+ if(getDerivedRes.isRight()){
+ outputHandler.addRecord(component.getComponentType().name(), component.getName(), component.getInvariantUUID(), component.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), getDerivedRes.right().value());
+ LOGGER.info("Failed to upgrade component with name {}, invariantUUID {}, version {} and latest generic. Status is {}. ", component.getName(), component.getInvariantUUID(), component.getVersion(), derivedFromGenericType);
+ return false;
+ }
+ latestGenericTypes.put(derivedFromGenericType, getDerivedRes.left().value().get(0));
+ }
+ if(StringUtils.isEmpty(derivedFromGenericType) ||
+ latestVersionExists(latestGenericTypes.get(derivedFromGenericType), derivedFromGenericVersion) ||
+ isVfcUpgradeRequired){
+ if(StringUtils.isNotEmpty(derivedFromGenericType))
+ LOGGER.info("Newer version {} of derived from generic type {} exists. ", latestGenericTypes.get(derivedFromGenericType).getJsonMetadataField(JsonPresentationFields.VERSION), derivedFromGenericType);
+ else
+ LOGGER.info("The vf resource with name {}, invariantUUID {}, version {}, has an empty derivedFromGenericType field. ", component.getName(), component.getInvariantUUID(), component.getVersion());
+
+ LOGGER.info("Starting to perform check out of vf with name {}, invariantUUID {}, version {}. ", component.getName(), component.getInvariantUUID(), component.getVersion());
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> checkouRes = lifecycleBusinessLogic.changeComponentState(component.getComponentType(), component.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT, changeInfo, true, false);
+ if(checkouRes.isRight()){
+ LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.CHECKOUT);
+ outputHandler.addRecord(component.getComponentType().name(), component.getName(), component.getInvariantUUID(), component.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), checkouRes.right().value().getFormattedMessage());
+ return false;
+ }
+ //update included VFCs, if it is required as per configuration
+ if(isVfcUpgradeRequired && CollectionUtils.isNotEmpty(checkouRes.left().value().getComponentInstances())){
+ LOGGER.info("VFC upgrade is required: updating components of vf with name {}, invariantUUID {}, version {}. ", component.getName(), component.getInvariantUUID(), component.getVersion());
+ Either<org.openecomp.sdc.be.model.Component, ResponseFormat> updateCompositionRes =
+ updateComposition(checkouRes.left().value());
+ if(updateCompositionRes.isRight()){
+ LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getVersion(), "updateComposition", updateCompositionRes.right().value().getFormattedMessage());
+ outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), updateCompositionRes.right().value().getFormattedMessage());
+ return false;
+ }
+ }
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> certifyRes = performFullCertification(checkouRes.left().value());
+ if(certifyRes.isRight()){
+ LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.CERTIFY);
+ outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), certifyRes.right().value().getFormattedMessage());
+ return false;
+ }
+ updatedComponent = certifyRes.left().value();
+ } else {
+ LOGGER.info("The version {} of derived from generic type {} is up to date. No need to upgrade component with name {}, invariantUUID {} and version {}. ", latestGenericTypes.get(derivedFromGenericType), derivedFromGenericType,component.getName(), component.getInvariantUUID(), component.getVersion());
+ }
+ LOGGER.info(UPGRADE_COMPONENT_SUCCEEDED, component.getComponentType().getValue(), component.getName(), component.getInvariantUUID(), component.getVersion());
+ outputHandler.addRecord(updatedComponent.getComponentType().name(), updatedComponent.getName(), updatedComponent.getUUID(), updatedComponent.getUniqueId(), MigrationResult.MigrationStatus.COMPLETED.name(), updatedComponent.equals(component) ? UpgradeStatus.NOT_UPGRADED : UpgradeStatus.UPGRADED);
+ return true;
+ }
+
+ private StorageOperationStatus upgradeNodeType(GraphVertex nodeTypeV, Map<String, org.openecomp.sdc.be.model.Component> upgradedNodeTypesMap, List<String> allCertifiedUids, List<String> nodeTypes) {
+ StorageOperationStatus result = StorageOperationStatus.OK;
+ LOGGER.info("Starting upgrade node type with name {}, invariantUUID {}, version{}. ", nodeTypeV.getMetadataProperty(GraphPropertyEnum.NAME), nodeTypeV.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID), nodeTypeV.getMetadataProperty(GraphPropertyEnum.VERSION));
+ LOGGER.info("Starting to find derived to for node type with name {}, invariantUUID {}, version{}. ", nodeTypeV.getMetadataProperty(GraphPropertyEnum.NAME), nodeTypeV.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID), nodeTypeV.getMetadataProperty(GraphPropertyEnum.VERSION));
+ Either<List<GraphVertex>, TitanOperationStatus> parentResourceRes = titanDao.getParentVertecies(nodeTypeV, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseMetadata);
+ if(parentResourceRes.isRight() && parentResourceRes.right().value() != TitanOperationStatus.NOT_FOUND ){
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(parentResourceRes.right().value());
+
+ }
+ List<GraphVertex> derivedResourcesUid = new ArrayList<>();
+ if(parentResourceRes.isLeft()){
+ for(GraphVertex chV: parentResourceRes.left().value()){
+ Optional<String> op = allCertifiedUids.stream().filter(id -> id.equals((String)chV.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID))).findAny();
+ if(op.isPresent()){
+ derivedResourcesUid.add(chV);
+ }
+ }
+ }
+ String uniqueId = (String)nodeTypeV.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID);
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getRes = toscaOperationFacade.getToscaElement(uniqueId);
+ if(getRes.isRight()){
+ LOGGER.info("failed to fetch element with uniqueId {} ", uniqueId);
+ return getRes.right().value();
+ }
+
+ org.openecomp.sdc.be.model.Resource nt = (Resource)getRes.left().value();
+ boolean isNeedToUpgrade = true;
+ if(upgradedNodeTypesMap.containsKey(nt.getToscaResourceName()) || nodeTypes.stream().filter( p -> p.equals(nt.getToscaResourceName())).findAny().isPresent()){
+ isNeedToUpgrade = false;
+ }
+ if(isNeedToUpgrade){
+ LOGGER.info("Starting to perform check out of node type with name {}, invariantUUID {}, version {}. ", nt.getName(), nt.getInvariantUUID(), nt.getVersion());
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> checkouRes = lifecycleBusinessLogic.changeComponentState(nt.getComponentType(), nt.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT, changeInfo, true, false);
+ if(checkouRes.isRight()){
+ return StorageOperationStatus.GENERAL_ERROR;
+ }
+ org.openecomp.sdc.be.model.Component upgradetComp = checkouRes.left().value();
+ boolean res = performFullCertification(upgradetComp).isLeft();
+ if(!res){
+ return StorageOperationStatus.GENERAL_ERROR;
+ }
+ upgradedNodeTypesMap.put(nt.getToscaResourceName(), upgradetComp);
+ titanDao.commit();
+ }
+ for(GraphVertex chV: derivedResourcesUid){
+ result = upgradeNodeType(chV, upgradedNodeTypesMap, allCertifiedUids, nodeTypes);
+ LOGGER.info("Upgrade node type with name {}, invariantUUID {}, version {} has been finished with the status {}", chV.getMetadataProperty(GraphPropertyEnum.NAME), chV.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID), chV.getMetadataProperty(GraphPropertyEnum.VERSION), result);
+ }
+ return result;
+ }
+
+ private Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> performFullCertification(org.openecomp.sdc.be.model.Component component) {
+ LOGGER.info("Starting to perform full certification of {} with name {}, invariantUUID {}, version {}. ",
+ component.getComponentType().getValue(), component.getName(), component.getInvariantUUID(), component.getVersion());
+
+ Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> changeStateEither = lifecycleBusinessLogic.changeComponentState(component.getComponentType(), component.getUniqueId(), user, LifeCycleTransitionEnum.CERTIFICATION_REQUEST, changeInfo, true, false);
+ if(changeStateEither.isRight()){
+ LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.CERTIFICATION_REQUEST);
+ return changeStateEither;
+ }
+ changeStateEither = lifecycleBusinessLogic.changeComponentState(component.getComponentType(), changeStateEither.left().value().getUniqueId(), user, LifeCycleTransitionEnum.START_CERTIFICATION, changeInfo, true, false);
+ if(changeStateEither.isRight()){
+ LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.START_CERTIFICATION);
+ return changeStateEither;
+ }
+ changeStateEither = lifecycleBusinessLogic.changeComponentState(component.getComponentType(), changeStateEither.left().value().getUniqueId(), user, LifeCycleTransitionEnum.CERTIFY, changeInfo, true, false);
+ if(changeStateEither.isRight()){
+ LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.CERTIFY);
+ }
+ else {
+ LOGGER.info("Full certification of {} with name {}, invariantUUID {}, version {} finished successfully",
+ changeStateEither.left().value().getComponentType().getValue(), changeStateEither.left().value().getName(),
+ changeStateEither.left().value().getInvariantUUID(), changeStateEither.left().value().getVersion());
+ }
+ return changeStateEither;
+ }
+
+ private Either<List<GraphVertex>, TitanOperationStatus> findDerivedResources(String parentResource) {
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+
+ propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, parentResource);
+ propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+
+ return titanDao.getByCriteria(VertexTypeEnum.NODE_TYPE, propertiesToMatch, JsonParseFlagEnum.ParseMetadata);
+ }
+
+ private boolean latestVersionExists(GraphVertex latestDerivedFrom, String currentVersion) {
+ return isGreater((String)latestDerivedFrom.getJsonMetadataField(JsonPresentationFields.VERSION), currentVersion);
+ }
+
+ private boolean isGreater(String latestVersion, String currentVersion) {
+ if(latestVersion != null && currentVersion == null)
+ return true;
+ if(latestVersion == null)
+ return false;
+ return Double.parseDouble(latestVersion) > Double.parseDouble(currentVersion);
+ }
+
+ private Either<List<String>, TitanOperationStatus> getAllLatestCertifiedComponentUids(VertexTypeEnum vertexType, ComponentTypeEnum componentType) {
+ LOGGER.info("Starting to fetch all latest certified not checked out components with type {} upon upgrade migration 1710 process", componentType);
+ Either<List<String>, TitanOperationStatus> result = null;
+ Map<String, String> latestCertifiedMap = new HashMap<>();
+ Map<String, String> latestNotCertifiedMap = new HashMap<>();
+
+ Either<List<GraphVertex>, TitanOperationStatus> getComponentsRes = getAllLatestCertifiedComponents(vertexType, componentType);
+ if(getComponentsRes.isRight() && getComponentsRes.right().value() != TitanOperationStatus.NOT_FOUND){
+ LOGGER.error("Failed to fetch all latest certified not checked out components with type {}. Status is {}. ", componentType, getComponentsRes.right().value());
+ result = Either.right(getComponentsRes.right().value());
+ }
+ if(getComponentsRes.isRight()){
+ result = Either.left(new ArrayList<>());
+ }
+ if(result == null){
+ for(GraphVertex component : getComponentsRes.left().value()){
+ String invariantUUID = (String)component.getJsonMetadataField(JsonPresentationFields.INVARIANT_UUID);
+ if(((String)component.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals(LifecycleStateEnum.CERTIFIED.name())){
+ latestCertifiedMap.put(invariantUUID, (String)component.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID));
+ } else {
+ latestNotCertifiedMap.put(invariantUUID, (String)component.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID));
+ }
+ }
+ result = Either.left(latestCertifiedMap.entrySet().stream().filter(e->!latestNotCertifiedMap.containsKey(e.getKey())).map(e->e.getValue()).collect(Collectors.toList()));
+ }
+ return result;
+ }
+
+ private Either<List<GraphVertex>, TitanOperationStatus> getAllLatestCertifiedComponents(VertexTypeEnum vertexType, ComponentTypeEnum componentType){
+
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+ propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+ if(vertexType == VertexTypeEnum.TOPOLOGY_TEMPLATE && componentType == ComponentTypeEnum.RESOURCE)
+ propertiesNotToMatch.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.CVFC.name());
+ return titanDao.getByCriteria(vertexType, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata);
+ }
+
+ protected Either<List<String>, TitanOperationStatus> findResourcesPathRecursively(GraphVertex nodeTypeV, List<String> allCertifiedUids) {
+ Either<List<GraphVertex>, TitanOperationStatus> parentResourceRes = titanDao.getParentVertecies(nodeTypeV, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseMetadata);
+ if(parentResourceRes.isRight()){
+ return Either.right(parentResourceRes.right().value());
+ }
+ List<GraphVertex> derivedResourcesUid = new ArrayList<>();
+ for(GraphVertex chV: parentResourceRes.left().value()){
+ Optional<String> op = allCertifiedUids.stream().filter(id -> id.equals((String)chV.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID))).findAny();
+ if(op.isPresent()){
+ derivedResourcesUid.add(chV);
+ }
+ }
+ return null;
+ }
+
+ private Either<List<GraphVertex>, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName){
+
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+
+ propertiesToMatch.put(property, nodeName);
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+
+ Either<List<GraphVertex>, TitanOperationStatus> highestResources = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata);
+ if (highestResources.isRight()) {
+ TitanOperationStatus status = highestResources.right().value();
+ LOGGER.debug("Failed to fetch resource with name {}. Status is {} ", nodeName, status);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+ List<GraphVertex> resources = highestResources.left().value();
+ List<GraphVertex> result = new ArrayList<>();
+ for(GraphVertex component:resources){
+ if(((String)component.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals(LifecycleStateEnum.CERTIFIED.name())){
+ result.add(component);
+ }
+ }
+ return Either.left(result);
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java
index 0ab863aa3e..898bd96177 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java
@@ -24,13 +24,11 @@ import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.Properties;
import java.util.Map.Entry;
+import java.util.Properties;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;