summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris André <chris.andre@yoppworks.com>2020-04-16 16:29:05 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-04-20 07:11:43 +0000
commit659556d07ad5b928cb0032f040dc86fcb11944c8 (patch)
treed8cd6bbb6cd960ce8ee76bd9c9248152a8d68ab7
parent8429c539b48ce851f98e086f5a722c13ebcdc151 (diff)
Added early check for null value for `containerV`
- Formatting code following project's code style - Added early check for null value for `containerV` Issue-ID: SDC-2904 Signed-off-by: Chris Andre <chris.andre@yoppworks.com> Change-Id: Ib8d7c1bf36608855c73d8a0df637e86aefce9377
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1911/SdcDeploymentArtTimeOutMigration.java81
1 files changed, 48 insertions, 33 deletions
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
index cba562750a..af067403e7 100644
--- 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
@@ -73,7 +73,8 @@ public class SdcDeploymentArtTimeOutMigration extends InstanceMigrationBase impl
public MigrationResult migrate() {
StorageOperationStatus status = updateDeploymentArtifactTimeOut();
return status == StorageOperationStatus.OK ?
- MigrationResult.success() : MigrationResult.error("failed to update instance deployment artifact timeOut. Error : " + status);
+ MigrationResult.success()
+ : MigrationResult.error("failed to update instance deployment artifact timeOut. Error : " + status);
}
protected StorageOperationStatus updateDeploymentArtifactTimeOut() {
@@ -81,7 +82,9 @@ public class SdcDeploymentArtTimeOutMigration extends InstanceMigrationBase impl
propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
- Either<List<GraphVertex>, JanusGraphOperationStatus> byCriteria = janusGraphDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
+ Either<List<GraphVertex>, JanusGraphOperationStatus> byCriteria = janusGraphDao
+ .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch,
+ JsonParseFlagEnum.ParseAll);
return byCriteria.either(this::proceed, this::handleError);
}
@@ -89,48 +92,60 @@ public class SdcDeploymentArtTimeOutMigration extends InstanceMigrationBase impl
protected StorageOperationStatus handleOneContainer(GraphVertex containerVorig) {
StorageOperationStatus status = StorageOperationStatus.NOT_FOUND;
GraphVertex containerV = getVertexById(containerVorig.getUniqueId());
- try {
- Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(containerV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, JsonParseFlagEnum.ParseAll);
- GraphVertex instDeployArt = childVertex.left().value();
- Collection<MapArtifactDataDefinition> values = (Collection<MapArtifactDataDefinition>) instDeployArt.getJson().values();
- List<ArtifactDataDefinition> artifactDataDefinitionsList = values.stream().map(f -> f.getMapToscaDataDefinition().values()).flatMap(f -> f.stream().filter(isRelevantArtifact())).collect(Collectors.toList());
- artifactDataDefinitionsList.forEach(t -> t.setTimeout(defaultTimeOut));
- status = updateVertexAndCommit(instDeployArt);
- } catch (NullPointerException e) {
- log.error("Null Pointer Exception occurred - this mean we have zombie vertex, migration task will continue anyway", e);
- status = StorageOperationStatus.OK;
- }
- catch (Exception e) {
- //it is happy flow as well
- log.error("Exception occurred:", e);
- log.error("Migration task will continue anyway, please find below vertex details related to this exception", e);
- if (containerV != null){
+ if (containerV == null) {
+ log.error("Unexpected null value for `containerV`");
+ } else {
+ try {
+ Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao
+ .getChildVertex(containerV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, JsonParseFlagEnum.ParseAll);
+ GraphVertex instDeployArt = childVertex.left().value();
+ Collection<MapArtifactDataDefinition> values = (Collection<MapArtifactDataDefinition>) instDeployArt
+ .getJson().values();
+ List<ArtifactDataDefinition> artifactDataDefinitionsList = values.stream()
+ .map(f -> f.getMapToscaDataDefinition().values())
+ .flatMap(f -> f.stream().filter(isRelevantArtifact()))
+ .collect(Collectors.toList());
+ artifactDataDefinitionsList.forEach(t -> t.setTimeout(defaultTimeOut));
+ status = updateVertexAndCommit(instDeployArt);
+
+ } catch (NullPointerException e) {
+ log.error(
+ "Null Pointer Exception occurred - this mean we have zombie vertex, migration task will continue anyway",
+ e);
+ status = StorageOperationStatus.OK;
+ } catch (Exception e) {
+ //it is happy flow as well
+ log.error("Exception occurred:", e);
+ log.error(
+ "Migration task will continue anyway, please find below vertex details related to this exception",
+ e);
log.error("containerV.getUniqueId() {} ---> ", containerV.getUniqueId());
- }
- status = StorageOperationStatus.OK;
- } finally {
- if (status != StorageOperationStatus.OK) {
- janusGraphDao.rollback();
- log.info("failed to update vertex ID {} ", containerV.getUniqueId());
- if (status == StorageOperationStatus.NOT_FOUND) {
- //it is happy flow as well
- status = StorageOperationStatus.OK;
+ 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());
}
}
- else{
- log.info("vertex ID {} successfully updated", containerV.getUniqueId());
- }
-
}
+
return status;
}
private static Predicate<ArtifactDataDefinition> isRelevantArtifact() {
- return p -> ((p.getArtifactType().equals(ArtifactTypeEnum.HEAT.getType()) || p.getArtifactType().equals(ArtifactTypeEnum.HEAT_VOL.getType()) || p.getArtifactType().equals(ArtifactTypeEnum.HEAT_NET.getType()))
- && p.getTimeout() != defaultTimeOut);
+ 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);
}