diff options
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java')
8 files changed, 178 insertions, 39 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java index a043bb85b6..b3767a3b62 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java @@ -92,6 +92,18 @@ public interface AaiServiceProvider { final Vserver vserver); /** + * Invoke a DELETE request for a vserver. + * + * @param cloudOwner the cloud owner + * @param cloudRegion the cloud region + * @param tenantId the ID of the tenant + * @param vserver the ID of the vserver + * @return + */ + void invokeDeleteVserver(final String cloudOwner, final String cloudRegion, final String tenantId, + final String vserverId); + + /** * Invoke a GET request for the a tenant. * * @param cloudOwner the cloud owner diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java index 364a6415a8..6c3d7c2ca6 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java @@ -109,6 +109,13 @@ public class AaiServiceProviderImpl implements AaiServiceProvider { } @Override + public void invokeDeleteVserver(final String cloudOwner, final String cloudRegion, final String tenant, + final String vserverId) { + aaiClientProvider.getAaiClient().delete( + AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenant, vserverId)); + } + + @Override public Tenant invokeGetTenant(final String cloudOwner, final String cloudRegion, final String tenantId) { return aaiClientProvider.getAaiClient() .get(Tenant.class, diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java index 8af6889ae2..320715dd33 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java @@ -58,6 +58,14 @@ public interface VnfmServiceProvider { String terminateVnf(final String vnfSelfLink, final TerminateVnfRequest terminateVnfRequest); /** + * Invoke a delete request for a VNF. + * + * @param vnfSelfLink the link to he VNF on the VNFM + * @return the operation ID of the instantiation operation + */ + void deleteVnf(final String vnfSelfLink); + + /** * Invoke a get request for a VNFM operation. * * @param vnfmId the id of the VNFM in AAI diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java index d447befa45..246444fa8c 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java @@ -104,6 +104,17 @@ public class VnfmServiceProviderImpl implements VnfmServiceProvider { } @Override + public void deleteVnf(final String vnfSelfLink) { + logger.debug("Sending delete request to : " + vnfSelfLink); + final ResponseEntity<Void> response = httpServiceProvider.deleteHttpRequest(vnfSelfLink, Void.class); + if (response.getStatusCode() != HttpStatus.OK) { + throw new VnfmRequestFailureException( + "Delete request to " + vnfSelfLink + " return status code: " + response.getStatusCode()); + } + } + + + @Override public Optional<InlineResponse200> getOperation(final String vnfmId, final String operationId) { final String url = urlProvider.getOperationUrl(vnfmId, operationId); return httpServiceProvider.get(url, InlineResponse200.class); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/JobManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/JobManager.java index 97a945cf1d..89356c1b67 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/JobManager.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/JobManager.java @@ -110,11 +110,27 @@ public class JobManager { final InlineResponse200 operationResponse) { final OperationStateEnum operationState = OperationStateEnum.fromValue(operationResponse.getOperationState().getValue()); - if (operationState == OperationStateEnum.COMPLETED && vnfmOperation.isWaitForNotificationForSuccess() - && !vnfmOperation.isNotificationProcessed()) { - return org.onap.vnfmadapter.v1.model.OperationStateEnum.PROCESSING; + switch (vnfmOperation.getNotificationStatus()) { + case NOTIFICATION_PROCESSING_NOT_REQUIRED: + default: + return operationState; + case NOTIFICATION_PROCESSING_PENDING: + return org.onap.vnfmadapter.v1.model.OperationStateEnum.PROCESSING; + case NOTIFICATION_PROCEESING_SUCCESSFUL: + return operationState; + case NOTIFICATION_PROCESSING_FAILED: + return org.onap.vnfmadapter.v1.model.OperationStateEnum.FAILED; } - return operationState; + } + + public void notificationProcessedForOperation(final String operationId, + final boolean notificationProcessingWasSuccessful) { + final java.util.Optional<VnfmOperation> relatedOperation = mapOfJobIdToVnfmOperation.values().stream() + .filter(operation -> operation.getOperationId().equals(operationId)).findFirst(); + if (relatedOperation.isPresent()) { + relatedOperation.get().setNotificationProcessed(notificationProcessingWasSuccessful); + } + logger.debug("No operation found for operation ID " + operationId); } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/VnfmOperation.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/VnfmOperation.java index 916c9e4011..e0ad327bd3 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/VnfmOperation.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/jobmanagement/VnfmOperation.java @@ -27,13 +27,13 @@ public class VnfmOperation { private final String vnfmId; private final String operationId; - private boolean waitForNotificationForSuccess = false; - private boolean isNotificationProcessed = false; + private NotificationStatus notificationStatus; public VnfmOperation(final String vnfmId, final String operationId, final boolean waitForNotificationForSuccess) { this.vnfmId = vnfmId; this.operationId = operationId; - this.waitForNotificationForSuccess = waitForNotificationForSuccess; + this.notificationStatus = waitForNotificationForSuccess ? NotificationStatus.NOTIFICATION_PROCESSING_PENDING + : NotificationStatus.NOTIFICATION_PROCESSING_NOT_REQUIRED; } /** @@ -55,31 +55,43 @@ public class VnfmOperation { } /** - * Check if a notification should be processed before the operation is considered successfully - * completed. + * Set the required notification has been processed for the operation. * - * @return <code>true></code> if a notification must be processed before the operation is considered - * successfully completed, <code>false</code> otherwise + * @param notificationProcessingWasSuccessful <code>true</code> if the notification processing was + * successful, <code>false<code> otherwise */ - public boolean isWaitForNotificationForSuccess() { - return waitForNotificationForSuccess; + public void setNotificationProcessed(final boolean notificationProcessingWasSuccessful) { + this.notificationStatus = + notificationProcessingWasSuccessful ? NotificationStatus.NOTIFICATION_PROCEESING_SUCCESSFUL + : NotificationStatus.NOTIFICATION_PROCESSING_FAILED; } /** - * Set the required notification has been processed for the operation. + * Get the notification status for the operation. + * + * @return the notification status */ - public void setNotificationProcessed() { - this.isNotificationProcessed = true; + public NotificationStatus getNotificationStatus() { + return notificationStatus; } - /** - * Check if the required notification has been processed. - * - * @return <code>true</code> of the required notification has been processed, <code>false</code> - * otherwise - */ - public boolean isNotificationProcessed() { - return isNotificationProcessed; + public enum NotificationStatus { + /** + * No notification handling is required to determine the status of the operation + */ + NOTIFICATION_PROCESSING_NOT_REQUIRED, + /** + * A notification must be processed before the notification can be considered to be completed + */ + NOTIFICATION_PROCESSING_PENDING, + /** + * A notification has been successfully handled for the operation + */ + NOTIFICATION_PROCEESING_SUCCESSFUL, + /** + * An error occurred processing a notification for the operation + */ + NOTIFICATION_PROCESSING_FAILED; } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java index 36b197dd06..b82ed86beb 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java @@ -30,11 +30,13 @@ import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Vserver; import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiHelper; import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiServiceProvider; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmServiceProvider; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationStateEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo; +import org.onap.so.adapters.vnfmadapter.jobmanagement.JobManager; import org.slf4j.Logger; /** @@ -46,16 +48,19 @@ public class NotificationHandler implements Runnable { private final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification; private final AaiHelper aaiHelper; private final AaiServiceProvider aaiServiceProvider; - - + private final VnfmServiceProvider vnfmServiceProvider; + private final JobManager jobManager; private final InlineResponse201 vnfInstance; public NotificationHandler(final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification, final AaiHelper aaiHelper, final AaiServiceProvider aaiServiceProvider, + final VnfmServiceProvider vnfmServiceProvider, final JobManager jobManager, final InlineResponse201 vnfInstance) { this.vnfLcmOperationOccurrenceNotification = vnfLcmOperationOccurrenceNotification; this.aaiHelper = aaiHelper; this.aaiServiceProvider = aaiServiceProvider; + this.vnfmServiceProvider = vnfmServiceProvider; + this.jobManager = jobManager; this.vnfInstance = vnfInstance; } @@ -63,12 +68,12 @@ public class NotificationHandler implements Runnable { public void run() { try { if (vnfLcmOperationOccurrenceNotification.getOperationState().equals(OperationStateEnum.COMPLETED)) { - final GenericVnf genericVnf = - aaiServiceProvider.invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).get(0); - switch (vnfLcmOperationOccurrenceNotification.getOperation()) { case INSTANTIATE: - handleVnfInstantiated(genericVnf); + handleVnfInstantiate(); + break; + case TERMINATE: + handleVnfTerminate(); break; default: } @@ -79,7 +84,15 @@ public class NotificationHandler implements Runnable { } } - private void handleVnfInstantiated(final GenericVnf genericVnf) { + private void handleVnfInstantiate() { + if (vnfLcmOperationOccurrenceNotification.getOperationState().equals(OperationStateEnum.COMPLETED)) { + handleVnfInstantiateCompleted(); + } + } + + private void handleVnfInstantiateCompleted() { + final GenericVnf genericVnf = + aaiServiceProvider.invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).get(0); final String ipAddress = getOamIpAddress(vnfInstance); logger.debug("Updating " + genericVnf.getVnfId() + " with VNF OAM IP ADDRESS: " + ipAddress); genericVnf.setIpv4OamAddress(ipAddress); @@ -108,6 +121,45 @@ public class NotificationHandler implements Runnable { } } + private void handleVnfTerminate() { + switch (vnfLcmOperationOccurrenceNotification.getOperationState()) { + case COMPLETED: + handleVnfTerminateCompleted(); + break; + case FAILED: + case ROLLING_BACK: + handleVnfTerminateFailed(); + break; + default: + } + } + + private void handleVnfTerminateFailed() { + final GenericVnf genericVnf = + aaiServiceProvider.invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).get(0); + updateVservers(vnfLcmOperationOccurrenceNotification, genericVnf.getVnfId(), + vnfInstance.getVimConnectionInfo()); + jobManager.notificationProcessedForOperation(vnfLcmOperationOccurrenceNotification.getId(), false); + } + + private void handleVnfTerminateCompleted() { + final GenericVnf genericVnf = + aaiServiceProvider.invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).get(0); + updateVservers(vnfLcmOperationOccurrenceNotification, genericVnf.getVnfId(), + vnfInstance.getVimConnectionInfo()); + + boolean deleteSuccessful = false; + try { + vnfmServiceProvider.deleteVnf(genericVnf.getSelflink()); + deleteSuccessful = true; + } finally { + jobManager.notificationProcessedForOperation(vnfLcmOperationOccurrenceNotification.getId(), + deleteSuccessful); + genericVnf.setOrchestrationStatus("Assigned"); + aaiServiceProvider.invokePutGenericVnf(genericVnf); + } + } + private void updateVservers(final VnfLcmOperationOccurrenceNotification notification, final String vnfId, final List<InlineResponse201VimConnectionInfo> vnfInstancesVimConnectionInfo) { final Map<String, InlineResponse201VimConnectionInfo> vimConnectionIdToVimConnectionInfo = new HashMap<>(); @@ -116,17 +168,21 @@ public class NotificationHandler implements Runnable { } for (final LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs vnfc : notification.getAffectedVnfcs()) { - + final InlineResponse201VimConnectionInfo vimConnectionInfo = + getVimConnectionInfo(vimConnectionIdToVimConnectionInfo, vnfc); switch (vnfc.getChangeType()) { case ADDED: final Vserver vserver = aaiHelper.createVserver(vnfc); aaiHelper.addRelationshipFromVserverVnfToGenericVnf(vserver, vnfId); - final InlineResponse201VimConnectionInfo vimConnectionInfo = - getVimConnectionInfo(vimConnectionIdToVimConnectionInfo, vnfc); + aaiServiceProvider.invokePutVserver(getCloudOwner(vimConnectionInfo), getCloudRegion(vimConnectionInfo), getTenant(vimConnectionInfo), vserver); break; case REMOVED: + aaiServiceProvider.invokeDeleteVserver(getCloudOwner(vimConnectionInfo), + getCloudRegion(vimConnectionInfo), getTenant(vimConnectionInfo), + vnfc.getComputeResource().getResourceId()); + break; case MODIFIED: case TEMPORARY: default: diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnContoller.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnContoller.java index 60f3f51e52..f0958cbe7d 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnContoller.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnContoller.java @@ -34,6 +34,7 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperatio import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationStateEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; +import org.onap.so.adapters.vnfmadapter.jobmanagement.JobManager; import org.onap.so.adapters.vnfmadapter.notificationhandling.NotificationHandler; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -56,14 +57,16 @@ public class Sol003LcnContoller { private final AaiServiceProvider aaiServiceProvider; private final AaiHelper aaiHelper; private final VnfmServiceProvider vnfmServiceProvider; + private final JobManager jobManager; private final ExecutorService executor = Executors.newCachedThreadPool(); @Autowired Sol003LcnContoller(final AaiServiceProvider aaiServiceProvider, final AaiHelper aaiHelper, - final VnfmServiceProvider vnfmServiceProvider) { + final VnfmServiceProvider vnfmServiceProvider, final JobManager jobManager) { this.aaiServiceProvider = aaiServiceProvider; this.aaiHelper = aaiHelper; this.vnfmServiceProvider = vnfmServiceProvider; + this.jobManager = jobManager; } @PostMapping(value = "/lcn/VnfIdentifierCreationNotification") @@ -85,12 +88,10 @@ public class Sol003LcnContoller { @RequestBody final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification) { logger.info(LOG_LCN_RECEIVED + vnfLcmOperationOccurrenceNotification); - final OperationEnum operation = vnfLcmOperationOccurrenceNotification.getOperation(); - if ((operation.equals(OperationEnum.INSTANTIATE)) - && vnfLcmOperationOccurrenceNotification.getOperationState().equals(OperationStateEnum.COMPLETED)) { + if (isANotificationOfInterest(vnfLcmOperationOccurrenceNotification)) { final InlineResponse201 vnfInstance = getVnfInstance(vnfLcmOperationOccurrenceNotification); final NotificationHandler handler = new NotificationHandler(vnfLcmOperationOccurrenceNotification, - aaiHelper, aaiServiceProvider, vnfInstance); + aaiHelper, aaiServiceProvider, vnfmServiceProvider, jobManager, vnfInstance); executor.execute(handler); } @@ -98,6 +99,22 @@ public class Sol003LcnContoller { return new ResponseEntity<>(HttpStatus.NO_CONTENT); } + private boolean isANotificationOfInterest(final VnfLcmOperationOccurrenceNotification notification) { + return isInstanitiateCompleted(notification) || isTerminateTerminalState(notification); + } + + private boolean isInstanitiateCompleted(final VnfLcmOperationOccurrenceNotification notification) { + return notification.getOperation().equals(OperationEnum.INSTANTIATE) + && notification.getOperationState().equals(OperationStateEnum.COMPLETED); + } + + private boolean isTerminateTerminalState(final VnfLcmOperationOccurrenceNotification notification) { + return notification.getOperation().equals(OperationEnum.TERMINATE) + && (notification.getOperationState().equals(OperationStateEnum.COMPLETED) + || notification.getOperationState().equals(OperationStateEnum.FAILED) + || notification.getOperationState().equals(OperationStateEnum.ROLLED_BACK)); + } + private InlineResponse201 getVnfInstance( final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification) { return vnfmServiceProvider.getVnf(vnfLcmOperationOccurrenceNotification.getLinks().getVnfInstance().getHref()) |