summaryrefslogtreecommitdiffstats
path: root/asdctool
diff options
context:
space:
mode:
Diffstat (limited to 'asdctool')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration1707Task.java41
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationException.java29
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationMsg.java56
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationOperationUtils.java139
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AddGroupUuid.java131
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AllowMultipleHeats.java144
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AppConfig.java602
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/DerivedFromAlignment.java232
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/GroupsAlignment.java201
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/MigrationCategory.java48
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/MigrationSubCategory.java36
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/ServiceMigration.java1515
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/VfcNamingAlignment.java184
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1607/CsarMigration.java93
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1610/TitanFixUtils.java384
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1610/ToscaArtifactsAlignment.java461
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/DataTypesUpdate.java428
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/Migration1702.java1406
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/DistributionStatusUpdate.java160
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707.java58
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java585
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707Config.java279
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707MissingInfoFix.java220
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707RelationsFix.java151
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707VnfFix.java120
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/MigrationTitanStrategy.java33
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/MigrationUtils.java47
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/RenameGraphPropertyKeys.java56
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaNamesUpdate.java388
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java175
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/VfModulesPropertiesAdding.java257
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/CategoriesUtils.java45
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java132
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ConsumersMigration.java67
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/InvariantUUIDResolver.java61
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/JsonModelMigration.java112
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/MigrationByIdDerivedNodeTypeResolver.java43
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java353
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesMigration.java86
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesResolver.java101
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourceVersionMigration.java42
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourcesCategoriesMigration.java181
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceCategoriesMigration.java71
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceVersionMigration.java43
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServicesMigration.java180
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UserStatesMigration.java187
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UsersMigration.java78
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VFResourcesMigration.java79
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VersionMigration.java118
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledCapabilitiesMigrationService.java104
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledCapabilityRequirementMigrationService.java184
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledRequirementsMigrationService.java104
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/RequirementsCapabilitiesMigrationService.java111
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java14
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java1
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java18
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java3
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java21
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactsVertexResult.java30
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java2
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java5
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java27
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java66
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/VertexResult.java30
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/EsToCassandraDataMigrationMenu.java2
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java345
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java4
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java6
-rw-r--r--asdctool/src/main/resources/scripts/dataMigration.sh56
-rw-r--r--asdctool/src/main/resources/scripts/dataMigration1607.sh33
-rw-r--r--asdctool/src/main/resources/scripts/dataMigration1610.sh41
-rw-r--r--asdctool/src/main/resources/scripts/dataMigration1702.sh35
-rw-r--r--asdctool/src/main/resources/scripts/dataMigration1707.sh35
-rw-r--r--asdctool/src/main/resources/scripts/validationTool.sh3
74 files changed, 161 insertions, 11757 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration1707Task.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration1707Task.java
deleted file mode 100644
index 2c19c94cff..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/Migration1707Task.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.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
- * @return true if migration completed successfully or false otherwise
- */
- boolean migrate();
-
- /**
- *
- * @return a description of what this migration does
- */
- String description();
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationException.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationException.java
deleted file mode 100644
index 8e958b9ad1..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration;
-
-public class MigrationException extends RuntimeException {
-
- public MigrationException(String message) {
- super(message);
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationMsg.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationMsg.java
deleted file mode 100644
index e743e5387b..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationMsg.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration;
-
-public enum MigrationMsg {
- RENMAE_KEY_PROPERTIES_1707("renaming key properties"),
- KEY_PROPERTY_NOT_EXIST("key propery %s not exist"),
- RENAME_KEY_PROPERTY_FAILED("failed to rename key property %s"),
- FAILED_TO_RETRIEVE_GRAPH("failed to get graph %s"),
- PROPERTY_KEY_NOT_EXIST("property key %s not found."),
- FAILED_TO_RETRIEVE_NODES("failed to retrieve nodes from graph. error status: %s"),
- FAILED_TO_GET_NODE_FROM_GRAPH("failed to retrieve node from graph. error status : %s"),
- FAILED_TO_CREATE_NODE("failed to create node of type %s. reason: %s"),
- FAILED_TO_RETRIEVE_CATEGORIES("failed to retrieve categories. error status: %s"),
- FAILED_TO_RETRIEVE_CATEGORY("failed to retrieve category %s. error status: %s"),
- FAILED_TO_CREATE_SUB_CATEGORY("failed to create sub category %s of category %s. error status: %s"),
- FAILED_TO_CREATE_CATEGORY("failed to create category %s. error status: %s"),
- FAILED_TO_RETRIEVE_USER_STATES("failed to retrieve user %s states. error status: %s"),
- FAILED_TO_RETRIEVE_MIGRATION_USER_STATES("failed to retrieve migrating user %s states for deletion. error status: %s"),
- FAILED_TO_RETRIEVE_MIGRATION_USER("failed to retrieve migration user %s. error status: %s"),
- FAILED_TO_RETRIEVE_VERSION_RELATION("failed to retrieve version relation from component with id %s to component with id %s. error status: %s"),
- FAILED_TO_RETRIEVE_REQ_CAP("failed to retrieve fulfilled requirements or capabilities for instance %s. error status: %s"),
- FAILED_TO_RETRIEVE_VERTEX("failed to retrieve vertex with id: %s. error status: %s"),
- FAILED_TO_RETRIEVE_CAP_REQ_VERTEX("failed to retrieve capabilities or requirements vertex for component %s. error status: %s"),
- FAILED_TO_ASSOCIATE_CAP_REQ("failed to associate fulfilled capabilities or requirements for components %s. error status: %s"),
- FAILED_TO_RETRIEVE_TOSCA_DEF("failed to retrieve tosca definition for requirement or capability %s. error status %s"),
- ;
-
- private String message;
-
- MigrationMsg(String migrationDescription) {
- this.message = migrationDescription;
- }
-
- public String getMessage(String ... msgProperties) {
- return String.format(this.message, msgProperties);
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationOperationUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationOperationUtils.java
deleted file mode 100644
index 7a34521d93..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/MigrationOperationUtils.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration;
-
-import com.thinkaurelius.titan.core.PropertyKey;
-import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.core.TitanVertex;
-import com.thinkaurelius.titan.core.schema.TitanManagement;
-import fj.data.Either;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.Map;
-import java.util.Optional;
-
-@Component("migrationUtils")
-public class MigrationOperationUtils {
-
- private static Logger log = LoggerFactory.getLogger(MigrationOperationUtils.class);
-
- @Autowired
- private TitanGenericDao titanGenericDao;
-
- /**
- * rename a set or property keys
- *
- * @param propertyKeys a mapping between the old property key name and the property key name to replace it with
- *
- * @return true if rename ended successfully or false otherwise
- */
- public boolean renamePropertyKeys(Map<String, String> propertyKeys) {
- Either<TitanGraph, TitanOperationStatus> graph = titanGenericDao.getGraph();
- return graph.either((titanGraph) -> renamePropertyKeys(titanGraph, propertyKeys),
- (titanOperationStatus) -> operationFailed(MigrationMsg.FAILED_TO_RETRIEVE_GRAPH.getMessage(titanOperationStatus.name())));
- }
-
- private boolean renamePropertyKeys(TitanGraph titanGraph, Map<String, String> propertyKeys) {
- try {
- for (Map.Entry<String, String> propertyKeyEntry : propertyKeys.entrySet()) {
- boolean renameSucceeded = renamePropertyKey(titanGraph, propertyKeyEntry);
- if (!renameSucceeded) {
- return false;
- }
- }
- return true;
- } catch (RuntimeException e) {
- log.error(e.getMessage(), e);
- return false;
- }
- }
-
- private Boolean renamePropertyKey(TitanGraph titanGraph, Map.Entry<String, String> propertyKeyEntry) {
- String renameFromKey = propertyKeyEntry.getKey();
- String renameToKey = propertyKeyEntry.getValue();
- log.info(String.format("renaming property key %s to %s", renameFromKey, renameToKey));
- return renameProperty(titanGraph, renameFromKey, renameToKey);
- }
-
- private Boolean renameProperty(TitanGraph titanGraph, String renameFromKey, String renameToKey) {
- if (titanGraph.containsPropertyKey(renameFromKey) && titanGraph.containsPropertyKey(renameToKey)) {//new property already exist, we cant rename to it we need to add new and remove old on every vertices which has the old one.
- return renamePropertyOnEachVertex(titanGraph, renameFromKey, renameToKey);
- }
- return renamePropertyOnGraphLevel(titanGraph, renameFromKey, renameToKey);
- }
-
- private Boolean renamePropertyOnGraphLevel(TitanGraph titanGraph, String renameFromKey, String renameToKey) {
- TitanManagement titanManagement = titanGraph.openManagement();
- return Optional.ofNullable(titanManagement.getPropertyKey(renameFromKey))
- .map(propertyKey -> renamePropertyOnGraph(titanManagement, propertyKey, renameToKey))
- .orElseGet(() -> {log.info(MigrationMsg.PROPERTY_KEY_NOT_EXIST.getMessage(renameFromKey)); return true;}) ;//if property key not exist rename is considered to be successful
- }
-
- private boolean renamePropertyOnEachVertex(TitanGraph graph, String oldKey, String newKey) {
- addNewPropertyKeyOnVertices(graph, oldKey, newKey);
- removeOldPropertyKeyFromGraph(graph, oldKey);
- graph.tx().commit();
- return true;
- }
-
- private void removeOldPropertyKeyFromGraph(TitanGraph graph, String oldKey) {
- graph.getPropertyKey(oldKey).remove();
- }
-
- private void addNewPropertyKeyOnVertices(TitanGraph graph, String oldKey, String newKey) {
- graph.query().has(oldKey).vertices().forEach(titanVertex -> {
- copyOldKeyValueAndDropKey(oldKey, newKey, (TitanVertex) titanVertex);
- });
- }
-
- private void copyOldKeyValueAndDropKey(String oldKey, String newKey, TitanVertex titanVertex) {
- VertexProperty<Object> oldProperty = titanVertex.property(oldKey);
- Object oldKeyValue = oldProperty.value();
-
- titanVertex.property(newKey, oldKeyValue);
- oldProperty.remove();
- }
-
- private boolean renamePropertyOnGraph(TitanManagement titanManagement, PropertyKey fromPropertyKey, String toKey) {
- try {
- titanManagement.changeName(fromPropertyKey, toKey);
- titanManagement.commit();
- return true;
- } catch (RuntimeException e) {
- log.error(MigrationMsg.RENAME_KEY_PROPERTY_FAILED.getMessage(fromPropertyKey.name()), e.getMessage());
- titanManagement.rollback();
- return false;
- }
- }
-
- private boolean operationFailed(String errorMessage) {
- log.error(errorMessage);
- return false;
- }
-
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AddGroupUuid.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AddGroupUuid.java
deleted file mode 100644
index 03583fdfec..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AddGroupUuid.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1604;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
-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.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.resources.data.GroupData;
-import org.slf4j.Logger;
-
-import fj.data.Either;
-
-public class AddGroupUuid {
-
- public static boolean addGroupUuids(TitanGenericDao titanGenericDao, Logger log, boolean inTrsansaction) {
-
- boolean result = true;
-
- try {
-
- log.debug("========================================================");
- log.debug("Before find all groups");
-
- Either<List<GroupData>, TitanOperationStatus> allGroups = titanGenericDao.getByCriteria(NodeTypeEnum.Group,
- null, null, GroupData.class);
-
- if (allGroups.isRight()) {
- TitanOperationStatus status = allGroups.right().value();
- log.debug("After finding all groups. Status is {}", status);
- if (status != TitanOperationStatus.NOT_FOUND && status != TitanOperationStatus.OK) {
- result = false;
- return result;
- } else {
- return result;
- }
- }
-
- List<GroupData> groups = allGroups.left().value();
-
- log.info("The number of groups fetched is {}", groups == null ? 0 : groups.size());
-
- int numberOfUpdates = 0;
- if (false == groups.isEmpty()) {
- Map<String, List<GroupData>> invariantIdToGroups = groups.stream()
- .collect(Collectors.groupingBy(p -> p.getGroupDataDefinition().getInvariantUUID()));
-
- // All the groups with the same invariantUUID should have the
- // same group UUID since update VF flow with CSAR was not
- // supported in the E2E environment.
-
- log.info("The number of different invariantUuids is {}",
- invariantIdToGroups == null ? 0 : invariantIdToGroups.size());
-
- for (Entry<String, List<GroupData>> entry : invariantIdToGroups.entrySet()) {
-
- String invariantUuid = entry.getKey();
- List<GroupData> groupsData = entry.getValue();
-
- StringBuilder builder = new StringBuilder();
- groupsData.forEach(p -> builder.append(p.getGroupDataDefinition().getUniqueId() + ","));
-
- String groupUUID = groupsData.get(0).getGroupDataDefinition().getGroupUUID();
-
- if (groupUUID == null) {
-
- groupUUID = UniqueIdBuilder.generateUUID();
-
- log.debug("Before updating groups {} with groupUUID {}",builder.toString(),groupUUID);
-
- for (GroupData groupData : groupsData) {
-
- numberOfUpdates++;
- groupData.getGroupDataDefinition().setGroupUUID(groupUUID);
- Either<GroupData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(groupData,
- GroupData.class);
- if (updateNode.isRight()) {
- log.error("Failed to update group {}. Error is {}",groupData,updateNode.right().value().toString());
- result = false;
- return result;
- }
-
- }
-
- log.debug("After updating groups {} with groupUUID {}",builder.toString(),groupUUID);
- }
-
- }
- }
-
- log.info("The number of groups updated with groupUUID is {}", numberOfUpdates);
-
- return result;
-
- } finally {
- log.info("Finish updating groupUUIDs. Status is {}.", result);
- if (inTrsansaction == false) {
- if (result == false) {
- titanGenericDao.rollback();
- } else {
- titanGenericDao.commit();
- }
- }
- }
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AllowMultipleHeats.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AllowMultipleHeats.java
deleted file mode 100644
index 3c9d6fa08f..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AllowMultipleHeats.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1604;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-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.resources.data.ArtifactData;
-import org.slf4j.Logger;
-
-import fj.data.Either;
-
-public class AllowMultipleHeats {
-
- public static boolean removeAndUpdateHeatPlaceHolders(TitanGenericDao titanGenericDao, Logger log,
- boolean inTrsansaction) {
-
- boolean result = true;
-
- try {
-
- List<ArtifactData> artifactsToDelete = new ArrayList<>();
- List<ArtifactData> artifactsToUpdate = new ArrayList<>();
-
- String[] phLabels = { "heat", "heatvol", "heatnet" };
-
- for (String artifactLabel : phLabels) {
- Map<String, Object> properties = new HashMap<>();
-
- properties.put(GraphPropertiesDictionary.ARTIFACT_LABEL.getProperty(), artifactLabel);
-
- Either<List<ArtifactData>, TitanOperationStatus> allHeatArtifacts = titanGenericDao
- .getByCriteria(NodeTypeEnum.ArtifactRef, properties, null, ArtifactData.class);
-
- if (allHeatArtifacts.isRight()) {
- TitanOperationStatus status = allHeatArtifacts.right().value();
- if (status == TitanOperationStatus.NOT_FOUND) {
- continue;
- } else {
- result = false;
- return result;
- }
-
- }
-
- List<ArtifactData> list = allHeatArtifacts.left().value();
- log.debug("Found {} artifacts with label {}",(list == null ? 0 : list.size()),artifactLabel);
-
- if (list != null && false == list.isEmpty()) {
-
- for (ArtifactData artifactData : list) {
- String esId = artifactData.getArtifactDataDefinition().getEsId();
- if (esId == null || true == esId.isEmpty()) {
- artifactsToDelete.add(artifactData);
- } else {
- artifactsToUpdate.add(artifactData);
- }
- }
- }
- }
-
- if (false == artifactsToDelete.isEmpty()) {
- for (ArtifactData artifactData : artifactsToDelete) {
- // System.out.println("Going to delete artifact " +
- // artifactData);
- log.debug("Going to delete artifact {}",artifactData);
- Either<ArtifactData, TitanOperationStatus> deleteNode = titanGenericDao.deleteNode(artifactData,
- ArtifactData.class);
- if (deleteNode.isRight()) {
- log.error("Failed to delete artifact node {}", deleteNode.left().value());
- result = false;
- return result;
- } else {
- log.debug("Delete artifact node {}",deleteNode.left().value());
- }
- }
- }
-
- log.debug("Number of deleted artifacts is {}",artifactsToDelete.size());
-
- int counter = 0;
- if (false == artifactsToUpdate.isEmpty()) {
- for (ArtifactData artifactData : artifactsToUpdate) {
- // System.out.println("Going to update artifact " +
- // artifactData);
-
- if (artifactData.getArtifactDataDefinition().getMandatory() != null
- && true == artifactData.getArtifactDataDefinition().getMandatory()) {
- log.debug("Going to update artifact {}",artifactData);
- counter++;
- artifactData.getArtifactDataDefinition().setMandatory(false);
- Either<ArtifactData, TitanOperationStatus> updatedNode = titanGenericDao
- .updateNode(artifactData, ArtifactData.class);
- if (updatedNode.isRight()) {
- log.error("Failed to update artifact node {}", updatedNode.left().value());
- result = false;
- return result;
- } else {
- log.debug("Update artifact node {}",updatedNode.left().value());
- }
- }
- }
- }
-
- log.debug("Number of updated artifacts is {}",counter);
-
- return result;
-
- } finally {
- if (inTrsansaction == false) {
- if (result == false) {
- titanGenericDao.rollback();
- } else {
- titanGenericDao.commit();
- }
- }
- }
- }
-
-}
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
deleted file mode 100644
index 3218ed262e..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/AppConfig.java
+++ /dev/null
@@ -1,602 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1604;
-
-import org.openecomp.sdc.asdctool.impl.PopulateComponentCache;
-import org.openecomp.sdc.asdctool.impl.migration.MigrationOperationUtils;
-import org.openecomp.sdc.asdctool.impl.migration.v1607.CsarMigration;
-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.Migration1707ArtifactUuidFix;
-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.*;
-import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
-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.ComponentCassandraDao;
-import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao;
-import org.openecomp.sdc.be.dao.config.DAOSpringConfig;
-import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
-import org.openecomp.sdc.be.dao.impl.AuditingDao;
-import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
-import org.openecomp.sdc.be.model.cache.ComponentCache;
-import org.openecomp.sdc.be.model.jsontitan.operations.GroupsOperation;
-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.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;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.context.annotation.Primary;
-
-@Configuration
-@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();
- }
- @Bean(name = "componentsUtils")
- public ComponentsUtils componentsUtils() {
- return new ComponentsUtils();
- }
- @Bean(name = "updateDataTypes")
- public DataTypesUpdate dataTypesUpdate() {
- return new DataTypesUpdate();
- }
- @Bean(name = "serviceMigrationBean")
- public ServiceMigration serviceMigration() {
- return new ServiceMigration();
- }
-
- @Bean(name = "vfcNamingAlignmentBean")
- public VfcNamingAlignment vfcNamingAlignment() {
- return new VfcNamingAlignment();
- }
-
- @Bean(name = "derivedFromAlignment")
- public DerivedFromAlignment derivedFromAlignment() {
- return new DerivedFromAlignment();
- }
-
- @Bean(name = "groupsAlignment")
- public GroupsAlignment groupsAlignment() {
- return new GroupsAlignment();
- }
-
- @Bean(name = "csarMigration")
- public CsarMigration csarMigration() {
- return new CsarMigration();
- }
-
- @Bean(name = "resource-operation")
- public ResourceOperation resourceOperation() {
- return new ResourceOperation();
- }
-
- @Bean(name = "service-operation")
- public ServiceOperation serviceOperation() {
- return new ServiceOperation();
- }
-
- @Bean(name = "component-instance-operation")
- public ComponentInstanceOperation componentInstanceOperation() {
- return new ComponentInstanceOperation();
- }
-
- @Bean(name = "capability-instanceOperation")
- public CapabilityInstanceOperation capabilityInstanceOperation() {
- return new CapabilityInstanceOperation();
- }
-
- @Bean(name = "property-operation")
- @Primary
- public PropertyOperation propertyOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
- return new PropertyOperation(titanGenericDao);
- }
-
- @Bean(name = "attribute-operation")
- public AttributeOperation attribueOperation() {
- return new AttributeOperation();
- }
-
- @Bean(name = "application-datatype-cache")
- public ApplicationDataTypeCache applicationDataTypeCache() {
- return new ApplicationDataTypeCache();
- }
-
- @Bean(name = "requirement-operation")
- public RequirementOperation requirementOperation() {
- return new RequirementOperation();
- }
-
- @Bean(name = "capability-operation")
- public CapabilityOperation capabilityOperation() {
- return new CapabilityOperation();
- }
-
- @Bean(name = "interface-operation")
- public InterfaceLifecycleOperation interfaceLifecycleOperation() {
- return new InterfaceLifecycleOperation();
- }
-
- @Bean(name = "element-operation")
- @Primary
- public IElementOperation elementOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
- return new ElementOperation(titanGenericDao);
- }
-
- @Bean(name = "additional-information-operation")
- public IAdditionalInformationOperation addioAdditionalInformationOperation() {
- return new AdditionalInformationOperation();
- }
-
- @Bean(name = "capability-type-operation")
- public CapabilityTypeOperation capabilityTypeOperation() {
- return new CapabilityTypeOperation();
- }
-
- @Bean(name = "artifact-operation")
- public ArtifactOperation artifactOperation() {
- return new ArtifactOperation();
- }
-
- @Bean(name = "heat-parameter-operation")
- public HeatParametersOperation heatParametersOperation() {
- return new HeatParametersOperation();
- }
-
- @Bean(name = "product-operation")
- public ProductOperation productOperation() {
- return new ProductOperation();
- }
-
- @Bean(name = "lifecycle-operation")
- public LifecycleOperation lifecycleOperation() {
- return new LifecycleOperation();
- }
-
- @Bean(name = "group-operation")
- public GroupOperation groupOperation() {
- return new GroupOperation();
- }
-
- @Bean(name = "groups-operation")
- public GroupsOperation jsonGroupsOperation() {
- return new GroupsOperation();
- }
-
- @Bean(name = "group-instance-operation")
- public GroupInstanceOperation groupInstanceOperation() {
- return new GroupInstanceOperation();
- }
-
- @Bean(name = "group-type-operation")
- @Primary
- public GroupTypeOperation groupTypeOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenricDao, @Qualifier("property-operation")PropertyOperation propertyOperation) {
- return new GroupTypeOperation(titanGenricDao, propertyOperation);
- }
-
- @Bean(name = "attribute-operation")
- public AttributeOperation attributeOperation() {
- return new AttributeOperation();
- }
-
- @Bean(name = "titanFixUtils")
- public TitanFixUtils titanFixUtils() {
- return new TitanFixUtils();
- }
-
- @Bean(name = "populateComponentCache")
- public PopulateComponentCache populateComponentCache() {
- return new PopulateComponentCache();
- }
-
- @Bean(name = "artifact-cassandra-dao")
- public ArtifactCassandraDao artifactCassandraDao() {
- return new ArtifactCassandraDao();
- }
-
- @Bean(name = "component-cassandra-dao")
- public ComponentCassandraDao componentCassandraDao() {
- return new ComponentCassandraDao();
- }
-
- @Bean(name = "cassandra-client")
- public CassandraClient cassandraClient() {
- return new CassandraClient();
- }
-
- @Bean(name = "cacheManger-operation")
- public CacheMangerOperation cacheMangerOperation() {
- return new CacheMangerOperation();
- }
-
- @Bean(name = "component-cache")
- public ComponentCache componentCache() {
- return new ComponentCache();
- }
-
- @Bean(name = "input-operation")
- public InputsOperation inputsOperation() {
- return new InputsOperation();
- }
-
- /**
- * Returns new instance of AuditCassandraDao
- *
- * @return
- */
- @Bean(name = "audit-cassandra-dao")
- public AuditCassandraDao auditCassandraDao() {
- return new AuditCassandraDao();
- }
-
- /**
- * Returns new instance of UserBusinessLogic
- *
- * @return
- */
- @Bean(name = "userBusinessLogic")
- public IUserBusinessLogic userBusinessLogic() {
- return new UserBusinessLogic();
- }
-
- /**
- * Returns new instance of UserAdminOperation
- *
- * @return
- */
- @Bean(name = "user-operation")
- @Primary
- public IUserAdminOperation userOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
- return new UserAdminOperation(titanGenericDao);
- }
-
- /**
- * Returns new instance of GraphLockOperation
- *
- * @return
- */
- @Bean(name = "graph-lock-operation")
- public IGraphLockOperation graphLockOperation() {
- return new GraphLockOperation();
- }
-
- /**
- * Returns new instance of AuditingDao
- *
- * @return
- */
- @Bean(name = "auditingDao")
- public AuditingDao auditingDao() {
- return new AuditingDao();
- }
-
- /**
- * Returns new instance of AuditingManager
- *
- * @return
- */
- @Bean(name = "auditingManager")
- public IAuditingManager auditingManager() {
- return new AuditingManager();
- }
-
- /**
- * Returns new instance of ServiceBusinessLogic
- *
- * @return
- */
- @Bean(name = "serviceBusinessLogic")
- public ServiceBusinessLogic serviceBusinessLogic() {
- return new ServiceBusinessLogic();
- }
-
- /**
- * Returns new instance of ComponentsUtils
- *
- * @return
- */
- @Bean(name = "componentUtils")
- public ComponentsUtils componentUtils() {
- return new ComponentsUtils();
- }
-
- /**
- * Returns new instance of ToscaArtifactsAlignment
- *
- * @return
- */
- @Bean(name = "toscaArtifactsAlignment")
- public ToscaArtifactsAlignment toscaArtifactsAlignment() {
- return new ToscaArtifactsAlignment();
- }
-
- /**
- * Returns new instance of ArtifactsBusinessLogic
- *
- * @return
- */
- @Bean(name = "artifactBusinessLogic")
- public ArtifactsBusinessLogic artifactBusinessLogic() {
- return new ArtifactsBusinessLogic();
- }
-
- /**
- * Returns new instance of ResourceBusinessLogic
- *
- * @return
- */
- @Bean(name = "resourceBusinessLogic")
- public ResourceBusinessLogic resourceBusinessLogic() {
- return new ResourceBusinessLogic();
- }
-
- /**
- * Returns new instance of LifecycleBusinessLogic
- *
- * @return
- */
- @Bean(name = "lifecycleBusinessLogic")
- public LifecycleBusinessLogic lifecycleBusinessLogic() {
- return new LifecycleBusinessLogic();
- }
-
- /**
- * Returns new instance of ServiceDistributionArtifactsBuilder
- *
- * @return
- */
- @Bean(name = "serviceDistributionArtifactsBuilder")
- public ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder() {
- return new ServiceDistributionArtifactsBuilder();
- }
-
- /**
- * Returns new instance of DistributionEngine
- *
- * @return
- */
- @Bean(name = "distributionEngine")
- public IDistributionEngine distributionEngine() {
- // This dependency is needed for initializing context but is not used
- return null;
- }
-
- /**
- * Returns new instance of ElasticSearchClient
- *
- * @return
- */
- @Bean(name = "elasticsearch-client")
- public ElasticSearchClient elasticsearchClient() {
- // This dependency is needed for initializing context but is not used
- return null;
- }
-
- /**
- * Returns new instance of ProductBusinessLogic
- *
- * @return
- */
- @Bean(name = "productBusinessLogic")
- public ProductBusinessLogic productBusinessLogic() {
- return new ProductBusinessLogic();
- }
-
- /**
- * Returns new instance of ProductComponentInstanceBusinessLogic
- *
- * @return
- */
- @Bean(name = "productComponentInstanceBusinessLogic")
- public ProductComponentInstanceBusinessLogic productComponentInstanceBusinessLogic() {
- return new ProductComponentInstanceBusinessLogic();
- }
-
- /**
- * Returns new instance of ToscaExportHandler
- *
- * @return
- */
- @Bean(name = "tosca-export-handler")
- public ToscaExportHandler toscaExportHandler() {
- return new ToscaExportHandler();
- }
-
- /**
- * Returns new instance of CsarOperation
- *
- * @return
- */
- @Bean(name = "csar-operation")
- public CsarOperation csarOperation() {
- return new CsarOperation();
- }
-
- /**
- * Returns new instance of OnboardingClient
- *
- * @return
- */
- @Bean(name = "onboarding-client")
- public OnboardingClient onboardingClient() {
- return new OnboardingClient();
- }
-
- /**
- * Returns new instance of VFComponentInstanceBusinessLogic
- *
- * @return
- */
- @Bean(name = "vfComponentInstanceBusinessLogic")
- public VFComponentInstanceBusinessLogic vfComponentInstanceBusinessLogic() {
- return new VFComponentInstanceBusinessLogic();
- }
-
- /**
- * Returns new instance of ResourceImportManager
- *
- * @return
- */
- @Bean(name = "resourceImportManager")
- public ResourceImportManager resourceImportManager() {
- return new ResourceImportManager();
- }
-
- /**
- * Returns new instance of GroupBusinessLogic
- *
- * @return
- */
- @Bean(name = "groupBusinessLogic")
- public GroupBusinessLogic groupBusinessLogic() {
- return new GroupBusinessLogic();
- }
-
- /**
- * Returns new instance of InputsBusinessLogic
- *
- * @return
- */
- @Bean(name = "inputsBusinessLogic")
- public InputsBusinessLogic inputsBusinessLogic() {
- return new InputsBusinessLogic();
- }
-
- /**
- * Returns new instance of CompositionBusinessLogic
- *
- * @return
- */
- @Bean(name = "compositionBusinessLogic")
- public CompositionBusinessLogic compositionBusinessLogic() {
- return new CompositionBusinessLogic();
- }
-
- /**
- * Returns new instance of CsarUtils
- *
- * @return
- */
- @Bean(name = "csar-utils")
- public CsarUtils csarUtils() {
- return new CsarUtils();
- }
-
- /**
- * Returns new instance of ServiceComponentInstanceBusinessLogic
- *
- * @return
- */
- @Bean(name = "serviceComponentInstanceBusinessLogic")
- public ServiceComponentInstanceBusinessLogic serviceComponentInstanceBusinessLogic() {
- return new ServiceComponentInstanceBusinessLogic();
- }
- /**
- *
- * @return new instance of migration1702
- */
- @Bean(name = "migration1702")
- public Migration1702 migration1702() {
- return new Migration1702();
- }
-
-
- @Bean(name = "migrationUtils")
- public MigrationOperationUtils migrationUtils() {
- return new MigrationOperationUtils();
- }
-
- @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 = "migration1707UuidFix")
- public Migration1707ArtifactUuidFix migration1707ArtifactUuidFix() {
- return new Migration1707ArtifactUuidFix();
- }
-
-
-// @Bean(name = "migration1707relationsFix")
-// public Migration1707RelationsFix migration1707RelationsFix() {
-// return new Migration1707RelationsFix();
-// }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/DerivedFromAlignment.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/DerivedFromAlignment.java
deleted file mode 100644
index c1ddc4fee0..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/DerivedFromAlignment.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1604;
-
-import java.io.BufferedReader;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
-import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-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.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import fj.data.Either;
-
-public class DerivedFromAlignment {
- private static Logger log = LoggerFactory.getLogger(VfcNamingAlignment.class.getName());
- private Map<String, String> newDerivedFromValuesHM = new HashMap<String, String>();
- @Autowired
- protected TitanGenericDao titanGenericDao;
-
- public boolean alignDerivedFrom1604(String appConfigDir, String dataInputFileDir) {
- log.debug("Started alignDerivedFrom1604 procedure..");
- boolean result = false;
- try {
- if (!getDerivedFromValuesFromFile(dataInputFileDir)) {
- log.error("Started alignDerivedFrom1604 procedure was failed. Missing data in the input data file.");
- return result;
- }
- result = changeDerivedFrom();
- } finally {
- if (!result) {
- titanGenericDao.rollback();
- log.debug("**********************************************");
- log.debug("alignDerivedFrom1604 procedure FAILED!!");
- log.debug("**********************************************");
- } else {
- titanGenericDao.commit();
- log.debug("**********************************************");
- log.debug("alignDerivedFrom1604 procedure ended successfully!");
- log.debug("**********************************************");
- }
- }
- return result;
- }
-
- private boolean changeDerivedFrom() {
- Map<String, ResourceMetadataData> resourcesHM = getLatestVersionsOfResources();
- if (resourcesHM == null)
- return false;
- Map<String, ResourceMetadataData> derivedFromResourcesHM = getLatestCertifiedVersionsOfDerivedFromResources();
- if (derivedFromResourcesHM == null)
- return false;
- return updateEdges(resourcesHM, derivedFromResourcesHM);
- }
-
- private boolean updateEdges(Map<String, ResourceMetadataData> resourcesHM,
- Map<String, ResourceMetadataData> derivedFromResourcesHM) {
- log.debug("Updating of Edges has been started..");
- for (Entry<String, ResourceMetadataData> pair : resourcesHM.entrySet()) {
- ResourceMetadataData curResource = pair.getValue();
- String uniqeID = (String) curResource.getUniqueId();
- Either<ImmutablePair<ResourceMetadataData, GraphEdge>, TitanOperationStatus> parentResourceRes = titanGenericDao
- .getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), uniqeID,
- GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Resource, ResourceMetadataData.class);
- if (parentResourceRes.isLeft()) {
- ImmutablePair<ResourceMetadataData, GraphEdge> value = parentResourceRes.left().value();
- ResourceMetadataData parentResourceData = value.getKey();
- log.debug("Deleting old relation..");
- Either<GraphRelation, TitanOperationStatus> deletingRelationRes = titanGenericDao
- .deleteRelation(curResource, parentResourceData, GraphEdgeLabels.DERIVED_FROM);
- if (deletingRelationRes.isRight()) {
- log.error("Couldn't delete relation from resource {} to resource {}, error: {}",
- curResource.getMetadataDataDefinition().getName(),
- parentResourceData.getMetadataDataDefinition().getName(),
- deletingRelationRes.right().value());
- return false;
- }
- ResourceMetadataData newDerivedFromResource = derivedFromResourcesHM.get(pair.getKey());
- Either<GraphRelation, TitanOperationStatus> creatingRelationRes = titanGenericDao
- .createRelation(curResource, newDerivedFromResource, GraphEdgeLabels.DERIVED_FROM, null);
- if (creatingRelationRes.isRight()) {
- log.error("Couldn't create relation from resource {} to resource {}, error: {}",
- curResource.getMetadataDataDefinition().getName(),
- newDerivedFromResource.getMetadataDataDefinition().getName(),
- creatingRelationRes.right().value());
- return false;
- }
- } else {
- log.error("Couldn't get derived from resource for child resource {}, error: {}", pair.getKey(),
- parentResourceRes.right().value());
- return false;
- }
- }
- return true;
- }
-
- private Map<String, ResourceMetadataData> getLatestCertifiedVersionsOfDerivedFromResources() {
- log.debug("Getting latest certified versions of derived from resources according input file");
- Map<String, ResourceMetadataData> resourcesHM = new HashMap<String, ResourceMetadataData>();
- Map<String, Object> props = null;
- for (Entry<String, String> pair : newDerivedFromValuesHM.entrySet()) {
- props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.TOSCA_RESOURCE_NAME.getProperty(), pair.getValue());
- props.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
- Either<List<ResourceMetadataData>, TitanOperationStatus> highestVersionResource = titanGenericDao
- .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
- if (highestVersionResource.isRight()) {
- log.error("Couldn't get resource {} from DB, error: {}", pair.getValue(),
- highestVersionResource.right().value());
- return null;
- }
- List<ResourceMetadataData> highestVersionResourceAL = highestVersionResource.left().value();
- if (highestVersionResourceAL == null) {
- log.error("Couldn't get resource {}. No resource found", pair.getValue());
- return null;
- }
- ResourceMetadataData resource = highestVersionResourceAL.get(0);
- String state = resource.getMetadataDataDefinition().getState();
- if (!state.equals(LifecycleStateEnum.CERTIFIED.name())) {
- log.error(
- "alignDerivedFrom1604 procedure FAILED!! Derived from resource {} is not certified. Please certify manually and repeat the procedure.",
- pair.getValue());
- return null;
- }
- resourcesHM.put(pair.getKey(), resource);
- }
- return resourcesHM;
- }
-
- private Map<String, ResourceMetadataData> getLatestVersionsOfResources() {
- log.debug("Getting latest versions of resources according input file");
- Map<String, ResourceMetadataData> resourcesHM = new HashMap<String, ResourceMetadataData>();
- ResourceMetadataData foundResource = null;
- Map<String, Object> props = null;
- for (Entry<String, String> pair : newDerivedFromValuesHM.entrySet()) {// filter
- props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.NAME.getProperty(), pair.getKey());
- props.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
-
- Either<List<ResourceMetadataData>, TitanOperationStatus> highestVersionResource = titanGenericDao
- .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
- if (highestVersionResource.isRight()) {
- log.error("Couldn't get resource {} from DB, error: {}", pair.getKey(),
- highestVersionResource.right().value());
- return null;
- }
- List<ResourceMetadataData> highestVersionResourceAL = highestVersionResource.left().value();
- if (highestVersionResourceAL == null) {
- log.error("Couldn't get resource {}. No resource found", pair.getKey());
- return null;
- }
- if (highestVersionResourceAL.size() > 2) {
- log.error("Invalid response. Found more than two highest version resources with name {}.",
- pair.getKey());
- return null;
- }
- foundResource = highestVersionResourceAL.get(0);
- if (highestVersionResourceAL.size() == 2) {
- foundResource = foundResource.getMetadataDataDefinition().getState()
- .equals(LifecycleStateEnum.CERTIFIED.name()) ? highestVersionResourceAL.get(1) : foundResource;
- }
- resourcesHM.put(pair.getKey(), foundResource);
- }
- return resourcesHM;
- }
-
- private boolean getDerivedFromValuesFromFile(String dataInputFileDir) {
- BufferedReader br = null;
- String curPair = null;
- try {
- br = new BufferedReader(new FileReader(dataInputFileDir));
- while ((curPair = br.readLine()) != null) {
- String[] pair = curPair.split(" ");
- if (pair.length < 2) {
- log.error(
- "Expected at least two tokens in every line. Usage: <resource_name> <new_derived_from_name>");
- return false;
- }
- String derivedFrom = pair[pair.length - 1];
- String name = curPair.substring(0, curPair.length() - derivedFrom.length() - 1);
- newDerivedFromValuesHM.put(name, derivedFrom);
- }
- return true;
- } catch (FileNotFoundException e) {
- log.error("Started alignDerivedFrom1604 procedure was failed. Missing input data file.", e);
- } catch (IOException e) {
- log.error("Started alignDerivedFrom1604 procedure was failed. The input data file is empty.", e);
- } finally {
- if (br != null) {
- try {
- br.close();
- } catch (IOException e) {
- log.debug("failed to close file reader", e);
- }
- }
- }
- return false;
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/GroupsAlignment.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/GroupsAlignment.java
deleted file mode 100644
index aebcddfee2..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/GroupsAlignment.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1604;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.GroupDefinition;
-import org.openecomp.sdc.be.model.GroupTypeDefinition;
-import org.openecomp.sdc.be.model.operations.api.IArtifactOperation;
-import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
-import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import fj.data.Either;
-
-public class GroupsAlignment {
-
- private static Logger log = LoggerFactory.getLogger(ServiceMigration.class.getName());
-
- public static String INITIAL_VERSION = "1.0";
- private static final String DEFAULT_GROUP_VF_MODULE = "org.openecomp.groups.VfModule";
- private static final String MODULE = "::module-";
-
- @Autowired
- protected TitanGenericDao titanGenericDao;
- @Autowired
- protected IArtifactOperation artifactOperation;
- @Autowired
- protected IGroupOperation groupOperation;
- @Autowired
- protected GroupTypeOperation groupTypeOperation;
-
- public boolean alignGroups(String appConfigDir) {
-
- log.debug("Started the align groups procedure ...");
- log.debug("Getting all resources with resources");
- boolean result = false;
- try {
-
- Map<String, Object> properties = new HashMap<>();
- properties.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name());
- Either<List<ResourceMetadataData>, TitanOperationStatus> allVfResources = titanGenericDao
- .getByCriteria(NodeTypeEnum.Resource, properties, ResourceMetadataData.class);
-
- if (allVfResources.isRight()) {
- log.error("Couldn't get VF resources from DB, error: {}", allVfResources.right().value());
- result = false;
- return result;
- }
- List<ResourceMetadataData> resourcesList = allVfResources.left().value();
- if (resourcesList == null) {
- log.error("Couldn't get VF resources from DB, no resources found");
- result = false;
- return result;
- }
- log.debug("Found {} VF resources", resourcesList.size());
- for (ResourceMetadataData resource : resourcesList) {
- result = createGroupIfContainsArtifacts(resource);
- }
- } finally {
- if (!result) {
- titanGenericDao.rollback();
- log.debug("**********************************************");
- log.debug("The align groups procedure FAILED!!");
- log.debug("**********************************************");
- } else {
- titanGenericDao.commit();
- log.debug("**********************************************");
- log.debug("The align groups procedure ended successfully!");
- log.debug("**********************************************");
- }
- }
-
- return result;
- }
-
- private boolean createGroupIfContainsArtifacts(ResourceMetadataData resource) {
-
- String uniqueId = resource.getMetadataDataDefinition().getUniqueId();
- StorageOperationStatus result = StorageOperationStatus.OK;
- Either<Map<String, ArtifactDefinition>, StorageOperationStatus> allArtifactsRes = artifactOperation
- .getArtifacts(uniqueId, NodeTypeEnum.Resource, true);
- if (allArtifactsRes.isRight()) {
- log.error("Couldn't get resource artifacts from DB, error: {}", allArtifactsRes.right().value());
- return false;
- }
- Map<String, ArtifactDefinition> artifactsHM = allArtifactsRes.left().value();
- ArrayList<String> foundArtifactsAL = new ArrayList<String>();
- for (ArtifactDefinition curArtifact : artifactsHM.values()) {
- String atrifactType = curArtifact.getArtifactType();
- if (atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())
- || atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType())
- || atrifactType.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType())) {
- foundArtifactsAL.add(curArtifact.getUniqueId());
- }
- }
- if (foundArtifactsAL.size() > 0) {
- Either<List<GroupDefinition>, TitanOperationStatus> allGroupsRes = groupOperation
- .getAllGroupsFromGraph(uniqueId, NodeTypeEnum.Resource);
- int groupCounter = 1;
- if (allGroupsRes.isRight()) {
- if (allGroupsRes.right().value().name().equals(TitanOperationStatus.OK.name())
- || allGroupsRes.right().value().name().equals(TitanOperationStatus.NOT_FOUND.name())) {
- log.debug("Not found groups resource related to resource {}, response: {}",
- resource.getMetadataDataDefinition().getName(), allGroupsRes.right().value());
- } else {
- log.error("Not found groups resource related to resource {}, DB error: {}",
- resource.getMetadataDataDefinition().getName(), allGroupsRes.right().value());
- return false;
- }
- } else if (allGroupsRes.left().value() != null && allGroupsRes.left().value().size() > 0) {
- groupCounter += allGroupsRes.left().value().size();
- for (GroupDefinition curGroup : allGroupsRes.left().value()) {
- for (String curGroupArtifact : curGroup.getArtifacts()) {
- if (foundArtifactsAL.contains(curGroupArtifact)) {
- foundArtifactsAL.remove(curGroupArtifact);
- }
- }
- }
- }
- if (foundArtifactsAL.size() > 0) {
- GroupDefinition groupDefinition = new GroupDefinition();
- groupDefinition.setName(resource.getMetadataDataDefinition().getName() + MODULE + groupCounter);
- groupDefinition.setType(DEFAULT_GROUP_VF_MODULE);
- groupDefinition.setArtifacts(foundArtifactsAL);
- log.debug("Creating new group {} for VF resource {}", groupDefinition.getName(),
- resource.getMetadataDataDefinition().getName());
- return createGroup(resource.getUniqueId(), ComponentTypeEnum.RESOURCE, groupDefinition);
-
- }
- }
- return true;
- }
-
- private boolean createGroup(Object uniqueId, ComponentTypeEnum componentType, GroupDefinition groupDefinition) {
-
- NodeTypeEnum nodeTypeEnum = componentType.getNodeType();
- String groupType = groupDefinition.getType();
-
- Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeRes = groupTypeOperation
- .getLatestGroupTypeByType(groupType, true);
- if (getGroupTypeRes.isRight()) {
- log.error("Couldn't get grouptype by type {} from DB, error: {}", groupType,
- getGroupTypeRes.right().value());
- return false;
- }
-
- GroupTypeDefinition groupTypeDefinition = getGroupTypeRes.left().value();
-
- String invariantUUID = UniqueIdBuilder.buildInvariantUUID();
- groupDefinition.setInvariantUUID(invariantUUID);
- groupDefinition.setVersion(INITIAL_VERSION);
- groupDefinition.setTypeUid(groupTypeDefinition.getUniqueId());
-
- Either<GroupDefinition, StorageOperationStatus> addGroupToGraphRes = groupOperation.addGroup(nodeTypeEnum,
- (String) uniqueId, groupDefinition, true);
-
- if (addGroupToGraphRes.isRight()) {
- log.error("Couldn't add group {} to graph, error: {}", groupDefinition.getName(),
- addGroupToGraphRes.right().value());
- return false;
- }
- log.debug("The group {} has been created", groupDefinition.getName());
- return true;
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/MigrationCategory.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/MigrationCategory.java
deleted file mode 100644
index 5605f0980d..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/MigrationCategory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1604;
-
-import java.util.List;
-
-import org.openecomp.sdc.be.datatypes.category.CategoryDataDefinition;
-
-public class MigrationCategory extends CategoryDataDefinition {
- private String oldName;
-
- List<MigrationSubCategory> subcategories;
-
- public String getOldName() {
- return oldName;
- }
-
- public void setOldName(String oldName) {
- this.oldName = oldName;
- }
-
- public List<MigrationSubCategory> getSubcategories() {
- return subcategories;
- }
-
- public void setSubcategories(List<MigrationSubCategory> subcategories) {
- this.subcategories = subcategories;
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/MigrationSubCategory.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/MigrationSubCategory.java
deleted file mode 100644
index f1886622be..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/MigrationSubCategory.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1604;
-
-import org.openecomp.sdc.be.datatypes.category.SubCategoryDataDefinition;
-
-public class MigrationSubCategory extends SubCategoryDataDefinition {
- private String oldName;
-
- public String getOldName() {
- return oldName;
- }
-
- public void setOldName(String oldName) {
- this.oldName = oldName;
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/ServiceMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/ServiceMigration.java
deleted file mode 100644
index 0ef435e1c3..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/ServiceMigration.java
+++ /dev/null
@@ -1,1515 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1604;
-
-import static java.nio.file.Files.readAllBytes;
-import static java.nio.file.Paths.get;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.commons.lang3.tuple.ImmutablePair;
-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.api.ActionStatus;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
-import org.openecomp.sdc.be.dao.graph.datatype.RelationEndPoint;
-import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
-import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary;
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.RequirementDefinition;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.User;
-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.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.AdditionalInformationOperation;
-import org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation;
-import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
-import org.openecomp.sdc.be.model.operations.impl.LifecycleOperation;
-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.ResourceOperation;
-import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
-import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.resources.data.CapabilityData;
-import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
-import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
-import org.openecomp.sdc.be.resources.data.ProductMetadataData;
-import org.openecomp.sdc.be.resources.data.RelationshipInstData;
-import org.openecomp.sdc.be.resources.data.RequirementData;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.be.resources.data.ServiceMetadataData;
-import org.openecomp.sdc.be.resources.data.TagData;
-import org.openecomp.sdc.be.resources.data.category.CategoryData;
-import org.openecomp.sdc.be.resources.data.category.SubCategoryData;
-import org.openecomp.sdc.be.utils.CommonBeUtils;
-import org.openecomp.sdc.common.util.ValidationUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.yaml.snakeyaml.Yaml;
-
-import com.thinkaurelius.titan.core.TitanEdge;
-import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.core.TitanVertex;
-
-import fj.data.Either;
-
-public class ServiceMigration {
-
- private static final String[] NORMATIVE_OLD_NAMES = { "tosca.nodes.network.Network", "tosca.nodes.network.Port", "tosca.nodes.BlockStorage", "tosca.nodes.Compute", "tosca.nodes.Container.Application", "tosca.nodes.Container.Runtime",
- "tosca.nodes.Database", "tosca.nodes.DBMS", "tosca.nodes.LoadBalancer", "tosca.nodes.ObjectStorage", "tosca.nodes.Root", "tosca.nodes.SoftwareComponent", "tosca.nodes.WebApplication", "tosca.nodes.WebServer", };
-
- private static Logger log = LoggerFactory.getLogger(ServiceMigration.class.getName());
-
- @Autowired
- protected TitanGenericDao titanGenericDao;
- @Autowired
- protected ResourceOperation resourceOperation;
- @Autowired
- protected ServiceOperation serviceOperation;
- @Autowired
- protected ProductOperation productOperation;
- @Autowired
- protected LifecycleOperation lifecycleOperaion;
- @Autowired
- protected PropertyOperation propertyOperation;
- @Autowired
- protected AdditionalInformationOperation additionalInformationOperation;
- @Autowired
- protected ComponentInstanceOperation componentInstanceOperaion;
- @Autowired
- protected IElementOperation elementOperation;
-
- public boolean migrate1602to1604(String appConfigDir) {
-
- boolean result = false;
-
- try {
-
- if (!addResourceCounterToResources()) {
- log.debug("Failed to update resource instance counter on resources");
- result = false;
- return result;
- }
- if (!updateComponentInstanceType()) {
- log.debug("Failed to update component instance type");
- result = false;
- return result;
- }
- // fix VF
- if (!fixDerivedVf()) {
- log.debug("Failed to fix VFs");
- result = false;
- return result;
- }
- // update instances and relation
- if (!updateCalculatedEdges()) {
- log.debug("Failed to update calculated edges for VF instances");
- result = false;
- return result;
- }
- // update instances and relation
- if (!updateRelations()) {
- log.debug("Failed to update Instance And Relations in services");
- result = false;
- return result;
- }
- if (!updateCategories(appConfigDir)) {
- log.debug("Failed to update categories");
- result = false;
- return result;
- }
-
- if (!AllowMultipleHeats.removeAndUpdateHeatPlaceHolders(titanGenericDao, log, true)) {
- log.error("Failed to update heat place holders");
- result = false;
- return result;
- }
-
- if (!AddGroupUuid.addGroupUuids(titanGenericDao, log, true)) {
- log.error("Failed to update group UUIDs");
- result = false;
- return result;
- }
-
- result = true;
- } finally {
- if (!result) {
- titanGenericDao.rollback();
- } else {
- titanGenericDao.commit();
- }
- }
- return result;
- }
-
- private boolean updateCategories(String appConfigDir) {
- // String categoryMigrationFile = appConfigDir + File.separator +
- // "categoryMigration.yaml";
- String categoryMigrationFile = appConfigDir + "categoryMigration.yaml";
-
- Map<String, List<MigrationCategory>> categoriesFromYml;
- try {
- categoriesFromYml = createCategoriesFromYml(categoryMigrationFile);
- if (categoriesFromYml == null || categoriesFromYml.isEmpty()) {
- log.debug("updateCategories failed to load categories form migration file {}", categoryMigrationFile);
- return false;
- }
- } catch (Exception e) {
- log.debug("Failed to load category migration file : {}", categoryMigrationFile, e);
- return false;
- }
- for (Map.Entry<String, List<MigrationCategory>> entry : categoriesFromYml.entrySet()) {
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(entry.getKey());
- if (componentType != null) {
- switch (componentType) {
- case RESOURCE:
- if (updateResourceCategories(entry.getValue()) == false) {
- log.debug("updateCategories failed to update resource categories");
- return false;
- }
- break;
- case SERVICE:
- if (updateServiceCategories(entry.getValue()) == false) {
- log.debug("updateCategories failed to update service categories");
- return false;
- }
- break;
- default:
- log.debug("updateCategories no changes for categories from type {}", componentType);
- }
- } else {
- log.debug("updateCategories failed not supported component file in migration categories file" + entry.getKey());
- return false;
- }
- }
- return true;
- }
-
- private boolean updateServiceCategories(List<MigrationCategory> categories) {
- log.debug("updateServiceCategories STARTED");
- Either<List<CategoryDefinition>, ActionStatus> serviceCategories = elementOperation.getAllCategories(NodeTypeEnum.ServiceNewCategory, true);
- if (serviceCategories.isRight()) {
- log.debug("updateServiceCategories failed fetch all service categories ,error " + serviceCategories.right().value());
- return false;
- }
- for (MigrationCategory newCat : categories) {
-
- if (newCat.getOldName() == null) {
- // add new
- boolean exist = false;
- for (CategoryDefinition catInDB : serviceCategories.left().value()) {
- if (newCat.getName().equals(catInDB.getName())) {
- exist = true;
- break;
- }
- }
- if (!exist) {
- CategoryDefinition categoryDefinition = new CategoryDefinition(newCat);
- Either<CategoryDefinition, ActionStatus> result = elementOperation.createCategory(categoryDefinition, NodeTypeEnum.ServiceNewCategory, true);
- if (result.isRight()) {
- log.debug("Failed to create service category {} error {}", categoryDefinition, result.right().value());
- return false;
- }
- log.debug("service category {} created", categoryDefinition);
- }
- } else {
- // update exist
- for (CategoryDefinition catInDB : serviceCategories.left().value()) {
- if (newCat.getOldName().equals(catInDB.getName())) {
- Either<CategoryData, TitanOperationStatus> updateSingleResult = updateSingleResourceCategory(newCat, NodeTypeEnum.ServiceNewCategory);
- if (updateSingleResult.isRight()) {
- return false;
- }
- break;
- }
- }
- }
- }
- log.debug("updateServiceCategories ENDED");
- return true;
- }
-
- private Either<CategoryData, TitanOperationStatus> updateSingleResourceCategory(MigrationCategory newCat, NodeTypeEnum nodetype) {
- Map<String, Object> properties = new HashMap<>();
- properties.put(GraphPropertiesDictionary.NAME.getProperty(), newCat.getOldName());
- Either<List<CategoryData>, TitanOperationStatus> categoryEither = titanGenericDao.getByCriteria(nodetype, properties, CategoryData.class);
- if (categoryEither.isRight() && categoryEither.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Failed to get {} categories, for name {} error {}", nodetype, newCat.getOldName(), categoryEither.right().value());
- return Either.right(categoryEither.right().value());
- }
- List<CategoryData> categoryList = (categoryEither.isLeft() ? categoryEither.left().value() : null);
- if (categoryList == null) {
- log.debug("No {} categories, for name {} error {}", nodetype, newCat.getOldName());
- return Either.right(TitanOperationStatus.NOT_FOUND);
- }
- CategoryData categoryData = categoryList.get(0);
- categoryData.getCategoryDataDefinition().setName(newCat.getName());
- categoryData.getCategoryDataDefinition().setIcons(newCat.getIcons());
- categoryData.getCategoryDataDefinition().setNormalizedName(ValidationUtils.normalizeCategoryName4Uniqueness(newCat.getName()));
- Either<CategoryData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(categoryData, CategoryData.class);
- if (updateNode.isRight()) {
- log.debug("Failed to update {} category {} error {}", nodetype, categoryData, updateNode.right().value());
- return Either.right(updateNode.right().value());
- }
- log.debug("Update {} category {} ", nodetype, categoryData);
- return Either.left(updateNode.left().value());
- }
-
- private boolean updateResourceCategories(List<MigrationCategory> categories) {
- log.debug("updateResourceCategories STARTED");
- Either<List<CategoryDefinition>, ActionStatus> resourceCategories = elementOperation.getAllCategories(NodeTypeEnum.ResourceNewCategory, true);
- if (resourceCategories.isRight()) {
- log.debug("updateResourceCategories failed fetch all resource categories ,error " + resourceCategories.right().value());
- return false;
- }
- for (MigrationCategory newCat : categories) {
- if (newCat.getOldName() == null) {
- // add new
- // check if already created in previous running
- boolean exist = false;
- for (CategoryDefinition catInDB : resourceCategories.left().value()) {
- if (newCat.getName().equals(catInDB.getName())) {
- exist = true;
- }
- }
- if (!exist) {
- CategoryDefinition categoryDefinition = new CategoryDefinition(newCat);
- Either<CategoryDefinition, ActionStatus> resultCat = elementOperation.createCategory(categoryDefinition, NodeTypeEnum.ResourceNewCategory, true);
- if (resultCat.isRight()) {
- log.debug("Failed to create resource category {} error {}", categoryDefinition, resultCat.right().value());
- return false;
- }
- log.debug("resource category {} created", categoryDefinition);
-
- List<MigrationSubCategory> nSubCat = newCat.getSubcategories();
- List<MigrationSubCategory> newSubcat = nSubCat;
- List<MigrationSubCategory> subcategories = newSubcat;
- for (MigrationSubCategory msubcat : subcategories) {
- SubCategoryDefinition subcat = new SubCategoryDefinition(msubcat);
- Either<SubCategoryDefinition, ActionStatus> resultSubcat = elementOperation.createSubCategory(resultCat.left().value().getUniqueId(), subcat, NodeTypeEnum.ResourceSubcategory, true);
- if (resultSubcat.isRight()) {
- log.debug("Failed to create resource sub category {} error {}", subcat, resultSubcat.right().value());
- return false;
- }
- log.debug("resource sub category {} created for category {}", categoryDefinition, resultCat.left().value().getName());
- }
- }
- } else {
- // update exist
- for (CategoryDefinition catInDB : resourceCategories.left().value()) {
- if (newCat.getOldName().equals(catInDB.getName())) {
- Either<CategoryData, TitanOperationStatus> updateSingleResult = updateSingleResourceCategory(newCat, NodeTypeEnum.ResourceNewCategory);
- if (updateSingleResult.isRight()) {
- return false;
- }
-
- CategoryData categoryData = updateSingleResult.left().value();
- for (MigrationSubCategory migSubCat : newCat.getSubcategories()) {
- if (migSubCat.getOldName() == null) {
- // create new one
- boolean existSub = false;
- for (SubCategoryDefinition subCatInDb : catInDB.getSubcategories()) {
- if (subCatInDb.getName().equals(migSubCat.getName())) {
- existSub = true;
- }
- }
- if (!existSub) {
- SubCategoryDefinition subcat = new SubCategoryDefinition(migSubCat);
-
- Either<SubCategoryDefinition, ActionStatus> resultSubcat = elementOperation.createSubCategory((String) categoryData.getUniqueId(), subcat, NodeTypeEnum.ResourceSubcategory, true);
- if (resultSubcat.isRight()) {
- log.debug("Failed to create resource sub category {} error {}", subcat, resultSubcat.right().value());
- return false;
- }
- log.debug("resource sub category {} created for category {}", categoryData, resultSubcat.left().value().getName());
- }
- } else {
- if (updateSingleSubCategory(newCat, migSubCat, updateSingleResult.left().value()) == false) {
- return false;
- }
- }
- }
- break;
- }
- }
- }
- }
- return true;
- }
-
- private boolean updateSingleSubCategory(MigrationCategory newCat, MigrationSubCategory migSubCat, CategoryData categoryData) {
-
- Either<List<ImmutablePair<SubCategoryData, GraphEdge>>, TitanOperationStatus> subcategories = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceNewCategory), (String) categoryData.getUniqueId(),
- GraphEdgeLabels.SUB_CATEGORY, NodeTypeEnum.ResourceSubcategory, SubCategoryData.class);
-
- if (subcategories.isRight()) {
- log.debug("Failed to get resource sub categories, for name {} error {}", newCat.getOldName(), subcategories.right().value());
- return false;
- }
-
- for (ImmutablePair<SubCategoryData, GraphEdge> pair : subcategories.left().value()) {
- if (pair.getKey().getSubCategoryDataDefinition().getName().equals(migSubCat.getOldName())) {
- SubCategoryData subCategoryData = pair.getKey();
- subCategoryData.getSubCategoryDataDefinition().setName(migSubCat.getName());
- subCategoryData.getSubCategoryDataDefinition().setIcons(migSubCat.getIcons());
- subCategoryData.getSubCategoryDataDefinition().setNormalizedName(ValidationUtils.normalizeCategoryName4Uniqueness(migSubCat.getName()));
- Either<SubCategoryData, TitanOperationStatus> updateSubNode = titanGenericDao.updateNode(subCategoryData, SubCategoryData.class);
- if (updateSubNode.isRight()) {
- log.debug("Failed to update resource sub category {} error {}", subCategoryData, updateSubNode.right().value());
- return false;
- }
- log.debug("Update resource subcategory category {} ", subCategoryData);
- break;
- }
- }
- return true;
- }
-
- private Map<String, List<MigrationCategory>> createCategoriesFromYml(String categoriesTypesYml) {
- String yamlAsString;
- try {
- yamlAsString = new String(readAllBytes(get(categoriesTypesYml)));
- } catch (Exception e) {
- log.debug("Failed to load category import file exception : ", e);
- return null;
- }
-
- log.debug("received yaml: {}", yamlAsString);
-
- Map<String, Object> toscaJson = (Map<String, Object>) new Yaml().load(yamlAsString);
- Map<String, List<MigrationCategory>> allCategories = new HashMap<>();
-
- Iterator<Entry<String, Object>> categoryEntryItr = toscaJson.entrySet().iterator();
- while (categoryEntryItr.hasNext()) {
- Entry<String, Object> categoryTypeEntry = categoryEntryItr.next();
- String categoryType = categoryTypeEntry.getKey();
- List<MigrationCategory> categoriesPerType = null;
- Map<String, Object> categoryPerType = null;
- switch (categoryType) {
- case ComponentTypeEnum.SERVICE_PARAM_NAME:
- categoryPerType = (Map<String, Object>) categoryTypeEntry.getValue();
- categoriesPerType = createServiceCategories(categoryPerType);
- break;
- case ComponentTypeEnum.RESOURCE_PARAM_NAME:
- categoryPerType = (Map<String, Object>) categoryTypeEntry.getValue();
- categoriesPerType = createResourceCategories(categoryPerType);
- break;
- case ComponentTypeEnum.PRODUCT_PARAM_NAME:
- // TODO
- break;
- default:
- log.debug("Not supported category type - {}", categoryType);
- break;
- }
- if (categoriesPerType != null) {
- allCategories.put(categoryType, categoriesPerType);
- }
- }
- return allCategories;
- }
-
- private List<MigrationCategory> createServiceCategories(Map<String, Object> categories) {
- List<MigrationCategory> categroiesDef = new ArrayList<>();
- String catName = null;
- List<String> icons = null;
- String oldName = null;
- for (Entry<String, Object> entry : categories.entrySet()) {
- MigrationCategory catDef = new MigrationCategory();
- Map<String, Object> category = (Map<String, Object>) entry.getValue();
- catName = (String) category.get("name");
- catDef.setName(catName);
- icons = (List<String>) category.get("icons");
- catDef.setIcons(icons);
- String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(catName);
- catDef.setNormalizedName(normalizedName);
- oldName = (String) category.get("oldName");
- catDef.setOldName(oldName);
- categroiesDef.add(catDef);
- }
-
- return categroiesDef;
- }
-
- private List<MigrationCategory> createResourceCategories(Map<String, Object> categoryPerType) {
- List<MigrationCategory> categroiesDef = new ArrayList<>();
- for (Map.Entry<String, Object> entry : categoryPerType.entrySet()) {
- Map<String, Object> category = (Map<String, Object>) entry.getValue();
- MigrationCategory catDef = new MigrationCategory();
- String catName = (String) category.get("name");
- catDef.setName(catName);
- String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(catName);
- catDef.setNormalizedName(normalizedName);
- String oldName = (String) category.get("oldName");
- catDef.setOldName(oldName);
-
- Map<String, Object> subcategories = (Map<String, Object>) category.get("subcategories");
- List<MigrationSubCategory> subcateDef = new ArrayList<>();
- for (Entry<String, Object> subcategory : subcategories.entrySet()) {
- Map<String, Object> subcategoryInfo = (Map<String, Object>) subcategory.getValue();
- MigrationSubCategory subDef = new MigrationSubCategory();
- String subcategoryName = (String) subcategoryInfo.get("name");
- subDef.setName(subcategoryName);
- List<String> subcategoryIcons = (List<String>) subcategoryInfo.get("icons");
- subDef.setIcons(subcategoryIcons);
- normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(subcategoryName);
- subDef.setNormalizedName(normalizedName);
- oldName = (String) subcategoryInfo.get("oldName");
- subDef.setOldName(oldName);
-
- subcateDef.add(subDef);
- }
-
- catDef.setSubcategories(subcateDef);
- categroiesDef.add(catDef);
- }
- return categroiesDef;
- }
-
- private boolean updateCalculatedEdges() {
- log.debug("update calculated edges STARTED");
-
- Either<List<ComponentInstanceData>, TitanOperationStatus> allInstances = titanGenericDao.getByCriteria(NodeTypeEnum.ResourceInstance, null, ComponentInstanceData.class);
- if (allInstances.isRight() && !allInstances.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("updateCalculatedEdges failed fetch all resource instances ,error " + allInstances.right().value());
- return false;
- }
- if (allInstances.isRight() && allInstances.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("updateCalculatedEdges - no VFs");
- return true;
- }
- List<ComponentInstanceData> listOfInstances = allInstances.left().value();
- for (ComponentInstanceData instance : listOfInstances) {
- // check if already have calculated edges
- log.debug("start handle instance {}", instance.getUniqueId());
- boolean needProcess = true;
- Either<List<ImmutablePair<CapabilityData, GraphEdge>>, TitanOperationStatus> vfci = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance), instance.getUniqueId(),
- GraphEdgeLabels.CALCULATED_CAPABILITY, NodeTypeEnum.Capability, CapabilityData.class);
- if (vfci.isRight()) {
- if (!vfci.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("createCalculatedCapabilitiesForInstance failed to fetch instance for resource " + instance.getComponentInstDataDefinition().getComponentUid() + " error " + vfci.right().value());
- return false;
- }
- } else {
- if (vfci.left().value().size() > 0) {
- needProcess = false;
- }
- }
- Either<List<ImmutablePair<RequirementData, GraphEdge>>, TitanOperationStatus> vfciReq = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance), instance.getUniqueId(),
- GraphEdgeLabels.CALCULATED_REQUIREMENT, NodeTypeEnum.Requirement, RequirementData.class);
- if (vfciReq.isRight()) {
- if (!vfciReq.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("createCalculatedCapabilitiesForInstance failed to fetch instance for resource " + instance.getComponentInstDataDefinition().getComponentUid() + " error " + vfciReq.right().value());
- return false;
- }
- } else {
- if (vfciReq.left().value().size() > 0) {
- needProcess = false;
- }
- }
- Either<List<ImmutablePair<RequirementData, GraphEdge>>, TitanOperationStatus> vfciReqFF = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance), instance.getUniqueId(),
- GraphEdgeLabels.CALCULATED_REQUIREMENT_FULLFILLED, NodeTypeEnum.Requirement, RequirementData.class);
- if (vfciReqFF.isRight()) {
-
- if (!vfciReqFF.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("createCalculatedCapabilitiesForInstance failed to fetch instance for resource " + instance.getComponentInstDataDefinition().getComponentUid() + " error " + vfciReqFF.right().value());
- return false;
- }
- } else {
- if (vfciReqFF.left().value().size() > 0) {
- needProcess = false;
- }
- }
-
- if (needProcess == false) {
- log.debug("updateCalculatedEdges : for instance {} calculated capabilty/requirement already created", instance.getUniqueId());
- continue;
- }
- String originId = instance.getComponentInstDataDefinition().getComponentUid();
- Either<Resource, StorageOperationStatus> resourceE = resourceOperation.getResource(originId, true);
- if (resourceE.isRight()) {
- log.debug("updateCalculatedEdges failed to fetch origin resource with id {} error {}", originId, resourceE.right().value());
- return false;
- }
- Resource resource = resourceE.left().value();
- Map<String, List<RequirementDefinition>> requirements = resource.getRequirements();
- if (createCalculatedRequirementsForInstance(instance, requirements) != true) {
- return false;
- }
- Map<String, List<CapabilityDefinition>> capabilities = resource.getCapabilities();
- if (createCalculatedCapabilitiesForInstance(instance, capabilities) != true) {
- return false;
- }
- log.debug("finish handle instance {}", instance.getUniqueId());
- }
- log.debug("update calculated edges ENDED");
- return true;
- }
-
- private boolean createCalculatedCapabilitiesForInstance(ComponentInstanceData instance, Map<String, List<CapabilityDefinition>> capabilities) {
- for (Map.Entry<String, List<CapabilityDefinition>> entry : capabilities.entrySet()) {
- for (CapabilityDefinition capability : entry.getValue()) {
- Either<CapabilityData, TitanOperationStatus> capNode = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Capability), capability.getUniqueId(), CapabilityData.class);
- if (capNode.isRight()) {
- log.debug("createCalculatedCapabilitiesForInstance failed to fetch capability node with id " + capability.getUniqueId() + " error " + capNode.right().value());
- return false;
- }
- Map<String, Object> props = new HashMap<>();
- props.put(GraphEdgePropertiesDictionary.NAME.getProperty(), capability.getName());
- if (fillEdgeProperties(instance, props) != true) {
- return false;
- }
-
- Either<GraphRelation, TitanOperationStatus> createRelation = titanGenericDao.createRelation(instance, capNode.left().value(), GraphEdgeLabels.CALCULATED_CAPABILITY, props);
- if (createRelation.isRight()) {
- TitanOperationStatus titanOperationStatus = createRelation.right().value();
- log.debug("Failed to create calculated requirement from component instance {} to requirement {}, error: {}", instance.getUniqueId(), capNode.left().value().getUniqueId(), titanOperationStatus);
- return false;
- }
- log.debug("CALCULATED_CAPABILITY was created from {} to {} with props : {}", capNode.left().value().getUniqueId(), instance.getUniqueId(), props);
- }
- }
- return true;
- }
-
- private boolean fillEdgeProperties(ComponentInstanceData instance, Map<String, Object> props) {
- if (instance.getComponentInstDataDefinition().getOriginType().equals(OriginTypeEnum.VF)) {
- Either<List<ImmutablePair<ComponentInstanceData, GraphEdge>>, TitanOperationStatus> vfci = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource),
- instance.getComponentInstDataDefinition().getComponentUid(), GraphEdgeLabels.RESOURCE_INST, NodeTypeEnum.ResourceInstance, ComponentInstanceData.class);
- if (vfci.isRight()) {
- log.debug("createCalculatedCapabilitiesForInstance failed to fetch instance for resource " + instance.getComponentInstDataDefinition().getComponentUid() + " error " + vfci.right().value());
- return false;
- }
- ImmutablePair<ComponentInstanceData, GraphEdge> immutablePair = vfci.left().value().get(0);
- String vfciId = immutablePair.getLeft().getUniqueId();
- props.put(GraphEdgePropertiesDictionary.OWNER_ID.getProperty(), vfciId);
- props.put(GraphEdgePropertiesDictionary.SOURCE.getProperty(), immutablePair.getLeft().getComponentInstDataDefinition().getComponentUid());
-
- } else {
- props.put(GraphEdgePropertiesDictionary.OWNER_ID.getProperty(), instance.getUniqueId());
- props.put(GraphEdgePropertiesDictionary.SOURCE.getProperty(), instance.getComponentInstDataDefinition().getComponentUid());
- }
- return true;
- }
-
- private boolean createCalculatedRequirementsForInstance(ComponentInstanceData instance, Map<String, List<RequirementDefinition>> requirements) {
- for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) {
- for (RequirementDefinition requirement : entry.getValue()) {
- Either<RequirementData, TitanOperationStatus> reqNode = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Requirement), requirement.getUniqueId(), RequirementData.class);
- if (reqNode.isRight()) {
- log.debug("updateCalculatedEdges failed to fetch requirement node with id " + requirement.getUniqueId() + " error " + reqNode.right().value());
- return false;
- }
- Map<String, Object> props = new HashMap<>();
- props.put(GraphEdgePropertiesDictionary.NAME.getProperty(), requirement.getName());
-
- if (fillEdgeProperties(instance, props) != true) {
- return false;
- }
-
- Either<GraphRelation, TitanOperationStatus> createRelation = titanGenericDao.createRelation(instance, reqNode.left().value(), GraphEdgeLabels.CALCULATED_REQUIREMENT, props);
- if (createRelation.isRight()) {
- TitanOperationStatus titanOperationStatus = createRelation.right().value();
- log.debug("Failed to create calculated requirement from component instance {} to requirement {}, error: {}", instance.getUniqueId(), reqNode.left().value().getUniqueId(), titanOperationStatus);
- return false;
- }
- log.debug("CALCULATED_REQUIREMENT was created from {} to {} with props : {}", reqNode.left().value().getUniqueId(), instance.getUniqueId(), props);
- }
- }
- return true;
- }
-
- private boolean updateRelations() {
- log.debug("update relations and edges STARTED");
- Either<List<RelationshipInstData>, TitanOperationStatus> allRelations = titanGenericDao.getByCriteria(NodeTypeEnum.RelationshipInst, null, RelationshipInstData.class);
- if (allRelations.isRight()) {
- if (allRelations.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("updateRelations : No relations to update. updateRelations ENDED");
- return true;
- }
- log.debug("updateRelations : failed to fetch all relation nodes , error ", allRelations.right().value());
- return false;
- }
- for (RelationshipInstData rel : allRelations.left().value()) {
- // rel.set
- if (rel.getCapabilityOwnerId() != null && rel.getRequirementOwnerId() != null) {
- log.debug("updateRelations : for relation {} all fields alredy fixed -> {}", rel.getUniqueId(), rel);
- continue;
- }
- // update capability parameters
- if (updateCapabiltyFieldsInRelation(rel) != true) {
- return false;
- }
-
- // update requirement parameters and set calculated edge to full
- // filled
- if (updateRequirementFieldsInRelation(rel) != true) {
- return false;
- }
-
- Either<RelationshipInstData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(rel, RelationshipInstData.class);
- if (updateNode.isRight()) {
- log.debug("updateRelations : failed to update relation node with id {} , error {}", rel.getUniqueId(), updateNode.right().value());
- return false;
- }
- log.debug("Relations was updated with values {}", rel);
- }
- log.debug("update relations and edges ENDED");
- return true;
- }
-
- private boolean updateRequirementFieldsInRelation(RelationshipInstData rel) {
- Either<ImmutablePair<ComponentInstanceData, GraphEdge>, TitanOperationStatus> reqInst = titanGenericDao.getParentNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.RelationshipInst), rel.getUniqueId(), GraphEdgeLabels.RELATIONSHIP_INST,
- NodeTypeEnum.ResourceInstance, ComponentInstanceData.class);
- if (reqInst.isRight()) {
- log.debug("updateRelations : failed to fetch capability component instance for relation {}, error {}", rel.getUniqueId(), reqInst.right().value());
- return false;
- }
- ComponentInstanceData requirementInstanceData = reqInst.left().value().getLeft();
- ComponentInstanceDataDefinition reqRI = requirementInstanceData.getComponentInstDataDefinition();
- if (reqRI.getOriginType().equals(OriginTypeEnum.VF)) {
- Either<ImmutablePair<ComponentInstanceData, GraphEdge>, TitanOperationStatus> vfcInstInOrigVf = titanGenericDao.getChildByEdgeCriteria(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), reqRI.getComponentUid(),
- GraphEdgeLabels.RESOURCE_INST, NodeTypeEnum.ResourceInstance, ComponentInstanceData.class, null);
- if (vfcInstInOrigVf.isRight()) {
- log.debug("updateRelations : failed to fetch VFC instance in origin VF with id " + reqRI.getComponentUid() + ", error ", vfcInstInOrigVf.right().value());
- return false;
- }
- rel.setRequirementOwnerId(vfcInstInOrigVf.left().value().getLeft().getUniqueId());
- } else {
- rel.setRequirementOwnerId(reqRI.getUniqueId());
- }
- // get vertex
- Either<TitanVertex, TitanOperationStatus> vertexReqRI = titanGenericDao.getVertexByProperty(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance), requirementInstanceData.getUniqueId());
- if (vertexReqRI.isRight()) {
- log.debug("updateRelations : failed to fetch veterx for instance {}, error {}", requirementInstanceData.getUniqueId(), vertexReqRI.right().value());
- return false;
- }
- String[] splitIds = rel.getUniqueId().split("\\.");
- String reqName = splitIds[splitIds.length - 1];
- Map<String, Object> props = new HashMap<>();
- props.put(GraphEdgePropertiesDictionary.NAME.getProperty(), reqName);
- Either<List<Edge>, TitanOperationStatus> edgesForNode = titanGenericDao.getOutgoingEdgesByCriteria(vertexReqRI.left().value(), GraphEdgeLabels.CALCULATED_REQUIREMENT, props);
- if (edgesForNode.isRight()) {
- log.debug("updateRelations : failed to fetch edges for instance {} error {}", requirementInstanceData.getUniqueId(), edgesForNode.right().value());
- return false;
- }
- Edge edge = edgesForNode.left().value().get(0);
- String reqId = (String) titanGenericDao.getProperty((TitanVertex) edge.inVertex(), GraphPropertiesDictionary.UNIQUE_ID.getProperty());
- rel.setRequirementId(reqId);
-
- // change edge label
- TitanEdge newEdge = (TitanEdge) vertexReqRI.left().value().addEdge(GraphEdgeLabels.CALCULATED_REQUIREMENT_FULLFILLED.getProperty(), edge.inVertex());
- titanGenericDao.setProperties(newEdge, titanGenericDao.getProperties(edge));
- edge.remove();
-
- log.debug("Edge was changed to CALCULATED_REQUIREMENT_FULLFILLED for relation between {} and {}", reqId, requirementInstanceData.getUniqueId());
-
- return true;
- }
-
- public boolean updateCapabiltyFieldsInRelation(RelationshipInstData rel) {
- // update capability parameters
- Either<ImmutablePair<ComponentInstanceData, GraphEdge>, TitanOperationStatus> capInst = titanGenericDao.getChildByEdgeCriteria(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.RelationshipInst), rel.getUniqueId(),
- GraphEdgeLabels.CAPABILITY_NODE, NodeTypeEnum.ResourceInstance, ComponentInstanceData.class, null);
- if (capInst.isRight()) {
- log.debug("updateRelations : failed to fetch capabilty component instance for relation {}, error {}", rel.getUniqueId(), capInst.right().value());
- return false;
- }
- ComponentInstanceData capabiltyInstanceData = capInst.left().value().getLeft();
- ComponentInstanceDataDefinition capRI = capabiltyInstanceData.getComponentInstDataDefinition();
- if (capRI.getOriginType().equals(OriginTypeEnum.VF)) {
- Either<ImmutablePair<ComponentInstanceData, GraphEdge>, TitanOperationStatus> vfcInstInOrigVf = titanGenericDao.getChildByEdgeCriteria(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), capRI.getComponentUid(),
- GraphEdgeLabels.RESOURCE_INST, NodeTypeEnum.ResourceInstance, ComponentInstanceData.class, null);
- if (vfcInstInOrigVf.isRight()) {
- log.debug("updateRelations : failed to fetch VFC instance in origin VF with id " + capRI.getComponentUid() + ", error ", vfcInstInOrigVf.right().value());
- return false;
- }
- rel.setCapabilityOwnerId(vfcInstInOrigVf.left().value().getLeft().getUniqueId());
- } else {
- rel.setCapabilityOwnerId(capRI.getUniqueId());
- }
-
- // get vertex
- Either<TitanVertex, TitanOperationStatus> vertexCapRI = titanGenericDao.getVertexByProperty(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance), capabiltyInstanceData.getUniqueId());
- if (vertexCapRI.isRight()) {
- log.debug("updateRelations : failed to fetch veterx for instance {} , error {}", capabiltyInstanceData.getUniqueId(), vertexCapRI.right().value());
- return false;
- }
- // String[] splitIds = rel.getUniqueId().split("\\.");
- String capName = (String) capInst.left().value().getRight().getProperties().get(GraphEdgePropertiesDictionary.NAME.getProperty());// splitIds[splitIds.length
- // - 1];
- Map<String, Object> props = new HashMap<>();
- props.put(GraphEdgePropertiesDictionary.NAME.getProperty(), capName);
- Either<List<Edge>, TitanOperationStatus> edgesForNode = titanGenericDao.getOutgoingEdgesByCriteria(vertexCapRI.left().value(), GraphEdgeLabels.CALCULATED_CAPABILITY, props);
- if (edgesForNode.isRight()) {
- log.debug("updateRelations : failed to fetch edges for instance {} , error {}", capabiltyInstanceData.getUniqueId(), edgesForNode.right().value());
- return false;
- }
- Edge edge = edgesForNode.left().value().get(0);
- String capId = (String) titanGenericDao.getProperty((TitanVertex) edge.inVertex(), GraphPropertiesDictionary.UNIQUE_ID.getProperty());
- rel.setCapabiltyId(capId);
-
- return true;
- }
-
- private Either<List<String>, StorageOperationStatus> handleVfGroup(ResourceMetadataData metadata) {
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name());
- props.put(GraphPropertiesDictionary.NAME.getProperty(), metadata.getMetadataDataDefinition().getName());
-
- List<String> finished = new ArrayList<>();
-
- Either<List<ResourceMetadataData>, TitanOperationStatus> allVFByName = titanGenericDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
- if (allVFByName.isRight()) {
- log.debug("fixDerivedFv failed fetch all VF resources,error {}", allVFByName.right().value());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- Set<String> nonDuplicatedId = new HashSet<>();
- String uuid10 = null;
- for (ResourceMetadataData mdata : allVFByName.left().value()) {
- String version = mdata.getMetadataDataDefinition().getVersion();
- if (version.equals("1.0")) {
- uuid10 = mdata.getMetadataDataDefinition().getUUID();
- // break;
- }
- nonDuplicatedId.add((String) mdata.getUniqueId());
- }
- if (uuid10 == null) {
- uuid10 = allVFByName.left().value().get(0).getMetadataDataDefinition().getUUID();
- }
- props.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name());
- props.put(GraphPropertiesDictionary.UUID.getProperty(), uuid10);
-
- Either<List<ResourceMetadataData>, TitanOperationStatus> allVFByUUID = titanGenericDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
- if (allVFByUUID.isRight()) {
- log.debug("fixDerivedFv failed fetch all VF resources by UUID {} ,error {}", uuid10, allVFByUUID.right().value());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- for (ResourceMetadataData mdata : allVFByUUID.left().value()) {
- nonDuplicatedId.add((String) mdata.getUniqueId());
- }
- Either<TitanGraph, TitanOperationStatus> graph = titanGenericDao.getGraph();
- if (graph.isRight()) {
- log.debug("fixDerivedFv failed - No titan graph ,error {}", graph.right().value());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- // Map<String, String> derivedMapping = new HashMap<>();
- for (String resourceId : nonDuplicatedId) {
- // StorageOperationStatus handleSingleVfResult =
- // handleSingleVf(finished, derivedMapping, resourceId);
- StorageOperationStatus handleSingleVfResult = handleSingleVf(finished, resourceId);
- if (!handleSingleVfResult.equals(StorageOperationStatus.OK)) {
- log.debug("fixDerivedFv failed - handleSingleVfResult failed for resource {} ,error {}", resourceId, handleSingleVfResult);
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- }
- return Either.left(finished);
- }
-
- // private StorageOperationStatus handleSingleVf(List<String> finished,
- // Map<String, String> derivedMapping, String resourceId) {
- private StorageOperationStatus handleSingleVf(List<String> finished, String resourceId) {
- Either<TitanVertex, TitanOperationStatus> vertexByProperty = titanGenericDao.getVertexByProperty(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), resourceId);
- if (vertexByProperty.isRight()) {
- log.debug("fixDerivedFv failed to fetch resource by id {} ,error {}", resourceId, vertexByProperty.right().value());
- return StorageOperationStatus.GENERAL_ERROR;
- }
- Vertex vertexR = vertexByProperty.left().value();
- Iterator<Vertex> vertexDIter = vertexR.vertices(Direction.OUT, GraphEdgeLabels.DERIVED_FROM.getProperty());
- if (vertexDIter != null && vertexDIter.hasNext()) {
- // move edges
- // must be only one
- TitanVertex vertexD = (TitanVertex) vertexDIter.next();
- String idDerived = (String) titanGenericDao.getProperty(vertexD, GraphPropertiesDictionary.UNIQUE_ID.getProperty());
-
- // TODO clone resource
-
- // TODO add instance of new resource to VF
-
- // add to vf instance of vfc
- finished.add(resourceId);
- } else {
- log.debug("No derived edges for resource id {}", resourceId);
- }
- return StorageOperationStatus.OK;
- }
-
- private boolean updateComponentInstanceType() {
- log.debug("update component instances type STARTED");
- Either<List<ComponentInstanceData>, TitanOperationStatus> allInstances = titanGenericDao.getByCriteria(NodeTypeEnum.ResourceInstance, null, ComponentInstanceData.class);
- if (allInstances.isRight()) {
- if (allInstances.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("updateComponentInstanceType: no instances ti update ");
- return true;
- }
- log.debug("updateComponentInstanceType failed fetch all resource instances ,error " + allInstances.right().value());
- return false;
- }
-
- List<ComponentInstanceData> listOfInstances = allInstances.left().value();
- for (ComponentInstanceData instance : listOfInstances) {
- String originId = instance.getComponentInstDataDefinition().getComponentUid();
- Either<ComponentMetadataData, TitanOperationStatus> nodeResource = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), originId, ComponentMetadataData.class);
- if (nodeResource.isRight()) {
- log.debug("updateComponentInstanceType failed to fetch origin resource with id {} error {}", originId, nodeResource.right().value());
- return false;
- }
- ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) nodeResource.left().value().getMetadataDataDefinition()).getResourceType();
- if (resourceType == null) {
- log.debug("updateComponentInstanceType failed, no resource type for origin resource with id " + originId);
- return false;
- }
- OriginTypeEnum originType;
- switch (resourceType) {
- case VF:
- originType = OriginTypeEnum.VF;
- break;
- case VFC:
- originType = OriginTypeEnum.VFC;
- break;
- case VL:
- originType = OriginTypeEnum.VL;
- break;
- case CP:
- originType = OriginTypeEnum.CP;
- break;
- case CVFC:
- originType = OriginTypeEnum.CVFC;
- break;
- default:
- log.debug("updateComponentInstanceType failed, no supported resource type {} for origin resource with id {}", resourceType, originId);
- return false;
- }
- instance.getComponentInstDataDefinition().setOriginType(originType);
-
- Either<ComponentInstanceData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(instance, ComponentInstanceData.class);
- if (updateNode.isRight()) {
- log.debug("updateComponentInstanceType failed, failed to update component instance node with id " + instance.getUniqueId() + " error " + updateNode.right().value());
- return false;
- }
- log.debug("For instance with id {} the origin type was detected as {}", instance.getUniqueId(), originType);
- }
- log.debug("update component instances type ENDED");
- return true;
- }
-
- private boolean addResourceCounterToResources() {
-
- Either<List<ResourceMetadataData>, TitanOperationStatus> allResources = titanGenericDao.getByCriteria(NodeTypeEnum.Resource, null, ResourceMetadataData.class);
- if (allResources.isRight()) {
- if (allResources.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("addResourceCounterToResources - no resources");
- return true;
- }
- log.debug("addResourceCounterToResources failed fetch all resources,error {}", allResources.right().value());
- return false;
- }
- for (ResourceMetadataData resource : allResources.left().value()) {
- Either<TitanVertex, TitanOperationStatus> vertexByProperty = titanGenericDao.getVertexByProperty(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), resource.getUniqueId());
- if (vertexByProperty.isRight()) {
- log.error("failed to add instanceCounter to VF {} . error is: {}", resource.getUniqueId(), vertexByProperty.right().value().name());
- return false;
- }
- Vertex vfVertex = vertexByProperty.left().value();
- if (!vfVertex.property(GraphPropertiesDictionary.INSTANCE_COUNTER.getProperty()).isPresent()) {
- vfVertex.property(GraphPropertiesDictionary.INSTANCE_COUNTER.getProperty(), 0);
- }
- }
- return true;
- }
-
- private boolean fixDerivedVf() {
-
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name());
- Either<List<ResourceMetadataData>, TitanOperationStatus> allVF = titanGenericDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
- if (allVF.isRight()) {
- if (allVF.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("fixDerivedVf - no VFs");
- return true;
- }
- log.debug("fixDerivedFv failed fetch all VF resources,error {}", allVF.right().value());
- return false;
- }
-
- Map<String, String> vfUuidToVfcUuid = new HashMap<String, String>();
- for (ResourceMetadataData metadata : allVF.left().value()) {
- Either<Resource, StorageOperationStatus> eitherResource = resourceOperation.getResource(metadata.getMetadataDataDefinition().getUniqueId(), true);
- if (eitherResource.isRight()) {
- log.error("failed to migrate VF {} from version 1602 to version 1604. error is: {}", metadata.getMetadataDataDefinition().getUniqueId(), eitherResource.right().value().name());
- return false;
- }
- Resource vfResource = eitherResource.left().value();
- if (vfResource.getDerivedFrom() == null || vfResource.getDerivedFrom().isEmpty()) {
- continue;
- }
- Boolean isVfDeleted = vfResource.getIsDeleted();
- String vfUUID = vfResource.getUUID();
- String vfcUUID = vfUuidToVfcUuid.getOrDefault(vfUUID, null);
- if (vfcUUID == null) {
- vfcUUID = UUID.randomUUID().toString();
- vfUuidToVfcUuid.put(vfUUID, vfcUUID);
- }
-
- // handle lifecycle
- String vfUniqueId = vfResource.getUniqueId();
- LifecycleStateEnum vfcTargetState = vfResource.getLifecycleState();
- if (vfcTargetState.equals(LifecycleStateEnum.READY_FOR_CERTIFICATION) || vfcTargetState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS)) {
- User user = new User();
- user.setUserId(vfResource.getLastUpdaterUserId());
- Either<? extends Component, StorageOperationStatus> checkinComponent = lifecycleOperaion.checkinComponent(NodeTypeEnum.Resource, vfResource, user, user, true);
- if (checkinComponent.isRight()) {
- log.error("failed to checkin VF {}. error={}", vfUniqueId, checkinComponent.right().value().name());
- return false;
- }
- } else if (vfcTargetState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
- vfcTargetState = LifecycleStateEnum.NOT_CERTIFIED_CHECKIN;
- }
-
- // delete VF Properties
- List<PropertyDefinition> properties = vfResource.getProperties();
- if (properties != null && !properties.isEmpty()) {
- Either<Map<String, PropertyDefinition>, StorageOperationStatus> deleteAllProperties = propertyOperation.deleteAllPropertiesAssociatedToNode(NodeTypeEnum.Resource, vfUniqueId);
- if (deleteAllProperties.isRight() && !deleteAllProperties.right().value().equals(StorageOperationStatus.NOT_FOUND) && !deleteAllProperties.right().value().equals(StorageOperationStatus.OK)) {
- log.error("failed to delete properties of VF {} . error is: {}", metadata.getMetadataDataDefinition().getUniqueId(), deleteAllProperties.right().value().name());
- return false;
- }
- }
- // delete VF Additional Info
- List<AdditionalInformationDefinition> additionalInformation = vfResource.getAdditionalInformation();
- if (additionalInformation != null && !additionalInformation.isEmpty()) {
- Either<AdditionalInformationDefinition, StorageOperationStatus> deleteAllAdditionalInformationParameters = additionalInformationOperation.deleteAllAdditionalInformationParameters(NodeTypeEnum.Resource, vfUniqueId, true);
- if (deleteAllAdditionalInformationParameters.isRight() && !deleteAllAdditionalInformationParameters.right().value().equals(StorageOperationStatus.OK)
- && !deleteAllAdditionalInformationParameters.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
- log.error("failed to delete properties of VF {} . error is: {}", metadata.getMetadataDataDefinition().getUniqueId(), deleteAllAdditionalInformationParameters.right().value().name());
- return false;
- }
- }
- // delete VF derivedFrom
- GraphRelation derivedFromRelation = new GraphRelation(GraphEdgeLabels.DERIVED_FROM.getProperty());
- derivedFromRelation.setFrom(new RelationEndPoint(NodeTypeEnum.Resource, UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), vfUniqueId));
- Either<GraphRelation, TitanOperationStatus> deleteDerivedFromRelation = titanGenericDao.deleteOutgoingRelation(derivedFromRelation);
- if (deleteDerivedFromRelation.isRight()) {
- log.error("failed to delete derivedFrom relation of VF {} . error is: {}", metadata.getMetadataDataDefinition().getUniqueId(), deleteDerivedFromRelation.right().value().name());
- return false;
- }
-
- // create VFC
- Either<Resource, StorageOperationStatus> createVFC = createVFC(metadata, vfResource, vfcUUID, vfcTargetState);
- if (createVFC.isRight()) {
- log.error("failed to split VF {} to VFC. error is: {}", metadata.getMetadataDataDefinition().getUniqueId(), createVFC.right().value().name());
- return false;
- }
- Resource vfcResource = createVFC.left().value();
- if (!createVfcInstanceOnVf(vfcResource, vfUniqueId)) {
- return false;
- }
- // update VFC to deleted if required
- if (isVfDeleted != null && isVfDeleted) {
- Either<Component, StorageOperationStatus> markResourceToDelete = resourceOperation.markComponentToDelete(vfcResource, true);
- if (markResourceToDelete.isRight()) {
- log.error("failed to mark isDeleted on VFC {} . error is: {}", vfcResource.getUniqueId(), markResourceToDelete.right().value().name());
- return false;
- }
- }
-
- }
- return true;
- }
-
- private Either<Resource, StorageOperationStatus> createVFC(ResourceMetadataData metadata, Resource vfcResource, String uuid, LifecycleStateEnum vfcTargetState) {
-
- Boolean highestVersion = vfcResource.isHighestVersion();
- // Resource vfcResource = new Resource((ResourceMetadataDefinition)
- // vfResource.getComponentMetadataDefinition());
- // String componentName = vfcResource.getName()+"VFC";
- // vfcResource.setName(componentName);
- // vfcResource.setNormalizedName(ValidationUtils.normaliseComponentName(componentName));
- // vfcResource.setSystemName(ValidationUtils.convertToSystemName(componentName));
- vfcResource.setUniqueId(null);
- vfcResource.setUUID(uuid);
- vfcResource.setAllVersions(null);
- vfcResource.setArtifacts(null);
- vfcResource.setDeploymentArtifacts(null);
- vfcResource.setComponentInstances(null);
- vfcResource.setComponentInstancesProperties(null);
- vfcResource.setComponentInstancesRelations(null);
- vfcResource.setResourceType(ResourceTypeEnum.VFC);
- vfcResource.setIsDeleted(false);
-
- vfcResource.setLifecycleState(vfcTargetState);
- // vfcResource.setDerivedFrom(vfResource.getDerivedFrom());
- // vfcResource.setProperties(vfResource.getProperties());
- // vfcResource.setAdditionalInformation(vfResource.getAdditionalInformation());
- // vfcResource.setCategories(vfResource.getCategories());
- // vfcResource.setTags(vfResource.getTags());
-
- Either<Resource, StorageOperationStatus> createResource = resourceOperation.createResource(vfcResource, true);
- if (createResource.isRight()) {
- return createResource;
- }
- Resource afterCreateResource = createResource.left().value();
- Either<TitanVertex, TitanOperationStatus> vertexByProperty = titanGenericDao.getVertexByProperty(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), afterCreateResource.getUniqueId());
- if (vertexByProperty.isRight()) {
- return createResource;
- }
- Vertex newVfcVertex = vertexByProperty.left().value();
- newVfcVertex.property(GraphPropertiesDictionary.UUID.getProperty(), uuid);
- if (!highestVersion) {
- newVfcVertex.property(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), false);
- }
- return createResource;
- }
-
- private boolean createVfcInstanceOnVf(Resource vfcResource, String vfUniqueId) {
- // create VFC instance on VF
- ComponentInstance componentInstance = new ComponentInstance();
- componentInstance.setComponentUid(vfcResource.getUniqueId());
- componentInstance.setPosX("550");
- componentInstance.setPosY("300");
- componentInstance.setName(vfcResource.getName());
- componentInstance.setIcon(vfcResource.getIcon());
- componentInstance.setToscaComponentName(vfcResource.getToscaResourceName());
- Either<String, Boolean> handleNameLogic = handleNameLogic(componentInstance, vfUniqueId, vfcResource.getName());
- if (handleNameLogic.isRight()) {
- log.error("failed to create logical name for vfc instance");
- return false;
- }
- Either<ComponentInstance, StorageOperationStatus> createComponentInstance = componentInstanceOperaion.createComponentInstance(vfUniqueId, NodeTypeEnum.Resource, handleNameLogic.left().value(), componentInstance, NodeTypeEnum.Resource, true);
-
- if (createComponentInstance.isRight()) {
- log.error("failed to create vfc instance on vf {}. error: {}", vfUniqueId, createComponentInstance.right().value().name());
- return false;
- }
- return true;
- }
-
- private Either<String, Boolean> handleNameLogic(ComponentInstance componentInstance, String containerComponentId, String resourceName) {
-
- Either<Integer, StorageOperationStatus> componentInNumberStatus = resourceOperation.increaseAndGetComponentInstanceCounter(containerComponentId, true);
-
- if (componentInNumberStatus.isRight()) {
- log.debug("Failed to get component instance number for container component {} ", containerComponentId);
- return Either.right(false);
- }
- String resourceInNumber = componentInNumberStatus.left().value().toString();
- componentInstance.setComponentName(resourceName);
- componentInstance.setName(resourceName);
- String logicalName = componentInstanceOperaion.createComponentInstLogicalName(resourceInNumber, resourceName);
-
- Boolean eitherValidation = validateComponentInstanceName(logicalName, componentInstance, true);
- if (!eitherValidation) {
- return Either.right(false);
- }
-
- return Either.left(resourceInNumber);
- }
-
- private Boolean validateComponentInstanceName(String resourceInstanceName, ComponentInstance resourceInstance, boolean isCreate) {
-
- if (!ValidationUtils.validateStringNotEmpty(resourceInstanceName)) {
- return false;
- }
- resourceInstance.setNormalizedName(ValidationUtils.normalizeComponentInstanceName(resourceInstanceName));
- if (!isCreate) {
- if (!ValidationUtils.validateResourceInstanceNameLength(resourceInstanceName)) {
- return false;
- }
- if (!ValidationUtils.validateResourceInstanceName(resourceInstanceName)) {
- return false;
- }
- }
-
- return true;
-
- }
-
- public boolean migrate1604to1607(String appConfigDir) {
- log.debug("Started the migration procedure from version 1604 to version 1607 ...");
- log.debug("Getting all resources with resources");
- boolean result = false;
- Either<Boolean, StorageOperationStatus> resourceEither = null;
- try {
- Either<List<ResourceMetadataData>, TitanOperationStatus> allResources = titanGenericDao.getByCriteria(NodeTypeEnum.Resource, null, ResourceMetadataData.class);
- if (allResources.isRight()) {
- log.error("Couldn't get resources from DB, error: {}", allResources.right().value());
- result = false;
- return result;
- }
- List<ResourceMetadataData> resourcesList = allResources.left().value();
- if (resourcesList == null) {
- log.error("Couldn't get resources from DB, no resources found");
- result = false;
- return result;
- }
- log.debug("Found {} resources", resourcesList.size());
- for (ResourceMetadataData resource : resourcesList) {
- String resourceName = resource.getMetadataDataDefinition().getName();
- log.debug("Checking resource {}", resourceName);
- if (isNormative(resourceName)) {
- resourceEither = changeNormativeTypeName(resource);
- if (resourceEither.isRight()) {
- log.error("DB error during name changing");
- result = false;
- return result;
- }
- }
- if (((ResourceMetadataDataDefinition) resource.getMetadataDataDefinition()).getResourceType().name().equals("VF")) {
- resourceEither = setVfToscaResourceName(resource);
- if (resourceEither.isRight()) {
- log.error("DB error during tosca resource name setting");
- result = false;
- return result;
- }
- }
- }
- result = addInvariantUUIDs(appConfigDir);
- } finally {
- if (!result) {
- titanGenericDao.rollback();
- log.debug("**********************************************");
- log.debug("The migration procedure from version 1604 to version 1607 FAILED!!");
- log.debug("**********************************************");
- } else {
- titanGenericDao.commit();
- log.debug("**********************************************");
- log.debug("The migration procedure from version 1604 to version 1607 ended successfully!");
- log.debug("**********************************************");
- }
- }
-
- return result;
- }
-
- private boolean addInvariantUUIDs(String appConfigDir) {
- log.debug("Started adding of InvariantUUID ...");
- log.debug("Getting all resources with highest version");
-
- Map<String, Object> props = new HashMap<>();
- props.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
-
- List<ComponentMetadataData> fullComponentList = new ArrayList<ComponentMetadataData>();
-
- // getting resources
- Either<List<ResourceMetadataData>, TitanOperationStatus> allHighestVersionResources = titanGenericDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
- if (allHighestVersionResources.isRight()) {
- log.error("Couldn't get resources with highest version from DB, error: {}", allHighestVersionResources.right().value());
- return false;
- }
- List<ResourceMetadataData> allHighestVersionResourcesAL = allHighestVersionResources.left().value();
- if (allHighestVersionResourcesAL == null) {
- log.error("Couldn't get resources with highest version from DB, no resources found");
- return false;
- }
- log.debug("Found {} resources", allHighestVersionResourcesAL.size());
- fullComponentList.addAll(allHighestVersionResourcesAL);
-
- // getting services
- Either<List<ServiceMetadataData>, TitanOperationStatus> allHighestVersionServices = titanGenericDao.getByCriteria(NodeTypeEnum.Service, props, ServiceMetadataData.class);
- if (allHighestVersionServices.isRight()) {
- log.error("Couldn't get services with highest version from DB, error: {}", allHighestVersionServices.right().value());
- return false;
- }
- List<ServiceMetadataData> allHighestVersionServicesAL = allHighestVersionServices.left().value();
- if (allHighestVersionServicesAL == null) {
- log.error("Couldn't get services with highest version from DB, no services found");
- return false;
- }
- log.debug("Found {} services", allHighestVersionServicesAL.size());
- fullComponentList.addAll(allHighestVersionServicesAL);
-
- List<ComponentMetadataData> reducedComponentsAL = reduceHighestVersionResourcesList(fullComponentList);
-
- // getting products
- Either<List<ProductMetadataData>, TitanOperationStatus> allHighestVersionProducts = titanGenericDao.getByCriteria(NodeTypeEnum.Product, props, ProductMetadataData.class);
- if (allHighestVersionProducts.isRight()) {
- log.error("Couldn't get products with highest version from DB, error: {}", allHighestVersionProducts.right().value());
- return false;
- }
- List<ProductMetadataData> allHighestVersionProductsAL = allHighestVersionProducts.left().value();
- if (allHighestVersionProductsAL == null) {
- log.error("Couldn't get products with highest version from DB, no products found");
- return false;
- }
- log.debug("Found {} products", allHighestVersionProductsAL.size());
-
- List<ComponentMetadataData> fullProductList = new ArrayList<ComponentMetadataData>();
- fullProductList.addAll(allHighestVersionProductsAL);
- List<ComponentMetadataData> reducedProductAL = reduceHighestVersionResourcesList(fullProductList);
-
- for (ComponentMetadataData product : reducedProductAL) {
- if (!setProductInvariantUUIDIfExists((ProductMetadataData) product)) {
- return false;
- }
- }
- reducedComponentsAL.addAll(reducedProductAL);
-
- log.debug("Reduced list of Highest Version Components contains {} components", reducedComponentsAL.size());
- for (ComponentMetadataData componentMetaData : reducedComponentsAL) {
-
- String invariantUUID = componentMetaData.getMetadataDataDefinition().getInvariantUUID();
- log.debug("old invariantUUID {}", invariantUUID);
- if (invariantUUID == null || invariantUUID.isEmpty()) {
- invariantUUID = UniqueIdBuilder.buildInvariantUUID();
- componentMetaData.getMetadataDataDefinition().setInvariantUUID(invariantUUID);
- }
- log.debug("new invariantUUID {}", componentMetaData.getMetadataDataDefinition().getInvariantUUID());
- Either<ComponentMetadataData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(componentMetaData, ComponentMetadataData.class);
- if (updateNode.isRight()) {
- log.error("DB error during while updating component {}, error: {}", componentMetaData.getMetadataDataDefinition().getName(), updateNode.right().value());
- return false;
- }
- log.debug("updated invariantUUID {}", updateNode.left().value().getMetadataDataDefinition().getInvariantUUID());
- if (!isOnlyVersion(componentMetaData)) {
- ComponentOperation componentOperation = null;
- switch (NodeTypeEnum.getByName(componentMetaData.getLabel())) {
- case Resource:
- componentOperation = resourceOperation;
- break;
- case Service:
- componentOperation = serviceOperation;
- break;
- case Product:
- componentOperation = productOperation;
- break;
- default:
- break;
- }
- Either<Component, StorageOperationStatus> getComponentResult = componentOperation.getComponent((String) componentMetaData.getUniqueId(), true);
- if (getComponentResult.isRight()) {
- log.error("DB error during while getting component with uniqueID {}, error: {}", componentMetaData.getUniqueId(), getComponentResult.right().value());
- return false;
- }
- Component component = getComponentResult.left().value();
- if (component == null) {
- log.error("The component received from DB is empty");
- return false;
- }
-
- Map<String, String> allVersions = component.getAllVersions();
- log.debug("found {} versions for component {}", allVersions.size(), component.getName());
- Either<Boolean, StorageOperationStatus> resEither = updateAllVersions(allVersions, invariantUUID);
- if (resEither.isRight()) {
- log.error("DB error during invariantUUID adding");
- return false;
- }
- }
- }
- return true;
- }
-
- private boolean isOnlyVersion(ComponentMetadataData componentMetaData) {
- String version = componentMetaData.getMetadataDataDefinition().getVersion();
- if (version.equals("0.1"))
- return true;
- return false;
- }
-
- private boolean setProductInvariantUUIDIfExists(ProductMetadataData product) {
- Either<TitanVertex, TitanOperationStatus> getVertexRes = titanGenericDao.getVertexByProperty(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), product.getUniqueId());
- if (getVertexRes.isRight()) {
- log.error("DB error during retrieving product vertex {}", product.getMetadataDataDefinition().getName());
- return false;
- }
- Vertex productVertex = getVertexRes.left().value();
- String invariantUUID = productVertex.value(GraphPropertiesDictionary.CONSTANT_UUID.getProperty());
- if (invariantUUID != null && !invariantUUID.isEmpty()) {
- product.getMetadataDataDefinition().setInvariantUUID(invariantUUID);
- }
- return true;
- }
-
- private Either<Boolean, StorageOperationStatus> updateAllVersions(Map<String, String> allVersions, String invariantUUID) {
-
- if (allVersions != null) {
- for (String uniqueID : allVersions.values()) {
- Either<ComponentMetadataData, TitanOperationStatus> getNodeResult = titanGenericDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), uniqueID, ComponentMetadataData.class);
- if (getNodeResult.isRight()) {
- log.error("DB error during while getting component with uniqueID {}, error: {}", uniqueID, getNodeResult.right().value());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- ComponentMetadataData component = getNodeResult.left().value();
- component.getMetadataDataDefinition().setInvariantUUID(invariantUUID);
- Either<ComponentMetadataData, TitanOperationStatus> updateNodeResult = titanGenericDao.updateNode(component, ComponentMetadataData.class);
- log.debug("updated child invariantUUID {}", updateNodeResult.left().value().getMetadataDataDefinition().getInvariantUUID());
- if (updateNodeResult.isRight()) {
- log.error("DB error during while updating component {}, error: {}", component.getMetadataDataDefinition().getName(), updateNodeResult.right().value());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- }
- }
- return Either.left(true);
- }
-
- private List<ComponentMetadataData> reduceHighestVersionResourcesList(List<ComponentMetadataData> allHighestVersionResources) {
- List<ComponentMetadataData> resultList = null;
- Map<String, ComponentMetadataData> resultHM = new HashMap<String, ComponentMetadataData>();
- for (ComponentMetadataData resource : allHighestVersionResources) {
- if (resource.getMetadataDataDefinition().getInvariantUUID() != null && !resource.getMetadataDataDefinition().getInvariantUUID().isEmpty()) {
- log.debug("invariantUUID {} ", resource.getMetadataDataDefinition().getInvariantUUID());
- continue;
- }
- String curUUID = resource.getMetadataDataDefinition().getUUID();
- if (resultHM.containsKey(curUUID)) {
- int isHighest = resultHM.get(curUUID).getMetadataDataDefinition().getVersion().compareTo(resource.getMetadataDataDefinition().getVersion());
- if (isHighest > 0) {
- log.debug("version {} is great than {} ", resultHM.get(curUUID).getMetadataDataDefinition().getVersion(), resource.getMetadataDataDefinition().getVersion());
- continue;
- }
- }
- resultHM.put(curUUID, resource);
- }
- resultList = new ArrayList<ComponentMetadataData>(resultHM.values());
- return resultList;
- }
-
- private boolean isNormative(String resourceName) {
- for (int i = 0; i < NORMATIVE_OLD_NAMES.length; ++i) {
- if (NORMATIVE_OLD_NAMES[i].equals(resourceName))
- return true;
- }
- return false;
- }
-
- private Either<Boolean, StorageOperationStatus> changeNormativeTypeName(ResourceMetadataData resource) {
-
- String resourceName = resource.getMetadataDataDefinition().getName();
-
- if (resourceName != null && !resourceName.isEmpty()) {
- log.debug("Found normative type to change - {}", resourceName);
- String oldName = resourceName;
- String[] splitedName = resourceName.split("\\.");
- String newName = splitedName[splitedName.length - 1];
- String newSystemName = ValidationUtils.convertToSystemName(newName);
- String newNormalizedName = ValidationUtils.normaliseComponentName(newName);
- log.debug("Setting name to be {}", newName);
-
- resource.getMetadataDataDefinition().setName(newName);
- log.debug("Setting system name to be {}", newSystemName);
- resource.getMetadataDataDefinition().setSystemName(newSystemName);
- log.debug("Setting normalized name to be {}", newNormalizedName);
- resource.getMetadataDataDefinition().setNormalizedName(newNormalizedName);
- log.debug("Updating tag in metadata to be {}", newName);
- resource.getMetadataDataDefinition().getTags().remove(oldName);
- resource.getMetadataDataDefinition().getTags().add(newName);
-
- log.debug("Creating tag node with name {}", newName);
- TagData tagData = new TagData();
- tagData.setName(newName);
- Either<TagData, TitanOperationStatus> createNode = titanGenericDao.createNode(tagData, TagData.class);
- if (createNode.isRight()) {
- log.error("Error while creating tag node {}, error: {}.", newName, createNode.right().value());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
-
- Either<ResourceMetadataData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(resource, ResourceMetadataData.class);
- if (updateNode.isRight()) {
- log.error("DB error during while updating normative type {}, error: {}", resource.getMetadataDataDefinition().getName(), updateNode.right().value());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- log.debug("Normative type {} was successfully updated", resource.getMetadataDataDefinition().getName());
- return Either.left(true);
- }
-
- return Either.left(false);
- }
-
- private Either<Boolean, StorageOperationStatus> generateAndSetToscaResourceName(ResourceMetadataData resource, String toscaResourceName) {
- if (toscaResourceName == null) {
- toscaResourceName = CommonBeUtils.generateToscaResourceName(((ResourceMetadataDataDefinition) resource.getMetadataDataDefinition()).getResourceType().name(), resource.getMetadataDataDefinition().getSystemName());
- }
- Either<Boolean, StorageOperationStatus> validateToscaResourceNameExists = resourceOperation.validateToscaResourceNameExists(toscaResourceName);
- if (validateToscaResourceNameExists.isRight()) {
- StorageOperationStatus storageOperationStatus = validateToscaResourceNameExists.right().value();
- log.error("Couldn't validate toscaResourceName uniqueness - error: {}", storageOperationStatus);
- return Either.right(storageOperationStatus);
- }
- if (validateToscaResourceNameExists.left().value()) {
- log.debug("Setting tosca resource name to be {}", toscaResourceName);
- ((ResourceMetadataDataDefinition) resource.getMetadataDataDefinition()).setToscaResourceName(toscaResourceName);
- return Either.left(true);
- } else {
- // As agreed with Renana - cannot be fixed automatically
- log.warn("toscaResourceName {} is not unique! Cannot set it. Continuing...");
- return Either.left(false);
- }
- }
-
- public boolean testRemoveHeatPlaceHolders(String appConfigDir) {
-
- if (!AllowMultipleHeats.removeAndUpdateHeatPlaceHolders(titanGenericDao, log, false)) {
- log.error("Failed to update heat place holders");
- return false;
- }
- return true;
- }
-
- private Either<Boolean, StorageOperationStatus> setVfToscaResourceName(ResourceMetadataData resource) {
- String resourceName = resource.getMetadataDataDefinition().getName();
- String resourceType = ((ResourceMetadataDataDefinition) resource.getMetadataDataDefinition()).getResourceType().name();
- String toscaResourceName = CommonBeUtils.generateToscaResourceName(resourceType, resource.getMetadataDataDefinition().getSystemName());
- log.debug("Setting tosca resource name {} to VF {}", toscaResourceName, resourceName);
- ((ResourceMetadataDataDefinition) resource.getMetadataDataDefinition()).setToscaResourceName(toscaResourceName);
-
- Either<ResourceMetadataData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(resource, ResourceMetadataData.class);
- if (updateNode.isRight()) {
- log.error("DB error during while updating VF tosca resource name {}, error: {}", resource.getMetadataDataDefinition().getName(), updateNode.right().value());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- log.debug("Tosca resource name of VF {} was successfully updated", resource.getMetadataDataDefinition().getName());
- return Either.left(true);
- }
-
- public boolean testAddGroupUuids(String appConfigDir) {
-
- if (!AddGroupUuid.addGroupUuids(titanGenericDao, log, false)) {
- log.error("Failed to update group UUIDs");
- return false;
- }
- return true;
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/VfcNamingAlignment.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/VfcNamingAlignment.java
deleted file mode 100644
index e488017679..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1604/VfcNamingAlignment.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1604;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.be.resources.data.TagData;
-import org.openecomp.sdc.be.utils.CommonBeUtils;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.util.ValidationUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import fj.data.Either;
-
-public class VfcNamingAlignment {
-
- private static Logger log = LoggerFactory.getLogger(VfcNamingAlignment.class.getName());
-
- @Autowired
- protected TitanGenericDao titanGenericDao;
- @Autowired
- protected ResourceOperation resourceOperation;
-
- public boolean alignVfcNames1604(String appConfigDir) {
- log.debug("Started alignVfcNames1604 procedure..");
- log.debug("Getting all resources with resourceType = VFC/CP/VL");
- boolean result = false;
- try {
- Map<String, Object> notProperties = new HashMap<>();
- notProperties.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name());
- Either<List<ResourceMetadataData>, TitanOperationStatus> allVfcResources = titanGenericDao
- .getByCriteria(NodeTypeEnum.Resource, null, notProperties, ResourceMetadataData.class);
- if (allVfcResources.isRight()) {
- log.error("Couldn't get VFC resources from DB, error: {}", allVfcResources.right().value());
- result = false;
- return result;
- }
- List<ResourceMetadataData> vfcList = allVfcResources.left().value();
- if (vfcList == null) {
- log.error("Couldn't get VFC/CP/VL resources from DB, no resources found");
- result = false;
- return result;
- }
- log.debug("Found {} VFC/CP/VL resources", vfcList.size());
- for (ResourceMetadataData vfc : vfcList) {
- log.debug("Checking resource {}", vfc.getMetadataDataDefinition().getName());
- boolean wasChanged = false;
-
- Either<Boolean, StorageOperationStatus> vfcEither = fixToscaNameEmpty(vfc);
- if (vfcEither.isRight()) {
- log.error("DB error during checkIsToscaNameEmpty - exiting...");
- result = false;
- return result;
- }
- wasChanged = wasChanged | vfcEither.left().value();
-
- vfcEither = fixVfcToscaNameHasVf(vfc);
- if (vfcEither.isRight()) {
- log.error("DB error during checkIsVfcToscaNameHasVf - exiting...");
- result = false;
- return result;
- }
- wasChanged = wasChanged | vfcEither.left().value();
-
- if (wasChanged) {
- Either<ResourceMetadataData, TitanOperationStatus> updateVfc = updateVfc(vfc);
- if (updateVfc.isRight()) {
- log.error("DB error during while updating resource {}, error: {} - exiting...",
- vfc.getMetadataDataDefinition().getName(), updateVfc.right().value());
- result = false;
- return result;
- }
- log.debug("Resource {} was successfully updated", vfc.getMetadataDataDefinition().getName());
- }
-
- }
- result = true;
- } finally {
- if (!result) {
- titanGenericDao.rollback();
- log.debug("**********************************************");
- log.debug("alignVfcNames1604 procedure FAILED!!");
- log.debug("**********************************************");
- } else {
- titanGenericDao.commit();
- log.debug("**********************************************");
- log.debug("alignVfcNames1604 procedure ended successfully!");
- log.debug("**********************************************");
- }
- }
-
- return result;
- }
-
- private Either<ResourceMetadataData, TitanOperationStatus> updateVfc(ResourceMetadataData vfc) {
- return titanGenericDao.updateNode(vfc, ResourceMetadataData.class);
- }
-
- private Either<Boolean, StorageOperationStatus> fixToscaNameEmpty(ResourceMetadataData vfc) {
- String toscaResourceName = ((ResourceMetadataDataDefinition) vfc.getMetadataDataDefinition())
- .getToscaResourceName();
- if (toscaResourceName == null || toscaResourceName.trim().equals(Constants.EMPTY_STRING)) {
- log.debug("Tosca resource name is empty - setting new tosca name...");
- Either<Boolean, StorageOperationStatus> generateAndSetToscaResourceName = generateAndSetToscaResourceName(
- vfc, null);
- if (generateAndSetToscaResourceName.isRight()) {
- return Either.right(generateAndSetToscaResourceName.right().value());
- }
- return Either.left(true);
- }
- return Either.left(false);
- }
-
- private Either<Boolean, StorageOperationStatus> fixVfcToscaNameHasVf(ResourceMetadataData vfc) {
- String toscaResourceName = ((ResourceMetadataDataDefinition) vfc.getMetadataDataDefinition())
- .getToscaResourceName();
- if (toscaResourceName.contains(".vf.")) {
- log.debug("Tosca resource name {} is VF-style - setting new tosca name...", toscaResourceName);
- Either<Boolean, StorageOperationStatus> generateAndSetToscaResourceName = generateAndSetToscaResourceName(
- vfc, null);
- if (generateAndSetToscaResourceName.isRight()) {
- return Either.right(generateAndSetToscaResourceName.right().value());
- }
- return Either.left(true);
- }
- return Either.left(false);
- }
-
- private Either<Boolean, StorageOperationStatus> generateAndSetToscaResourceName(ResourceMetadataData vfc,
- String toscaResourceName) {
- if (toscaResourceName == null) {
- toscaResourceName = CommonBeUtils.generateToscaResourceName(
- ((ResourceMetadataDataDefinition) vfc.getMetadataDataDefinition()).getResourceType().name(),
- vfc.getMetadataDataDefinition().getSystemName());
- }
- Either<Boolean, StorageOperationStatus> validateToscaResourceNameExists = resourceOperation
- .validateToscaResourceNameExists(toscaResourceName);
- if (validateToscaResourceNameExists.isRight()) {
- StorageOperationStatus storageOperationStatus = validateToscaResourceNameExists.right().value();
- log.error("Couldn't validate toscaResourceName uniqueness - error: {}", storageOperationStatus);
- return Either.right(storageOperationStatus);
- }
- if (validateToscaResourceNameExists.left().value()) {
- log.debug("Setting tosca resource name to be {}", toscaResourceName);
- ((ResourceMetadataDataDefinition) vfc.getMetadataDataDefinition()).setToscaResourceName(toscaResourceName);
- return Either.left(true);
- } else {
- // As agreed with Renana - cannot be fixed automatically
- log.warn("toscaResourceName {} is not unique! Cannot set it. Continuing...");
- return Either.left(false);
- }
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1607/CsarMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1607/CsarMigration.java
deleted file mode 100644
index b141eecb87..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1607/CsarMigration.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1607;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-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.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.thinkaurelius.titan.core.TitanVertex;
-
-import fj.data.Either;
-
-public class CsarMigration {
- private static Logger log = LoggerFactory.getLogger(CsarMigration.class.getName());
-
- @Autowired
- protected TitanGenericDao titanGenericDao;
-
- public boolean removeCsarResources() {
- Map<String, Object> props = new HashMap<>();
- props.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name());
-
- Either<List<ResourceMetadataData>, TitanOperationStatus> byCriteria = titanGenericDao
- .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
- if (byCriteria.isRight()) {
- log.debug("Failed to fetch VF resources by criteria ", byCriteria.right().value());
- return false;
- }
- List<ResourceMetadataData> resources = byCriteria.left().value();
-
- try {
- for (ResourceMetadataData data : resources) {
- if (data.getMetadataDataDefinition().getCsarUUID() != null) {
- log.debug("VF {} with CSAR {}", data.getUniqueId(), data.getMetadataDataDefinition().getCsarUUID());
- Either<TitanVertex, TitanOperationStatus> vertexByProperty = titanGenericDao
- .getVertexByProperty(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), data.getUniqueId());
- if (vertexByProperty.isRight()) {
- log.debug("Failed to fetch vertex with id {} . skip resource {} ", data.getUniqueId(),
- data.getMetadataDataDefinition().getName());
- continue;
- }
- Vertex vertex = vertexByProperty.left().value();
- Iterator<VertexProperty<Object>> properties = vertex
- .properties(GraphPropertiesDictionary.CSAR_UUID.getProperty());
- while (properties.hasNext()) {
- VertexProperty<Object> next = properties.next();
- next.remove();
- }
-
- }
- }
- titanGenericDao.commit();
- } catch (Exception e) {
- log.debug("Failed to clean CSAR UUID. rollback");
- titanGenericDao.rollback();
- }
-
- return true;
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1610/TitanFixUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1610/TitanFixUtils.java
deleted file mode 100644
index fedd4d2545..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1610/TitanFixUtils.java
+++ /dev/null
@@ -1,384 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1610;
-
-import com.google.gson.Gson;
-import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.core.TitanVertex;
-import fj.data.Either;
-
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-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.operations.impl.CacheMangerOperation;
-import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.*;
-
-public class TitanFixUtils {
- private static Logger log = LoggerFactory.getLogger(TitanFixUtils.class.getName());
-
- @Autowired
- protected TitanGenericDao titanGenericDao;
- @Autowired
- protected CacheMangerOperation cacheMangerOperation;
-
- public boolean fixIconsInNormatives() {
- log.info("starting fix");
- String vlName = "VL";
- String elineName = "VL_ELINE";
- String elineFixedName = "VL ELINE";
- Either<TitanGraph, TitanOperationStatus> graphResult = titanGenericDao.getGraph();
- if (graphResult.isRight()) {
- log.error("failed to get graph object.");
- return false;
- }
-
- boolean operationFailed = false;
- Map<String, Object> vlVerticeProperties = null;
- Map<String, Object> elineVerticeProperties = null;
-
- try {
- TitanGraph titanGraph = graphResult.left().value();
- log.info("look up vl :{}", vlName);
-
- Iterable<TitanVertex> vertices = titanGraph.query()
- .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Resource.getName())
- .has(GraphPropertiesDictionary.NAME.getProperty(), vlName)
- .has(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true).vertices();
-
- if (vertices == null) {
- log.error("failed to get vernice for resource name {}", vlName);
- operationFailed = true;
- return false;
- }
-
- Iterator<TitanVertex> iterator = vertices.iterator();
- List<TitanVertex> vertexList = new ArrayList<>();
-
- if (iterator == null) {
- log.error("failed to get iterator over vertices object returned for resource id {}", vlName);
- operationFailed = true;
- return false;
- }
-
- while (iterator.hasNext()) {
- TitanVertex vertex = iterator.next();
- vertexList.add(vertex);
- }
-
- if (!(vertexList.size() == 1)) {
- log.error("failed to get 1 vertex for resource {} with highest true. instead got {}", vlName,
- vertexList.size());
- operationFailed = true;
- return false;
- }
-
- TitanVertex vlVertex = vertexList.get(0);
-
- log.info("look up eline:{}", elineName);
-
- boolean vl_eline_found = true;
-
- vertices = titanGraph.query()
- .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Resource.getName())
- .has(GraphPropertiesDictionary.NAME.getProperty(), elineName)
- .has(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true).vertices();
-
- if (vertices == null) {
- log.error("failed to get vertices object returned for resource {}", elineName);
- operationFailed = true;
-
- vl_eline_found = false;
- }
-
- if (vl_eline_found) {
- iterator = vertices.iterator();
- vertexList = new ArrayList<>();
- if (iterator == null) {
- log.error("failed to get iterator over vertices object returned for resource id {}", elineName);
- operationFailed = true;
-
- vl_eline_found = false;
- }
-
- if (vl_eline_found) {
- while (iterator.hasNext()) {
- TitanVertex vertex = iterator.next();
- vertexList.add(vertex);
- }
-
- if (!(vertexList.size() == 1)) {
- log.error("failed to get 1 vertex for resource {} with highest true. instead got {}",
- elineName, vertexList.size());
- operationFailed = true;
-
- vl_eline_found = false;
- }
- }
- }
-
- if (!vl_eline_found) {
- log.info("look up eline:{}", elineFixedName);
- vl_eline_found = true;
- operationFailed = false;
-
- vertices = titanGraph.query()
- .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Resource.getName())
- .has(GraphPropertiesDictionary.NAME.getProperty(), elineFixedName)
- .has(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true).vertices();
-
- if (vertices == null) {
- log.error("failed to get vertices object returned for resource {}", elineFixedName);
- operationFailed = true;
-
- vl_eline_found = false;
- }
-
- if (vl_eline_found) {
- iterator = vertices.iterator();
- vertexList = new ArrayList<>();
- if (iterator == null) {
- log.error("failed to get iterator over vertices object returned for resource id {}",
- elineFixedName);
- operationFailed = true;
-
- vl_eline_found = false;
- }
-
- if (vl_eline_found) {
- while (iterator.hasNext()) {
- TitanVertex vertex = iterator.next();
- vertexList.add(vertex);
- }
-
- if (!(vertexList.size() == 1)) {
- log.error("failed to get 1 vertex for resource {} with highest true. instead got {}",
- elineFixedName, vertexList.size());
- operationFailed = true;
-
- vl_eline_found = false;
- }
- }
- }
- }
-
- if (!vl_eline_found) {
- return false;
- } else {
- TitanVertex elineVertex = vertexList.get(0);
-
- vlVerticeProperties = titanGenericDao.getProperties(vlVertex);
-
- log.info("VL Vertice Properties {}", vlVerticeProperties);
- if ("network".equals(vlVerticeProperties.get(GraphPropertiesDictionary.ICON.getProperty()))) {
- log.info("nothing to update in vl");
- } else {
- log.info("updating property icon of vl");
- vlVertex.property(GraphPropertiesDictionary.ICON.getProperty(), "network");
- }
-
- elineVerticeProperties = titanGenericDao.getProperties(elineVertex);
-
- log.info("eline vertice Properties {}", elineVerticeProperties);
- if ("network".equals(elineVerticeProperties.get(GraphPropertiesDictionary.ICON.getProperty()))) {
- log.info("nothing to update in eline");
- } else {
- log.info("updating property icon of eline");
- elineVertex.property(GraphPropertiesDictionary.ICON.getProperty(), "network");
- }
-
- if ("VL ELINE".equals(elineVerticeProperties.get(GraphPropertiesDictionary.NAME.getProperty()))) {
- log.info("nothing to update in eline");
- } else {
- log.info("updating property name and tag of eline");
- elineVertex.property(GraphPropertiesDictionary.NAME.getProperty(), elineFixedName);
- List<String> tags = new ArrayList<>();
- tags.add("VL ELINE");
- elineVertex.property(GraphPropertiesDictionary.TAGS.getProperty(), new Gson().toJson(tags));
- }
-
- log.info("print current properties state");
-
- vlVerticeProperties = titanGenericDao.getProperties(vlVertex);
-
- log.info("vertice vl Properties {}", vlVerticeProperties);
- elineVerticeProperties = titanGenericDao.getProperties(elineVertex);
-
- log.info("vertice eline Properties {}", elineVerticeProperties);
- }
-
- try {
- Thread.sleep(30 * 1000);
- } catch (InterruptedException e) {
- log.error("exception", e);
- }
- return true;
- } finally {
- if (operationFailed) {
- titanGenericDao.rollback();
- } else {
- titanGenericDao.commit();
- long time = System.currentTimeMillis();
- if (vlVerticeProperties != null) {
- cacheMangerOperation.updateComponentInCache(
- (String) vlVerticeProperties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()), time,
- NodeTypeEnum.Resource);
- }
- if (elineVerticeProperties != null) {
- cacheMangerOperation.updateComponentInCache(
- (String) elineVerticeProperties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()),
- time, NodeTypeEnum.Resource);
- }
- }
- }
- }
-
- /**
- * in 1610 we encounter an issue that if a capability property overrides a
- * property of a derived capability then it was created with out a property
- * type when it was first imported as part of the capability types. this
- * will add property type to the properties missing it.
- */
- public boolean fixCapabiltyPropertyTypes() {
-
- String propertyIdSecure = "tosca.capabilities.Endpoint.Admin.secure";
- String propertyIdNetworkName = "tosca.capabilities.Endpoint.Public.network_name";
- Either<TitanGraph, TitanOperationStatus> graphResult = titanGenericDao.getGraph();
-
- if (graphResult.isRight()) {
- log.error("failed to get graph object.");
- return false;
- }
-
- boolean operationFailed = false;
- try {
- TitanGraph titanGraph = graphResult.left().value();
- log.info("look up propertyIdSecure:{}", propertyIdSecure);
- Iterable<TitanVertex> vertices = titanGraph.query()
- .has(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Property), propertyIdSecure).vertices();
- if (vertices == null) {
- log.error("failed to get vertices object returned for resource id {}", propertyIdSecure);
- operationFailed = true;
- return false;
- }
- Iterator<TitanVertex> iterator = vertices.iterator();
- List<TitanVertex> vertexList = new ArrayList<>();
-
- if (iterator == null) {
- log.error("failed to get iterator over vertices object returned for resource id {}", propertyIdSecure);
- operationFailed = true;
- return false;
- }
-
- while (iterator.hasNext()) {
- TitanVertex vertex = iterator.next();
- vertexList.add(vertex);
- }
-
- if (vertexList.size() != 1) {
- log.error("failed to get 1 vertex for resource id {} instead got {}", propertyIdSecure,
- vertexList.size());
- operationFailed = true;
- return false;
- }
-
- TitanVertex propertyVerticeSecure = vertexList.get(0);
-
- log.info("look up propertyIdNetworkName:{}", propertyIdNetworkName);
- vertices = titanGraph.query()
- .has(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Property), propertyIdNetworkName).vertices();
- if (vertices == null) {
- log.error("failed to get vertices object returned for resource id {}", propertyIdNetworkName);
- operationFailed = true;
- return false;
- }
-
- iterator = vertices.iterator();
- vertexList = new ArrayList<>();
-
- if (iterator == null) {
- log.error("failed to get iterator over vertices object returned for resource id {}",
- propertyIdNetworkName);
- operationFailed = true;
- return false;
- }
-
- while (iterator.hasNext()) {
- TitanVertex vertex = iterator.next();
- vertexList.add(vertex);
- }
-
- if (!(vertexList.size() == 1)) {
- log.error("failed to get 1 vertex for resource id {} instead got {}", propertyIdNetworkName,
- vertexList.size());
- operationFailed = true;
- return false;
- }
-
- TitanVertex propertyVerticeNetworkName = vertexList.get(0);
-
- Map<String, Object> verticeNetworkNameProperties = titanGenericDao
- .getProperties(propertyVerticeNetworkName);
-
- log.info("vertice NetworkName Properties {}", verticeNetworkNameProperties);
- Object type = verticeNetworkNameProperties.get(GraphPropertiesDictionary.TYPE.getProperty());
- if (type == null || "".equals(type)) {
- log.info("updating property Vertice Network Name");
- propertyVerticeNetworkName.property(GraphPropertiesDictionary.TYPE.getProperty(), "string");
- }
-
- Map<String, Object> verticeSecureProperties = titanGenericDao.getProperties(propertyVerticeSecure);
-
- log.info("vertice Secure Properties {}", verticeSecureProperties);
-
- type = verticeSecureProperties.get(GraphPropertiesDictionary.TYPE.getProperty());
-
- if (type == null || "".equals(type)) {
- log.info("updating property Vertice Secure");
- propertyVerticeSecure.property(GraphPropertiesDictionary.TYPE.getProperty(), "boolean");
- }
-
- log.info("print current properties state");
-
- verticeNetworkNameProperties = titanGenericDao.getProperties(propertyVerticeNetworkName);
-
- log.info("vertice NetworkName Properties {}", verticeNetworkNameProperties);
-
- verticeSecureProperties = titanGenericDao.getProperties(propertyVerticeSecure);
-
- log.info("vertice Secure Properties {}", verticeSecureProperties);
-
- return true;
- } finally {
- if (operationFailed) {
- titanGenericDao.rollback();
- } else {
- titanGenericDao.commit();
- }
- }
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1610/ToscaArtifactsAlignment.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1610/ToscaArtifactsAlignment.java
deleted file mode 100644
index 673190e8c1..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1610/ToscaArtifactsAlignment.java
+++ /dev/null
@@ -1,461 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1610;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.operations.api.IArtifactOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.AbstractOperation;
-import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.resources.data.ArtifactData;
-import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.be.resources.data.ServiceMetadataData;
-import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.util.StreamUtils;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import fj.data.Either;
-
-/**
- * This Class holds the logic to add Tosca Artifacts placeholder and payload.<br>
- * This addition is done for old version of Services and Resources (pre 1610) that weren't created with them.<br>
- *
- * @author mshitrit <br>
- *
- *
- */
-public class ToscaArtifactsAlignment extends AbstractOperation {
- @Autowired
- private IArtifactOperation artifactOperation;
-
- @Autowired
- private ServiceBusinessLogic serviceBusinessLogic;
-
- private static Logger log = LoggerFactory.getLogger(ToscaArtifactsAlignment.class.getName());
-
- private static final String ERROR_PREFIX = "Tosca Artifact Alignment Error: ";
-
- // API that Fetches Resource
- private final Function<ComponentMetadataData, Resource> resourceFetcher = componentMD -> getComponent(componentMD, ComponentTypeEnum.RESOURCE);
- // API that Fetches Service
- private final Function<ComponentMetadataData, Service> serviceFetcher = componentMD -> getComponent(componentMD, ComponentTypeEnum.SERVICE);
- // Class Getters
- private final Supplier<Class<ResourceMetadataData>> resourceClassGetter = () -> ResourceMetadataData.class;
- private final Supplier<Class<ServiceMetadataData>> serviceClassGetter = () -> ServiceMetadataData.class;
-
- /**
- * This method holds the logic to add Tosca Artifacts placeholder and payload.<br>
- *
- * @return true if succeed otherwise returns false
- */
- public boolean alignToscaArtifacts() {
- Wrapper<TitanOperationStatus> errorWrapper = new Wrapper<>();
- List<ResourceMetadataData> allResources = new ArrayList<>();
- List<ResourceMetadataData> resourcesWithoutToscaPlaceHolder = new ArrayList<>();
- List<ServiceMetadataData> allServices = new ArrayList<>();
- List<ServiceMetadataData> servicesWithoutToscaPlaceHolder = new ArrayList<>();
- log.debug("alignToscaArtifacts Start");
- try {
-
- if (errorWrapper.isEmpty()) {
- log.info("Fetching all resources");
- fillAllComponetOfSpecificType(allResources, NodeTypeEnum.Resource, resourceClassGetter, errorWrapper);
- }
-
- if (errorWrapper.isEmpty()) {
- // Filter Resources Without Tosca Artifacts
- log.info("filtering resources to add tosca placeholder");
- Either<List<ResourceMetadataData>, TitanOperationStatus> eitherRelevantResources = getComponentsWithMissingToscaArtifacts(resourceClassGetter, NodeTypeEnum.Resource, allResources);
- fillListOrWrapper(errorWrapper, resourcesWithoutToscaPlaceHolder, eitherRelevantResources);
- }
-
- if (errorWrapper.isEmpty()) {
- // Add PlaceHolders To Resources
- log.info("adding tosca placeholders artifacts to resources");
- addToscaArtifactToComponents(resourcesWithoutToscaPlaceHolder, resourceFetcher, NodeTypeEnum.Resource, errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- // Add payload to Resources
- log.info("generating payload to tosca artifacts on resources");
- fillResourcesPayload(allResources, errorWrapper);
- }
-
- if (errorWrapper.isEmpty()) {
- log.info("Fetching all services");
- fillAllComponetOfSpecificType(allServices, NodeTypeEnum.Service, serviceClassGetter, errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- // Filter Services Without Tosca Artifacts
- log.info("filtering services to add tosca placeholder");
- Either<List<ServiceMetadataData>, TitanOperationStatus> eitherRelevantServices = getComponentsWithMissingToscaArtifacts(serviceClassGetter, NodeTypeEnum.Service, allServices);
- fillListOrWrapper(errorWrapper, servicesWithoutToscaPlaceHolder, eitherRelevantServices);
- }
-
- if (errorWrapper.isEmpty()) {
- // Add PlaceHolders To Services
- log.info("adding tosca placeholders artifacts to services");
- addToscaArtifactToComponents(servicesWithoutToscaPlaceHolder, serviceFetcher, NodeTypeEnum.Service, errorWrapper);
- }
-
- if (errorWrapper.isEmpty()) {
- // Filter Services for Payload Add
- // Add payload to Services
- log.info("generating payload to tosca artifacts on services");
- fillToscaArtifactPayload(allServices, serviceFetcher, errorWrapper);
- }
- } finally {
- titanGenericDao.commit();
- }
- return errorWrapper.isEmpty();
-
- }
-
- private void fillResourcesPayload(List<ResourceMetadataData> allResources, Wrapper<TitanOperationStatus> errorWrapper) {
- if (errorWrapper.isEmpty()) {
- // First Only Non VF (CP, VL & VFC)
- List<ResourceMetadataData> basicResources = allResources.stream().filter(e -> isBasicResource((ResourceMetadataDataDefinition) e.getMetadataDataDefinition())).collect(Collectors.toList());
- // Filter resources for Payload Add
- // Add payload to resources
- fillToscaArtifactPayload(basicResources, resourceFetcher, errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- // VFs
- List<ResourceMetadataData> complexResource = allResources.stream().filter(e -> ((ResourceMetadataDataDefinition) e.getMetadataDataDefinition()).getResourceType() == ResourceTypeEnum.VF).collect(Collectors.toList());
- // Filter resources for Payload Add
- // Add payload to resources
- fillToscaArtifactPayload(complexResource, resourceFetcher, errorWrapper);
- }
- }
-
- private boolean isBasicResource(ResourceMetadataDataDefinition resourceMetadataDataDefinition) {
- final ResourceTypeEnum resourceType = resourceMetadataDataDefinition.getResourceType();
- boolean isBasicResource = resourceType == ResourceTypeEnum.CP || resourceType == ResourceTypeEnum.VL || resourceType == ResourceTypeEnum.VFC;
- return isBasicResource;
- }
-
- private <T extends ComponentMetadataData> void fillAllComponetOfSpecificType(List<T> components, NodeTypeEnum nodeType, Supplier<Class<T>> classGetter, Wrapper<TitanOperationStatus> errorWrapper) {
-
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.IS_DELETED.getProperty(), true);
- Either<List<T>, TitanOperationStatus> eitherComponentMD = titanGenericDao.getByCriteria(nodeType, null, props, classGetter.get());
- if (eitherComponentMD.isLeft()) {
- components.addAll(eitherComponentMD.left().value());
- } else {
- final TitanOperationStatus errorType = eitherComponentMD.right().value();
- if (errorType != TitanOperationStatus.NOT_FOUND) {
- log.error("{} When fetching all components of type:{} a titan error occured:{}", ERROR_PREFIX, nodeType.getName(), errorType.name());
- errorWrapper.setInnerElement(errorType);
- }
- }
-
- }
-
- private <T extends ComponentMetadataData, R extends Component> void addToscaArtifactToComponents(List<T> relevantResources, Function<ComponentMetadataData, R> componentConvertor, NodeTypeEnum nodeType,
- Wrapper<TitanOperationStatus> errorWrapper) {
-
- // This Stream contains all create tosca placeholder results
- Stream<StorageOperationStatus> addToscaToComponentsResultsStream = relevantResources.stream().map(e -> addToscaArtifacts(e, nodeType, componentConvertor));
- // Execute the stream, and collect error
- Optional<StorageOperationStatus> optionalError = addToscaToComponentsResultsStream.filter(e -> e != StorageOperationStatus.OK).findFirst();
-
- // Handle error
- if (optionalError.isPresent()) {
- errorWrapper.setInnerElement(TitanOperationStatus.NOT_CREATED);
- }
- }
-
- private <R extends Component> R getComponent(ComponentMetadataData md, ComponentTypeEnum componentTypeEnum) {
- R result = null;
- Either<R, StorageOperationStatus> eitherComponent = serviceBusinessLogic.getComponent(md.getMetadataDataDefinition().getUniqueId(), componentTypeEnum);
- if (eitherComponent.isRight()) {
- log.error("{} When fetching component {} of type:{} with uniqueId:{}", ERROR_PREFIX, md.getMetadataDataDefinition().getName(), componentTypeEnum.getValue(), md.getMetadataDataDefinition().getUniqueId());
- } else {
- result = eitherComponent.left().value();
- }
- return result;
- }
-
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> populateToscaArtifactsWithLog(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> ret;
- try {
- ret = serviceBusinessLogic.populateToscaArtifacts(component, user, isInCertificationRequest, inTransaction, shouldLock);
- if (ret.isLeft()) {
- log.debug("Added payload to tosca artifacts of component {} of type:{} with uniqueId:{}", component.getName(), component.getComponentType().getValue(), component.getUniqueId());
- }
- return ret;
- } catch (Exception e) {
- log.error("{} Exception Occured When filling tosca artifact payload for component {} of type:{} with uniqueId:{}", ERROR_PREFIX, component.getName(), component.getComponentType().name(), component.getUniqueId(), e);
- throw e;
- }
- }
-
- private <R extends Component, T extends ComponentMetadataData> void fillToscaArtifactPayload(List<T> relevantComponents, Function<ComponentMetadataData, R> componentCreator, Wrapper<TitanOperationStatus> errorWrapper) {
-
- final User dummyUser = buildDummyUser();
- // Stream for all fill payload results
- Stream<ImmutablePair<Component, Either<Either<ArtifactDefinition, Operation>, ResponseFormat>>>
- // Filter elements that needs generation of tosca payload
- fillToscaPayloadResultsStream = relevantComponents.stream().filter(e -> isGenerateToscaPayload(e))
- // Converts ComponentMetadataData to Component
- .map(e -> componentCreator.apply(e))
- // For each component generate payload for tosca
- // artifacts
- .map(component -> {
- return new ImmutablePair<Component, Either<Either<ArtifactDefinition, Operation>, ResponseFormat>>(component, populateToscaArtifactsWithLog(component, dummyUser, true, true, false));
- });
-
- try {
- // execute and the stream
- Optional<Component> optionalError = fillToscaPayloadResultsStream.
- // filter in error
- filter(e -> e.getRight().isRight())
- // convert the result to error and execute the stream
- .map(e -> e.getLeft()).findFirst();
-
- // Check if error occurred
- if (optionalError.isPresent()) {
- Component component = optionalError.get();
- log.error("{} When filling tosca artifact payload for component {} of type:{} with uniqueId:{}", ERROR_PREFIX, component.getName(), component.getComponentType().name(), component.getUniqueId());
-
- errorWrapper.setInnerElement(TitanOperationStatus.GENERAL_ERROR);
- }
- } catch (Exception e) {
- log.error("{} When filling tosca artifact payload for components : {}", ERROR_PREFIX, e.getMessage(), e);
- errorWrapper.setInnerElement(TitanOperationStatus.GENERAL_ERROR);
- }
- }
-
- private <R extends Component> StorageOperationStatus addToscaArtifacts(ComponentMetadataData component, NodeTypeEnum nodeType, Function<ComponentMetadataData, R> componentCreator) {
-
- StorageOperationStatus result = StorageOperationStatus.OK;
- R componentDefinition = componentCreator.apply(component);
-
- // Fetch artifacts to be Added
- Either<List<ArtifactDefinition>, StorageOperationStatus> eitherToscaArtifacts = getToscaArtifactsToAdd(componentDefinition);
- if (eitherToscaArtifacts.isRight()) {
- result = eitherToscaArtifacts.right().value();
- } else {
- List<ArtifactDefinition> toscaArtifactsToAdd = eitherToscaArtifacts.left().value();
- if (!CollectionUtils.isEmpty(eitherToscaArtifacts.left().value())) {
- final Stream<ImmutablePair<ArtifactDefinition, Either<ArtifactDefinition, StorageOperationStatus>>> createdToscaPlaceHolderStream = toscaArtifactsToAdd.stream()
- // creates the artifact in the graph
- .map(artifactDef -> new ImmutablePair<ArtifactDefinition, Either<ArtifactDefinition, StorageOperationStatus>>(artifactDef,
- artifactOperation.addArifactToComponent(artifactDef, componentDefinition.getUniqueId(), nodeType, false, true)));
-
- // Execute the stream, and collect error
- Optional<ImmutablePair<ArtifactDefinition, StorageOperationStatus>> optionalError = createdToscaPlaceHolderStream.filter(e -> e.getRight().isRight()).map(e -> new ImmutablePair<>(e.getLeft(), e.getRight().right().value()))
- .findFirst();
-
- // In case error occurred
- if (optionalError.isPresent()) {
- ArtifactDefinition toscaArtifact = optionalError.get().getLeft();
- StorageOperationStatus storageError = optionalError.get().getRight();
- log.error("{} When adding tosca artifact of type {} to component {} of type:{} with uniqueId:{} a storageError occurred:{}", ERROR_PREFIX, toscaArtifact.getArtifactType(), component.getMetadataDataDefinition().getName(),
- nodeType.getName(), component.getMetadataDataDefinition().getUniqueId(), storageError.name());
-
- result = storageError;
- } else {
- log.debug("Added tosca artifacts to component {} of type:{} with uniqueId:{}", component.getMetadataDataDefinition().getName(), nodeType.getName(), component.getMetadataDataDefinition().getUniqueId());
- }
-
- }
- }
-
- return result;
- }
-
- private <R extends Component> Either<List<ArtifactDefinition>, StorageOperationStatus> getToscaArtifactsToAdd(R componentDefinition) {
-
- Either<List<ArtifactDefinition>, StorageOperationStatus> result;
- List<ArtifactDefinition> toscaArtifactsAlreadyExist = new ArrayList<>();
- if (!MapUtils.isEmpty(componentDefinition.getToscaArtifacts())) {
- toscaArtifactsAlreadyExist.addAll(componentDefinition.getToscaArtifacts().values());
- }
-
- // Set Tosca Artifacts on component
- serviceBusinessLogic.setToscaArtifactsPlaceHolders(componentDefinition, buildDummyUser());
-
- List<ArtifactDefinition> toscaArtifactsToAdd = new ArrayList<>();
- if (!MapUtils.isEmpty(componentDefinition.getToscaArtifacts())) {
- final Collection<ArtifactDefinition> allToscaArtifacts = componentDefinition.getToscaArtifacts().values();
- Set<String> artifactTypesExist = toscaArtifactsAlreadyExist.stream().map(e -> e.getArtifactType()).collect(Collectors.toSet());
- toscaArtifactsToAdd = allToscaArtifacts.stream().filter(e -> !artifactTypesExist.contains(e.getArtifactType())).collect(Collectors.toList());
- result = Either.left(toscaArtifactsToAdd);
- } else {
- log.error("{} failed to add tosca artifacts in bussiness logic to component {} of type:{} with uniqueId:{}", ERROR_PREFIX, componentDefinition.getName(), componentDefinition.getComponentType().getValue(),
- componentDefinition.getUniqueId());
- result = Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
- }
- return result;
- }
-
- private User buildDummyUser() {
- User user = new User();
- user.setUserId("migrationTask");
- return user;
- }
-
- private boolean isGenerateToscaPayload(ComponentMetadataData component) {
- final String state = component.getMetadataDataDefinition().getState();
- boolean componentLifeCycleStateIsValid = LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name().equals(state) || LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name().equals(state);
-
- return !componentLifeCycleStateIsValid;
-
- }
-
- private <T> void fillListOrWrapper(Wrapper<TitanOperationStatus> wrapper, List<T> listToFill, Either<List<T>, TitanOperationStatus> either) {
- if (either.isRight()) {
- final TitanOperationStatus errorType = either.right().value();
- if (errorType != TitanOperationStatus.NOT_FOUND) {
- wrapper.setInnerElement(errorType);
- }
- } else {
- listToFill.addAll(either.left().value());
- }
- }
-
- private <T extends ComponentMetadataData> Either<List<T>, TitanOperationStatus> getComponentsWithMissingToscaArtifacts(Supplier<Class<T>> classGetter, NodeTypeEnum nodeType, List<T> allComponents) {
-
- Either<List<T>, TitanOperationStatus> result;
- Stream<ImmutablePair<T, Either<List<ArtifactData>, TitanOperationStatus>>> componentsWithToscaStream =
- // Create a Stream of pairs : component and its Tosca Artifacts
- allComponents.stream().map(e -> new ImmutablePair<>(e, getToscaArtifatcs(e, nodeType)));
-
- List<ImmutablePair<T, Either<List<ArtifactData>, TitanOperationStatus>>> componentsWithToscaArtifacts =
- // Collect the stream to list.
- // in case getToscaArtifatcs failed, the first failure is
- // added to the list
- // (the collection stops after first failure)
- StreamUtils.takeWhilePlusOneNoEval(componentsWithToscaStream, e -> e.getRight().isLeft()).collect(Collectors.toList());
-
- // retrieve the failure optional (it may or may not exist)
- Optional<TitanOperationStatus> isErrorOccured = componentsWithToscaArtifacts.stream()
- // convert to the right side of the pair of type Either
- .map(e -> e.getRight())
- // Filter in only the errors
- .filter(e -> e.isRight()).
- // map the error from Either to TitanOperationStatus
- map(e -> e.right().value()).findFirst();
-
- // In case failure occurred
- if (isErrorOccured.isPresent()) {
- result = Either.right(isErrorOccured.get());
- // In case NO failure occurred
- } else {
- List<T> filteredComponents = componentsWithToscaArtifacts.stream()
- // Filter in only elements that does NOT have tosca
- // artifacts
- .filter(e -> isNotContainAllToscaArtifacts(e))
- // Convert back to Components List & collect
- .map(e -> e.getLeft()).collect(Collectors.toList());
-
- result = Either.left(filteredComponents);
- }
-
- return result;
- }
-
- private <T extends ComponentMetadataData> boolean isNotContainAllToscaArtifacts(ImmutablePair<T, Either<List<ArtifactData>, TitanOperationStatus>> pair) {
-
- final List<ArtifactData> artifactList = pair.getRight().left().value();
-
- Set<ArtifactTypeEnum> filteredToscaList = artifactList.stream().
- // Convert to ArtifactDataDefinition
- map(e -> e.getArtifactDataDefinition()).
- // Filter in Only Tosca Artifacts
- filter(e -> e.getArtifactGroupType() == ArtifactGroupTypeEnum.TOSCA).
- // Convert To ArtifactTypeEnum
- map(e -> ArtifactTypeEnum.findType(e.getArtifactType())).
- // Filter Out nulls in case of Type not found
- filter(e -> e != null).collect(Collectors.toSet());
-
- boolean toscaArifactContained = filteredToscaList.contains(ArtifactTypeEnum.TOSCA_CSAR) && filteredToscaList.contains(ArtifactTypeEnum.TOSCA_TEMPLATE);
- return !toscaArifactContained;
- }
-
- private <T extends ComponentMetadataData> Either<List<ArtifactData>, TitanOperationStatus> getToscaArtifatcs(T component, NodeTypeEnum nodeType) {
-
- Either<List<ArtifactData>, TitanOperationStatus> result;
- // All The Artifacts of the Component
- Either<List<ImmutablePair<ArtifactData, GraphEdge>>, TitanOperationStatus> eitherComponentArtifacts = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(nodeType), component.getMetadataDataDefinition().getUniqueId(),
- GraphEdgeLabels.ARTIFACT_REF, NodeTypeEnum.ArtifactRef, ArtifactData.class);
-
- if (eitherComponentArtifacts.isLeft()) {
- // Convert Artifact Edge Pair to Artifact
- List<ArtifactData> toscaArtifacts = eitherComponentArtifacts.left().value().stream()
- // map ImmutablePair<ArtifactData, GraphEdge> to
- // ArtifactData
- .map(e -> e.getLeft())
- // Filter in only Tosca Artifacts
- .filter(artifact -> artifact.getArtifactDataDefinition().getArtifactGroupType() == ArtifactGroupTypeEnum.TOSCA)
- // Collect
- .collect(Collectors.toList());
- result = Either.left(toscaArtifacts);
- } else if (eitherComponentArtifacts.right().value() == TitanOperationStatus.NOT_FOUND) {
- result = Either.left(new ArrayList<>());
- } else {
- final TitanOperationStatus titanError = eitherComponentArtifacts.right().value();
- log.error("{} When fetching artifacts for component {} of type:{} with uniqueId:{} a titanError occurred:{}", ERROR_PREFIX, component.getMetadataDataDefinition().getName(), nodeType.getName(),
- component.getMetadataDataDefinition().getUniqueId(), titanError.name());
-
- result = Either.right(titanError);
- }
-
- return result;
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/DataTypesUpdate.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/DataTypesUpdate.java
deleted file mode 100644
index d7f36840c7..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/DataTypesUpdate.java
+++ /dev/null
@@ -1,428 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1702;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.components.impl.ImportUtils;
-import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
-import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
-import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
-import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
-import org.openecomp.sdc.be.resources.data.PropertyData;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.yaml.snakeyaml.Yaml;
-
-import fj.data.Either;
-
-/**
- * Allows to update existing or create new data types according input file (yaml)
- * @author ns019t
- *
- */
-public class DataTypesUpdate {
-
- private static Logger log = LoggerFactory.getLogger(Migration1702.class.getName());
-
- @Autowired
- private PropertyOperation propertyOperation;
- @Autowired
- private ComponentsUtils componentsUtils;
-
- @SuppressWarnings("unchecked")
- /**
- * Updates existing or creates new data types according input file (yaml)
- * @param dataTypeYmlFilePath
- * @return
- */
- public boolean updateDataTypes(String dataTypeYmlFilePath) {
-
-
- List<String> dataTypesToUpdate = new ArrayList<>();
- dataTypesToUpdate.add("org.openecomp.datatypes.EcompHoming");
- dataTypesToUpdate.add("org.openecomp.datatypes.EcompNaming");
- dataTypesToUpdate.add("org.openecomp.datatypes.network.NetworkAssignments");
- dataTypesToUpdate.add("org.openecomp.datatypes.network.ProviderNetwork");
- dataTypesToUpdate.add("org.openecomp.datatypes.network.NetworkFlows");
- dataTypesToUpdate.add("org.openecomp.datatypes.Artifact");
- dataTypesToUpdate.add("org.openecomp.datatypes.network.VlanRequirements");
- dataTypesToUpdate.add("org.openecomp.datatypes.network.IpRequirements");
- dataTypesToUpdate.add("org.openecomp.datatypes.network.MacAssignments");
- dataTypesToUpdate.add("org.openecomp.datatypes.network.MacRequirements");
- dataTypesToUpdate.add("org.openecomp.datatypes.heat.contrailV2.virtual.machine.subInterface.AddressPairIp");
- dataTypesToUpdate.add("org.openecomp.datatypes.heat.contrailV2.virtual.machine.subInterface.MacAddress");
- dataTypesToUpdate.add("org.openecomp.datatypes.heat.contrailV2.virtual.machine.subInterface.Properties");
- dataTypesToUpdate.add("org.openecomp.datatypes.heat.contrailV2.virtual.machine.subInterface.AddressPair");
- dataTypesToUpdate.add("org.openecomp.datatypes.heat.contrailV2.virtual.machine.subInterface.AddressPairs");
-
- boolean isSuccessful = true;
- List<DataTypeDefinition> dataTypes = extractDataTypesFromYaml(dataTypeYmlFilePath);
-
- if(CollectionUtils.isEmpty(dataTypes)){
- isSuccessful = false;
- }
-
- List<ImmutablePair<DataTypeDefinition, Boolean>> createdElementTypes = new ArrayList<>();
-
- Iterator<DataTypeDefinition> elementTypeItr = dataTypes.iterator();
- if(isSuccessful ){
- try {
- while (elementTypeItr.hasNext()) {
- DataTypeDefinition elementType = elementTypeItr.next();
- String elementName = elementType.getName();
- Either<ActionStatus, ResponseFormat> validateElementType = validateDataType(elementType);
- if (validateElementType.isRight()) {
- log.debug("Failed to validate data type {}. Status is {}. ", elementName, validateElementType.right().value());
- isSuccessful = false;
- break;
- }
- log.debug("Going to get data type by name {}. ", elementName);
- Either<DataTypeDefinition, StorageOperationStatus> findElementType = propertyOperation.getDataTypeByNameWithoutDerived(elementName);
- if (findElementType.isRight()) {
- StorageOperationStatus status = findElementType.right().value();
- if (status != StorageOperationStatus.NOT_FOUND) {
- log.debug("Failed to fetch data type {}. Status is {}. ", elementName , validateElementType.right().value());
- isSuccessful = false;
- break;
- } else {
- log.debug("Going to add data type with name {}. ", elementName);
- Either<DataTypeDefinition, StorageOperationStatus> dataModelResponse = propertyOperation.addDataType(elementType);
-
- if (dataModelResponse.isRight()) {
- if (dataModelResponse.right().value() != StorageOperationStatus.SCHEMA_VIOLATION) {
- log.debug("Failed to add data type {}. Status is {}. ", elementName , dataModelResponse.right().value());
- isSuccessful = false;
- break;
- } else {
- createdElementTypes.add(new ImmutablePair<DataTypeDefinition, Boolean>(elementType, false));
- }
- } else {
- createdElementTypes.add(new ImmutablePair<DataTypeDefinition, Boolean>(elementType, true));
- }
-
- }
- } else {
- log.debug("Going to update data type with name {}. ", elementName);
- Either<DataTypeDefinition, StorageOperationStatus> updateDataTypeRes = propertyOperation.updateDataType(elementType, findElementType.left().value());
- if (updateDataTypeRes.isRight()) {
- StorageOperationStatus status = updateDataTypeRes.right().value();
- if (status == StorageOperationStatus.OK) {
- createdElementTypes.add(new ImmutablePair<DataTypeDefinition, Boolean>(elementType, false));
- } else {
- log.debug("Failed to update data type {}. Status is {}. ", elementName , updateDataTypeRes.right().value());
- isSuccessful = false;
- break;
- }
- } else {
- createdElementTypes.add(new ImmutablePair<DataTypeDefinition, Boolean>(elementType, true));
- }
- }
- }
- } finally {
- if(isSuccessful){
- propertyOperation.getTitanGenericDao().commit();
- }else{
- propertyOperation.getTitanGenericDao().rollback();
- }
- }
- }
- return isSuccessful;
- }
-
- @SuppressWarnings("unchecked")
- static public List<DataTypeDefinition> extractDataTypesFromYaml(String dataTypeYmlFilePath) {
- String dataTypeName;
- List<DataTypeDefinition> dataTypes = new ArrayList<>();
- try {
- File file = new File(dataTypeYmlFilePath);
- FileReader fr = new FileReader(file);
- Map<String, Object> toscaJson = (Map<String, Object>) new Yaml().load(fr);
-
- Iterator<Entry<String, Object>> elementTypesEntryItr = toscaJson.entrySet().iterator();
- while (elementTypesEntryItr.hasNext()) {
- Entry<String, Object> elementTypeNameDataEntry = elementTypesEntryItr.next();
- dataTypeName = elementTypeNameDataEntry.getKey();
- Map<String, Object> elementTypeJsonData = (Map<String, Object>) elementTypeNameDataEntry.getValue();
-
- DataTypeDefinition dataType = new DataTypeDefinition();
- dataType.setName(dataTypeName);
-
- if (elementTypeJsonData != null) {
-
- if (elementTypeJsonData.containsKey(ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
- dataType.setDescription( (String)elementTypeJsonData.get(ToscaTagNamesEnum.DESCRIPTION.getElementName()));
- }
- if (elementTypeJsonData.containsKey(ToscaTagNamesEnum.DERIVED_FROM.getElementName())) {
- dataType.setDerivedFromName( (String)elementTypeJsonData.get(ToscaTagNamesEnum.DERIVED_FROM.getElementName()));
- }
- List<PropertyDefinition> properties = getProperties(elementTypeJsonData);
- if (elementTypeJsonData.containsKey(ToscaTagNamesEnum.PROPERTIES.getElementName())) {
- dataType.setProperties(properties);
- }
- }
- dataTypes.add(dataType);
- }
-
- } catch (Exception e) {
- log.debug("Failed to extract data types from Yaml file {}. ", dataTypeYmlFilePath);
- e.printStackTrace();
- }
- return dataTypes;
- }
-
- static public List<PropertyDefinition> getProperties(Map<String, Object> toscaJson) {
- List<PropertyDefinition> values = null;
- Either<Map<String, PropertyDefinition>, ResultStatusEnum> properties = ImportUtils.getProperties(toscaJson);
-
- if (properties.isLeft()) {
- values = new ArrayList<>();
- Map<String, PropertyDefinition> propertiesMap = properties.left().value();
- if (propertiesMap != null && propertiesMap.isEmpty() == false) {
-
- for (Entry<String, PropertyDefinition> entry : propertiesMap.entrySet()) {
- String propName = entry.getKey();
- PropertyDefinition propertyDefinition = entry.getValue();
- PropertyDefinition newPropertyDefinition = new PropertyDefinition(propertyDefinition);
- newPropertyDefinition.setName(propName);
- values.add(newPropertyDefinition);
- }
- }
- }
-
- return values;
- }
-
- private Either<ActionStatus, ResponseFormat> validateDataType(DataTypeDefinition dataType) {
-
- String dataTypeName = dataType.getName();
- List<PropertyDefinition> properties = dataType.getProperties();
- if (properties == null) {
- // At least one parameter should be defined either in the properties
- // section or at one of the parents
- String derivedDataType = dataType.getDerivedFromName();
- // If there are no properties, then we can create a data type if it
- // is an abstract one or it derives from non abstract data type
- if ((derivedDataType == null || derivedDataType.isEmpty())) {
- if (false == isAbstract(dataType.getName())) {
- if (false == ToscaPropertyType.isScalarType(dataTypeName)) {
- log.debug("Data type {} must have properties unless it derives from non abstract data type",dataType.getName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM, dataType, null);
-
- return Either.right(responseFormat);
- }
- }
- } else {
- // if it is not a scalar data type and it derives from abstract
- // data type, we should reject the request.
- if (false == ToscaPropertyType.isScalarType(dataTypeName) && true == isAbstract(derivedDataType)) {
- log.debug("Data type {} which derived from abstract data type must have at least one property",dataType.getName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM, dataType, null);
-
- return Either.right(responseFormat);
- }
- }
- } else {
- // properties tag cannot be empty
- if (properties.isEmpty()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY, dataType, null);
-
- return Either.right(responseFormat);
- }
-
- // check no duplicates
- Set<String> collect = properties.stream().map(p -> p.getName()).collect(Collectors.toSet());
- if (collect != null) {
- if (properties.size() != collect.size()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_DUPLICATE_PROPERTY, dataType, null);
-
- return Either.right(responseFormat);
- }
- }
-
- List<String> propertiesWithSameTypeAsDataType = properties.stream().filter(p -> p.getType().equals(dataType.getName())).map(p -> p.getName()).collect(Collectors.toList());
- if (propertiesWithSameTypeAsDataType != null && propertiesWithSameTypeAsDataType.isEmpty() == false) {
- log.debug("The data type {} contains properties with the type {}",dataType.getName(),dataType.getName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE, dataType, propertiesWithSameTypeAsDataType);
-
- return Either.right(responseFormat);
- }
- }
-
- String derivedDataType = dataType.getDerivedFromName();
- if (derivedDataType != null) {
- Either<DataTypeDefinition, StorageOperationStatus> derivedDataTypeByName = propertyOperation.getDataTypeByName(derivedDataType, true);
- if (derivedDataTypeByName.isRight()) {
- StorageOperationStatus status = derivedDataTypeByName.right().value();
- if (status == StorageOperationStatus.NOT_FOUND) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_DERIVED_IS_MISSING, dataType, null);
-
- return Either.right(responseFormat);
- } else {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.GENERAL_ERROR, dataType, null);
-
- return Either.right(responseFormat);
-
- }
- } else {
-
- DataTypeDefinition derivedDataTypeDef = derivedDataTypeByName.left().value();
- if (properties != null && properties.isEmpty() == false) {
-
- if (true == isScalarType(derivedDataTypeDef)) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_CANNOT_HAVE_PROPERTIES, dataType, null);
-
- return Either.right(responseFormat);
- }
-
- Set<String> allParentsProps = new HashSet<>();
- do {
- List<PropertyDefinition> currentParentsProps = derivedDataTypeDef.getProperties();
- if (currentParentsProps != null) {
- for (PropertyDefinition propertyDefinition : currentParentsProps) {
- allParentsProps.add(propertyDefinition.getName());
- }
- }
- derivedDataTypeDef = derivedDataTypeDef.getDerivedFrom();
- } while (derivedDataTypeDef != null);
-
- // Check that no property is already defined in one of the
- // ancestors
- Set<String> alreadyExistPropsCollection = properties.stream().filter(p -> allParentsProps.contains(p.getName())).map(p -> p.getName()).collect(Collectors.toSet());
- if (alreadyExistPropsCollection != null && alreadyExistPropsCollection.isEmpty() == false) {
- List<String> duplicateProps = new ArrayList<>();
- duplicateProps.addAll(alreadyExistPropsCollection);
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR, dataType, duplicateProps);
-
- return Either.right(responseFormat);
- }
-
- }
- }
- }
- return Either.left(ActionStatus.OK);
- }
-
- private boolean isAbstract(String dataTypeName) {
-
- ToscaPropertyType isPrimitiveToscaType = ToscaPropertyType.isValidType(dataTypeName);
-
- return isPrimitiveToscaType != null && isPrimitiveToscaType.isAbstract() == true;
-
- }
-
- private boolean isScalarType(DataTypeDefinition dataTypeDef) {
-
- boolean isScalar = false;
- DataTypeDefinition dataType = dataTypeDef;
-
- while (dataType != null) {
-
- String name = dataType.getName();
- if (ToscaPropertyType.isScalarType(name)) {
- isScalar = true;
- break;
- }
-
- dataType = dataType.getDerivedFrom();
- }
-
- return isScalar;
- }
-
-// public Either<DataTypeDefinition, StorageOperationStatus> updateDataType(DataTypeDefinition newDataTypeDefinition, DataTypeDefinition oldDataTypeDefinition) {
-//
-// Either<DataTypeDefinition, StorageOperationStatus> result = null;
-//
-// try {
-//
-// List<PropertyDefinition> newProperties = newDataTypeDefinition.getProperties();
-//
-// List<PropertyDefinition> oldProperties = oldDataTypeDefinition.getProperties();
-//
-// String newDerivedFromName = getDerivedFromName(newDataTypeDefinition);
-//
-// String oldDerivedFromName = getDerivedFromName(oldDataTypeDefinition);
-//
-// String dataTypeName = newDataTypeDefinition.getName();
-//
-// List<PropertyDefinition> propertiesToAdd = new ArrayList<>();
-// if (isPropertyOmitted(newProperties, oldProperties, dataTypeName) || isPropertyTypeChanged(dataTypeName, newProperties, oldProperties, propertiesToAdd) || isDerivedFromNameChanged(dataTypeName, newDerivedFromName, oldDerivedFromName)) {
-//
-// log.debug("The new data type " + dataTypeName + " is invalid.");
-//
-// result = Either.right(StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY);
-// return result;
-// }
-//
-// if (propertiesToAdd == null || propertiesToAdd.isEmpty()) {
-// log.debug("No new properties has been defined in the new data type " + newDataTypeDefinition);
-// result = Either.right(StorageOperationStatus.OK);
-// return result;
-// }
-//
-// Either<Map<String, PropertyData>, TitanOperationStatus> addPropertiesToDataType = addPropertiesToDataType(oldDataTypeDefinition.getUniqueId(), propertiesToAdd);
-//
-// if (addPropertiesToDataType.isRight()) {
-// log.debug("Failed to update data type {} to Graph. Status is {}", oldDataTypeDefinition, addPropertiesToDataType.right().value().name());
-// BeEcompErrorManager.getInstance().logBeFailedAddingNodeTypeError("UpdateDataType", "Property");
-// result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(addPropertiesToDataType.right().value()));
-// return result;
-// } else {
-//
-// Either<DataTypeDefinition, TitanOperationStatus> dataTypeByUid = this.getDataTypeByUid(oldDataTypeDefinition.getUniqueId());
-// if (dataTypeByUid.isRight()) {
-// TitanOperationStatus status = addPropertiesToDataType.right().value();
-// log.debug("Failed to get data type {} after update. Status is {}", oldDataTypeDefinition.getUniqueId(), status.name());
-// BeEcompErrorManager.getInstance().logBeFailedRetrieveNodeError("UpdateDataType", "Property", status.name());
-// result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
-// } else {
-// result = Either.left(dataTypeByUid.left().value());
-// }
-// }
-//
-// return result;
-//
-// }
-// }
-
-}
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
deleted file mode 100644
index 6fa8b45734..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1702/Migration1702.java
+++ /dev/null
@@ -1,1406 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1702;
-
-import java.io.BufferedWriter;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.Set;
-import java.util.UUID;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.commons.math3.analysis.solvers.RiddersSolver;
-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.components.impl.ArtifactsBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ImportUtils;
-import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
-import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaTagNamesEnum;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
-import org.openecomp.sdc.be.config.Configuration.VfModuleProperty;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.graph.GraphElementFactory;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
-import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
-import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary;
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentParametersView;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.GroupDefinition;
-import org.openecomp.sdc.be.model.GroupInstance;
-import org.openecomp.sdc.be.model.GroupProperty;
-import org.openecomp.sdc.be.model.GroupTypeDefinition;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.ResourceMetadataDefinition;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation;
-import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
-import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
-import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
-import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
-import org.openecomp.sdc.be.model.operations.impl.ResourceOperation;
-import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
-import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
-import org.openecomp.sdc.be.resources.data.ArtifactData;
-import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
-import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
-import org.openecomp.sdc.be.resources.data.DataTypeData;
-import org.openecomp.sdc.be.resources.data.GroupData;
-import org.openecomp.sdc.be.resources.data.PropertyData;
-import org.openecomp.sdc.be.resources.data.PropertyValueData;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.be.resources.data.ServiceMetadataData;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.util.ValidationUtils;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.yaml.snakeyaml.Yaml;
-
-import com.thinkaurelius.titan.core.TitanGraph;
-import com.thinkaurelius.titan.core.TitanGraphQuery;
-import com.thinkaurelius.titan.core.TitanVertex;
-
-import fj.data.Either;
-
-public class Migration1702 {
- private static final String CONFIG_GROUP_TYPES_YML = "/config/groupTypes.yml";
-
- private static final String CONFIG_DATA_TYPES_YML = "/config/dataTypes.yml";
-
- private static Logger log = LoggerFactory.getLogger(Migration1702.class.getName());
-
- @Autowired
- protected TitanGenericDao titanGenericDao;
- @Autowired
- protected ResourceOperation resourceOperation;
- @Autowired
- protected ServiceOperation serviceOperation;
- @Autowired
- private ServiceBusinessLogic serviceBusinessLogic;
- @Autowired
- private GroupTypeOperation groupTypeOperation;
- @Autowired
- private PropertyOperation propertyOperation;
- @Autowired
- private ComponentsUtils componentsUtils;
- @Autowired
- private GroupOperation groupOperation;
-
- @Autowired
- private ArtifactsBusinessLogic artifactsBusinessLogic;
-
- @Autowired
- private UserBusinessLogic userAdminManager;
-
- @Autowired
- private ComponentInstanceOperation componentInstanceOperation;
-
- public boolean migrate(String appConfigDir) {
- boolean result = true;
- String methodName = "alignCustomizationUUID";
-
- try {
- if (!alignCustomizationUUID()) {
- log.error("Failed to align customization UUID");
- result = false;
- return result;
- }
- methodName = "alignGroupDataType";
- if (!alignGroupDataType()) {
- log.error("Failed to align Group data type");
- result = false;
- return result;
- }
- methodName = "alignVfModuleProperties";
- if (!alignVfModuleProperties()) {
- log.error("Failed to align Vf Module Properties");
- result = false;
- return result;
- }
- methodName = "alignDataType";
- if (!alignDataType()) {
- log.error("Failed to align data type");
- result = false;
- return result;
- }
- methodName = "alignHeatEnv";
- if (!alignHeatEnv()) {
- log.error("Failed to align heat env on VF level");
- result = false;
- return result;
- }
- methodName = "alignModuleInstances";
- if (!alignModuleInstances()) {
- log.error("Failed to align module instances");
- result = false;
- return result;
- }
-
- } catch (Exception e) {
- log.error("Failed {} with exception: ", methodName, e);
- result = false;
- }
- return result;
- }
-
- private boolean alignModuleInstances() {
- log.info(" Align Module Instances");
- boolean result = true;
- boolean statusToReturn = true;
-
- Writer writer = null;
-
- try {
- long time = System.currentTimeMillis();
- writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("runstatusModules_" + time + ".csv"), "utf-8"));
-
- writer.write("resource id, instance id, group id, status\n");
-
- Either<List<ServiceMetadataData>, TitanOperationStatus> allServices = titanGenericDao.getByCriteria(NodeTypeEnum.Service, null, ServiceMetadataData.class);
- if (allServices.isRight()) {
- if (allServices.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.error("Align heat env on Vf - Failed to fetch services {}", allServices.right().value());
- result = false;
- statusToReturn = false;
- return statusToReturn;
- } else {
- log.debug("No Services. ");
- return statusToReturn;
- }
- }
- log.info("Need to handle {} services", allServices.left().value().size());
- long handledServices = 0;
- for (ServiceMetadataData metadata : allServices.left().value()) {
- String serviceId = metadata.getMetadataDataDefinition().getUniqueId();
- Either<ImmutablePair<List<ComponentInstance>, List<RequirementCapabilityRelDef>>, TitanOperationStatus> riRes = componentInstanceOperation.getComponentInstancesOfComponent(serviceId, NodeTypeEnum.Service, NodeTypeEnum.Resource);
- if (riRes.isRight()) {
- if (riRes.right().value() == TitanOperationStatus.NOT_FOUND) {
- log.info("No instancces for service {}", serviceId);
- } else {
- log.info("Align vf modules - failed to fetch component instances for service {} error {}", riRes.right().value());
- writeModuleResultToFile(writer, serviceId, null, null, riRes.right().value());
- statusToReturn = false;
- }
- ++handledServices;
- continue;
- }
- List<ComponentInstance> componentInstances = riRes.left().value().left;
- for (ComponentInstance ci : componentInstances) {
- Either<TitanVertex, TitanOperationStatus> ciVertexRes = titanGenericDao.getVertexByProperty(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), ci.getUniqueId());
- if (ciVertexRes.isRight()) {
- log.info("Failed to fetch vertex for component instance {}, error {}", ci.getUniqueId(), ciVertexRes.right().value());
- writeModuleResultToFile(writer, serviceId, ci.getUniqueId(), null, ciVertexRes.right().value());
- statusToReturn = false;
- continue;
- }
- TitanVertex ciVertex = ciVertexRes.left().value();
- if (createGroupInstancesOnComponentInstance(writer, ci, ciVertex, serviceId) == false) {
- statusToReturn = false;
- continue;
- }
- }
- writer.flush();
- ++handledServices;
- }
-
- log.info("Handled {} services", handledServices);
- } catch (Exception e) {
- log.error("Failed {} with exception: ", "alignModuleInstances", e);
- result = false;
- statusToReturn = false;
- } finally {
-
- log.info(" Align Module Instances finished");
- if (!result) {
- log.info("Doing rollback");
- titanGenericDao.rollback();
- } else {
- log.info("Doing commit");
- titanGenericDao.commit();
- }
- try {
- writer.flush();
- writer.close();
- } catch (Exception ex) {
- /* ignore */}
- }
- return statusToReturn;
- }
-
- private boolean createGroupInstancesOnComponentInstance(Writer writer, ComponentInstance ci, TitanVertex ciVertex, String serviceId) {
- boolean statusToReturn = true;
-
- Map<String, Object> properties = titanGenericDao.getProperties(ciVertex);
- ComponentInstanceData createdComponentInstance = GraphElementFactory.createElement(NodeTypeEnum.ResourceInstance.getName(), GraphElementTypeEnum.Node, properties, ComponentInstanceData.class);
-
- Either<List<GroupDefinition>, TitanOperationStatus> groupEither = groupOperation.getAllGroupsFromGraph(ci.getComponentUid(), NodeTypeEnum.Resource);
- if (groupEither.isRight()) {
- if (groupEither.right().value() != TitanOperationStatus.OK && groupEither.right().value() != TitanOperationStatus.NOT_FOUND) {
- TitanOperationStatus status = groupEither.right().value();
- log.error("Failed to associate group instances to component instance {}. Status is {}", ci.getUniqueId(), status);
- writeModuleResultToFile(writer, serviceId, ci.getUniqueId(), null, status);
- return false;
- } else {
- log.debug("No groups for component instance {}. ", ci.getUniqueId());
-
- writeModuleResultToFile(writer, serviceId, ci.getUniqueId(), null, "No groups");
- return true;
- }
- }
- List<GroupDefinition> groupsIמResource = groupEither.left().value();
- if (groupsIמResource != null && !groupsIמResource.isEmpty()) {
- List<GroupDefinition> vfGroupsListInResource = groupsIמResource.stream().filter(p -> p.getType().equals("org.openecomp.groups.VfModule")).collect(Collectors.toList());
-
- for (GroupDefinition groupInResource : vfGroupsListInResource) {
- Iterator<Edge> edgesToInstances = ciVertex.edges(Direction.OUT, GraphEdgeLabels.GROUP_INST.getProperty());
- boolean exist = false;
- String normalizedName = ValidationUtils.normalizeComponentInstanceName(ci.getNormalizedName() + ".." + groupInResource.getName());
- String grInstId = UniqueIdBuilder.buildResourceInstanceUniuqeId(ci.getUniqueId(), groupInResource.getUniqueId(), normalizedName);
-
-
- while (edgesToInstances.hasNext()) {
- Edge edgeToInst = edgesToInstances.next();
- Vertex grInstVertex = edgeToInst.inVertex();
- String grId = (String) titanGenericDao.getProperty((TitanVertex) grInstVertex, GraphPropertiesDictionary.UNIQUE_ID.getProperty());
- if (grId.equals(grInstId)) {
- exist = true;
- break;
- }
- }
- if (!exist) {
- Either<GroupInstance, StorageOperationStatus> status = componentInstanceOperation.createGroupInstance(ciVertex, groupInResource, ci);
- if (status.isRight()) {
- log.error("Failed to create group instance {} in component instance {}. Status is {}", grInstId, ci.getUniqueId(), status.right().value());
- statusToReturn = false;
- writeModuleResultToFile(writer, serviceId, ci.getUniqueId(), grInstId, status.right().value());
- } else {
- writeModuleResultToFile(writer, serviceId, ci.getUniqueId(), grInstId, "OK");
- }
- } else {
- writeModuleResultToFile(writer, serviceId, ci.getUniqueId(), grInstId, "Exist");
- }
-
- }
- }
- return statusToReturn;
- }
-
- @SuppressWarnings("resource")
- private boolean alignHeatEnv() {
- Writer writer = null;
- log.info(" Align heat env on Vf level");
- boolean statusToReturn = true;
-
- boolean result = true;
- try {
- long time = System.currentTimeMillis();
- writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("runstatusEnv_" + time + ".csv"), "utf-8"));
-
- writer.write("resource id, operation, artifact id, status\n");
- User user = buildDummyUser();
-
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name());
-
- Either<List<ResourceMetadataData>, TitanOperationStatus> allResources = titanGenericDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
- if (allResources.isRight()) {
- if (allResources.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.error("Align heat env on Vf - Failed to fetch resources {}", allResources.right().value());
- statusToReturn = false;
- result = false;
- return statusToReturn;
- } else {
- log.debug("No VF resources. ");
- return result;
- }
- }
- List<ResourceMetadataData> resources = allResources.left().value();
- log.debug("Need to handle {} resources", resources.size());
-
- long totalHandledArtifacts = 0;
- for (ResourceMetadataData metadata : resources) {
- Either<List<ImmutablePair<ArtifactData, GraphEdge>>, TitanOperationStatus> artifactNodesRes = titanGenericDao.getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) metadata.getUniqueId(),
- GraphEdgeLabels.ARTIFACT_REF, NodeTypeEnum.ArtifactRef, ArtifactData.class);
- if (artifactNodesRes.isRight()) {
- if (artifactNodesRes.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.error("Align heat env on Vf - Failed to fetch artifacts for resources {}", metadata.getUniqueId(), artifactNodesRes.right().value());
- writer.write(metadata.getUniqueId() + ",get artifacts, ,Failed to fetch artifacts " + artifactNodesRes.right().value() + "\n");
- statusToReturn = false;
- continue;
- } else {
- log.debug("No artifact for resource {} . ", metadata.getUniqueId());
- writer.write(metadata.getUniqueId() + ",get artifacts, ,No artfacts\n");
- continue;
- }
- }
- List<ImmutablePair<ArtifactData, GraphEdge>> artifacts = artifactNodesRes.left().value();
-
- for (ImmutablePair<ArtifactData, GraphEdge> pair : artifacts) {
- ArtifactData artifactData = pair.left;
- if (isNeedCreatePlaceHolder(artifactData)) {
- // check if exist heat env - if not -> create
- String heatEnvId = (String) artifactData.getUniqueId() + "env";
- if (validateOrCreateHeatEnv(user, metadata, artifactData, heatEnvId, writer) == false) {
- statusToReturn = false;
- }
- // check if connected to group - if not -> connect
- if (validateOrAssociateHeatAnv(metadata, artifactData, heatEnvId, writer) == false) {
- statusToReturn = false;
- }
- ++totalHandledArtifacts;
- writer.flush();
- }
-
- }
- }
- log.debug("Total handled {} artifacts", totalHandledArtifacts);
- } catch (Exception e) {
- log.error("Failed {} with exception: ", "alignHeatEnv", e);
- result = false;
- } finally {
-
- log.info("Aling heat env on VF level finished ");
- if (!result) {
- log.info("Doing rollback");
- titanGenericDao.rollback();
- } else {
- log.info("Doing commit");
- titanGenericDao.commit();
- }
- try {
- writer.flush();
- writer.close();
- } catch (Exception ex) {
- /* ignore */}
- }
- return statusToReturn;
- }
-
- private boolean validateOrAssociateHeatAnv(ResourceMetadataData metadata, ArtifactData artifactData, String heatEnvId, Writer writer) {
- boolean statusToReturn = true;
-
- String resourceId = (String) metadata.getUniqueId();
- Either<ArtifactData, TitanOperationStatus> heatEnvArtifactRes = titanGenericDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), heatEnvId, ArtifactData.class);
- if (heatEnvArtifactRes.isRight()) {
- log.error("Align heat env on Vf - Failed to fetch heat env node for id {} {}", heatEnvId, heatEnvArtifactRes.right().value());
- writeResultToFile(writer, "get artifact node for relation", resourceId, heatEnvId, heatEnvArtifactRes.right().value());
- return false;
- }
- ArtifactData heatEnvArtifact = heatEnvArtifactRes.left().value();
-
- Either<List<ImmutablePair<GroupData, GraphEdge>>, TitanOperationStatus> groupsForHeatRes = titanGenericDao.getParentNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) artifactData.getUniqueId(),
- GraphEdgeLabels.GROUP_ARTIFACT_REF, NodeTypeEnum.Group, GroupData.class);
- if (groupsForHeatRes.isRight()) {
- writeResultToFile(writer, "getChildrenNodes groups for heat", resourceId, (String) artifactData.getUniqueId(), groupsForHeatRes.right().value());
- if (groupsForHeatRes.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.error("Align heat env on Vf - Failed to fetch groups for heat artifact {} in resources {} : {}", artifactData.getUniqueId(), metadata.getUniqueId(), groupsForHeatRes.right().value());
- return false;
- } else {
- log.debug("Align heat env on Vf - No groups for heat artifact {} in resources {} : {}", artifactData.getUniqueId(), metadata.getUniqueId(), groupsForHeatRes.right().value());
- return true;
- }
- }
- List<ImmutablePair<GroupData, GraphEdge>> groupsForHeat = groupsForHeatRes.left().value();
- Either<List<ImmutablePair<GroupData, GraphEdge>>, TitanOperationStatus> groupsForHeatEnvRes = titanGenericDao.getParentNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), heatEnvId, GraphEdgeLabels.GROUP_ARTIFACT_REF, NodeTypeEnum.Group,
- GroupData.class);
- List<ImmutablePair<GroupData, GraphEdge>> groupsForHeatEnv;
- if (groupsForHeatEnvRes.isRight()) {
- if (groupsForHeatEnvRes.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.error("Align heat env on Vf - Failed to fetch groups for heat env artifact {} in resources {} : ", artifactData.getUniqueId(), metadata.getUniqueId(), groupsForHeatEnvRes.right().value());
- writeResultToFile(writer, "getChildrenNodes groups for heat env", resourceId, heatEnvId, groupsForHeatEnvRes.right().value());
- return false;
- } else {
- groupsForHeatEnv = new ArrayList<>();
- }
- } else {
- groupsForHeatEnv = groupsForHeatEnvRes.left().value();
- }
-
- for (ImmutablePair<GroupData, GraphEdge> heatGroup : groupsForHeat) {
- // check if exist
- boolean exist = false;
- GroupDataDefinition groupDataDefinition = heatGroup.left.getGroupDataDefinition();
- for (ImmutablePair<GroupData, GraphEdge> heatEnvGroup : groupsForHeatEnv) {
- if (groupDataDefinition.getName().equals(heatEnvGroup.left.getGroupDataDefinition().getName())) {
- exist = true;
- break;
- }
- }
- String groupId = (String) heatGroup.left.getUniqueId();
- if (!exist) {
- // need associate
-
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(GraphPropertiesDictionary.NAME.getProperty(), heatEnvArtifact.getLabel());
- Either<GraphRelation, TitanOperationStatus> createRelation = titanGenericDao.createRelation(heatGroup.left, heatEnvArtifact, GraphEdgeLabels.GROUP_ARTIFACT_REF, properties);
- log.trace("After associate group {} to artifact {}", groupDataDefinition.getName(), heatEnvArtifact.getUniqueIdKey());
- if (createRelation.isRight()) {
- log.error("Align heat env on Vf - Failed to associate heat env artifact {} to group {} : {}", artifactData.getUniqueId(), groupDataDefinition.getUniqueId(), createRelation.right().value());
-
- writeResultToFile(writer, "associate to group- relation" + groupId, resourceId, heatEnvId, groupsForHeatRes.right().value());
- statusToReturn = false;
- } else {
- writeResultToFile(writer, "associate to group " + groupId, resourceId, heatEnvId, "OK");
- }
- } else {
- writeResultToFile(writer, "associate group " + groupId, resourceId, heatEnvId, "Exist");
- }
- }
- return statusToReturn;
- }
-
- private boolean validateOrCreateHeatEnv(User user, ResourceMetadataData metadata, ArtifactData artifactData, String heatEnvId, Writer writer) {
- String resourceId = metadata.getMetadataDataDefinition().getUniqueId();
- boolean statusToReturn = true;
- Either<ArtifactData, TitanOperationStatus> node = titanGenericDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), heatEnvId, ArtifactData.class);
- boolean isContinue = true;
- if (node.isRight()) {
- if (TitanOperationStatus.NOT_FOUND == node.right().value()) {
- // create
- ArtifactDefinition heatArtifact = new ArtifactDefinition(artifactData.getArtifactDataDefinition());
- ResourceMetadataDefinition resourceMetadataDataDefinition = new ResourceMetadataDefinition((ResourceMetadataDataDefinition) metadata.getMetadataDataDefinition());
-
- Resource resource = new Resource(resourceMetadataDataDefinition);
-
- String heatUpdater = heatArtifact.getUserIdLastUpdater();
- Either<User, ActionStatus> userHeat = userAdminManager.getUser(heatUpdater, true);
-
- Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder = artifactsBusinessLogic.createHeatEnvPlaceHolder(heatArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME, (String) metadata.getUniqueId(), NodeTypeEnum.Resource,
- metadata.getMetadataDataDefinition().getName(), userHeat.left().value(), resource, null, false);
- if (createHeatEnvPlaceHolder.isRight()) {
- log.error("Align heat env on Vf - Failed to create heat env {} for heat {} : {}", heatEnvId, heatArtifact.getUniqueId(), createHeatEnvPlaceHolder.right().value().getText());
- writeResultToFile(writer, "create placeholder", resourceId, heatEnvId, createHeatEnvPlaceHolder.right().value().getText());
- isContinue = false;
- statusToReturn = false;
- } else {
- writeResultToFile(writer, "create placeholder", resourceId, heatEnvId, "OK");
- }
- } else {
- log.error("Align heat env on Vf - Failed to fetch heat env node for id {} {}", heatEnvId, node.right().value());
- writeResultToFile(writer, "create placeholder - get", resourceId, heatEnvId, node.right().value());
- isContinue = false;
- statusToReturn = false;
- }
- } else {
- writeResultToFile(writer, "create placeholder - get", resourceId, heatEnvId, "Exist");
- }
- if (isContinue) {
- log.debug("associate heat env artifact to all resources ");
- String heatUniqueId = (String) artifactData.getUniqueId();
- Either<TitanVertex, TitanOperationStatus> heatVertexRes = titanGenericDao.getVertexByProperty(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), heatUniqueId);
- if (heatVertexRes.isRight()) {
- log.debug("Failed to fetch vertex for heat {} error {}", heatUniqueId, heatVertexRes.right().value());
- writeResultToFile(writer, "create placeholder - get heat vertex", resourceId, heatEnvId, heatVertexRes.right().value());
- statusToReturn = false;
- return statusToReturn;
- }
- TitanVertex heatVertex = heatVertexRes.left().value();
- Either<TitanVertex, TitanOperationStatus> heatEnvVertexRes = titanGenericDao.getVertexByProperty(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), heatEnvId);
- if (heatEnvVertexRes.isRight()) {
- log.debug("Failed to fetch vertex for heat env {} error {}", heatEnvId, heatEnvVertexRes.right().value());
- writeResultToFile(writer, "create placeholder - get heat env vertex", resourceId, heatEnvId, heatEnvVertexRes.right().value());
- statusToReturn = false;
- return statusToReturn;
- }
-
- Vertex heatEnvVertex = heatEnvVertexRes.left().value();
- Iterator<Edge> edgesToHeat = heatVertex.edges(Direction.IN, GraphEdgeLabels.ARTIFACT_REF.name());
- while (edgesToHeat.hasNext()) {
- Edge edgeToHeat = edgesToHeat.next();
- boolean exist = false;
- Vertex outVertexHeat = edgeToHeat.outVertex();
- Map<String, Object> outVertexProps = titanGenericDao.getProperties(outVertexHeat);
-
- String resIdToHeat = (String) outVertexProps.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
-
- Iterator<Edge> edgesToEnv = heatEnvVertex.edges(Direction.IN, GraphEdgeLabels.ARTIFACT_REF.name());
- while (edgesToEnv.hasNext()) {
- Edge edgeToEnv = edgesToEnv.next();
- Vertex outVertexEnv = edgeToEnv.outVertex();
- String resIdToEnv = (String) titanGenericDao.getProperty((TitanVertex) outVertexEnv, GraphPropertiesDictionary.UNIQUE_ID.getProperty());
- if (resIdToHeat.equals(resIdToEnv)) {
- exist = true;
- break;
- }
- }
- if (!exist) {
- Map<String, Object> properties = titanGenericDao.getProperties(edgeToHeat);
- // need to associate additional resource to heat env
- // update artifact label on edge
- String heatEnvLabel = (String) titanGenericDao.getProperty((TitanVertex) heatEnvVertex, GraphPropertiesDictionary.ARTIFACT_LABEL.getProperty());
- properties.put(GraphEdgePropertiesDictionary.NAME.getProperty(), heatEnvLabel);
-
- TitanOperationStatus createEdge = titanGenericDao.createEdge(outVertexHeat, heatEnvVertex, GraphEdgeLabels.ARTIFACT_REF, properties);
- if (createEdge == TitanOperationStatus.OK) {
- writeResultToFile(writer, "associate to resource " + resIdToHeat, resourceId, heatEnvId, "OK");
- } else {
- writeResultToFile(writer, "associate to resource " + resIdToHeat, resourceId, heatEnvId, createEdge);
- statusToReturn = false;
- }
- } else {
- writeResultToFile(writer, "associate to resource " + resIdToHeat, resourceId, heatEnvId, "Exist");
- }
- }
- }
- return statusToReturn;
- }
-
- private void writeResultToFile(Writer writer, String op, String resourceId, String artifactD, Object status) {
- try {
- StringBuffer sb = new StringBuffer(resourceId);
- sb.append(",").append(op).append(",").append(artifactD).append(",").append(status).append("\n");
- writer.write(sb.toString());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- private void writeModuleResultToFile(Writer writer, String resourceId, String instanceId, String groupId, Object status) {
- try {
- StringBuffer sb = new StringBuffer(resourceId);
- sb.append(",").append(instanceId).append(",").append(groupId).append(",").append(status).append("\n");
- writer.write(sb.toString());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- private boolean isNeedCreatePlaceHolder(ArtifactData artifactData) {
- String artifactType = artifactData.getArtifactDataDefinition().getArtifactType();
- ArtifactTypeEnum type = ArtifactTypeEnum.findType(artifactType);
- if (ArtifactGroupTypeEnum.DEPLOYMENT == artifactData.getArtifactDataDefinition().getArtifactGroupType() && (ArtifactTypeEnum.HEAT == type || ArtifactTypeEnum.HEAT_NET == type || ArtifactTypeEnum.HEAT_VOL == type)) {
- return true;
- }
- return false;
- }
-
- private boolean alignVfModuleProperties() {
- boolean result = true;
- try {
- log.info(" Align Vf module properties");
-
- final Pattern pattern = Pattern.compile("\\..(.*?)\\..");
- final String LABEL_NAME = "vf_module_label";
- final String VOLUME_GROUP_NAME = "volume_group";
-
- Either<TitanGraph, TitanOperationStatus> graph = titanGenericDao.getGraph();
- if (graph.isRight()) {
- log.error("Align Vf module properties - Failed to get graph {}", graph.right().value());
- result = false;
- return result;
- }
-
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name());
-
- Either<List<ResourceMetadataData>, TitanOperationStatus> allResources = titanGenericDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
-
- if (allResources.isRight()) {
- if (allResources.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("Align Vf module properties - no VF resources");
- result = true;
- return result;
- } else {
- log.error("Align Vf module properties - generateTosca failed fetch all resources,error {}", allResources.right().value());
- result = false;
- return result;
- }
- }
-
- List<ResourceMetadataData> listAllVFs = allResources.left().value();
-
- ComponentParametersView componentParametersView = new ComponentParametersView(true);
- componentParametersView.setIgnoreGroups(false);
- componentParametersView.setIgnoreArtifacts(false);
-
- log.info("Align Vf module properties - Starting to update the VF's");
- Map<String, VfModuleProperty> vfModuleProperties = ConfigurationManager.getConfigurationManager().getConfiguration().getVfModuleProperties();
- for (ResourceMetadataData resourceMetadataData : listAllVFs) {
- String uniqueId = (String) resourceMetadataData.getUniqueId();
-
- Either<Resource, StorageOperationStatus> resourceResponse = resourceOperation.getResource(uniqueId, componentParametersView, true);
-
- if (resourceResponse.isRight()) {
- log.error("Align Vf module properties - failed resource with UniqueID: {} , error {}", uniqueId, resourceResponse.right().value());
- result = false;
- return result;
- }
-
- Resource resource = resourceResponse.left().value();
- List<GroupDefinition> groups = resource.getGroups();
-
- if (groups == null || groups.isEmpty()) {
- log.debug("Align Vf module properties - resource UniqueID: {} does not contain groups", resource.getUniqueId());
- continue;
- } else {
-
- for (GroupDefinition groupDefinition : groups) {
-
- if (groupDefinition.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
- log.info("update vf module proerties for group {} ", groupDefinition.getUniqueId());
-
- List<GroupProperty> properties = groupDefinition.convertToGroupProperties();
- if (properties == null) {
- properties = new ArrayList<>();
- }
- Boolean isBase = false;
- List<String> artifacts = groupDefinition.getArtifacts();
- if (artifacts == null) {
- artifacts = new ArrayList<>();
- }
- Boolean isVolumeGroup = false;
- for (String artifactId : artifacts) {
- ArtifactDefinition artifactDef = null;
- Map<String, ArtifactDefinition> deploymentArtifacts = resource.getDeploymentArtifacts();
- artifactDef = findArtifactInList(deploymentArtifacts, artifactId);
- if (artifactDef != null && artifactDef.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) {
- isVolumeGroup = true;
- break;
- }
- }
- for (GroupProperty groupProperty : properties) {
- if (groupProperty.getName().equals(Constants.IS_BASE)) {
- isBase = Boolean.valueOf(groupProperty.getValue());
- break;
- }
- }
-
- if (null == isBase) {
- log.error("Align Vf module properties - isBase not found in DEFAULT_GROUP_VF_MODULE");
- result = false;
- return result;
- }
-
- String vfModuleLabel = null;
- String moduleName = groupDefinition.getName();
- Matcher matcher = pattern.matcher(moduleName);
-
- if (matcher.find()) {
- vfModuleLabel = matcher.group(1);
- } else {
- vfModuleLabel = moduleName;
- }
-
- boolean isBasePrimitive = isBase;
- boolean isVolumeGroupPrimitive = isVolumeGroup;
- String vfModuleLabelFinal = vfModuleLabel;
- List<GroupProperty> propertiesToAdd = new ArrayList<>();
- properties.stream().forEach(p -> {
- if (p.getValueUniqueUid() == null) {
- if (vfModuleProperties.containsKey(p.getName())) {
- if (isBasePrimitive) {
- p.setValue(vfModuleProperties.get(p.getName()).getForBaseModule());
- } else {
- p.setValue(vfModuleProperties.get(p.getName()).getForNonBaseModule());
- }
- } else if (p.getName().equals(VOLUME_GROUP_NAME)) {
- p.setValue(String.valueOf(isVolumeGroupPrimitive));
- } else if (p.getName().equals(LABEL_NAME)) {
- p.setValue(vfModuleLabelFinal);
- }
- propertiesToAdd.add(p);
- }
-
- });
-
- List<GroupProperty> propertiesAlreadyExistOnGraph = properties.stream().filter(p -> !(p.getValueUniqueUid() == null || p.getValueUniqueUid().isEmpty())).collect(Collectors.toList());
- int numOfPropertiesAlreadyExist = propertiesAlreadyExistOnGraph.size();
-
- log.debug("Need to update default values vfModule {} properties {} ", properties.size(), properties);
-
- Either<GroupTypeDefinition, TitanOperationStatus> groupTypeRes = groupTypeOperation.getGroupTypeByUid(groupDefinition.getTypeUid());
- if (groupTypeRes.isRight()) {
- TitanOperationStatus operationStatus = groupTypeRes.right().value();
- log.debug("Failed to find group type {}",groupDefinition.getTypeUid());
- if (operationStatus == TitanOperationStatus.NOT_FOUND) {
- result = false;
- return result;
- }
- }
-
- GroupTypeDefinition groupTypeDefinition = groupTypeRes.left().value();
- List<PropertyDefinition> groupTypeProperties = groupTypeDefinition.getProperties();
- Map<String, PropertyDefinition> groupTypePropertiesMap = groupTypeProperties.stream().collect(Collectors.toMap(p -> p.getName(), p -> p));
-
- int i = numOfPropertiesAlreadyExist + 1;
- for (GroupProperty prop : propertiesToAdd) {
- if (prop.getUniqueId() == null || prop.getUniqueId().isEmpty()) {
- continue;
- }
- GroupData groupData = new GroupData(groupDefinition);
-
- Either<PropertyValueData, TitanOperationStatus> addPropertyToGroup = groupOperation.addPropertyToGroup(groupData, prop, groupTypePropertiesMap.get(prop.getName()), i);
- if (addPropertyToGroup.isRight()) {
- log.info("Failed to add properties {} to group type :{} error {} ", prop.getName(), groupData.getUniqueId(), addPropertyToGroup.right().value());
- result = false;
- return result;
- }
- ++i;
- }
- }
- }
- }
- }
- } catch (Exception e) {
- log.error("Failed {} with exception: ", "alignVfModuleProperties", e);
- result = false;
- } finally {
- log.info(" Align Vf module properties finished");
- if (!result) {
- log.info("Doing rollback");
- titanGenericDao.rollback();
- } else {
- log.info("Doing commit");
- titanGenericDao.commit();
- }
- }
- return true;
- }
-
- private ArtifactDefinition findArtifactInList(Map<String, ArtifactDefinition> deploymentArtifacts, String artifactId) {
- Optional<ArtifactDefinition> op = deploymentArtifacts.values().stream().filter(p -> p.getUniqueId().equals(artifactId)).findAny();
- if (op.isPresent())
- return op.get();
- return null;
- }
-
- private boolean generateTosca() {
- log.info("Regenerate Tosca and CSAR for VFs and Services");
- Either<TitanGraph, TitanOperationStatus> graph = titanGenericDao.getGraph();
- if (graph.isRight()) {
- log.error("Failed to get graph {}", graph.right().value());
- return false;
- }
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name());
-
- User user = buildDummyUser();
-
- Map<String, Object> propsHasNot = new HashMap<String, Object>();
- propsHasNot.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- propsHasNot.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
-
- Either<List<ResourceMetadataData>, TitanOperationStatus> allResources = titanGenericDao.getByCriteria(NodeTypeEnum.Resource, props, propsHasNot, ResourceMetadataData.class);
- if (allResources.isRight()) {
- if (allResources.right().value().equals(TitanOperationStatus.NOT_FOUND)) {
- log.debug("generateTosca - no VF resources");
- } else {
- log.info("generateTosca failed fetch all resources,error {}", allResources.right().value());
- return false;
- }
- } else {
- if (!handleComponents(user, allResources.left().value(), resourceOperation)) {
- log.info("generateTosca failed generate tosca artifacts for resources");
- return false;
-
- }
- }
- Either<List<ServiceMetadataData>, TitanOperationStatus> allServices = titanGenericDao.getByCriteria(NodeTypeEnum.Service, null, propsHasNot, ServiceMetadataData.class);
- if (allServices.isRight()) {
- if (allServices.right().value() == TitanOperationStatus.NOT_FOUND) {
- log.debug("generateTosca - no services");
-
- } else {
- log.debug("generateTosca failed fetch all services,error {}",allServices.right().value());
- return false;
- }
- } else {
- if (!handleComponents(user, allServices.left().value(), serviceOperation)) {
- log.info("generateTosca failed generate tosca artifacts for services");
- return false;
-
- }
- }
- log.info("Regenerate Tosca and CSAR for VFs and Services finished");
- return true;
- }
-
- private <T extends ComponentMetadataData> boolean handleComponents(User user, List<T> allResources, ComponentOperation operation) {
- for (ComponentMetadataData resource : allResources) {
- if (resource.getMetadataDataDefinition().isDeleted() == null || !resource.getMetadataDataDefinition().isDeleted()) {
- Either<Component, StorageOperationStatus> component = operation.getComponent((String) resource.getUniqueId(), true);
- if (component.isRight()) {
- log.info("generateTosca failed fetch component with id {} , error {}", (String) resource.getUniqueId(), component.right().value());
- return false;
- }
- if (populateToscaArtifactsWithLog(component.left().value(), user) != ActionStatus.OK) {
- return false;
- }
- }
- }
- return true;
- }
-
- private boolean alignCustomizationUUID() {
- boolean result = true;
- try {
- log.info("Update customization UUID for all component instances on graph");
- Either<TitanGraph, TitanOperationStatus> graph = titanGenericDao.getGraph();
- if (graph.isRight()) {
- log.error("Failed to get graph {}", graph.right().value());
- return result;
- }
- TitanGraph tGraph = graph.left().value();
- TitanGraphQuery<? extends TitanGraphQuery> query = tGraph.query();
- query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ResourceInstance.getName());
- Iterable<TitanVertex> vertices = query.vertices();
- if (vertices == null) {
- log.info("No component instances on graph");
- return result;
- }
- Iterator<TitanVertex> iterator = vertices.iterator();
- if (!iterator.hasNext()) {
- log.info("No component instances on graph");
- }
- while (iterator.hasNext()) {
- TitanVertex vertex = iterator.next();
- String property = (String) titanGenericDao.getProperty(vertex, GraphPropertiesDictionary.CUSTOMIZATION_UUID.getProperty());
- if (!ValidationUtils.validateStringNotEmpty(property)) {
- UUID uuid = UUID.randomUUID();
- vertex.property(GraphPropertiesDictionary.CUSTOMIZATION_UUID.getProperty(), uuid.toString());
- }
- }
- } catch (Exception e) {
- log.error("Failed {} with exception: ", "alignCustomizationUUID", e);
- result = false;
- } finally {
- log.info("Update customization UUID finished ");
- if (!result) {
- log.info("Doing rollback");
- titanGenericDao.rollback();
- } else {
- log.info("Doing commit");
- titanGenericDao.commit();
- }
- }
- return result;
- }
-
- private ActionStatus populateToscaArtifactsWithLog(Component component, User user) {
- ActionStatus ret = ActionStatus.OK;
- LifecycleStateEnum lifecycleState = component.getLifecycleState();
- if (!needRegenarateTosca(lifecycleState)) {
- log.debug("Component {} is in state {}, don't generatate Tosca", component.getUniqueId(), lifecycleState);
- return ret;
- }
-
- try {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> populateToscaArtifacts = serviceBusinessLogic.populateToscaArtifacts(component, user, true, false, true, true);
- if (populateToscaArtifacts.isLeft()) {
- log.debug("Added payload to tosca artifacts of component {} of type:{} with uniqueId:{}", component.getName(), component.getComponentType().getValue(), component.getUniqueId());
- } else {
- log.error("Failed to generate TOSCA artifacts for component {} of type:{} with uniqueId:{}", component.getName(), component.getComponentType().name(), component.getUniqueId());
- return ActionStatus.GENERAL_ERROR;
- }
- return ret;
- } catch (Exception e) {
- log.error("Exception Occured When filling tosca artifact payload for component {} of type:{} with uniqueId:{}", component.getName(), component.getComponentType().name(), component.getUniqueId(), e);
- return ActionStatus.GENERAL_ERROR;
- }
- }
-
- private boolean needRegenarateTosca(LifecycleStateEnum lifecycleState) {
- if (lifecycleState == LifecycleStateEnum.READY_FOR_CERTIFICATION || lifecycleState == LifecycleStateEnum.CERTIFICATION_IN_PROGRESS || lifecycleState == LifecycleStateEnum.CERTIFIED) {
- return true;
- }
- return false;
- }
-
- private User buildDummyUser() {
- User user = new User();
- user.setUserId("migrationTask");
- return user;
- }
-
- private boolean alignGroupDataType() {
- boolean result = true;
- try {
- log.info(" Align group data type properties");
- String categoryMigrationFile = CONFIG_GROUP_TYPES_YML;
- String yamlAsString;
- try {
-
- InputStream inputStream = getClass().getResourceAsStream(categoryMigrationFile);
- if (inputStream == null) {
- log.info("Failed to load input file : {}", categoryMigrationFile);
- result = false;
- return result;
- }
- yamlAsString = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());
-
- } catch (Exception e) {
- log.info("Failed to load group types file exception : ", e);
- result = false;
- return result;
- }
-
- log.debug("received yaml: {}", yamlAsString);
-
- Map<String, Object> toscaJson = (Map<String, Object>) new Yaml().load(yamlAsString);
-
- if (toscaJson == null || toscaJson.isEmpty()) {
- log.info("group types file is empty");
- result = false;
- return result;
- }
-
- Map<String, Object> vfModule = (Map<String, Object>) toscaJson.get("org.openecomp.groups.VfModule");
- if (vfModule == null || vfModule.isEmpty()) {
- log.info("No vfModule in group types file");
- result = false;
- return result;
- }
- Map<String, Object> properties = (Map<String, Object>) vfModule.get("properties");
- if (properties == null || properties.isEmpty()) {
- log.info("No properties for vfModule in group types file");
- result = false;
- return result;
- }
- Either<GroupTypeDefinition, StorageOperationStatus> latestGroupTypeByType = groupTypeOperation.getLatestGroupTypeByType("org.openecomp.groups.VfModule", true);
- if (latestGroupTypeByType.isRight()) {
- log.info("Failed to fetch org.openecomp.groups.VfModule group type, error :{}", latestGroupTypeByType.right().value());
- result = false;
- return result;
- }
- GroupTypeDefinition groupTypeInGraph = latestGroupTypeByType.left().value();
- List<PropertyDefinition> propertiesInGraph = groupTypeInGraph.getProperties();
-
- List<PropertyDefinition> propertiesToAdd = new ArrayList<>();
-
- properties.entrySet().stream().filter(e -> !ifExistOnGraph(e.getKey(), propertiesInGraph)).forEach(fe -> {
- PropertyDefinition property = new PropertyDefinition();
- property.setName(fe.getKey());
- Map<String, Object> definitionInYaml = (Map<String, Object>) fe.getValue();
- property.setType((String) definitionInYaml.get("type"));
- property.setRequired((Boolean) definitionInYaml.get("required"));
- property.setDescription((String) definitionInYaml.get("description"));
- String defaultValue = definitionInYaml.get("default") == null ? null : definitionInYaml.get("default").toString();
- if (defaultValue != null) {
- property.setDefaultValue(defaultValue);
- }
- propertiesToAdd.add(property);
- });
-
- if (!propertiesToAdd.isEmpty()) {
- log.debug("Need to add to vfModule {} properties {} ", propertiesToAdd.size(), propertiesToAdd);
-
- Either<Map<String, PropertyData>, TitanOperationStatus> addPropertiesToCapablityType = propertyOperation.addPropertiesToElementType(groupTypeInGraph.getUniqueId(), NodeTypeEnum.GroupType, propertiesToAdd);
- if (addPropertiesToCapablityType.isRight()) {
- log.info("Failed to add properties to group type :{}", addPropertiesToCapablityType.right().value());
- result = false;
- return result;
- }
- } else {
- log.debug("No properties to add to vfModule");
- }
-
- } catch (Exception e) {
- log.error("Failed {} with exception: ", "alignGroupDataType", e);
- result = false;
- } finally {
- log.info(" Align group data type properties finished");
- if (!result) {
- log.info("Doing rollback");
- titanGenericDao.rollback();
- } else {
- log.info("Doing commit");
- titanGenericDao.commit();
- }
- }
- return result;
- }
-
- private boolean ifExistOnGraph(String name, List<PropertyDefinition> propertiesInGraph) {
- for (PropertyDefinition pd : propertiesInGraph) {
- if (pd.getName().equals(name)) {
- return true;
- }
- }
- return false;
- }
-
- public boolean alignDataType() {
-
- log.info(" Align data type properties");
-
- boolean isSuccessful = true;
- List<DataTypeDefinition> dataTypes = extractDataTypesFromYaml();
-
- if (CollectionUtils.isEmpty(dataTypes)) {
- isSuccessful = false;
- }
-
- List<ImmutablePair<DataTypeDefinition, Boolean>> createdElementTypes = new ArrayList<>();
-
- Iterator<DataTypeDefinition> elementTypeItr = dataTypes.iterator();
- if (isSuccessful) {
- try {
- while (elementTypeItr.hasNext()) {
- DataTypeDefinition elementType = elementTypeItr.next();
- String elementName = elementType.getName();
- Either<ActionStatus, ResponseFormat> validateElementType = validateDataType(elementType);
- if (validateElementType.isRight()) {
- log.debug("Failed to validate data type {}. Status is {}. ", elementName, validateElementType.right().value());
- isSuccessful = false;
- break;
- }
- log.debug("Going to get data type by name {}. ", elementName);
- Either<DataTypeDefinition, StorageOperationStatus> findElementType = propertyOperation.getDataTypeByNameWithoutDerived(elementName);
- if (findElementType.isRight()) {
- StorageOperationStatus status = findElementType.right().value();
- if (status != StorageOperationStatus.NOT_FOUND) {
- log.debug("Failed to fetch data type {}. Status is {}. ", elementName, validateElementType.right().value());
- isSuccessful = false;
- break;
- } else {
- log.debug("Going to add data type with name {}. ", elementName);
- Either<DataTypeDefinition, StorageOperationStatus> dataModelResponse = propertyOperation.addDataType(elementType);
-
- if (dataModelResponse.isRight()) {
- if (dataModelResponse.right().value() != StorageOperationStatus.SCHEMA_VIOLATION) {
- log.debug("Failed to add data type {}. Status is {}. ", elementName, dataModelResponse.right().value());
- isSuccessful = false;
- break;
- } else {
- createdElementTypes.add(new ImmutablePair<DataTypeDefinition, Boolean>(elementType, false));
- }
- } else {
- createdElementTypes.add(new ImmutablePair<DataTypeDefinition, Boolean>(dataModelResponse.left().value(), true));
- }
-
- }
- } else {
- DataTypeDefinition dataTypeDefinition = findElementType.left().value();
- log.debug("Going to update data type with name {}. ", elementName);
- Either<Map<String, PropertyDefinition>, StorageOperationStatus> deleteDataTypeRes = propertyOperation.deleteAllPropertiesAssociatedToNode(NodeTypeEnum.DataType, dataTypeDefinition.getUniqueId());
- if (deleteDataTypeRes.isRight()) {
- StorageOperationStatus status = deleteDataTypeRes.right().value();
- if (status != StorageOperationStatus.OK) {
-
- log.debug("Failed to update data type {}. Status is {}. ", elementName, deleteDataTypeRes.right().value());
- isSuccessful = false;
- break;
- }
- }
-
- Either<Map<String, PropertyData>, TitanOperationStatus> updateDataTypeRes = propertyOperation.addPropertiesToElementType(dataTypeDefinition.getUniqueId(), NodeTypeEnum.DataType, elementType.getProperties());
-
- if (updateDataTypeRes.isRight()) {
- TitanOperationStatus status = updateDataTypeRes.right().value();
-
- log.debug("Failed to update data type {}. Status is {}. ", elementName, updateDataTypeRes.right().value());
- isSuccessful = false;
- break;
-
- } else {
- createdElementTypes.add(new ImmutablePair<DataTypeDefinition, Boolean>(elementType, true));
- }
-
- DataTypeData dataTypeData = new DataTypeData();
- dataTypeData.setDataTypeDataDefinition(elementType);
- dataTypeData.getDataTypeDataDefinition().setUniqueId(dataTypeDefinition.getUniqueId());
- long modificationTime = System.currentTimeMillis();
- dataTypeData.getDataTypeDataDefinition().setModificationTime(modificationTime);
-
- Either<DataTypeData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(dataTypeData, DataTypeData.class);
- if (updateNode.isRight()) {
- TitanOperationStatus operationStatus = updateNode.right().value();
- log.debug("Failed to update modification time data type {} from graph. status is {}",
- dataTypeDefinition.getUniqueId() ,operationStatus);
- BeEcompErrorManager.getInstance().logInternalFlowError("AddPropertyToDataType", "Failed to fetch data type. Status is " + operationStatus, ErrorSeverity.ERROR);
- isSuccessful = false;
- break;
- } else {
- log.debug("Update data type uid {}. Set modification time to {}", dataTypeDefinition.getUniqueId(), modificationTime);
- isSuccessful = true;
- }
- }
- }
- } finally {
- log.info(" Finish to align data type properties");
- if (isSuccessful) {
- propertyOperation.getTitanGenericDao().commit();
- } else {
- propertyOperation.getTitanGenericDao().rollback();
- }
- }
- }
- return isSuccessful;
- }
-
- @SuppressWarnings("unchecked")
- private List<DataTypeDefinition> extractDataTypesFromYaml() {
- String dataTypeYmlFilePath = CONFIG_DATA_TYPES_YML;
- String yamlAsString;
- try {
-
- InputStream inputStream = getClass().getResourceAsStream(dataTypeYmlFilePath);
- if (inputStream == null) {
- log.info("Failed to load input file : {}", dataTypeYmlFilePath);
- return null;
- }
- yamlAsString = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());
-
- } catch (Exception e) {
- log.info("Failed to load group types file exception : ", e);
- return null;
- }
-
- log.debug("received yaml: {}", yamlAsString);
-
- String dataTypeName;
- List<DataTypeDefinition> dataTypes = new ArrayList<>();
-
- Map<String, Object> toscaJson = (Map<String, Object>) new Yaml().load(yamlAsString);
- Iterator<Entry<String, Object>> elementTypesEntryItr = toscaJson.entrySet().iterator();
- while (elementTypesEntryItr.hasNext()) {
- Entry<String, Object> elementTypeNameDataEntry = elementTypesEntryItr.next();
- dataTypeName = elementTypeNameDataEntry.getKey();
- Map<String, Object> elementTypeJsonData = (Map<String, Object>) elementTypeNameDataEntry.getValue();
-
- DataTypeDefinition dataType = new DataTypeDefinition();
- dataType.setName(dataTypeName);
-
- if (elementTypeJsonData != null) {
-
- if (elementTypeJsonData.containsKey(ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
- dataType.setDescription((String) elementTypeJsonData.get(ToscaTagNamesEnum.DESCRIPTION.getElementName()));
- }
- if (elementTypeJsonData.containsKey(ToscaTagNamesEnum.DERIVED_FROM.getElementName())) {
- dataType.setDerivedFromName((String) elementTypeJsonData.get(ToscaTagNamesEnum.DERIVED_FROM.getElementName()));
- }
- List<PropertyDefinition> properties = getProperties(elementTypeJsonData);
- if (elementTypeJsonData.containsKey(ToscaTagNamesEnum.PROPERTIES.getElementName())) {
- dataType.setProperties(properties);
- }
- }
- dataTypes.add(dataType);
- }
-
- return dataTypes;
- }
-
- private List<PropertyDefinition> getProperties(Map<String, Object> toscaJson) {
- List<PropertyDefinition> values = null;
- Either<Map<String, PropertyDefinition>, ResultStatusEnum> properties = ImportUtils.getProperties(toscaJson);
-
- if (properties.isLeft()) {
- values = new ArrayList<>();
- Map<String, PropertyDefinition> propertiesMap = properties.left().value();
- if (propertiesMap != null && propertiesMap.isEmpty() == false) {
-
- for (Entry<String, PropertyDefinition> entry : propertiesMap.entrySet()) {
- String propName = entry.getKey();
- PropertyDefinition propertyDefinition = entry.getValue();
- PropertyDefinition newPropertyDefinition = new PropertyDefinition(propertyDefinition);
- newPropertyDefinition.setName(propName);
- values.add(newPropertyDefinition);
- }
- }
- }
-
- return values;
- }
-
- private Either<ActionStatus, ResponseFormat> validateDataType(DataTypeDefinition dataType) {
-
- String dataTypeName = dataType.getName();
- List<PropertyDefinition> properties = dataType.getProperties();
- if (properties == null) {
- // At least one parameter should be defined either in the properties
- // section or at one of the parents
- String derivedDataType = dataType.getDerivedFromName();
- // If there are no properties, then we can create a data type if it
- // is an abstract one or it derives from non abstract data type
- if ((derivedDataType == null || derivedDataType.isEmpty())) {
- if (false == isAbstract(dataType.getName())) {
- if (false == ToscaPropertyType.isScalarType(dataTypeName)) {
- log.debug("Data type {} must have properties unless it derives from non abstract data type",dataType.getName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM, dataType, null);
-
- return Either.right(responseFormat);
- }
- }
- } else {
- // if it is not a scalar data type and it derives from abstract
- // data type, we should reject the request.
- if (false == ToscaPropertyType.isScalarType(dataTypeName) && true == isAbstract(derivedDataType)) {
- log.debug("Data type {} which derived from abstract data type must have at least one property",dataType.getName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM, dataType, null);
-
- return Either.right(responseFormat);
- }
- }
- } else {
- // properties tag cannot be empty
- if (properties.isEmpty()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY, dataType, null);
-
- return Either.right(responseFormat);
- }
-
- // check no duplicates
- Set<String> collect = properties.stream().map(p -> p.getName()).collect(Collectors.toSet());
- if (collect != null) {
- if (properties.size() != collect.size()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_DUPLICATE_PROPERTY, dataType, null);
-
- return Either.right(responseFormat);
- }
- }
-
- List<String> propertiesWithSameTypeAsDataType = properties.stream().filter(p -> p.getType().equals(dataType.getName())).map(p -> p.getName()).collect(Collectors.toList());
- if (propertiesWithSameTypeAsDataType != null && propertiesWithSameTypeAsDataType.isEmpty() == false) {
- log.debug("The data type contains properties with the type {}",dataType.getName(),dataType.getName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE, dataType, propertiesWithSameTypeAsDataType);
-
- return Either.right(responseFormat);
- }
- }
-
- String derivedDataType = dataType.getDerivedFromName();
- if (derivedDataType != null) {
- Either<DataTypeDefinition, StorageOperationStatus> derivedDataTypeByName = propertyOperation.getDataTypeByName(derivedDataType, true);
- if (derivedDataTypeByName.isRight()) {
- StorageOperationStatus status = derivedDataTypeByName.right().value();
- if (status == StorageOperationStatus.NOT_FOUND) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_DERIVED_IS_MISSING, dataType, null);
-
- return Either.right(responseFormat);
- } else {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.GENERAL_ERROR, dataType, null);
-
- return Either.right(responseFormat);
-
- }
- } else {
-
- DataTypeDefinition derivedDataTypeDef = derivedDataTypeByName.left().value();
- if (properties != null && properties.isEmpty() == false) {
-
- if (true == isScalarType(derivedDataTypeDef)) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_CANNOT_HAVE_PROPERTIES, dataType, null);
-
- return Either.right(responseFormat);
- }
-
- Set<String> allParentsProps = new HashSet<>();
- do {
- List<PropertyDefinition> currentParentsProps = derivedDataTypeDef.getProperties();
- if (currentParentsProps != null) {
- for (PropertyDefinition propertyDefinition : currentParentsProps) {
- allParentsProps.add(propertyDefinition.getName());
- }
- }
- derivedDataTypeDef = derivedDataTypeDef.getDerivedFrom();
- } while (derivedDataTypeDef != null);
-
- // Check that no property is already defined in one of the
- // ancestors
- Set<String> alreadyExistPropsCollection = properties.stream().filter(p -> allParentsProps.contains(p.getName())).map(p -> p.getName()).collect(Collectors.toSet());
- if (alreadyExistPropsCollection != null && alreadyExistPropsCollection.isEmpty() == false) {
- List<String> duplicateProps = new ArrayList<>();
- duplicateProps.addAll(alreadyExistPropsCollection);
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR, dataType, duplicateProps);
-
- return Either.right(responseFormat);
- }
-
- }
- }
- }
- return Either.left(ActionStatus.OK);
- }
-
- private boolean isAbstract(String dataTypeName) {
-
- ToscaPropertyType isPrimitiveToscaType = ToscaPropertyType.isValidType(dataTypeName);
-
- return isPrimitiveToscaType != null && isPrimitiveToscaType.isAbstract() == true;
-
- }
-
- private boolean isScalarType(DataTypeDefinition dataTypeDef) {
-
- boolean isScalar = false;
- DataTypeDefinition dataType = dataTypeDef;
-
- while (dataType != null) {
-
- String name = dataType.getName();
- if (ToscaPropertyType.isScalarType(name)) {
- isScalar = true;
- break;
- }
-
- dataType = dataType.getDerivedFrom();
- }
-
- return isScalar;
- }
-
-}
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
deleted file mode 100644
index 744965ff68..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/DistributionStatusUpdate.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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
deleted file mode 100644
index 1012ebddd4..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-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.stereotype.Component;
-
-import java.util.List;
-import java.util.Optional;
-
-@Component("migration1707")
-public class Migration1707 {
-
- private static Logger LOGGER = LoggerFactory.getLogger(Migration1707.class);
-
- private List<Migration1707Task> migrations;
-
- public Migration1707(List<Migration1707Task> migrations) {
- this.migrations = migrations;
- }
-
- public boolean migrate() {
- 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) {
- LOGGER.error(String.format("Migration of class %s has failed.", migration.getClass()));
- return false;
- }
- LOGGER.info(String.format("Completed migration. %s", migration.description()));
- }
- return true;
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java
deleted file mode 100644
index b3f138241e..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707ArtifactUuidFix.java
+++ /dev/null
@@ -1,585 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-import java.io.BufferedWriter;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-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.GroupDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentParametersView;
-import org.openecomp.sdc.be.model.DistributionStatusEnum;
-import org.openecomp.sdc.be.model.GroupDefinition;
-import org.openecomp.sdc.be.model.GroupInstance;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.openecomp.sdc.common.api.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import fj.data.Either;
-
-@org.springframework.stereotype.Component("migration1707UuidFix")
-public class Migration1707ArtifactUuidFix {
-
- @Autowired
- private TitanDao titanDao;
-
- @Autowired
- private ToscaOperationFacade toscaOperationFacade;
-
- private static Logger log = LoggerFactory.getLogger(Migration1707ArtifactUuidFix.class.getName());
-
- public boolean migrate(String fixComponent, String runMode) {
- List<Resource> vfLst = new ArrayList<>();
- List<Service> serviceList = new ArrayList<>();
-
- long time = System.currentTimeMillis();
-
- if (fixComponent.equals("vf_only")) {
- if (fetchFaultVf(fixComponent, vfLst, time) == false) {
- return false;
- }
- } else {
- if (fetchServices(fixComponent, serviceList, time) == false) {
- return false;
- }
- }
- if (runMode.equals("service_vf") || runMode.equals("fix")) {
- log.info("Mode {}. Find problem VFs", runMode);
- if (fetchVf(serviceList, vfLst, time) == false) {
- log.info("Mode {}. Find problem VFs finished with failure", runMode);
- return false;
- }
- log.info("Mode {}. Find problem VFs finished with success", runMode);
- }
- if (runMode.equals("fix") || runMode.equals("fix_only_services")) {
- log.info("Mode {}. Start fix", runMode);
- if (fix(vfLst, serviceList) == false) {
- log.info("Mode {}. Fix finished with failure", runMode);
- return false;
- }
- log.info("Mode {}. Fix finished with success", runMode);
- }
-
- return true;
- }
-
- private boolean fetchFaultVf(String fixComponent, List<Resource> vfLst, long time) {
- log.info("Find fault VF ");
- Writer writer = null;
- try {
- String fileName = "fault_" + time + ".csv";
- writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
- writer.write("vf name, vf id, state, version\n");
-
- Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
- hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
- hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF.name());
-
- Map<GraphPropertyEnum, Object> hasNotProps = new HashMap<>();
- hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
- log.info("Try to fetch resources with properties {} and not {}", hasProps, hasNotProps);
-
- Either<List<GraphVertex>, TitanOperationStatus> servicesByCriteria = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, hasNotProps, JsonParseFlagEnum.ParseAll);
- if (servicesByCriteria.isRight()) {
- log.info("Failed to fetch resources {}", servicesByCriteria.right().value());
- return false;
- }
- List<GraphVertex> resources = servicesByCriteria.left().value();
- for (GraphVertex gv : resources) {
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreComponentInstances(false);
- filter.setIgnoreArtifacts(false);
- filter.setIgnoreGroups(false);
-
- Either<Resource, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(gv.getUniqueId());
- if (toscaElement.isRight()) {
- log.info("Failed to fetch resources {} {}", gv.getUniqueId(), toscaElement.right().value());
- return false;
- }
-
- Resource resource = toscaElement.left().value();
- String resourceName = resource.getName();
- Map<String, ArtifactDefinition> deploymentArtifacts = resource.getDeploymentArtifacts();
- List<GroupDefinition> groups = resource.getGroups();
- if (groups == null || groups.isEmpty()) {
- log.info("No groups for resource {} id {} ", resourceName, gv.getUniqueId());
- continue;
- }
- boolean isProblematic = false;
- for (GroupDefinition gr : groups) {
- if (gr.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
- if (isProblematicGroup(gr, resourceName, deploymentArtifacts)) {
- isProblematic = true;
- break;
- }
- }
- }
- if (isProblematic) {
- vfLst.add(resource);
- writeModuleResultToFile(writer, resource, null);
- writer.flush();
- }
- titanDao.commit();
- }
-
- } catch (Exception e) {
- log.info("Failed to fetch vf resources ", e);
- return false;
- } finally {
- titanDao.commit();
- try {
- writer.flush();
- writer.close();
- } catch (Exception ex) {
- /* ignore */}
- }
- return true;
- }
-
- private boolean fetchVf(List<Service> serviceList, List<Resource> vfLst, long time) {
- log.info("Find problem VF ");
- if (serviceList.isEmpty()) {
- log.info("No services as input");
- return true;
- }
- Writer writer = null;
- try {
- String fileName = "problemVf_" + time + ".csv";
- writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
- writer.write("vf name, vf id, state, version, example service name\n");
- Set<String> vfIds = new HashSet<>();
- for (Service service : serviceList) {
- List<ComponentInstance> componentInstances = service.getComponentInstances();
- for (ComponentInstance ci : componentInstances) {
- if (!vfIds.contains(ci.getComponentUid())) {
- vfIds.add(ci.getComponentUid());
- Either<Resource, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(ci.getComponentUid());
- if (toscaElement.isRight()) {
- log.info("Failed to fetch resource {} {}", ci.getComponentUid(), toscaElement.right().value());
- return false;
- }
- Resource resource = toscaElement.left().value();
- vfLst.add(resource);
- writeModuleResultToFile(writer, resource, service);
- writer.flush();
- titanDao.commit();
- }
- }
- }
- log.info("output file with list of Vf : {}", fileName);
- } catch (Exception e) {
- log.info("Failed to fetch services ", e);
- return false;
- } finally {
- titanDao.commit();
- try {
- writer.flush();
- writer.close();
- } catch (Exception ex) {
- /* ignore */}
- }
- return true;
- }
-
- private boolean fetchServices(String fixServices, List<Service> serviceList, long time) {
- log.info("Find problem Services {}", fixServices);
- Writer writer = null;
-
- try {
- String fileName = "problemService_" + time + ".csv";
- writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
- writer.write("service name, service id, state, version\n");
-
- Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
- hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
- if (fixServices.equals("distributed_only")) {
- hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- hasProps.put(GraphPropertyEnum.DISTRIBUTION_STATUS, DistributionStatusEnum.DISTRIBUTED.name());
- }
-
- Map<GraphPropertyEnum, Object> hasNotProps = new HashMap<>();
- hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
- log.info("Try to fetch services with properties {} and not {}", hasProps, hasNotProps);
-
- Either<List<GraphVertex>, TitanOperationStatus> servicesByCriteria = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, hasNotProps, JsonParseFlagEnum.ParseAll);
- if (servicesByCriteria.isRight()) {
- log.info("Failed to fetch services {}", servicesByCriteria.right().value());
- return false;
- }
- List<GraphVertex> services = servicesByCriteria.left().value();
- for (GraphVertex gv : services) {
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreComponentInstances(false);
- filter.setIgnoreArtifacts(false);
- filter.setIgnoreGroups(false);
-
- Either<Service, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(gv.getUniqueId());
- if (toscaElement.isRight()) {
- log.info("Failed to fetch service {} {}", gv.getUniqueId(), toscaElement.right().value());
- return false;
- }
- Service service = toscaElement.left().value();
- List<ComponentInstance> componentInstances = service.getComponentInstances();
- boolean isProblematic = false;
- if (componentInstances == null) {
- log.info("No instances for service {} ", gv.getUniqueId());
- continue;
- }
- String serviceName = (String) gv.getMetadataProperty(GraphPropertyEnum.NAME);
-
- for (ComponentInstance ci : componentInstances) {
- Map<String, ArtifactDefinition> deploymentArtifacts = ci.getDeploymentArtifacts();
- List<GroupInstance> groupInstances = ci.getGroupInstances();
- if (groupInstances == null || groupInstances.isEmpty()) {
- log.info("No instance groups for instance {} in service {} id {} ", ci.getName(), serviceName, gv.getUniqueId());
- continue;
- }
-
- for (GroupInstance gi : groupInstances) {
- if (gi.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
- if (isProblematicGroupInstance(gi, ci.getName(), serviceName, deploymentArtifacts)) {
- isProblematic = true;
- break;
- }
- }
- }
- if (isProblematic) {
- serviceList.add(service);
- writeModuleResultToFile(writer, service, null);
- writer.flush();
- break;
- }
- }
- titanDao.commit();
- }
- log.info("output file with list of services : {}", fileName);
- } catch (Exception e) {
- log.info("Failed to fetch services ", e);
- return false;
- } finally {
- titanDao.commit();
- try {
- writer.flush();
- writer.close();
- } catch (Exception ex) {
- /* ignore */}
- }
- return true;
- }
-
- private boolean isProblematicGroup(GroupDefinition gr, String resourceName, Map<String, ArtifactDefinition> deploymentArtifacts) {
- List<String> artifacts = gr.getArtifacts();
- List<String> artifactsUuid = gr.getArtifactsUuid();
-
- if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) {
- log.info("No groups in resource {} ", resourceName);
- return false;
- }
- if (artifacts.size() < artifactsUuid.size()) {
- log.info(" artifacts.size() < artifactsUuid.size() group {} in resource {} ", gr.getName(), resourceName);
- return true;
- }
- if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) {
- log.info(" artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() group {} in resource {} ", gr.getName(), resourceName);
- return true;
- }
- if (artifactsUuid.contains(null)) {
- log.info(" artifactsUuid.contains(null) group {} in resource {} ", gr.getName(), resourceName);
- return true;
- }
-
- for (String artifactId : artifacts) {
- String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
- ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactlabel);
- if (artifactDefinition == null) {
- log.info(" artifactDefinition == null label {} group {} in resource {} ", artifactlabel, gr.getName(), resourceName);
- return true;
- }
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactDefinition.getArtifactType());
- if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
- if (!artifactId.equals(artifactDefinition.getUniqueId())) {
- log.info(" !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} group {} in resource {} ", artifactlabel, artifactId, gr.getName(), resourceName);
- return true;
- }
- if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
- log.info(" artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} group {} in resource {} ", artifactlabel, gr.getName(), resourceName);
- return true;
- }
- }
- }
- return false;
- }
-
- private boolean isProblematicGroupInstance(GroupInstance gi, String instName, String servicename, Map<String, ArtifactDefinition> deploymentArtifacts) {
- List<String> artifacts = gi.getArtifacts();
- List<String> artifactsUuid = gi.getArtifactsUuid();
- List<String> instArtifactsUuid = gi.getGroupInstanceArtifactsUuid();
-
- if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) {
- log.info("No instance groups for instance {} in service {} ", instName, servicename);
- return false;
- }
- if (artifacts.size() < artifactsUuid.size()) {
- log.info(" artifacts.size() < artifactsUuid.size() inst {} in service {} ", instName, servicename);
- return true;
- }
- if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) {
- log.info(" artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() inst {} in service {} ", instName, servicename);
- return true;
- }
- if (artifactsUuid.contains(null)) {
- log.info(" artifactsUuid.contains(null) inst {} in service {} ", instName, servicename);
- return true;
- }
-
- for (String artifactId : artifacts) {
- String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
- ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactlabel);
- if (artifactDefinition == null) {
- log.info(" artifactDefinition == null label {} inst {} in service {} ", artifactlabel, instName, servicename);
- return true;
- }
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactDefinition.getArtifactType());
- if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
- if (!artifactId.equals(artifactDefinition.getUniqueId())) {
- log.info(" !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} inst {} in service {} ", artifactlabel, artifactId, instName, servicename);
- return true;
- }
- if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
- log.info(" artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ", artifactlabel, instName, servicename);
- return true;
- }
- } else {
- if (!instArtifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
- log.info(" instArtifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ", artifactlabel, instName, servicename);
- return true;
- }
- }
- }
- return false;
- }
-
- private boolean fix(List<Resource> vfLst, List<Service> serviceList) {
- boolean res = true;
-
- if (vfLst != null && !vfLst.isEmpty()) {
- res = fixVf(vfLst);
- if (res) {
- for (Component component : vfLst) {
- TopologyTemplate topologyTemplate = ModelConverter.convertToToscaElement(component);
- Map<String, GroupDataDefinition> groups = topologyTemplate.getGroups();
- res = fixDataOnGraph(component.getUniqueId(), VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
- }
- }
- }
-
- if (res == true && serviceList != null && !serviceList.isEmpty()) {
- res = fixServices(serviceList);
- if (res) {
- for (Component component : serviceList) {
- TopologyTemplate topologyTemplate = ModelConverter.convertToToscaElement(component);
- Map<String, MapGroupsDataDefinition> groups = topologyTemplate.getInstGroups();
- res = fixDataOnGraph(component.getUniqueId(), VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, groups);
- }
- }
- }
-
- return res;
- }
-
- private <T extends ToscaDataDefinition> boolean fixDataOnGraph(String componentId, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> groups) {
- boolean res = true;
- Either<GraphVertex, TitanOperationStatus> getResponse = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getResponse.isRight()) {
- log.debug("Couldn't fetch component unique id {}, error: {}", componentId, getResponse.right().value());
- res = false;
-
- }
- if (res) {
- GraphVertex componentVertex = getResponse.left().value();
-
- GraphVertex toscaDataVertex = null;
- Either<GraphVertex, TitanOperationStatus> groupVertexEither = titanDao.getChildVertex(componentVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson);
- if (groupVertexEither.isRight()) {
- res = false;
- log.debug("failed to get child {} vertex for component unique id {}, error: {}", edgeLabelEnum, componentId, groupVertexEither.right().value());
- }
- if (res) {
- toscaDataVertex = groupVertexEither.left().value();
- toscaDataVertex.setJson(groups);
- Either<GraphVertex, TitanOperationStatus> updatevertexEither = titanDao.updateVertex(toscaDataVertex);
- if (updatevertexEither.isRight()) {
- log.debug("failed to update vertex for component unique id {}, error: {}", componentId, updatevertexEither.right().value());
- titanDao.rollback();
- return false;
- }
- }
- }
-
- titanDao.commit();
-
- return res;
- }
-
- private boolean fixServices(List<Service> serviceList) {
- for (Service service : serviceList) {
- log.debug("Migration1707ArtifactUuidFix fix service: id {}, name {} ", service.getUniqueId(), service.getName());
- List<ComponentInstance> instances = service.getComponentInstances();
- for (ComponentInstance instance : instances) {
- Map<String, ArtifactDefinition> artifactsMap = instance.getDeploymentArtifacts();
- List<GroupInstance> groupsList = instance.getGroupInstances();
- if (groupsList != null && artifactsMap != null) {
- for (GroupInstance group : groupsList) {
- if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
- log.debug("Migration1707ArtifactUuidFix fix group: resource id {}, group name {} ", service.getUniqueId(), group.getName());
- List<String> groupArtifacts = new ArrayList<String>(group.getArtifacts());
-
- group.getArtifacts().clear();
- group.getArtifactsUuid().clear();
- group.getGroupInstanceArtifacts().clear();
- group.getGroupInstanceArtifactsUuid().clear();
-
- for (String artifactId : groupArtifacts) {
- String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
- log.debug("Migration1707ArtifactUuidFix fix group: group name {} artifactId for fix {} artifactlabel {} ", group.getName(), artifactId, artifactlabel);
- if (!artifactlabel.isEmpty() && artifactsMap.containsKey(artifactlabel)) {
- ArtifactDefinition artifact = artifactsMap.get(artifactlabel);
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
- String correctArtifactId = artifact.getUniqueId();
- String correctArtifactUUID = artifact.getArtifactUUID();
- if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
-
- log.debug("Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID);
- group.getArtifacts().add(correctArtifactId);
- if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
- group.getArtifactsUuid().add(correctArtifactUUID);
- }
- } else {
- log.debug("Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID);
- group.getGroupInstanceArtifacts().add(correctArtifactId);
- if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
- group.getGroupInstanceArtifactsUuid().add(correctArtifactUUID);
- }
- }
- }
- }
- }
- }
- }
- }
-
- }
- return true;
-
- }
-
- private boolean fixVf(List<Resource> vfLst) {
- for (Resource resource : vfLst) {
- log.debug("Migration1707ArtifactUuidFix fix resource: id {}, name {} ", resource.getUniqueId(), resource.getName());
- Map<String, ArtifactDefinition> artifactsMap = resource.getDeploymentArtifacts();
- List<GroupDefinition> groupsList = resource.getGroups();
- if (groupsList != null && artifactsMap != null) {
- for (GroupDefinition group : groupsList) {
- if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) && group.getArtifacts() != null) {
- log.debug("Migration1707ArtifactUuidFix fix group: resource id {}, group name {} ", resource.getUniqueId(), group.getName());
- List<String> groupArtifacts = new ArrayList<String>(group.getArtifacts());
- group.getArtifacts().clear();
- group.getArtifactsUuid().clear();
- for (String artifactId : groupArtifacts) {
- String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
- log.debug("Migration1707ArtifactUuidFix fix group: group name {} artifactId for fix {} artifactlabel {} ", group.getName(), artifactId, artifactlabel);
- if (!artifactlabel.isEmpty() && artifactsMap.containsKey(artifactlabel)) {
- ArtifactDefinition artifact = artifactsMap.get(artifactlabel);
- String correctArtifactId = artifact.getUniqueId();
- String correctArtifactUUID = artifact.getArtifactUUID();
- log.debug("Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID);
- group.getArtifacts().add(correctArtifactId);
- if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
- group.getArtifactsUuid().add(correctArtifactUUID);
- }
-
- }
- }
- }
- }
- }
-
- }
-
- return true;
- }
-
- private String findArtifactLabelFromArtifactId(String artifactId) {
- String artifactLabel = "";
-
- int index = artifactId.lastIndexOf(".");
- if (index > 0 && index + 1 < artifactId.length())
- artifactLabel = artifactId.substring(index + 1);
- return artifactLabel;
- }
-
- private void writeModuleResultToFile(Writer writer, org.openecomp.sdc.be.model.Component component, Service service) {
- try {
- // "service name, service id, state, version
- StringBuffer sb = new StringBuffer(component.getName());
- sb.append(",").append(component.getUniqueId()).append(",").append(component.getLifecycleState()).append(",").append(component.getVersion());
- if (service != null) {
- sb.append(",").append(service.getName());
- }
- sb.append("\n");
- writer.write(sb.toString());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-}
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
deleted file mode 100644
index 36919d7520..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707Config.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-
-import java.util.List;
-
-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;
-import org.openecomp.sdc.be.dao.TitanClientStrategy;
-import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
-import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
-import org.openecomp.sdc.be.model.DerivedNodeTypeResolver;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations;
-import org.openecomp.sdc.be.model.jsontitan.operations.CategoryOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaDataOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.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;
-import org.openecomp.sdc.be.model.operations.impl.ToscaDefinitionPathCalculatorImpl;
-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
-public class Migration1707Config {
-
-
- @Bean(name = "migration1707")
- public Migration1707 migration1707(List<Migration1707Task> migrations) {
- return new Migration1707(migrations);
- }
-
- @Bean(name = "renameGraphPropertyKeysMigration")
- @Order(1)
- public Migration1707Task renameGraphPropertyKeysMigration() {
- return new RenameGraphPropertyKeys();
- }
-
- @Bean(name = "toscaNamesUpdate")
- @Order(2)
- public Migration1707Task toscaNamesUpdate() {
- return new ToscaNamesUpdate();
- }
-
- @Bean(name = "users-migration")
- @Order(3)
- public Migration1707Task usersMigration() {
- return new UsersMigration();
- }
-
- @Bean(name = "resource-category-migration")
- @Order(4)
- public Migration1707Task resourceCategoriesMigration() {
- return new ResourcesCategoriesMigration();
- }
-
- @Bean(name = "service-category-migration")
- @Order(5)
- public Migration1707Task serviceCategoriesMigration() {
- return new ServiceCategoriesMigration();
- }
-
- @Bean(name = "normatives-migration")
- @Order(6)
- public Migration1707Task normativesMigration() {
- return new NormativesMigration();
- }
-
- @Bean(name = "vf-migration")
- @Order(7)
- public Migration1707Task vfMigration() {
- return new VFResourcesMigration();
- }
-
- @Bean(name = "service-migration")
- @Order(8)
- public Migration1707Task serviceMigration() {
- return new ServicesMigration();
- }
-
- @Bean(name = "consumers-migration")
- @Order(9)
- public Migration1707Task consumersMigration() { return new ConsumersMigration(); }
-
- @Bean(name = "tosca-template-regeneration")
- @Order(10)
- public Migration1707Task ToscaTemplateRegeneration() {
- return new ToscaTemplateRegeneration();
- }
-
- @Bean(name = "distributionStatusUpdate")
- public DistributionStatusUpdate distributionStatusUpdate() {
- return new DistributionStatusUpdate();
- }
-
- @Bean("resource-version-migration")
- public VersionMigration<Resource> resourceVersionMigration() {
- return new ResourceVersionMigration();
- }
-
- @Bean("service-version-migration")
- public VersionMigration<Service> serviceVersionMigration() {
- return new ServiceVersionMigration();
- }
-
- @Bean(name = "normatives-resolver")
- public NormativesResolver normativesResolver() {
- return new NormativesResolver();
- }
-
- @Bean(name = "property-operation-mig")
- public PropertyOperation propertyOperation(@Qualifier("titan-generic-dao-migration") TitanGenericDao titanGenericDao) {
- return new PropertyOperation(titanGenericDao);
- }
-
- @Bean(name = "group-type-operation-mig")
- public GroupTypeOperation groupTypeOperation(@Qualifier("titan-generic-dao-migration") TitanGenericDao titanGenericDao, @Qualifier("property-operation-mig") PropertyOperation propertyOperation) {
- return new GroupTypeOperation(titanGenericDao, propertyOperation);
- }
-
- @Bean(name = "titan-generic-dao-migration")
- public TitanGenericDao titanGenericDaoMigration(@Qualifier("migration-titan-client") TitanGraphClient titanGraphClient) {
- return new TitanGenericDao(titanGraphClient);
- }
-
- @Bean(name = "migration-titan-strategy")
- public TitanClientStrategy migrationStrategy() {
- return new MigrationTitanStrategy();
- }
-
- @Bean(name = "migration-titan-client", initMethod = "createGraph")
- public TitanGraphClient titanMigrationClient(@Qualifier("migration-titan-strategy") TitanClientStrategy titanClientStrategy) {
- return new TitanGraphClient(titanClientStrategy);
- }
-
- @Bean(name = "user-operation-migration")
- public IUserAdminOperation userOperationNewKeySpace(@Qualifier("titan-generic-dao-migration") TitanGenericDao titanGenericDao) {
- return new UserAdminOperation(titanGenericDao);
- }
-
- @Bean(name = "element-operation-migration")
- public IElementOperation elementOperationNewKeyspace(@Qualifier("titan-generic-dao-migration") TitanGenericDao titanGenericDao) {
- return new ElementOperation(titanGenericDao);
- }
-
- @Bean(name = "tosca-operation-facade")
- public ToscaOperationFacade toscaOperationFacade() {
- return new ToscaOperationFacade();
- }
-
- @Bean(name = "node-type-operation")
- public NodeTypeOperation nodeTypeOperation(@Qualifier("mig-derived-resolver") DerivedNodeTypeResolver migrationDerivedNodeTypeResolver) {
- return new NodeTypeOperation(migrationDerivedNodeTypeResolver);
- }
-
- @Bean(name = "topology-template-operation")
- public TopologyTemplateOperation topologyTemplateOperation() {
- return new TopologyTemplateOperation();
- }
-
- @Bean(name = "node-template-operation")
- public NodeTemplateOperation nodeTemplateOperation() {
- return new NodeTemplateOperation();
- }
-
- @Bean(name = "titan-dao")
- public TitanDao titanDao(@Qualifier("migration-titan-client") TitanGraphClient titanGraphClient) {
- return new TitanDao(titanGraphClient);
- }
-
- @Bean(name = "category-operation")
- public CategoryOperation categoryOperation() {
- return new CategoryOperation();
- }
-
- @Bean(name = "artifacts-operation")
- public ArtifactsOperations artifactsOperation() {
- return new ArtifactsOperations();
- }
-
- @Bean(name = "tosca-data-operation")
- public ToscaDataOperation toscaDataOperation() {
- return new ToscaDataOperation();
- }
-
- @Bean(name = "tosca-element-lifecycle-operation")
- public ToscaElementLifecycleOperation toscaElementLifecycleOperation() {
- return new ToscaElementLifecycleOperation();
- }
-
- @Bean(name = "tosca-path-calculator")
- public ToscaDefinitionPathCalculator pathCalculator() {
- return new ToscaDefinitionPathCalculatorImpl();
- }
-
- @Bean(name = "fulfilled-capabilities-mig-service")
- public FulfilledCapabilitiesMigrationService fulfilledCapabilitiesMigService() {
- return new FulfilledCapabilitiesMigrationService();
- }
-
- @Bean(name = "fulfilled-requirements-mig-service")
- public FulfilledRequirementsMigrationService requirementsMigService() {
- return new FulfilledRequirementsMigrationService();
- }
-
- @Bean(name ="req-cap-mig-service")
- public RequirementsCapabilitiesMigrationService reqCapMigService() {
- return new RequirementsCapabilitiesMigrationService();
- }
-
- @Bean(name = "mig-derived-resolver")
- public DerivedNodeTypeResolver migrationDerivedNodeTypeResolver() {
- 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();
- }
-
- @Bean(name = "node-template-missing-data-resolver")
- public NodeTemplateMissingDataResolver nodeTemplateMissingDataResolver() {
- return new NodeTemplateMissingDataResolver<>();
- }
-
- @Bean(name = "migration1707MissingInfoFix")
- public Migration1707MissingInfoFix migration1707MissingInfoFix() {
- return new Migration1707MissingInfoFix();
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707MissingInfoFix.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707MissingInfoFix.java
deleted file mode 100644
index ff41f12b8e..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707MissingInfoFix.java
+++ /dev/null
@@ -1,220 +0,0 @@
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-import fj.data.Either;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.NodeTemplateMissingDataResolver;
-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.*;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
-import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
-import org.openecomp.sdc.be.model.*;
-import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
-import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.IServiceOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-@org.springframework.stereotype.Component("migration1707MissingInfoFix")
-public class Migration1707MissingInfoFix {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(Migration1707MissingInfoFix.class);
-
- @Resource(name = "service-operation")
- private IServiceOperation serviceOperation;
-
- @Resource(name = "node-template-missing-data-resolver")
- private NodeTemplateMissingDataResolver nodeTemplateMissingDataResolver;
-
- @Resource(name = "tosca-operation-facade")
- private ToscaOperationFacade toscaOperations;
-
- @Resource(name = "titan-dao")
- private TitanDao titanDao;
-
-
- public boolean migrate(){
- boolean res = updateVFs();
- if(res)
- res = updateServices();
- return res;
- }
-
- private ComponentParametersView getFilter() {
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreComponentInstances(false);
- filter.setIgnoreArtifacts(false);
- filter.setIgnoreGroups(false);
- filter.setIgnoreComponentInstancesInputs(false);
- return filter;
- }
-
- // if new service has VF instances with no groups - try to fetch them from old graph
- private boolean oldServiceModelRequired(Component newService) {
- Predicate<ComponentInstance> vfInstanceWithNoGroups = p -> OriginTypeEnum.VF == p.getOriginType() && (null == p.getGroupInstances() || p.getGroupInstances().isEmpty());
- return null != newService.getComponentInstances() && newService.getComponentInstances().stream()
- .anyMatch(vfInstanceWithNoGroups);
- }
-
-
-
- private List<GraphVertex> fetchVertices(Map<GraphPropertyEnum, Object> hasProps){
- Either<List<GraphVertex>, TitanOperationStatus> componentsByCriteria = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, JsonParseFlagEnum.ParseAll);
- if (componentsByCriteria.isRight()) {
- LOGGER.debug("couldn't fetch assets from sdctitan");
- return null;
- }
- return componentsByCriteria.left().value();
- }
-
- private boolean updateVFs() {
-
- boolean res = true;
- Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
- hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
- hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF.name());
-
- List<GraphVertex> resources = fetchVertices(hasProps);
- if(null == resources)
- return false;
- ComponentParametersView filter = getFilter();
- Map<String, ToscaElement> origCompMap = new HashMap<>();
-
- for (GraphVertex gv : resources) {
- boolean fixed = true;
- Either<Component, StorageOperationStatus> toscaElement = toscaOperations.getToscaElement(gv.getUniqueId(), filter);
- if (toscaElement.isRight()) {
- LOGGER.debug("Failed to fetch resource {} {}", gv.getUniqueId(), toscaElement.right().value());
- return false;
- }
- Component resource = toscaElement.left().value();
- Map<String, Boolean> updateMap = new HashMap<>();
- nodeTemplateMissingDataResolver.updateVFComposition(resource, origCompMap, updateMap);
- if(updateMap.get(JsonConstantKeysEnum.COMPOSITION.name())){
- LOGGER.info("applying instance tosca name fix on VF {}", gv.getUniqueId());
- fixed = toscaOperations.updateComponentInstanceMetadataOfTopologyTemplate(resource).isLeft();
- }
- if(updateMap.get(EdgeLabelEnum.GROUPS.name())) {
- List<GroupDataDefinition> groups = new ArrayList<>(resource.getGroups());
- LOGGER.info("applying groups vertex fix on VF {}", gv.getUniqueId());
- fixed = fixed && toscaOperations.updateGroupsOnComponent(resource, ComponentTypeEnum.RESOURCE, groups).isLeft();
- }
-
- res = res && fixed;
- titanDao.commit();
- }
- return res;
- }
-
- private Map<String, MapPropertiesDataDefinition> buildInstancesInputsMap(Component component){
- Map<String, MapPropertiesDataDefinition> instanceInputsMap = new HashMap<>();
- for (Map.Entry<String, List<ComponentInstanceInput>> entry : component.getComponentInstancesInputs().entrySet()) {
- MapPropertiesDataDefinition inputsMap = new MapPropertiesDataDefinition();
- inputsMap.setMapToscaDataDefinition(entry.getValue().stream().map(e -> new PropertyDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
- instanceInputsMap.put(entry.getKey(), inputsMap);
- }
- return instanceInputsMap;
- }
-
-
-
- private Map<String, MapGroupsDataDefinition> buildGroupInstanceMap(Component component) {
- Map<String, MapGroupsDataDefinition> instGroupsMap = new HashMap<>();
- for (ComponentInstance instance : component.getComponentInstances()) {
- if (instance.getGroupInstances() != null) {
- MapGroupsDataDefinition groupsMap = new MapGroupsDataDefinition();
- groupsMap.setMapToscaDataDefinition(instance.getGroupInstances().stream().map(e -> new GroupInstanceDataDefinition(e)).collect(Collectors.toMap(e -> e.getName(), e -> e)));
- instGroupsMap.put(instance.getUniqueId(), groupsMap);
- }
- }
- return instGroupsMap;
- }
-
- private <T extends ToscaDataDefinition> boolean updateDataVertex(GraphVertex componentVertex, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel, Map<String, T> dataMap){
- Either<GraphVertex, TitanOperationStatus> dataVertexEither = titanDao.getChildVertex(componentVertex, edgeLabel, JsonParseFlagEnum.ParseJson);
- if (dataVertexEither.isRight()) {
- if(TitanOperationStatus.NOT_FOUND != dataVertexEither.right().value())
- return false;
- return (nodeTemplateMissingDataResolver.topologyTemplateOperation.assosiateElementToData(componentVertex, vertexType, edgeLabel, dataMap)).isLeft();
- }
- GraphVertex dataVertex = dataVertexEither.left().value();
- dataVertex.setJson(dataMap);
- return (titanDao.updateVertex(dataVertex)).isLeft();
-
- }
-
-
- private boolean updateServices(){
-
- boolean res = true;
- Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
- hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
-
- List<GraphVertex> componentsByCriteria = fetchVertices(hasProps);
- if(null == componentsByCriteria)
- return false;
-
- ComponentParametersView filter = getFilter();
- Map<String, ToscaElement> origCompMap = new HashMap<>();
-
- Predicate<ComponentInstance> containsGroupInstances = p -> null != p.getGroupInstances() && !p.getGroupInstances().isEmpty();
-
- for (GraphVertex gv : componentsByCriteria) {
-
- boolean fixed = true;
- Either<org.openecomp.sdc.be.model.Service, StorageOperationStatus> toscaElement = toscaOperations.getToscaElement(gv.getUniqueId(), filter);
- if (toscaElement.isRight()) {
- LOGGER.debug("Failed to fetch service {} {}", gv.getUniqueId(), toscaElement.right().value());
- return false;
- }
- Component service = toscaElement.left().value();
- Component oldService = null;
-
- if(oldServiceModelRequired(service)){
- Either<Service, StorageOperationStatus> oldServiceEither = serviceOperation.getService(gv.getUniqueId(), filter, false);
- if (oldServiceEither.isRight()){
- LOGGER.debug("couldn't fetch service {} from old titan", gv.getUniqueId());
- }else {
- oldService = oldServiceEither.left().value();
- oldService = oldService.getComponentInstances().stream().anyMatch(containsGroupInstances) ? oldService : null;
- }
- }
-
- Map<String, Boolean> updateMap = new HashMap<>();
- nodeTemplateMissingDataResolver.updateServiceComposition(service, origCompMap, oldService, updateMap);
- if(updateMap.get(JsonConstantKeysEnum.COMPOSITION.name())) {
- LOGGER.info("applying instance tosca name fix on service {}", gv.getUniqueId());
- fixed = (toscaOperations.updateComponentInstanceMetadataOfTopologyTemplate(service)).isLeft();
- }
- if(updateMap.get(EdgeLabelEnum.INST_GROUPS.name())) {
- Map<String, MapGroupsDataDefinition> groupsMap = buildGroupInstanceMap(service);
- LOGGER.info("applying groups instances vertex fix on service {}", gv.getUniqueId());
- fixed = fixed && updateDataVertex(gv, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, groupsMap);
- }
- if(updateMap.get(EdgeLabelEnum.INST_INPUTS.name())) {
- Map<String, MapPropertiesDataDefinition> instInputs = buildInstancesInputsMap(service);
- LOGGER.info("applying instances inputs vertex fix on service {}", gv.getUniqueId());
- fixed = fixed && updateDataVertex(gv, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
- }
- res = res && fixed;
- titanDao.commit();
- }
- return res;
- }
-}
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
deleted file mode 100644
index 204f0a5fc8..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707RelationsFix.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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
deleted file mode 100644
index 5d7a887a7f..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/Migration1707VnfFix.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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/MigrationTitanStrategy.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/MigrationTitanStrategy.java
deleted file mode 100644
index 0274ca425e..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/MigrationTitanStrategy.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.TitanClientStrategy;
-
-public class MigrationTitanStrategy implements TitanClientStrategy {
-
- @Override
- public String getConfigFile() {
- return ConfigurationManager.getConfigurationManager().getConfiguration().getTitanMigrationKeySpaceCfgFile();
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/MigrationUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/MigrationUtils.java
deleted file mode 100644
index 04f810af5e..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/MigrationUtils.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-import org.apache.commons.lang.enums.Enum;
-import org.openecomp.sdc.asdctool.impl.migration.MigrationException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class MigrationUtils {
-
- private static Logger LOGGER = LoggerFactory.getLogger(MigrationUtils.class);
-
- public static boolean handleError(String errorMsg) {
- LOGGER.error(errorMsg);
- return false;
- }
-
- public static <T> T handleError(T errorStatus, String errorMsg) {
- LOGGER.error(errorMsg);
- return errorStatus;
- }
-
- public static <A> A willThrowException(String withMsg) {
- throw new MigrationException(withMsg);
- }
-
-}
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
deleted file mode 100644
index 9f571167db..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/RenameGraphPropertyKeys.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-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;
-
-import java.util.HashMap;
-import java.util.Map;
-
-@Component("renameGraphPropertyKeysMigration")
-public class RenameGraphPropertyKeys implements Migration1707Task {
-
- private final static Map<String, String> KEY_PROPERTIES_TO_RENAME;
-
- @Autowired
- private MigrationOperationUtils migrationUtils;
-
- static {
- KEY_PROPERTIES_TO_RENAME = new HashMap<>();
- KEY_PROPERTIES_TO_RENAME.put("attuid", GraphPropertiesDictionary.USERID.getProperty());
- KEY_PROPERTIES_TO_RENAME.put("pmatt", GraphPropertiesDictionary.PROJECT_CODE.getProperty());
- KEY_PROPERTIES_TO_RENAME.put("attContact", GraphPropertiesDictionary.CONTACT_ID.getProperty());
- KEY_PROPERTIES_TO_RENAME.put("attCreator", GraphPropertiesDictionary.CREATOR_ID.getProperty());
- }
-
- @Override
- public boolean migrate() {
- return migrationUtils.renamePropertyKeys(KEY_PROPERTIES_TO_RENAME);
- }
-
- @Override
- public String description() {
- return MigrationMsg.RENMAE_KEY_PROPERTIES_1707.getMessage();
- }
-}
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
deleted file mode 100644
index 665fe15315..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaNamesUpdate.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-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.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;
-import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.resources.data.AttributeData;
-import org.openecomp.sdc.be.resources.data.AttributeValueData;
-import org.openecomp.sdc.be.resources.data.CapabilityData;
-import org.openecomp.sdc.be.resources.data.CapabilityTypeData;
-import org.openecomp.sdc.be.resources.data.DataTypeData;
-import org.openecomp.sdc.be.resources.data.GroupData;
-import org.openecomp.sdc.be.resources.data.GroupTypeData;
-import org.openecomp.sdc.be.resources.data.InputValueData;
-import org.openecomp.sdc.be.resources.data.InputsData;
-import org.openecomp.sdc.be.resources.data.PolicyTypeData;
-import org.openecomp.sdc.be.resources.data.PropertyData;
-import org.openecomp.sdc.be.resources.data.PropertyValueData;
-import org.openecomp.sdc.be.resources.data.RelationshipInstData;
-import org.openecomp.sdc.be.resources.data.RelationshipTypeData;
-import org.openecomp.sdc.be.resources.data.RequirementData;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-
-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("toscaNamesUpdate")
-public class ToscaNamesUpdate implements Migration1707Task {
- private static Logger log = LoggerFactory.getLogger(ToscaNamesUpdate.class.getName());
-
- @Override
- public String description() {
- return "toscaNamesUpdate";
- }
-
- @Autowired
- protected TitanGenericDao titanGenericDao;
-
- @Override
- public boolean migrate() {
- boolean result = true;
- List<ImmutableTriple<NodeTypeEnum, Class<GraphNode>, Function<GraphNode, ImmutablePair<String, GraphNode>>>> updateInfoList = new ArrayList<>();
- for (NodeTypeEnum nodeType : NodeTypeEnum.values()){
- ImmutableTriple<NodeTypeEnum, Class<GraphNode>, Function<GraphNode, ImmutablePair<String, GraphNode>>> updateInfo = getInfo(nodeType);
- if(null == updateInfo)
- continue;
- updateInfoList.add(updateInfo);
- }
-
- for(ImmutableTriple<NodeTypeEnum, Class<GraphNode>, Function<GraphNode, ImmutablePair<String, GraphNode>>> nodeTypeData : updateInfoList){
- log.debug("before updating namespace on nodeType {}", nodeTypeData.left.getName());
- result = updateNamespaceByNodeType(nodeTypeData);
- if(!result){
- log.debug("alignNamespace procedure failed during execution of updating namespace on nodeType {}", nodeTypeData.left.getName());
- return false;
- }
- }
- return true;
- }
-
- private <T extends GraphNode> ImmutableTriple<NodeTypeEnum, Class<T>, Function<T, ImmutablePair<String, T>>> getInfo(NodeTypeEnum nodeType) {
- switch (nodeType) {
- case Resource:
- Function<ResourceMetadataData, ImmutablePair<String, ResourceMetadataData>> resourceFunc = r -> updateResource(r);
- return new ImmutableTriple(nodeType, ResourceMetadataData.class, resourceFunc);
- case GroupType:
- Function<GroupTypeData, ImmutablePair<String, GroupTypeData>> groupTypeFunc = g -> updateGroupType(g);
- return new ImmutableTriple(nodeType, GroupTypeData.class, groupTypeFunc);
- case Group:
- Function<GroupData, ImmutablePair<String, GroupData>> groupFunc = g -> updateGroupNode(g);
- return new ImmutableTriple(nodeType, GroupData.class, groupFunc);
- case PolicyType:
- Function<PolicyTypeData, ImmutablePair<String , PolicyTypeData>> policyFunc = p -> updatePolicyType(p);
- return new ImmutableTriple(nodeType, PolicyTypeData.class, policyFunc);
- case RelationshipType:
- Function<RelationshipTypeData, ImmutablePair<String, RelationshipTypeData>> relTypeFunc = r -> updateRelationshipType(r);
- return new ImmutableTriple(nodeType, RelationshipTypeData.class, relTypeFunc);
- case RelationshipInst:
- Function<RelationshipInstData, ImmutablePair<String, RelationshipInstData>> relFunc = r -> updateRelationshipNode(r);
- return new ImmutableTriple(nodeType, RelationshipInstData.class, relFunc);
- case Requirement:
- Function<RequirementData, ImmutablePair<String, RequirementData>> reqFunc = r -> updateRequirementType(r);
- return new ImmutableTriple(nodeType, RequirementData.class, reqFunc);
- case CapabilityType:
- Function<CapabilityTypeData, ImmutablePair<String, CapabilityTypeData>> capTypeFunc = c -> updateCapabilityType(c);
- return new ImmutableTriple(nodeType, CapabilityTypeData.class, capTypeFunc);
- case Capability:
- Function<CapabilityData, ImmutablePair<String, CapabilityData>> capFunc = c -> updateCapabilityNode(c);
- return new ImmutableTriple(nodeType, CapabilityData.class, capFunc);
- case Property:
- Function<PropertyData, ImmutablePair<String, PropertyData>> propFunc = p -> updatePropNode(p);
- return new ImmutableTriple(nodeType, PropertyData.class, propFunc);
- case PropertyValue:
- Function<PropertyValueData, ImmutablePair<String, PropertyValueData>> propValueFunc = p -> updatePropValueNode(p);
- return new ImmutableTriple(nodeType, PropertyValueData.class, propValueFunc);
- case Attribute:
- Function<AttributeData, ImmutablePair<String, AttributeData>> attrFunc = a -> updateAttributeNode(a);
- return new ImmutableTriple(nodeType, AttributeData.class, attrFunc);
- case AttributeValue:
- Function<AttributeValueData, ImmutablePair<String, AttributeValueData>> attrValueFunc = a -> updateAttrValueNode(a);
- return new ImmutableTriple(nodeType, AttributeValueData.class, attrValueFunc);
- case Input:
- Function<InputsData, ImmutablePair<String, InputsData>> inputFunc = i -> updateInputNode(i);
- return new ImmutableTriple(nodeType, InputsData.class, inputFunc);
- case InputValue:
- Function<InputValueData, ImmutablePair<String, InputValueData>> inputValueFunc = i -> updateInputValueNode(i);
- return new ImmutableTriple(nodeType, InputValueData.class, inputValueFunc);
- case DataType:
- Function<DataTypeData, ImmutablePair<String, DataTypeData>> dataTypeFunc = d -> updateDataType(d);
- return new ImmutableTriple(nodeType, DataTypeData.class, dataTypeFunc);
- default:
- return null;
- }
-
- }
-
-
-
- private boolean ifRight(TitanOperationStatus status){
- return TitanOperationStatus.NOT_FOUND == status;
- }
-
- private <T extends GraphNode> boolean ifLeft(List<T> allNodes, ImmutableTriple<NodeTypeEnum, Class<T>, Function<T, ImmutablePair<String, T>>> nodeTypeData){
- boolean result = true;
- try {
- for (T node : allNodes) {
- ImmutablePair<String, T> nodeToUpdate = nodeTypeData.right.apply(node);
- Either<T, TitanOperationStatus> updatedNode = updateNodeIncludingUID(nodeToUpdate.left, nodeToUpdate.right, nodeTypeData.middle);
- if (updatedNode.isRight()) {
- result = false;
- break;
- }
- }
- } finally {
- if (!result) {
- titanGenericDao.rollback();
- } else {
- titanGenericDao.commit();
- }
- }
- return result;
- }
-
- private <T extends GraphNode> boolean updateNamespaceByNodeType(ImmutableTriple<NodeTypeEnum, Class<T>, Function<T, ImmutablePair<String, T>>> nodeTypeData) {
- Either<List<T>, TitanOperationStatus> getAllNodes = titanGenericDao.getByCriteria(nodeTypeData.left, null, nodeTypeData.middle);
- return getAllNodes.either(list -> ifLeft(list, nodeTypeData), status -> ifRight(status));
- }
-
- private ImmutablePair<String, ResourceMetadataData> updateResource(ResourceMetadataData resource) {
- String toscaResourceName = updateNamespace(((ResourceMetadataDataDefinition) resource.getMetadataDataDefinition()).getToscaResourceName());
- ((ResourceMetadataDataDefinition) resource.getMetadataDataDefinition()).setToscaResourceName(toscaResourceName);
- return new ImmutablePair<>((String) resource.getUniqueId(), resource);
- }
-
- private ImmutablePair<String, GroupTypeData> updateGroupType(GroupTypeData group) {
- String originId = group.getUniqueId();
- group.getGroupTypeDataDefinition().setUniqueId(updateNamespace(originId));
- String type = updateNamespace(group.getGroupTypeDataDefinition().getType());
- group.getGroupTypeDataDefinition().setType(type);
- return new ImmutablePair<>(originId, group);
- }
-
- private ImmutablePair<String, GroupData> updateGroupNode(GroupData group) {
- String type = updateNamespace(group.getGroupDataDefinition().getType());
- group.getGroupDataDefinition().setType(type);
- return new ImmutablePair<>((String) group.getUniqueId(), group);
- }
-
-
- private ImmutablePair<String, PolicyTypeData> updatePolicyType(PolicyTypeData policy) {
- String originId = policy.getUniqueId();
- policy.getPolicyTypeDataDefinition().setUniqueId(updateNamespace(originId));
- String type = updateNamespace(policy.getPolicyTypeDataDefinition().getType());
- policy.getPolicyTypeDataDefinition().setType(type);
- return new ImmutablePair<>(originId, policy);
- }
-
- private ImmutablePair<String, RelationshipTypeData> updateRelationshipType(RelationshipTypeData relation) {
- String type = updateNamespace(relation.getRelationshipTypeDataDefinition().getType());
- relation.getRelationshipTypeDataDefinition().setType(type);
- List<String> validSources = relation.getRelationshipTypeDataDefinition().getValidSourceTypes();
- if(null != validSources){
- List<String> validSourceTypes = new ArrayList<>();
- for (String validSourceType : validSources) {
- validSourceTypes.add(updateNamespace(validSourceType));
- }
- relation.getRelationshipTypeDataDefinition().setValidSourceTypes(validSourceTypes);
- }
- return new ImmutablePair<>(relation.getUniqueId(), relation);
- }
-
- private ImmutablePair<String, RelationshipInstData> updateRelationshipNode(RelationshipInstData relation) {
- String type = updateNamespace(relation.getType());
- relation.setType(type);
- return new ImmutablePair<>(relation.getUniqueId(), relation);
- }
-
- private ImmutablePair<String, RequirementData> updateRequirementType(RequirementData req) {
- String node = req.getNode();
- if(null != node)
- req.setNode(updateNamespace(node));
- String type = updateNamespace(req.getRelationshipType());
- req.setRelationshipType(type);
- return new ImmutablePair<>(req.getUniqueId(), req);
- }
-
- private ImmutablePair<String, CapabilityTypeData> updateCapabilityType(CapabilityTypeData capType) {
- String originId = capType.getUniqueId();
- capType.getCapabilityTypeDataDefinition().setUniqueId(updateNamespace(originId));
- String type = updateNamespace(capType.getCapabilityTypeDataDefinition().getType());
- capType.getCapabilityTypeDataDefinition().setType(type);
- List<String> validSources = capType.getCapabilityTypeDataDefinition().getValidSourceTypes();
- if(null != validSources){
- List<String> validSourceTypes = new ArrayList<>();
- for (String validSourceType : validSources) {
- validSourceTypes.add(updateNamespace(validSourceType));
- }
- capType.getCapabilityTypeDataDefinition().setValidSourceTypes(validSourceTypes);
- }
- return new ImmutablePair<>(originId, capType);
-
- }
-
- private ImmutablePair<String, CapabilityData> updateCapabilityNode(CapabilityData capNode) {
- List<String> validSources = capNode.getValidSourceTypes();
- if(null != validSources){
- List<String> validSourceTypes = new ArrayList<>();
- for (String validSourceType : validSources) {
- validSourceTypes.add(updateNamespace(validSourceType));
- }
- capNode.setValidSourceTypes(validSourceTypes);
- }
- return new ImmutablePair<>(capNode.getUniqueId(), capNode);
- }
-
-
- private ImmutablePair<String, PropertyData> updatePropNode(PropertyData propType) {
- String originId = (String)propType.getUniqueId();
- propType.getPropertyDataDefinition().setUniqueId(updateNamespace(originId));
- String type = updateNamespace(propType.getPropertyDataDefinition().getType());
- propType.getPropertyDataDefinition().setType(type);
- if ("list".equalsIgnoreCase(type) || "map".equalsIgnoreCase(type)){
- SchemaDefinition schema = propType.getPropertyDataDefinition().getSchema();
- if(null != schema && null != schema.getProperty())
- handleSchemaTypeDef(schema.getProperty());
- }
- return new ImmutablePair<>(originId, propType);
- }
-
- private ImmutablePair<String, PropertyValueData> updatePropValueNode(PropertyValueData prop) {
- String type = updateNamespace(prop.getType());
- prop.setType(type);
- return new ImmutablePair<>(prop.getUniqueId(), prop);
- }
-
- private ImmutablePair<String, AttributeValueData> updateAttrValueNode(AttributeValueData attr) {
- String type = updateNamespace(attr.getType());
- attr.setType(type);
- return new ImmutablePair<>(attr.getUniqueId(), attr);
- }
-
- private ImmutablePair<String, InputValueData> updateInputValueNode(InputValueData input) {
- String type = updateNamespace(input.getType());
- input.setType(type);
- return new ImmutablePair<>(input.getUniqueId(), input);
- }
-
- private ImmutablePair<String, InputsData> updateInputNode(InputsData input){
- String type = updateNamespace(input.getPropertyDataDefinition().getType());
- input.getPropertyDataDefinition().setType(type);
- if ("list".equalsIgnoreCase(type) || "map".equalsIgnoreCase(type)){
- SchemaDefinition schema = input.getPropertyDataDefinition().getSchema();
- if(null != schema && null != schema.getProperty())
- handleSchemaTypeDef(schema.getProperty());
- }
- return new ImmutablePair<>((String)input.getUniqueId(), input);
- }
-
-
- private void handleSchemaTypeDef(PropertyDataDefinition schemaProp) {
- String schemaType = updateNamespace(schemaProp.getType());
- schemaProp.setType(schemaType);
- }
-
- private ImmutablePair<String, DataTypeData> updateDataType(DataTypeData dataType) {
- String originId = dataType.getUniqueId();
- dataType.getDataTypeDataDefinition().setUniqueId(updateNamespace(originId));
- String name = updateNamespace(dataType.getDataTypeDataDefinition().getName());
- dataType.getDataTypeDataDefinition().setName(name);
- String derivedFromName = updateNamespace(dataType.getDataTypeDataDefinition().getDerivedFromName());
- dataType.getDataTypeDataDefinition().setDerivedFromName(derivedFromName);
- return new ImmutablePair<>(originId, dataType);
-
- }
-
- private ImmutablePair<String, AttributeData> updateAttributeNode(AttributeData attr){
- String type = updateNamespace(attr.getAttributeDataDefinition().getType());
- attr.getAttributeDataDefinition().setType(type);
- if("list".equalsIgnoreCase(type) || "map".equalsIgnoreCase(type)){
- SchemaDefinition schema = attr.getAttributeDataDefinition().getSchema();
- if(null != schema && null != schema.getProperty())
- handleSchemaTypeDef(schema.getProperty());
- }
- return new ImmutablePair<>(attr.getUniqueId(), attr);
- }
-
-
-
- private String updateNamespace(String oldName) {
- if (oldName == null) {
- return null;
- }
- String name = oldName.replace("com.att.d2.", "org.openecomp.");
- // correcting naming convention
- return name.replace("org.openecomp.resources.", "org.openecomp.resource.");
- }
-
- private <T extends GraphNode> T onSuccess(TitanVertex vertex, GraphNode node, Class<T> clazz){
- Map<String, Object> newProp = titanGenericDao.getProperties(vertex);
- return GraphElementFactory.createElement(node.getLabel(), GraphElementTypeEnum.Node, newProp, clazz);
- }
-
- private <T extends GraphNode> Either<T, TitanOperationStatus> handleNode(Vertex vertex, GraphNode node, Class<T> clazz){
- try {
-
- Map<String, Object> mapProps = node.toGraphMap();
-
- for (Map.Entry<String, Object> entry : mapProps.entrySet()) {
- vertex.property(entry.getKey(), entry.getValue());
- }
-
- Either<TitanVertex, TitanOperationStatus> vertexByPropertyAndLabel = titanGenericDao.getVertexByProperty(node.getUniqueIdKey(), node.getUniqueId());
- return vertexByPropertyAndLabel.either(v -> Either.left(onSuccess(v, node, clazz)), status -> Either.right(status));
-
- } catch (Exception e) {
- if (log.isDebugEnabled()) {
- log.debug("Failed to update node for {}", node.getKeyValueId(), e);
- }
- return Either.right(TitanGraphClient.handleTitanException(e));
- }
- }
-
- private <T extends GraphNode> Either<T, TitanOperationStatus> updateNodeIncludingUID(String originId, GraphNode node, Class<T> clazz) {
- Either<TitanVertex, TitanOperationStatus> vertexByProperty = titanGenericDao.getVertexByProperty(node.getUniqueIdKey(), originId);
- return vertexByProperty.either(vertex -> handleNode(vertex, node, clazz), status -> Either.right(status));
- }
-}
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
deleted file mode 100644
index 7d009fe158..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/ToscaTemplateRegeneration.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-
-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;
-import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
-import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-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.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.tosca.ToscaError;
-import org.openecomp.sdc.be.tosca.ToscaExportHandler;
-import org.openecomp.sdc.be.tosca.ToscaRepresentation;
-import org.openecomp.sdc.common.util.GeneralUtility;
-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("toscaTemplateRegeneration")
-public class ToscaTemplateRegeneration implements Migration1707Task {
-
- private static Logger LOGGER = LoggerFactory.getLogger(ToscaTemplateRegeneration.class);
-
- @Autowired
- protected ArtifactCassandraDao artifactCassandraDao;
-
- @Autowired
- private ToscaExportHandler toscaExportUtils;
-
- @Autowired
- private ToscaOperationFacade toscaOperationFacade;
-
- @Override
- public boolean migrate() {
- boolean result = true;
- Either<List<GraphVertex>, StorageOperationStatus> getAllCertifiedComponentsRes;
- try{
- getAllCertifiedComponentsRes = getAllCertifiedComponents();
- if(getAllCertifiedComponentsRes.isRight()){
- result = false;
- }
- if(result && CollectionUtils.isNotEmpty(getAllCertifiedComponentsRes.left().value())){
- result = regenerateToscaTemplateArtifacts(getAllCertifiedComponentsRes.left().value());
- }
- } catch(Exception e){
- LOGGER.error("The exception {} has been occured upon tosca template regeneration migration. ", e);
- result = false;
- } finally {
- if(result){
- toscaOperationFacade.commit();
- } else {
- toscaOperationFacade.rollback();
- }
- }
- return result;
- }
-
- private boolean regenerateToscaTemplateArtifacts(List<GraphVertex> components) {
- boolean result = true;
- for(GraphVertex componentV : components){
- String componentId = componentV.getUniqueId();
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentsRes = toscaOperationFacade.getToscaElement(componentId);
- 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;
- }
- }
- return result;
- }
-
- @SuppressWarnings("unchecked")
- 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);
- if (exportComponent.isRight()) {
- 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.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.getUniqueId(), exportComponent.right().value());
- result = false;
- }
- }
- if(result){
- 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);
-
- Either<GraphVertex, TitanOperationStatus> updateVertexRes = toscaOperationFacade.getTitanDao().updateVertex(toscaDataVertexRes.left().value());
- if(updateVertexRes.isRight()){
- result = false;
- }
- }
- if(result){
- ESArtifactData artifactData = new ESArtifactData(data.getEsId(), exportComponent.left().value().getMainYaml().getBytes());
- CassandraOperationStatus status = artifactCassandraDao.saveArtifact(artifactData);
- if(status != CassandraOperationStatus.OK){
- result = false;
- }
- }
- return result;
- }
-
- public Either<List<GraphVertex>, StorageOperationStatus> getAllCertifiedComponents() {
-
- Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
- propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- List<GraphVertex> components = null;
- Either<List<GraphVertex>, TitanOperationStatus> getVerticiesRes = toscaOperationFacade.getTitanDao().getByCriteria(null, propertiesToMatch,JsonParseFlagEnum.NoParse);
-
- 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()){
- components = getVerticiesRes.left().value();
- }
- return Either.left(components);
- }
-
- @Override
- public String description() {
- return "toscaTemplateRegeneration";
- }
-}
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
deleted file mode 100644
index 89ac6f7cb6..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/VfModulesPropertiesAdding.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707;
-
-import java.util.ArrayList;
-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 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;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.GroupDefinition;
-import org.openecomp.sdc.be.model.GroupInstance;
-import org.openecomp.sdc.be.model.GroupInstanceProperty;
-import org.openecomp.sdc.be.model.GroupProperty;
-import org.openecomp.sdc.be.model.GroupTypeDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.jsontitan.operations.BaseOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
-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.GroupTypeOperation;
-import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
-import org.openecomp.sdc.be.resources.data.PropertyData;
-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("vfModulesPropertiesAdding")
-public class VfModulesPropertiesAdding {
-
- private static Logger LOGGER = LoggerFactory.getLogger(VfModulesPropertiesAdding.class);
-
- @Autowired
- private ToscaOperationFacade toscaOperationFacade;
-
- @Autowired
- private TopologyTemplateOperation topologyTemplateOperation;
-
- @Resource(name ="group-type-operation-mig")
- private GroupTypeOperation groupTypeOperation;
-
- @Resource(name = "property-operation-mig")
- private PropertyOperation propertyOperation;
-
-
- public boolean migrate(String groupsTypeYmlFilePath) {
- LOGGER.debug("Going to add new properties to vfModules. ");
- boolean result = true;
- GroupTypeDefinition vfModule;
- Either<List<GraphVertex>, TitanOperationStatus> getAllTopologyTemplatesRes = null;
- String vfModuleUid = "org.openecomp.groups.VfModule.1.0.grouptype";
- Either<GroupTypeDefinition, TitanOperationStatus> getGroupTypeVfModuleRes ;
- List<PropertyDefinition> updatedProperties = null;
- try{
- LOGGER.debug("Going to fetch {}. ", vfModuleUid);
- getGroupTypeVfModuleRes = groupTypeOperation.getGroupTypeByUid(vfModuleUid);
-
- 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();
- 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(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);
- if (getAllTopologyTemplatesRes.isRight() && getAllTopologyTemplatesRes.right().value() != TitanOperationStatus.NOT_FOUND) {
- LOGGER.debug("Failed to fetch all non marked topology templates , propsHasNot {}, error {}", propsHasNot, getAllTopologyTemplatesRes.right().value());
- result = false;
- }
- }
- if(result && getAllTopologyTemplatesRes!=null && getAllTopologyTemplatesRes.isLeft()){
- result = addNewVfModulesProperties(getAllTopologyTemplatesRes.left().value(), updatedProperties);
- }
- } catch (Exception e){
- result = false;
- }
- finally{
- if(result){
- toscaOperationFacade.commit();
- } else {
- toscaOperationFacade.rollback();
- }
- }
- return result;
- }
-
- private boolean addNewVfModulesProperties(List<GraphVertex> components, List<PropertyDefinition> updatedProperties) {
- boolean result = true;
- 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(GraphVertex componentV, List<PropertyDefinition> updatedProperties) {
- boolean result = true;
- List<GroupDefinition> vfModules = null;
- 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 -> 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(getToscaElementRes.left().value().getComponentInstances())){
- result = addPropertiesToVfModuleInstances(getToscaElementRes.left().value(), componentV, updatedProperties);
- }
- return result;
- }
-
- 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;
- 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()
- .stream()
- .filter(gi -> gi.getType().equals(BaseOperation.VF_MODULE))
- .collect(Collectors.toList());
- }
- if(vfModuleInstances != null){
- for(GroupInstance vfModuleInstance :vfModuleInstances){
- addAllNewProperties(vfModuleInstance.getProperties(),updatedProperties);
- pathKeys = new ArrayList<>();
- pathKeys.add(componentInstance.getUniqueId());
- StorageOperationStatus status = topologyTemplateOperation
- .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 boolean addNewPropertiesToGroupType(GroupTypeDefinition vfModule, List<PropertyDefinition> newProperties) {
- boolean result = true;
- Either<Map<String, PropertyData>, TitanOperationStatus> addPropertiesRes = propertyOperation
- .addPropertiesToElementType(vfModule.getUniqueId(), NodeTypeEnum.GroupType, newProperties);
- if(addPropertiesRes.isRight()){
- result = false;
- }
- return result;
- }
-
- private List<PropertyDefinition> getAllVfModuleTypePropertiesFromYaml(String groupsTypeYmlFilePath) {
- List<DataTypeDefinition> groupTypes = DataTypesUpdate.extractDataTypesFromYaml(groupsTypeYmlFilePath);
- DataTypeDefinition vfModule = groupTypes.stream().filter(g -> g.getName().equals(BaseOperation.VF_MODULE)).findFirst().orElse(null);
- return vfModule.getProperties();
- }
-
- private List<PropertyDefinition> getNewVfModuleTypeProperties(List<PropertyDefinition> allVfModuleTypeProperties, GroupTypeDefinition vfModule) {
- Map<String, PropertyDefinition> existingVfModuleTypeProperties = vfModule.getProperties()
- .stream()
- .collect(Collectors.toMap(p -> p.getName(), p -> p));
-
- List<PropertyDefinition> newGroupTypeProperties = new ArrayList<>();
- for(PropertyDefinition property : allVfModuleTypeProperties){
- if(!existingVfModuleTypeProperties.containsKey(property.getName())){
- newGroupTypeProperties.add(property);
- }
- }
- return newGroupTypeProperties;
- }
-
- public String description() {
- return "vfModulesPropertiesAdding";
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/CategoriesUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/CategoriesUtils.java
deleted file mode 100644
index 44d95395d0..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/CategoriesUtils.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import org.openecomp.sdc.be.model.category.CategoryDefinition;
-import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class CategoriesUtils {
-
- public static final String OLD_CATEGORY_ID_SUB_STR = "layer";
-
- public static List<CategoryDefinition> filterOldCategories(List<CategoryDefinition> categoryDefinitions) {
- return categoryDefinitions.stream()
- .filter(categoryDefinition -> !categoryDefinition.getUniqueId().contains(OLD_CATEGORY_ID_SUB_STR))
- .collect(Collectors.toList());
- }
-
- public static List<SubCategoryDefinition> filterOldSubCategories(List<SubCategoryDefinition> categoryDefinitions) {
- return categoryDefinitions.stream()
- .filter(categoryDefinition -> !categoryDefinition.getUniqueId().contains(OLD_CATEGORY_ID_SUB_STR))
- .collect(Collectors.toList());
- }
-
-}
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
deleted file mode 100644
index 7603a5704a..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ComponentMigration.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import fj.data.Either;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations.RequirementsCapabilitiesMigrationService;
-import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
-import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.GroupDefinition;
-import org.openecomp.sdc.be.model.GroupInstance;
-import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.migration.MigrationMalformedDataLogger;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.openecomp.sdc.common.api.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Resource;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-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> {
-
- private static Logger LOGGER = LoggerFactory.getLogger(ComponentMigration.class);
-
- @Resource(name = "tosca-operation-facade")
- private ToscaOperationFacade toscaOperations;
-
- @Resource(name = "req-cap-mig-service")
- RequirementsCapabilitiesMigrationService<T> requirementsCapabilitiesMigrationService;
-
- @Resource(name = "invariant-uuid-resolver")
- private InvariantUUIDResolver <T> invariantUUIDResolver;
-
- @Resource(name = "node-template-missing-data-resolver")
- private NodeTemplateMissingDataResolver nodeTemplateMissingDataResolver;
-
- @Override
- boolean save(T element) {
- LOGGER.debug(String.format("creating component %s in new graph", 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())));
- }
-
- @Override
- Either<T, StorageOperationStatus> getElementFromNewGraph(T element) {
- LOGGER.debug(String.format("checking if component %s already exists on new graph", element.getName()));
- return toscaOperations.getToscaElement(element.getUniqueId(), JsonParseFlagEnum.ParseMetadata);
- }
-
- @Override
- public StorageOperationStatus getNotFoundErrorStatus() {
- 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;
- }
-
-
- protected void setMissingTemplateInfo(List<T> components) {
- Map<String, ToscaElement> origCompMap = new HashMap<>();
- for (T component : components) {
- List<ComponentInstance> instances = component.getComponentInstances();
- if(null != instances) {
- for (ComponentInstance instance : instances) {
- nodeTemplateMissingDataResolver.resolveNodeTemplateInfo(instance, origCompMap, component);
- nodeTemplateMissingDataResolver.fixVFGroupInstances(component, instance);
- }
- }
- nodeTemplateMissingDataResolver.fixVFGroups(component);
- }
- }
-
-
-
-
-
-
-
-
-
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ConsumersMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ConsumersMigration.java
deleted file mode 100644
index c455f870aa..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ConsumersMigration.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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
deleted file mode 100644
index e26a01e1b4..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/InvariantUUIDResolver.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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
deleted file mode 100644
index 76c66de1c9..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/JsonModelMigration.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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.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 Migration1707Task {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(JsonModelMigration.class);
-
- @Resource(name = "titan-dao")
- TitanDao titanDao;
-
- @Override
- public boolean migrate() {
- Either<List<T>, ?> elementsToMigrate = getElementsToMigrate();
- return elementsToMigrate.either(this::migrateElementsToNewGraph,
- errorStatus -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_RETRIEVE_NODES.getMessage(errorStatus.toString())));
- }
-
- boolean doPostSaveOperation(T element) {
- return true;
- }
-
- boolean doPostMigrateOperation(List<T> elements) {
- 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) {
- titanDao.rollback();
- return false;
- }
- titanDao.commit();
- }
- return postMigrate(elementsToMigrate);
- }
-
- private boolean migrateElement(T node) {
- boolean savedSuccessfully = saveElementIfNotExists(node);
- return savedSuccessfully && doPostSaveOperation(node);
- }
-
- private boolean postMigrate(List<T> elements) {
- boolean postMigrateSuccessfully = doPostMigrateOperation(elements);
- if (!postMigrateSuccessfully) {
- titanDao.rollback();
- return false;
- }
- titanDao.commit();
- return true;
- }
-
- private boolean saveElementIfNotExists(T element) {
- return isExists(element).either(isExist -> isExist || save(element),
- status -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_GET_NODE_FROM_GRAPH.getMessage(status.toString())));
- }
-
-
- private Either<Boolean, ?> isExists(T element) {
- Either<T, ?> byId = getElementFromNewGraph(element);
- return byId.either(existingVal -> Either.left(true),
- this::getEitherNotExistOrErrorStatus);
- }
-
- private <S> Either<Boolean, S> getEitherNotExistOrErrorStatus(S status) {
- return status == getNotFoundErrorStatus() ? Either.left(false) : Either.right(status);
- }
-
- abstract Either<List<T>, ?> getElementsToMigrate();
-
- abstract Either<T, ?> getElementFromNewGraph(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/MigrationByIdDerivedNodeTypeResolver.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/MigrationByIdDerivedNodeTypeResolver.java
deleted file mode 100644
index 066ab9a01a..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/MigrationByIdDerivedNodeTypeResolver.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import fj.data.Either;
-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.model.DerivedNodeTypeResolver;
-
-import javax.annotation.Resource;
-import java.util.Collections;
-import java.util.List;
-
-public class MigrationByIdDerivedNodeTypeResolver implements DerivedNodeTypeResolver {
-
- @Resource(name = "titan-dao")
- private TitanDao titanDao;
-
- @Override
- public Either<List<GraphVertex>, TitanOperationStatus> findDerivedResources(String parentResource) {
- return titanDao.getVertexById(parentResource, JsonParseFlagEnum.ParseMetadata).left().map(Collections::singletonList);
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java
deleted file mode 100644
index c83421066c..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NodeTemplateMissingDataResolver.java
+++ /dev/null
@@ -1,353 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
-import fj.data.Either;
-import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
-import org.openecomp.sdc.be.model.*;
-import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
-import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
-import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
-import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.openecomp.sdc.common.api.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-
-public class NodeTemplateMissingDataResolver <T extends Component> {
-
- private static Logger LOGGER = LoggerFactory.getLogger(NodeTemplateMissingDataResolver.class);
-
- @Resource(name = "tosca-element-lifecycle-operation")
- private ToscaElementLifecycleOperation lifecycleOperation;
-
- @Resource(name = "topology-template-operation")
- public TopologyTemplateOperation topologyTemplateOperation;
-
- public void resolveNodeTemplateInfo(ComponentInstanceDataDefinition vfInst, Map<String, ToscaElement> origCompMap, T component) {
- lifecycleOperation.resolveToscaComponentName(vfInst, origCompMap);
- if(OriginTypeEnum.VF == vfInst.getOriginType()) {
- collectVFInstanceInputs(component, origCompMap, vfInst);
- }
- }
-
-
-
-
- public void updateServiceComposition(Component component, Map<String, ToscaElement> origCompMap, Component oldModelService, Map<String, Boolean> updateMap){
-
- boolean composition = false;
- boolean instInputs = false;
- boolean instGroups = false;
- List<ComponentInstance> instances = component.getComponentInstances();
- if(null != instances) {
- for (ComponentInstance instance : instances) {
- composition = composition || lifecycleOperation.resolveToscaComponentName(instance, origCompMap);
- if(OriginTypeEnum.VF == instance.getOriginType()) {
- instInputs = instInputs || collectVFInstanceInputs(component, origCompMap, instance);
- instGroups = instGroups || resolveInstGroupsFromOldTitanGraphAndApplyFix(component, instance, oldModelService);
- }
- }
- }
- updateMap.put(JsonConstantKeysEnum.COMPOSITION.name(), composition);
- updateMap.put(EdgeLabelEnum.INST_INPUTS.name(), instInputs);
- updateMap.put(EdgeLabelEnum.INST_GROUPS.name(), instGroups);
- }
-
-
- public void updateVFComposition(Component component, Map<String, ToscaElement> origCompMap, Map<String, Boolean> updateMap) {
-
- boolean composition = false;
- boolean groups = fixVFGroups(component);
- List<ComponentInstance> instances = component.getComponentInstances();
- if(null != instances) {
- for (ComponentInstance instance : instances) {
- composition = composition || lifecycleOperation.resolveToscaComponentName(instance, origCompMap);
- }
- }
- updateMap.put(JsonConstantKeysEnum.COMPOSITION.name(), composition);
- updateMap.put(EdgeLabelEnum.GROUPS.name(), groups);
- }
-
-
-
- private boolean resolveInstGroupsFromOldTitanGraphAndApplyFix(Component component, ComponentInstance instance, Component oldService){
-
- boolean res = false;
- //info already exists, apply fix if needed
- if(null != instance.getGroupInstances() && !instance.getGroupInstances().isEmpty()) {
- res = fixVFGroupInstances(component, instance);
- //get group instances from old model
- }else if(null != oldService){
- ComponentInstance origInstance = oldService.getComponentInstances().stream()
- .filter(p -> instance.getUniqueId().equals(p.getUniqueId()))
- .findAny().orElse(null);
- if(null != origInstance && null != origInstance.getGroupInstances()) {
- fixVFGroupInstances(oldService, origInstance);
- instance.setGroupInstances(origInstance.getGroupInstances());
- res = true;
- }
- }
- return res;
- }
-
- private boolean collectVFInstanceInputs(Component component, Map<String, ToscaElement> origCompMap, ComponentInstanceDataDefinition vfInst) {
- boolean res = false;
- String ciUid = vfInst.getUniqueId();
- String origCompUid = vfInst.getComponentUid();
- if(null == component.getComponentInstancesInputs())
- component.setComponentInstancesInputs(new HashMap<>());
- Map<String, List<ComponentInstanceInput>> componentInstInputs = component.getComponentInstancesInputs();
- Either<ToscaElement, StorageOperationStatus> origComp = fetchToscaElement(origCompMap, vfInst, origCompUid);
- if(origComp.isRight())
- return false;
- Map<String, PropertyDataDefinition> origVFInputs = ((TopologyTemplate)origComp.left().value()).getInputs();
- if (origVFInputs != null && !origVFInputs.isEmpty()) {
- res = true;
- Map<String, ComponentInstanceInput> collectedVFInputs = origVFInputs.values().stream()
- .collect(Collectors.toMap(PropertyDataDefinition::getName, ComponentInstanceInput::new));
-
- List<ComponentInstanceInput> instInputList = componentInstInputs.get(ciUid);
- Map<String, ComponentInstanceInput> existingInstInputs = ToscaDataDefinition.listToMapByName(instInputList);
- collectedVFInputs.putAll(existingInstInputs);
- List<ComponentInstanceInput> mergedList = new ArrayList<>(collectedVFInputs.values());
- componentInstInputs.put(ciUid, mergedList);
- }
- return res;
- }
-
- private Either<ToscaElement, StorageOperationStatus> fetchToscaElement(Map<String, ToscaElement> origCompMap, ComponentInstanceDataDefinition vfInst, String origCompUid) {
- Either<ToscaElement, StorageOperationStatus> origCompEither;
- if (!origCompMap.containsKey(origCompUid)) {
- origCompEither = topologyTemplateOperation.getToscaElement(origCompUid);
- if (origCompEither.isRight()) {
- LOGGER.error("failed to fetch Tosca element {} with id {}", vfInst.getComponentName(), origCompUid);
- return origCompEither;
- }
- origCompMap.put(origCompUid, origCompEither.left().value());
- }
- return Either.left(origCompMap.get(origCompUid));
- }
-
- protected boolean isProblematicGroup(GroupDefinition gr, String resourceName, Map<String, ArtifactDefinition> deploymentArtifacts) {
- List<String> artifacts = gr.getArtifacts();
- List<String> artifactsUuid = gr.getArtifactsUuid();
-
- if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) {
- LOGGER.debug("No groups in resource {} ", resourceName);
- return false;
- }
- if (artifacts.size() < artifactsUuid.size()) {
- LOGGER.debug(" artifacts.size() < artifactsUuid.size() group {} in resource {} ", gr.getName(), resourceName);
- return true;
- }
- if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) {
- LOGGER.debug(" artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() group {} in resource {} ", gr.getName(), resourceName);
- return true;
- }
- if (artifactsUuid.contains(null)) {
- LOGGER.debug(" artifactsUuid.contains(null) group {} in resource {} ", gr.getName(), resourceName);
- return true;
- }
-
- for (String artifactId : artifacts) {
- String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
- ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactlabel);
- if (artifactDefinition == null) {
- LOGGER.debug(" artifactDefinition == null label {} group {} in resource {} ", artifactlabel, gr.getName(), resourceName);
- return true;
- }
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactDefinition.getArtifactType());
- if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
- if (!artifactId.equals(artifactDefinition.getUniqueId())) {
- LOGGER.debug(" !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} group {} in resource {} ", artifactlabel, artifactId, gr.getName(), resourceName);
- return true;
- }
- if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
- LOGGER.debug(" artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} group {} in resource {} ", artifactlabel, gr.getName(), resourceName);
- return true;
- }
- }
- }
- return false;
- }
-
- protected boolean isProblematicGroupInstance(GroupInstance gi, String instName, String servicename, Map<String, ArtifactDefinition> deploymentArtifacts) {
- List<String> artifacts = gi.getArtifacts();
- List<String> artifactsUuid = gi.getArtifactsUuid();
- List<String> instArtifactsUuid = gi.getGroupInstanceArtifactsUuid();
-
- if ((artifactsUuid == null || artifactsUuid.isEmpty()) && (artifacts == null || artifacts.isEmpty())) {
- LOGGER.debug("No instance groups for instance {} in service {} ", instName, servicename);
- return false;
- }
- if (artifacts.size() < artifactsUuid.size()) {
- LOGGER.debug(" artifacts.size() < artifactsUuid.size() inst {} in service {} ", instName, servicename);
- return true;
- }
- if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) {
- LOGGER.debug(" artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() inst {} in service {} ", instName, servicename);
- return true;
- }
- if (artifactsUuid.contains(null)) {
- LOGGER.debug(" artifactsUuid.contains(null) inst {} in service {} ", instName, servicename);
- return true;
- }
-
- for (String artifactId : artifacts) {
- String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
- ArtifactDefinition artifactDefinition = deploymentArtifacts.get(artifactlabel);
- if (artifactDefinition == null) {
- LOGGER.debug(" artifactDefinition == null label {} inst {} in service {} ", artifactlabel, instName, servicename);
- return true;
- }
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactDefinition.getArtifactType());
- if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
- if (!artifactId.equals(artifactDefinition.getUniqueId())) {
- LOGGER.debug(" !artifactId.equals(artifactDefinition.getUniqueId() artifact {} artId {} inst {} in service {} ", artifactlabel, artifactId, instName, servicename);
- return true;
- }
- if (!artifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
- LOGGER.debug(" artifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ", artifactlabel, instName, servicename);
- return true;
- }
- } else {
- if (!instArtifactsUuid.contains(artifactDefinition.getArtifactUUID())) {
- LOGGER.debug(" instArtifactsUuid.contains(artifactDefinition.getArtifactUUID() label {} inst {} in service {} ", artifactlabel, instName, servicename);
- return true;
- }
- }
- }
- return false;
- }
-
- private String findArtifactLabelFromArtifactId(String artifactId) {
- String artifactLabel = "";
-
- int index = artifactId.lastIndexOf(".");
- if (index > 0 && index + 1 < artifactId.length())
- artifactLabel = artifactId.substring(index + 1);
- return artifactLabel;
- }
-
- public boolean fixVFGroups(Component component){
- boolean res = false;
-
- Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
- List<GroupDefinition> groups = component.getGroups();
- if (groups == null || groups.isEmpty()) {
- LOGGER.debug("No groups in component {} id {} ", component.getName(), component.getUniqueId());
- return res;
- }
-
- for (GroupDefinition group : groups) {
- if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) && deploymentArtifacts != null) {
- if (isProblematicGroup(group, component.getName(), deploymentArtifacts)) {
- res = true;
- List<String> groupArtifacts = null == group.getArtifacts()? new ArrayList<>() : new ArrayList<>(group.getArtifacts());
- group.setArtifacts(new ArrayList<>());
- group.setArtifactsUuid(new ArrayList<>());
- for (String artifactId : groupArtifacts) {
- String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
- LOGGER.debug("fix group: group name {} artifactId for fix {} artifactlabel {} ", group.getName(), artifactId, artifactlabel);
- if (!artifactlabel.isEmpty() && deploymentArtifacts.containsKey(artifactlabel)) {
- ArtifactDefinition artifact = deploymentArtifacts.get(artifactlabel);
- String correctArtifactId = artifact.getUniqueId();
- String correctArtifactUUID = artifact.getArtifactUUID();
- LOGGER.debug(" fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID);
- group.getArtifacts().add(correctArtifactId);
- if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
- group.getArtifactsUuid().add(correctArtifactUUID);
- }
- }
- }
- }
- }
- }
- return res;
- }
-
- public boolean fixVFGroupInstances(Component component, ComponentInstance instance){
- boolean res = false;
-
- Map<String, ArtifactDefinition> deploymentArtifacts = instance.getDeploymentArtifacts();
- List<GroupInstance> groupInstances = instance.getGroupInstances();
- if (groupInstances == null || groupInstances.isEmpty()) {
- LOGGER.debug("No instance groups for instance {} in service {} id {} ", instance.getName(), component.getName(), component.getUniqueId());
- return res;
- }
- for (GroupInstance group : groupInstances) {
- if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
- if (isProblematicGroupInstance(group, instance.getName(), component.getName(), deploymentArtifacts)) {
- res = true;
- LOGGER.debug("Migration1707ArtifactUuidFix fix group: resource id {}, group name {} ", component.getUniqueId(), group.getName());
- List<String> groupArtifacts = null == group.getArtifacts()? new ArrayList<>() : new ArrayList<>(group.getArtifacts());
- group.setArtifacts(new ArrayList<>());
- group.setArtifactsUuid(new ArrayList<>());
- group.setGroupInstanceArtifacts(new ArrayList<>());
- group.setGroupInstanceArtifactsUuid(new ArrayList<>());
-
- for (String artifactId : groupArtifacts) {
- String artifactlabel = findArtifactLabelFromArtifactId(artifactId);
- LOGGER.debug("Migration1707ArtifactUuidFix fix group: group name {} artifactId for fix {} artifactlabel {} ", group.getName(), artifactId, artifactlabel);
- if (!artifactlabel.isEmpty() && deploymentArtifacts.containsKey(artifactlabel)) {
- ArtifactDefinition artifact = deploymentArtifacts.get(artifactlabel);
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
- String correctArtifactId = artifact.getUniqueId();
- String correctArtifactUUID = artifact.getArtifactUUID();
- if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
-
- LOGGER.debug("Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID);
- group.getArtifacts().add(correctArtifactId);
- if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
- group.getArtifactsUuid().add(correctArtifactUUID);
- }
- } else {
- LOGGER.debug("Migration1707ArtifactUuidFix fix group: group name {} correct artifactId {} artifactUUID {} ", group.getName(), correctArtifactId, correctArtifactUUID);
- group.getGroupInstanceArtifacts().add(correctArtifactId);
- if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
- group.getGroupInstanceArtifactsUuid().add(correctArtifactUUID);
- }
- }
- }
- }
- }
- }
- }
- return res;
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesMigration.java
deleted file mode 100644
index 1717b1fa83..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesMigration.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import fj.data.Either;
-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.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("59da26b4-edd0-4412-a2e6-d6711f376340");
-
- @javax.annotation.Resource(name = "normatives-resolver")
- private NormativesResolver normativesResolver;
-
- @javax.annotation.Resource(name = "resource-version-migration")
- private VersionMigration<Resource> versionMigration;
-
- @Override
- public String description() {
- return "migration of node types";
- }
-
- @Override
- Either<List<Resource>, ?> getElementsToMigrate() {
- return normativesResolver.getAllNodeTypeNormatives();
- }
-
- @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/NormativesResolver.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesResolver.java
deleted file mode 100644
index cc9e6ec972..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/NormativesResolver.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Queue;
-import java.util.stream.Collectors;
-
-public class NormativesResolver {
-
- @javax.annotation.Resource(name = "resource-operation")
- private IResourceOperation resourceOperation;
-
- /**
- *
- * @return list of all normatives sorted by neighboring order
- */
- public Either<List<Resource>, StorageOperationStatus> getAllNodeTypeNormatives() {
- Either<List<Resource>, StorageOperationStatus> rootNormatives = resourceOperation.getRootResources();
- return rootNormatives.either(this::getAllNormatives,
- Either::right);
-
- }
-
- private Either<List<Resource>, StorageOperationStatus> getAllNormatives(List<Resource> rootResources) {
- List<Resource> allNormatives = new ArrayList<>();
- for (Resource rootResource : rootResources) {
- Either<List<Resource>, StorageOperationStatus> normativesOfRoot = getAllNodeTypeNormatives(rootResource);
- if (normativesOfRoot.isRight()) {
- return Either.right(normativesOfRoot.right().value());
- }
- allNormatives.addAll(normativesOfRoot.left().value());
- }
- return Either.left(allNormatives);
- }
-
- private Either<List<Resource>, StorageOperationStatus> getAllNodeTypeNormatives(Resource root) {
- List<Resource> normativeResources = new ArrayList<>();
- Queue<Resource> resources = new ArrayDeque<>();
- resources.add(root);
- while (!resources.isEmpty()) {
- Resource currentResource = resources.poll();
- normativeResources.add(currentResource);
- Either<List<Resource>, StorageOperationStatus> allDerivedResources = getAllNonVFDerivedResources(currentResource);
- if (allDerivedResources.isRight()) {
- return Either.right(allDerivedResources.right().value());
- }
- List<Resource> derivedResources = allDerivedResources.left().value();
- replaceDerivedNameWithDerivedUniqueId(currentResource, derivedResources);
- resources.addAll(derivedResources);
- }
- return Either.left(normativeResources);
- }
-
- private void replaceDerivedNameWithDerivedUniqueId(Resource currentResource, List<Resource> derivedResources) {
- derivedResources.forEach(resource -> resource.setDerivedFrom(Collections.singletonList(currentResource.getUniqueId())));
- }
-
- private Either<List<Resource>, StorageOperationStatus> getAllNonVFDerivedResources(Resource resource) {
- Either<List<Resource>, StorageOperationStatus> childrenNodes = resourceOperation.getAllDerivedResources(resource);
- return childrenNodes.either(resourceList -> Either.left(filterNonVFResources(resourceList)),
- this::resolveEmptyListOrErrorStatus);
- }
-
- private List<Resource> filterNonVFResources(List<Resource> resources) {
- return resources.stream().filter(resource -> resource.getResourceType() != ResourceTypeEnum.VF).collect(Collectors.toList());
- }
-
- private Either<List<Resource>, StorageOperationStatus> resolveEmptyListOrErrorStatus(StorageOperationStatus storageOperationStatus) {
- return storageOperationStatus == StorageOperationStatus.NOT_FOUND ? Either.left(Collections.emptyList()) : Either.right(storageOperationStatus);
- }
-
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourceVersionMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourceVersionMigration.java
deleted file mode 100644
index aeb85a7d35..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourceVersionMigration.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-
-import java.util.List;
-
-public class ResourceVersionMigration extends VersionMigration<Resource> {
-
- @javax.annotation.Resource(name = "resource-operation")
- private IResourceOperation resourceOperation;
-
- @Override
- NodeTypeEnum getNodeTypeEnum() {
- return NodeTypeEnum.Resource;
- }
-
-}
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
deleted file mode 100644
index f605d8c3fa..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ResourcesCategoriesMigration.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-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.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;
-import org.openecomp.sdc.be.datatypes.category.CategoryDataDefinition;
-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;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import static org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.CategoriesUtils.filterOldCategories;
-import static org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.CategoriesUtils.filterOldSubCategories;
-
-
-public class ResourcesCategoriesMigration implements Migration1707Task {
-
- @Resource(name = "element-operation")
- private IElementOperation elementOperation;
-
- @Resource(name = "element-operation-migration")
- private IElementOperation elementOperationMigration;
-
- @Resource(name = "titan-dao")
- TitanDao titanDao;
-
- @Override
- public String description() {
- return "migrate resource categories";
- }
-
- @Override
- public boolean migrate() {
- return getCategoriesToMigrate().either(this::migrateCategories,
- errorStatus -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_RETRIEVE_CATEGORIES.getMessage(errorStatus.name())));
- }
-
- private Either<List<CategoryDefinition>, ActionStatus> getCategoriesToMigrate() {
- return elementOperation.getAllCategories(NodeTypeEnum.ResourceNewCategory, false);
- }
-
- private boolean migrateCategories(List<CategoryDefinition> categoryDefinitions) {
- List<CategoryDefinition> categoriesToMigrate = filterOldCategoriesAndSubCategories(categoryDefinitions);
- for (CategoryDefinition categoryDefinition : categoriesToMigrate) {
- boolean isMigrated = migrateCategoryIfNotExists(categoryDefinition);
- if (!isMigrated) {
- titanDao.rollback();
- return false;
- }
- titanDao.commit();
- }
- return true;
- }
-
-
- //since production was malformed we need to fixed it by removing wrong categories and sub categories
- private List<CategoryDefinition> filterOldCategoriesAndSubCategories(List<CategoryDefinition> categoryDefinitions) {
- Map<String, List<CategoryDefinition>> categoriesByNormalName = categoryDefinitions.stream().collect(Collectors.groupingBy(CategoryDataDefinition::getNormalizedName));
- List<CategoryDefinition> categoriesToMigrate = filterOldCategories(categoryDefinitions);
- for (CategoryDefinition categoryDefinition : categoriesToMigrate) {
- List<SubCategoryDefinition> newSubCategories = getAllDistinctSubCategories(categoriesByNormalName.get(categoryDefinition.getNormalizedName()));
- categoryDefinition.setSubcategories(newSubCategories);
- }
- return categoriesToMigrate;
- }
-
- private List<SubCategoryDefinition> getAllDistinctSubCategories (List<CategoryDefinition> categoriesDefinitions) {
- 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);
- }
-
- private List<SubCategoryDefinition> getDistinctSubCategories(Map<String, List<SubCategoryDefinition>> subCategoriesByNormalName) {
- List<SubCategoryDefinition> allSubCategories = new ArrayList<>();
- for (List<SubCategoryDefinition> subCategoryDefinitions : subCategoriesByNormalName.values()) {
- if (subCategoryDefinitions.size() == 1) {
- allSubCategories.addAll(subCategoryDefinitions);
- } else {
- allSubCategories.addAll(filterOldSubCategories(subCategoryDefinitions));
- }
- }
- return allSubCategories;
- }
-
- private boolean migrateCategoryIfNotExists(CategoryDefinition categoryDefinition) {
- return isExists(categoryDefinition).either(isExist -> isExist ? migrateSubCategories(categoryDefinition) : migrateCategoryAndSubCategories(categoryDefinition),
- error -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_RETRIEVE_CATEGORY.getMessage(categoryDefinition.getName(), error.name())));
- }
-
- private boolean migrateCategoryAndSubCategories(CategoryDefinition resourceCategory) {
- return elementOperationMigration.createCategory(resourceCategory, NodeTypeEnum.ResourceNewCategory)
- .either(createdCategory -> this.migrateSubCategories(resourceCategory),
- status -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_CREATE_CATEGORY.getMessage(resourceCategory.getName(), status.name())));
- }
-
- private boolean migrateSubCategories(CategoryDefinition categoryDefinition) {
- for (SubCategoryDefinition subCategory : categoryDefinition.getSubcategories()) {
- boolean isMigrated = migrateSubcategoryIfNotExists(categoryDefinition, subCategory);
- if (!isMigrated) {
- return false;
- }
- }
- return true;
- }
-
- private boolean migrateSubcategoryIfNotExists(CategoryDefinition parentCategory, SubCategoryDefinition subCategory) {
- return isExists(parentCategory, subCategory).either(isExists -> isExists || migrateSubCategory(parentCategory, subCategory),
- status -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_RETRIEVE_CATEGORY.getMessage(subCategory.getName(), status.name())));
- }
-
- private boolean migrateSubCategory(CategoryDefinition categoryDefinition, SubCategoryDefinition subCategory) {
- return elementOperationMigration.createSubCategory(categoryDefinition.getUniqueId(), subCategory, NodeTypeEnum.ResourceSubcategory)
- .either(createdSubCategory -> true,
- errorStatus -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_CREATE_SUB_CATEGORY.getMessage(subCategory.getName(), categoryDefinition.getName(), errorStatus.name())));
-
- }
-
- private Either<Boolean, ActionStatus> isExists(CategoryDefinition category) {
- Either<CategoryDefinition, ActionStatus> byId = getCategoryById(category);
- return byId.either(existingVal -> Either.left(true),
- this::getEitherNotExistOrErrorStatus);
- }
-
- private Either<Boolean, ActionStatus> isExists(CategoryDefinition parentCategory, SubCategoryDefinition subCategory) {
- return getSubCategoryById(parentCategory, subCategory).either(existingVal -> Either.left(true),
- this::getEitherNotExistOrErrorStatus);
- }
-
- private Either<Boolean, ActionStatus> getEitherNotExistOrErrorStatus(ActionStatus status) {
- return status == ActionStatus.COMPONENT_CATEGORY_NOT_FOUND ? Either.left(false) : Either.right(status);
- }
-
- private Either<CategoryDefinition, ActionStatus> getCategoryById(CategoryDefinition category) {
- return elementOperationMigration.getCategory(NodeTypeEnum.ResourceNewCategory, category.getUniqueId());
- }
-
- 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
deleted file mode 100644
index 857bcd9b43..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceCategoriesMigration.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.category.CategoryDefinition;
-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.List;
-
-import static org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils.handleError;
-
-public class ServiceCategoriesMigration extends JsonModelMigration<CategoryDefinition> {
-
- @Resource(name = "element-operation")
- private IElementOperation elementOperation;
-
- @Resource(name = "element-operation-migration")
- private IElementOperation elementOperationMigration;
-
-
- @Override
- public String description() {
- return "migrate services categories";
- }
-
- @Override
- Either<List<CategoryDefinition>, ?> getElementsToMigrate() {
- return elementOperation.getAllCategories(NodeTypeEnum.ServiceNewCategory, false).left().map(CategoriesUtils::filterOldCategories);
- }
-
- @Override
- Either<CategoryDefinition, ?> getElementFromNewGraph(CategoryDefinition node) {
- 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
- 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
- ActionStatus getNotFoundErrorStatus() {
- return ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceVersionMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceVersionMigration.java
deleted file mode 100644
index 32ef06a220..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServiceVersionMigration.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
-import org.openecomp.sdc.be.model.operations.api.IServiceOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-
-import java.util.List;
-
-public class ServiceVersionMigration extends VersionMigration<Service> {
-
- @javax.annotation.Resource(name = "service-operation")
- private IServiceOperation serviceOperation;
-
- @Override
- NodeTypeEnum getNodeTypeEnum() {
- return NodeTypeEnum.Service;
- }
-
-}
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
deleted file mode 100644
index 040d220912..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/ServicesMigration.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import javax.annotation.Resource;
-
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-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.migration.MigrationMalformedDataLogger;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import fj.data.Either;
-
-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")
- private IServiceOperation serviceOperation;
-
- @Resource(name = "service-version-migration")
- private VersionMigration<Service> versionMigration;
-
- @Override
- public String description() {
- return "migrate services";
- }
-
- @Override
- Either<List<Service>, ?> getElementsToMigrate() {
- return serviceOperation.getAll();
- }
-
- @Override
- boolean save(Service element) {
- MigrationMalformedDataLogger.logIfServiceUsingMalformedVfs(element);
- filterOutDuplicatePropsAndAttrs(element);
- element.setConformanceLevel(DEFAULT_CONFORMANCE_LEVEL);
- requirementsCapabilitiesMigrationService.overrideInstanceCapabilitiesRequirements(element);
- return super.save(element);
- }
-
- @Override
- boolean doPostSaveOperation(Service element) {
- return element.getComponentInstances() == null ||
- (requirementsCapabilitiesMigrationService.associateFulfilledRequirements(element, NodeTypeEnum.Service) &&
- requirementsCapabilitiesMigrationService.associateFulfilledCapabilities(element, NodeTypeEnum.Service));
- }
-
- @Override
- boolean doPostMigrateOperation(List<Service> elements) {
- LOGGER.info("migrating services versions");
- return versionMigration.buildComponentsVersionChain(elements);
- }
-
- @Override
- void doPreMigrationOperation(List<Service> elements) {
- super.doPreMigrationOperation(elements);
- setMissingTemplateInfo(elements);
- }
-
- 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 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 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 void removeDuplicatedNameAttributes(Service service) {
- Map<String, List<ComponentInstanceProperty>> componentInstancesAttributes = service.getComponentInstancesAttributes();
- componentInstancesAttributes.forEach((uid, attributes) -> {
- componentInstancesAttributes.put(uid, getUniquedNameAttributeList(service, attributes));
- });
- }
-
- 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 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
deleted file mode 100644
index 3f62273931..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UserStatesMigration.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import com.thinkaurelius.titan.core.TitanVertex;
-import fj.data.Either;
-import org.apache.tinkerpop.gremlin.structure.Direction;
-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.be.dao.neo4j.GraphPropertiesDictionary;
-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.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.resources.data.UserData;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-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> {
-
- private static final String MIGRATING_USER_ID = "jh0003";
- private static final int OUT_VERTEX_INDEX = 0;
- private static final int IN_VERTEX_INDEX = 1;
- private static Logger LOGGER = LoggerFactory.getLogger(UserStatesMigration.class);
-
- @Resource(name = "titan-generic-dao")
- private TitanGenericDao genericDao;
-
- @Resource(name = "titan-generic-dao-migration")
- private TitanGenericDao genericDaoMigration;
-
- @Override
- public String description() {
- return "migrate user states";
- }
-
-
- @Override
- public boolean migrate() {
-// return removeMigratingUserStates() && super.migrate();
- return super.migrate();
- }
-
- @Override
- Either<List<Edge>, TitanOperationStatus> getElementsToMigrate() {
- LOGGER.debug("fetching user states edges from old graph");
- return genericDao.getAll(NodeTypeEnum.User, UserData.class)
- .left().bind(this::getEdgesForUsers);
- }
-
- @Override
- Either<Edge, TitanOperationStatus> getElementFromNewGraph(Edge edge) {
- LOGGER.debug("finding user state edge in new graph");
- Vertex outVertex = edge.outVertex();
- String outVertexUIDKey = getVertexUniqueId(outVertex);
- String outVertexUIDValue = outVertex.property(outVertexUIDKey).value().toString();
-
- Vertex inVertex = edge.inVertex();
- String inVertexUIDKey = getVertexUniqueId(inVertex);
- String inVertexUIDValue = inVertex.property(inVertexUIDKey).value().toString();
-
- return genericDaoMigration.getEdgeByVerticies(outVertexUIDKey, outVertexUIDValue, inVertexUIDKey, inVertexUIDValue, edge.label());
- }
-
- @Override
- boolean save(Edge userState) {
- Either<InOutVertices, TitanOperationStatus> titanVertices = findEdgeInOutVerticesInNewGraph(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
- TitanOperationStatus getNotFoundErrorStatus() {
- return TitanOperationStatus.NOT_FOUND;
- }
-
-// private boolean removeMigratingUserStates() {
-// Either<UserData, TitanOperationStatus> migratingUser = genericDaoMigration.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.User), MIGRATING_USER_ID, UserData.class);
-// return migratingUser.either(user -> deleteAllEdges(user, Direction.OUT),
-// errorStatus -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_RETRIEVE_MIGRATION_USER.getMessage(MIGRATING_USER_ID, errorStatus.name())));
-// }
-
- private Either<List<Edge>, TitanOperationStatus> getEdgesForUsers(List<UserData> users) {
- List<Edge> edges = new ArrayList<>();
- for (UserData user : users) {
- Either<List<Edge>, TitanOperationStatus> edgesForNode = genericDao.getEdgesForNode(user, Direction.OUT);
- if (edgesForNode.isRight()) {
- TitanOperationStatus errorStatus = edgesForNode.right().value();
- LOGGER.error(MigrationMsg.FAILED_TO_RETRIEVE_USER_STATES.getMessage(user.getEmail(), errorStatus.name()));
- return Either.right(errorStatus);
- }
- edges.addAll(edgesForNode.left().value());
- }
- return Either.left(ignoreProductEdges(edges));
- }
-
- private List<Edge> ignoreProductEdges(List<Edge> edges) {
- return edges.stream().filter(edge -> !isInEdgeOfProductType(edge.inVertex())).collect(Collectors.toList());
- }
-
- private boolean isInEdgeOfProductType(Vertex inVertex) {
- Property<Object> nodeLabelProperty = inVertex.property(GraphPropertiesDictionary.LABEL.getProperty());
- return nodeLabelProperty != null && nodeLabelProperty.value().equals(NodeTypeEnum.Product.getName());
- }
-
- private String getVertexUniqueId(Vertex vertex) {
- String nodeLabel = vertex.property(GraphPropertiesDictionary.LABEL.getProperty()).value().toString();
- return UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.getByName(nodeLabel));
- }
-
- private Either<InOutVertices, TitanOperationStatus> findEdgeInOutVerticesInNewGraph(Edge userEdge) {
- Either<TitanVertex, TitanOperationStatus> outVertex = getMigratedVertexByOldVertex(userEdge.outVertex());
- Either<TitanVertex, TitanOperationStatus> inVertex = getMigratedVertexByOldVertex(userEdge.inVertex());
- return Either.sequenceLeft(list(outVertex, inVertex)).left().map(InOutVertices::new);
- }
-
- private Either<TitanVertex, TitanOperationStatus> getMigratedVertexByOldVertex(Vertex vertex) {
- 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 -> handleError(err, String.format("could not find vertex %s in new graph.", vertexUniqueId))) ;
- }
-
-// private boolean deleteAllEdges(UserData userData, Direction direction) {
-// Either<List<Edge>, TitanOperationStatus> edgesForNode = genericDaoMigration.getEdgesForNode(userData, direction);
-// if (edgesForNode.isRight()) {
-// LOGGER.error(MigrationMsg.FAILED_TO_RETRIEVE_MIGRATION_USER_STATES.getMessage(MIGRATING_USER_ID, edgesForNode.right().value().name()));
-// return false;
-// }
-// edgesForNode.left().value().forEach(Edge::remove);
-// return true;
-// }
-
- private class InOutVertices {
- private TitanVertex outVertex;
- private TitanVertex inVertex;
-
- InOutVertices(fj.data.List<TitanVertex> inOutVertices) {
- outVertex = inOutVertices.index(OUT_VERTEX_INDEX);
- inVertex = inOutVertices.index(IN_VERTEX_INDEX);
- }
-
- TitanVertex getOutVertex() {
- return outVertex;
- }
-
- 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
deleted file mode 100644
index 6e0a8a9247..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/UsersMigration.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import fj.data.Either;
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Resource;
-import java.util.List;
-
-import static org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils.handleError;
-
-public class UsersMigration extends JsonModelMigration<User> {
-
- private static Logger LOGGER = LoggerFactory.getLogger(UsersMigration.class);
-
- @Resource(name = "user-operation")
- IUserAdminOperation userAdminOperation;
-
- @Resource(name = "user-operation-migration")
- IUserAdminOperation userAdminOperationMigration;
-
-
- @Override
- Either<List<User>, ActionStatus> getElementsToMigrate() {
- LOGGER.debug("fetching users to migrate from old graph");
- return userAdminOperation.getAllUsers();
- }
-
- @Override
- Either<User, ActionStatus> getElementFromNewGraph(User user) {
- LOGGER.debug(String.format("trying to load user %s from new graph", user.getUserId()));
- return user.getStatus().equals(UserStatusEnum.ACTIVE) ? userAdminOperationMigration.getUserData(user.getUserId(), false) :
- userAdminOperationMigration.getInactiveUserData(user.getUserId());
- }
-
- @Override
- boolean save(User user) {
- LOGGER.debug(String.format("trying to save user %s to new graph", user.getUserId()));
- return userAdminOperationMigration.saveUserData(user)
- .either(savedUser -> true,
- err -> handleError(String.format("failed when saving user %s. error %s", user.getUserId(), err.name())));
- }
-
- @Override
- public ActionStatus getNotFoundErrorStatus() {
- return ActionStatus.USER_NOT_FOUND;
- }
-
- @Override
- public String description() {
- return "migrate users";
- }
-
-}
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
deleted file mode 100644
index 82d22addf3..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VFResourcesMigration.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import java.util.List;
-
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import fj.data.Either;
-
-public class VFResourcesMigration extends ComponentMigration<Resource> {
-
- private static Logger LOGGER = LoggerFactory.getLogger(VFResourcesMigration.class);
-
- @javax.annotation.Resource(name = "resource-operation")
- private IResourceOperation resourceOperation;
-
- @javax.annotation.Resource(name = "resource-version-migration")
- private VersionMigration<Resource> versionMigration;
-
- @Override
- public String description() {
- return "migrate VFs";
- }
-
- @Override
- Either<List<Resource>, ?> getElementsToMigrate() {
- return resourceOperation.getVFResources();
- }
-
- @Override
- boolean save(Resource element) {
- requirementsCapabilitiesMigrationService.overrideInstanceCapabilitiesRequirements(element);
- return super.save(element);
- }
-
- @Override
- boolean doPostSaveOperation(Resource element) {
- return element.getComponentInstances() == null ||
- (requirementsCapabilitiesMigrationService.associateFulfilledRequirements(element, NodeTypeEnum.Resource) &&
- requirementsCapabilitiesMigrationService.associateFulfilledCapabilities(element, NodeTypeEnum.Resource));
- }
-
- @Override
- boolean doPostMigrateOperation(List<Resource> elements) {
- LOGGER.info("migrating VFs versions");
- return versionMigration.buildComponentsVersionChain(elements);
- }
-
- @Override
- void doPreMigrationOperation(List<Resource> elements) {
- super.doPreMigrationOperation(elements);
- setMissingTemplateInfo(elements);
- }
-
-
-}
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
deleted file mode 100644
index 514760fba2..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/VersionMigration.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
-
-import fj.data.Either;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-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;
-import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
-import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
-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.impl.UniqueIdBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Resource;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-public abstract class VersionMigration<T extends Component> {
-
- private static Logger LOGGER = LoggerFactory.getLogger(VersionMigration.class);
-
- @Resource(name = "titan-generic-dao-migration")
- private TitanGenericDao titanGenericDaoMigration;
-
- @Resource(name = "titan-dao")
- private TitanDao titanDao;
-
- public boolean buildComponentsVersionChain(List<T> components) {
- 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) {
- titanDao.rollback();
- return false;
- }
- titanDao.commit();
- }
- return true;
- }
-
- private boolean buildVersionChainForInvariant(List<T> components) {
- sortComponentsByVersion(components);
- for (int i = 0; i < components.size() -1; i++) {
- String lowerVersionUid = components.get(i).getUniqueId();
- String higherVersionUid = components.get(i + 1).getUniqueId();
- boolean versionCreated = createVersionRelationIfNotExist(lowerVersionUid, higherVersionUid);
- if (!versionCreated) {
- return false;
- }
- }
- return true;
- }
-
- private void sortComponentsByVersion(List<T> components) {
- Collections.sort(components, (o1, o2) -> Double.valueOf(o1.getVersion()).compareTo(Double.valueOf(o2.getVersion())));
- }
-
- private boolean createVersionRelationIfNotExist(String fromUid, String toUid) {
- Either<Boolean, TitanOperationStatus> isVersionExists = isVersionExists(fromUid, toUid);
- return isVersionExists.either(versionExists -> versionExists || createVersionRelation(fromUid, toUid),
- errorStatus -> MigrationUtils.handleError(MigrationMsg.FAILED_TO_RETRIEVE_VERSION_RELATION.getMessage(fromUid, toUid, isVersionExists.right().value().name())));
- }
-
- 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> 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));
- }
-
- private Either<Boolean, TitanOperationStatus> isVersionExists(String fromUid, String toUid) {
- LOGGER.debug(String.format("checking if version edge between vertex %s and vertex %s already exist", fromUid, toUid));
- String uidKey = UniqueIdBuilder.getKeyByNodeType(getNodeTypeEnum());
- Either<Edge, TitanOperationStatus> edgeByVertices = titanGenericDaoMigration.getEdgeByVerticies(uidKey, fromUid, uidKey, toUid, EdgeLabelEnum.VERSION.name());
- if (isNotFoundStatus(edgeByVertices)) {
- return Either.left(false);
- }
- return edgeByVertices.bimap(foundEdge -> true,
- error -> error);
- }
-
- private boolean isNotFoundStatus(Either<Edge, TitanOperationStatus> edgeByVertices) {
- return edgeByVertices.isRight() && edgeByVertices.right().value() == TitanOperationStatus.NOT_FOUND;
- }
-
- abstract NodeTypeEnum getNodeTypeEnum();
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledCapabilitiesMigrationService.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledCapabilitiesMigrationService.java
deleted file mode 100644
index 23b1afec93..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledCapabilitiesMigrationService.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations;
-
-import fj.data.Either;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-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.CapabilityDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.MapListCapabiltyDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.operations.api.ICapabilityOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation;
-import org.openecomp.sdc.be.resources.data.CapabilityData;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-public class FulfilledCapabilitiesMigrationService extends FulfilledCapabilityRequirementMigrationService<CapabilityDefinition, CapabilityData> {
-
- @Resource(name = "capability-operation")
- private ICapabilityOperation capabilityOperation;
-
- @Resource(name = "component-instance-operation")
- private ComponentInstanceOperation componentInstanceOperation;
-
- @Override
- Either<CapabilityDefinition, StorageOperationStatus> getToscaDefinition(CapabilityData data) {
- return capabilityOperation.getCapability(data.getUniqueId());
- }
-
- @Override
- void setPath(CapabilityDefinition def, List<String> path) {
- def.setPath(path);
- }
-
- @Override
- String getType(CapabilityDefinition def) {
- return def.getType();
- }
-
- @Override
- Either<List<ImmutablePair<CapabilityData, GraphEdge>>, TitanOperationStatus> getFulfilledCapReqs(ComponentInstance instance, NodeTypeEnum nodeTypeEnum) {
- return componentInstanceOperation.getFulfilledCapabilities(instance, nodeTypeEnum);
- }
-
- @Override
- ListDataDefinition convertToDefinitionListObject(List<CapabilityDefinition> capReqDefList) {
- List<CapabilityDataDefinition> capabilityDataDefinitions = new ArrayList<>();
- capabilityDataDefinitions.addAll(capReqDefList);
- return new ListCapabilityDataDefinition(capabilityDataDefinitions);
- }
-
- @Override
- MapDataDefinition convertToDefinitionMapObject(Map<String, ListDataDefinition> reqCapForInstance) {
- Map<String, ListCapabilityDataDefinition> capabilitiesList = castDataDefinitionListToCapabilityList(reqCapForInstance);
- return new MapListCapabiltyDataDefinition(capabilitiesList);
- }
-
- @Override
- Either<GraphVertex, TitanOperationStatus> getAssociatedDefinitions(GraphVertex component) {
- return titanDao.getChildVertex(component, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, JsonParseFlagEnum.NoParse);
- }
-
- @Override
- Either<GraphVertex, StorageOperationStatus> associateToGraph(GraphVertex graphVertex, Map<String, MapDataDefinition> defsByInstance) {
- return topologyTemplateOperation.assosiateElementToData(graphVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, defsByInstance);
- }
-
- private Map<String, ListCapabilityDataDefinition> castDataDefinitionListToCapabilityList(Map<String, ListDataDefinition> reqCapForInstance) {
- return reqCapForInstance.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> (ListCapabilityDataDefinition) entry.getValue()));
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledCapabilityRequirementMigrationService.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledCapabilityRequirementMigrationService.java
deleted file mode 100644
index 33b5574408..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledCapabilityRequirementMigrationService.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations;
-
-import fj.Function;
-import fj.data.Either;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.asdctool.impl.migration.MigrationException;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
-import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.api.ToscaDefinitionPathCalculator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Resource;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import static org.openecomp.sdc.asdctool.impl.migration.MigrationMsg.*;
-import static org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils.willThrowException;
-
-public abstract class FulfilledCapabilityRequirementMigrationService<T extends ToscaDataDefinition, S extends GraphNode> {
-
- private static Logger LOGGER = LoggerFactory.getLogger(FulfilledCapabilityRequirementMigrationService.class);
-
- @Resource(name = "topology-template-operation")
- TopologyTemplateOperation topologyTemplateOperation;
-
- @Resource(name = "tosca-path-calculator")
- private ToscaDefinitionPathCalculator toscaDefinitionPathCalculator;
-
- @Resource(name = "titan-dao")
- TitanDao titanDao;
-
- public boolean associateToscaDefinitions(Component component, NodeTypeEnum componentType) {
- try {
- return isDefinitionsAlreadyAssociated(component) || doAssociateToscaDefinitions(component, componentType);
- } catch (MigrationException e) {
- LOGGER.error(e.getMessage(), e);
- return false;
- }
- }
-
- private boolean isDefinitionsAlreadyAssociated(Component component) {
- GraphVertex componentVertex = titanDao.getVertexById(component.getUniqueId()).left().on((err) -> willThrowException(FAILED_TO_RETRIEVE_VERTEX.getMessage(component.getName(), err.name())));
- return this.getAssociatedDefinitions(componentVertex)
- .either(vertex -> true,
- errorStatus -> notFoundStatusOrFail(component, errorStatus));
-
- }
-
- private boolean notFoundStatusOrFail(Component component, TitanOperationStatus error) {
- if (error.equals(TitanOperationStatus.NOT_FOUND)) {
- return false;
- }
- throw new MigrationException(FAILED_TO_RETRIEVE_CAP_REQ_VERTEX.getMessage(component.getName(), error.name()));
- }
-
- private boolean doAssociateToscaDefinitions(Component component, NodeTypeEnum componentType) {
- try {
- Map<String, MapDataDefinition> toscaDefByInstance = groupToscaDefinitionByInstance(component, componentType);
- return toscaDefByInstance.isEmpty() || updateOnGraph(component, toscaDefByInstance);
- } catch (MigrationException e) {
- LOGGER.error(e.getMessage(), e);
- return false;
- }
- }
-
- private Map<String, MapDataDefinition> groupToscaDefinitionByInstance(Component component, NodeTypeEnum componentType) {
- Map<String, MapDataDefinition> toscaDefByInstance = new HashMap<>();
- for (ComponentInstance componentInstance : component.getComponentInstances()) {
- List<ImmutablePair<S, GraphEdge>> fulfilledCapReq = getFulfilledCapReqs(componentType, componentInstance);
- if (fulfilledCapReq.isEmpty()) {
- continue;
- }
- toscaDefByInstance.put(componentInstance.getUniqueId(), getReqCapToscaDefs(fulfilledCapReq, componentInstance));
- }
- return toscaDefByInstance;
- }
-
- private MapDataDefinition getReqCapToscaDefs(List<ImmutablePair<S, GraphEdge>> capReqsData, ComponentInstance componentInstance) {
- Map<String, List<T>> capReqDefinitions = getCapReqDefinitions(componentInstance, capReqsData);
- return convertToMapDefinition(capReqDefinitions);
- }
-
- private List<ImmutablePair<S, GraphEdge>> getFulfilledCapReqs(NodeTypeEnum componentType, ComponentInstance componentInstance) {
- return getFulfilledCapReqs(componentInstance, componentType)
- .either(Function.identity(),
- error -> emptyListOrFail(error, componentInstance.getName()));
- }
-
- private List<ImmutablePair<S, GraphEdge>> emptyListOrFail(TitanOperationStatus error, String instanceName) {
- if (error.equals(TitanOperationStatus.NOT_FOUND)) {
- return Collections.emptyList();
- }
- String errorMsg = FAILED_TO_RETRIEVE_REQ_CAP.getMessage(instanceName, error.name());
- throw new MigrationException(errorMsg);
- }
-
- private Map<String, List<T>> getCapReqDefinitions(ComponentInstance componentInstance, List<ImmutablePair<S, GraphEdge>> capReqDataList) {
- return capReqDataList.stream()
- .map(capReqData -> convertToToscaDef(componentInstance, capReqData))
- .collect(Collectors.groupingBy(this::getType));
- }
-
- private T convertToToscaDef(ComponentInstance componentInstance, ImmutablePair<S, GraphEdge> data) {
- T def = getReqCapDataDefinition(data);
- List<String> definitionPath = toscaDefinitionPathCalculator.calculateToscaDefinitionPath(componentInstance, data.getRight());
- setPath(def, definitionPath);
- return def;
- }
-
- private T getReqCapDataDefinition(ImmutablePair<S, GraphEdge> data) {
- S capReqData = data.getLeft();
- return getToscaDefinition(capReqData).left().on(err -> willThrowException(FAILED_TO_RETRIEVE_TOSCA_DEF.getMessage(capReqData.getUniqueId().toString(), err.toString())));
- }
-
- private boolean updateOnGraph(Component component, Map<String, MapDataDefinition> defsByInstance) {
- GraphVertex graphVertex = getComponentGraphVertex(component);
- Either<GraphVertex, StorageOperationStatus> associatedVertex = associateToGraph(graphVertex, defsByInstance);
- return associatedVertex.either(vertex -> true, err -> MigrationUtils.handleError(FAILED_TO_ASSOCIATE_CAP_REQ.getMessage(component.getName(), err.name())));
- }
-
- private GraphVertex getComponentGraphVertex(Component component) {
- return titanDao.getVertexById(component.getUniqueId())
- .left().on(error -> willThrowException(FAILED_TO_RETRIEVE_VERTEX.getMessage(component.getUniqueId(), error.name())));
- }
-
- private MapDataDefinition convertToMapDefinition(Map<String, List<T>> toscaDefs) {
- Map<String, ListDataDefinition> defsListByType = toscaDefs.entrySet().stream()
- .collect(Collectors.toMap(Map.Entry::getKey, entry -> convertToDefinitionListObject(entry.getValue())));
- return convertToDefinitionMapObject(defsListByType);
- }
-
- abstract Either<T, ?> getToscaDefinition(S data);
-
- abstract void setPath(T def, List<String> path);
-
- abstract String getType(T def);
-
- abstract Either<List<ImmutablePair<S, GraphEdge>>, TitanOperationStatus> getFulfilledCapReqs(ComponentInstance instance, NodeTypeEnum nodeTypeEnum);
-
- abstract ListDataDefinition convertToDefinitionListObject(List<T> capReqDefList);
-
- abstract MapDataDefinition convertToDefinitionMapObject(Map<String, ListDataDefinition> reqCapForInstance);
-
- abstract Either<GraphVertex, TitanOperationStatus> getAssociatedDefinitions(GraphVertex component);
-
- abstract Either<GraphVertex, StorageOperationStatus> associateToGraph(GraphVertex graphVertex, Map<String, MapDataDefinition> defsByInstance);
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledRequirementsMigrationService.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledRequirementsMigrationService.java
deleted file mode 100644
index 2b720af751..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/FulfilledRequirementsMigrationService.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations;
-
-import fj.data.Either;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
-import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-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.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.RequirementDefinition;
-import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
-import org.openecomp.sdc.be.model.operations.api.IRequirementOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.resources.data.RequirementData;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-public class FulfilledRequirementsMigrationService extends FulfilledCapabilityRequirementMigrationService<RequirementDefinition, RequirementData> {
-
- @Resource(name = "requirement-operation")
- IRequirementOperation requirementOperation;
-
- @Resource(name = "component-instance-operation")
- IComponentInstanceOperation componentInstanceOperation;
-
- @Override
- Either<RequirementDefinition, TitanOperationStatus> getToscaDefinition(RequirementData data) {
- return requirementOperation.getRequirement(data.getUniqueId());
- }
-
- @Override
- void setPath(RequirementDefinition def, List<String> path) {
- def.setPath(path);
- }
-
- @Override
- String getType(RequirementDefinition def) {
- return def.getCapability();
- }
-
- @Override
- Either<List<ImmutablePair<RequirementData, GraphEdge>>, TitanOperationStatus> getFulfilledCapReqs(ComponentInstance instance, NodeTypeEnum nodeTypeEnum) {
- return componentInstanceOperation.getFulfilledRequirements(instance, nodeTypeEnum);
- }
-
- @Override
- ListDataDefinition convertToDefinitionListObject(List<RequirementDefinition> capReqDefList) {
- List<RequirementDataDefinition> requirementDataDefinitions = new ArrayList<>();
- requirementDataDefinitions.addAll(capReqDefList);
- return new ListRequirementDataDefinition(requirementDataDefinitions);
- }
-
- @Override
- MapDataDefinition convertToDefinitionMapObject(Map<String, ListDataDefinition> reqCapForInstance) {
- Map<String, ListRequirementDataDefinition> reqDefList = castDefinitionListToRequirementList(reqCapForInstance);
- return new MapListRequirementDataDefinition(reqDefList);
- }
-
- @Override
- Either<GraphVertex, TitanOperationStatus> getAssociatedDefinitions(GraphVertex component) {
- return titanDao.getChildVertex(component, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, JsonParseFlagEnum.NoParse);
- }
-
- @Override
- Either<GraphVertex, StorageOperationStatus> associateToGraph(GraphVertex graphVertex, Map<String, MapDataDefinition> defsByInstance) {
- return topologyTemplateOperation.assosiateElementToData(graphVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, defsByInstance);
- }
-
- private Map<String, ListRequirementDataDefinition> castDefinitionListToRequirementList(Map<String, ListDataDefinition> reqCapForInstance) {
- return reqCapForInstance.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> (ListRequirementDataDefinition) entry.getValue()));
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/RequirementsCapabilitiesMigrationService.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/RequirementsCapabilitiesMigrationService.java
deleted file mode 100644
index e468dd2fc5..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/migration/v1707/jsonmodel/relations/RequirementsCapabilitiesMigrationService.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel.relations;
-
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.RequirementDefinition;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
-public class RequirementsCapabilitiesMigrationService<T extends Component> {
-
- @Resource(name = "fulfilled-capabilities-mig-service")
- FulfilledCapabilitiesMigrationService fulfilledCapabilityUpdate;
-
- @Resource(name = "fulfilled-requirements-mig-service")
- FulfilledRequirementsMigrationService fulfilledRequirementUpdate;
-
- public boolean associateFulfilledCapabilities(T component, NodeTypeEnum nodeType) {
- return fulfilledCapabilityUpdate.associateToscaDefinitions(component, nodeType);
- }
-
- public boolean associateFulfilledRequirements(T component, NodeTypeEnum nodeType) {
- return fulfilledRequirementUpdate.associateToscaDefinitions(component, nodeType);
- }
-
- public void overrideInstanceCapabilitiesRequirements(T element) {
- if (element.getComponentInstances() != null) {
- clearInstancesCapabilitiesRequirements(element);
- setInstancesRequirementsFromComponent(element);
- setInstancesCapabilitiesFromComponent(element);
- }
- }
-
- private void clearInstancesCapabilitiesRequirements(T element) {
- element.getComponentInstances().forEach(componentInstance -> {
- if (componentInstance.getCapabilities() != null) {
- componentInstance.getCapabilities().clear();
- }
- if (componentInstance.getRequirements() != null) {
- componentInstance.getRequirements().clear();
- }
- });
- }
-
- private void setInstancesCapabilitiesFromComponent(T element) {
- if (element.getCapabilities() != null) {
- Map<String, ComponentInstance> instancesById = groupInstancesById(element);
- element.getCapabilities().forEach((type, definitions) -> { setCapabilitiesOnInstance(instancesById, type, definitions);});
- }
- }
-
- private void setInstancesRequirementsFromComponent(T element) {
- if (element.getRequirements() != null) {
- Map<String, ComponentInstance> instancesById = groupInstancesById(element);
- element.getRequirements().forEach((type, requirements) -> { setRequirementsOnInstance(instancesById, type, requirements);});
- }
- }
-
- private void setCapabilitiesOnInstance(Map<String, ComponentInstance> instances, String capabilityType, List<CapabilityDefinition> definitions) {
- Map<String, List<CapabilityDefinition>> capByInstance = definitions.stream().collect(Collectors.groupingBy(CapabilityDefinition::getOwnerId));
- capByInstance.forEach((instanceId, capabilityDefinitions) -> { setCapabilitiesOnInstanceByType(instances.get(instanceId), capabilityType, capabilityDefinitions); });
- }
-
- private void setRequirementsOnInstance(Map<String, ComponentInstance> instances, String requirementType, List<RequirementDefinition> requirements) {
- Map<String, List<RequirementDefinition>> reqByInstance = requirements.stream().collect(Collectors.groupingBy(RequirementDefinition::getOwnerId));
- reqByInstance.forEach((instanceId, reqDefinitions) -> { setRequirementsOnInstanceByType(instances.get(instanceId), requirementType, reqDefinitions);});
- }
-
- private void setCapabilitiesOnInstanceByType(ComponentInstance instance, String capabilityType, List<CapabilityDefinition> capabilityDefinitions) {
- instance.getCapabilities().putIfAbsent(capabilityType, new ArrayList<>());
- instance.getCapabilities().get(capabilityType).addAll(capabilityDefinitions);
- }
-
- private void setRequirementsOnInstanceByType(ComponentInstance instance, String requirementType, List<RequirementDefinition> reqDefinitions) {
- instance.getRequirements().putIfAbsent(requirementType, new ArrayList<>());
- instance.getRequirements().get(requirementType).addAll(reqDefinitions);
- }
-
- private Map<String, ComponentInstance> groupInstancesById(T element) {
- return element.getComponentInstances()
- .stream()
- .collect(Collectors.toMap(ComponentInstance::getUniqueId, Function.identity()));
- }
-
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java
index facb9d70f2..79b36f0004 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java
@@ -16,12 +16,22 @@ public class ValidationConfigManager {
return outputFilePath;
}
- public static void setOutputFilePath(String outputFilePath) {
- ValidationConfigManager.outputFilePath = outputFilePath;
+ public static void setOutputFilePath(String outputPath) {
+ ValidationConfigManager.outputFilePath = outputPath+ "/reportOutput.txt";
}
private static String outputFilePath;
+ public static String getCsvReportFilePath() {
+ return csvReportFilePath;
+ }
+
+ public static void setCsvReportFilePath(String outputPath) {
+ ValidationConfigManager.csvReportFilePath = outputPath +"/csvSummary_"+System.currentTimeMillis()+".csv";
+ }
+
+ private static String csvReportFilePath = "summary.csv";
+
public static Properties setValidationConfiguration(String path){
InputStream input = null;
try {
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java
index 038134bbfe..80e80ab472 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java
@@ -1,6 +1,5 @@
package org.openecomp.sdc.asdctool.impl.validator.config;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationTitanStrategy;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ArtifactValidationUtils;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ServiceArtifactValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.VfArtifactValidationTask;
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java
index 84d881c168..15f25738c0 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java
@@ -3,6 +3,7 @@ package org.openecomp.sdc.asdctool.impl.validator.executers;
import fj.data.Either;
import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
+import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
@@ -29,9 +30,6 @@ public class TopologyTemplateValidatorExecuter {
protected TitanDao titanDao;
@Autowired
- protected ToscaOperationFacade toscaOperationFacade;
-
- @Autowired
protected TopologyTemplateOperation topologyTemplateOperation;
protected String name;
@@ -44,10 +42,6 @@ public class TopologyTemplateValidatorExecuter {
return name;
}
- public void reportValidateTaskStatus(TopologyTemplateValidationTask validationTask, boolean success, GraphVertex vertexScanned) {
- ReportManager.reportValidationTaskStatus(vertexScanned, validationTask.getTaskName(), validationTask.getTaskResultStatus(), success);
- }
-
protected List<GraphVertex> getVerticesToValidate(ComponentTypeEnum type) {
Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
props.put(GraphPropertyEnum.COMPONENT_TYPE, type.name());
@@ -58,7 +52,7 @@ public class TopologyTemplateValidatorExecuter {
Either<List<GraphVertex>, TitanOperationStatus> results = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props);
if (results.isRight()) {
System.out.println("getVerticesToValidate failed "+ results.right().value());
- return new ArrayList<GraphVertex>();
+ return new ArrayList<>();
}
System.out.println("getVerticesToValidate: "+results.left().value().size()+" vertices to scan");
return results.left().value();
@@ -71,20 +65,22 @@ public class TopologyTemplateValidatorExecuter {
boolean successAllVertices = true;
int vertexNum = 0;
int verticesSize = vertices.size();
+
for (GraphVertex vertex: vertices) {
vertexNum++;
boolean successAllTasks = true;
for (TopologyTemplateValidationTask task: tasks) {
ReportManager.reportStartTaskRun(vertex, task.getTaskName());
- boolean success = task.validate(vertex);
- if (!success) {
+ VertexResult result = task.validate(vertex);
+ if (!result.getStatus()) {
failedTasks.add(task.getTaskName());
successAllVertices = false;
successAllTasks = false;
} else if (successAllTasks && vertexNum == verticesSize) {
successTasks.add(task.getTaskName());
}
- reportValidateTaskStatus(task, success, vertex);
+ ReportManager.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus());
+ ReportManager.reportTaskEnd(vertex.getUniqueId(), task.getTaskName(), result);
}
String componentScanStatus = successAllTasks? "success" : "failed";
System.out.println("Topology Template "+vertex.getUniqueId()+" Validation finished with "+componentScanStatus);
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java
index 6ca012546b..d73b197ac7 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java
@@ -1,12 +1,13 @@
package org.openecomp.sdc.asdctool.impl.validator.tasks;
+import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
/**
* Created by chaya on 7/5/2017.
*/
public interface TopologyTemplateValidationTask {
- boolean validate(GraphVertex vertex);
+ VertexResult validate(GraphVertex vertex);
String getTaskName();
String getTaskResultStatus();
void setTaskResultStatus(String status);
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java
index dd79943885..faccd647c2 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java
@@ -27,21 +27,21 @@ public class ArtifactValidationUtils {
@Autowired
private TopologyTemplateOperation topologyTemplateOperation;
- public boolean validateArtifactsAreInCassandra(GraphVertex vertex, String taskName, List<ArtifactDataDefinition> artifacts) {
- boolean allArtifactsExist = true;
+ public ArtifactsVertexResult validateArtifactsAreInCassandra(GraphVertex vertex, String taskName, List<ArtifactDataDefinition> artifacts) {
+ ArtifactsVertexResult result = new ArtifactsVertexResult(true);
for(ArtifactDataDefinition artifact:artifacts) {
boolean isArtifactExist = isArtifcatInCassandra(artifact.getEsId());
String status = isArtifactExist ? "Artifact " + artifact.getEsId() + " is in Cassandra" :
"Artifact " + artifact.getEsId() + " doesn't exist in Cassandra";
- if (!isArtifactExist) {
- ReportManager.addFailedVertex(taskName, vertex.getUniqueId());
- }
+
ReportManager.writeReportLineToFile(status);
if (!isArtifactExist) {
- allArtifactsExist = false;
+ ReportManager.addFailedVertex(taskName, vertex.getUniqueId());
+ result.setStatus(false);
+ result.addNotFoundArtifact(artifact.getUniqueId());
}
}
- return allArtifactsExist;
+ return result;
}
public boolean isArtifcatInCassandra(String uniueId) {
@@ -54,7 +54,6 @@ public class ArtifactValidationUtils {
}
Long count = countOfArtifactsEither.left().value();
if (count <1) {
- //System.out.print("Artifact "+uniueId+" count is: "+count);
return false;
}
return true;
@@ -70,14 +69,16 @@ public class ArtifactValidationUtils {
return artifacts;
}
- public boolean validateTopologyTemplateArtifacts(GraphVertex vertex, String taskName) {
+ public ArtifactsVertexResult validateTopologyTemplateArtifacts(GraphVertex vertex, String taskName) {
+ ArtifactsVertexResult result = new ArtifactsVertexResult();
ComponentParametersView paramView = new ComponentParametersView();
paramView.disableAll();
paramView.setIgnoreArtifacts(false);
paramView.setIgnoreComponentInstances(false);
Either<ToscaElement, StorageOperationStatus> toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView);
if (toscaElementEither.isRight()) {
- return false;
+ result.setStatus(false);
+ return result;
}
TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value();
Map<String, ArtifactDataDefinition> deploymentArtifacts = element.getDeploymentArtifacts();
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactsVertexResult.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactsVertexResult.java
new file mode 100644
index 0000000000..c010148644
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactsVertexResult.java
@@ -0,0 +1,30 @@
+package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts;
+
+import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Created by chaya on 7/25/2017.
+ */
+public class ArtifactsVertexResult extends VertexResult{
+ Set<String> notFoundArtifacts = new HashSet<>();
+
+ public ArtifactsVertexResult() {
+
+ }
+
+ public ArtifactsVertexResult(boolean status) {
+ super(status);
+ }
+
+ public void addNotFoundArtifact(String artifactId) {
+ notFoundArtifacts.add(artifactId);
+ }
+
+ @Override
+ public String getResult() {
+ return notFoundArtifacts.toString();
+ }
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java
index 410691fb47..0a224f8d84 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java
@@ -20,7 +20,7 @@ public class ServiceArtifactValidationTask extends ServiceValidationTask {
}
@Override
- public boolean validate(GraphVertex vertex) {
+ public ArtifactsVertexResult validate(GraphVertex vertex) {
return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName());
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java
index 01bc26fe2b..bb25d25e2b 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts;
import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask;
+import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
import org.springframework.beans.factory.annotation.Autowired;
@@ -18,11 +19,11 @@ public class VfArtifactValidationTask extends VfValidationTask {
protected TopologyTemplateOperation topologyTemplateOperation;
public VfArtifactValidationTask() {
- this.name = "Artifact Validation Task";
+ this.name = "VF Artifact Validation Task";
}
@Override
- public boolean validate(GraphVertex vertex) {
+ public VertexResult validate(GraphVertex vertex) {
return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName());
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java
index f8de1d3264..187359f127 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java
@@ -4,10 +4,12 @@ import fj.data.Either;
import org.apache.cassandra.cql3.CQL3Type;
import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
+import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
@@ -32,7 +34,11 @@ public class ModuleJsonTask extends ServiceValidationTask {
}
@Override
- public boolean validate(GraphVertex vertex) {
+ public VertexResult validate(GraphVertex vertex) {
+ if (!isAfterSubmitForTesting(vertex)) {
+ return new VertexResult(true);
+ }
+
ComponentParametersView paramView = new ComponentParametersView();
paramView.disableAll();
paramView.setIgnoreArtifacts(false);
@@ -40,23 +46,20 @@ public class ModuleJsonTask extends ServiceValidationTask {
paramView.setIgnoreComponentInstances(false);
Either<ToscaElement, StorageOperationStatus> toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView);
if (toscaElementEither.isRight()) {
- return false;
+ return new VertexResult(false);
}
TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value();
- if (!isAfterSubmitForTesting(element)) {
- return true;
- }
Map<String, MapGroupsDataDefinition> instGroups = element.getInstGroups();
Map<String, MapArtifactDataDefinition> instDeploymentArtifacts = element.getInstDeploymentArtifacts();
for (Map.Entry<String, MapGroupsDataDefinition> pair : Optional.ofNullable(instGroups).orElse(Collections.emptyMap()).entrySet()) {
MapGroupsDataDefinition groups = pair.getValue();
if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) {
- return findCoordinateModuleJson(pair, instDeploymentArtifacts, vertex);
+ return new VertexResult(findCoordinateModuleJson(pair, instDeploymentArtifacts, vertex));
}
- return true;
+ return new VertexResult(true);
}
- return true;
+ return new VertexResult(true);
}
private boolean findCoordinateModuleJson(Map.Entry<String, MapGroupsDataDefinition> pair, Map<String, MapArtifactDataDefinition> instDeploymentArtifacts, GraphVertex vertex) {
@@ -84,9 +87,9 @@ public class ModuleJsonTask extends ServiceValidationTask {
return false;
}
- private boolean isAfterSubmitForTesting(TopologyTemplate element){
- List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.READY_FOR_CERTIFICATION,
- LifecycleStateEnum.CERTIFICATION_IN_PROGRESS, LifecycleStateEnum.CERTIFIED));
- return allowedStates.contains(element.getLifecycleState());
+ private boolean isAfterSubmitForTesting(GraphVertex vertex){
+ List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.READY_FOR_CERTIFICATION.name(),
+ LifecycleStateEnum.CERTIFICATION_IN_PROGRESS.name(), LifecycleStateEnum.CERTIFIED.name()));
+ return allowedStates.contains(vertex.getMetadataProperty(GraphPropertyEnum.STATE));
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
index 116883967a..64bea12957 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
@@ -1,7 +1,6 @@
package org.openecomp.sdc.asdctool.impl.validator.utils;
import org.apache.commons.lang.text.StrBuilder;
-import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
@@ -16,23 +15,42 @@ import java.util.*;
*/
public class ReportManager {
- private static List<ValidationTaskResult> taskResults;
private static String reportOutputFilePath;
+ private static String csvReportFilePath;
private static Map<String, Set<String>> failedVerticesPerTask = new HashMap<>();
+ private static Map<String, Map<String, VertexResult>> resultsPerVertex = new HashMap<>();
public ReportManager() {
try {
- taskResults = new ArrayList<>();
- // open file for first time
- reportOutputFilePath = ValidationConfigManager.getOutputFilePath();
- StrBuilder sb = new StrBuilder();
- sb.appendln("-----------------------Validation Tool Results:-------------------------");
- Files.write(Paths.get(reportOutputFilePath), sb.toString().getBytes());
+ initCsvFile();
+ initReportFile();
} catch (IOException e) {
e.printStackTrace();
}
}
+ private void initReportFile() throws IOException {
+ reportOutputFilePath = ValidationConfigManager.getOutputFilePath();
+ StrBuilder sb = new StrBuilder();
+ sb.appendln("-----------------------Validation Tool Results:-------------------------");
+ Files.write(Paths.get(reportOutputFilePath), sb.toString().getBytes());
+ }
+
+ private void initCsvFile() throws IOException {
+ csvReportFilePath = ValidationConfigManager.getCsvReportFilePath();
+ StrBuilder sb = new StrBuilder();
+ sb.append("Vertex ID,"+"Task Name,"+"Success,"+"Result Details"+","+"Result Description");
+ sb.appendNewLine();
+ Files.write(Paths.get(csvReportFilePath), sb.toString().getBytes());
+ }
+
+ public static void reportTaskEnd(String vertexId, String taskName, VertexResult result) {
+ Map<String, VertexResult> vertexTasksResults =
+ Optional.ofNullable(resultsPerVertex.get(vertexId)).orElse(new HashMap<>());
+ vertexTasksResults.put(taskName, result);
+ resultsPerVertex.put(vertexId, vertexTasksResults);
+ }
+
public static void addFailedVertex (String taskName, String vertexId) {
Set<String> failedVertices = failedVerticesPerTask.get(taskName);
if (failedVertices == null) {
@@ -42,12 +60,7 @@ public class ReportManager {
failedVerticesPerTask.put(taskName, failedVertices);
}
- public static void reportValidationTaskStatus(GraphVertex vertexScanned, String taskName, String taskResultMessage, boolean success) {
- taskResults.add(new ValidationTaskResult(vertexScanned, taskName, taskResultMessage, success));
- printValidationTaskStatus(vertexScanned, taskName, success);
- }
-
- private static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success) {
+ public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success) {
String successStatus = success ? "success" : "failed";
String line = "-----------------------Vertex: "+vertexScanned.getUniqueId()+", Task " + taskName + " " +successStatus+"-----------------------";
StrBuilder sb = new StrBuilder();
@@ -57,16 +70,6 @@ public class ReportManager {
writeReportLineToFile(line);
}
- public static void reportValidationTaskSummary(TopologyTemplateValidationTask task, int numOfFailedComponents, int numOfSuccessComponents) {
- StrBuilder sb = new StrBuilder();
- sb.appendNewLine();
- sb.appendln("-----------------------Task " + task.getTaskName() + " Validation Summary-----------------------");
- sb.appendln("Num of failed components: "+ numOfFailedComponents);
- sb.appendln("Num of success components: "+ numOfSuccessComponents);
- sb.appendln("Total components scanned: " + numOfFailedComponents+numOfSuccessComponents);
- writeReportLineToFile(sb.toString());
- }
-
public static void writeReportLineToFile(String message) {
try {
Files.write(Paths.get(reportOutputFilePath), new StrBuilder().appendNewLine().toString().getBytes(), StandardOpenOption.APPEND);
@@ -110,5 +113,20 @@ public class ReportManager {
sb.appendNewLine();
});
writeReportLineToFile(sb.toString());
+ printAllResults();
+ }
+
+ public static void printAllResults() {
+ resultsPerVertex.forEach((vertex, tasksResults)->{
+ tasksResults.forEach((task, result) -> {
+ try {
+ String resultLine = vertex +","+task+","+result.getStatus()+","+result.getResult();
+ Files.write(Paths.get(csvReportFilePath), resultLine.getBytes(), StandardOpenOption.APPEND);
+ Files.write(Paths.get(csvReportFilePath), new StrBuilder().appendNewLine().toString().getBytes(), StandardOpenOption.APPEND);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+ });
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/VertexResult.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/VertexResult.java
new file mode 100644
index 0000000000..4fe8ec30f5
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/VertexResult.java
@@ -0,0 +1,30 @@
+package org.openecomp.sdc.asdctool.impl.validator.utils;
+
+/**
+ * Created by chaya on 7/25/2017.
+ */
+public class VertexResult {
+
+ boolean status;
+
+ public VertexResult() {
+
+ }
+
+ public VertexResult(boolean status) {
+ this.status = status;
+ }
+
+ public boolean getStatus() {
+ return status;
+ }
+
+ public void setStatus(boolean status) {
+ this.status = status;
+ }
+
+ public String getResult() {
+ return String.valueOf(status);
+ }
+
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/EsToCassandraDataMigrationMenu.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/EsToCassandraDataMigrationMenu.java
index b82b62b551..d563f2cf33 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/EsToCassandraDataMigrationMenu.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/EsToCassandraDataMigrationMenu.java
@@ -32,7 +32,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
public class EsToCassandraDataMigrationMenu {
- private static Logger log = LoggerFactory.getLogger(MigrationMenu.class.getName());
+ private static Logger log = LoggerFactory.getLogger(EsToCassandraDataMigrationMenu.class.getName());
public static void main(String[] args) throws Exception {
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
deleted file mode 100644
index 600ebf848a..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/MigrationMenu.java
+++ /dev/null
@@ -1,345 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.asdctool.main;
-
-import java.util.Arrays;
-import java.util.Optional;
-
-import org.openecomp.sdc.asdctool.impl.PopulateComponentCache;
-import org.openecomp.sdc.asdctool.impl.migration.v1604.AppConfig;
-import org.openecomp.sdc.asdctool.impl.migration.v1604.DerivedFromAlignment;
-import org.openecomp.sdc.asdctool.impl.migration.v1604.GroupsAlignment;
-import org.openecomp.sdc.asdctool.impl.migration.v1604.ServiceMigration;
-import org.openecomp.sdc.asdctool.impl.migration.v1604.VfcNamingAlignment;
-import org.openecomp.sdc.asdctool.impl.migration.v1607.CsarMigration;
-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.Migration1702;
-import org.openecomp.sdc.asdctool.impl.migration.v1707.*;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.common.api.ConfigurationSource;
-import org.openecomp.sdc.common.impl.ExternalConfiguration;
-import org.openecomp.sdc.common.impl.FSConfigurationSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-
-public class MigrationMenu {
-
- private static Logger log = LoggerFactory.getLogger(MigrationMenu.class.getName());
- private static final String SERVICE_MIGARTION_BEAN = "serviceMigrationBean";
-
- private static enum MigrationOperationEnum {
- MIGRATION_1602_1604("migrate-1602-1604", SERVICE_MIGARTION_BEAN),
- ALIGN_DERIVED_FROM_1604("align-derived-from-1604", "derivedFromAlignment"),
- MIGRATE_1604_1607("migrate-1604-1607", SERVICE_MIGARTION_BEAN),
- ALIGN_VFC_NAMES_1604("align-vfc-names-1604", "vfcNamingAlignmentBean"),
- TEST_REMOVE_HEAT_PLACEHOLDERS("testremoveheatplaceholders", SERVICE_MIGARTION_BEAN),
- TEST_ADD_GROUP_UUIDS("testaddgroupuuids", SERVICE_MIGARTION_BEAN),
- ALIGN_GROUPS("align-groups", "groupsAlignment"),
- CLEAN_CSAR("clean-csar", "csarMigration"),
- POPULATE_COMPONENT_CACHE("populate-component-cache", "populateComponentCache"),
- FIX_PROPERTIES("fix-properties", "titanFixUtils"),
- ALIGN_TOSCA_ARTIFACTS("align-tosca-artifacts", "toscaArtifactsAlignment"),
- FIX_ICONS("fix-icons", "titanFixUtils"),
- MIGRATION_1610_1702("migrate-1610-1702", "migration1702"),
- MIGRATION_1702_1707("migrate-1702-1707", "migration1707"),
- 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"),
- MIGRATION_1707_UUID_FIX("fix-UUID-1707", "migration1707UuidFix"),
- MIGRATION_1707_MISSING_INFO_FIX("fix-missing-info-1707", "migration1707MissingInfoFix");
- // UPDATE_DATA_TYPES("update_data_types", "updateDataTypes");
-
- private String value, beanName;
-
- public static MigrationOperationEnum findByValue(String value) {
- Optional<MigrationOperationEnum> optionalFound = Arrays.asList(MigrationOperationEnum.values()).stream().filter(e -> e.getValue().equalsIgnoreCase(value)).findAny();
- return optionalFound.isPresent() ? optionalFound.get() : null;
- }
-
- MigrationOperationEnum(String value, String beanName) {
- this.value = value;
- this.beanName = beanName;
- }
-
- public String getValue() {
- return value;
- }
-
- public String getBeanName() {
- return beanName;
- }
- };
-
- //arguments will be [operation] [version] [config path] [align derived - optional]
- //example : migrate-1610-1702 1702 /home/config
- public static void main(String[] args) throws Exception {
-
- if (args == null || args.length < 3) {
- usageAndExit();
- }
- MigrationOperationEnum operationEnum = MigrationOperationEnum.findByValue(args[0]);
- String appConfigDir = args[2];
- String dataInputFileDir = null;
- if (operationEnum == MigrationOperationEnum.ALIGN_DERIVED_FROM_1604 ) {
- dataInputFileDir = args[3];
- }
- log.info("Run with configuration folder {}", appConfigDir);
- AnnotationConfigApplicationContext context = initContext(appConfigDir);
- try {
- ServiceMigration serviceMigration = (ServiceMigration) context.getBean(SERVICE_MIGARTION_BEAN);
- switch (operationEnum) {
- case MIGRATION_1602_1604:
- log.info("Start Titan migration from 1602 version to 1604");
- if (serviceMigration.migrate1602to1604(appConfigDir)) {
- log.info("Titan migration from 1602 version to 1604 was finished successfull");
- System.exit(0);
- } else {
- log.info("Titan migration from 1602 version to 1604 was failed");
- System.exit(2);
- }
- break;
- case MIGRATE_1604_1607:
- log.info("Start Titan migration from 1604 version to 1607");
- if (serviceMigration.migrate1604to1607(appConfigDir)) {
- log.info("Titan migration from 1604 version to 1607 was finished successfull");
- System.exit(0);
- } else {
- log.info("Titan migration from 1604 version to 1607 was failed");
- System.exit(2);
- }
- break;
- case ALIGN_VFC_NAMES_1604:
- VfcNamingAlignment vfcNamingAlignment = (VfcNamingAlignment) context.getBean(operationEnum.getBeanName());
- log.info("Start VFC naming alignment on 1604");
- if (vfcNamingAlignment.alignVfcNames1604(appConfigDir)) {
- log.info("VFC naming alignment on 1604 was finished successfull");
- System.exit(0);
- } else {
- log.info("VFC naming alignment on 1604 was failed");
- System.exit(2);
- }
- break;
- case TEST_REMOVE_HEAT_PLACEHOLDERS:
- boolean check = serviceMigration.testRemoveHeatPlaceHolders(appConfigDir);
- if (check == true) {
- System.exit(0);
- } else {
- System.exit(2);
- }
- break;
- case TEST_ADD_GROUP_UUIDS:
- check = serviceMigration.testAddGroupUuids(appConfigDir);
- if (check == true) {
- System.exit(0);
- } else {
- System.exit(2);
- }
- break;
- case ALIGN_DERIVED_FROM_1604:
- DerivedFromAlignment derivedFromAlignment = (DerivedFromAlignment) context.getBean(operationEnum.getBeanName());
- log.info("Start derived from alignment on 1604");
- if (derivedFromAlignment.alignDerivedFrom1604(appConfigDir, dataInputFileDir)) {
- log.info("Derived from alignment on 1604 was finished successfull");
- System.exit(0);
- } else {
- log.info("Derived from alignment on 1604 was failed");
- System.exit(2);
- }
- break;
- case ALIGN_GROUPS:
- GroupsAlignment groupsAlignment = (GroupsAlignment) context.getBean(operationEnum.getBeanName());
- log.debug("Start derived from alignment on 1604");
- if (groupsAlignment.alignGroups(appConfigDir)) {
- log.debug("Groups alignment was finished successfull");
- System.exit(0);
- } else {
- log.debug("Groups alignment was failed");
- System.exit(2);
- }
- break;
- case CLEAN_CSAR:
- log.info("Start remove CSAR resources");
- CsarMigration csarMigration = (CsarMigration) context.getBean(operationEnum.getBeanName());
- if (csarMigration.removeCsarResources()) {
- log.info("Remove CSAR resources finished successfully");
- System.exit(0);
- } else {
- log.info("Remove CSAR resources failed");
- System.exit(2);
- }
- break;
- case POPULATE_COMPONENT_CACHE:
- PopulateComponentCache populateComponentCache = (PopulateComponentCache) context.getBean(operationEnum.getBeanName());
- populateComponentCache.populateCache();
- System.exit(0);
- break;
- case FIX_PROPERTIES:
- log.debug("Start fix capability properties types");
- TitanFixUtils titanFixUtils = (TitanFixUtils) context.getBean(operationEnum.getBeanName());
- if (titanFixUtils.fixCapabiltyPropertyTypes()) {
- log.debug("Fix capability properties types finished successfully");
- System.exit(0);
- } else {
- log.debug("Fix capability properties types failed");
- System.exit(2);
- }
- break;
- case FIX_ICONS:
- log.info("Start fix icons of vl and eline");
- titanFixUtils = (TitanFixUtils) context.getBean(operationEnum.getBeanName());
- if (titanFixUtils.fixIconsInNormatives()) {
- log.info("Fix icons of vl and eline finished successfully");
- System.exit(0);
- } else {
- log.info("Fix icons of vl and eline failed");
- System.exit(2);
- }
- break;
- case ALIGN_TOSCA_ARTIFACTS:
- log.info("Start align tosca artifacts");
- ToscaArtifactsAlignment toscaArtifactsAlignment = (ToscaArtifactsAlignment) context.getBean(operationEnum.getBeanName());
- boolean isSuccessful = toscaArtifactsAlignment.alignToscaArtifacts();
- if (isSuccessful) {
- log.info("Tosca Artifacts alignment was finished successfully");
- System.exit(0);
- } else {
- log.info("Tosca Artifacts alignment has failed");
- System.exit(2);
- }
- break;
- case MIGRATION_1610_1702:
- log.info("Start SDC migration from 1610 to 1702");
- Migration1702 migration = (Migration1702) context.getBean(operationEnum.getBeanName());
- isSuccessful = migration.migrate(appConfigDir);
- if (isSuccessful) {
- log.info("SDC migration from 1610 to 1702 was finished successful");
- System.exit(0);
- } else{
- log.info("SDC migration from 1610 to 1702 has failed");
- System.exit(2);
- }
-
- break;
- case MIGRATION_1702_1707://this migration is currently not needed, but will be commented out for production env
-// log.info("Start SDC migration from 1702 to 1707");
- Migration1707 migration1707 = (Migration1707) context.getBean(operationEnum.getBeanName());
- isSuccessful = migration1707.migrate();
- if (isSuccessful) {
- log.info("SDC migration from 1702 to 1707 was finished successfully");
- System.exit(0);
- } else{
- log.info("SDC migration from 1702 to 1707 has failed");
- System.exit(2);
- }
- System.exit(0);
- break;
- case VFMODULES_PROPERTIES_ADDING://this migration is currently not needed, but will be commented out for production env
- log.info("Start adding new properties to vfModules");
- VfModulesPropertiesAdding migrationVfModulesProperties = (VfModulesPropertiesAdding) context.getBean(operationEnum.getBeanName());
- isSuccessful = migrationVfModulesProperties.migrate(args[1]);
- if (isSuccessful) {
- log.info("Adding new properties to vfModules was finished successfully");
- System.exit(0);
- } else{
- log.info("Adding new properties to vfModules has failed");
- System.exit(2);
- }
- System.exit(0);
- break;
- case MIGRATION_1707_UUID_FIX:
- if (args == null || args.length < 5) {
- System.out.println("Usage: fix-UUID-1707 <configuration dir> <all/distributed_only> <services/service_vf/fix/fix_only_services>");
- System.exit(1);
- }
- String fixServices = args[3];
- String runMode = args[4];
- log.info("Start fixing artifact UUID after 1707 migration with arguments run with configuration [{}] , for [{}] services", runMode, fixServices);
-
- Migration1707ArtifactUuidFix migrationFix = (Migration1707ArtifactUuidFix) context.getBean(operationEnum.getBeanName());
- isSuccessful = migrationFix.migrate(fixServices, runMode);
- if (isSuccessful) {
- log.info("Fixing artifacts UUID for 1707 was finished successfully");
- } else{
- log.info("Fixing artifacts UUID for 1707 has failed");
- System.exit(2);
- }
- System.exit(0);
- break;
- case MIGRATION_1707_MISSING_INFO_FIX:
-
- log.info("Start fixing missing group and instance info after 1707 migration");
-
- Migration1707MissingInfoFix migration1707Fix = (Migration1707MissingInfoFix) context.getBean(operationEnum.getBeanName());
- isSuccessful = migration1707Fix.migrate();
- if (isSuccessful) {
- log.info("Fixing groups and node templates missing info was finished successfully");
- } else{
- log.info("Fixing groups and node templates missing info has failed");
- System.exit(2);
- }
- System.exit(0);
- break;
- default:
- usageAndExit();
- }
- } catch (Exception t) {
- log.info("Failed {} with exception: {}", operationEnum, t.toString());
- t.printStackTrace();
- log.debug("Error while Running MigrationMenu {}", t.getMessage(), t);
- System.exit(3);
- } finally {
- context.close();
- }
- }
-
- private static AnnotationConfigApplicationContext initContext(String appConfigDir) {
- ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
- ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class, Migration1707Config.class);
- return context;
- }
-
- private static void usageAndExit() {
- MigrationUsage();
- System.exit(1);
- }
-
- private static void MigrationUsage() {
- System.out.println("Usage: migrate-1602-1604 <configuration dir>");
- System.out.println("Usage: migrate-1604-1607 <configuration dir>");
- System.out.println("Usage: align-vfc-names-1604 <configuration dir>");
- System.out.println("Usage: align-derived-from-1604 <configuration dir> <data_input_file dir>");
- System.out.println("Usage: align-groups <configuration dir>");
- System.out.println("Usage: fix-properties <configuration dir>");
- 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>");
- System.out.println("Usage: fix-UUID-1707 <configuration dir> <all/distributed_only> <services/service_vf/fix/fix_only_services>");
- System.out.println("Usage: fix-missing-info-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
index 758dae0342..394683bbc5 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImport.java
@@ -130,9 +130,9 @@ public class SdcSchemaFileImport {
System.err.println("Failed to pack SDC.zip file, error: "+ex);
System.exit(1);
}
-
- //Generation flow end - generating SDC from normatives
+ //Generation flow end - generating SDC from normatives
+
AnnotationConfigApplicationContext context = initContext(appConfigDir);
schemaFilesCassandraDao = (SdcSchemaFilesCassandraDao) context.getBean("sdc-schema-files-cassandra-dao");
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
index db87a66cd3..1ee006a49f 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
@@ -3,7 +3,6 @@ package org.openecomp.sdc.asdctool.main;
import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL;
import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager;
import org.openecomp.sdc.asdctool.impl.validator.config.ValidationToolConfiguration;
-import org.openecomp.sdc.asdctool.impl.migration.v1604.AppConfig;
import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.common.api.ConfigurationSource;
@@ -22,8 +21,9 @@ public class ValidationTool {
public static void main(String[] args) throws Exception {
- String outputFilePath = args[0];
- ValidationConfigManager.setOutputFilePath(outputFilePath);
+ String outputPath = args[0];
+ ValidationConfigManager.setOutputFilePath(outputPath);
+ ValidationConfigManager.setCsvReportFilePath(outputPath);
String appConfigDir = args[1];
AnnotationConfigApplicationContext context = initContext(appConfigDir);
diff --git a/asdctool/src/main/resources/scripts/dataMigration.sh b/asdctool/src/main/resources/scripts/dataMigration.sh
deleted file mode 100644
index e1f4f24a30..0000000000
--- a/asdctool/src/main/resources/scripts/dataMigration.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/bash
-
-##############################
-# Data Migration
-##############################
-
-CURRENT_DIR=`pwd`
-BASEDIR=$(dirname $1)
-
-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"
-
-case $1 in
- 1604)
- command="java $JVM_LOG_FILE -cp $JARS $mainClass migrate-1602-1604 $@"
- echo $command
- ;;
- 1607)
- command="sh ./dataMigration1607.sh $@"
- echo $command
- ;;
- 1610)
- command="sh ./dataMigration1610.sh $@"
- echo $command
- ;;
- 1702)
- command="sh ./dataMigration1702.sh $@"
- echo $command
- ;;
- 1707)
- command="sh ./dataMigration1707.sh $@"
- echo $command
- ;;
- *)
- echo "No migration for this version $1"
- ;;
-esac
-
-$command
-result=$?
-
-echo "***********************************"
-echo "***** $result *********************"
-echo "***********************************"
-
-exit $result
-
-
diff --git a/asdctool/src/main/resources/scripts/dataMigration1607.sh b/asdctool/src/main/resources/scripts/dataMigration1607.sh
deleted file mode 100644
index 027852d882..0000000000
--- a/asdctool/src/main/resources/scripts/dataMigration1607.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/bash
-
-##############################
-# Data Migration 1607
-##############################
-
-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 migrate-1604-1607 $@"
-echo $command
-
-$command
-result=$?
-
-echo "***********************************"
-echo "***** $result *********************"
-echo "***********************************"
-
-exit $result
-
-
diff --git a/asdctool/src/main/resources/scripts/dataMigration1610.sh b/asdctool/src/main/resources/scripts/dataMigration1610.sh
deleted file mode 100644
index 45d61adeee..0000000000
--- a/asdctool/src/main/resources/scripts/dataMigration1610.sh
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/bin/bash
-
-##############################
-# Data Migration 1610
-##############################
-
-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-properties $@"
-echo $command
-
-$command
-result=$?
-
-if [ $result -eq 0 ]
-then
- command="java $JVM_LOG_FILE -cp $JARS $mainClass align-tosca-artifacts $@"
- echo $command
- $command
- result=$?
-fi
-
-echo "***********************************"
-echo "***** $result *********************"
-echo "***********************************"
-
-exit $result
-
-
diff --git a/asdctool/src/main/resources/scripts/dataMigration1702.sh b/asdctool/src/main/resources/scripts/dataMigration1702.sh
deleted file mode 100644
index f2bf56e4ef..0000000000
--- a/asdctool/src/main/resources/scripts/dataMigration1702.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-
-##############################
-# Data Migration 1702
-##############################
-
-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 migrate-1610-1702 $@"
-echo $command
-
-$command
-result=$?
-
-
-
-echo "***********************************"
-echo "***** $result *********************"
-echo "***********************************"
-
-exit $result
-
-
diff --git a/asdctool/src/main/resources/scripts/dataMigration1707.sh b/asdctool/src/main/resources/scripts/dataMigration1707.sh
deleted file mode 100644
index 11a151a7c3..0000000000
--- a/asdctool/src/main/resources/scripts/dataMigration1707.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-
-##############################
-# Data 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 -Xmx6000M -cp $JARS $mainClass migrate-1702-1707 $@"
-echo $command
-
-$command
-result=$?
-
-
-
-echo "***********************************"
-echo "***** $result *********************"
-echo "***********************************"
-
-exit $result
-
-
diff --git a/asdctool/src/main/resources/scripts/validationTool.sh b/asdctool/src/main/resources/scripts/validationTool.sh
index 23eaeb8da7..58cd7f3f6a 100644
--- a/asdctool/src/main/resources/scripts/validationTool.sh
+++ b/asdctool/src/main/resources/scripts/validationTool.sh
@@ -18,7 +18,8 @@ source ${FULL_PATH}/baseOperation.sh
mainClass="org.openecomp.sdc.asdctool.main.ValidationTool"
-command="java $JVM_LOG_FILE -cp $JARS $mainClass reportOutput.txt /home/vagrant/catalog-be/config/catalog-be/"
+#command="java $JVM_LOG_FILE -cp $JARS $mainClass reportOutput.txt /home/vagrant/catalog-be/config/catalog-be/"
+command="java $JVM_LOG_FILE -cp $JARS $mainClass . /apps/jetty/base/be/config/catalog-be/"
echo $command
$command