diff options
author | ChrisC <christophe.closset@intl.att.com> | 2021-03-12 15:54:32 +0100 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2021-03-13 15:19:51 +0000 |
commit | defcbad3b225e098be507b99ae5ea5f6ef587399 (patch) | |
tree | ea8fe164e2b7ea5c6e702b1fa49c69beefa84f5b /asdctool/src/main/java/org/openecomp | |
parent | da1e922cf682af524ab9392d341ede8b9d28093d (diff) |
Remove unused code
Remove unused and untested or poorly tested code for migrating old DB
Issue-ID: SDC-3428
Signed-off-by: ChrisC <christophe.closset@intl.att.com>
Change-Id: I39b086111b5be8d1caf4d6d45bf92105d03709eb
Diffstat (limited to 'asdctool/src/main/java/org/openecomp')
12 files changed, 0 insertions, 1817 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/InstanceMigrationBase.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/InstanceMigrationBase.java index b0a1d502aa..5876898d7e 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/InstanceMigrationBase.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/InstanceMigrationBase.java @@ -24,7 +24,6 @@ import fj.data.Either; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.janusgraph.core.JanusGraphVertex; -import org.openecomp.sdc.asdctool.migration.tasks.mig2002.SdcCollapsingRolesRFCstateMigration; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -152,21 +151,6 @@ public abstract class InstanceMigrationBase { return false; } - protected List<JanusGraphVertex> getVertexByEdgeSide(Iterator<Edge> edges, SdcCollapsingRolesRFCstateMigration.EdgeSide side) { - List<JanusGraphVertex> vertexList = new ArrayList(); - while (edges.hasNext()) { - Edge edge = edges.next(); - - if (side == SdcCollapsingRolesRFCstateMigration.EdgeSide.OUT) { - vertexList.add((JanusGraphVertex) edge.outVertex()); - } else { - vertexList.add((JanusGraphVertex) edge.inVertex()); - } - } - - return vertexList; - } - protected Iterator<Edge> getVertexEdge(GraphVertex containerV, Direction direction, EdgeLabelEnum edgeLabel) { return containerV.getVertex().edges(direction, edgeLabel.name()); } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1802/SdcCatalogMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1802/SdcCatalogMigration.java deleted file mode 100644 index 43399b616d..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1802/SdcCatalogMigration.java +++ /dev/null @@ -1,168 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 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.migration.tasks.mig1802; - -import fj.data.Either; -import org.apache.commons.collections.ListUtils; -import org.apache.tinkerpop.gremlin.structure.Direction; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -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.IdBuilderUtils; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation; -import org.openecomp.sdc.common.log.wrappers.Logger; -import org.springframework.stereotype.Component; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -@Component -public class SdcCatalogMigration implements Migration { - private static final Logger LOGGER = Logger.getLogger(SdcCatalogMigration.class); - private static final List<ResourceTypeEnum> EXCLUDE_TYPES = Arrays.asList(ResourceTypeEnum.VFCMT, ResourceTypeEnum.Configuration); - - private ToscaElementOperation toscaElementOperation; - private JanusGraphDao janusGraphDao; - - public SdcCatalogMigration(TopologyTemplateOperation toscaElementOperation, JanusGraphDao janusGraphDao) { - this.toscaElementOperation = toscaElementOperation; - this.janusGraphDao = janusGraphDao; - } - - @Override - public String description() { - return "optimize sdc catalog vertices"; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(1802), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - JanusGraphOperationStatus status = null; - try { - status = getOrCreateCatalogRoot() - .either(this::associateCatalogRootToCatalogElements, - err -> {LOGGER.error("failed to create catalog root. err: {}", err); return err;}); - return status == JanusGraphOperationStatus.OK ? MigrationResult.success() : MigrationResult.error("failed to create and associate catalog root. error: " + status); - } finally { - commitOrRollBack(status); - } - } - - private void commitOrRollBack(JanusGraphOperationStatus status) { - if (status == JanusGraphOperationStatus.OK) { - janusGraphDao.commit(); - } else { - janusGraphDao.rollback(); - } - } - - private Either<GraphVertex, JanusGraphOperationStatus> getOrCreateCatalogRoot() { - LOGGER.info("creating or getting catalog root vertex"); - return janusGraphDao.getVertexByLabel(VertexTypeEnum.CATALOG_ROOT) - .right() - .bind(this::createRootCatalogVertexOrError); - } - - - private Either<GraphVertex, JanusGraphOperationStatus> createRootCatalogVertexOrError(JanusGraphOperationStatus janusGraphOperationStatus) { - return janusGraphOperationStatus == JanusGraphOperationStatus.NOT_FOUND ? createRootCatalogVertex() : Either.right( - janusGraphOperationStatus); - } - - private Either<GraphVertex, JanusGraphOperationStatus> createRootCatalogVertex() { - LOGGER.info("Creating root catalog vertex"); - GraphVertex catalogRootVertex = new GraphVertex(VertexTypeEnum.CATALOG_ROOT); - catalogRootVertex.setUniqueId(IdBuilderUtils.generateUniqueId()); - return janusGraphDao.createVertex(catalogRootVertex); - } - - private Either<List<GraphVertex>, JanusGraphOperationStatus> getAllCatalogVertices() { - LOGGER.info("fetching all catalog resources"); - return toscaElementOperation.getListOfHighestComponents(ComponentTypeEnum.RESOURCE, EXCLUDE_TYPES, JsonParseFlagEnum.ParseMetadata) - .right() - .bind(this::errOrEmptyListIfNotFound) - .left() - .bind(this::getAllCatalogVertices); - } - - private Either<List<GraphVertex>, JanusGraphOperationStatus> errOrEmptyListIfNotFound(JanusGraphOperationStatus err) { - return JanusGraphOperationStatus.NOT_FOUND.equals(err) ? Either.left(new ArrayList<>()) : Either.right(err); - } - - @SuppressWarnings("unchecked") - private Either<List<GraphVertex>, JanusGraphOperationStatus> getAllCatalogVertices(List<GraphVertex> allResourceCatalogVertices) { - LOGGER.info("number of resources: {}", allResourceCatalogVertices.size()); - LOGGER.info("fetching all catalog services"); - return toscaElementOperation.getListOfHighestComponents(ComponentTypeEnum.SERVICE, EXCLUDE_TYPES, JsonParseFlagEnum.ParseMetadata) - .right() - .bind(this::errOrEmptyListIfNotFound) - .left() - .map(allServiceVertices -> ListUtils.union(allServiceVertices, allResourceCatalogVertices)); - } - - private JanusGraphOperationStatus associateCatalogRootToCatalogElements(GraphVertex root) { - return getAllCatalogVertices() - .either(catalogVertices -> associateCatalogRootToCatalogElements(root, catalogVertices), - err -> err); - } - - private JanusGraphOperationStatus associateCatalogRootToCatalogElements(GraphVertex root, List<GraphVertex> catalogElements) { - LOGGER.info("number of catalog elements: {}", catalogElements.size()); - LOGGER.info("connect all catalog elements to root edge"); - List<GraphVertex> nonConnectedElements = catalogElements.stream().filter(this::edgeNotAlreadyExists).collect(Collectors.toList()); - int numOfCreatedEdges = 0; - for (GraphVertex catalogElement : nonConnectedElements) { - JanusGraphOperationStatus - edgeCreationStatus = janusGraphDao - .createEdge(root, catalogElement, EdgeLabelEnum.CATALOG_ELEMENT, null); - if (edgeCreationStatus != JanusGraphOperationStatus.OK) { - LOGGER.error("failed to create edge from catalog element to vertex {}", catalogElement.getUniqueId()); - return edgeCreationStatus; - } - LOGGER.debug("created edge from catalog root to element {}", catalogElement.getUniqueId()); - numOfCreatedEdges++; - } - LOGGER.info("number edges created: {}", numOfCreatedEdges); - return JanusGraphOperationStatus.OK; - } - - private boolean edgeNotAlreadyExists(GraphVertex catalogElement) { - return !catalogElement.getVertex().edges(Direction.IN, EdgeLabelEnum.CATALOG_ELEMENT.name()).hasNext(); - } - - -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ForwardPathMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ForwardPathMigration.java deleted file mode 100644 index 8796517c6e..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ForwardPathMigration.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright © 2016-2018 European Support Limited - * - * 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. - */ - -package org.openecomp.sdc.asdctool.migration.tasks.mig1806; - -import com.google.common.collect.ImmutableSet; -import fj.data.Either; -import org.apache.tinkerpop.gremlin.structure.Direction; -import org.apache.tinkerpop.gremlin.structure.Edge; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.janusgraph.core.JanusGraphVertex; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.be.config.ConfigurationManager; -import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -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.IdBuilderUtils; -import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.ComponentParametersView; -import org.openecomp.sdc.be.model.Service; -import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.model.jsonjanusgraph.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.model.operations.impl.UserAdminOperation; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -//@org.springframework.stereotype.Component -public class ForwardPathMigration implements Migration { - - private JanusGraphDao janusGraphDao; - private UserAdminOperation userAdminOperation; - private ToscaOperationFacade toscaOperationFacade; - private User user = null; - - public ForwardPathMigration(JanusGraphDao janusGraphDao, - UserAdminOperation userAdminOperation, ToscaOperationFacade toscaOperationFacade) { - this.janusGraphDao = janusGraphDao; - this.userAdminOperation = userAdminOperation; - this.toscaOperationFacade = toscaOperationFacade; - } - - @Override - public String description() { - return "remove corrupted forwarding paths "; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(1806), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - final String userId = ConfigurationManager.getConfigurationManager().getConfiguration().getAutoHealingOwner(); - - Either<User, ActionStatus> userData = (Either<User, ActionStatus>) userAdminOperation - .getUserData(userId, false); - if (userData.isRight()) { - return MigrationResult.error( - "failed to delete unused forwarding paths. Failed to resolve user : " + userId + " error " + userData - .right().value()); - } else { - user = userData.left().value(); - } - StorageOperationStatus status = cleanAllServices(); - - return status == StorageOperationStatus.OK ? MigrationResult.success() - : MigrationResult.error("failed to remove corrupted forwarding paths . Error : " + status); - - } - - private StorageOperationStatus cleanAllServices() { - StorageOperationStatus status; - - Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class); - hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); - Map<GraphPropertyEnum, Object> hasNotProps = new HashMap<>(); - hasNotProps.put(GraphPropertyEnum.IS_DELETED, true); - status = janusGraphDao - .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, hasNotProps, JsonParseFlagEnum.ParseAll) - .either(this::cleanServices, this::handleError); - return status; - } - - private StorageOperationStatus cleanServices(List<GraphVertex> containersV) { - StorageOperationStatus status = StorageOperationStatus.OK; - for (GraphVertex container : containersV) { - ComponentParametersView componentParametersView = new ComponentParametersView(); - componentParametersView.setIgnoreComponentInstances(false); - componentParametersView.setIgnoreCapabilities(false); - componentParametersView.setIgnoreRequirements(false); - componentParametersView.setIgnoreServicePath(false); - Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade - .getToscaElement(container.getUniqueId(), componentParametersView); - if (toscaElement.isRight()) { - return toscaElement.right().value(); - } - status = fixDataOnGraph(toscaElement.left().value()); - if (status != StorageOperationStatus.OK) { - break; - } - } - return status; - } - - - private StorageOperationStatus handleError(JanusGraphOperationStatus err) { - janusGraphDao.rollback(); - return DaoStatusConverter - .convertJanusGraphStatusToStorageStatus( - JanusGraphOperationStatus.NOT_FOUND == err ? JanusGraphOperationStatus.OK : err); - } - - private StorageOperationStatus fixDataOnGraph(Component component) { - if (!(component instanceof Service)){ - return StorageOperationStatus.OK; - } - Service service = (Service) component; - Either<GraphVertex, JanusGraphOperationStatus> getResponse = janusGraphDao.getVertexById(service.getUniqueId(), - JsonParseFlagEnum.NoParse); - if (getResponse.isRight()) { - return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getResponse.right().value()); - - } - Set<String> ciNames = new HashSet<>(); - if (service.getComponentInstances() != null && !service.getComponentInstances().isEmpty()) { - ciNames = service.getComponentInstances().stream().map(ci -> ci.getName()) - .collect(Collectors.toSet()); - } - GraphVertex componentVertex = getResponse.left().value(); - - GraphVertex toscaDataVertex; - Either<GraphVertex, JanusGraphOperationStatus> groupVertexEither = janusGraphDao.getChildVertex(componentVertex, - EdgeLabelEnum.FORWARDING_PATH, JsonParseFlagEnum.ParseJson); - if (groupVertexEither.isRight() && groupVertexEither.right().value() == JanusGraphOperationStatus.NOT_FOUND) { - return StorageOperationStatus.OK; - } - if (groupVertexEither.isRight()) { - return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(groupVertexEither.right().value()); - } - toscaDataVertex = groupVertexEither.left().value(); - Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>( - (Map<String, ForwardingPathDataDefinition>) toscaDataVertex.getJson()); - List<String> toBeDeletedFP = new ArrayList<>(); - for (Map.Entry<String, ForwardingPathDataDefinition> forwardingPathDataDefinition : forwardingPaths - .entrySet()) { - Set<String> nodeNames = forwardingPathDataDefinition.getValue().getPathElements() - .getListToscaDataDefinition() - .stream().map(element -> ImmutableSet.of(element.getFromNode(), element.getToNode())) - .flatMap(set -> set.stream()).collect(Collectors.toSet()); - if (!ciNames.containsAll(nodeNames)) { - toBeDeletedFP.add(forwardingPathDataDefinition.getKey()); - } - } - if (toBeDeletedFP.isEmpty()) { - janusGraphDao.rollback(); - return StorageOperationStatus.OK; - } - toBeDeletedFP.stream().forEach(fpKey -> forwardingPaths.remove(fpKey)); - toscaDataVertex.setJson(forwardingPaths); - Either<GraphVertex, JanusGraphOperationStatus> updatevertexEither = updateOrCopyOnUpdate( - toscaDataVertex, componentVertex); - if (updatevertexEither.isRight()) { - janusGraphDao.rollback(); - return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updatevertexEither.right().value()); - } - janusGraphDao.commit(); - return StorageOperationStatus.OK; - } - - private Either<GraphVertex, JanusGraphOperationStatus> cloneDataVertex(GraphVertex dataVertex, GraphVertex toscaElementVertex, Edge edgeToRemove) { - EdgeLabelEnum label = EdgeLabelEnum.FORWARDING_PATH; - GraphVertex newDataVertex = new GraphVertex(dataVertex.getLabel()); - String id = IdBuilderUtils.generateChildId(toscaElementVertex.getUniqueId(), dataVertex.getLabel()); - newDataVertex.cloneData(dataVertex); - newDataVertex.setUniqueId(id); - - Either<GraphVertex, JanusGraphOperationStatus> createVertex = janusGraphDao.createVertex(newDataVertex); - if (createVertex.isRight()) { - return createVertex; - } - newDataVertex = createVertex.left().value(); - JanusGraphOperationStatus - createEdge = janusGraphDao - .createEdge(toscaElementVertex, newDataVertex, label, janusGraphDao.getEdgeProperties(edgeToRemove)); - if (createEdge != JanusGraphOperationStatus.OK) { - return Either.right(createEdge); - } - edgeToRemove.remove(); - return Either.left(newDataVertex); - } - - private Either<GraphVertex, JanusGraphOperationStatus> updateOrCopyOnUpdate(GraphVertex dataVertex, GraphVertex toscaElementVertex ) { - EdgeLabelEnum label = EdgeLabelEnum.FORWARDING_PATH; - Iterator<Edge> edges = dataVertex.getVertex().edges(Direction.IN, label.name()); - int edgeCount = 0; - Edge edgeToRemove = null; - while (edges.hasNext()) { - Edge edge = edges.next(); - ++edgeCount; - Vertex outVertex = edge.outVertex(); - String outId = (String) janusGraphDao - .getProperty((JanusGraphVertex) outVertex, GraphPropertyEnum.UNIQUE_ID.getProperty()); - if (toscaElementVertex.getUniqueId().equals(outId)) { - edgeToRemove = edge; - } - } - if (edgeToRemove == null) { - return Either.right(JanusGraphOperationStatus.GENERAL_ERROR); - } - switch (edgeCount) { - case 0: - // error - return Either.right(JanusGraphOperationStatus.GENERAL_ERROR); - case 1: - // update - return janusGraphDao.updateVertex(dataVertex); - default: - // copy on update - return cloneDataVertex(dataVertex, toscaElementVertex, edgeToRemove); - } - } -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ResourceLifecycleMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ResourceLifecycleMigration.java deleted file mode 100644 index 8f7fc3eeb5..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ResourceLifecycleMigration.java +++ /dev/null @@ -1,159 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 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.migration.tasks.mig1806; - -import fj.data.Either; -import org.openecomp.sdc.asdctool.enums.LifecycleStateEnum; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; -import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; -import org.openecomp.sdc.be.config.ConfigurationManager; -import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; -import org.openecomp.sdc.be.model.User; -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.UserAdminOperation; -import org.openecomp.sdc.common.log.wrappers.Logger; -import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.stereotype.Component; - -import java.math.BigInteger; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; - -@Component -public class ResourceLifecycleMigration implements Migration { - - private JanusGraphDao janusGraphDao; - private LifecycleBusinessLogic lifecycleBusinessLogic; - private UserAdminOperation userAdminOperation; - - private User user = null; - - private static final Logger log = Logger.getLogger(ResourceLifecycleMigration.class); - - public ResourceLifecycleMigration(JanusGraphDao janusGraphDao, LifecycleBusinessLogic lifecycleBusinessLogic, UserAdminOperation userAdminOperation) { - this.janusGraphDao = janusGraphDao; - this.lifecycleBusinessLogic = lifecycleBusinessLogic; - this.userAdminOperation = userAdminOperation; - } - - @Override - public String description() { - return "change resource lifecycle state from testing to certified"; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(1806), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - log.info("start change resource lifecycle states migration"); - final String userId = ConfigurationManager.getConfigurationManager().getConfiguration().getAutoHealingOwner(); - - Either<User, ActionStatus> userReq = userAdminOperation.getUserData(userId, false); - if (userReq.isRight()) { - log.error("Upgrade migration failed. User {} resolve failed: {} ", userId, userReq.right().value()); - return MigrationResult.error("failed to change lifecycle state of resources. Failed to resolve user : " + userId + " error " + userReq.right().value()); - } else { - user = userReq.left().value(); - log.info("User {} will perform upgrade operation with role {}", user.getUserId(), user.getRole()); - } - - StorageOperationStatus status = changeResourceLifecycleState(); - - return status == StorageOperationStatus.OK ? MigrationResult.success() : MigrationResult.error("failed to change lifecycle state of resources. Error : " + status); - } - - private StorageOperationStatus changeResourceLifecycleState() { - StorageOperationStatus status; - status = findResourcesAndChangeStatus(VertexTypeEnum.NODE_TYPE); - if (StorageOperationStatus.OK == status) { - status = findResourcesAndChangeStatus(VertexTypeEnum.TOPOLOGY_TEMPLATE); - } - janusGraphDao.commit(); - return status; - } - - private StorageOperationStatus findResourcesAndChangeStatus(VertexTypeEnum type) { - StorageOperationStatus status; - Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class); - props.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); - props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.READY_FOR_CERTIFICATION.name()); - props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - - Map<GraphPropertyEnum, Object> hasNot = new EnumMap<>(GraphPropertyEnum.class); - hasNot.put(GraphPropertyEnum.IS_DELETED, true); - - log.info("findResourcesAndChangeStatus for type {} and state {}", type ,LifecycleStateEnum.READY_FOR_CERTIFICATION); - status = janusGraphDao.getByCriteria(type, props, hasNot, JsonParseFlagEnum.ParseAll).either(this::changeState, this::handleError); - log.info("status {} for type {} and state {}", status, type ,LifecycleStateEnum.READY_FOR_CERTIFICATION); - - log.info("findResourcesAndChangeStatus for type {} and state {}", type ,LifecycleStateEnum.CERTIFICATION_IN_PROGRESS); - props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS.name()); - status = janusGraphDao.getByCriteria(type, props, hasNot, JsonParseFlagEnum.ParseAll).either(this::changeState, this::handleError); - log.info("status {} for type {} and state {}", status, type ,LifecycleStateEnum.CERTIFICATION_IN_PROGRESS); - - - return status; - } - - private StorageOperationStatus changeState(List<GraphVertex> resourcesV) { - StorageOperationStatus status = StorageOperationStatus.OK; - - for (GraphVertex resourceV : resourcesV) { - status = changeResourceState(resourceV); - if (status != StorageOperationStatus.OK) { - log.info("Failed to change state to certified of resource with id {} , continue to next, reset status", resourceV.getUniqueId() ); - status = StorageOperationStatus.OK; - } - } - return status; - } - - private StorageOperationStatus changeResourceState(GraphVertex resourceV) { - log.debug("Change state to certified to resource with id {} ", resourceV.getUniqueId() ); - - LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction("change resource state by migration"); - final Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> changeComponentState = lifecycleBusinessLogic.changeComponentState(ComponentTypeEnum.RESOURCE, resourceV.getUniqueId(), user, LifeCycleTransitionEnum.CERTIFY, changeInfo, false, true); - return changeComponentState.isLeft() ? StorageOperationStatus.OK : StorageOperationStatus.GENERAL_ERROR; - } - - private StorageOperationStatus handleError(JanusGraphOperationStatus err) { - log.debug("receive janusgraph error {}", err); - return DaoStatusConverter.convertJanusGraphStatusToStorageStatus( - JanusGraphOperationStatus.NOT_FOUND == err ? JanusGraphOperationStatus.OK : err); - } - -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigration.java deleted file mode 100644 index a28c27fe6c..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigration.java +++ /dev/null @@ -1,236 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 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.migration.tasks.mig1806; - -import fj.data.Either; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.asdctool.migration.tasks.InstanceMigrationBase; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; -import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.jsonjanusgraph.enums.JsonConstantKeysEnum; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTemplateOperation; -import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.openecomp.sdc.common.log.wrappers.Logger; -import org.springframework.stereotype.Component; - -import java.math.BigInteger; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; - -@Component -public class SDCInstancesMigration extends InstanceMigrationBase implements Migration { - - private NodeTemplateOperation nodeTemplateOperation; - - private static final Logger log = Logger.getLogger(SDCInstancesMigration.class); - - private static final String ALLOTTED_CATEGORY = "Allotted Resource"; - - private static final List<String> UUID_PROPS_NAMES = Arrays.asList("providing_service_uuid", "providing_service_uuid"); - - - public SDCInstancesMigration(JanusGraphDao janusGraphDao, NodeTemplateOperation nodeTemplateOperation) { - super(janusGraphDao); - this.nodeTemplateOperation = nodeTemplateOperation; - } - - @Override - public String description() { - return "connect instances in container to its origins"; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(1806), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - StorageOperationStatus status = upgradeTopologyTemplates(); - return status == StorageOperationStatus.OK ? MigrationResult.success() : MigrationResult.error("failed to create connection between instances and origins. Error : " + status); - } - - protected StorageOperationStatus handleOneContainer(GraphVertex containerVorig) { - StorageOperationStatus status = StorageOperationStatus.OK; - - GraphVertex containerV = getVertexById(containerVorig.getUniqueId()); - - boolean needConnectAllotted = false; - ComponentTypeEnum componentType = containerV.getType(); - Map<String, MapPropertiesDataDefinition> instanceProperties = null; - if (componentType == ComponentTypeEnum.RESOURCE) { - Either<GraphVertex, JanusGraphOperationStatus> subcategoryV = janusGraphDao - .getChildVertex(containerV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse); - if (subcategoryV.isRight()) { - log.debug("Failed to fetch category vertex for resource {} error {} ", containerV.getUniqueId(), subcategoryV.right().value()); - return StorageOperationStatus.GENERAL_ERROR; - } - GraphVertex catV = subcategoryV.left().value(); - Map<GraphPropertyEnum, Object> metadataProperties = catV.getMetadataProperties(); - - String name = (String) metadataProperties.get(GraphPropertyEnum.NAME); - if (name.equals(ALLOTTED_CATEGORY)) { - log.debug("Find allotted resource {}.", containerV.getUniqueId()); - needConnectAllotted = true; - Either<Map<String, MapPropertiesDataDefinition>, StorageOperationStatus> instProperties = getInstProperties(containerV); - if ( instProperties.isRight() ){ - return instProperties.right().value(); - } - instanceProperties = instProperties.left().value(); - } - } - Map<String, CompositionDataDefinition> jsonComposition = (Map<String, CompositionDataDefinition>) containerV.getJson(); - if (jsonComposition != null && !jsonComposition.isEmpty()) { - try { - status = connectInstances(containerV, needConnectAllotted, instanceProperties, jsonComposition); - - } finally { - if (status == StorageOperationStatus.OK) { - janusGraphDao.commit(); - } else { - janusGraphDao.rollback(); - } - } - } - return status; - } - - - private Either<Map<String, MapPropertiesDataDefinition>, StorageOperationStatus> getInstProperties(GraphVertex containerV) { - Map<String, MapPropertiesDataDefinition> instanceProperties; - Either<GraphVertex, JanusGraphOperationStatus> instProps = janusGraphDao - .getChildVertex(containerV, EdgeLabelEnum.INST_PROPERTIES, JsonParseFlagEnum.ParseAll); - - if (instProps.isRight()) { - if (instProps.right().value() == JanusGraphOperationStatus.NOT_FOUND) { - instanceProperties = new HashMap<>(); - } else { - log.debug("Failed to fetch instance properties vertex for resource {} error {} ", containerV.getUniqueId(), instProps.right().value()); - return Either.right(StorageOperationStatus.GENERAL_ERROR); - } - } else { - instanceProperties = (Map<String, MapPropertiesDataDefinition>) instProps.left().value().getJson(); - } - return Either.left(instanceProperties); - } - - private StorageOperationStatus connectInstances(GraphVertex containerV, boolean needConnectAllotted, Map<String, MapPropertiesDataDefinition> instanceProperties, - Map<String, CompositionDataDefinition> jsonComposition) { - StorageOperationStatus status = StorageOperationStatus.OK; - CompositionDataDefinition compositionDataDefinition = jsonComposition.get(JsonConstantKeysEnum.COMPOSITION.getValue()); - Map<String, ComponentInstanceDataDefinition> componentInstances = compositionDataDefinition.getComponentInstances(); - for (Map.Entry<String, ComponentInstanceDataDefinition> entry : componentInstances.entrySet()) { - status = handleInstance(containerV, needConnectAllotted, instanceProperties, entry); - if ( status != StorageOperationStatus.OK){ - if ( status == StorageOperationStatus.NOT_FOUND ){ - log.debug("reset status and continue"); - status = StorageOperationStatus.OK; - }else{ - log.debug("Failed handle instance. exit"); - break; - } - } - } - return status; - } - - private StorageOperationStatus handleInstance(GraphVertex containerV, boolean needConnectAllotted, Map<String, MapPropertiesDataDefinition> instanceProperties, Map.Entry<String, ComponentInstanceDataDefinition> entry) { - ComponentInstanceDataDefinition instance = entry.getValue(); - StorageOperationStatus status = nodeTemplateOperation.createInstanceEdge(containerV, instance); - if (status != StorageOperationStatus.OK) { - if ( status == StorageOperationStatus.NOT_FOUND ){ - Boolean highest = (Boolean) containerV.getMetadataProperties().get(GraphPropertyEnum.IS_HIGHEST_VERSION); - log.debug("No origin for instance {} with ID {}. The component is highest ={}, Reset status and continue.. ", instance.getUniqueId(), instance.getComponentUid(), highest); - status = StorageOperationStatus.OK; - }else{ - log.debug("Failed to connect in container {} instance {} to origin {} error {} ", containerV.getUniqueId(), instance.getUniqueId(), instance.getComponentUid(), status); - return status; - } - } - if (needConnectAllotted) { - status = connectAllotedInstances(containerV, instanceProperties, instance); - } - return status; - } - - private StorageOperationStatus connectAllotedInstances(GraphVertex containerV, Map<String, MapPropertiesDataDefinition> instanceProperties, ComponentInstanceDataDefinition instance) { - StorageOperationStatus status = StorageOperationStatus.OK; - if ( instanceProperties != null ){ - MapPropertiesDataDefinition mapPropertiesDataDefinition = instanceProperties.get(instance.getUniqueId()); - if ( mapPropertiesDataDefinition != null ){ - status = checkAllottedPropertyAndConnect(containerV, instance, mapPropertiesDataDefinition); - }else{ - log.debug("No isntances properties for instance {}", instance.getUniqueId()); - } - } - return status; - } - - private StorageOperationStatus checkAllottedPropertyAndConnect(GraphVertex containerV, ComponentInstanceDataDefinition instance, MapPropertiesDataDefinition mapPropertiesDataDefinition) { - Map<String, PropertyDataDefinition> mapToscaDataDefinition = mapPropertiesDataDefinition.getMapToscaDataDefinition(); - StorageOperationStatus status = StorageOperationStatus.OK; - Optional<Entry<String, PropertyDataDefinition>> findFirst = mapToscaDataDefinition - .entrySet() - .stream() - .filter(e -> UUID_PROPS_NAMES.contains(e.getKey())) - .findFirst(); - - if ( findFirst.isPresent() ){ - PropertyDataDefinition property = findFirst.get().getValue(); - String serviceUUID = property.getValue(); - if ( serviceUUID != null ){ - log.debug("Defined reference service on property {} value {} on instance {}", property.getName(), property.getValue(), instance.getUniqueId() ); - status = nodeTemplateOperation.createAllottedOfEdge(containerV.getUniqueId(), instance.getUniqueId(), serviceUUID); - if ( status != StorageOperationStatus.OK ){ - if ( status == StorageOperationStatus.NOT_FOUND ){ - Boolean highest = (Boolean) containerV.getMetadataProperties().get(GraphPropertyEnum.IS_HIGHEST_VERSION); - log.debug("No origin for allotted reference {} with UUID {}. the component highest = {}, Reset status and continue.. ", instance.getUniqueId(), serviceUUID, highest); - status = StorageOperationStatus.OK; - }else{ - log.debug("Failed to connect in container {} instance {} to allotted service {} error {} ", containerV.getUniqueId(), instance.getUniqueId(), instance.getComponentUid(), status); - return status; - } - } - }else{ - log.debug("No value for property {} on instance {}", property.getName(),instance.getUniqueId() ); - } - }else{ - log.debug("No sercific properties of dependencies for instance {}", instance.getUniqueId()); - } - return status; - } - -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SdcArchiveMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SdcArchiveMigration.java deleted file mode 100644 index ea1541ef8d..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SdcArchiveMigration.java +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 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.migration.tasks.mig1806; - -import fj.data.Either; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.dao.jsongraph.utils.IdBuilderUtils; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.common.log.wrappers.Logger; -import org.springframework.stereotype.Component; - -import java.math.BigInteger; - -@Component -public class SdcArchiveMigration implements Migration { - private static final Logger logger = Logger.getLogger(SdcArchiveMigration.class); - - private JanusGraphDao janusGraphDao; - - public SdcArchiveMigration(JanusGraphDao janusGraphDao) { - this.janusGraphDao = janusGraphDao; - } - - @Override - public String description() { - return "add archive node for archiving/restoring components "; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(1806), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - JanusGraphOperationStatus status = null; - try { - status = getOrCreateArchiveRoot(); - return status == JanusGraphOperationStatus.OK ? MigrationResult.success() : MigrationResult.error("failed to create archive root node. error: " + status); - } finally { - commitOrRollBack(status); - } - } - - private void commitOrRollBack(JanusGraphOperationStatus status) { - if (status == JanusGraphOperationStatus.OK) { - janusGraphDao.commit(); - } else { - janusGraphDao.rollback(); - } - } - - private JanusGraphOperationStatus getOrCreateArchiveRoot() { - logger.info("creating or getting catalog archive vertex"); - return janusGraphDao.getVertexByLabel(VertexTypeEnum.ARCHIVE_ROOT) - .either(v -> JanusGraphOperationStatus.OK, s -> this.createRootArchiveVertex()); - } - - private JanusGraphOperationStatus createRootArchiveVertex() { - GraphVertex archiveRootVertex = new GraphVertex(VertexTypeEnum.ARCHIVE_ROOT); - archiveRootVertex.setUniqueId(IdBuilderUtils.generateUniqueId()); - archiveRootVertex.addMetadataProperty(GraphPropertyEnum.LABEL, VertexTypeEnum.ARCHIVE_ROOT); - archiveRootVertex.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, archiveRootVertex.getUniqueId()); - - logger.info("Creating root archive vertex {}", archiveRootVertex.getUniqueId()); - - final Either<GraphVertex, JanusGraphOperationStatus> vertexE = janusGraphDao.createVertex(archiveRootVertex); - - return vertexE.isLeft() ? JanusGraphOperationStatus.OK : vertexE.right().value(); - } - -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1902/InterfaceOperationMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1902/InterfaceOperationMigration.java deleted file mode 100644 index fd71336fd5..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1902/InterfaceOperationMigration.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright © 2016-2018 European Support Limited - * - * 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. - */ - -package org.openecomp.sdc.asdctool.migration.tasks.mig1902; - -import fj.data.Either; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.be.config.ConfigurationManager; -import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -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.datatypes.elements.InterfaceDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation; -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.UserAdminOperation; -import org.openecomp.sdc.common.log.wrappers.Logger; -import org.springframework.beans.factory.annotation.Autowired; - -import java.math.BigInteger; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; - -@org.springframework.stereotype.Component -public class InterfaceOperationMigration implements Migration { - - private static final Logger LOGGER = Logger.getLogger(InterfaceOperationMigration.class); - - @Autowired - private JanusGraphDao janusGraphDao; - @Autowired - private UserAdminOperation userAdminOperation; - @Autowired - private InterfaceOperation interfaceOperation; - - @Override - public String description() { - return "Update interface operation data to latest data model"; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(1902), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - final String userId = ConfigurationManager.getConfigurationManager().getConfiguration().getAutoHealingOwner(); - - Either<User, ActionStatus> userData = userAdminOperation.getUserData(userId, false); - if (userData.isRight()) { - return MigrationResult.error( - "failed to update interface operation data. Failed to resolve user : " - + userId + " error " + userData.right().value()); - } - - StorageOperationStatus status = getAndUpdateAllComponents(); - return status == StorageOperationStatus.OK ? MigrationResult.success() - : MigrationResult.error("failed to update interface operation data . Error : " + status); - } - - private StorageOperationStatus getAndUpdateAllComponents(){ - Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class); - hasNotProps.put(GraphPropertyEnum.IS_DELETED, true); - return janusGraphDao - .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, null, hasNotProps, JsonParseFlagEnum.ParseAll) - .either(this::updateComponentVertices, this::handleError); - } - - private StorageOperationStatus updateComponentVertices(List<GraphVertex> containersV) { - StorageOperationStatus status = StorageOperationStatus.OK; - for (GraphVertex container : containersV) { - status = updateDataOnGraph(container); - if (status != StorageOperationStatus.OK) { - break; - } - } - return status; - } - - private StorageOperationStatus handleError(JanusGraphOperationStatus err) { - janusGraphDao.rollback(); - return DaoStatusConverter.convertJanusGraphStatusToStorageStatus( - JanusGraphOperationStatus.NOT_FOUND == err ? JanusGraphOperationStatus.OK : err); - } - - private StorageOperationStatus updateDataOnGraph(GraphVertex componentVertex) { - try { - Either<GraphVertex, JanusGraphOperationStatus> interfaceVertexEither = - janusGraphDao - .getChildVertex(componentVertex, EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.ParseJson); - if (interfaceVertexEither.isLeft()) { - GraphVertex interfaceVertex = interfaceVertexEither.left().value(); - Map<String, InterfaceDataDefinition> interfaceDefinitions = (Map<String, InterfaceDataDefinition>) interfaceVertex.getJson(); - if(MapUtils.isNotEmpty(interfaceDefinitions)){ - for (Map.Entry<String, InterfaceDataDefinition> interfaceDefinition : interfaceDefinitions.entrySet()) { - if (StringUtils.isEmpty(interfaceDefinition.getValue().getType())) { - interfaceDefinition.getValue().setType(interfaceDefinition.getValue().getToscaResourceName()); - } - } - interfaceVertex.setJson(interfaceDefinitions); - Either<GraphVertex, JanusGraphOperationStatus> updateInterfaceVertexEither = janusGraphDao - .updateVertex(interfaceVertex); - if(updateInterfaceVertexEither.isRight()){ - return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateInterfaceVertexEither.right().value()); - } - } - - StorageOperationStatus statusRes = interfaceOperation.removeToscaDataVertex( - interfaceVertex, EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION); - if (statusRes != StorageOperationStatus.NOT_FOUND && statusRes != StorageOperationStatus.OK) { - return statusRes; - } - } - - Either<GraphVertex, JanusGraphOperationStatus> instInterfaceVertexEither = - janusGraphDao.getChildVertex(componentVertex, EdgeLabelEnum.INST_INTERFACES, JsonParseFlagEnum.ParseJson); - if (instInterfaceVertexEither.isLeft()) { - GraphVertex instInterfaceVertex = instInterfaceVertexEither.left().value(); - Map<String, MapInterfaceDataDefinition> instInterfaceDefinitions = (Map<String, MapInterfaceDataDefinition>) instInterfaceVertex.getJson(); - if(MapUtils.isNotEmpty(instInterfaceDefinitions)){ - for (Map.Entry<String, MapInterfaceDataDefinition> mapInstInterfaceDataDefinitions : instInterfaceDefinitions.entrySet()) { - for (Map.Entry<String, InterfaceDataDefinition> instInterfaceDataDefinitions : mapInstInterfaceDataDefinitions.getValue().getMapToscaDataDefinition().entrySet()) { - if (StringUtils.isEmpty(instInterfaceDataDefinitions.getValue().getType())) { - instInterfaceDataDefinitions.getValue().setType(instInterfaceDataDefinitions.getValue().getToscaResourceName()); - } - } - } - instInterfaceVertex.setJson(instInterfaceDefinitions); - Either<GraphVertex, JanusGraphOperationStatus> updateInstInterfaceVertexEither = janusGraphDao - .updateVertex(instInterfaceVertex); - if(updateInstInterfaceVertexEither.isRight()){ - return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateInstInterfaceVertexEither.right().value()); - } - } - } - - janusGraphDao.commit(); - } catch (Exception e) { - LOGGER.debug("Interface operation migration failed with error : ", e); - janusGraphDao.rollback(); - return StorageOperationStatus.GENERAL_ERROR; - } - - return StorageOperationStatus.OK; - } -}
\ No newline at end of file diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1902/SdcConsumerMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1902/SdcConsumerMigration.java deleted file mode 100644 index 16f0c485dc..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1902/SdcConsumerMigration.java +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2020 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.migration.tasks.mig1902; - -import fj.data.Either; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.resources.data.ConsumerData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.math.BigInteger; -import java.util.List; - -@Component -public class SdcConsumerMigration implements Migration { - - private static final Logger logger = LoggerFactory.getLogger(SdcConsumerMigration.class); - - private JanusGraphGenericDao janusGraphGenericDao; - - public SdcConsumerMigration(JanusGraphGenericDao janusGraphGenericDao) { - this.janusGraphGenericDao = janusGraphGenericDao; - } - - @Override - public String description() { - return "remove all consumer nodes"; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(1902), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - JanusGraphOperationStatus status = null; - try { - status = handleConsumerNodes(); - if (status == JanusGraphOperationStatus.OK){ - logger.info("removed all consumer nodes."); - return MigrationResult.success(); - } else { - return MigrationResult.error("failed to remove consumer nodes. error: " + status); - } - } finally { - commitOrRollBack(status); - } - } - - private void commitOrRollBack(JanusGraphOperationStatus status) { - if (status == JanusGraphOperationStatus.OK) { - janusGraphGenericDao.commit(); - } else { - janusGraphGenericDao.rollback(); - } - } - - private JanusGraphOperationStatus handleConsumerNodes() { - logger.info("getting all consumer nodes."); - return janusGraphGenericDao.getAll(NodeTypeEnum.ConsumerCredentials, ConsumerData.class) - .either(this::removeConsumerNodes, this::handleError); - } - - private JanusGraphOperationStatus removeConsumerNodes(List<ConsumerData> consumerNodes){ - logger.info("found {} consumer nodes.", consumerNodes.size()); - return consumerNodes.stream() - .map(consumerNode -> janusGraphGenericDao.deleteNode(consumerNode, ConsumerData.class)) - .filter(Either::isRight) - .map(either -> either.right().value()) - .findAny() - .orElse(JanusGraphOperationStatus.OK); - } - - private JanusGraphOperationStatus handleError(JanusGraphOperationStatus status){ - if (status == JanusGraphOperationStatus.NOT_FOUND) { - logger.info("found 0 consumer nodes."); - return JanusGraphOperationStatus.OK; - } else{ - return status; - } - } - -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1911/SdcDeploymentArtTimeOutMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1911/SdcDeploymentArtTimeOutMigration.java deleted file mode 100644 index af067403e7..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1911/SdcDeploymentArtTimeOutMigration.java +++ /dev/null @@ -1,152 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2020 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.migration.tasks.mig1911; - -import fj.data.Either; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.asdctool.migration.tasks.InstanceMigrationBase; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -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.datatypes.elements.ArtifactDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.openecomp.sdc.common.api.ArtifactTypeEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.math.BigInteger; -import java.util.Collection; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@Component -public class SdcDeploymentArtTimeOutMigration extends InstanceMigrationBase implements Migration { - - private static final Logger log = LoggerFactory.getLogger(SdcDeploymentArtTimeOutMigration.class); - private static Integer defaultTimeOut = 120; - - public SdcDeploymentArtTimeOutMigration(JanusGraphDao janusGraphDao) { - super(janusGraphDao); - } - - @Override - public String description() { - return "update instance deployment artifact timeOut to default value 120 minutes"; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(1911), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - StorageOperationStatus status = updateDeploymentArtifactTimeOut(); - return status == StorageOperationStatus.OK ? - MigrationResult.success() - : MigrationResult.error("failed to update instance deployment artifact timeOut. Error : " + status); - } - - protected StorageOperationStatus updateDeploymentArtifactTimeOut() { - Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); - Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - Either<List<GraphVertex>, JanusGraphOperationStatus> byCriteria = janusGraphDao - .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, - JsonParseFlagEnum.ParseAll); - return byCriteria.either(this::proceed, this::handleError); - } - - @Override - protected StorageOperationStatus handleOneContainer(GraphVertex containerVorig) { - StorageOperationStatus status = StorageOperationStatus.NOT_FOUND; - GraphVertex containerV = getVertexById(containerVorig.getUniqueId()); - - if (containerV == null) { - log.error("Unexpected null value for `containerV`"); - } else { - try { - Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao - .getChildVertex(containerV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, JsonParseFlagEnum.ParseAll); - GraphVertex instDeployArt = childVertex.left().value(); - Collection<MapArtifactDataDefinition> values = (Collection<MapArtifactDataDefinition>) instDeployArt - .getJson().values(); - List<ArtifactDataDefinition> artifactDataDefinitionsList = values.stream() - .map(f -> f.getMapToscaDataDefinition().values()) - .flatMap(f -> f.stream().filter(isRelevantArtifact())) - .collect(Collectors.toList()); - artifactDataDefinitionsList.forEach(t -> t.setTimeout(defaultTimeOut)); - status = updateVertexAndCommit(instDeployArt); - - } catch (NullPointerException e) { - log.error( - "Null Pointer Exception occurred - this mean we have zombie vertex, migration task will continue anyway", - e); - status = StorageOperationStatus.OK; - } catch (Exception e) { - //it is happy flow as well - log.error("Exception occurred:", e); - log.error( - "Migration task will continue anyway, please find below vertex details related to this exception", - e); - log.error("containerV.getUniqueId() {} ---> ", containerV.getUniqueId()); - - status = StorageOperationStatus.OK; - } finally { - if (status != StorageOperationStatus.OK) { - janusGraphDao.rollback(); - log.info("failed to update vertex ID {} ", containerV.getUniqueId()); - if (status == StorageOperationStatus.NOT_FOUND) { - //it is happy flow as well - status = StorageOperationStatus.OK; - } - } else { - log.info("vertex ID {} successfully updated", containerV.getUniqueId()); - } - } - } - - return status; - } - - private static Predicate<ArtifactDataDefinition> isRelevantArtifact() { - - return p -> ((p.getArtifactType().equals(ArtifactTypeEnum.HEAT.getType()) || p.getArtifactType() - .equals(ArtifactTypeEnum.HEAT_VOL.getType()) || p.getArtifactType() - .equals(ArtifactTypeEnum.HEAT_NET.getType())) - && p.getTimeout() != defaultTimeOut); - - } - -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesCERTIFIEDstateMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesCERTIFIEDstateMigration.java deleted file mode 100644 index 9cf56cf325..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesCERTIFIEDstateMigration.java +++ /dev/null @@ -1,154 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2020 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.migration.tasks.mig2002; - -import fj.data.Either; -import org.apache.tinkerpop.gremlin.structure.Direction; -import org.openecomp.sdc.asdctool.enums.DistributionStatusEnum; -import org.openecomp.sdc.asdctool.enums.LifecycleStateEnum; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.asdctool.migration.tasks.InstanceMigrationBase; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.math.BigInteger; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; - -@Component -public class SdcCollapsingRolesCERTIFIEDstateMigration extends InstanceMigrationBase implements Migration { - - private static final Logger log = LoggerFactory.getLogger(SdcCollapsingRolesCERTIFIEDstateMigration.class); - - public SdcCollapsingRolesCERTIFIEDstateMigration(JanusGraphDao janusGraphDao) { - super(janusGraphDao); - } - - @Override - public String description() { - return "remove LS=READY_FOR_CERTIFICATION edge from service node + migrate DISTRIBUTION approved/rejected states to <waiting for distribution> state"; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(2002), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - StorageOperationStatus status = updateServiceLifeCycleState(); - return status == StorageOperationStatus.OK ? - MigrationResult.success() : MigrationResult.error("failed to service state. Error : " + status); - } - - protected StorageOperationStatus updateServiceLifeCycleState() { - Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); - propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); - Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - Either<List<GraphVertex>, JanusGraphOperationStatus> byCriteria = janusGraphDao - .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, - JsonParseFlagEnum.ParseAll); - return byCriteria.either(this::proceed, this::handleError); - } - - @Override - protected StorageOperationStatus handleOneContainer(GraphVertex containerVorig) { - StorageOperationStatus status = StorageOperationStatus.NOT_FOUND; - GraphVertex containerV = getVertexById(containerVorig.getUniqueId()); - - if (containerV == null) { - log.error("Unexpected null value for `containerV`"); - } else { - try { - - //update edges to meet above change - // update LS eges from RFC to NOT_CERTIFIED_CHECKIN - - updateEdgeProperty(EdgePropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name(), - getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_STATE)); - - if (containerV.getMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS) - .equals(DistributionStatusEnum.DISTRIBUTION_APPROVED.name()) || containerV - .getMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS) - .equals(DistributionStatusEnum.DISTRIBUTION_REJECTED.name())) { - - // update vertex state property from DISTRIBUTION_APPROVED/REJECTED to DISTRIBUTION_NOT_APPROVED state - - Map<GraphPropertyEnum, Object> metadataProperties = containerV.getMetadataProperties(); - metadataProperties.put(GraphPropertyEnum.DISTRIBUTION_STATUS, - DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED.name()); - containerV.setMetadataProperties(metadataProperties); - - //update edges to meet above change - //delete LAST_DISTRIBUTION_STATE_MODIFIER edge - - removeEdges( - getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER)); - - } - - status = updateVertexAndCommit(containerV); - - } catch (NullPointerException e) { - log.error( - "Null Pointer Exception occurred - this mean we have zombie vertex, migration task will continue anyway", - e); - status = StorageOperationStatus.EXEUCTION_FAILED; - } catch (Exception e) { - //it is happy flow as well - log.error("Exception occurred:", e); - log.error( - "Migration task will continue anyway, please find below vertex details related to this exception", - e); - log.error("containerV.getUniqueId() ---> {} ", containerV.getUniqueId()); - - } finally { - if (status != StorageOperationStatus.OK) { - janusGraphDao.rollback(); - log.info("failed to update vertex ID {} ", containerV.getUniqueId()); - log.info("Storage Operation Status {}", status.toString()); - } else { - log.info("vertex ID {} successfully updated", containerV.getUniqueId()); - } - } - } - - return status; - } - - -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesCIPstateMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesCIPstateMigration.java deleted file mode 100644 index 463ccd8695..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesCIPstateMigration.java +++ /dev/null @@ -1,153 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2020 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.migration.tasks.mig2002; - -import fj.data.Either; -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.asdctool.enums.LifecycleStateEnum; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.asdctool.migration.tasks.InstanceMigrationBase; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.math.BigInteger; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -@Component -public class SdcCollapsingRolesCIPstateMigration extends InstanceMigrationBase implements Migration { - - private static final Logger log = LoggerFactory.getLogger(SdcCollapsingRolesCIPstateMigration.class); - - public SdcCollapsingRolesCIPstateMigration(JanusGraphDao janusGraphDao) { - super(janusGraphDao); - } - - @Override - public String description() { - return "update Service state from CERTIFICATION_IN_PROGRES to NOT_CERTIFIED_CHECKOUT state "; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(2002), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - StorageOperationStatus status = updateServiceLifeCycleState(); - return status == StorageOperationStatus.OK ? - MigrationResult.success() : MigrationResult.error("failed to service state. Error : " + status); - } - - protected StorageOperationStatus updateServiceLifeCycleState() { - Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); - propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFICATION_IN_PROGRESS.name()); - propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - Either<List<GraphVertex>, JanusGraphOperationStatus> byCriteria = janusGraphDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll); - return byCriteria.either(this::proceed, this::handleError); - } - - @Override - protected StorageOperationStatus handleOneContainer(GraphVertex containerVorig) { - StorageOperationStatus status = StorageOperationStatus.NOT_FOUND; - GraphVertex containerV = getVertexById(containerVorig.getUniqueId()); - try { - - // update vertex state property from READY_FOR_CERTIFICATION to NOT_CERTIFIED_CHECKIN state - - Map<GraphPropertyEnum, Object> metadataProperties = containerV.getMetadataProperties(); - metadataProperties.put(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name()); - containerV.setMetadataProperties(metadataProperties); - - //update edges to meet above change - // remove STATE and LAST_MODIFIER edges - removeEdges(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.STATE)); - removeEdges(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_MODIFIER)); - - //find designer with LS = NOT_CERTIFIED_CHECKIN - Vertex relevantDesigner = findRelevantDesigner(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_STATE)); - removeEdges(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_STATE)); - Map<EdgePropertyEnum, Object> edgeProperties = new HashMap<>(); - edgeProperties.put(EdgePropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name()); - JanusGraphOperationStatus createSTedgeStatus = janusGraphDao.createEdge(relevantDesigner, containerV.getVertex(), EdgeLabelEnum.STATE, edgeProperties); - JanusGraphOperationStatus createLMedgeStatus = janusGraphDao.createEdge(relevantDesigner, containerV.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>()); - - status = updateVertexAndCommit(containerV); - - } catch (NullPointerException e) { - log.error("Null Pointer Exception occurred - this mean we have zombie vertex, migration task will continue anyway", e); - status = StorageOperationStatus.EXEUCTION_FAILED; - } catch (Exception e) { - //it is happy flow as well - log.error("Exception occurred:", e); - log.error("Migration task will continue anyway, please find below vertex details related to this exception", e); - if (containerV != null) { - log.error("containerV.getUniqueId() ---> {} ", containerV.getUniqueId()); - } - - } finally { - if (status != StorageOperationStatus.OK) { - janusGraphDao.rollback(); - log.info("failed to update vertex ID {} ", containerV.getUniqueId()); - log.info("Storage Operation Status {}", status.toString()); - } else { - log.info("vertex ID {} successfully updated", containerV.getUniqueId()); - } - - } - return status; - } - - private Vertex findRelevantDesigner(Iterator<Edge> edges) { - Vertex vertex = null; - while (edges.hasNext()) { - Edge edge = edges.next(); - String state = (String) janusGraphDao.getProperty(edge, EdgePropertyEnum.STATE); - if (state.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name())) { - vertex = edge.outVertex(); - } - } - return vertex; - } - -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesRFCstateMigration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesRFCstateMigration.java deleted file mode 100644 index 559715ef5d..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesRFCstateMigration.java +++ /dev/null @@ -1,147 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2020 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.migration.tasks.mig2002; - -import fj.data.Either; -import org.apache.tinkerpop.gremlin.structure.Direction; -import org.janusgraph.core.JanusGraphVertex; -import org.openecomp.sdc.asdctool.enums.LifecycleStateEnum; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.Migration; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.asdctool.migration.tasks.InstanceMigrationBase; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.math.BigInteger; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Component -public class SdcCollapsingRolesRFCstateMigration extends InstanceMigrationBase implements Migration { - - private static final Logger log = LoggerFactory.getLogger(SdcCollapsingRolesRFCstateMigration.class); - - public SdcCollapsingRolesRFCstateMigration(JanusGraphDao janusGraphDao) { - super(janusGraphDao); - } - - @Override - public String description() { - return "update Service state from READY_FOR_CERTIFICATION to NOT_CERTIFIED_CHECKOUT state "; - } - - @Override - public DBVersion getVersion() { - return DBVersion.from(BigInteger.valueOf(2002), BigInteger.valueOf(0)); - } - - @Override - public MigrationResult migrate() { - StorageOperationStatus status = updateServiceLifeCycleState(); - return status == StorageOperationStatus.OK ? - MigrationResult.success() : MigrationResult.error("failed to service state. Error : " + status); - } - - protected StorageOperationStatus updateServiceLifeCycleState() { - Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); - propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.READY_FOR_CERTIFICATION.name()); - propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - Either<List<GraphVertex>, JanusGraphOperationStatus> byCriteria = janusGraphDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll); - return byCriteria.either(this::proceed, this::handleError); - } - - @Override - protected StorageOperationStatus handleOneContainer(GraphVertex containerVorig) { - StorageOperationStatus status = StorageOperationStatus.NOT_FOUND; - GraphVertex containerV = getVertexById(containerVorig.getUniqueId()); - try { - - // update vertex state property from READY_FOR_CERTIFICATION to NOT_CERTIFIED_CHECKIN state - - Map<GraphPropertyEnum, Object> metadataProperties = containerV.getMetadataProperties(); - metadataProperties.put(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name()); - containerV.setMetadataProperties(metadataProperties); - - //update edges to meet above change - - List<JanusGraphVertex> stateEdgesOutVertexList = getVertexByEdgeSide(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.STATE), EdgeSide.OUT); - List<JanusGraphVertex> lastStateEdgesOutVertexList = getVertexByEdgeSide(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_STATE), EdgeSide.OUT); - - if (sameUser(stateEdgesOutVertexList, lastStateEdgesOutVertexList)) { - updateEdgeProperty(EdgePropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name(), getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.STATE)); - removeEdges(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_STATE)); - } else { - removeEdges(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.STATE)); - removeEdges(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_STATE)); - Map<EdgePropertyEnum, Object> edgeProperties = new HashMap<>(); - edgeProperties.put(EdgePropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name()); - janusGraphDao.createEdge(lastStateEdgesOutVertexList.get(0), containerV.getVertex(), EdgeLabelEnum.STATE, edgeProperties); - - } - - status = updateVertexAndCommit(containerV); - - } catch (NullPointerException e) { - log.error("Null Pointer Exception occurred - this mean we have zombie vertex, migration task will continue anyway", e); - status = StorageOperationStatus.EXEUCTION_FAILED; - } catch (Exception e) { - //it is happy flow as well - log.error("Exception occurred:", e); - log.error("Migration task will ?" + - "" + - "" + - ", please find below vertex details related to this exception", e); - if (containerV != null) { - log.error("containerV.getUniqueId() ---> {} ", containerV.getUniqueId()); - } - - } finally { - if (status != StorageOperationStatus.OK) { - janusGraphDao.rollback(); - log.info("failed to update vertex ID {} ", containerV.getUniqueId()); - log.info("Storage Operation Status {}", status.toString()); - } else { - log.info("vertex ID {} successfully updated", containerV.getUniqueId()); - } - - } - return status; - } - - -} |