diff options
Diffstat (limited to 'controlloop/common')
9 files changed, 138 insertions, 47 deletions
diff --git a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java index bf00a51d3..9cb211b22 100644 --- a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java +++ b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java @@ -327,7 +327,7 @@ public class SOActorServiceProvider implements Actor { // Construct SO Request SORequest request = new SORequest(); - request.requestId = onset.requestID; +// request.requestId = onset.requestID; request.requestDetails = new SORequestDetails(); request.requestDetails.modelInfo = new SOModelInfo(); request.requestDetails.cloudConfiguration = new SOCloudConfiguration(); @@ -344,7 +344,7 @@ public class SOActorServiceProvider implements Actor { // request.requestDetails.modelInfo.modelType = "vfModule"; request.requestDetails.modelInfo.modelInvariantId = getVfModuleItemModelInvariantId(); - request.requestDetails.modelInfo.modelNameVersionId = getVfModuleItemModelNameVersionId(); + request.requestDetails.modelInfo.modelVersionId = getVfModuleItemModelNameVersionId(); request.requestDetails.modelInfo.modelName = getVfModuleItemModelName(); request.requestDetails.modelInfo.modelVersion = getVfModuleItemModelVersionId(); // @@ -365,7 +365,7 @@ public class SOActorServiceProvider implements Actor { relatedInstanceListElement1.relatedInstance.modelInfo = new SOModelInfo(); relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = getServiceItemModelInvariantId(); - relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = getServiceItemModelNameVersionId(); + relatedInstanceListElement1.relatedInstance.modelInfo.modelVersionId = getServiceItemModelNameVersionId(); relatedInstanceListElement1.relatedInstance.modelInfo.modelName = getServiceItemModelName(); relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = getServiceItemModelVersion(); // @@ -373,7 +373,7 @@ public class SOActorServiceProvider implements Actor { relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = getVnfItemModelInvariantId(); - relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = getVnfItemModelNameVersionId(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelVersionId = getVnfItemModelNameVersionId(); relatedInstanceListElement2.relatedInstance.modelInfo.modelName = getVnfItemModelName(); relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = getVnfItemModelVersion(); relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = getVnfItemVnfType(); @@ -397,9 +397,9 @@ public class SOActorServiceProvider implements Actor { * @param wm * @param request */ - public static void sendRequest(WorkingMemory wm, Object request) { + public static void sendRequest(String requestID, WorkingMemory wm, Object request) { SOManager Mm = new SOManager(); - Mm.asyncSORestCall(wm, getServiceItemServiceInstanceId(), getVnfItemVnfId(), (SORequest)request); + Mm.asyncSORestCall(requestID, wm, getServiceItemServiceInstanceId(), getVnfItemVnfId(), (SORequest)request); } /** diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java index 26a82fe57..d52f7fd47 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java @@ -48,6 +48,7 @@ import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.guard.Util; import org.onap.policy.so.SOResponse; +import org.onap.policy.so.SOResponseWrapper; import org.onap.policy.vfc.VFCResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -420,16 +421,16 @@ public class ControlLoopOperationManager implements Serializable { return result.getKey(); } return null; - } else if (response instanceof SOResponse) { - SOResponse msoResponse = (SOResponse) response; + } else if (response instanceof SOResponseWrapper) { + SOResponseWrapper msoResponse = (SOResponseWrapper) response; - switch (msoResponse.httpResponseCode) { + switch (msoResponse.SOResponse.httpResponseCode) { case 200: case 202: // // Consider it as success // - this.completeOperation(this.attempts, msoResponse.httpResponseCode + " Success", PolicyResult.SUCCESS); + this.completeOperation(this.attempts, msoResponse.SOResponse.httpResponseCode + " Success", PolicyResult.SUCCESS); if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) { return null; } @@ -438,7 +439,7 @@ public class ControlLoopOperationManager implements Serializable { // // Consider it as failure // - this.completeOperation(this.attempts, msoResponse.httpResponseCode + " Failed", PolicyResult.FAILURE); + this.completeOperation(this.attempts, msoResponse.SOResponse.httpResponseCode + " Failed", PolicyResult.FAILURE); if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) { return null; } diff --git a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java index 9ea480981..e2d140c03 100644 --- a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java +++ b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java @@ -79,19 +79,21 @@ public final class RESTManager { post.setEntity(input); HttpResponse response = client.execute(post); - - String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); - logger.debug("HTTP POST Response Status Code: {}", response.getStatusLine().getStatusCode()); - logger.debug("HTTP POST Response Body:"); - logger.debug(returnBody); - - return new Pair<Integer, String>(response.getStatusLine().getStatusCode(), returnBody); - } catch (IOException e) { + if (response != null) { + String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); + logger.debug("HTTP POST Response Status Code: {}", response.getStatusLine().getStatusCode()); + logger.debug("HTTP POST Response Body:"); + logger.debug(returnBody); + + return new Pair<Integer, String>(response.getStatusLine().getStatusCode(), returnBody); + } else { + logger.error("Response from {} is null", url); + return null; + } + } catch (Exception e) { logger.error("Failed to POST to {}",url,e); - return null; - } - + } } public static Pair<Integer, String> get(String url, String username, String password, Map<String, String> headers) { 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 c3828bb79..4ac98054f 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 @@ -135,7 +135,7 @@ public final class SOManager { * * This method makes an asynchronous Rest call to MSO and inserts the response into the Drools working memory */ - public void asyncSORestCall(WorkingMemory wm, String serviceInstanceId, String vnfInstanceId, SORequest request) { + public void asyncSORestCall(String requestID, WorkingMemory wm, String serviceInstanceId, String vnfInstanceId, SORequest request) { executors.submit(new Runnable() { @Override @@ -165,19 +165,26 @@ public final class SOManager { netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, System.lineSeparator(), soJson); Pair<Integer, String> httpResponse = RESTManager.post(url, "policy", "policy", headers, "application/json", soJson); - if (httpResponse != null) { - netLogger.info("[IN|{}|{}|]{}{}", url, "SO", System.lineSeparator(), httpResponse.b); + if (httpResponse != null ) { + if (httpResponse.b != null && httpResponse.a != null) { + netLogger.info("[IN|{}|{}|]{}{}", url, "SO", System.lineSeparator(), httpResponse.b); + + Gson gson = new Gson(); + so = gson.fromJson(httpResponse.b, SOResponse.class); + so.httpResponseCode = httpResponse.a; + } else { + logger.error("SO Response status/code is null."); + so.httpResponseCode = 999; + } - Gson gson = new Gson(); - so = gson.fromJson(httpResponse.b, SOResponse.class); - so.httpResponseCode = httpResponse.a; } else { logger.error("SO Response returned null."); so.httpResponseCode = 999; } - wm.insert(so); - logger.info("SOResponse inserted " + gsonPretty.toJson(so)); + SOResponseWrapper SoWrapper = new SOResponseWrapper(so, requestID); + wm.insert(SoWrapper); + logger.info("SOResponse inserted " + gsonPretty.toJson(SoWrapper)); } catch (Exception e) { logger.error("Error while performing asyncSORestCall: "+ e.getMessage(),e); diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOModelInfo.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOModelInfo.java index 94070ba9a..c6e138a2a 100644 --- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOModelInfo.java +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOModelInfo.java @@ -38,8 +38,8 @@ public class SOModelInfo implements Serializable { @SerializedName("modelInvariantId") public String modelInvariantId; - @SerializedName("modelNameVersionId") - public String modelNameVersionId; + @SerializedName("modelVersionId") + public String modelVersionId; @SerializedName("modelName") public String modelName; diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponseWrapper.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponseWrapper.java new file mode 100644 index 000000000..6b2017eb2 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponseWrapper.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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; + +import java.io.Serializable; + +import com.google.gson.annotations.SerializedName; + +public class SOResponseWrapper implements Serializable { + + private static final long serialVersionUID = 7673023687132889069L; + + @SerializedName("SOResponse") + public SOResponse SOResponse; + public transient String requestID; + + + public SOResponseWrapper(SOResponse response, String reqID) { + this.SOResponse = response; + this.requestID = reqID; + } + + @Override + public String toString() { + return "SOResponseWrapper [SOResponse=" + SOResponse + ", RequestID=" + requestID + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((SOResponse == null) ? 0 : SOResponse.hashCode()); + result = prime * result + ((requestID == null) ? 0 : requestID.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (getClass() != obj.getClass()) { + return false; + } + SOResponseWrapper other = (SOResponseWrapper) obj; + if (SOResponse == null) { + if (other.SOResponse != null) { + return false; + } + } else if (!SOResponse.equals(other.SOResponse)) { + return false; + } + if (requestID == null) { + if (other.requestID != null) { + return false; + } + } else if (!requestID.equals(other.requestID)) { + return false; + } + return true; + } + +} diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestDemo.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestDemo.java index af8f4be0e..79f8d9392 100644 --- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestDemo.java +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestDemo.java @@ -50,7 +50,7 @@ public class TestDemo { request.requestDetails.modelInfo.modelType = "vfModule"; request.requestDetails.modelInfo.modelInvariantId = "ff5256d2-5a33-55df-13ab-12abad84e7ff"; - request.requestDetails.modelInfo.modelNameVersionId = "fe6478e5-ea33-3346-ac12-ab121484a3fe"; + request.requestDetails.modelInfo.modelVersionId = "fe6478e5-ea33-3346-ac12-ab121484a3fe"; request.requestDetails.modelInfo.modelName = "vSAMP12..base..module-0"; request.requestDetails.modelInfo.modelVersion = "1"; @@ -77,7 +77,7 @@ public class TestDemo { relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "service"; relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = "ff3514e3-5a33-55df-13ab-12abad84e7ff"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = "fe6985cd-ea33-3346-ac12-ab121484a3fe"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelVersionId = "fe6985cd-ea33-3346-ac12-ab121484a3fe"; relatedInstanceListElement2.relatedInstance.modelInfo.modelName = "parent service model name"; relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = "1.0"; @@ -85,7 +85,7 @@ public class TestDemo { relatedInstanceListElement3.relatedInstance.modelInfo = new SOModelInfo(); relatedInstanceListElement3.relatedInstance.modelInfo.modelType = "vnf"; relatedInstanceListElement3.relatedInstance.modelInfo.modelInvariantId = "ff5256d1-5a33-55df-13ab-12abad84e7ff"; - relatedInstanceListElement3.relatedInstance.modelInfo.modelNameVersionId = "fe6478e4-ea33-3346-ac12-ab121484a3fe"; + relatedInstanceListElement3.relatedInstance.modelInfo.modelVersionId = "fe6478e4-ea33-3346-ac12-ab121484a3fe"; relatedInstanceListElement3.relatedInstance.modelInfo.modelName = "vSAMP12"; relatedInstanceListElement3.relatedInstance.modelInfo.modelVersion = "1.0"; relatedInstanceListElement3.relatedInstance.modelInfo.modelCustomizationName = "vSAMP12 1"; @@ -123,7 +123,7 @@ public class TestDemo { request.requestDetails.modelInfo.modelType = "vfModule"; request.requestDetails.modelInfo.modelInvariantId = "a9c4a35a-de48-451a-9e4e-343f2ac52928"; - request.requestDetails.modelInfo.modelNameVersionId = "e0d98ad1-238d-4555-b439-023d3f9079f6"; + request.requestDetails.modelInfo.modelVersionId = "e0d98ad1-238d-4555-b439-023d3f9079f6"; request.requestDetails.modelInfo.modelName = "0d9e0d9d352749f4B3cb..dnsscaling..module-0"; request.requestDetails.modelInfo.modelVersion = "2.0"; @@ -144,7 +144,7 @@ public class TestDemo { relatedInstanceListElement1.relatedInstance.modelInfo = new SOModelInfo(); relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = "24329a0c-1d57-4210-b1af-a65df64e9d59"; - relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = "ac642881-8e7e-4217-bd64-16ad41c42e30"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelVersionId = "ac642881-8e7e-4217-bd64-16ad41c42e30"; relatedInstanceListElement1.relatedInstance.modelInfo.modelName = "5116d67e-0b4f-46bf-a46f"; relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = "2.0"; @@ -153,7 +153,7 @@ public class TestDemo { relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = "09fd971e-db5f-475d-997c-cf6704b6b8fe"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = "152ed917-6dcc-46ee-bf8a-a775c5aa5a74"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelVersionId = "152ed917-6dcc-46ee-bf8a-a775c5aa5a74"; relatedInstanceListElement2.relatedInstance.modelInfo.modelName = "9e4c31d2-4b25-4d9e-9fb4"; relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = "2.0"; relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = "0d9e0d9d-3527-49f4-b3cb 2"; diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java index 2dd4d0908..e70a88517 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java @@ -27,9 +27,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import org.onap.policy.so.SORequest; -import org.onap.policy.so.util.Serialization; - @Path("/serviceInstances") public class SoSimulatorJaxRs { @@ -37,10 +34,13 @@ public class SoSimulatorJaxRs { @Path("/v5/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules") @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") - public String SoPostQuery(@PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId, String req) + public String SoPostQuery(@PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId) { - SORequest request = Serialization.gsonPretty.fromJson(req, SORequest.class); - return "{\"requestReferences\": {\"instanceId\": \"ff305d54-75b4-ff1b-bdb2-eb6b9e5460ff\", \"requestId\": " + request.requestId + "}}"; + + // the requestID contained in the SO Response is a newly generated requestID + // with no relation to the requestID in Policy controlLoopEvent + return "{\"requestReferences\": {\"instanceId\": \"ff305d54-75b4-ff1b-bdb2-eb6b9e5460ff\", \"requestId\": \"rq1234d1-5a33-ffdf-23ab-12abad84e331\" }}"; + } } diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java index 090236c40..3e5af3891 100644 --- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java +++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java @@ -86,7 +86,7 @@ public class SoSimulatorTest { // request.requestDetails.modelInfo.modelType = "vfModule"; request.requestDetails.modelInfo.modelInvariantId = "f32568ec-2f1c-458a-864b-0593d53d141a"; - request.requestDetails.modelInfo.modelNameVersionId = "69615025-879d-4f0d-afe3-b7d1a7eeed1f"; + request.requestDetails.modelInfo.modelVersionId = "69615025-879d-4f0d-afe3-b7d1a7eeed1f"; request.requestDetails.modelInfo.modelName = "C15ce9e1E9144c8fB8bb..dnsscaling..module-1"; request.requestDetails.modelInfo.modelVersion = "1.0"; // @@ -111,7 +111,7 @@ public class SoSimulatorTest { relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = "4fcbc1c0-7793-46d8-8aa1-fa1c2ed9ec7b"; - relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = + relatedInstanceListElement1.relatedInstance.modelInfo.modelVersionId = "5c996219-b2e2-4c76-9b43-7e8672a33c1d"; relatedInstanceListElement1.relatedInstance.modelInfo.modelName = "8330e932-2a23-4943-8606"; relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = "1.0"; @@ -121,7 +121,7 @@ public class SoSimulatorTest { relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = "033a32ed-aa65-4764-a736-36f2942f1aa0"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = + relatedInstanceListElement2.relatedInstance.modelInfo.modelVersionId = "d4d072dc-4e21-4a03-9524-628985819a8e"; relatedInstanceListElement2.relatedInstance.modelInfo.modelName = "c15ce9e1-e914-4c8f-b8bb"; relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = "1"; |