aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'asdctool/src/main')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/EsToCassandraDataMigrationConfig.java7
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java268
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration1707Task.java (renamed from asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration.java)6
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AppConfig.java57
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/Migration1702.java2
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/DistributionStatusUpdate.java140
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707.java15
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707Config.java101
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707RelationsFix.java131
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707VnfFix.java100
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/RenameGraphPropertyKeys.java6
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaNamesUpdate.java4
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java66
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/VfModulesPropertiesAdding.java108
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java39
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ConsumersMigration.java47
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/InvariantUUIDResolver.java41
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/JsonModelMigration.java20
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesMigration.java34
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourcesCategoriesMigration.java33
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceCategoriesMigration.java11
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServicesMigration.java121
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UserStatesMigration.java16
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UsersMigration.java12
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VFResourcesMigration.java2
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VersionMigration.java40
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java76
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java84
-rw-r--r--asdctool/src/main/resources/config/configuration.yaml4
-rw-r--r--asdctool/src/main/resources/config/groupTypes.yml15
-rw-r--r--asdctool/src/main/resources/config/logback.xml28
-rw-r--r--asdctool/src/main/resources/scripts/dataMigration1707.sh2
-rw-r--r--asdctool/src/main/resources/scripts/distributionStatusUpdate1707.sh35
-rw-r--r--asdctool/src/main/resources/scripts/migration1707RelationsFix.sh33
-rw-r--r--asdctool/src/main/resources/scripts/retrieve_schema_file.sh20
-rw-r--r--asdctool/src/main/resources/scripts/vfmoduleFix1707.sh35
36 files changed, 1219 insertions, 540 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/EsToCassandraDataMigrationConfig.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/EsToCassandraDataMigrationConfig.java
index 2c0471fb17..3242c27384 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/EsToCassandraDataMigrationConfig.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/EsToCassandraDataMigrationConfig.java
@@ -23,6 +23,7 @@ package org.openecomp.sdc.asdctool.impl;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraClient;
+import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -47,5 +48,9 @@ public class EsToCassandraDataMigrationConfig {
public CassandraClient cassandraClient() {
return new CassandraClient();
}
-
+
+ @Bean(name = "sdc-schema-files-cassandra-dao")
+ public SdcSchemaFilesCassandraDao sdcSchemaFilesCassandraDao() {
+ return new SdcSchemaFilesCassandraDao();
+ }
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java
index 3f63570ecd..ace1c038f2 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/TitanGraphInitializer.java
@@ -2,18 +2,14 @@ package org.openecomp.sdc.asdctool.impl;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.graph.datatype.ActionEnum;
import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.resources.data.UserData;
@@ -72,49 +68,28 @@ public class TitanGraphInitializer {
return false;
}
- private static void createDefaultUsers() {
- List<UserData> users = createUserList();
- for (UserData user : users) {
- Vertex vertex = null;
- Map<String, Object> checkedProperties = new HashMap<String, Object>();
- checkedProperties.put(GraphPropertiesDictionary.USERID.getProperty(), user.getUserId());
- checkedProperties.put(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.User.getName());
- Map<String, Object> properties = null;
- if (!isVertexExist(checkedProperties)) {
- vertex = graph.addVertex();
- vertex.property(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.User.getName());
- properties = user.toGraphMap();
- for (Map.Entry<String, Object> entry : properties.entrySet()) {
- vertex.property(entry.getKey(), entry.getValue());
- }
- }
- }
+ private static void createDefaultAdminUser() {
+ createUser(getDefaultUserAdmin());
graph.tx().commit();
}
- private static List<UserData> createUserList() {
- LinkedList<UserData> users = new LinkedList<UserData>();
- users.add(getDefaultUserAdmin1());
- users.add(getDefaultUserAdmin2());
- users.add(getDefaultUserDesigner1());
- users.add(getDefaultUserDesigner2());
- users.add(getDefaultUserTester1());
- users.add(getDefaultUserTester2());
- users.add(getDefaultUserTester3());
- users.add(getDefaultUserGovernor1());
- users.add(getDefaultUserGovernor2());
- users.add(getDefaultUserOps1());
- users.add(getDefaultUserOps2());
- users.add(getDefaultUserProductManager1());
- users.add(getDefaultUserProductManager2());
- users.add(getDefaultUserProductStrategist1());
- users.add(getDefaultUserProductStrategist2());
- users.add(getDefaultUserProductStrategist3());
- return users;
+ private static void createUser(UserData user) {
+ Map<String, Object> checkedProperties = new HashMap<>();
+ checkedProperties.put(GraphPropertiesDictionary.USERID.getProperty(), user.getUserId());
+ checkedProperties.put(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.User.getName());
+ Map<String, Object> properties = null;
+ if (!isVertexExist(checkedProperties)) {
+ Vertex vertex = graph.addVertex();
+ vertex.property(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.User.getName());
+ properties = user.toGraphMap();
+ for (Map.Entry<String, Object> entry : properties.entrySet()) {
+ vertex.property(entry.getKey(), entry.getValue());
+ }
+ }
}
- private static UserData getDefaultUserAdmin1() {
+ private static UserData getDefaultUserAdmin() {
UserData userData = new UserData();
userData.setAction(ActionEnum.Create);
userData.setElementType(GraphElementTypeEnum.Node);
@@ -128,215 +103,6 @@ public class TitanGraphInitializer {
return userData;
}
- private static UserData getDefaultUserAdmin2() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("tr0001");
- userData.setEmail("admin@sdc.com");
- userData.setFirstName("Todd");
- userData.setLastName("Rundgren");
- userData.setRole("ADMIN");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserDesigner1() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("cs0008");
- userData.setEmail("designer@sdc.com");
- userData.setFirstName("Carlos");
- userData.setLastName("Santana");
- userData.setRole("DESIGNER");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserDesigner2() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("me0009");
- userData.setEmail("designer@sdc.com");
- userData.setFirstName("Melissa");
- userData.setLastName("Etheridge");
- userData.setRole("DESIGNER");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserTester1() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("jm0007");
- userData.setEmail("tester@sdc.com");
- userData.setFirstName("Joni");
- userData.setLastName("Mitchell");
- userData.setRole("TESTER");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserTester2() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("kb0004");
- userData.setEmail("tester@sdc.com");
- userData.setFirstName("Kate");
- userData.setLastName("Bush");
- userData.setRole("TESTER");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserTester3() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("jt0005");
- userData.setEmail("tester@sdc.com");
- userData.setFirstName("James");
- userData.setLastName("Taylor");
- userData.setRole("TESTER");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserOps1() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("op0001");
- userData.setEmail("ops@sdc.com");
- userData.setFirstName("Steve");
- userData.setLastName("Regev");
- userData.setRole("OPS");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserOps2() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("af0006");
- userData.setEmail("designer@sdc.com");
- userData.setFirstName("Aretha");
- userData.setLastName("Franklin");
- userData.setRole("OPS");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserGovernor1() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("gv0001");
- userData.setEmail("governor@sdc.com");
- userData.setFirstName("David");
- userData.setLastName("Shadmi");
- userData.setRole("GOVERNOR");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserGovernor2() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("ah0002");
- userData.setEmail("admin@sdc.com");
- userData.setFirstName("Alex");
- userData.setLastName("Harvey");
- userData.setRole("GOVERNOR");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserProductManager1() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("pm0001");
- userData.setEmail("pm1@sdc.com");
- userData.setFirstName("Teddy");
- userData.setLastName("Isashar");
- userData.setRole("PRODUCT_MANAGER");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserProductManager2() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("pm0002");
- userData.setEmail("pm2@sdc.com");
- userData.setFirstName("Sarah");
- userData.setLastName("Bettens");
- userData.setRole("PRODUCT_MANAGER");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserProductStrategist1() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("ps0001");
- userData.setEmail("ps1@sdc.com");
- userData.setFirstName("Eden");
- userData.setLastName("Rozin");
- userData.setRole("PRODUCT_STRATEGIST");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserProductStrategist2() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("ps0002");
- userData.setEmail("ps2@sdc.com");
- userData.setFirstName("Ella");
- userData.setLastName("Kvetny");
- userData.setRole("PRODUCT_STRATEGIST");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
-
- private static UserData getDefaultUserProductStrategist3() {
- UserData userData = new UserData();
- userData.setAction(ActionEnum.Create);
- userData.setElementType(GraphElementTypeEnum.Node);
- userData.setUserId("ps0003");
- userData.setEmail("ps3@sdc.com");
- userData.setFirstName("Geva");
- userData.setLastName("Alon");
- userData.setRole("PRODUCT_STRATEGIST");
- userData.setStatus(UserStatusEnum.ACTIVE.name());
- userData.setLastLoginTime(0L);
- return userData;
- }
private static void createVertexIndixes() {
logger.info("** createVertexIndixes started");
@@ -399,6 +165,6 @@ public class TitanGraphInitializer {
private static void createIndexesAndDefaults() {
createVertexIndixes();
createEdgeIndixes();
- createDefaultUsers();
+ createDefaultAdminUser();
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration1707Task.java
index d74bae6087..92e185dbd7 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration1707Task.java
@@ -1,6 +1,10 @@
package org.openecomp.sdc.asdctool.impl.migration;
-public interface Migration {
+/**
+ * for 1707 migration only!!!
+ * please don't implement this interface unless you are sure you want to run with 1707 migration classes
+ */
+public interface Migration1707Task {
/**
* performs a migration operation
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AppConfig.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AppConfig.java
index 514c28b9b1..25132caf28 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AppConfig.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AppConfig.java
@@ -27,9 +27,11 @@ import org.openecomp.sdc.asdctool.impl.migration.v1610.TitanFixUtils;
import org.openecomp.sdc.asdctool.impl.migration.v1610.ToscaArtifactsAlignment;
import org.openecomp.sdc.asdctool.impl.migration.v1702.DataTypesUpdate;
import org.openecomp.sdc.asdctool.impl.migration.v1702.Migration1702;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.VfModulesPropertiesAdding;
+import org.openecomp.sdc.asdctool.impl.migration.v1707.Migration1707RelationsFix;
+import org.openecomp.sdc.asdctool.impl.migration.v1707.Migration1707VnfFix;
import org.openecomp.sdc.be.auditing.api.IAuditingManager;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.ArtifactsResolver;
import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
import org.openecomp.sdc.be.components.impl.*;
@@ -51,7 +53,32 @@ import org.openecomp.sdc.be.model.operations.api.IAdditionalInformationOperation
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
-import org.openecomp.sdc.be.model.operations.impl.*;
+import org.openecomp.sdc.be.model.operations.impl.AdditionalInformationOperation;
+import org.openecomp.sdc.be.model.operations.impl.ArtifactOperation;
+import org.openecomp.sdc.be.model.operations.impl.AttributeOperation;
+import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityInstanceOperation;
+import org.openecomp.sdc.be.model.operations.impl.CapabilityOperation;
+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.ConsumerOperation;
+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.HeatParametersOperation;
+import org.openecomp.sdc.be.model.operations.impl.InputsOperation;
+import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.LifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.OnboardingClient;
+import org.openecomp.sdc.be.model.operations.impl.ProductOperation;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.model.operations.impl.RequirementOperation;
+import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
+import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
+import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation;
import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
import org.openecomp.sdc.be.user.IUserBusinessLogic;
@@ -66,6 +93,11 @@ import org.springframework.context.annotation.Primary;
@Import(DAOSpringConfig.class)
public class AppConfig {
+ @Bean(name="artifact-resolver")
+ public ArtifactsResolver artifactsResolver() {
+ return new ArtifactResolverImpl();
+ }
+
@Bean(name = "sdc-schema-files-cassandra-dao")
public SdcSchemaFilesCassandraDao sdcSchemaFilesCassandraDao() {
return new SdcSchemaFilesCassandraDao();
@@ -543,9 +575,22 @@ public class AppConfig {
return new MigrationOperationUtils();
}
- @Bean(name = "vfModulesPropertiesAdding")
- public VfModulesPropertiesAdding vfModulesPropertiesAdding() {
- return new VfModulesPropertiesAdding();
- }
+ @Bean("consumer-operation")
+ public ConsumerOperation consumerOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
+ return new ConsumerOperation(titanGenericDao);
+ }
+ @Bean(name = "migration1707relationsFix")
+ public Migration1707RelationsFix migration1707RelationsFix() {
+ return new Migration1707RelationsFix();
+ }
+ @Bean(name = "migration1707vnfFix")
+ public Migration1707VnfFix migration1707VnfFix() {
+ return new Migration1707VnfFix();
+ }
+
+// @Bean(name = "migration1707relationsFix")
+// public Migration1707RelationsFix migration1707RelationsFix() {
+// return new Migration1707RelationsFix();
+// }
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/Migration1702.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/Migration1702.java
index 861e9136a3..6fa8b45734 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/Migration1702.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/Migration1702.java
@@ -1036,10 +1036,8 @@ public class Migration1702 {
property.setName(fe.getKey());
Map<String, Object> definitionInYaml = (Map<String, Object>) fe.getValue();
property.setType((String) definitionInYaml.get("type"));
- // Fix by Tal G
property.setRequired((Boolean) definitionInYaml.get("required"));
property.setDescription((String) definitionInYaml.get("description"));
- // Fix by Tal G
String defaultValue = definitionInYaml.get("default") == null ? null : definitionInYaml.get("default").toString();
if (defaultValue != null) {
property.setDefaultValue(defaultValue);
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/DistributionStatusUpdate.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/DistributionStatusUpdate.java
new file mode 100644
index 0000000000..7c0b57fb1d
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/DistributionStatusUpdate.java
@@ -0,0 +1,140 @@
+package org.openecomp.sdc.asdctool.impl.migration.v1707;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.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.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+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("distributionStatusUpdate")
+public class DistributionStatusUpdate {
+ private static Logger LOGGER = LoggerFactory.getLogger(DistributionStatusUpdate.class);
+
+ @Autowired
+ private ToscaOperationFacade toscaOperationFacade;
+ @Autowired
+ private TitanDao titanDao;
+
+
+ public boolean migrate() {
+ boolean result = true;
+ Either<Map<GraphVertex, org.openecomp.sdc.be.model.Service>, StorageOperationStatus> getAllServiceComponentsRes = getAllServiceComponents();
+ if(getAllServiceComponentsRes.isRight()){
+ result = false;
+ }
+ if(result && MapUtils.isNotEmpty(getAllServiceComponentsRes.left().value())){
+ updateDistributionStatusFromMetadata(getAllServiceComponentsRes.left().value());
+ updateDistributionStatusToNotDistributed(getAllServiceComponentsRes.left().value());
+ }
+
+ toscaOperationFacade.commit();
+
+ return result;
+ }
+
+
+ private void updateDistributionStatusToNotDistributed(Map<GraphVertex, org.openecomp.sdc.be.model.Service> components) {
+
+ Map<GraphVertex, org.openecomp.sdc.be.model.Service> filteredComponents = components.entrySet()
+ .stream()
+ .filter(e -> e.getValue().getLifecycleState() != LifecycleStateEnum.CERTIFIED)
+ .collect(Collectors.toMap(e -> e.getKey(), e -> (Service)e.getValue()));
+
+ Service service;
+ Either<GraphVertex, TitanOperationStatus> updateResponse;
+ GraphVertex metadataV;
+
+ for(Entry<GraphVertex, Service> currComponent : filteredComponents.entrySet()){
+ metadataV = currComponent.getKey();
+ service = currComponent.getValue();
+ try {
+ metadataV.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED.name());
+ updateResponse = titanDao.updateVertex(metadataV);
+
+ if (updateResponse.isRight()) {
+ LOGGER.debug("failed to updateDistributionStatusToNotDistributed service {} error {}", service.getUniqueId(), updateResponse.right().value());
+ }
+
+ } catch (Exception e) {
+ LOGGER.debug("failed to updateDistributionStatusToNotDistributed service {} error {}", service.getUniqueId(), e.toString());
+ }
+ }
+ }
+
+ private void updateDistributionStatusFromMetadata(Map<GraphVertex, org.openecomp.sdc.be.model.Service> components) {
+ Service service;
+ String statusFromMetadata;
+ Either<GraphVertex, TitanOperationStatus> updateResponse;
+ GraphVertex metadataV;
+
+ for(Entry<GraphVertex, Service> currComponent : components.entrySet()){
+ metadataV = currComponent.getKey();
+ service = currComponent.getValue();
+ try {
+ statusFromMetadata = (String) metadataV.getJsonMetadataField(JsonPresentationFields.DISTRIBUTION_STATUS);
+ metadataV.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, statusFromMetadata);
+ updateResponse = titanDao.updateVertex(metadataV);
+
+ if (updateResponse.isRight()) {
+ LOGGER.debug("failed to updateDistributionStatusFromMetadata service {} error {}", service.getUniqueId(), updateResponse.right().value());
+ }
+
+ } catch (Exception e) {
+ LOGGER.debug("failed to read distribution status of service {} error {}", service.getUniqueId(), e.toString());
+ }
+
+ }
+ }
+
+
+ public Either<Map<GraphVertex, org.openecomp.sdc.be.model.Service>, StorageOperationStatus> getAllServiceComponents() {
+
+ Map<GraphVertex, org.openecomp.sdc.be.model.Service> components = new HashMap<>();
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> propertiesNotMatch = new EnumMap<>(GraphPropertyEnum.class);
+ propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ propertiesNotMatch.put(GraphPropertyEnum.IS_DELETED, true);
+ Either<List<GraphVertex>, TitanOperationStatus> getVerticiesRes = toscaOperationFacade.getTitanDao().getByCriteria(null, propertiesToMatch, propertiesNotMatch, JsonParseFlagEnum.ParseAll);
+
+ if (getVerticiesRes.isRight() && getVerticiesRes.right().value() != TitanOperationStatus.NOT_FOUND) {
+ LOGGER.debug("Failed to fetch all service components. Status is {}", getVerticiesRes.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVerticiesRes.right().value()));
+ }
+ if(getVerticiesRes.isLeft()){
+ List<GraphVertex> componentVerticies = getVerticiesRes.left().value();
+ for (GraphVertex componentV : componentVerticies) {
+ ComponentParametersView filters = new ComponentParametersView(true);
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentsRes = toscaOperationFacade.getToscaElement(componentV.getUniqueId(), filters);
+ if (getComponentsRes.isRight()) {
+ return Either.right(getComponentsRes.right().value());
+ }
+ components.put(componentV, (Service) getComponentsRes.left().value());
+ }
+ }
+ return Either.left(components);
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707.java
index be40e4cd0d..84214cc0b0 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707.java
@@ -1,27 +1,29 @@
package org.openecomp.sdc.asdctool.impl.migration.v1707;
-import org.openecomp.sdc.asdctool.impl.migration.Migration;
+import org.openecomp.sdc.asdctool.impl.migration.Migration1707Task;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import javax.annotation.Resource;
import java.util.List;
+import java.util.Optional;
@Component("migration1707")
public class Migration1707 {
private static Logger LOGGER = LoggerFactory.getLogger(Migration1707.class);
- private List<Migration> migrations;
+ private List<Migration1707Task> migrations;
- public Migration1707(List<Migration> migrations) {
+ public Migration1707(List<Migration1707Task> migrations) {
this.migrations = migrations;
}
public boolean migrate() {
- for (Migration migration : migrations) {
+ int startMigrationFrom = Optional.ofNullable(ConfigurationManager.getConfigurationManager().getConfiguration().getStartMigrationFrom()).orElse(0);
+ List<Migration1707Task> migrations = this.migrations.subList(startMigrationFrom, this.migrations.size());
+ for (Migration1707Task migration : migrations) {
LOGGER.info(String.format("Starting migration. %s", migration.description()));
boolean migrationCompletedSuccessfully = migration.migrate();
if (!migrationCompletedSuccessfully) {
@@ -33,5 +35,4 @@ public class Migration1707 {
return true;
}
-
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707Config.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707Config.java
index 9c39b58404..eeb29d67c2 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707Config.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707Config.java
@@ -3,19 +3,8 @@ package org.openecomp.sdc.asdctool.impl.migration.v1707;
import java.util.List;
-import org.openecomp.sdc.asdctool.impl.migration.Migration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.MigrationByIdDerivedNodeTypeResolver;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.NormativesMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.NormativesResolver;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.ResourceVersionMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.ResourcesCategoriesMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.ServiceCategoriesMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.ServiceVersionMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.ServicesMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.UserStatesMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.UsersMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.VFResourcesMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.VersionMigration;
+import org.openecomp.sdc.asdctool.impl.migration.Migration1707Task;
+import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.*;
import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations.FulfilledCapabilitiesMigrationService;
import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations.FulfilledRequirementsMigrationService;
import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations.RequirementsCapabilitiesMigrationService;
@@ -37,6 +26,7 @@ import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
import org.openecomp.sdc.be.model.operations.api.ToscaDefinitionPathCalculator;
+import org.openecomp.sdc.be.model.operations.impl.ConsumerOperation;
import org.openecomp.sdc.be.model.operations.impl.ElementOperation;
import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
@@ -45,6 +35,7 @@ import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;
@Configuration
@@ -52,69 +43,72 @@ public class Migration1707Config {
@Bean(name = "migration1707")
- public Migration1707 migration1707(List<Migration> migrations) {
+ public Migration1707 migration1707(List<Migration1707Task> migrations) {
return new Migration1707(migrations);
}
- @Bean(name = "renameGraphPropertyKeysMigration")
- @Order(1)
- public Migration renameGraphPropertyKeysMigration() {
- return new RenameGraphPropertyKeys();
- }
+ //@Bean(name = "renameGraphPropertyKeysMigration")
+ //@Order(1)
+ //public Migration1707Task renameGraphPropertyKeysMigration() {
+ // return new RenameGraphPropertyKeys();
+ // }
- @Bean(name = "toscaNamesUpdate")
- @Order(2)
- public Migration toscaNamesUpdate() {
- return new ToscaNamesUpdate();
- }
+ //@Bean(name = "toscaNamesUpdate")
+ //@Order(2)
+ //public Migration1707Task toscaNamesUpdate() {
+ // return new ToscaNamesUpdate();
+ //}
@Bean(name = "users-migration")
- @Order(3)
- public Migration usersMigration() {
+ @Order(1)
+ public Migration1707Task usersMigration() {
return new UsersMigration();
}
@Bean(name = "resource-category-migration")
- @Order(4)
- public Migration resourceCategoriesMigration() {
+ @Order(2)
+ public Migration1707Task resourceCategoriesMigration() {
return new ResourcesCategoriesMigration();
}
@Bean(name = "service-category-migration")
- @Order(5)
- public Migration serviceCategoriesMigration() {
+ @Order(3)
+ public Migration1707Task serviceCategoriesMigration() {
return new ServiceCategoriesMigration();
}
@Bean(name = "normatives-migration")
- @Order(6)
- public Migration normativesMigration() {
+ @Order(4)
+ public Migration1707Task normativesMigration() {
return new NormativesMigration();
}
@Bean(name = "vf-migration")
- @Order(7)
- public Migration vfMigration() {
+ @Order(5)
+ public Migration1707Task vfMigration() {
return new VFResourcesMigration();
}
@Bean(name = "service-migration")
- @Order(8)
- public Migration serviceMigration() {
+ @Order(6)
+ public Migration1707Task serviceMigration() {
return new ServicesMigration();
}
- @Bean(name = "user-states-migration")
- @Order(9)
- public Migration userStatesMigration() {
- return new UserStatesMigration();
+ @Bean(name = "consumers-migration")
+ @Order(7)
+ public Migration1707Task consumersMigration() { return new ConsumersMigration(); }
+
+ @Bean(name = "tosca-template-regeneration")
+ @Order(8)
+ public Migration1707Task ToscaTemplateRegeneration() {
+ return new ToscaTemplateRegeneration();
+ }
+
+ @Bean(name = "distributionStatusUpdate")
+ public DistributionStatusUpdate distributionStatusUpdate() {
+ return new DistributionStatusUpdate();
}
-
-// @Bean(name = "tosca-template-regeneration")
-// @Order(10)
-// public Migration ToscaTemplateRegeneration() {
-// return new ToscaTemplateRegeneration();
-// }
@Bean("resource-version-migration")
public VersionMigration<Resource> resourceVersionMigration() {
@@ -236,5 +230,20 @@ public class Migration1707Config {
return new MigrationByIdDerivedNodeTypeResolver();
}
+ @Bean(name = "invariant-uuid-resolver")
+ public InvariantUUIDResolver invariantUUIDResolver() {
+ return new InvariantUUIDResolver();
+ }
+
+ @Bean(name="consumer-operation-mig")
+ @Primary
+ public ConsumerOperation consumerOperation(@Qualifier("titan-generic-dao-migration") TitanGenericDao titanGenericDao) {
+ return new ConsumerOperation(titanGenericDao);
+ }
+
+ @Bean(name = "vfModulesPropertiesAdding")
+ public VfModulesPropertiesAdding vfModulesPropertiesAdding() {
+ return new VfModulesPropertiesAdding();
+ }
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707RelationsFix.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707RelationsFix.java
new file mode 100644
index 0000000000..47bce78893
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707RelationsFix.java
@@ -0,0 +1,131 @@
+package org.openecomp.sdc.asdctool.impl.migration.v1707;
+
+import java.util.EnumMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+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.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+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("migration1707relationsFix")
+public class Migration1707RelationsFix {
+
+ private static Logger LOGGER = LoggerFactory.getLogger(Migration1707RelationsFix.class);
+
+ @Autowired
+ private TitanDao titanDao;
+
+ public boolean migrate() {
+ boolean result = true;
+
+ try{
+ Map<GraphPropertyEnum, Object> propsHasNot = new EnumMap<>(GraphPropertyEnum.class);
+ propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
+ Either<List<GraphVertex>, TitanOperationStatus> getAllTopologyTemplatesRes = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, null, propsHasNot, JsonParseFlagEnum.ParseMetadata);
+ if (getAllTopologyTemplatesRes.isRight() && getAllTopologyTemplatesRes.right().value() != TitanOperationStatus.NOT_FOUND) {
+ LOGGER.debug("Failed to fetch all non marked as deleted topology templates , error {}", getAllTopologyTemplatesRes.right().value());
+ result = false;
+ }
+ if(getAllTopologyTemplatesRes.isLeft()){
+ fixComponentsRelations(getAllTopologyTemplatesRes.left().value());
+ }
+ if(result){
+ Either<List<GraphVertex>, TitanOperationStatus> getAllNodeTypesRes = titanDao.getByCriteria(VertexTypeEnum.NODE_TYPE, null, propsHasNot, JsonParseFlagEnum.ParseMetadata);
+ if (getAllNodeTypesRes.isRight() && getAllNodeTypesRes.right().value() != TitanOperationStatus.NOT_FOUND) {
+ LOGGER.debug("Failed to fetch all non marked as deleted node types , error {}", getAllNodeTypesRes.right().value());
+ result = false;
+ }
+ if(getAllNodeTypesRes.isLeft()){
+ fixComponentsRelations(getAllNodeTypesRes.left().value());
+ }
+ }
+ } catch (Exception e){
+ LOGGER.debug("The exception {} occured upon migration 1707 relations fixing. ", e.getMessage());
+ e.printStackTrace();
+ result = false;
+ }
+ finally{
+ if(result){
+ titanDao.commit();
+ } else {
+ titanDao.rollback();
+ }
+ }
+ return result;
+ }
+
+ private void fixComponentsRelations(List<GraphVertex> notDeletedComponentVerticies) {
+ notDeletedComponentVerticies.stream().forEach(this::fixComponentRelations);
+ }
+
+ private void fixComponentRelations(GraphVertex componentV) {
+ fixCreatorComponentRelation(componentV);
+ fixLastModifierComponentRelation(componentV);
+ fixStateComponentRelation(componentV);
+ }
+
+ private void fixStateComponentRelation(GraphVertex componentV) {
+ boolean relevantEdgeFound = false;
+ Iterator<Edge> edges = componentV.getVertex().edges(Direction.IN, EdgeLabelEnum.STATE.name());
+ String getState = (String) componentV.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE);
+ while(edges.hasNext()){
+ Edge edge = edges.next();
+ String edgeState = (String) edge.property(GraphPropertyEnum.STATE.getProperty()).orElse(null);
+ if(getState.equals(edgeState) && !relevantEdgeFound){
+ relevantEdgeFound = true;
+ } else {
+ removeEdge(edge);
+ }
+ }
+ }
+
+ private void fixCreatorComponentRelation(GraphVertex componentV) {
+ boolean relevantUserFound = false;
+ Iterator<Edge> edges = componentV.getVertex().edges(Direction.IN, EdgeLabelEnum.CREATOR.name());
+ String getCreatorUserId = (String) componentV.getJsonMetadataField(JsonPresentationFields.USER_ID_CREATOR);
+ while(edges.hasNext()){
+ Edge edge = edges.next();
+ String userId = (String) edge.outVertex().property(GraphPropertyEnum.USERID.getProperty()).orElse(null);
+ if(getCreatorUserId.equals(userId) && !relevantUserFound){
+ relevantUserFound = true;
+ } else {
+ removeEdge(edge);
+ }
+ }
+ }
+
+ private void fixLastModifierComponentRelation(GraphVertex componentV) {
+ boolean relevantUserFound = false;
+ Iterator<Edge> edges = componentV.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_MODIFIER.name());
+ String getLastUpdaterUserId = (String) componentV.getJsonMetadataField(JsonPresentationFields.USER_ID_LAST_UPDATER);
+ while(edges.hasNext()){
+ Edge edge = edges.next();
+ String updaterId = (String) edge.outVertex().property(GraphPropertyEnum.USERID.getProperty()).orElse(null);
+ if(getLastUpdaterUserId.equals(updaterId) && !relevantUserFound){
+ relevantUserFound = true;
+ } else {
+ removeEdge(edge);
+ }
+ }
+ }
+
+ private void removeEdge(Edge edge) {
+ LOGGER.debug("Going to remove edge {} upon migration 1707 relations fixing. ", edge.id());
+ edge.remove();
+ LOGGER.debug("The edge {} has been removed. ", edge.id());
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707VnfFix.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707VnfFix.java
new file mode 100644
index 0000000000..d3bd494a85
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707VnfFix.java
@@ -0,0 +1,100 @@
+package org.openecomp.sdc.asdctool.impl.migration.v1707;
+
+import java.util.EnumMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+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.jsongraph.utils.JsonParserUtils;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+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.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.thinkaurelius.titan.core.TitanVertex;
+
+import fj.data.Either;
+
+@Component("migration1707vnfFix")
+public class Migration1707VnfFix{
+
+ private static final String VF_MODULES_METADATA = "vfModulesMetadata";
+
+ @Autowired
+ private TitanDao titanDao;
+
+ @Autowired
+ private TopologyTemplateOperation topologyTemplateOperation;
+
+ private static Logger LOGGER = LoggerFactory.getLogger(Migration1707RelationsFix.class);
+
+ public boolean migrate() {
+ boolean result = true;
+
+ Map<GraphPropertyEnum, Object> propsHasNot = new EnumMap<>(GraphPropertyEnum.class);
+ propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
+
+ Map<GraphPropertyEnum, Object> propsHas = new EnumMap<>(GraphPropertyEnum.class);
+ propsHas.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ propsHas.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF.name());
+ propsHas.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED);
+
+ Either<List<GraphVertex>, TitanOperationStatus> getAllTopologyTemplatesRes = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, null, propsHasNot, JsonParseFlagEnum.ParseMetadata);
+ if (getAllTopologyTemplatesRes.isRight() && getAllTopologyTemplatesRes.right().value() != TitanOperationStatus.NOT_FOUND) {
+ LOGGER.debug("Failed to fetch all non marked as deleted topology templates , error {}", getAllTopologyTemplatesRes.right().value());
+ result = false;
+ }
+ List<GraphVertex> metadataVertices = getAllTopologyTemplatesRes.left().value();
+ for (GraphVertex metadataV : metadataVertices) {
+ Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> dataFromGraph = topologyTemplateOperation.getDataFromGraph(metadataV.getUniqueId(), EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
+ if (dataFromGraph.isLeft()) {
+ Map<String, ArtifactDataDefinition> artifacts = dataFromGraph.left().value();
+ if (artifacts.containsKey(VF_MODULES_METADATA)) {
+ artifacts.remove(VF_MODULES_METADATA);
+ Either<GraphVertex, TitanOperationStatus> vertexById = titanDao.getVertexById(metadataV.getUniqueId());
+ TitanVertex vertex = vertexById.left().value().getVertex();
+ Iterator<Edge> edges = vertex.edges(Direction.OUT, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS.name());
+ if (edges.hasNext()) {
+ Edge edge = edges.next();
+ Vertex dataV = edge.inVertex();
+
+ String jsonStr;
+ try {
+ jsonStr = JsonParserUtils.jsonToString(artifacts);
+ dataV.property(GraphPropertyEnum.JSON.getProperty(), jsonStr);
+ } catch (Exception e) {
+ LOGGER.debug("Failed to update deployment artifacts for VF {}", metadataV.getUniqueId());
+ }
+ }
+ }
+ }
+ TitanOperationStatus commit = titanDao.commit();
+ if ( commit != TitanOperationStatus.OK){
+ LOGGER.debug("Failed to commit changes for deployment artifacts for VF {} {}", metadataV.getUniqueId(), metadataV.getMetadataProperty(GraphPropertyEnum.NAME));
+ }
+ }
+
+ return result;
+ }
+
+ public String description() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/RenameGraphPropertyKeys.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/RenameGraphPropertyKeys.java
index a69fb9d011..a1c1b6b4cc 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/RenameGraphPropertyKeys.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/RenameGraphPropertyKeys.java
@@ -1,8 +1,6 @@
package org.openecomp.sdc.asdctool.impl.migration.v1707;
-import org.openecomp.sdc.asdctool.impl.migration.MigrationMsg;
-import org.openecomp.sdc.asdctool.impl.migration.Migration;
-import org.openecomp.sdc.asdctool.impl.migration.MigrationOperationUtils;
+import org.openecomp.sdc.asdctool.impl.migration.*;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -11,7 +9,7 @@ import java.util.HashMap;
import java.util.Map;
@Component("renameGraphPropertyKeysMigration")
-public class RenameGraphPropertyKeys implements Migration {
+public class RenameGraphPropertyKeys implements Migration1707Task {
private final static Map<String, String> KEY_PROPERTIES_TO_RENAME;
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaNamesUpdate.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaNamesUpdate.java
index 262c300009..5213fae619 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaNamesUpdate.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaNamesUpdate.java
@@ -8,7 +8,7 @@ import java.util.function.Function;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.openecomp.sdc.asdctool.impl.migration.Migration;
+import org.openecomp.sdc.asdctool.impl.migration.Migration1707Task;
import org.openecomp.sdc.be.dao.graph.GraphElementFactory;
import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
@@ -46,7 +46,7 @@ import com.thinkaurelius.titan.core.TitanVertex;
import fj.data.Either;
@Component("toscaNamesUpdate")
-public class ToscaNamesUpdate implements Migration {
+public class ToscaNamesUpdate implements Migration1707Task {
private static Logger log = LoggerFactory.getLogger(ToscaNamesUpdate.class.getName());
@Override
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java
index 824bb83ec9..09e52619f0 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java
@@ -1,14 +1,11 @@
package org.openecomp.sdc.asdctool.impl.migration.v1707;
import java.util.EnumMap;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-import org.apache.commons.collections.MapUtils;
-import org.openecomp.sdc.asdctool.impl.migration.Migration;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.asdctool.impl.migration.Migration1707Task;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
@@ -34,7 +31,7 @@ import org.springframework.stereotype.Component;
import fj.data.Either;
@Component("toscaTemplateRegeneration")
-public class ToscaTemplateRegeneration implements Migration {
+public class ToscaTemplateRegeneration implements Migration1707Task {
private static Logger LOGGER = LoggerFactory.getLogger(ToscaTemplateRegeneration.class);
@@ -50,13 +47,13 @@ public class ToscaTemplateRegeneration implements Migration {
@Override
public boolean migrate() {
boolean result = true;
- Either<Map<GraphVertex, org.openecomp.sdc.be.model.Component>, StorageOperationStatus> getAllCertifiedComponentsRes;
+ Either<List<GraphVertex>, StorageOperationStatus> getAllCertifiedComponentsRes;
try{
getAllCertifiedComponentsRes = getAllCertifiedComponents();
if(getAllCertifiedComponentsRes.isRight()){
result = false;
}
- if(result && MapUtils.isNotEmpty(getAllCertifiedComponentsRes.left().value())){
+ if(result && CollectionUtils.isNotEmpty(getAllCertifiedComponentsRes.left().value())){
result = regenerateToscaTemplateArtifacts(getAllCertifiedComponentsRes.left().value());
}
} catch(Exception e){
@@ -72,17 +69,21 @@ public class ToscaTemplateRegeneration implements Migration {
return result;
}
- private boolean regenerateToscaTemplateArtifacts(Map<GraphVertex, org.openecomp.sdc.be.model.Component> components) {
+ private boolean regenerateToscaTemplateArtifacts(List<GraphVertex> components) {
boolean result = true;
-
- Map<GraphVertex, org.openecomp.sdc.be.model.Component> filteredComponents = components.entrySet()
- .stream()
- .filter(e -> e.getValue().getToscaArtifacts()!=null && e.getValue().getToscaArtifacts().containsKey(ToscaExportHandler.ASSET_TOSCA_TEMPLATE))
- .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
-
- for(Entry<GraphVertex, org.openecomp.sdc.be.model.Component> currComponent : filteredComponents.entrySet()){
- result = regenerateToscaTemplateArtifact(currComponent);
- if(!result){
+ for(GraphVertex componentV : components){
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentsRes = toscaOperationFacade.getToscaElement(componentV);
+ if (getComponentsRes.isRight()) {
+ result = false;
+ break;
+ }
+ if(getComponentsRes.left().value().getToscaArtifacts()!=null && getComponentsRes.left().value().getToscaArtifacts().containsKey(ToscaExportHandler.ASSET_TOSCA_TEMPLATE)){
+ result = regenerateToscaTemplateArtifact(getComponentsRes.left().value(), componentV);
+ }
+ if(result){
+ toscaOperationFacade.commit();
+ } else {
+ toscaOperationFacade.rollback();
break;
}
}
@@ -90,26 +91,26 @@ public class ToscaTemplateRegeneration implements Migration {
}
@SuppressWarnings("unchecked")
- private boolean regenerateToscaTemplateArtifact(Map.Entry<GraphVertex, org.openecomp.sdc.be.model.Component> parent) {
+ private boolean regenerateToscaTemplateArtifact(org.openecomp.sdc.be.model.Component parent, GraphVertex parentV) {
boolean result = true;
Either<GraphVertex, TitanOperationStatus> toscaDataVertexRes = null;
ArtifactDataDefinition data = null;
LOGGER.debug("tosca artifact generation");
- Either<ToscaRepresentation, ToscaError> exportComponent = toscaExportUtils.exportComponent(parent.getValue());
+ Either<ToscaRepresentation, ToscaError> exportComponent = toscaExportUtils.exportComponent(parent);
if (exportComponent.isRight()) {
- LOGGER.debug("Failed export tosca yaml for component {} error {}", parent.getValue().getUniqueId(), exportComponent.right().value());
+ LOGGER.debug("Failed export tosca yaml for component {} error {}", parent.getUniqueId(), exportComponent.right().value());
result = false;
}
if(result){
- LOGGER.debug("Tosca yaml exported for component {} ", parent.getValue().getUniqueId());
- toscaDataVertexRes = toscaOperationFacade.getTitanDao().getChildVertex(parent.getKey(), EdgeLabelEnum.TOSCA_ARTIFACTS, JsonParseFlagEnum.ParseJson);
+ LOGGER.debug("Tosca yaml exported for component {} ", parent.getUniqueId());
+ toscaDataVertexRes = toscaOperationFacade.getTitanDao().getChildVertex(parentV, EdgeLabelEnum.TOSCA_ARTIFACTS, JsonParseFlagEnum.ParseJson);
if(toscaDataVertexRes.isRight()){
- LOGGER.debug("Failed to fetch tosca data vertex {} for component {}. Status is {}", EdgeLabelEnum.TOSCA_ARTIFACTS, parent.getValue().getUniqueId(), exportComponent.right().value());
+ LOGGER.debug("Failed to fetch tosca data vertex {} for component {}. Status is {}", EdgeLabelEnum.TOSCA_ARTIFACTS, parent.getUniqueId(), exportComponent.right().value());
result = false;
}
}
if(result){
- data = parent.getValue().getToscaArtifacts().get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+ data = parent.getToscaArtifacts().get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
data.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(exportComponent.left().value().getMainYaml().getBytes()));
((Map<String, ArtifactDataDefinition>) toscaDataVertexRes.left().value().getJson()).put(ToscaExportHandler.ASSET_TOSCA_TEMPLATE, data);
@@ -129,26 +130,19 @@ public class ToscaTemplateRegeneration implements Migration {
return result;
}
- public Either<Map<GraphVertex, org.openecomp.sdc.be.model.Component>, StorageOperationStatus> getAllCertifiedComponents() {
+ public Either<List<GraphVertex>, StorageOperationStatus> getAllCertifiedComponents() {
- Map<GraphVertex, org.openecomp.sdc.be.model.Component> components = new HashMap<>();
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- Either<List<GraphVertex>, TitanOperationStatus> getVerticiesRes = toscaOperationFacade.getTitanDao().getByCriteria(null, propertiesToMatch,JsonParseFlagEnum.ParseAll);
+ List<GraphVertex> components = null;
+ Either<List<GraphVertex>, TitanOperationStatus> getVerticiesRes = toscaOperationFacade.getTitanDao().getByCriteria(null, propertiesToMatch,JsonParseFlagEnum.ParseMetadata);
if (getVerticiesRes.isRight() && getVerticiesRes.right().value() != TitanOperationStatus.NOT_FOUND) {
LOGGER.debug("Failed to fetch all certified components. Status is {}", getVerticiesRes.right().value());
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVerticiesRes.right().value()));
}
if(getVerticiesRes.isLeft()){
- List<GraphVertex> componentVerticies = getVerticiesRes.left().value();
- for (GraphVertex componentV : componentVerticies) {
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentsRes = toscaOperationFacade.getToscaElement(componentV);
- if (getComponentsRes.isRight()) {
- return Either.right(getComponentsRes.right().value());
- }
- components.put(componentV, getComponentsRes.left().value());
- }
+ components = getVerticiesRes.left().value();
}
return Either.left(components);
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/VfModulesPropertiesAdding.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/VfModulesPropertiesAdding.java
index 5b1441903f..ca1ed2b2a8 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/VfModulesPropertiesAdding.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/VfModulesPropertiesAdding.java
@@ -13,10 +13,12 @@ import javax.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.asdctool.impl.migration.v1702.DataTypesUpdate;
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.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -45,7 +47,7 @@ import fj.data.Either;
@Component("vfModulesPropertiesAdding")
public class VfModulesPropertiesAdding {
- private static Logger LOGGER = LoggerFactory.getLogger(ToscaTemplateRegeneration.class);
+ private static Logger LOGGER = LoggerFactory.getLogger(VfModulesPropertiesAdding.class);
@Autowired
private ToscaOperationFacade toscaOperationFacade;
@@ -61,25 +63,35 @@ public class VfModulesPropertiesAdding {
public boolean migrate(String groupsTypeYmlFilePath) {
+ LOGGER.debug("Going to add new properties to vfModules. ");
boolean result = true;
- Either<Map<org.openecomp.sdc.be.model.Component, GraphVertex>, StorageOperationStatus> getAllComponentsRes = null;
GroupTypeDefinition vfModule;
Either<List<GraphVertex>, TitanOperationStatus> getAllTopologyTemplatesRes = null;
- List<PropertyDefinition> newProperties = null;
-
+ String vfModuleUid = "org.openecomp.groups.VfModule.1.0.grouptype";
Either<GroupTypeDefinition, TitanOperationStatus> getGroupTypeVfModuleRes ;
+ List<PropertyDefinition> updatedProperties = null;
try{
- getGroupTypeVfModuleRes = groupTypeOperation.getGroupTypeByUid("org.openecomp.groups.VfModule.1.0.grouptype");
+ LOGGER.debug("Going to fetch {}. ", vfModuleUid);
+ getGroupTypeVfModuleRes = groupTypeOperation.getGroupTypeByUid(vfModuleUid);
- if(getGroupTypeVfModuleRes.isRight()){
- result = false;
+ if(getGroupTypeVfModuleRes.isRight() && getGroupTypeVfModuleRes.right().value() != TitanOperationStatus.NOT_FOUND){
+ LOGGER.debug("Failed to fetch the group type {}. The status is {}. ", vfModuleUid, getGroupTypeVfModuleRes.right().value());
+ result = false;
+ }
+ if(getGroupTypeVfModuleRes.isRight() && getGroupTypeVfModuleRes.right().value() == TitanOperationStatus.NOT_FOUND){
+ LOGGER.debug("The group type with id {} was not found. Skipping adding the new properties. ", vfModuleUid);
+ return true;
}
if(result){
+ LOGGER.debug("Going to add the new properties {} to org.openecomp.groups.VfModule.1.0.grouptype. ");
vfModule = getGroupTypeVfModuleRes.left().value();
- newProperties = getNewVfModuleTypeProperties(getAllVfModuleTypePropertiesFromYaml(groupsTypeYmlFilePath), vfModule);
- result = addNewPropertiesToGroupType(vfModule, newProperties);
+ updatedProperties = getAllVfModuleTypePropertiesFromYaml(groupsTypeYmlFilePath);
+ result = addNewPropertiesToGroupType(vfModule, getNewVfModuleTypeProperties(updatedProperties, vfModule));
+ if(!result){
+ LOGGER.debug("Failed to add the new properties {} to org.openecomp.groups.VfModule.1.0.grouptype. ");
+ }
}
- if(result && CollectionUtils.isNotEmpty(newProperties)){
+ if(result && CollectionUtils.isNotEmpty(updatedProperties)){
Map<GraphPropertyEnum, Object> propsHasNot = new EnumMap<>(GraphPropertyEnum.class);
propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
getAllTopologyTemplatesRes = toscaOperationFacade.getTitanDao().getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, null, propsHasNot, JsonParseFlagEnum.ParseAll);
@@ -89,13 +101,7 @@ public class VfModulesPropertiesAdding {
}
}
if(result && getAllTopologyTemplatesRes!=null && getAllTopologyTemplatesRes.isLeft()){
- getAllComponentsRes = getAllContainerComponents(getAllTopologyTemplatesRes.left().value());
- if(getAllComponentsRes.isRight()){
- result = false;
- }
- }
- if(result && getAllComponentsRes != null){
- result = addNewVfModulesProperties(getAllComponentsRes.left().value(), newProperties);
+ result = addNewVfModulesProperties(getAllTopologyTemplatesRes.left().value(), updatedProperties);
}
} catch (Exception e){
result = false;
@@ -110,41 +116,61 @@ public class VfModulesPropertiesAdding {
return result;
}
- private boolean addNewVfModulesProperties(Map<org.openecomp.sdc.be.model.Component, GraphVertex> components, List<PropertyDefinition> newGroupTypeProperties) {
+ private boolean addNewVfModulesProperties(List<GraphVertex> components, List<PropertyDefinition> updatedProperties) {
boolean result = true;
- for(Map.Entry<org.openecomp.sdc.be.model.Component, GraphVertex> component : components.entrySet()){
- result = addNewPropertiesToVfModules(component, newGroupTypeProperties);
+ for(GraphVertex component : components){
+ LOGGER.debug("Going to add the new properties {} to component {}. ", updatedProperties, component.getUniqueId());
+ result = addNewPropertiesToVfModules(component, updatedProperties);
if(!result){
+ LOGGER.debug("Failed to add the new properties {} to component {}. ", updatedProperties, component.getUniqueId());
break;
}
+ toscaOperationFacade.commit();
}
return result;
}
- private boolean addNewPropertiesToVfModules(Entry<org.openecomp.sdc.be.model.Component, GraphVertex> component, List<PropertyDefinition> newGroupTypeProperties) {
+ private boolean addNewPropertiesToVfModules(GraphVertex componentV, List<PropertyDefinition> updatedProperties) {
boolean result = true;
List<GroupDefinition> vfModules = null;
- if(CollectionUtils.isNotEmpty(component.getKey().getGroups())){
- vfModules = component.getKey().getGroups().stream().filter(g -> g.getType().equals(BaseOperation.VF_MODULE)).collect(Collectors.toList());
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getToscaElementRes = toscaOperationFacade.getToscaElement(componentV);
+ if(getToscaElementRes.isRight()){
+ LOGGER.debug("Failed to fetch the component {}. ", componentV.getUniqueId());
+ result = false;
+ }
+ else if(CollectionUtils.isNotEmpty(getToscaElementRes.left().value().getGroups())){
+ vfModules = getToscaElementRes.left().value().getGroups().stream().filter(g -> g.getType().equals(BaseOperation.VF_MODULE)).collect(Collectors.toList());
}
if(vfModules != null){
- vfModules.forEach(vfModule -> vfModule.getProperties().addAll(newGroupTypeProperties));
- StorageOperationStatus status = topologyTemplateOperation.updateToscaDataOfToscaElement(component.getValue(), EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, vfModules, JsonPresentationFields.NAME);
+ vfModules.forEach(vfModule -> addAllNewProperties(vfModule.getProperties(), updatedProperties));
+ StorageOperationStatus status = topologyTemplateOperation.updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, vfModules, JsonPresentationFields.NAME);
if(status!= StorageOperationStatus.OK){
+ LOGGER.debug("Failed to add the new properties {} to groups of component {}. ", updatedProperties, componentV.getUniqueId());
result = false;
}
}
- if(result && CollectionUtils.isNotEmpty(component.getKey().getComponentInstances())){
- result = addPropertiesToVfModuleInstances(component, newGroupTypeProperties);
+ if(result && CollectionUtils.isNotEmpty(getToscaElementRes.left().value().getComponentInstances())){
+ result = addPropertiesToVfModuleInstances(getToscaElementRes.left().value(), componentV, updatedProperties);
}
return result;
}
- private boolean addPropertiesToVfModuleInstances(Entry<org.openecomp.sdc.be.model.Component, GraphVertex> component, List<PropertyDefinition> newGroupTypeProperties) {
+ private void addAllNewProperties(List<PropertyDataDefinition> vfModuleProperties, List<PropertyDefinition> updatedProperties) {
+ Map<String, PropertyDataDefinition> propertiesMap = vfModuleProperties.stream().collect(Collectors.toMap(p->p.getName(), p->p));
+
+ for(PropertyDefinition property : updatedProperties){
+ if(!propertiesMap.containsKey(property.getName())){
+ vfModuleProperties.add(property);
+ }
+ }
+ }
+
+ private boolean addPropertiesToVfModuleInstances(org.openecomp.sdc.be.model.Component component, GraphVertex componentV, List<PropertyDefinition> updatedProperties) {
boolean result = true;
List<GroupInstance> vfModuleInstances;
List<String> pathKeys;
- for(ComponentInstance componentInstance : component.getKey().getComponentInstances()){
+ LOGGER.debug("Going to add the new properties {} to group instances of component {}. ", updatedProperties, componentV.getUniqueId());
+ for(ComponentInstance componentInstance : component.getComponentInstances()){
vfModuleInstances = null;
if(CollectionUtils.isNotEmpty(componentInstance.getGroupInstances())){
vfModuleInstances = componentInstance.getGroupInstances()
@@ -154,41 +180,25 @@ public class VfModulesPropertiesAdding {
}
if(vfModuleInstances != null){
for(GroupInstance vfModuleInstance :vfModuleInstances){
- vfModuleInstance.getProperties().addAll(newGroupTypeProperties);
+ addAllNewProperties(vfModuleInstance.getProperties(),updatedProperties);
pathKeys = new ArrayList<>();
pathKeys.add(componentInstance.getUniqueId());
StorageOperationStatus status = topologyTemplateOperation
- .updateToscaDataDeepElementOfToscaElement(component.getValue(), EdgeLabelEnum.INST_GROUPS, VertexTypeEnum.INST_GROUPS, vfModuleInstance, pathKeys, JsonPresentationFields.NAME);
+ .updateToscaDataDeepElementOfToscaElement(componentV, EdgeLabelEnum.INST_GROUPS, VertexTypeEnum.INST_GROUPS, vfModuleInstance, pathKeys, JsonPresentationFields.NAME);
if(status!= StorageOperationStatus.OK){
result = false;
+ LOGGER.debug("Failed to add the new properties {} to group instances of component {}. ", updatedProperties, componentV.getUniqueId());
break;
}
}
if(!result){
+ LOGGER.debug("Failed to add the new properties {} to group instances of component {}. ", updatedProperties, componentV.getUniqueId());
break;
}
}
}
return result;
}
-
- private Either<Map<org.openecomp.sdc.be.model.Component, GraphVertex>, StorageOperationStatus> getAllContainerComponents(List<GraphVertex> componentsV) {
- Map<org.openecomp.sdc.be.model.Component, GraphVertex> foundComponents = new HashMap<>();
- Either<Map<org.openecomp.sdc.be.model.Component, GraphVertex>, StorageOperationStatus> result = null;
- for(GraphVertex componentV : componentsV){
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentRes = toscaOperationFacade.getToscaElement(componentV);
- if(getComponentRes.isRight()){
- result = Either.right(getComponentRes.right().value());
- break;
- }
- foundComponents.put(getComponentRes.left().value(), componentV);
- }
- if(result == null){
- result = Either.left(foundComponents);
- }
- return result;
- }
-
private boolean addNewPropertiesToGroupType(GroupTypeDefinition vfModule, List<PropertyDefinition> newProperties) {
boolean result = true;
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java
index c9212f91ca..63eb8879c9 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java
@@ -1,20 +1,20 @@
package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-import fj.Function;
import fj.data.Either;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations.FulfilledCapabilitiesMigrationService;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations.FulfilledRequirementsMigrationService;
import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations.RequirementsCapabilitiesMigrationService;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.migration.MigrationMalformedDataLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
+import java.util.List;
+import java.util.stream.Collectors;
+
import static org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils.handleError;
public abstract class ComponentMigration <T extends Component> extends JsonModelMigration<T> {
@@ -27,10 +27,15 @@ public abstract class ComponentMigration <T extends Component> extends JsonModel
@Resource(name = "req-cap-mig-service")
RequirementsCapabilitiesMigrationService<T> requirementsCapabilitiesMigrationService;
+ @Resource(name = "invariant-uuid-resolver")
+ private InvariantUUIDResolver <T> invariantUUIDResolver;
+
@Override
- Either<T, StorageOperationStatus> save(T element) {
+ boolean save(T element) {
LOGGER.debug(String.format("creating component %s in new graph", element.getName()));
- return toscaOperations.createToscaComponent(element).right().map(err -> handleError(err, String.format("failed to create component %s.", element.getName())));
+ return toscaOperations.createToscaComponent(element)
+ .either(savedNode -> true,
+ err -> handleError(String.format("failed to create component %s with id %s. reason: %s", element.getName(), element.getUniqueId(), err.name())));
}
@@ -45,4 +50,26 @@ public abstract class ComponentMigration <T extends Component> extends JsonModel
return StorageOperationStatus.NOT_FOUND;
}
+ @Override
+ void doPreMigrationOperation(List<T> elements) {
+ setMissingInvariantUids(elements);
+ }
+
+ //some invariants uids are missing in production
+ private void setMissingInvariantUids(List<T> components) {
+ List<T> missingInvariantCmpts = getComponentsWithNoInvariantUUIDs(components);
+ for (T missingInvariantCmpt : missingInvariantCmpts) {
+ missingInvariantCmpt.setInvariantUUID(invariantUUIDResolver.resolveInvariantUUID(components, missingInvariantCmpt));
+ }
+ }
+
+ private List<T> getComponentsWithNoInvariantUUIDs(List<T> components) {
+ List<T> cmptsWithoutInvariant = components.stream().filter(c -> c.getInvariantUUID() == null).collect(Collectors.toList());
+ if (!cmptsWithoutInvariant.isEmpty()) {
+ cmptsWithoutInvariant.forEach(cmpt -> MigrationMalformedDataLogger.logMalformedDataMsg(String.format("component %s is missing invariant uuid", cmpt.getUniqueId())));
+ }
+ return cmptsWithoutInvariant;
+ }
+
+
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ConsumersMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ConsumersMigration.java
new file mode 100644
index 0000000000..83078baf6e
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ConsumersMigration.java
@@ -0,0 +1,47 @@
+package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
+
+import fj.data.Either;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ConsumerOperation;
+import org.openecomp.sdc.be.resources.data.ConsumerData;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+import static org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils.handleError;
+
+public class ConsumersMigration extends JsonModelMigration<ConsumerData> {
+
+ @Resource(name = "consumer-operation")
+ private ConsumerOperation consumerOperation;
+
+ @Resource(name = "consumer-operation-mig")
+ private ConsumerOperation consumerOperationMigration;
+
+ @Override
+ Either<List<ConsumerData>, ?> getElementsToMigrate() {
+ return consumerOperation.getAll();
+ }
+
+ @Override
+ Either<ConsumerData, ?> getElementFromNewGraph(ConsumerData element) {
+ return consumerOperationMigration.getCredentials(element.getConsumerDataDefinition().getConsumerName());
+ }
+
+ @Override
+ boolean save(ConsumerData element) {
+ return consumerOperationMigration.createCredentials(element)
+ .either(savedConsumer -> true,
+ err -> handleError(String.format("failed to save consumer %s. reason: %s", element.getConsumerDataDefinition().getConsumerName(), err.name())));
+ }
+
+ @Override
+ StorageOperationStatus getNotFoundErrorStatus() {
+ return StorageOperationStatus.NOT_FOUND;
+ }
+
+ @Override
+ public String description() {
+ return "consumers migration";
+ }
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/InvariantUUIDResolver.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/InvariantUUIDResolver.java
new file mode 100644
index 0000000000..bf28507877
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/InvariantUUIDResolver.java
@@ -0,0 +1,41 @@
+package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
+
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.operations.migration.MigrationMalformedDataLogger;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+
+public class InvariantUUIDResolver <T extends Component> {
+
+ public String resolveInvariantUUID(List<T> components, T missingInvariantCmpt) {
+ String uuid = missingInvariantCmpt.getUUID();
+ String systemName = missingInvariantCmpt.getSystemName();
+ String invariantUid = findInvariantUUidByAllVersionsMap(missingInvariantCmpt, components).orElseGet(() -> findInvariantUUidByUUIDOrSystemName(components, uuid, systemName));
+ if (invariantUid == null) {
+ MigrationMalformedDataLogger.logMalformedDataMsg(String.format("could not find invariant uuid for component %s with id %s", missingInvariantCmpt.getName(), missingInvariantCmpt.getUniqueId()));
+ }
+ return invariantUid;
+ }
+
+ private String findInvariantUUidByUUIDOrSystemName(List<T> components, String uuid, String systemName) {
+ return components.stream()
+ .filter(c -> c.getUUID().equals(uuid) || c.getSystemName().equals(systemName))
+ .map(Component::getInvariantUUID)
+ .filter(c -> c != null)
+ .findAny().orElse(null);
+ }
+
+ private Optional<String> findInvariantUUidByAllVersionsMap(T component, List<T> allComponents) {
+ if (component.getAllVersions() == null) return Optional.empty();
+ Collection<String> allVersionsComponentIds = component.getAllVersions().values();
+ return allComponents.stream().filter(c -> allVersionsComponentIds.contains(c.getUniqueId()))
+ .map(Component::getInvariantUUID)
+ .filter(c -> c != null)
+ .findAny();
+
+
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/JsonModelMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/JsonModelMigration.java
index 6070104d44..4e62b2f497 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/JsonModelMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/JsonModelMigration.java
@@ -1,17 +1,19 @@
package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
import fj.data.Either;
+import org.openecomp.sdc.asdctool.impl.migration.Migration1707Task;
import org.openecomp.sdc.asdctool.impl.migration.MigrationMsg;
-import org.openecomp.sdc.asdctool.impl.migration.Migration;
import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import java.util.List;
-public abstract class JsonModelMigration<T> implements Migration {
+public abstract class JsonModelMigration<T> implements Migration1707Task {
- private final boolean COMPLETED_OK = true;
+ private static final Logger LOGGER = LoggerFactory.getLogger(JsonModelMigration.class);
@Resource(name = "titan-dao")
TitanDao titanDao;
@@ -31,7 +33,11 @@ public abstract class JsonModelMigration<T> implements Migration {
return true;
}
+ void doPreMigrationOperation(List<T> elements){}
+
private boolean migrateElementsToNewGraph(List<T> elementsToMigrate) {
+ LOGGER.info(this.description() + ": starting to migrate elements to new graph. elements to migrate: {}", elementsToMigrate.size());
+ doPreMigrationOperation(elementsToMigrate);
for (T node : elementsToMigrate) {
boolean migratedSuccessfully = migrateElement(node);
if (!migratedSuccessfully) {
@@ -59,14 +65,10 @@ public abstract class JsonModelMigration<T> implements Migration {
}
private boolean saveElementIfNotExists(T element) {
- return isExists(element).either(isExist -> isExist || createElement(element),
+ return isExists(element).either(isExist -> isExist || save(element),
status -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_GET_NODE_FROM_GRAPH.getMessage(status.toString())));
}
- private boolean createElement(T element) {
- return save(element).either(savedNode -> COMPLETED_OK,
- errorStatus -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_CREATE_NODE.getMessage(element.getClass().getName(), errorStatus.toString())));
- }
private Either<Boolean, ?> isExists(T element) {
Either<T, ?> byId = getElementFromNewGraph(element);
@@ -82,7 +84,7 @@ public abstract class JsonModelMigration<T> implements Migration {
abstract Either<T, ?> getElementFromNewGraph(T element);
- abstract Either<T, ?> save(T element);
+ abstract boolean save(T element);
abstract <S extends Enum> S getNotFoundErrorStatus();
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesMigration.java
index 5fc02301dc..82d59e57b7 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesMigration.java
@@ -1,18 +1,22 @@
package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
import fj.data.Either;
-import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import jersey.repackaged.com.google.common.collect.Sets;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
+import java.util.Optional;
+import java.util.Set;
public class NormativesMigration extends ComponentMigration<Resource> {
private static Logger LOGGER = LoggerFactory.getLogger(NormativesMigration.class);
+ private static final String JCP_VERSION_PROPERTY = "jcp-version";
+ private static final Set<String> e2eMalformedVfcs = Sets.newHashSet("71879ee1-ad63-46d0-9943-d33083a6fdbb", "e54e7c4d-6020-4c53-838b-42d34c0da5c9");
@javax.annotation.Resource(name = "normatives-resolver")
private NormativesResolver normativesResolver;
@@ -31,6 +35,30 @@ public class NormativesMigration extends ComponentMigration<Resource> {
}
@Override
+ boolean save(Resource element) {
+ if (e2eMalformedVfcs.contains(element.getUniqueId())) {
+ replaceJcpVersionPropertyTypeToVersion(element);
+ }
+ return super.save(element);
+ }
+
+ private void replaceJcpVersionPropertyTypeToVersion(Resource element) {
+ getJcpIntegerProperty(element).ifPresent(propertyDefinition -> {
+ LOGGER.info("resource {} with id {}: found property jcp-version with type 'integer', changing type to 'version'", element.getName(), element.getUniqueId());
+ propertyDefinition.setType(ToscaPropertyType.VERSION.getType());
+ });
+ }
+
+ private Optional<PropertyDefinition> getJcpIntegerProperty(Resource element) {
+ if (element.getProperties() == null) return Optional.empty();
+ return element.getProperties().stream()
+ .filter(prop -> prop.getName().equals(JCP_VERSION_PROPERTY))
+ .filter(prop -> prop.getType().equals(ToscaPropertyType.INTEGER.getType()))
+ .findAny();
+
+ }
+
+ @Override
boolean doPostMigrateOperation(List<Resource> elements) {
LOGGER.info("migrating node types versions");
return versionMigration.buildComponentsVersionChain(elements);
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourcesCategoriesMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourcesCategoriesMigration.java
index 01654d284f..5285c4c406 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourcesCategoriesMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourcesCategoriesMigration.java
@@ -2,7 +2,7 @@ package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
import fj.data.Either;
import org.openecomp.sdc.asdctool.impl.migration.MigrationMsg;
-import org.openecomp.sdc.asdctool.impl.migration.Migration;
+import org.openecomp.sdc.asdctool.impl.migration.Migration1707Task;
import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
@@ -11,6 +11,7 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import javax.annotation.Resource;
import java.util.ArrayList;
@@ -22,7 +23,7 @@ import static org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.Categori
import static org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.CategoriesUtils.filterOldSubCategories;
-public class ResourcesCategoriesMigration implements Migration {
+public class ResourcesCategoriesMigration implements Migration1707Task {
@Resource(name = "element-operation")
private IElementOperation elementOperation;
@@ -74,7 +75,10 @@ public class ResourcesCategoriesMigration implements Migration {
}
private List<SubCategoryDefinition> getAllDistinctSubCategories (List<CategoryDefinition> categoriesDefinitions) {
- Map<String, List<SubCategoryDefinition>> subCategoriesByNormalName = categoriesDefinitions.stream().flatMap(ct -> ct.getSubcategories().stream()).collect(Collectors.groupingBy(SubCategoryDefinition::getNormalizedName));
+ Map<String, List<SubCategoryDefinition>> subCategoriesByNormalName = categoriesDefinitions.stream()
+ .filter(ct -> ct.getSubcategories()!=null)
+ .flatMap(ct -> ct.getSubcategories().stream())
+ .collect(Collectors.groupingBy(SubCategoryDefinition::getNormalizedName));
return getDistinctSubCategories(subCategoriesByNormalName);
}
@@ -112,7 +116,7 @@ public class ResourcesCategoriesMigration implements Migration {
}
private boolean migrateSubcategoryIfNotExists(CategoryDefinition parentCategory, SubCategoryDefinition subCategory) {
- return isExists(subCategory).either(isExists -> isExists || migrateSubCategory(parentCategory, subCategory),
+ return isExists(parentCategory, subCategory).either(isExists -> isExists || migrateSubCategory(parentCategory, subCategory),
status -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_RETRIEVE_CATEGORY.getMessage(subCategory.getName(), status.name())));
}
@@ -124,13 +128,13 @@ public class ResourcesCategoriesMigration implements Migration {
}
private Either<Boolean, ActionStatus> isExists(CategoryDefinition category) {
- Either<CategoryDefinition, ActionStatus> byId = getCategoryById(category.getUniqueId());
+ Either<CategoryDefinition, ActionStatus> byId = getCategoryById(category);
return byId.either(existingVal -> Either.left(true),
this::getEitherNotExistOrErrorStatus);
}
- private Either<Boolean, ActionStatus> isExists(SubCategoryDefinition subCategory) {
- return getSubCategoryById(subCategory.getUniqueId()).either(existingVal -> Either.left(true),
+ private Either<Boolean, ActionStatus> isExists(CategoryDefinition parentCategory, SubCategoryDefinition subCategory) {
+ return getSubCategoryById(parentCategory, subCategory).either(existingVal -> Either.left(true),
this::getEitherNotExistOrErrorStatus);
}
@@ -138,12 +142,19 @@ public class ResourcesCategoriesMigration implements Migration {
return status == ActionStatus.COMPONENT_CATEGORY_NOT_FOUND ? Either.left(false) : Either.right(status);
}
- private Either<CategoryDefinition, ActionStatus> getCategoryById(String uid) {
- return elementOperationMigration.getCategory(NodeTypeEnum.ResourceNewCategory, uid);
+ private Either<CategoryDefinition, ActionStatus> getCategoryById(CategoryDefinition category) {
+ return elementOperationMigration.getCategory(NodeTypeEnum.ResourceNewCategory, category.getUniqueId());
}
- private Either<SubCategoryDefinition, ActionStatus> getSubCategoryById(String uid) {
- return elementOperationMigration.getSubCategory(NodeTypeEnum.ResourceSubcategory, uid);
+ private Either<SubCategoryDefinition, ActionStatus> getSubCategoryById(CategoryDefinition parentCategory, SubCategoryDefinition subCategory) {
+ String subCategoryUid = getExpectedSubCategoryId(parentCategory, subCategory);
+ return elementOperationMigration.getSubCategory(NodeTypeEnum.ResourceSubcategory, subCategoryUid);
+ }
+
+ //since a sub category might belong to a different category in old graph its new graph id is different than its old graph id
+ private String getExpectedSubCategoryId(CategoryDefinition parentCategory, SubCategoryDefinition subCategory) {
+ String parentId = UniqueIdBuilder.buildCategoryUid(parentCategory.getNormalizedName(), NodeTypeEnum.ResourceNewCategory);
+ return UniqueIdBuilder.buildSubCategoryUid(parentId, subCategory.getNormalizedName());
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceCategoriesMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceCategoriesMigration.java
index f745b88d02..f8f79ad9ba 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceCategoriesMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceCategoriesMigration.java
@@ -10,6 +10,8 @@ import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import javax.annotation.Resource;
import java.util.List;
+import static org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils.handleError;
+
public class ServiceCategoriesMigration extends JsonModelMigration<CategoryDefinition> {
@Resource(name = "element-operation")
@@ -31,12 +33,15 @@ public class ServiceCategoriesMigration extends JsonModelMigration<CategoryDefin
@Override
Either<CategoryDefinition, ?> getElementFromNewGraph(CategoryDefinition node) {
- return elementOperationMigration.getCategory(NodeTypeEnum.ServiceNewCategory, node.getUniqueId());
+ String categoryUid = UniqueIdBuilder.buildCategoryUid(node.getNormalizedName(), NodeTypeEnum.ServiceNewCategory);//in malformed graph there are some categories with different id but same normalized name. so in new graph they same id
+ return elementOperationMigration.getCategory(NodeTypeEnum.ServiceNewCategory, categoryUid);
}
@Override
- Either<CategoryDefinition, ActionStatus> save(CategoryDefinition graphNode) {
- return elementOperationMigration.createCategory(graphNode, NodeTypeEnum.ServiceNewCategory);
+ boolean save(CategoryDefinition graphNode) {
+ return elementOperationMigration.createCategory(graphNode, NodeTypeEnum.ServiceNewCategory)
+ .either(savedCategory -> true,
+ err -> handleError(String.format("failed to save category %s. error: %s", graphNode.getName(), err.name())));
}
@Override
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServicesMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServicesMigration.java
index f5ff96284f..254a75b317 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServicesMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServicesMigration.java
@@ -1,25 +1,23 @@
package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
import fj.data.Either;
-import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.operations.api.IServiceOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.migration.MigrationErrorInformer;
+import org.openecomp.sdc.be.model.operations.migration.MigrationMalformedDataLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ServicesMigration extends ComponentMigration<Service> {
+ private static final String DEFAULT_CONFORMANCE_LEVEL = "0.0";
private static Logger LOGGER = LoggerFactory.getLogger(ServicesMigration.class);
@Resource(name = "service-operation")
@@ -39,10 +37,10 @@ public class ServicesMigration extends ComponentMigration<Service> {
}
@Override
- Either<Service, StorageOperationStatus> save(Service element) {
- MigrationErrorInformer.logIfServiceUsingMalformedVfs(element);
- filterOutVFInstancePropsAndAttrs(element);
- element.setConformanceLevel("0.0");
+ boolean save(Service element) {
+ MigrationMalformedDataLogger.logIfServiceUsingMalformedVfs(element);
+ filterOutDuplicatePropsAndAttrs(element);
+ element.setConformanceLevel(DEFAULT_CONFORMANCE_LEVEL);
requirementsCapabilitiesMigrationService.overrideInstanceCapabilitiesRequirements(element);
return super.save(element);
}
@@ -60,48 +58,95 @@ public class ServicesMigration extends ComponentMigration<Service> {
return versionMigration.buildComponentsVersionChain(elements);
}
- private void filterOutVFInstancePropsAndAttrs(Service element) {
- if (element.getComponentInstances() != null) {
- List<String> vfInstancesIds = getVFInstancesIds(element);
- filterOutVFInstacnecProps(element, vfInstancesIds);
- filterOutVFInstanceAttrs(element, vfInstancesIds);
+ private void filterOutDuplicatePropsAndAttrs(Service element) {
+ if (element.getComponentInstancesProperties() != null) {
+ removeDuplicatedNameProperties(element);
}
+ if (element.getComponentInstancesAttributes() != null) {
+ removeDuplicatedNameAttributes(element);
+ }
+ }
+
+ private void removeDuplicatedNameProperties(Service service) {
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = service.getComponentInstancesProperties();
+ componentInstancesProperties.forEach((uid, properties) -> {
+ componentInstancesProperties.put(uid, getUniquedNamePropertyList(service, properties));
+ });
}
- private void filterOutVFInstanceAttrs(Service element, List<String> vfInstancesIds) {
- Map<String, List<ComponentInstanceAttribute>> componentInstancesAttributes = element.getComponentInstancesAttributes();
- if (componentInstancesAttributes != null) {
- element.setComponentInstancesAttributes(filterOutVFInstanceAttributes(componentInstancesAttributes, vfInstancesIds));
+ private List<ComponentInstanceProperty> getUniquedNamePropertyList(Service service, List<ComponentInstanceProperty> properties) {
+ if (properties == null) {
+ return null;
}
+ List<ComponentInstanceProperty> uniqueNameProperties = new ArrayList<>();
+ Map<String, List<ComponentInstanceProperty>> collect = properties.stream().collect(Collectors.groupingBy(ComponentInstanceProperty::getName));
+ collect.forEach((name, duplicatedProperties) -> {
+ logServiceDuplicateProperties(service, name, duplicatedProperties);
+ uniqueNameProperties.add(duplicatedProperties.get(0));
+ });
+ return uniqueNameProperties;
}
- private void filterOutVFInstacnecProps(Service element, List<String> vfInstancesIds) {
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = element.getComponentInstancesProperties();
- if (componentInstancesProperties != null) {
- element.setComponentInstancesProperties(filterOutVFInstanceProperties(componentInstancesProperties, vfInstancesIds));
+ private void logServiceDuplicateProperties(Service service, String name, List<ComponentInstanceProperty> duplicatedProperties) {
+ if (duplicatedProperties.size() > 1) {
+ LOGGER.debug("service {} with id {} has instance {} with duplicate property {}", service.getName(), service.getUniqueId(), duplicatedProperties.get(0).getUniqueId(), name);
}
}
- private Map<String, List<ComponentInstanceProperty>> filterOutVFInstanceProperties(Map<String, List<ComponentInstanceProperty>> instances, List<String> vfInstanceIds) {
- return instances.entrySet()
- .stream()
- .filter(entry -> !vfInstanceIds.contains(entry.getKey()))
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ private void removeDuplicatedNameAttributes(Service service) {
+ Map<String, List<ComponentInstanceProperty>> componentInstancesAttributes = service.getComponentInstancesAttributes();
+ componentInstancesAttributes.forEach((uid, attributes) -> {
+ componentInstancesAttributes.put(uid, getUniquedNameAttributeList(service, attributes));
+ });
}
- private Map<String, List<ComponentInstanceAttribute>> filterOutVFInstanceAttributes(Map<String, List<ComponentInstanceAttribute>> instances, List<String> vfInstanceIds) {
- return instances.entrySet()
- .stream()
- .filter(entry -> !vfInstanceIds.contains(entry.getKey()))
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ private List<ComponentInstanceProperty> getUniquedNameAttributeList(Service service, List<ComponentInstanceProperty> attributes) {
+ if (attributes == null) {
+ return null;
+ }
+ List<ComponentInstanceProperty> uniqueNameAttributes = new ArrayList<>();
+ Map<String, List<ComponentInstanceProperty>> collect = attributes.stream().collect(Collectors.groupingBy(ComponentInstanceProperty::getName));
+ collect.forEach((name, duplicatedAttributess) -> {
+ logServiceMalformedAttributes(service, name, duplicatedAttributess);
+ uniqueNameAttributes.add(duplicatedAttributess.get(0));
+ });
+ return uniqueNameAttributes;
}
- private List<String> getVFInstancesIds(Service service) {
- return service.getComponentInstances()
- .stream()
- .filter(componentInstance -> componentInstance.getOriginType() == OriginTypeEnum.VF)
- .map(ComponentInstanceDataDefinition::getUniqueId)
- .collect(Collectors.toList());
+ private void logServiceMalformedAttributes(Service service, String name, List<ComponentInstanceProperty> duplicatedAttributess) {
+ if (duplicatedAttributess.size() > 1) {
+ MigrationMalformedDataLogger.logMalformedDataMsg(String.format("service %s with id %s has instance %s with duplicate attribute %s",
+ service.getName(), service.getUniqueId(), duplicatedAttributess.get(0).getUniqueId(), name));
+ }
}
+ // private void filterOutVFInstanceAttrs(Service element, List<String> vfInstancesIds) {
+// Map<String, List<ComponentInstanceAttribute>> componentInstancesAttributes = element.getComponentInstancesAttributes();
+// if (componentInstancesAttributes != null) {
+// element.setComponentInstancesAttributes(filterOutVFInstanceAttributes(componentInstancesAttributes, vfInstancesIds));
+// }
+// }
+//
+// private void filterOutVFInstacnecProps(Service element, List<String> vfInstancesIds) {
+// Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = element.getComponentInstancesProperties();
+// if (componentInstancesProperties != null) {
+// element.setComponentInstancesProperties(filterOutVFInstanceProperties(componentInstancesProperties, vfInstancesIds));
+// }
+// }
+//
+// private Map<String, List<ComponentInstanceProperty>> filterOutVFInstanceProperties(Map<String, List<ComponentInstanceProperty>> instances, List<String> vfInstanceIds) {
+// return instances.entrySet()
+// .stream()
+// .filter(entry -> !vfInstanceIds.contains(entry.getKey()))
+// .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+// }
+//
+// private Map<String, List<ComponentInstanceAttribute>> filterOutVFInstanceAttributes(Map<String, List<ComponentInstanceAttribute>> instances, List<String> vfInstanceIds) {
+// return instances.entrySet()
+// .stream()
+// .filter(entry -> !vfInstanceIds.contains(entry.getKey()))
+// .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+// }
+
+
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UserStatesMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UserStatesMigration.java
index b248d90bd2..67d9235cee 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UserStatesMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UserStatesMigration.java
@@ -7,7 +7,6 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.openecomp.sdc.asdctool.impl.migration.MigrationMsg;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
@@ -23,6 +22,7 @@ import java.util.List;
import java.util.stream.Collectors;
import static fj.data.List.list;
+import static org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils.handleError;
public class UserStatesMigration extends JsonModelMigration<Edge> {
@@ -71,9 +71,16 @@ public class UserStatesMigration extends JsonModelMigration<Edge> {
}
@Override
- Either<Edge, TitanOperationStatus> save(Edge userState) {
+ boolean save(Edge userState) {
Either<InOutVertices, TitanOperationStatus> titanVertices = findEdgeInOutVerticesInNewGraph(userState);
- return titanVertices.left().bind(inOutVertices -> genericDaoMigration.copyEdge(inOutVertices.getOutVertex(), inOutVertices.getInVertex(), userState));
+ return titanVertices.either(inOutVertices -> saveUserState(inOutVertices, userState),
+ err -> handleError(String.format("could not find user edge %s in vertx. error: %s", userState.label(), err.name())));
+ }
+
+ private boolean saveUserState(InOutVertices inOutVertices, Edge userState) {
+ return genericDaoMigration.copyEdge(inOutVertices.getOutVertex(), inOutVertices.getInVertex(), userState)
+ .either(edge -> true,
+ err -> handleError(String.format("failed to save user state edge %s. reason: %s", userState.label(), err.name())));
}
@Override
@@ -125,7 +132,7 @@ public class UserStatesMigration extends JsonModelMigration<Edge> {
String vertexUniqueId = getVertexUniqueId(vertex);
LOGGER.debug(String.format("fetching vertex %s from new graph", vertexUniqueId));
return genericDaoMigration.getVertexByProperty(vertexUniqueId, vertex.property(vertexUniqueId).value())
- .right().map(err -> MigrationUtils.handleError(err, String.format("could not find vertex %s in new graph.", vertexUniqueId))) ;
+ .right().map(err -> handleError(err, String.format("could not find vertex %s in new graph.", vertexUniqueId))) ;
}
// private boolean deleteAllEdges(UserData userData, Direction direction) {
@@ -154,6 +161,7 @@ public class UserStatesMigration extends JsonModelMigration<Edge> {
TitanVertex getInVertex() {
return inVertex;
}
+
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UsersMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UsersMigration.java
index 9dd3fc4853..a578f066bf 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UsersMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UsersMigration.java
@@ -1,13 +1,10 @@
package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-import fj.Function;
import fj.data.Either;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,13 +33,16 @@ public class UsersMigration extends JsonModelMigration<User> {
@Override
Either<User, ActionStatus> getElementFromNewGraph(User user) {
LOGGER.debug(String.format("trying to load user %s from new graph", user.getUserId()));
- return userAdminOperationMigration.getUserData(user.getUserId(), false);
+ return user.getStatus().equals(UserStatusEnum.ACTIVE) ? userAdminOperationMigration.getUserData(user.getUserId(), false) :
+ userAdminOperationMigration.getInactiveUserData(user.getUserId());
}
@Override
- Either<User, StorageOperationStatus> save(User user) {
+ boolean save(User user) {
LOGGER.debug(String.format("trying to save user %s to new graph", user.getUserId()));
- return userAdminOperationMigration.saveUserData(user);
+ return userAdminOperationMigration.saveUserData(user)
+ .either(savedUser -> true,
+ err -> handleError(String.format("failed when saving user %s. error %s", user.getUserId(), err.name())));
}
@Override
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VFResourcesMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VFResourcesMigration.java
index b684883323..34c40f0aa9 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VFResourcesMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VFResourcesMigration.java
@@ -31,7 +31,7 @@ public class VFResourcesMigration extends ComponentMigration<Resource> {
}
@Override
- Either<Resource, StorageOperationStatus> save(Resource element) {
+ boolean save(Resource element) {
requirementsCapabilitiesMigrationService.overrideInstanceCapabilitiesRequirements(element);
return super.save(element);
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VersionMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VersionMigration.java
index 7dadd79a1b..145ae28c81 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VersionMigration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VersionMigration.java
@@ -1,9 +1,7 @@
package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
import fj.data.Either;
-import org.apache.commons.lang3.StringUtils;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.openecomp.sdc.asdctool.impl.migration.MigrationException;
import org.openecomp.sdc.asdctool.impl.migration.MigrationMsg;
import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
@@ -13,7 +11,6 @@ import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,8 +33,7 @@ public abstract class VersionMigration<T extends Component> {
private TitanDao titanDao;
public boolean buildComponentsVersionChain(List<T> components) {
- setMissingInvariantUid(components);
- Map<String, List<T>> componentsByInvariant = components.stream().collect(Collectors.groupingBy(Component::getInvariantUUID));
+ Map<String, List<T>> componentsByInvariant = components.stream().filter(c -> c.getInvariantUUID() != null).collect(Collectors.groupingBy(Component::getInvariantUUID));
for (List<T> componentsList : componentsByInvariant.values()) {
boolean versionChainBuilt = buildVersionChainForInvariant(componentsList);
if (!versionChainBuilt) {
@@ -63,7 +59,7 @@ public abstract class VersionMigration<T extends Component> {
}
private void sortComponentsByVersion(List<T> components) {
- Collections.sort(components, (o1, o2) -> o1.getVersion().compareTo(o2.getVersion()));
+ Collections.sort(components, (o1, o2) -> Double.valueOf(o1.getVersion()).compareTo(Double.valueOf(o2.getVersion())));
}
private boolean createVersionRelationIfNotExist(String fromUid, String toUid) {
@@ -74,10 +70,10 @@ public abstract class VersionMigration<T extends Component> {
private boolean createVersionRelation(String fromUid, String toUid) {
LOGGER.debug(String.format("creating version edge between vertex %s and vertex %s", fromUid, toUid));
- Either<GraphVertex, TitanOperationStatus> vertexById = titanDao.getVertexById(fromUid);
- Either<GraphVertex, TitanOperationStatus> vertexById1 = titanDao.getVertexById(toUid);
- if (vertexById1.isLeft() && vertexById.isLeft()) {
- TitanOperationStatus versionCreated = titanDao.createEdge(vertexById.left().value(), vertexById1.left().value(), EdgeLabelEnum.VERSION, new HashMap<>());
+ Either<GraphVertex, TitanOperationStatus> fromVertex = titanDao.getVertexById(fromUid);
+ Either<GraphVertex, TitanOperationStatus> toVertex = titanDao.getVertexById(toUid);
+ if (toVertex.isLeft() && fromVertex.isLeft()) {
+ TitanOperationStatus versionCreated = titanDao.createEdge(fromVertex.left().value(), toVertex.left().value(), EdgeLabelEnum.VERSION, new HashMap<>());
return versionCreated == TitanOperationStatus.OK;
}
return MigrationUtils.handleError(String.format("could not create version edge between vertex %s and vertex %s.", fromUid, toUid));
@@ -99,28 +95,4 @@ public abstract class VersionMigration<T extends Component> {
}
abstract NodeTypeEnum getNodeTypeEnum();
-
- //some invariatn uids are missing in production
- private void setMissingInvariantUid(List<T> components) {
- List<T> missingInvariantCmpts = getComponentsWithNoInvariantUids(components);
- for (T missingInvariantCmpt : missingInvariantCmpts) {
- String uuid = missingInvariantCmpt.getUUID();
- missingInvariantCmpt.setInvariantUUID(findInvariantUidOrElseFail(components, uuid));
- }
- }
-
- private List<T> getComponentsWithNoInvariantUids(List<T> components) {
- List<T> cmptsWithoutInvariant = components.stream().filter(c -> c.getInvariantUUID() == null).collect(Collectors.toList());
- LOGGER.info(String.format("the following components are missing invariant uids: %s", StringUtils.join(cmptsWithoutInvariant.stream().map(Component::getUniqueId).collect(Collectors.toList()), ",")));
- return cmptsWithoutInvariant;
- }
-
- private String findInvariantUidOrElseFail(List<T> components, String uuid) {
- return components.stream()
- .filter(c -> c.getUUID().equals(uuid))
- .map(Component::getInvariantUUID)
- .filter(c -> c != null)
- .findAny().orElseThrow(() -> new MigrationException(String.format("cannot find invariantuid for component with uuid %s", uuid)));
- }
-
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java
index c914e3b082..c3d8743b86 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java
@@ -35,6 +35,8 @@ import org.openecomp.sdc.asdctool.impl.migration.v1610.ToscaArtifactsAlignment;
import org.openecomp.sdc.asdctool.impl.migration.v1702.Migration1702;
import org.openecomp.sdc.asdctool.impl.migration.v1707.Migration1707;
import org.openecomp.sdc.asdctool.impl.migration.v1707.Migration1707Config;
+import org.openecomp.sdc.asdctool.impl.migration.v1707.DistributionStatusUpdate;
+import org.openecomp.sdc.asdctool.impl.migration.v1707.Migration1707VnfFix;
import org.openecomp.sdc.asdctool.impl.migration.v1707.VfModulesPropertiesAdding;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.common.api.ConfigurationSource;
@@ -64,7 +66,10 @@ public class MigrationMenu {
FIX_ICONS("fix-icons", "titanFixUtils"),
MIGRATION_1610_1702("migrate-1610-1702", "migration1702"),
MIGRATION_1702_1707("migrate-1702-1707", "migration1707"),
- VFMODULES_PROPERTIES_ADDING("vfModules-properties-adding", "vfModulesPropertiesAdding");
+ DISTRIBUTION_STATUS_UPDATE_1707("distribution-status-update-1707", "distributionStatusUpdate"),
+ VFMODULES_PROPERTIES_ADDING("vfModules-properties-adding", "vfModulesPropertiesAdding"),
+ MIGRATION_1707_RELATIONS_FIX("fix-relations-after-migration-1707", "migration1707relationsFix"),
+ MIGRATION_1707_VNF_FIX("fix-vnf-after-migration-1707", "migration1707vnfFix");
// UPDATE_DATA_TYPES("update_data_types", "updateDataTypes");
private String value, beanName;
@@ -238,9 +243,8 @@ public class MigrationMenu {
}
break;
- case MIGRATION_1702_1707:
+ case MIGRATION_1702_1707://this migration is currently not needed, but will be commented out for production env
// log.info("Start ASDC migration from 1702 to 1707");
- System.exit(0);
// Migration1707 migration1707 = (Migration1707) context.getBean(operationEnum.getBeanName());
// isSuccessful = migration1707.migrate();
// if (isSuccessful) {
@@ -250,18 +254,59 @@ public class MigrationMenu {
// log.info("SDC migration from 1702 to 1707 has failed");
// System.exit(2);
// }
+ System.exit(0);
break;
- case VFMODULES_PROPERTIES_ADDING:
- log.info("Start adding new properties to vfModules");
- VfModulesPropertiesAdding migrationVfModulesProperties = (VfModulesPropertiesAdding) context.getBean(operationEnum.getBeanName());
- isSuccessful = migrationVfModulesProperties.migrate(args[1]);
- if (isSuccessful) {
- log.info("Adding new properties to vfModules was finished successfully");
- System.exit(0);
- } else{
- log.info("Adding new properties to vfModules has failed");
- System.exit(2);
- }
+ case VFMODULES_PROPERTIES_ADDING://this migration is currently not needed, but will be commented out for production env
+// log.info("Start adding new properties to vfModules");
+// VfModulesPropertiesAdding migrationVfModulesProperties = (VfModulesPropertiesAdding) context.getBean(operationEnum.getBeanName());
+// isSuccessful = migrationVfModulesProperties.migrate(args[1]);
+// if (isSuccessful) {
+// log.info("Adding new properties to vfModules was finished successfully");
+// System.exit(0);
+// } else{
+// log.info("Adding new properties to vfModules has failed");
+// System.exit(2);
+// }
+ System.exit(0);
+ break;
+ case MIGRATION_1707_VNF_FIX://this migration is currently not needed, but will be commented out for production env
+// log.info("Start fixing vnf after 1707 migration");
+// Migration1707VnfFix migrationVnfFix = (Migration1707VnfFix) context.getBean(operationEnum.getBeanName());
+// isSuccessful = migrationVnfFix.migrate();
+// if (isSuccessful) {
+// log.info("Fixing VNFs after 1707 migration was finished successfully");
+// System.exit(0);
+// } else{
+// log.info("Fixing VNFs after 1707 migration has failed");
+// System.exit(2);
+// }
+ System.exit(0);
+ break;
+ case DISTRIBUTION_STATUS_UPDATE_1707://not needed can be dropped
+// log.info("Start Distribution status update 1707");
+// DistributionStatusUpdate distStatusUpdate = (DistributionStatusUpdate) context.getBean(operationEnum.getBeanName());
+// isSuccessful = distStatusUpdate.migrate();
+// if (isSuccessful) {
+// log.info("ASDC Distribution status update 1707 was finished successful");
+// System.exit(0);
+// } else{
+// log.info("ASDC Distribution status update 1707 has failed");
+// System.exit(2);
+// }
+ System.exit(0);
+ break;
+ case MIGRATION_1707_RELATIONS_FIX://not needed can be dropped
+// log.info("Start fixing relations after 1707 migration");
+// Migration migrationFix = (Migration1707RelationsFix) context.getBean(operationEnum.getBeanName());
+// isSuccessful = migrationFix.migrate();
+// if (isSuccessful) {
+// log.info("Fixing relations after 1707 migration was finished successfully");
+// System.exit(0);
+// } else{
+// log.info("Fixing relations after 1707 migration has failed");
+// System.exit(2);
+// }
+ System.exit(0);
break;
default:
usageAndExit();
@@ -298,6 +343,9 @@ public class MigrationMenu {
System.out.println("Usage: migrate-1610-1702 <configuration dir>");
System.out.println("Usage: migrate-1702-1707 <configuration dir>");
System.out.println("Usage: update_data_types <configuration dir> <data_types_input_file path>");
+ System.out.println("Usage: distribution-status-update-1707");
System.out.println("Usage: vfModules-properties-adding <group_types_input_file path> <configuration dir>");
+ System.out.println("Usage: fix-relations-after-migration-1707 <configuration dir>");
+ System.out.println("Usage: fix-vnf-after-migration-1707 <configuration dir>");
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java
new file mode 100644
index 0000000000..edeb56787b
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java
@@ -0,0 +1,84 @@
+package org.openecomp.sdc.asdctool.main;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Date;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.openecomp.sdc.asdctool.impl.EsToCassandraDataMigrationConfig;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao;
+import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+
+public class SdcSchemaFileImport {
+
+ private static SdcSchemaFilesCassandraDao schemaFilesCassandraDao;
+
+ public static void main(String[] args) throws Exception {
+
+ final String FILE_NAME = "SDC.zip";
+
+ if (args == null || args.length < 4) {
+ usageAndExit();
+ }
+
+ String pathAndFile = args[0];
+ String sdcReleaseNum = args[1];
+ String conformanceLevel = args[2];
+ String appConfigDir = args[3];
+
+ File file = new File(pathAndFile);
+ if(!file.exists()){
+ System.out.println("The file or path does not exist");
+ System.exit(1);
+ } else if(!file.isFile()){
+ System.out.println("Specify the file name");
+ System.exit(1);
+ }
+
+ AnnotationConfigApplicationContext context = initContext(appConfigDir);
+ schemaFilesCassandraDao = (SdcSchemaFilesCassandraDao) context.getBean("sdc-schema-files-cassandra-dao");
+
+ Path path = Paths.get(pathAndFile);
+ byte[] fileBytes = Files.readAllBytes(path);
+
+ Date date = new Date();
+ String md5Hex = DigestUtils.md5Hex(fileBytes);
+
+ SdcSchemaFilesData schemeFileData = new SdcSchemaFilesData(sdcReleaseNum, date, conformanceLevel, FILE_NAME, fileBytes, md5Hex);
+ CassandraOperationStatus saveSchemaFile = schemaFilesCassandraDao.saveSchemaFile(schemeFileData);
+
+ if(!saveSchemaFile.equals(CassandraOperationStatus.OK)){
+ System.out.println("SdcSchemaFileImport failed cassandra error" + saveSchemaFile);
+ System.exit(1);
+ }
+
+ System.out.println("SdcSchemaFileImport successfully completed");
+
+ System.exit(0);
+ }
+
+ private static void usageAndExit(){
+ SdcSchemaFileImportUsage();
+ System.exit(1);
+ }
+
+ private static void SdcSchemaFileImportUsage(){
+ System.out.println("Usage: <file dir/filename> <SDC release number> <Schema conformance level> <configuration dir>");
+ }
+
+ private static AnnotationConfigApplicationContext initContext(String appConfigDir) {
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(EsToCassandraDataMigrationConfig.class);
+ return context;
+ }
+}
diff --git a/asdctool/src/main/resources/config/configuration.yaml b/asdctool/src/main/resources/config/configuration.yaml
index d376ba3c0e..beca6c98aa 100644
--- a/asdctool/src/main/resources/config/configuration.yaml
+++ b/asdctool/src/main/resources/config/configuration.yaml
@@ -25,8 +25,8 @@ beSslPort: 8443
version: 1.0
released: 2012-11-30
-titanCfgFile: C:\Git_work\Git_UGN\d2-sdnc\asdctool\src\main\resources\config\titan.properties
-titanMigrationKeySpaceCfgFile: C:\Git_work\Git_UGN\d2-sdnc\asdctool\src\main\resources\config\titan-migration.properties
+titanCfgFile: src\main\resources\config\titan.properties
+titanMigrationKeySpaceCfgFile: src\main\resources\config\titan-migration.properties
titanInMemoryGraph: false
titanLockTimeout: 1800
titanReconnectIntervalInSeconds: 3
diff --git a/asdctool/src/main/resources/config/groupTypes.yml b/asdctool/src/main/resources/config/groupTypes.yml
index c72dc88c53..ce457e4add 100644
--- a/asdctool/src/main/resources/config/groupTypes.yml
+++ b/asdctool/src/main/resources/config/groupTypes.yml
@@ -63,7 +63,20 @@ org.openecomp.groups.VfModule:
Group.
VID operator must select the Volume Group instance to attach to a VF-Module
at deployment time.
-
+ availability_zone_count:
+ type: integer
+ required: false
+ description: >
+ Quantity of Availability Zones needed for this VF-Module
+ (source: Extracted from VF-Module HEAT template)
+ vfc_list:
+ type: map
+ entry_schema:
+ description: <vfc_id>:<count>
+ type: string
+ required: false
+ description: >
+ Identifies the set of VM types and their count included in the VF-Module
tosca.groups.Root:
description: The TOSCA Group Type all other TOSCA Group Types derive from
interfaces:
diff --git a/asdctool/src/main/resources/config/logback.xml b/asdctool/src/main/resources/config/logback.xml
index 87795ae163..0426a32d9e 100644
--- a/asdctool/src/main/resources/config/logback.xml
+++ b/asdctool/src/main/resources/config/logback.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
- <property scope="system" name="ECOMP-component-name" value="ASDC" />
- <property scope="system" name="ECOMP-subcomponent-name" value="ASDC-TOOL" />
+ <property scope="system" name="ECOMP-component-name" value="SDC" />
+ <property scope="system" name="ECOMP-subcomponent-name" value="SDC-TOOL" />
<property name="default-log-pattern"
value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{uuid}|%X{serviceInstanceID}|%thread||${ECOMP-subcomponent-name}|%X{userId}|%level|%X{alarmSeverity}|%X{localAddr}|${beFqdn}|%X{remoteAddr}|%logger{35}|%X{timer}|ActivityType=&lt;%M&gt;, Desc=&lt;%msg&gt;%n" />
@@ -36,9 +36,33 @@
</encoder>
</appender>
+ <appender name="MALFORMED_DATA"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${HOME}/asdctool/logs/${ECOMP-component-name}/${ECOMP-subcomponent-name}/malformed-data.log</file>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${HOME}/asdctool/logs/${ECOMP-component-name}/${ECOMP-subcomponent-name}/malformed-data.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${default-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+
<root level="INFO">
<appender-ref ref="DEBUG_ROLLING" />
</root>
<logger name="org.openecomp.sdc" level="INFO" />
+ <logger name="org.openecomp.sdc.be.model.operations.migration" level="ERROR" >
+ <appender-ref ref="MALFORMED_DATA"/>
+ </logger>
</configuration> \ No newline at end of file
diff --git a/asdctool/src/main/resources/scripts/dataMigration1707.sh b/asdctool/src/main/resources/scripts/dataMigration1707.sh
index e67de2a540..11a151a7c3 100644
--- a/asdctool/src/main/resources/scripts/dataMigration1707.sh
+++ b/asdctool/src/main/resources/scripts/dataMigration1707.sh
@@ -18,7 +18,7 @@ source ${FULL_PATH}/baseOperation.sh
mainClass="org.openecomp.sdc.asdctool.main.MigrationMenu"
-command="java $JVM_LOG_FILE -cp $JARS $mainClass migrate-1702-1707 $@"
+command="java $JVM_LOG_FILE -Xmx6000M -cp $JARS $mainClass migrate-1702-1707 $@"
echo $command
$command
diff --git a/asdctool/src/main/resources/scripts/distributionStatusUpdate1707.sh b/asdctool/src/main/resources/scripts/distributionStatusUpdate1707.sh
new file mode 100644
index 0000000000..a9d308f933
--- /dev/null
+++ b/asdctool/src/main/resources/scripts/distributionStatusUpdate1707.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+##############################
+# Distribution Status Update 1707
+##############################
+
+CURRENT_DIR=`pwd`
+BASEDIR=$(dirname $0)
+
+if [ ${BASEDIR:0:1} = "/" ]
+then
+ FULL_PATH=$BASEDIR
+else
+ FULL_PATH=$CURRENT_DIR/$BASEDIR
+fi
+
+source ${FULL_PATH}/baseOperation.sh
+
+mainClass="org.openecomp.sdc.asdctool.main.MigrationMenu"
+
+command="java $JVM_LOG_FILE -cp $JARS $mainClass distribution-status-update-1707 $@"
+echo $command
+
+$command
+result=$?
+
+
+
+echo "***********************************"
+echo "***** $result *********************"
+echo "***********************************"
+
+exit $result
+
+
diff --git a/asdctool/src/main/resources/scripts/migration1707RelationsFix.sh b/asdctool/src/main/resources/scripts/migration1707RelationsFix.sh
new file mode 100644
index 0000000000..c930243750
--- /dev/null
+++ b/asdctool/src/main/resources/scripts/migration1707RelationsFix.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+##############################
+# Data Migration: fix relations after migration 1707
+##############################
+
+CURRENT_DIR=`pwd`
+BASEDIR=$(dirname $0)
+
+if [ ${BASEDIR:0:1} = "/" ]
+then
+ FULL_PATH=$BASEDIR
+else
+ FULL_PATH=$CURRENT_DIR/$BASEDIR
+fi
+
+source ${FULL_PATH}/baseOperation.sh
+
+mainClass="org.openecomp.sdc.asdctool.main.MigrationMenu"
+
+command="java $JVM_LOG_FILE -cp $JARS $mainClass fix-relations-after-migration-1707 $@"
+echo $command
+
+$command
+result=$?
+
+echo "***********************************"
+echo "***** $result *********************"
+echo "***********************************"
+
+exit $result
+
+
diff --git a/asdctool/src/main/resources/scripts/retrieve_schema_file.sh b/asdctool/src/main/resources/scripts/retrieve_schema_file.sh
new file mode 100644
index 0000000000..f66b530f20
--- /dev/null
+++ b/asdctool/src/main/resources/scripts/retrieve_schema_file.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+cass_user=asdc_user
+cass_pass='Aa1234%^!'
+sdcReleaseNum=$1
+conformanceLevel=$2
+
+CQLSH="/home/vagrant/cassandra/apache-cassandra-2.1.9/bin/cqlsh"
+
+
+ ### Get payload
+
+ select_payload="select payload from sdcartifact.sdcschemafiles where conformanceLevel='$conformanceLevel' and sdcReleaseNum='$sdcReleaseNum'"
+
+ echo "Run: [$select_payload]"
+
+$CQLSH -e "$select_payload" |grep "0x" |xxd -r -p > SDC-downloaded.zip
+
+res=$?
+echo "After select payload, res=[$res]" \ No newline at end of file
diff --git a/asdctool/src/main/resources/scripts/vfmoduleFix1707.sh b/asdctool/src/main/resources/scripts/vfmoduleFix1707.sh
new file mode 100644
index 0000000000..48579242bf
--- /dev/null
+++ b/asdctool/src/main/resources/scripts/vfmoduleFix1707.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+##############################
+# Distribution Status Update 1707
+##############################
+
+CURRENT_DIR=`pwd`
+BASEDIR=$(dirname $0)
+
+if [ ${BASEDIR:0:1} = "/" ]
+then
+ FULL_PATH=$BASEDIR
+else
+ FULL_PATH=$CURRENT_DIR/$BASEDIR
+fi
+
+source ${FULL_PATH}/baseOperation.sh
+
+mainClass="org.openecomp.sdc.asdctool.main.MigrationMenu"
+
+command="java $JVM_LOG_FILE -cp $JARS $mainClass fix-vnf-after-migration-1707 $@"
+echo $command
+
+$command
+result=$?
+
+
+
+echo "***********************************"
+echo "***** $result *********************"
+echo "***********************************"
+
+exit $result
+
+