-package org.openecomp.sdc.be.model.jsontitan.operations;
+package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
import fj.data.Either;
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.TitanDao;
+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.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
+import org.openecomp.sdc.be.model.jsonjanusgraph.enums.JsonConstantKeysEnum;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
import java.util.*;
import java.util.stream.Collectors;
-import static org.openecomp.sdc.be.model.jsontitan.operations.ArchiveOperation.Action.ARCHIVE;
-import static org.openecomp.sdc.be.model.jsontitan.operations.ArchiveOperation.Action.RESTORE;
+import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArchiveOperation.Action.ARCHIVE;
+import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArchiveOperation.Action.RESTORE;
/**
* Created by yavivi on 25/03/2018.
ARCHIVE, RESTORE;
}
- public ArchiveOperation(TitanDao titanDao, IGraphLockOperation graphLockOperation){
- this.titanDao = titanDao;
+ public ArchiveOperation(JanusGraphDao janusGraphDao, IGraphLockOperation graphLockOperation){
+ this.janusGraphDao = janusGraphDao;
this.graphLockOperation = graphLockOperation;
}
public Either<List<String>, ActionStatus> archiveComponent(String componentId) {
- final Either<GraphVertex, TitanOperationStatus> vertexResult = this.titanDao.getVertexById(componentId);
+ final Either<GraphVertex, JanusGraphOperationStatus> vertexResult = this.janusGraphDao.getVertexById(componentId);
if (vertexResult.isLeft()){
return doAction(ARCHIVE, vertexResult.left().value());
} else {
}
public Either<List<String>, ActionStatus> restoreComponent(String componentId) {
- final Either<GraphVertex, TitanOperationStatus> vertexResult = this.titanDao.getVertexById(componentId);
+ final Either<GraphVertex, JanusGraphOperationStatus> vertexResult = this.janusGraphDao.getVertexById(componentId);
if (vertexResult.isLeft()){
return doAction(RESTORE, vertexResult.left().value());
} else {
private ActionStatus onVspStateChanged(Action action, String csarId) {
Map<GraphPropertyEnum, Object> props = new HashMap<>();
props.put(GraphPropertyEnum.CSAR_UUID, csarId);
- Either<List<GraphVertex>, TitanOperationStatus> vfsE = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props);
+ Either<List<GraphVertex>, JanusGraphOperationStatus> vfsE = janusGraphDao
+ .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props);
return vfsE.either(vList -> setVspArchived(action, vList), s -> onError("VSP_"+action.name(), csarId, s));
}
GraphVertex highestVersion = this.getHighestVersionFrom(vList.get(0));
StorageOperationStatus lockStatus = this.graphLockOperation.lockComponent(highestVersion.getUniqueId(), highestVersion.getType().getNodeType());
if (lockStatus != StorageOperationStatus.OK){
- return onError(action.name(), highestVersion.getUniqueId(), TitanOperationStatus.ALREADY_LOCKED);
+ return onError(action.name(), highestVersion.getUniqueId(), JanusGraphOperationStatus.ALREADY_LOCKED);
}
try {
boolean val = action == ARCHIVE ? true : false;
v.setJsonMetadataField(JsonPresentationFields.IS_VSP_ARCHIVED, val);
v.addMetadataProperty(GraphPropertyEnum.IS_VSP_ARCHIVED, val);
- titanDao.updateVertex(v);
+ janusGraphDao.updateVertex(v);
}
return commitAndCheck("VSP_"+action.name(), vList.toString());
} finally {
public List<String> setArchivedOriginsFlagInComponentInstances(GraphVertex compositionService) {
List<String> ciUidsWithArchivedOrigins = new LinkedList();
- Either<List<GraphVertex>, TitanOperationStatus> instanceOfVerticesE = titanDao.getChildrenVertecies(compositionService, EdgeLabelEnum.INSTANCE_OF, JsonParseFlagEnum.NoParse);
- Either<List<GraphVertex>, TitanOperationStatus> proxyOfVerticesE = titanDao.getChildrenVertecies(compositionService, EdgeLabelEnum.PROXY_OF, JsonParseFlagEnum.NoParse);
+ Either<List<GraphVertex>, JanusGraphOperationStatus> instanceOfVerticesE = janusGraphDao
+ .getChildrenVertecies(compositionService, EdgeLabelEnum.INSTANCE_OF, JsonParseFlagEnum.NoParse);
+ Either<List<GraphVertex>, JanusGraphOperationStatus> proxyOfVerticesE = janusGraphDao
+ .getChildrenVertecies(compositionService, EdgeLabelEnum.PROXY_OF, JsonParseFlagEnum.NoParse);
List<GraphVertex> all = new LinkedList<>();
if (instanceOfVerticesE.isLeft()){
//Lock the Highest Version
StorageOperationStatus lockStatus = this.graphLockOperation.lockComponent(highestVersion.getUniqueId(), highestVersion.getType().getNodeType());
if (lockStatus != StorageOperationStatus.OK){
- return Either.right(onError(action.name(), componentVertex.getUniqueId(), TitanOperationStatus.ALREADY_LOCKED));
+ return Either.right(onError(action.name(), componentVertex.getUniqueId(), JanusGraphOperationStatus.ALREADY_LOCKED));
}
//Refetch latest version with full parsing
- highestVersion = this.titanDao.getVertexById(highestVersion.getUniqueId(), JsonParseFlagEnum.ParseAll).left().value();
+ highestVersion = this.janusGraphDao
+ .getVertexById(highestVersion.getUniqueId(), JsonParseFlagEnum.ParseAll).left().value();
try {
//Get Catalog and Archive Roots
- GraphVertex catalogRoot = titanDao.getVertexByLabel(VertexTypeEnum.CATALOG_ROOT).left().value();
- GraphVertex archiveRoot = titanDao.getVertexByLabel(VertexTypeEnum.ARCHIVE_ROOT).left().value();
+ GraphVertex catalogRoot = janusGraphDao.getVertexByLabel(VertexTypeEnum.CATALOG_ROOT).left().value();
+ GraphVertex archiveRoot = janusGraphDao.getVertexByLabel(VertexTypeEnum.ARCHIVE_ROOT).left().value();
if (action == ARCHIVE) {
archiveEdges(catalogRoot, archiveRoot, highestVersion);
restoreEdges(catalogRoot, archiveRoot, highestVersion);
}
setPropertiesByAction(highestVersion, action);
- titanDao.updateVertex(highestVersion);
+ janusGraphDao.updateVertex(highestVersion);
List<String> affectedComponentIds = handleParents(highestVersion, catalogRoot, archiveRoot, action);
ActionStatus sc = commitAndCheck(action.name(), highestVersion.getUniqueId());
}
private ActionStatus commitAndCheck(String action, String componentId) {
- TitanOperationStatus status = titanDao.commit();
- if (!status.equals(TitanOperationStatus.OK)){
+ JanusGraphOperationStatus status = janusGraphDao.commit();
+ if (!status.equals(JanusGraphOperationStatus.OK)){
return onError(action, componentId, status);
}
return ActionStatus.OK;
* @return
*/
private GraphVertex getHighestVersionFrom(GraphVertex v) {
- Either<GraphVertex, TitanOperationStatus> childVertexE = titanDao.getChildVertex(v, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+ Either<GraphVertex, JanusGraphOperationStatus> childVertexE = janusGraphDao
+ .getChildVertex(v, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
GraphVertex highestVersionVertex = v;
while (childVertexE.isLeft()) {
highestVersionVertex = childVertexE.left().value();
- childVertexE = titanDao.getChildVertex(highestVersionVertex, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+ childVertexE = janusGraphDao
+ .getChildVertex(highestVersionVertex, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
}
return highestVersionVertex;
}
}
private List<String> handleParents(GraphVertex v, GraphVertex catalogRoot, GraphVertex archiveRoot, Action action) {
- Either<GraphVertex, TitanOperationStatus> parentVertexE = titanDao.getParentVertex(v, EdgeLabelEnum.VERSION, JsonParseFlagEnum.ParseAll);
+ Either<GraphVertex, JanusGraphOperationStatus> parentVertexE = janusGraphDao
+ .getParentVertex(v, EdgeLabelEnum.VERSION, JsonParseFlagEnum.ParseAll);
List<String> affectedCompIds = new ArrayList();
affectedCompIds.add(v.getUniqueId());
}
}
setPropertiesByAction(cv, action);
- titanDao.updateVertex(cv);
- parentVertexE = titanDao.getParentVertex(cv, EdgeLabelEnum.VERSION, JsonParseFlagEnum.ParseAll);
+ janusGraphDao.updateVertex(cv);
+ parentVertexE = janusGraphDao
+ .getParentVertex(cv, EdgeLabelEnum.VERSION, JsonParseFlagEnum.ParseAll);
}
return affectedCompIds;
}
private void archiveEdges(GraphVertex catalogRoot, GraphVertex archiveRoot, GraphVertex v) {
- titanDao.deleteAllEdges(catalogRoot, v, EdgeLabelEnum.CATALOG_ELEMENT);
- titanDao.createEdge(archiveRoot, v, EdgeLabelEnum.ARCHIVE_ELEMENT, null);
+ janusGraphDao.deleteAllEdges(catalogRoot, v, EdgeLabelEnum.CATALOG_ELEMENT);
+ janusGraphDao.createEdge(archiveRoot, v, EdgeLabelEnum.ARCHIVE_ELEMENT, null);
setPropertiesByAction(v, ARCHIVE);
}
private void restoreEdges(GraphVertex catalogRoot, GraphVertex archiveRoot, GraphVertex v) {
- titanDao.deleteAllEdges(archiveRoot, v, EdgeLabelEnum.ARCHIVE_ELEMENT);
- titanDao.createEdge(catalogRoot, v, EdgeLabelEnum.CATALOG_ELEMENT, null);
+ janusGraphDao.deleteAllEdges(archiveRoot, v, EdgeLabelEnum.ARCHIVE_ELEMENT);
+ janusGraphDao.createEdge(catalogRoot, v, EdgeLabelEnum.CATALOG_ELEMENT, null);
setPropertiesByAction(v, RESTORE);
}
v.setJsonMetadataField(JsonPresentationFields.ARCHIVE_TIME, now);
}
- private ActionStatus onError(String action, String componentId, TitanOperationStatus s) {
+ private ActionStatus onError(String action, String componentId, JanusGraphOperationStatus s) {
ActionStatus ret = ActionStatus.GENERAL_ERROR;
- if (s == TitanOperationStatus.NOT_FOUND){
+ if (s == JanusGraphOperationStatus.NOT_FOUND){
ret = ActionStatus.RESOURCE_NOT_FOUND;
- } else if (s == TitanOperationStatus.ALREADY_LOCKED) {
+ } else if (s == JanusGraphOperationStatus.ALREADY_LOCKED) {
ret = ActionStatus.COMPONENT_IN_USE;
}
String retCodeVal = ret.name();