From 3bb06374d5b6747d32ea9554259596d0a45fadc2 Mon Sep 17 00:00:00 2001 From: Chris André Date: Thu, 16 Apr 2020 17:48:06 -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-2905 Signed-off-by: Chris Andre Change-Id: I648e9a4a04be3f2e7cd3e30a70c04de2257a99d3 --- .../SdcCollapsingRolesCERTIFIEDstateMigration.java | 81 +++++++++++++--------- 1 file changed, 48 insertions(+), 33 deletions(-) (limited to 'asdctool/src') 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 index 1d7d3d1298..9cf56cf325 100644 --- 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 @@ -70,7 +70,7 @@ public class SdcCollapsingRolesCERTIFIEDstateMigration extends InstanceMigration public MigrationResult migrate() { StorageOperationStatus status = updateServiceLifeCycleState(); return status == StorageOperationStatus.OK ? - MigrationResult.success() : MigrationResult.error("failed to service state. Error : " + status); + MigrationResult.success() : MigrationResult.error("failed to service state. Error : " + status); } protected StorageOperationStatus updateServiceLifeCycleState() { @@ -79,7 +79,9 @@ public class SdcCollapsingRolesCERTIFIEDstateMigration extends InstanceMigration 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); + Either, JanusGraphOperationStatus> byCriteria = janusGraphDao + .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, + JsonParseFlagEnum.ParseAll); return byCriteria.either(this::proceed, this::handleError); } @@ -87,51 +89,64 @@ public class SdcCollapsingRolesCERTIFIEDstateMigration extends InstanceMigration protected StorageOperationStatus handleOneContainer(GraphVertex containerVorig) { StorageOperationStatus status = StorageOperationStatus.NOT_FOUND; GraphVertex containerV = getVertexById(containerVorig.getUniqueId()); - try { - //update edges to meet above change - // update LS eges from RFC to NOT_CERTIFIED_CHECKIN + if (containerV == null) { + log.error("Unexpected null value for `containerV`"); + } else { + try { - updateEdgeProperty(EdgePropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name(), getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_STATE)); + //update edges to meet above change + // update LS eges from RFC to NOT_CERTIFIED_CHECKIN - if (containerV.getMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS).equals(DistributionStatusEnum.DISTRIBUTION_APPROVED.name()) || containerV.getMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS).equals(DistributionStatusEnum.DISTRIBUTION_REJECTED.name())) { + updateEdgeProperty(EdgePropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name(), + getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_STATE)); - // update vertex state property from DISTRIBUTION_APPROVED/REJECTED to DISTRIBUTION_NOT_APPROVED state + if (containerV.getMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS) + .equals(DistributionStatusEnum.DISTRIBUTION_APPROVED.name()) || containerV + .getMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS) + .equals(DistributionStatusEnum.DISTRIBUTION_REJECTED.name())) { - Map metadataProperties = containerV.getMetadataProperties(); - metadataProperties.put(GraphPropertyEnum.DISTRIBUTION_STATUS, DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED.name()); - containerV.setMetadataProperties(metadataProperties); + // update vertex state property from DISTRIBUTION_APPROVED/REJECTED to DISTRIBUTION_NOT_APPROVED state - //update edges to meet above change - //delete LAST_DISTRIBUTION_STATE_MODIFIER edge + Map metadataProperties = containerV.getMetadataProperties(); + metadataProperties.put(GraphPropertyEnum.DISTRIBUTION_STATUS, + DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED.name()); + containerV.setMetadataProperties(metadataProperties); - removeEdges(getVertexEdge(containerV, Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER)); + //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); + 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) { + } 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()); + } 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; } -- cgit 1.2.3-korg