From defcbad3b225e098be507b99ae5ea5f6ef587399 Mon Sep 17 00:00:00 2001 From: ChrisC Date: Fri, 12 Mar 2021 15:54:32 +0100 Subject: Remove unused code Remove unused and untested or poorly tested code for migrating old DB Issue-ID: SDC-3428 Signed-off-by: ChrisC Change-Id: I39b086111b5be8d1caf4d6d45bf92105d03709eb --- .../migration/tasks/InstanceMigrationBase.java | 16 -- .../tasks/mig1802/SdcCatalogMigration.java | 168 -------------- .../tasks/mig1806/ForwardPathMigration.java | 256 --------------------- .../tasks/mig1806/ResourceLifecycleMigration.java | 159 ------------- .../tasks/mig1806/SDCInstancesMigration.java | 236 ------------------- .../tasks/mig1806/SdcArchiveMigration.java | 96 -------- .../tasks/mig1902/InterfaceOperationMigration.java | 172 -------------- .../tasks/mig1902/SdcConsumerMigration.java | 108 --------- .../mig1911/SdcDeploymentArtTimeOutMigration.java | 152 ------------ .../SdcCollapsingRolesCERTIFIEDstateMigration.java | 154 ------------- .../SdcCollapsingRolesCIPstateMigration.java | 153 ------------ .../SdcCollapsingRolesRFCstateMigration.java | 147 ------------ .../tasks/mig1802/SdcCatalogMigrationTest.java | 65 ------ .../tasks/mig1806/ForwardPathMigrationTest.java | 77 ------- .../mig1806/ResourceLifecycleMigrationTest.java | 74 ------ .../tasks/mig1806/SDCInstancesMigrationTest.java | 95 -------- .../tasks/mig1806/SdcArchiveMigrationTest.java | 66 ------ .../asdctool/migration/tasks/mig1806/Version.java | 36 --- 18 files changed, 2230 deletions(-) delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1802/SdcCatalogMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ForwardPathMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ResourceLifecycleMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SdcArchiveMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1902/InterfaceOperationMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1902/SdcConsumerMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1911/SdcDeploymentArtTimeOutMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesCERTIFIEDstateMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesCIPstateMigration.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig2002/SdcCollapsingRolesRFCstateMigration.java delete mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1802/SdcCatalogMigrationTest.java delete mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ForwardPathMigrationTest.java delete mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ResourceLifecycleMigrationTest.java delete mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigrationTest.java delete mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SdcArchiveMigrationTest.java delete mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/Version.java (limited to 'asdctool/src') 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 getVertexByEdgeSide(Iterator edges, SdcCollapsingRolesRFCstateMigration.EdgeSide side) { - List 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 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 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 getOrCreateCatalogRoot() { - LOGGER.info("creating or getting catalog root vertex"); - return janusGraphDao.getVertexByLabel(VertexTypeEnum.CATALOG_ROOT) - .right() - .bind(this::createRootCatalogVertexOrError); - } - - - private Either createRootCatalogVertexOrError(JanusGraphOperationStatus janusGraphOperationStatus) { - return janusGraphOperationStatus == JanusGraphOperationStatus.NOT_FOUND ? createRootCatalogVertex() : Either.right( - janusGraphOperationStatus); - } - - private Either createRootCatalogVertex() { - LOGGER.info("Creating root catalog vertex"); - GraphVertex catalogRootVertex = new GraphVertex(VertexTypeEnum.CATALOG_ROOT); - catalogRootVertex.setUniqueId(IdBuilderUtils.generateUniqueId()); - return janusGraphDao.createVertex(catalogRootVertex); - } - - private Either, 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, JanusGraphOperationStatus> errOrEmptyListIfNotFound(JanusGraphOperationStatus err) { - return JanusGraphOperationStatus.NOT_FOUND.equals(err) ? Either.left(new ArrayList<>()) : Either.right(err); - } - - @SuppressWarnings("unchecked") - private Either, JanusGraphOperationStatus> getAllCatalogVertices(List 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 catalogElements) { - LOGGER.info("number of catalog elements: {}", catalogElements.size()); - LOGGER.info("connect all catalog elements to root edge"); - List 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 userData = (Either) 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 hasProps = new EnumMap<>(GraphPropertyEnum.class); - hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); - Map 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 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 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 getResponse = janusGraphDao.getVertexById(service.getUniqueId(), - JsonParseFlagEnum.NoParse); - if (getResponse.isRight()) { - return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getResponse.right().value()); - - } - Set 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 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 forwardingPaths = new HashMap<>( - (Map) toscaDataVertex.getJson()); - List toBeDeletedFP = new ArrayList<>(); - for (Map.Entry forwardingPathDataDefinition : forwardingPaths - .entrySet()) { - Set 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 updatevertexEither = updateOrCopyOnUpdate( - toscaDataVertex, componentVertex); - if (updatevertexEither.isRight()) { - janusGraphDao.rollback(); - return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updatevertexEither.right().value()); - } - janusGraphDao.commit(); - return StorageOperationStatus.OK; - } - - private Either 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 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 updateOrCopyOnUpdate(GraphVertex dataVertex, GraphVertex toscaElementVertex ) { - EdgeLabelEnum label = EdgeLabelEnum.FORWARDING_PATH; - Iterator 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 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 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 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 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 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 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 instanceProperties = null; - if (componentType == ComponentTypeEnum.RESOURCE) { - Either 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 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, StorageOperationStatus> instProperties = getInstProperties(containerV); - if ( instProperties.isRight() ){ - return instProperties.right().value(); - } - instanceProperties = instProperties.left().value(); - } - } - Map jsonComposition = (Map) 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, StorageOperationStatus> getInstProperties(GraphVertex containerV) { - Map instanceProperties; - Either 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) instProps.left().value().getJson(); - } - return Either.left(instanceProperties); - } - - private StorageOperationStatus connectInstances(GraphVertex containerV, boolean needConnectAllotted, Map instanceProperties, - Map jsonComposition) { - StorageOperationStatus status = StorageOperationStatus.OK; - CompositionDataDefinition compositionDataDefinition = jsonComposition.get(JsonConstantKeysEnum.COMPOSITION.getValue()); - Map componentInstances = compositionDataDefinition.getComponentInstances(); - for (Map.Entry 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 instanceProperties, Map.Entry 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 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 mapToscaDataDefinition = mapPropertiesDataDefinition.getMapToscaDataDefinition(); - StorageOperationStatus status = StorageOperationStatus.OK; - Optional> 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 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 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 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 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 interfaceVertexEither = - janusGraphDao - .getChildVertex(componentVertex, EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.ParseJson); - if (interfaceVertexEither.isLeft()) { - GraphVertex interfaceVertex = interfaceVertexEither.left().value(); - Map interfaceDefinitions = (Map) interfaceVertex.getJson(); - if(MapUtils.isNotEmpty(interfaceDefinitions)){ - for (Map.Entry interfaceDefinition : interfaceDefinitions.entrySet()) { - if (StringUtils.isEmpty(interfaceDefinition.getValue().getType())) { - interfaceDefinition.getValue().setType(interfaceDefinition.getValue().getToscaResourceName()); - } - } - interfaceVertex.setJson(interfaceDefinitions); - Either 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 instInterfaceVertexEither = - janusGraphDao.getChildVertex(componentVertex, EdgeLabelEnum.INST_INTERFACES, JsonParseFlagEnum.ParseJson); - if (instInterfaceVertexEither.isLeft()) { - GraphVertex instInterfaceVertex = instInterfaceVertexEither.left().value(); - Map instInterfaceDefinitions = (Map) instInterfaceVertex.getJson(); - if(MapUtils.isNotEmpty(instInterfaceDefinitions)){ - for (Map.Entry mapInstInterfaceDataDefinitions : instInterfaceDefinitions.entrySet()) { - for (Map.Entry instInterfaceDataDefinitions : mapInstInterfaceDataDefinitions.getValue().getMapToscaDataDefinition().entrySet()) { - if (StringUtils.isEmpty(instInterfaceDataDefinitions.getValue().getType())) { - instInterfaceDataDefinitions.getValue().setType(instInterfaceDataDefinitions.getValue().getToscaResourceName()); - } - } - } - instInterfaceVertex.setJson(instInterfaceDefinitions); - Either 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 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 propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); - Map propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - Either, 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 childVertex = janusGraphDao - .getChildVertex(containerV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, JsonParseFlagEnum.ParseAll); - GraphVertex instDeployArt = childVertex.left().value(); - Collection values = (Collection) instDeployArt - .getJson().values(); - List 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 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 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 propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); - propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); - Map propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - Either, 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 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 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 propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - Either, 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 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 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 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 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 propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); - propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - Either, 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 metadataProperties = containerV.getMetadataProperties(); - metadataProperties.put(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name()); - containerV.setMetadataProperties(metadataProperties); - - //update edges to meet above change - - List stateEdgesOutVertexList = getVertexByEdgeSide(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.STATE), EdgeSide.OUT); - List 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 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; - } - - -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1802/SdcCatalogMigrationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1802/SdcCatalogMigrationTest.java deleted file mode 100644 index 2223d2847d..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1802/SdcCatalogMigrationTest.java +++ /dev/null @@ -1,65 +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 org.junit.Test; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation; - -public class SdcCatalogMigrationTest { - - private SdcCatalogMigration createTestSubject() { - return new SdcCatalogMigration(new TopologyTemplateOperation(), new JanusGraphDao(new JanusGraphClient())); - } - - @Test - public void testDescription() throws Exception { - SdcCatalogMigration testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.description(); - } - - @Test - public void testGetVersion() throws Exception { - SdcCatalogMigration testSubject; - DBVersion result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getVersion(); - } - - @Test - public void testMigrate() throws Exception { - SdcCatalogMigration testSubject; - MigrationResult result; - - // default test - testSubject = createTestSubject(); - result = testSubject.migrate(); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ForwardPathMigrationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ForwardPathMigrationTest.java deleted file mode 100644 index 5a1f0bf0dc..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ForwardPathMigrationTest.java +++ /dev/null @@ -1,77 +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 static org.junit.Assert.assertThat; - -import java.math.BigInteger; -import org.hamcrest.core.Is; -import org.hamcrest.core.IsNull; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; -import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation; - -@ExtendWith(MockitoExtension.class) -class ForwardPathMigrationTest { - - private ForwardPathMigration forwardPathMigration = null; - - @Mock - private JanusGraphDao janusGraphDao; - - @Mock - private UserAdminOperation userAdminOperation; - - @Mock - private ToscaOperationFacade toscaOperationFacade; - - @BeforeEach - public void setUp() throws Exception { - forwardPathMigration = new ForwardPathMigration(janusGraphDao, userAdminOperation, toscaOperationFacade); - } - - @Test - void testDescription() { - assertThat(forwardPathMigration, IsNull.notNullValue()); - assertThat("remove corrupted forwarding paths ", Is.is(forwardPathMigration.description())); - } - - @Test - void testGetVersion() { - DBVersion dbVersion = DBVersion.from(BigInteger.valueOf(Version.MAJOR.getValue()), BigInteger.valueOf(Version.MINOR.getValue())); - assertThat(dbVersion, Is.is(forwardPathMigration.getVersion())); - } - - @Test - void testMigrate() { - assertThat(forwardPathMigration, IsNull.notNullValue()); - Assertions.assertThrows(NullPointerException.class, () -> { - forwardPathMigration.migrate(); - }); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ResourceLifecycleMigrationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ResourceLifecycleMigrationTest.java deleted file mode 100644 index d11f70c4bb..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/ResourceLifecycleMigrationTest.java +++ /dev/null @@ -1,74 +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 org.hamcrest.core.Is; -import org.hamcrest.core.IsNull; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation; - -import java.math.BigInteger; - -import static org.junit.Assert.assertThat; - -@RunWith(MockitoJUnitRunner.class) -public class ResourceLifecycleMigrationTest { - - @Mock - private JanusGraphDao janusGraphDao; - @Mock - private LifecycleBusinessLogic lifecycleBusinessLogic; - @Mock - private UserAdminOperation userAdminOperation; - - ResourceLifecycleMigration resourceLifecycleMigration = null; - - @Before - public void setUp() throws Exception { - resourceLifecycleMigration = - new ResourceLifecycleMigration(janusGraphDao, lifecycleBusinessLogic, userAdminOperation); - } - - @Test - public void testDescription() { - assertThat(resourceLifecycleMigration,IsNull.notNullValue()); - assertThat("change resource lifecycle state from testing to certified", Is.is(resourceLifecycleMigration.description())); - } - - @Test - public void testGetVersion() { - DBVersion dbVersion = DBVersion.from(BigInteger.valueOf(Version.MAJOR.getValue()), BigInteger.valueOf(Version.MINOR.getValue())); - assertThat(dbVersion, Is.is(resourceLifecycleMigration.getVersion())); - } - - @Test(expected = NullPointerException.class) - public void testMigrate() { - assertThat(resourceLifecycleMigration,IsNull.notNullValue()); - resourceLifecycleMigration.migrate(); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigrationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigrationTest.java deleted file mode 100644 index 4721b1eb02..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigrationTest.java +++ /dev/null @@ -1,95 +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.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; -import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult.MigrationStatus; -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.datatypes.elements.ComponentInstanceDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -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 java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class SDCInstancesMigrationTest{ - @Mock - private JanusGraphDao janusGraphDao; - @Mock - private NodeTemplateOperation nodeTemplateOperation; - @Mock - GraphVertex topologyTemplateVertex; - - - @Test - public void testFailedMigration(){ - SDCInstancesMigration instancesMigration = new SDCInstancesMigration(janusGraphDao, nodeTemplateOperation); - when(janusGraphDao.getByCriteria(any(), any(), any(), any() )).thenReturn(Either.right( - JanusGraphOperationStatus.GENERAL_ERROR)); - - MigrationResult migrate = instancesMigration.migrate(); - MigrationStatus migrationStatus = migrate.getMigrationStatus(); - assertEquals(MigrationStatus.FAILED, migrationStatus); - } - @Test - public void testSuccessMigration(){ - SDCInstancesMigration instancesMigration = new SDCInstancesMigration(janusGraphDao, nodeTemplateOperation); - List list = new ArrayList<>(); - GraphVertex vertexOrig = new GraphVertex(); - Map jsonComposition = new HashMap<>(); - CompositionDataDefinition composition = new CompositionDataDefinition(); - Map componentInstances = new HashMap<>(); - ComponentInstanceDataDefinition instance = new ComponentInstanceDataDefinition(); - componentInstances.put("instanceId", instance); - composition.setComponentInstances(componentInstances); - jsonComposition.put(JsonConstantKeysEnum.COMPOSITION.getValue(), composition); - vertexOrig.setJson(jsonComposition); - vertexOrig.setType(ComponentTypeEnum.SERVICE); - list.add(vertexOrig); - - - when(janusGraphDao.getVertexById(any())).thenReturn(Either.left(vertexOrig)); - when(janusGraphDao.getByCriteria(any(), any(), any(), any() )).thenReturn(Either.left(list)); - when(nodeTemplateOperation.createInstanceEdge(vertexOrig, instance)).thenReturn(StorageOperationStatus.OK); - when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK); - - MigrationResult migrate = instancesMigration.migrate(); - MigrationStatus migrationStatus = migrate.getMigrationStatus(); - assertEquals(MigrationStatus.COMPLETED, migrationStatus); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SdcArchiveMigrationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SdcArchiveMigrationTest.java deleted file mode 100644 index 03695367b0..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SdcArchiveMigrationTest.java +++ /dev/null @@ -1,66 +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 org.hamcrest.core.Is; -import org.hamcrest.core.IsNull; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.sdc.asdctool.migration.core.DBVersion; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; - -import java.math.BigInteger; - -import static org.junit.Assert.assertThat; - -@RunWith(MockitoJUnitRunner.class) -public class SdcArchiveMigrationTest { - @Mock - private JanusGraphDao janusGraphDao; - - SdcArchiveMigration sdcArchiveMigration = null; - - @Before - public void setUp() throws Exception { - sdcArchiveMigration = new SdcArchiveMigration(janusGraphDao); - } - - @Test - public void testDescription() { - assertThat(sdcArchiveMigration,IsNull.notNullValue()); - assertThat("add archive node for archiving/restoring components ", Is.is(sdcArchiveMigration.description())); - } - - @Test - public void testGetVersion() { - DBVersion dbVersion = DBVersion.from(BigInteger.valueOf(Version.MAJOR.getValue()), BigInteger.valueOf(Version.MINOR.getValue())); - assertThat(dbVersion, Is.is(sdcArchiveMigration.getVersion())); - } - - @Test(expected = NullPointerException.class) - public void testMigrate() { - assertThat(sdcArchiveMigration,IsNull.notNullValue()); - sdcArchiveMigration.migrate(); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/Version.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/Version.java deleted file mode 100644 index 9df5232cce..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/Version.java +++ /dev/null @@ -1,36 +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; - -public enum Version { - - MINOR(0), MAJOR(1806); - - private final int value; - - private Version(final int newValue) { - value = newValue; - } - - public int getValue() { - return value; - } -} -- cgit 1.2.3-korg