summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/vfc/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-impl/vfc/src/main')
-rw-r--r--models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java57
1 files changed, 24 insertions, 33 deletions
diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
index 695b1b189..850f37552 100644
--- a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
+++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
@@ -26,11 +26,9 @@ import com.google.gson.JsonSyntaxException;
import java.util.HashMap;
import java.util.Map;
-import org.drools.core.WorkingMemory;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
-import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.rest.RestManager;
import org.onap.policy.rest.RestManager.Pair;
import org.onap.policy.vfc.util.Serialization;
@@ -43,31 +41,41 @@ public final class VfcManager implements Runnable {
private String username;
private String password;
private VfcRequest vfcRequest;
- private WorkingMemory workingMem;
+ private VfcCallback callback;
private static final Logger logger = LoggerFactory.getLogger(VfcManager.class);
// The REST manager used for processing REST calls for this VFC manager
private RestManager restManager;
+ public interface VfcCallback {
+ void onResponse(VfcResponse responseError);
+ }
+
/**
* Constructor.
*
- * @param wm Drools working memory
+ * @param cb Callback method to call when response
* @param request request
+ * @param url URL to VFC component
+ * @param user username
+ * @param pwd password
*/
- public VfcManager(WorkingMemory wm, VfcRequest request) {
- if (wm == null || request == null) {
+ public VfcManager(VfcCallback cb, VfcRequest request, String url, String user, String pwd) {
+ if (cb == null || request == null) {
throw new IllegalArgumentException(
- "the parameters \"wm\" and \"request\" on the VfcManager constructor may not be null");
+ "the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null");
}
- workingMem = wm;
+ if (url == null) {
+ throw new IllegalArgumentException(
+ "the \"url\" parameter on the VfcManager constructor may not be null");
+ }
+ callback = cb;
vfcRequest = request;
+ vfcUrlBase = url;
+ username = user;
+ password = pwd;
restManager = new RestManager();
-
- // use getPEManagerEnvProperty() for required properties; others are optional
- setVfcParams(getPeManagerEnvProperty("vfc.url"), PolicyEngine.manager.getEnvironmentProperty("vfc.username"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.password"));
}
/**
@@ -101,12 +109,12 @@ public final class VfcManager implements Runnable {
httpDetails = restManager.post(vfcUrl, username, password, headers, "application/json", vfcRequestJson);
} catch (Exception e) {
logger.error(e.getMessage(), e);
- workingMem.insert(responseError);
+ this.callback.onResponse(responseError);
return;
}
if (httpDetails == null) {
- workingMem.insert(responseError);
+ this.callback.onResponse(responseError);
return;
}
@@ -142,7 +150,7 @@ public final class VfcManager implements Runnable {
if (httpDetailsGet.first == 200
&& ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) {
logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus());
- workingMem.insert(responseGet);
+ this.callback.onResponse(responseGet);
break;
}
Thread.sleep(20000);
@@ -151,7 +159,7 @@ public final class VfcManager implements Runnable {
&& (responseGet.getResponseDescriptor().getStatus() != null)
&& (!responseGet.getResponseDescriptor().getStatus().isEmpty())) {
logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus());
- workingMem.insert(responseGet);
+ this.callback.onResponse(responseGet);
}
} catch (JsonSyntaxException e) {
logger.error("Failed to deserialize into VfcResponse {}", e.getLocalizedMessage(), e);
@@ -171,21 +179,4 @@ public final class VfcManager implements Runnable {
protected void setRestManager(final RestManager restManager) {
this.restManager = restManager;
}
-
- /**
- * This method reads and validates environmental properties coming from the policy engine. Null
- * properties cause an {@link IllegalArgumentException} runtime exception to be thrown
- *
- * @param string the name of the parameter to retrieve
- * @return the property value
- */
-
- private String getPeManagerEnvProperty(String enginePropertyName) {
- String enginePropertyValue = PolicyEngine.manager.getEnvironmentProperty(enginePropertyName);
- if (enginePropertyValue == null) {
- throw new IllegalArgumentException("The value of policy engine manager environment property \""
- + enginePropertyName + "\" may not be null");
- }
- return enginePropertyValue;
- }
}