diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2019-04-05 21:07:07 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2019-04-08 10:42:22 -0400 |
commit | ada55be1b59899e461dc5177782e381f89cbc407 (patch) | |
tree | 7bdb3eb5fe44e166a75a3333bf81f2293a3585de /models-interactions/model-impl/vfc/src/main | |
parent | eb7127ac85b3df30a09277721a5f9271033843e7 (diff) |
Remove drools PDP dependency
Removing working memory and use of PolicyEngine from
drools in these classes.
Cleaned up some unused imports and checkstyle.
Issue-ID: POLICY-1264
Change-Id: Id059da9689a721b0eafc6b310adcbdad43574ce7
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
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.java | 57 |
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; - } } |