1 package org.openecomp.sdc.asdctool.migration.tasks.mig1806;
4 import org.openecomp.sdc.asdctool.migration.core.DBVersion;
5 import org.openecomp.sdc.asdctool.migration.core.task.Migration;
6 import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
7 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
8 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
9 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
10 import org.openecomp.sdc.be.dao.jsongraph.utils.IdBuilderUtils;
11 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
12 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
13 import org.openecomp.sdc.common.log.wrappers.Logger;
14 import org.springframework.stereotype.Component;
16 import java.math.BigInteger;
19 public class SdcArchiveMigration implements Migration {
20 private static final Logger logger = Logger.getLogger(SdcArchiveMigration.class);
22 private TitanDao titanDao;
24 public SdcArchiveMigration(TitanDao titanDao) {
25 this.titanDao = titanDao;
29 public String description() {
30 return "add archive node for archiving/restoring components ";
34 public DBVersion getVersion() {
35 return DBVersion.from(BigInteger.valueOf(1806), BigInteger.valueOf(0));
39 public MigrationResult migrate() {
40 TitanOperationStatus status = null;
42 status = getOrCreateArchiveRoot();
43 return status == TitanOperationStatus.OK ? MigrationResult.success() : MigrationResult.error("failed to create archive root node. error: " + status);
45 commitOrRollBack(status);
49 private void commitOrRollBack(TitanOperationStatus status) {
50 if (status == TitanOperationStatus.OK) {
57 private TitanOperationStatus getOrCreateArchiveRoot() {
58 logger.info("creating or getting catalog archive vertex");
59 return titanDao.getVertexByLabel(VertexTypeEnum.ARCHIVE_ROOT)
60 .either(v -> TitanOperationStatus.OK, s -> this.createRootArchiveVertex());
63 private TitanOperationStatus createRootArchiveVertex() {
64 GraphVertex archiveRootVertex = new GraphVertex(VertexTypeEnum.ARCHIVE_ROOT);
65 archiveRootVertex.setUniqueId(IdBuilderUtils.generateUniqueId());
66 archiveRootVertex.addMetadataProperty(GraphPropertyEnum.LABEL, VertexTypeEnum.ARCHIVE_ROOT);
67 archiveRootVertex.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, archiveRootVertex.getUniqueId());
69 logger.info("Creating root archive vertex {}", archiveRootVertex.getUniqueId());
71 final Either<GraphVertex, TitanOperationStatus> vertexE = titanDao.createVertex(archiveRootVertex);
73 return vertexE.isLeft() ? TitanOperationStatus.OK : vertexE.right().value();