aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/model-impl
diff options
context:
space:
mode:
authorHockla, Ali (ah999m) <ah999m@att.com>2017-11-08 17:27:16 -0600
committerHockla, Ali (ah999m) <ah999m@att.com>2017-11-08 17:33:31 -0600
commit48c62738bf4c5653e36c6ea1e8e33e649b8526fc (patch)
treeb80c35c608012e842861ef14cb9034a86406ac40 /controlloop/common/model-impl
parent9cbbe8c6abd790ab84ff47214db1f63bb5c2e1d7 (diff)
Fix SO Request body
- Renamed modelNameVersionId to modelVersionId in SOModelInfo - Removed requestID from SO Request body - As a result of this, an SOResponseWrapper was needed in order to attach the control loop event requestId to use in the SOResponse rule in drl (the requestID that is returned in the SO response is a newly generated requestId with no relation to the Policy control loop event requestId as per Arthur) - Updated drl to reflect the above mentioned change - Updated simulator and junits to reflect changes - Added an additional null httpResponse check/logger statement in SOManager and RestManager Issue-ID: POLICY-438 Change-Id: I5f414ba69b60b5565cca9073b47f4c4835e5abbf Signed-off-by: Hockla, Ali (ah999m) <ah999m@att.com>
Diffstat (limited to 'controlloop/common/model-impl')
-rw-r--r--controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java24
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java23
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOModelInfo.java4
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponseWrapper.java81
-rw-r--r--controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestDemo.java12
5 files changed, 117 insertions, 27 deletions
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";