summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/vfc/src
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-04-05 21:07:07 -0400
committerPamela Dragosh <pdragosh@research.att.com>2019-04-08 10:42:22 -0400
commitada55be1b59899e461dc5177782e381f89cbc407 (patch)
tree7bdb3eb5fe44e166a75a3333bf81f2293a3585de /models-interactions/model-impl/vfc/src
parenteb7127ac85b3df30a09277721a5f9271033843e7 (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')
-rw-r--r--models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java57
-rw-r--r--models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java110
2 files changed, 49 insertions, 118 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;
- }
}
diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
index f8a5c5287..15534dbbb 100644
--- a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
+++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
@@ -24,7 +24,6 @@ package org.onap.policy.vfc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.endsWith;
@@ -37,18 +36,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-import org.drools.core.WorkingMemory;
-import org.junit.After;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-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.VfcManager.VfcCallback;
import org.onap.policy.vfc.util.Serialization;
-public class VfcManagerTest {
- private static WorkingMemory mockedWorkingMemory;
+public class VfcManagerTest implements VfcCallback {
private RestManager mockedRestManager;
@@ -60,11 +55,6 @@ public class VfcManagerTest {
private VfcRequest request;
private VfcResponse response;
- @BeforeClass
- public static void beforeTestVfcManager() {
- mockedWorkingMemory = mock(WorkingMemory.class);
- }
-
/**
* Set up the mocked REST manager.
*/
@@ -118,64 +108,43 @@ public class VfcManagerTest {
response.setResponseDescriptor(responseDescriptor);
}
- /**
- * Remove the environnment.
- */
- @After
- public void tearDown() {
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
- }
-
@Test
public void testVfcInitiation() {
try {
- new VfcManager(null, null);
+ new VfcManager(null, null, null, null, null);
fail("test should throw an exception here");
}
catch (IllegalArgumentException e) {
- assertEquals("the parameters \"wm\" and \"request\" on the VfcManager constructor may not be null",
+ assertEquals("the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null",
e.getMessage());
}
try {
- new VfcManager(mockedWorkingMemory, null);
+ new VfcManager(this, null, null, null, null);
fail("test should throw an exception here");
}
catch (IllegalArgumentException e) {
- assertEquals("the parameters \"wm\" and \"request\" on the VfcManager constructor may not be null",
+ assertEquals("the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null",
e.getMessage());
}
try {
- new VfcManager(mockedWorkingMemory, request);
+ new VfcManager(this, request, null, null, null);
fail("test should throw an exception here");
}
catch (IllegalArgumentException e) {
- assertEquals("The value of policy engine manager environment property \"vfc.url\" may not be null",
+ assertEquals("the \"url\" parameter on the VfcManager constructor may not be null",
e.getMessage());
}
- // add url; username & password are not required
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- new VfcManager(mockedWorkingMemory, request);
+ new VfcManager(this, request, "http://somewhere.over.the.rainbow", null, null);
- // url & username, but no password
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
-
- // url, username, and password
- PolicyEngine.manager.getEnvironment().put("vfc.password", "Toto");
- new VfcManager(mockedWorkingMemory, request);
+ new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Toto");
}
@Test
public void testVfcExecutionException() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "Exception");
-
- VfcManager manager = new VfcManager(mockedWorkingMemory, request);
+ VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Exception");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
@@ -191,94 +160,62 @@ public class VfcManagerTest {
.thenThrow(new RuntimeException("OzException"));
managerThread.join();
-
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
}
@Test
public void testVfcExecutionNull() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "Null");
-
- VfcManager manager = new VfcManager(mockedWorkingMemory, request);
+ VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Null");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
+ when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
.thenReturn(null);
managerThread.join();
-
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
}
@Test
public void testVfcExecutionError0() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "Error0");
-
- VfcManager manager = new VfcManager(mockedWorkingMemory, request);
+ VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Error0");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
+ when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseErr);
managerThread.join();
-
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
}
@Test
public void testVfcExecutionBadResponse() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "BadResponse");
-
- VfcManager manager = new VfcManager(mockedWorkingMemory, request);
+ VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "BadResponse");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
+ when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseBadResponse);
managerThread.join();
-
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
}
@Test
public void testVfcExecutionOk() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "OK");
-
- VfcManager manager = new VfcManager(mockedWorkingMemory, request);
+ VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Ok");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
+ when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponsePutOk);
@@ -286,9 +223,12 @@ public class VfcManagerTest {
.thenReturn(httpResponseGetOk);
managerThread.join();
+ }
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
+ @Override
+ public void onResponse(VfcResponse responseError) {
+ //
+ // Nothing needs to be done
+ //
}
}