diff options
author | Piyush Garg <piyush.garg1@amdocs.com> | 2018-08-29 15:40:53 +0530 |
---|---|---|
committer | Piyush Garg <piyush.garg1@amdocs.com> | 2018-08-31 20:48:21 +0000 |
commit | 0b6288e180c1d33bba88b3df5e03442c57058db9 (patch) | |
tree | 072c9c553f9ac7a4874ce97101be5c6e211d547e /controlloop/common/model-impl/so/src/main | |
parent | 8279af376b435e1d7dd118a1955c5681edf3b847 (diff) |
Added support for VF Module Delete recipe
Enhanced SOActorServiceProvider to support VF Module Delete Recipe.
Added SOOperationType enum to map the policy recipe with the SO API that
we want to call for a recipe. vf module id from non-base vf module is
used to construct the delete request url and same will be deleted.
Updated SOManager so that it sends request to SO based on the
SOOperationType enum value.
Enhanced RESTManager to add support for the http delete using new class
HttpDeleteWithBody (to allow pass the payload to the SO delete VF module API).
Change-Id: I15b678ed9ebc85dfa7cb62bbf23e41c0fe6e4c69
Issue-ID: POLICY-1079
Signed-off-by: Piyush Garg <piyush.garg1@amdocs.com>
Diffstat (limited to 'controlloop/common/model-impl/so/src/main')
3 files changed, 108 insertions, 30 deletions
diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java index a3f2be30b..5acd973ef 100644 --- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java @@ -98,19 +98,35 @@ public final class SOManager { } /** + * Works just like {@link SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest) + * except the vfModuleInstanceId is always null + * + * @see SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest) + */ + public Future<SOResponse> asyncSORestCall(final String requestID, final WorkingMemory wm, + final String serviceInstanceId, final String vnfInstanceId, + final SORequest request) { + return asyncSORestCall(requestID, wm, serviceInstanceId, vnfInstanceId, null, request); + } + + /** * This method makes an asynchronous Rest call to MSO and inserts the response into * Drools working memory. - * - * @param requestID request id - * @param wm the Drools working memory - * @param serviceInstanceId service instance id - * @param vnfInstanceId vnf instance id - * @param request the SO request + * + * @param requestID + * @param wm the Drools working memory + * @param serviceInstanceId service instance id to construct the request url + * @param vnfInstanceId vnf instance id to construct the request url + * @param vfModuleInstanceId vfModule instance id to construct the request url (required in case of delete vf + * module) + * @param request the SO request * @return a concurrent Future for the thread that handles the request */ public Future<SOResponse> asyncSORestCall(final String requestID, final WorkingMemory wm, - final String serviceInstanceId, final String vnfInstanceId, final SORequest request) { - return executors.submit(new AsyncSORestCallThread(requestID, wm, serviceInstanceId, vnfInstanceId, request)); + final String serviceInstanceId, final String vnfInstanceId, final String vfModuleInstanceId, final + SORequest request) { + return executors.submit(new AsyncSORestCallThread(requestID, wm, serviceInstanceId, vnfInstanceId, + vfModuleInstanceId, request)); } /** @@ -121,23 +137,26 @@ public final class SOManager { final WorkingMemory wm; final String serviceInstanceId; final String vnfInstanceId; + final String vfModuleInstanceId; final SORequest request; /** * Constructor, sets the context of the request. * - * @param requestID The request ID - * @param wm reference to the Drools working memory - * @param serviceInstanceId the service instance in SO to use - * @param vnfInstanceId the VNF instance that is the subject of the request - * @param request the request itself + * @param requestID The request ID + * @param wm reference to the Drools working memory + * @param serviceInstanceId the service instance in SO to use + * @param vnfInstanceId the VNF instance that is the subject of the request + * @param vfModuleInstanceId the vf module instance id (not null in case of delete vf module request) + * @param request the request itself */ private AsyncSORestCallThread(final String requestID, final WorkingMemory wm, final String serviceInstanceId, - final String vnfInstanceId, final SORequest request) { + final String vnfInstanceId, final String vfModuleInstanceId, final SORequest request) { this.requestID = requestID; this.wm = wm; this.serviceInstanceId = serviceInstanceId; this.vnfInstanceId = vnfInstanceId; + this.vfModuleInstanceId = vfModuleInstanceId; this.request = request; } @@ -150,16 +169,26 @@ public final class SOManager { String username = PolicyEngine.manager.getEnvironmentProperty("so.username"); String password = PolicyEngine.manager.getEnvironmentProperty("so.password"); - // The URL of the request we will POST - String url = urlBase + "/serviceInstantiation/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId - + "/vfModules/scaleOut"; - // Create a JSON representation of the request String soJson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create().toJson(request); - - netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson); - Pair<Integer, String> httpResponse = - restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson); + String url = null; + Pair<Integer, String> httpResponse = null; + + if (request.getOperationType() != null && request.getOperationType() + .equals(SoOperationType.SCALE_OUT)) { + url = urlBase + "/serviceInstantiation/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + + "/vfModules/scaleOut"; + netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson); + httpResponse = restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson); + } else if (request.getOperationType() != null && request.getOperationType() + .equals(SoOperationType.DELETE_VF_MODULE)) { + url = urlBase + "/serviceInstances/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + + "/vfModules/" + vfModuleInstanceId; + netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson); + httpResponse = restManager.delete(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson); + } else { + return null; + } // Process the response from SO SOResponse response = waitForSOOperationCompletion(urlBase, username, password, url, httpResponse); @@ -241,7 +270,7 @@ public final class SOManager { * Parse the response message from SO into a SOResponse object. * * @param requestURL The URL of the HTTP request - * @param httpDetails The HTTP message returned from SO + * @param httpResponse The HTTP message returned from SO * @return The parsed response */ private SOResponse processSOResponse(final String requestURL, final Pair<Integer, String> httpResponse) { @@ -250,7 +279,7 @@ public final class SOManager { // A null httpDetails indicates a HTTP problem, a valid response from SO must be // either 200 // or 202 - if (!httpResultIsNullFree(httpResponse) || (httpResponse.a != 200 && httpResponse.a != 202)) { + if (!httpResultIsNullFree(httpResponse) || (httpResponse.first != 200 && httpResponse.first != 202)) { logger.error("Invalid HTTP response received from SO"); response.setHttpResponseCode(SO_RESPONSE_ERROR); return response; @@ -258,7 +287,7 @@ public final class SOManager { // Parse the JSON of the response into our POJO try { - response = Serialization.gsonPretty.fromJson(httpResponse.b, SOResponse.class); + response = Serialization.gsonPretty.fromJson(httpResponse.second, SOResponse.class); } catch (JsonSyntaxException e) { logger.error("Failed to deserialize HTTP response into SOResponse: ", e); response.setHttpResponseCode(SO_RESPONSE_ERROR); @@ -267,14 +296,14 @@ public final class SOManager { // Set the HTTP response code of the response if needed if (response.getHttpResponseCode() == 0) { - response.setHttpResponseCode(httpResponse.a); + response.setHttpResponseCode(httpResponse.first); } - netLogger.info("[IN|{}|{}|]{}{}", "SO", requestURL, LINE_SEPARATOR, httpResponse.b); + netLogger.info("[IN|{}|{}|]{}{}", "SO", requestURL, LINE_SEPARATOR, httpResponse.second); if (logger.isDebugEnabled()) { logger.debug("***** Response to SO Request to URL {}:", requestURL); - logger.debug(httpResponse.b); + logger.debug(httpResponse.second); } return response; @@ -308,7 +337,7 @@ public final class SOManager { * @return true if the request for the response is finished */ private boolean isRequestStateFinished(final Pair<Integer, String> latestHTTPDetails, final SOResponse response) { - if (latestHTTPDetails != null && 200 == latestHTTPDetails.a && isRequestStateDefined(response)) { + if (latestHTTPDetails != null && 200 == latestHTTPDetails.first && isRequestStateDefined(response)) { String requestState = response.getRequest().getRequestStatus().getRequestState(); return "COMPLETE".equalsIgnoreCase(requestState) || "FAILED".equalsIgnoreCase(requestState); } else { @@ -323,7 +352,7 @@ public final class SOManager { * @return true if no nulls are found */ private boolean httpResultIsNullFree(Pair<Integer, String> httpOperationResult) { - return httpOperationResult != null && httpOperationResult.a != null && httpOperationResult.b != null; + return httpOperationResult != null && httpOperationResult.first != null && httpOperationResult.second != null; } /** diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java index 4a2f405e7..8bcbacf73 100644 --- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java @@ -51,6 +51,8 @@ public class SORequest implements Serializable { @SerializedName("requestStatus") private SORequestStatus requestStatus; + private transient SoOperationType operationType; + public SORequest() { // required by author } @@ -111,4 +113,11 @@ public class SORequest implements Serializable { this.startTime = startTime; } + public SoOperationType getOperationType() { + return operationType; + } + + public void setOperationType(SoOperationType operationType) { + this.operationType = operationType; + } } diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java new file mode 100644 index 000000000..7619e3a84 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2018 Amdocs. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.so; + +/** + * Enumeration of SO Operations type that can be performed by a policy + */ +public enum SoOperationType { + SCALE_OUT("Create Vf Module"), + DELETE_VF_MODULE("Delete Vf Module"); + + private String operationType; + + SoOperationType(String operationType) { + this.operationType = operationType; + } + + @Override + public String toString() { + return this.operationType; + } +} |