summaryrefslogtreecommitdiffstats
path: root/controlloop/common/model-impl/so/src/main/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-01-30 17:06:20 +0000
committerliamfallon <liam.fallon@ericsson.com>2018-01-30 17:06:52 +0000
commit65f5fcc147c8dcc43b9c30742c81545859ab3e02 (patch)
tree3e0dddf90b2a1fd942399e3f9a7d479c64d35840 /controlloop/common/model-impl/so/src/main/java
parent7767c5643349e5e6691a07afd5c4acd3ef9d5617 (diff)
Fix technical debt/JUnit on SO/VFC/SO ACTOR
Unit test expanded for SO POJOs, technical debt removed in SO actor and VFC pojos. Change-Id: I23b886c40c1ac6ac8dc2ebbaade315b71cca9dd0 Signed-off-by: liamfallon <liam.fallon@ericsson.com> Issue-ID: POLICY-455
Diffstat (limited to 'controlloop/common/model-impl/so/src/main/java')
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java381
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyExceptionHolder.java (renamed from controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyException.java)4
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java14
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java12
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponseWrapper.java18
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceExceptionHolder.java (renamed from controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceException.java)4
6 files changed, 241 insertions, 192 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 4b1d1d630..35227d310 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
@@ -32,6 +32,7 @@ import org.drools.core.WorkingMemory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,176 +43,212 @@ import com.google.gson.JsonSyntaxException;
public final class SOManager {
- private static final Logger logger = LoggerFactory.getLogger(SOManager.class);
- private static final Logger netLogger =
- LoggerFactory.getLogger(org.onap.policy.drools.event.comm.Topic.NETWORK_LOGGER);
- private static ExecutorService executors = Executors.newCachedThreadPool();
-
- static final String MEDIA_TYPE = "application/json";
-
- static final String LINE_SEPARATOR = System.lineSeparator();
-
- public static SOResponse createModuleInstance(String url, String urlBase, String username,
- String password, SORequest request) {
-
- //
- // Call REST
- //
- Map<String, String> headers = new HashMap<>();
- headers.put("Accept", MEDIA_TYPE);
-
- //
- // 201 - CREATED - you are done just return
- //
- String requestJson = Serialization.gsonPretty.toJson(request);
- netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, requestJson);
- Pair<Integer, String> httpDetails =
- new RESTManager().post(url, username, password, headers, MEDIA_TYPE, requestJson);
-
- if (httpDetails == null) {
- return null;
- }
-
- if (httpDetails.a == 202) {
- try {
- SOResponse response =
- Serialization.gsonPretty.fromJson(httpDetails.b, SOResponse.class);
-
- String body = Serialization.gsonPretty.toJson(response);
- logger.debug("***** Response to post:");
- logger.debug(body);
-
- String requestId = response.getRequestReferences().getRequestId();
- int attemptsLeft = 20;
-
- String urlGet = urlBase + "/orchestrationRequests/v2/" + requestId;
- SOResponse responseGet = null;
-
- while (attemptsLeft-- > 0) {
-
- Pair<Integer, String> httpDetailsGet =
- new RESTManager().get(urlGet, username, password, headers);
- responseGet =
- Serialization.gsonPretty.fromJson(httpDetailsGet.b, SOResponse.class);
- netLogger.info("[IN|{}|{}|]{}{}", "SO", urlGet, LINE_SEPARATOR,
- httpDetailsGet.b);
-
- body = Serialization.gsonPretty.toJson(responseGet);
- logger.debug("***** Response to get:");
- logger.debug(body);
-
- if (httpDetailsGet.a == 200) {
- if (responseGet.getRequest().getRequestStatus().getRequestState()
- .equalsIgnoreCase("COMPLETE")
- || responseGet.getRequest().getRequestStatus().getRequestState()
- .equalsIgnoreCase("FAILED")) {
- logger.debug("***** ######## VF Module Creation {}",
- responseGet.getRequest().getRequestStatus().getRequestState());
- return responseGet;
- }
- }
- Thread.sleep(20000);
- }
-
- if (responseGet != null && responseGet.getRequest() != null
- && responseGet.getRequest().getRequestStatus() != null
- && responseGet.getRequest().getRequestStatus().getRequestState() != null) {
- logger.warn("***** ######## VF Module Creation timeout. Status: ( {})",
- responseGet.getRequest().getRequestStatus().getRequestState());
- }
-
- return responseGet;
- }
- catch (JsonSyntaxException e) {
- logger.error("Failed to deserialize into SOResponse: ", e);
- }
- catch (InterruptedException e) {
- logger.error("Interrupted exception: ", e);
- Thread.currentThread().interrupt();
- }
- }
-
-
-
- return null;
- }
-
- /**
- *
- * @param wm
- * @param url
- * @param urlBase
- * @param username
- * @param password
- * @param request
- *
- * This method makes an asynchronous Rest call to MSO and inserts the response into the
- * Drools working memory
- */
- public void asyncSORestCall(String requestID, WorkingMemory wm, String serviceInstanceId,
- String vnfInstanceId, SORequest request) {
- executors.submit(new Runnable() {
- @Override
- public void run() {
- try {
- String serverRoot = PolicyEngine.manager.getEnvironmentProperty("so.url");
- String username = PolicyEngine.manager.getEnvironmentProperty("so.username");
- String password = PolicyEngine.manager.getEnvironmentProperty("so.password");
-
- String url = serverRoot + "/serviceInstances/v5/" + serviceInstanceId + "/vnfs/"
- + vnfInstanceId + "/vfModules";
-
- String auth = username + ":" + password;
-
- Map<String, String> headers = new HashMap<>();
- byte[] encodedBytes = Base64.getEncoder().encode(auth.getBytes());
- headers.put("Accept", MEDIA_TYPE);
- headers.put("Authorization", "Basic " + new String(encodedBytes));
-
- Gson gsonPretty =
- new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
-
- String soJson = gsonPretty.toJson(request);
-
- SOResponse so = new SOResponse();
- netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson);
- Pair<Integer, String> httpResponse = new RESTManager().post(url, "policy",
- "policy", headers, MEDIA_TYPE, soJson);
-
- if (httpResponse != null) {
- if (httpResponse.b != null && httpResponse.a != null) {
- netLogger.info("[IN|{}|{}|]{}{}", url, "SO", LINE_SEPARATOR,
- httpResponse.b);
-
- Gson gson = new Gson();
- so = gson.fromJson(httpResponse.b, SOResponse.class);
- so.setHttpResponseCode(httpResponse.a);
- }
- else {
- logger.error("SO Response status/code is null.");
- so.setHttpResponseCode(999);
- }
-
- }
- else {
- logger.error("SO Response returned null.");
- so.setHttpResponseCode(999);
- }
-
- 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);
-
- // create dummy SO object to trigger cleanup
- SOResponse so = new SOResponse();
- so.setHttpResponseCode(999);
- wm.insert(so);
- }
- }
- });
- }
-
+ private static final Logger logger = LoggerFactory.getLogger(SOManager.class);
+ private static final Logger netLogger = LoggerFactory.getLogger(org.onap.policy.drools.event.comm.Topic.NETWORK_LOGGER);
+ private static ExecutorService executors = Executors.newCachedThreadPool();
+
+ static final String MEDIA_TYPE = "application/json";
+
+ static final String LINE_SEPARATOR = System.lineSeparator();
+
+ // REST get timeout value in milliseconds
+ private static final long DEFAULT_GET_REQUEST_TIMEOUT = 20000;
+
+ // The REST manager used for processing REST calls for this VFC manager
+ private RESTManager restManager;
+
+ private long restGetTimeout = DEFAULT_GET_REQUEST_TIMEOUT;
+
+ public SOManager() {
+ restManager = new RESTManager();
+ }
+
+ public SOResponse createModuleInstance(String url, String urlBase, String username, String password, SORequest request) {
+
+ //
+ // Call REST
+ //
+ Map<String, String> headers = new HashMap<>();
+ headers.put("Accept", MEDIA_TYPE);
+
+ //
+ // 201 - CREATED - you are done just return
+ //
+ String requestJson = Serialization.gsonPretty.toJson(request);
+ netLogger.info("[OUT|{}|{}|{}|{}|{}|{}|]{}{}", "SO", url, username, password, headers, MEDIA_TYPE, LINE_SEPARATOR, requestJson);
+ Pair<Integer, String> httpDetails = restManager.post(url, username, password, headers, MEDIA_TYPE, requestJson);
+
+ if (httpDetails == null) {
+ return null;
+ }
+
+ if (httpDetails.a != 202) {
+ return null;
+ }
+
+ try {
+ SOResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, SOResponse.class);
+
+ String body = Serialization.gsonPretty.toJson(response);
+ logger.debug("***** Response to post:");
+ logger.debug(body);
+
+ String requestId = response.getRequestReferences().getRequestId();
+ int attemptsLeft = 20;
+
+ String urlGet = urlBase + "/orchestrationRequests/v2/" + requestId;
+ SOResponse responseGet = null;
+
+ while (attemptsLeft-- > 0) {
+ Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers);
+ if (httpDetailsGet == null) {
+ return null;
+ }
+
+ responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, SOResponse.class);
+ netLogger.info("[IN|{}|{}|]{}{}", "SO", urlGet, LINE_SEPARATOR, httpDetailsGet.b);
+
+ body = Serialization.gsonPretty.toJson(responseGet);
+ logger.debug("***** Response to get:");
+ logger.debug(body);
+
+ if (httpDetailsGet.a == 200 &&
+ (responseGet.getRequest().getRequestStatus().getRequestState().equalsIgnoreCase("COMPLETE")
+ || responseGet.getRequest().getRequestStatus().getRequestState().equalsIgnoreCase("FAILED"))) {
+ logger.debug("***** ######## VF Module Creation {}",
+ responseGet.getRequest().getRequestStatus().getRequestState());
+ return responseGet;
+ }
+ Thread.sleep(restGetTimeout);
+ }
+
+ if (responseGet != null && responseGet.getRequest() != null
+ && responseGet.getRequest().getRequestStatus() != null
+ && responseGet.getRequest().getRequestStatus().getRequestState() != null) {
+ logger.warn("***** ######## VF Module Creation timeout. Status: ( {})",
+ responseGet.getRequest().getRequestStatus().getRequestState());
+ }
+
+ return responseGet;
+ }
+ catch (JsonSyntaxException e) {
+ logger.error("Failed to deserialize into SOResponse: ", e);
+ }
+ catch (InterruptedException e) {
+ logger.error("Interrupted exception: ", e);
+ Thread.currentThread().interrupt();
+ }
+
+ return null;
+ }
+
+ /**
+ *
+ * @param wm
+ * @param url
+ * @param urlBase
+ * @param username
+ * @param password
+ * @param request
+ *
+ * This method makes an asynchronous Rest call to MSO and inserts the response into the
+ * Drools working memory
+ * @return
+ */
+ public Future<?> asyncSORestCall(String requestID, WorkingMemory wm, String serviceInstanceId, String vnfInstanceId, SORequest request) {
+ return executors.submit(new AsyncSORestCallThread(requestID, wm, serviceInstanceId, vnfInstanceId, request));
+ }
+
+ private class AsyncSORestCallThread implements Runnable {
+ final String requestID;
+ final WorkingMemory wm;
+ final String serviceInstanceId;
+ final String vnfInstanceId;
+ final SORequest request;
+
+ private AsyncSORestCallThread(final String requestID, final WorkingMemory wm, final String serviceInstanceId, final String vnfInstanceId, final SORequest request) {
+ this.requestID = requestID;
+ this.wm = wm;
+ this.serviceInstanceId = serviceInstanceId;
+ this.vnfInstanceId = vnfInstanceId;
+ this.request = request;
+ }
+
+ @Override
+ public void run() {
+ try {
+ String serverRoot = PolicyEngine.manager.getEnvironmentProperty("so.url");
+ String username = PolicyEngine.manager.getEnvironmentProperty("so.username");
+ String password = PolicyEngine.manager.getEnvironmentProperty("so.password");
+
+ String url = serverRoot + "/serviceInstances/v5/" + serviceInstanceId + "/vnfs/"
+ + vnfInstanceId + "/vfModules";
+
+ String auth = username + ":" + password;
+
+ Map<String, String> headers = new HashMap<>();
+ byte[] encodedBytes = Base64.getEncoder().encode(auth.getBytes());
+ headers.put("Accept", MEDIA_TYPE);
+ headers.put("Authorization", "Basic " + new String(encodedBytes));
+
+ Gson gsonPretty =
+ new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
+
+ String soJson = gsonPretty.toJson(request);
+
+ SOResponse so = new SOResponse();
+ netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson);
+ Pair<Integer, String> httpResponse = restManager.post(url, "policy", "policy", headers, MEDIA_TYPE, soJson);
+
+ if (httpResponse != null) {
+ if (httpResponse.b != null && httpResponse.a != null) {
+ netLogger.info("[IN|{}|{}|]{}{}", url, "SO", LINE_SEPARATOR, httpResponse.b);
+
+ Gson gson = new Gson();
+ so = gson.fromJson(httpResponse.b, SOResponse.class);
+ so.setHttpResponseCode(httpResponse.a);
+ }
+ else {
+ logger.error("SO Response status/code is null.");
+ so.setHttpResponseCode(999);
+ }
+
+ }
+ else {
+ logger.error("SO Response returned null.");
+ so.setHttpResponseCode(999);
+ }
+
+ SOResponseWrapper soWrapper = new SOResponseWrapper(so, requestID);
+ wm.insert(soWrapper);
+ if (logger.isInfoEnabled()) {
+ logger.info("SOResponse inserted " + gsonPretty.toJson(soWrapper));
+ }
+ }
+ catch (Exception e) {
+ logger.error("Error while performing asyncSORestCall: " + e.getMessage(), e);
+
+ // create dummy SO object to trigger cleanup
+ SOResponse so = new SOResponse();
+ so.setHttpResponseCode(999);
+ wm.insert(so);
+ }
+ }
+ }
+
+ /**
+ * method to allow tuning of REST get timeout
+ * @param restGetTimeout the timeout value
+ */
+ protected void setRestGetTimeout(final long restGetTimeout) {
+ this.restGetTimeout = restGetTimeout;
+ }
+
+ /**
+ * Protected setter for rest manager to allow mocked rest manager to be used for testing
+ * @param restManager the test REST manager
+ */
+ protected void setRestManager(final RESTManager restManager) {
+ this.restManager = restManager;
+ }
}
diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyException.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyExceptionHolder.java
index 7065feaac..cab396d01 100644
--- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyException.java
+++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyExceptionHolder.java
@@ -24,7 +24,7 @@ import java.io.Serializable;
import com.google.gson.annotations.SerializedName;
-public class SOPolicyException implements Serializable {
+public class SOPolicyExceptionHolder implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
@@ -34,7 +34,7 @@ public class SOPolicyException implements Serializable {
@SerializedName("text")
private String text;
- public SOPolicyException() {
+ public SOPolicyExceptionHolder() {
//required by author
}
diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java
index a86418198..72e35d96e 100644
--- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java
+++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java
@@ -58,6 +58,7 @@ public class SORequestDetails implements Serializable {
this.requestInfo = soRequestDetails.requestInfo;
this.relatedInstanceList = soRequestDetails.relatedInstanceList;
this.requestParameters = soRequestDetails.requestParameters;
+ this.subscriberInfo = soRequestDetails.subscriberInfo;
}
@Override
@@ -99,6 +100,12 @@ public class SORequestDetails implements Serializable {
}
else if (!requestParameters.equals(other.requestParameters))
return false;
+ if (subscriberInfo == null) {
+ if (other.subscriberInfo != null)
+ return false;
+ }
+ else if (!subscriberInfo.equals(other.subscriberInfo))
+ return false;
return true;
}
@@ -160,11 +167,16 @@ public class SORequestDetails implements Serializable {
this.subscriberInfo = subscriberInfo;
}
+ public void setRelatedInstanceList(List<SORelatedInstanceListElement> relatedInstanceList) {
+ this.relatedInstanceList = relatedInstanceList;
+ }
+
@Override
public String toString() {
return "SORequestDetails [modelInfo=" + modelInfo + ", cloudConfiguration="
+ cloudConfiguration + ", requestInfo=" + requestInfo + ", relatedInstanceList="
- + relatedInstanceList + ", requestParameters=" + requestParameters + "]";
+ + relatedInstanceList + ", requestParameters=" + requestParameters +
+ ", subscriberInfo=" + subscriberInfo + "]";
}
}
diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java
index c9dad036a..49860417c 100644
--- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java
+++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java
@@ -29,28 +29,28 @@ public class SORequestError implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
@SerializedName("policyException")
- private SOPolicyException policyException;
+ private SOPolicyExceptionHolder policyException;
@SerializedName("serviceException")
- private SOServiceException serviceException;
+ private SOServiceExceptionHolder serviceException;
public SORequestError() {
// required by author
}
- public SOPolicyException getPolicyException() {
+ public SOPolicyExceptionHolder getPolicyException() {
return policyException;
}
- public SOServiceException getServiceException() {
+ public SOServiceExceptionHolder getServiceException() {
return serviceException;
}
- public void setPolicyException(SOPolicyException policyException) {
+ public void setPolicyException(SOPolicyExceptionHolder policyException) {
this.policyException = policyException;
}
- public void setServiceException(SOServiceException serviceException) {
+ public void setServiceException(SOServiceExceptionHolder serviceException) {
this.serviceException = serviceException;
}
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
index 184ae5ef1..e18cbb62d 100644
--- 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
@@ -29,12 +29,12 @@ public class SOResponseWrapper implements Serializable {
private static final long serialVersionUID = 7673023687132889069L;
@SerializedName("SoResponse")
- private SOResponse SoResponse;
+ private SOResponse soResponse;
private transient String requestID;
public SOResponseWrapper(SOResponse response, String reqID) {
- this.SoResponse = response;
+ this.soResponse = response;
this.requestID = reqID;
}
@@ -50,12 +50,12 @@ public class SOResponseWrapper implements Serializable {
return false;
}
SOResponseWrapper other = (SOResponseWrapper) obj;
- if (SoResponse == null) {
- if (other.SoResponse != null) {
+ if (soResponse == null) {
+ if (other.soResponse != null) {
return false;
}
}
- else if (!SoResponse.equals(other.SoResponse)) {
+ else if (!soResponse.equals(other.soResponse)) {
return false;
}
if (requestID == null) {
@@ -74,14 +74,14 @@ public class SOResponseWrapper implements Serializable {
}
public SOResponse getSoResponse() {
- return SoResponse;
+ return soResponse;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
- result = prime * result + ((SoResponse == null) ? 0 : SoResponse.hashCode());
+ result = prime * result + ((soResponse == null) ? 0 : soResponse.hashCode());
result = prime * result + ((requestID == null) ? 0 : requestID.hashCode());
return result;
}
@@ -91,12 +91,12 @@ public class SOResponseWrapper implements Serializable {
}
public void setSoResponse(SOResponse sOResponse) {
- SoResponse = sOResponse;
+ soResponse = sOResponse;
}
@Override
public String toString() {
- return "SOResponseWrapper [SOResponse=" + SoResponse + ", RequestID=" + requestID + "]";
+ return "SOResponseWrapper [SOResponse=" + soResponse + ", RequestID=" + requestID + "]";
}
}
diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceException.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceExceptionHolder.java
index 3290f2e41..61366d3c5 100644
--- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceException.java
+++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceExceptionHolder.java
@@ -26,7 +26,7 @@ import java.util.List;
import com.google.gson.annotations.SerializedName;
-public class SOServiceException implements Serializable {
+public class SOServiceExceptionHolder implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
@@ -39,7 +39,7 @@ public class SOServiceException implements Serializable {
@SerializedName("variables")
private List<String> variables = new LinkedList<>();
- public SOServiceException() {
+ public SOServiceExceptionHolder() {
// required by author
}