From 659556d07ad5b928cb0032f040dc86fcb11944c8 Mon Sep 17 00:00:00 2001 From: Chris André Date: Thu, 16 Apr 2020 16:29:05 -0400 Subject: 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 Change-Id: Ib8d7c1bf36608855c73d8a0df637e86aefce9377 --- .../mig1911/SdcDeploymentArtTimeOutMigration.java | 81 +++++++++++++--------- 1 file changed, 48 insertions(+), 33 deletions(-) (limited to 'asdctool/src/main/java') 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 propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - Either, JanusGraphOperationStatus> byCriteria = janusGraphDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll); + Either, 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 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); - if (containerV != null){ + 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; + 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 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); } -- cgit 1.2.3-korg