VNFM adapter handle getOperation after VNF delete 05/90105/1
authorMichaelMorris <michael.morris@est.tech>
Tue, 18 Jun 2019 17:58:42 +0000 (17:58 +0000)
committerMichaelMorris <michael.morris@est.tech>
Tue, 18 Jun 2019 17:58:42 +0000 (17:58 +0000)
Change-Id: Iaa8d792f5660b1caf16d081779c14799d827a544
Issue-ID: SO-2030
Signed-off-by: MichaelMorris <michael.morris@est.tech>
adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/JobManager.java
adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/VnfmOperation.java
adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java

index b3552c7..537bb77 100644 (file)
@@ -84,42 +84,53 @@ public class JobManager {
             throw new JobNotFoundException("No job found with ID: " + jobId);
         }
 
-        final Optional<InlineResponse200> operationOptional =
-                vnfmServiceProvider.getOperation(vnfmOperation.getVnfmId(), vnfmOperation.getOperationId());
-        if (!operationOptional.isPresent()) {
-            return response.operationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.OPERATION_NOT_FOUND);
+        if (vnfmOperation.isVnfDeleted()) {
+            response.setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND);
+            return response.operationState(getOperationState(vnfmOperation, null));
         }
-        final InlineResponse200 operation = operationOptional.get();
 
-        logger.debug("Job Id: " + jobId + ", operationId: " + operation.getId() + ", operation details: " + operation);
+        try {
+            final Optional<InlineResponse200> operationOptional =
+                    vnfmServiceProvider.getOperation(vnfmOperation.getVnfmId(), vnfmOperation.getOperationId());
 
-        if (operation.getOperationState() == null) {
-            return response.operationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.WAITING_FOR_STATUS);
-        }
+            if (!operationOptional.isPresent()) {
+                return response.operationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.OPERATION_NOT_FOUND);
+            }
+            final InlineResponse200 operation = operationOptional.get();
+
+            logger.debug(
+                    "Job Id: " + jobId + ", operationId: " + operation.getId() + ", operation details: " + operation);
+
+            if (operation.getOperationState() == null) {
+                return response.operationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.WAITING_FOR_STATUS);
+            }
 
-        response.setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND);
-        response.setId(operation.getId());
-        response.setOperation(OperationEnum.fromValue(operation.getOperation().getValue()));
-        response.setOperationState(getOperationState(vnfmOperation, operation));
-        response.setStartTime(operation.getStartTime());
-        response.setStateEnteredTime(operation.getStateEnteredTime());
-        response.setVnfInstanceId(operation.getVnfInstanceId());
+            response.setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND);
+            response.setId(operation.getId());
+            response.setOperation(OperationEnum.fromValue(operation.getOperation().getValue()));
+            response.setOperationState(getOperationState(vnfmOperation, operation));
+            response.setStartTime(operation.getStartTime());
+            response.setStateEnteredTime(operation.getStateEnteredTime());
+            response.setVnfInstanceId(operation.getVnfInstanceId());
 
-        return response;
+            return response;
+        } catch (final Exception exception) {
+            logger.error("Exception encountered trying to get operation status for operation id "
+                    + vnfmOperation.getOperationId(), exception);
+            return response.operationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.WAITING_FOR_STATUS);
+        }
     }
 
     private OperationStateEnum getOperationState(final VnfmOperation vnfmOperation,
             final InlineResponse200 operationResponse) {
-        final OperationStateEnum operationState =
-                OperationStateEnum.fromValue(operationResponse.getOperationState().getValue());
         switch (vnfmOperation.getNotificationStatus()) {
             case NOTIFICATION_PROCESSING_NOT_REQUIRED:
             default:
-                return operationState;
+                return OperationStateEnum.fromValue(operationResponse.getOperationState().getValue());
             case NOTIFICATION_PROCESSING_PENDING:
                 return org.onap.vnfmadapter.v1.model.OperationStateEnum.PROCESSING;
             case NOTIFICATION_PROCEESING_SUCCESSFUL:
-                return operationState;
+                return org.onap.vnfmadapter.v1.model.OperationStateEnum.COMPLETED;
             case NOTIFICATION_PROCESSING_FAILED:
                 return org.onap.vnfmadapter.v1.model.OperationStateEnum.FAILED;
         }
@@ -138,4 +149,15 @@ public class JobManager {
         }
     }
 
+    public void vnfDeleted(final String operationId) {
+        logger.debug("VNF deleyed for operation ID {}", operationId);
+        final java.util.Optional<VnfmOperation> relatedOperation = mapOfJobIdToVnfmOperation.values().stream()
+                .filter(operation -> operation.getOperationId().equals(operationId)).findFirst();
+        if (relatedOperation.isPresent()) {
+            relatedOperation.get().setVnfDeleted();;
+        } else {
+            logger.debug("No operation found for operation ID " + operationId);
+        }
+    }
+
 }
index 7ce08df..3bfe48a 100644 (file)
@@ -28,6 +28,7 @@ public class VnfmOperation {
     private final String vnfmId;
     private final String operationId;
     private NotificationStatus notificationStatus;
+    private boolean vnfDeleted;
 
     public VnfmOperation(final String vnfmId, final String operationId, final boolean waitForNotificationForSuccess) {
         this.vnfmId = vnfmId;
@@ -75,6 +76,23 @@ public class VnfmOperation {
         return notificationStatus;
     }
 
+    /**
+     * Set the VNF has been deleted from the VNFM.
+     */
+    public void setVnfDeleted() {
+        this.vnfDeleted = true;
+    }
+
+    /**
+     * Check if the VNF has been deleted from the VNFM
+     *
+     * @return <code>true</code> of the VNF has been deleted from the VNFM, <code>false</code> otherwise
+     */
+    public boolean isVnfDeleted() {
+        return vnfDeleted;
+    }
+
+
     public enum NotificationStatus {
         /**
          * No notification handling is required to determine the status of the operation
index c09aa0c..93c7ea9 100644 (file)
@@ -161,6 +161,7 @@ public class NotificationHandler implements Runnable {
         } finally {
             jobManager.notificationProcessedForOperation(vnfLcmOperationOccurrenceNotification.getVnfLcmOpOccId(),
                     deleteSuccessful);
+            jobManager.vnfDeleted(vnfLcmOperationOccurrenceNotification.getVnfLcmOpOccId());
             genericVnf.setOrchestrationStatus("Assigned");
             genericVnf.setSelflink("");
             aaiServiceProvider.invokePutGenericVnf(genericVnf);