aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java4
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java7
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java8
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java8
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java11
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/TestUtilsCommon.java6
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java19
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java4
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java2
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java4
-rw-r--r--applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java5
-rw-r--r--applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequest.java18
-rw-r--r--applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java8
-rw-r--r--applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java4
-rw-r--r--applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java10
-rw-r--r--applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java16
-rw-r--r--applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java7
-rw-r--r--applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java18
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/provider/DecisionProvider.java6
19 files changed, 78 insertions, 87 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java
index 47ff70f6..32b950b4 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -49,7 +49,7 @@ public interface ToscaPolicyTranslator {
* @param request Incoming DecisionRequest
* @return Xacml Request object
*/
- Request convertRequest(DecisionRequest request);
+ Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException;
/**
* Implement this method to convert a Xacml Response
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
index 34936b06..3ac57b7b 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
@@ -69,7 +69,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
}
@Override
- public Request convertRequest(DecisionRequest request) {
+ public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException {
return null;
}
@@ -99,9 +99,10 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
scanAdvice(xacmlResult.getAssociatedAdvice(), decisionResponse);
} else {
//
- // TODO we have to return an ErrorResponse object instead
+ // Return error information back
//
- decisionResponse.setStatus("A better error message");
+ decisionResponse.setStatus("error");
+ decisionResponse.setMessage(xacmlResult.getStatus().getStatusMessage());
}
}
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
index aba5e252..d9661829 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
@@ -127,17 +127,13 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator {
}
@Override
- public Request convertRequest(DecisionRequest request) {
+ public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException {
LOGGER.info("Converting Request {}", request);
try {
return RequestParser.parseRequest(StdCombinedPolicyRequest.createInstance(request));
} catch (IllegalArgumentException | IllegalAccessException | DataTypeException e) {
- LOGGER.error("Failed to convert DecisionRequest", e);
+ throw new ToscaPolicyConversionException("Failed to parse request", e);
}
- //
- // TODO throw exception
- //
- return null;
}
/**
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
index d5e2a395..7ca995e0 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
@@ -100,17 +100,13 @@ public class StdMatchableTranslator extends StdBaseTranslator {
}
@Override
- public Request convertRequest(DecisionRequest request) {
+ public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException {
LOGGER.info("Converting Request {}", request);
try {
return StdMatchablePolicyRequest.createInstance(request);
} catch (XacmlApplicationException e) {
- LOGGER.error("Failed to convert DecisionRequest", e);
+ throw new ToscaPolicyConversionException("Failed to convert DecisionRequest", e);
}
- //
- // TODO throw exception
- //
- return null;
}
/**
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
index 11271651..0fdd3a96 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
@@ -232,7 +232,16 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
//
// Convert to a XacmlRequest
//
- Request xacmlRequest = this.getTranslator().convertRequest(request);
+ Request xacmlRequest;
+ try {
+ xacmlRequest = this.getTranslator().convertRequest(request);
+ } catch (ToscaPolicyConversionException e) {
+ LOGGER.error("Failed to convert request", e);
+ DecisionResponse response = new DecisionResponse();
+ response.setStatus("error");
+ response.setMessage(e.getLocalizedMessage());
+ return Pair.of(response, null);
+ }
//
// Now get a decision
//
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/TestUtilsCommon.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/TestUtilsCommon.java
index ab5dde27..026bea9e 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/TestUtilsCommon.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/TestUtilsCommon.java
@@ -112,9 +112,11 @@ public class TestUtilsCommon {
* @param policyIds Collection of IdReference objects
* @return Response object
*/
- public static Response createXacmlResponse(StatusCode code, Decision decision, Collection<Obligation> obligations,
+ public static Response createXacmlResponse(StatusCode code, String message, Decision decision,
+ Collection<Obligation> obligations,
Collection<IdReference> policyIds) {
- StdStatus status = new StdStatus(code);
+
+ StdStatus status = new StdStatus(code, message);
StdMutableResult result = new StdMutableResult(decision, status);
result.addObligations(obligations);
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
index 8039a9cf..8e692583 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
@@ -120,7 +120,7 @@ public class StdBaseTranslatorTest {
}
@Test
- public void test() throws ParseException {
+ public void testTranslatorNormalFlow() throws Exception {
StdBaseTranslator translator = new MyStdBaseTranslator();
assertNotNull(translator);
assertThatThrownBy(() -> translator.convertPolicy(null)).isInstanceOf(ToscaPolicyConversionException.class);
@@ -176,7 +176,7 @@ public class StdBaseTranslatorTest {
ids.put("onap.policies.Test", "1.0.0");
Collection<IdReference> policyIds = TestUtilsCommon.createPolicyIdList(ids);
- Response xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_OK,
+ Response xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_OK, null,
Decision.PERMIT, Arrays.asList(obligation), policyIds);
DecisionResponse decision = translator.convertResponse(xacmlResponse);
@@ -210,7 +210,7 @@ public class StdBaseTranslatorTest {
ids.put("onap.policies.Test", "1.0.0");
Collection<IdReference> policyIds = TestUtilsCommon.createPolicyIdList(ids);
- Response xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_OK,
+ Response xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_OK, null,
Decision.PERMIT, Arrays.asList(obligation), policyIds);
DecisionResponse decision = translator.convertResponse(xacmlResponse);
@@ -220,28 +220,25 @@ public class StdBaseTranslatorTest {
assertThat(decision.getPolicies()).isNotNull();
assertThat(decision.getPolicies().size()).isEqualTo(0);
- //
- // This will need more work when I fix
- // the convertResponse
- //
-
Obligation badObligation = TestUtilsCommon.createXacmlObligation(
ToscaDictionary.ID_OBLIGATION_REST_BODY.stringValue(),
Arrays.asList(assignmentBadPolicy, assignmentUnknown));
- xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE,
+ xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE, null,
Decision.PERMIT, Arrays.asList(badObligation), policyIds);
decision = translator.convertResponse(xacmlResponse);
assertNotNull(decision);
- xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_OK,
- Decision.DENY, Arrays.asList(badObligation), policyIds);
+ xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_PROCESSING_ERROR,
+ "Bad obligation", Decision.DENY, Arrays.asList(badObligation), policyIds);
decision = translator.convertResponse(xacmlResponse);
assertNotNull(decision);
+ assertThat(decision.getStatus()).isEqualTo("error");
+ assertThat(decision.getMessage()).isEqualTo("Bad obligation");
}
private class MyStdBaseTranslator extends StdBaseTranslator {
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java
index 6ff7a7f1..42c13d9e 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java
@@ -108,7 +108,7 @@ public class StdCombinedPolicyResultsTranslatorTest {
ids.put("onap.policies.Test", "1.0.0");
Collection<IdReference> policyIds = TestUtilsCommon.createPolicyIdList(ids);
- Response xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_OK,
+ Response xacmlResponse = TestUtilsCommon.createXacmlResponse(StdStatusCode.STATUS_CODE_OK, null,
Decision.PERMIT, Arrays.asList(obligation), policyIds);
DecisionResponse decision = translator.convertResponse(xacmlResponse);
@@ -148,7 +148,7 @@ public class StdCombinedPolicyResultsTranslatorTest {
}
@Test
- public void testDecision() {
+ public void testDecision() throws ToscaPolicyConversionException {
StdCombinedPolicyResultsTranslator translator = new StdCombinedPolicyResultsTranslator();
DecisionRequest decision = new DecisionRequest();
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
index aeb4cf88..e191a08a 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
@@ -237,7 +237,7 @@ public class StdMatchableTranslatorTest {
Collection<IdReference> policyIds = TestUtilsCommon.createPolicyIdList(ids);
com.att.research.xacml.api.Response xacmlResponse = TestUtilsCommon.createXacmlResponse(
- StdStatusCode.STATUS_CODE_OK, Decision.PERMIT,
+ StdStatusCode.STATUS_CODE_OK, null, Decision.PERMIT,
Arrays.asList(obligation1, obligation2, obligation3), policyIds);
//
// Test the response
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java
index e7ea049a..c95d3ca5 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -255,7 +255,7 @@ public class StdXacmlApplicationServiceProviderTest {
}
@Test
- public void testMakeDecision() {
+ public void testMakeDecision() throws ToscaPolicyConversionException {
prov.createEngine(null);
DecisionRequest decreq = mock(DecisionRequest.class);
diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
index 60fac498..f1006c6d 100644
--- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
+++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
@@ -99,9 +99,8 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
* the one in LegacyGuardTranslator is used.
*/
@Override
- public Request convertRequest(DecisionRequest request) {
- LOGGER.info("this convertRequest shouldn't be used");
- return null;
+ public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException {
+ throw new ToscaPolicyConversionException("this convertRequest shouldn't be used");
}
/**
diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequest.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequest.java
index 51d8f0ed..1e3e9150 100644
--- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequest.java
+++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequest.java
@@ -34,13 +34,13 @@ import lombok.Setter;
import lombok.ToString;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
+import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
@Getter
@Setter
@ToString
@XACMLRequest(ReturnPolicyIdList = true)
public class GuardPolicyRequest {
-
private static final String STR_GUARD = "guard";
@XACMLSubject(includeInResults = true)
@@ -82,9 +82,11 @@ public class GuardPolicyRequest {
*
* @param decisionRequest Input DecisionRequest
* @return StdMetadataPolicyRequest
+ * @throws ToscaPolicyConversionException If we cannot parse the request
*/
@SuppressWarnings("unchecked")
- public static GuardPolicyRequest createInstance(DecisionRequest decisionRequest) {
+ public static GuardPolicyRequest createInstance(DecisionRequest decisionRequest)
+ throws ToscaPolicyConversionException {
//
// Create our return object
//
@@ -133,14 +135,14 @@ public class GuardPolicyRequest {
request.targetId = guard.get("target").toString();
}
if (guard.containsKey("vfCount")) {
- //
- // TODO this can potentially throw a NumberFormatException. Fix this to
- // throw the exception when you fix the ConvertRequest to throw exceptions also.
- //
- request.vfCount = Integer.decode(guard.get("vfCount").toString());
+ try {
+ request.vfCount = Integer.decode(guard.get("vfCount").toString());
+ } catch (NumberFormatException e) {
+ throw new ToscaPolicyConversionException("Failed to decode vfCount", e);
+ }
}
return request;
}
-}
+} \ No newline at end of file
diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
index 4365cad6..fd46a988 100644
--- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
+++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
@@ -140,17 +140,13 @@ public class GuardTranslator implements ToscaPolicyTranslator {
/**
* Convert Request.
*/
- public Request convertRequest(DecisionRequest request) {
+ public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException {
LOGGER.info("Converting Request {}", request);
try {
return RequestParser.parseRequest(GuardPolicyRequest.createInstance(request));
} catch (IllegalArgumentException | IllegalAccessException | DataTypeException e) {
- LOGGER.error("Failed to convert DecisionRequest", e);
+ throw new ToscaPolicyConversionException("Failed to convert DecisionRequest", e);
}
- //
- // TODO throw exception
- //
- return null;
}
/**
diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
index b5585a7c..5b62f364 100644
--- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
+++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
@@ -23,6 +23,7 @@
package org.onap.policy.xacml.pdp.application.guard;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import com.att.research.xacml.api.Response;
import java.io.File;
@@ -191,7 +192,8 @@ public class CoordinationTest {
// the application.
//
CoordinationGuardTranslator translator = new CoordinationGuardTranslator();
- assertThat(translator.convertRequest(null)).isNull();
+ assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
+ translator.convertRequest(null)).withMessage("this convertRequest shouldn't be used");
assertThat(translator.convertResponse(null)).isNull();
assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile(
policyFolder.getRoot().getAbsolutePath() + "/nonexist.yaml")).isNull();
diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java
index b3ef3bdd..41fd4705 100644
--- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java
+++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java
@@ -23,16 +23,18 @@
package org.onap.policy.xacml.pdp.application.guard;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
+import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
public class GuardPolicyRequestTest {
@Test
- public void testAnomalies() {
+ public void testAnomalies() throws ToscaPolicyConversionException {
DecisionRequest decisionRequest = new DecisionRequest();
assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
@@ -82,6 +84,12 @@ public class GuardPolicyRequestTest {
resources.put("guard", guard);
decisionRequest.setResource(resources);
assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
+
+ guard.put("vfCount", "I am not valid");
+ resources.put("guard", guard);
+ decisionRequest.setResource(resources);
+ assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
+ GuardPolicyRequest.createInstance(decisionRequest));
}
}
diff --git a/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java b/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java
index 436028fd..5c41a9e2 100644
--- a/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java
+++ b/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java
@@ -22,7 +22,6 @@
package org.onap.policy.xacml.pdp.application.monitoring;
-import com.att.research.xacml.api.Request;
import com.att.research.xacml.api.Response;
import java.util.ArrayList;
import java.util.Arrays;
@@ -109,17 +108,10 @@ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider
public Pair<DecisionResponse, Response> makeDecision(DecisionRequest request,
Map<String, String[]> requestQueryParams) {
//
- // Convert to a XacmlRequest
+ // Make the decision
//
- Request xacmlRequest = this.getTranslator().convertRequest(request);
- //
- // Now get a decision
- //
- Response xacmlResponse = this.xacmlDecision(xacmlRequest);
- //
- // Convert to a DecisionResponse
- //
- DecisionResponse decisionResponse = this.getTranslator().convertResponse(xacmlResponse);
+ Pair<DecisionResponse, Response> decisionPair = super.makeDecision(request, requestQueryParams);
+ DecisionResponse decisionResponse = decisionPair.getKey();
//
// Abbreviate results if needed
//
@@ -137,7 +129,7 @@ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider
policy.remove("version");
}
}
- return Pair.of(decisionResponse, xacmlResponse);
+ return decisionPair;
}
@Override
diff --git a/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java b/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java
index 98a1c657..546c29eb 100644
--- a/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java
+++ b/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java
@@ -95,11 +95,8 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator {
}
@Override
- public Request convertRequest(DecisionRequest request) {
- //
- // We do nothing to DecisionRequest for native xacml application
- //
- return null;
+ public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException {
+ throw new ToscaPolicyConversionException("Do not call native convertRequest");
}
@Override
diff --git a/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java b/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
index ee1ccdce..5a8978f7 100644
--- a/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
+++ b/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
@@ -25,7 +25,6 @@ package org.onap.policy.xacml.pdp.application.optimization;
import com.att.research.xacml.api.Advice;
import com.att.research.xacml.api.AttributeAssignment;
import com.att.research.xacml.api.Decision;
-import com.att.research.xacml.api.Request;
import com.att.research.xacml.api.Response;
import com.att.research.xacml.api.Result;
import java.nio.file.Path;
@@ -180,25 +179,16 @@ public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvid
}
}
//
- // Convert to a XacmlRequest
+ // Make the decision
//
- Request xacmlRequest = this.getTranslator().convertRequest(request);
- //
- // Now get a decision
- //
- Response xacmlResponse = this.xacmlDecision(xacmlRequest);
- //
- // Convert to a DecisionResponse
- //
- Pair<DecisionResponse, Response> returnPair = Pair.of(this.getTranslator().convertResponse(xacmlResponse),
- xacmlResponse);
+ Pair<DecisionResponse, Response> decisionPair = super.makeDecision(request, requestQueryParams);
//
// Add back in advice from subscriber
//
if (xacmlSubscriberResponse != null) {
- addSubscriberAdvice(xacmlSubscriberResponse, returnPair.getLeft());
+ addSubscriberAdvice(xacmlSubscriberResponse, decisionPair.getLeft());
}
- return returnPair;
+ return decisionPair;
}
@Override
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/DecisionProvider.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/DecisionProvider.java
index 1c83b058..24d03281 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/DecisionProvider.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/DecisionProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -112,6 +112,10 @@ public class DecisionProvider {
}
private void calculateStatistic(Response xacmlResponse) {
+ if (xacmlResponse == null) {
+ XacmlPdpStatisticsManager.getCurrent().updateErrorCount();
+ return;
+ }
for (Result result : xacmlResponse.getResults()) {
switch (result.getDecision()) {
case PERMIT: