diff options
author | MichaelMorris <michael.morris@est.tech> | 2019-04-05 14:40:27 +0000 |
---|---|---|
committer | MichaelMorris <michael.morris@est.tech> | 2019-04-05 14:40:27 +0000 |
commit | 12565266faef74572cec51e01bd7f6ad394e7775 (patch) | |
tree | 202d493255101468b72066a28d949026e09f9ce0 /adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org | |
parent | 10ef4462e14cfc57a0d3b074569e9b209186d5f1 (diff) |
Send terminate VNF to VNFM
Issue-ID: SO-1633
Change-Id: I2d1010496725a47af7af108a681e1c16c749126c
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org')
10 files changed, 202 insertions, 30 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java index bacbea141e..77951062e8 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java @@ -95,12 +95,22 @@ public class AaiHelper { * @return the VNFM to use, or <code>null</code> if no VNFM has been assigned yet */ public EsrVnfm getAssignedVnfm(final GenericVnf vnf) { - final Relationship relationship = getRelationship(vnf, "esr-vnfm"); - final String vnfmId = getRelationshipKey(relationship, "esr-vnfm.vnfm-id"); + final String vnfmId = getIdOfAssignedVnfm(vnf); return vnfmId == null ? null : aaiServiceProvider.invokeGetVnfm(vnfmId); } /** + * Get the ID of the VNFM assigned for use for the given generic VNF. + * + * @param vnf the generic VNF + * @return the ID of the VNFM to use, or <code>null</code> if no VNFM has been assigned yet + */ + public String getIdOfAssignedVnfm(final GenericVnf vnf) { + final Relationship relationship = getRelationship(vnf, "esr-vnfm"); + return getRelationshipKey(relationship, "esr-vnfm.vnfm-id"); + } + + /** * Get the tenant assigned for use for the given generic VNF. * * @param vnf the generic VNF 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 aaf7e460ed..8af6889ae2 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 @@ -24,6 +24,7 @@ import com.google.common.base.Optional; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.TerminateVnfRequest; /** * Provides methods for invoking REST calls to a VNFM. @@ -48,6 +49,15 @@ public interface VnfmServiceProvider { String instantiateVnf(final String vnfSelfLink, final InstantiateVnfRequest instantiateVnfRequest); /** + * Invoke a terminate request for a VNF. + * + * @param vnfSelfLink the link to he VNF on the VNFM + * @param terminateVnfRequest the terminate request + * @return the operation ID of the termination operation + */ + String terminateVnf(final String vnfSelfLink, final TerminateVnfRequest terminateVnfRequest); + + /** * 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 4a2c7a9696..d447befa45 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 @@ -24,6 +24,7 @@ import com.google.common.base.Optional; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.TerminateVnfRequest; import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmRequestFailureException; import org.onap.so.rest.service.HttpRestServiceProvider; import org.slf4j.Logger; @@ -56,13 +57,50 @@ public class VnfmServiceProviderImpl implements VnfmServiceProvider { @Override public String instantiateVnf(final String vnfSelfLink, final InstantiateVnfRequest instantiateVnfRequest) { logger.debug("Sending instantiate request " + instantiateVnfRequest + " to : " + vnfSelfLink); - final ResponseEntity<Void> response = httpServiceProvider.getHttpResponse(vnfSelfLink, Void.class); + + ResponseEntity<Void> response = null; + try { + response = httpServiceProvider.postHttpRequest(instantiateVnfRequest, vnfSelfLink + "/instantiate", + Void.class); + } catch (final Exception exception) { + final String errorMessage = + "Instantiate request to " + vnfSelfLink + " resulted in exception" + instantiateVnfRequest; + logger.error(errorMessage, exception); + throw new VnfmRequestFailureException(errorMessage, exception); + } if (response.getStatusCode() != HttpStatus.ACCEPTED) { - throw new VnfmRequestFailureException("Instantiate request to " + vnfSelfLink + " return status code: " - + response.getStatusCode() + ", request: " + instantiateVnfRequest); + final String errorMessage = "Instantiate request to " + vnfSelfLink + " returned status code: " + + response.getStatusCode() + ", request: " + instantiateVnfRequest; + logger.error(errorMessage); + throw new VnfmRequestFailureException(errorMessage); } final String locationHeader = response.getHeaders().get("Location").iterator().next(); return locationHeader.substring(locationHeader.lastIndexOf("/") + 1); + + } + + @Override + public String terminateVnf(final String vnfSelfLink, final TerminateVnfRequest terminateVnfRequest) { + logger.debug("Sending terminate request " + terminateVnfRequest + " to : " + vnfSelfLink); + + ResponseEntity<Void> response = null; + try { + response = httpServiceProvider.postHttpRequest(terminateVnfRequest, vnfSelfLink + "/terminate", Void.class); + } catch (final Exception exception) { + final String errorMessage = + "Terminate request to " + vnfSelfLink + " resulted in exception" + terminateVnfRequest; + logger.error(errorMessage, exception); + throw new VnfmRequestFailureException(errorMessage, exception); + } + if (response.getStatusCode() != HttpStatus.ACCEPTED) { + final String errorMessage = "Terminate request to " + vnfSelfLink + " returned status code: " + + response.getStatusCode() + ", request: " + terminateVnfRequest; + logger.error(errorMessage); + throw new VnfmRequestFailureException(errorMessage); + } + final String locationHeader = response.getHeaders().get("Location").iterator().next(); + return locationHeader.substring(locationHeader.lastIndexOf("/") + 1); + } @Override 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 ac11bcee4b..97a945cf1d 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 @@ -27,6 +27,7 @@ import java.util.Map; import java.util.UUID; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmServiceProvider; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.JobNotFoundException; import org.onap.vnfmadapter.v1.model.OperationEnum; import org.onap.vnfmadapter.v1.model.OperationStateEnum; import org.onap.vnfmadapter.v1.model.OperationStatusRetrievalStatusEnum; @@ -82,7 +83,7 @@ public class JobManager { final QueryJobResponse response = new QueryJobResponse(); if (vnfmOperation == null) { - return null; + throw new JobNotFoundException("No job found with ID: " + jobId); } final Optional<InlineResponse200> operationOptional = diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java index 4bedb47e3d..9249b9e620 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java @@ -21,7 +21,6 @@ package org.onap.so.adapters.vnfmadapter.lifecycle; import com.google.common.base.Optional; -import java.util.UUID; import org.onap.aai.domain.yang.EsrVnfm; import org.onap.aai.domain.yang.GenericVnf; import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiHelper; @@ -30,7 +29,11 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmHelper; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmServiceProvider; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.TerminateVnfRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.TerminateVnfRequest.TerminationTypeEnum; import org.onap.so.adapters.vnfmadapter.jobmanagement.JobManager; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfNotFoundException; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; @@ -87,12 +90,6 @@ public class LifecycleManager { return response; } - private GenericVnf getGenericVnfFromAai(final String vnfIdInAai) { - final GenericVnf genericVnf = aaiServiceProvider.invokeGetGenericVnf(vnfIdInAai); - logger.debug("Retrieved generic VNF from AAI: " + genericVnf); - return genericVnf; - } - private void checkIfVnfAlreadyExistsInVnfm(final GenericVnf genericVnf) { if (genericVnf.getSelflink() != null && !genericVnf.getSelflink().isEmpty()) { Optional<InlineResponse201> response = Optional.absent(); @@ -132,11 +129,35 @@ public class LifecycleManager { * @return the response to the request */ public DeleteVnfResponse deleteVnf(final String vnfIdInAai) { - // vnfm ID and operation ID set to random value for now, will be set correctly once we implement - // terminate call towards the VNFM - final String jobId = jobManager.createJob(UUID.randomUUID().toString(), UUID.randomUUID().toString(), true); - final DeleteVnfResponse response = new DeleteVnfResponse(); - response.setJobId(jobId); - return response; + final GenericVnf genericVnf = getGenericVnfFromAai(vnfIdInAai); + final String vnfmId = getIdOfAssignedVnfm(genericVnf); + + final String operationId = sendTerminateRequestToVnfm(genericVnf); + final String jobId = jobManager.createJob(vnfmId, operationId, true); + + return new DeleteVnfResponse().jobId(jobId); + } + + private String sendTerminateRequestToVnfm(final GenericVnf genericVnf) { + final TerminateVnfRequest terminateVnfRequest = new TerminateVnfRequest(); + terminateVnfRequest.setTerminationType(TerminationTypeEnum.FORCEFUL); + return vnfmServiceProvider.terminateVnf(genericVnf.getSelflink(), terminateVnfRequest); + } + + private GenericVnf getGenericVnfFromAai(final String vnfIdInAai) { + final GenericVnf genericVnf = aaiServiceProvider.invokeGetGenericVnf(vnfIdInAai); + if (genericVnf == null) { + throw new VnfNotFoundException("VNF not found in AAI: " + vnfIdInAai); + } + logger.debug("Retrieved generic VNF from AAI: " + genericVnf); + return genericVnf; + } + + private String getIdOfAssignedVnfm(final GenericVnf genericVnf) { + final String vnfmId = aaiHelper.getIdOfAssignedVnfm(genericVnf); + if (vnfmId == null) { + throw new VnfmNotFoundException("No VNFM found in AAI for VNF " + genericVnf.getVnfId()); + } + return vnfmId; } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java index 055b8e0450..65bc450c5f 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java @@ -87,9 +87,12 @@ public class VnfmAdapterController { logger.info("REST request vnfCreate with body: {}", createVnfRequest); - final CreateVnfResponse createVnfResponse = lifecycleManager.createVnf(vnfId, createVnfRequest); - clearLoggingMDCs(); - return new ResponseEntity<>(createVnfResponse, HttpStatus.ACCEPTED); + try { + final CreateVnfResponse createVnfResponse = lifecycleManager.createVnf(vnfId, createVnfRequest); + return new ResponseEntity<>(createVnfResponse, HttpStatus.ACCEPTED); + } finally { + clearLoggingMDCs(); + } } @DeleteMapping(value = "/vnfs/{vnfId}") @@ -113,9 +116,12 @@ public class VnfmAdapterController { logger.info("REST request vnfDelete for VNF: {}", vnfId); - final DeleteVnfResponse response = lifecycleManager.deleteVnf(vnfId); - clearLoggingMDCs(); - return new ResponseEntity<>(response, HttpStatus.ACCEPTED); + try { + final DeleteVnfResponse response = lifecycleManager.deleteVnf(vnfId); + return new ResponseEntity<>(response, HttpStatus.ACCEPTED); + } finally { + clearLoggingMDCs(); + } } @GetMapping(value = "/jobs/{jobId}") @@ -136,12 +142,12 @@ public class VnfmAdapterController { setLoggingMDCs(requestId, partnerName, invocationId); - final QueryJobResponse response = jobManager.getVnfmOperation(jobId); - if (response == null) { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); + try { + final QueryJobResponse response = jobManager.getVnfmOperation(jobId); + return new ResponseEntity<>(response, HttpStatus.OK); + } finally { + clearLoggingMDCs(); } - return new ResponseEntity<>(response, HttpStatus.OK); - } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/JobNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/JobNotFoundException.java new file mode 100644 index 0000000000..1fd3902137 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/JobNotFoundException.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.vnfmadapter.rest.exceptions; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * Exception for job not found. + */ +@ResponseStatus(HttpStatus.NOT_FOUND) +public class JobNotFoundException extends RuntimeException { + + private static final long serialVersionUID = 6398018034431666933L; + + public JobNotFoundException(final String message) { + super(message); + } + +} + diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfNotFoundException.java new file mode 100644 index 0000000000..1413f99080 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfNotFoundException.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.vnfmadapter.rest.exceptions; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * Exception for VNF not found. + */ +@ResponseStatus(HttpStatus.NOT_FOUND) +public class VnfNotFoundException extends RuntimeException { + + private static final long serialVersionUID = 6398018034431666933L; + + public VnfNotFoundException(final String message) { + super(message); + } + +} + diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmNotFoundException.java index 100aa17893..1ce6ccaef7 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmNotFoundException.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmNotFoundException.java @@ -20,9 +20,13 @@ package org.onap.so.adapters.vnfmadapter.rest.exceptions; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + /** * Exception for VNFM not found. */ +@ResponseStatus(HttpStatus.BAD_REQUEST) public class VnfmNotFoundException extends RuntimeException { private static final long serialVersionUID = 6398018034431666933L; diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmRequestFailureException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmRequestFailureException.java index 57a812da0a..9c247cc746 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmRequestFailureException.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmRequestFailureException.java @@ -31,5 +31,9 @@ public class VnfmRequestFailureException extends RuntimeException { super(message); } + public VnfmRequestFailureException(final String message, final Throwable throwable) { + super(message, throwable); + } + } |