diff options
author | jhh <jorge.hernandez-herrero@att.com> | 2020-04-14 12:36:49 -0500 |
---|---|---|
committer | jhh <jorge.hernandez-herrero@att.com> | 2020-04-14 12:42:59 -0500 |
commit | 09f593ae4faca45070f26a5eaafd765eadb08801 (patch) | |
tree | 4f3ecdaf406f47d9c8f49aed3e81b4fad0a438b0 /feature-lifecycle/src/main/java/org/onap | |
parent | 0eebda49d2a552edd3f202bd5b50af923f123ace (diff) |
native controller generates invalid properties
Additional instrumetation and tests have been added
as well.
Issue-ID: POLICY-2489
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: I65df586f3a44acf3d6f825ebfb8bd73107255a1f
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src/main/java/org/onap')
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) { |