summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'feature-lifecycle/src/main')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java10
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java27
2 files changed, 31 insertions, 6 deletions
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java
index 9a11955a..65ed3501 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java
@@ -96,7 +96,7 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
try {
controller.start();
} catch (RuntimeException e) {
- logger.warn("failed deploy (cannot start ontroller) for policy: {}", policy, e);
+ logger.warn("failed deploy (cannot start controller) for policy: {}", policy, e);
PolicyEngineConstants.getManager().removePolicyController(controller);
return false;
}
@@ -199,7 +199,7 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
private void configTopic(
String configCommPrefix, String topicName, List<ControllerEvent> events, Properties controllerProps) {
- String configTopicPrefix = configCommPrefix + "." + topicName;
+ String configTopicPrefix = configCommPrefix + ".topics." + topicName;
configTopics(configCommPrefix, topicName, controllerProps);
for (ControllerEvent configEvent : events) {
configEvent(configTopicPrefix, configEvent, controllerProps);
@@ -213,7 +213,6 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
private void configEvent(String propPrefix, ControllerEvent configEvent, Properties controllerProps) {
String eventPropPrefix = propPrefix + ".events";
- controllerProps.setProperty(eventPropPrefix, configEvent.getEventClass());
if (configEvent.getEventFilter() != null) {
controllerProps.setProperty(
eventPropPrefix + "." + configEvent.getEventClass() + ".filter", configEvent.getEventFilter());
@@ -225,10 +224,11 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
}
private void configTopicItemList(String itemPrefix, String item, Properties controllerProps) {
- if (controllerProps.getProperty(itemPrefix) == null) {
+ String itemValue = controllerProps.getProperty(itemPrefix);
+ if (itemValue == null) {
controllerProps.setProperty(itemPrefix, item);
} else {
- controllerProps.setProperty(itemPrefix, "," + item);
+ controllerProps.setProperty(itemPrefix, itemValue + "," + item);
}
}
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
index 5c8f9dc2..4093b510 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
@@ -18,9 +18,11 @@
package org.onap.policy.drools.server.restful;
+import com.worldturner.medeia.api.ValidationFailedException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
+import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
@@ -356,7 +358,7 @@ public class RestLifecycleManager {
@Path("policies/operations")
@ApiOperation(value = "Gets Policy Operations", responseContainer = "List")
public Response policiesOperations() {
- return Response.status(Response.Status.OK).entity(List.of("deployment", "undeployment")).build();
+ return Response.status(Response.Status.OK).entity(List.of("deployment", "undeployment", "validation")).build();
}
/**
@@ -381,6 +383,29 @@ public class RestLifecycleManager {
return deployUndeployOperation(policy, false);
}
+ /**
+ * POST a policy for validation.
+ */
+
+ @POST
+ @Path("policies/operations/validation")
+ @ApiOperation(value = "Validates a policy", responseContainer = "List")
+ public Response validateOperation(@ApiParam(value = "Tosca Policy", required = true) String policy) {
+ ToscaPolicy toscaPolicy = getToscaPolicy(policy);
+ if (toscaPolicy == null) {
+ return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+ }
+
+ try {
+ LifecycleFeature.fsm.getDomainMaker().conformance(toscaPolicy);
+ } catch (ValidationFailedException v) {
+ logger.trace("policy {} validation errors: {}", toscaPolicy, v.getMessage(), v);
+ return Response.status(Response.Status.NOT_ACCEPTABLE).entity(v.getFailures()).build();
+ }
+
+ return Response.status(Response.Status.OK).entity(Collections.emptyList()).build();
+ }
+
private Response deployUndeployOperation(String policy, boolean deploy) {
ToscaPolicy toscaPolicy = getToscaPolicy(policy);
if (toscaPolicy == null) {