From 2bda454c5a0036a8fa5af120a90a0c1f94e76b31 Mon Sep 17 00:00:00 2001 From: jhh Date: Thu, 5 Mar 2020 14:32:21 -0600 Subject: Add optional controllerName in Op. Legacy Policies Optional controllerName has been added to Legacy Operational policies to be able to route Operational Policies to an specific drools controller. Currently, the policies are deployed to all controllers that support a policy type. In the case, that there are multiple controllers set, and the policy is only to be routed to one of them, this field should be populated. Issue-ID: POLICY-2388 Signed-off-by: jhh Change-Id: I7288ce0069a723b8e6ec535331dc9cda56fbf130 --- .../models/tosca/legacy/concepts/LegacyOperationalPolicy.java | 3 ++- .../tosca/legacy/mapping/LegacyOperationalPolicyMapper.java | 10 ++++++++++ .../tosca/legacy/concepts/LegacyOperationalPolicyTest.java | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'models-tosca') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java index 70453da76..a87fab1e0 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications 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. @@ -42,5 +42,6 @@ public class LegacyOperationalPolicy { private String policyVersion; private String content; + private String controllerName; } \ No newline at end of file diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java index de1bc12d7..881a5fadd 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 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. @@ -47,6 +48,7 @@ public class LegacyOperationalPolicyMapper // Property name for the operational policy content private static final String CONTENT_PROPERTY = "content"; + private static final String CONTROLLER_PROPERTY = "controllerName"; private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapper.class); @@ -69,6 +71,9 @@ public class LegacyOperationalPolicyMapper final Map propertyMap = new HashMap<>(); toscaPolicy.setProperties(propertyMap); toscaPolicy.getProperties().put(CONTENT_PROPERTY, legacyOperationalPolicy.getContent()); + if (legacyOperationalPolicy.getControllerName() != null) { + toscaPolicy.getProperties().put(CONTROLLER_PROPERTY, legacyOperationalPolicy.getControllerName()); + } final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_1_0"); @@ -115,6 +120,11 @@ public class LegacyOperationalPolicyMapper legacyOperationalPolicy.setContent(content); + String controllerName = toscaPolicy.getProperties().get(CONTROLLER_PROPERTY); + if (controllerName != null) { + legacyOperationalPolicy.setControllerName(controllerName); + } + return legacyOperationalPolicy; } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicyTest.java index 36cea6372..43ad191cc 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicyTest.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. @@ -39,6 +39,8 @@ public class LegacyOperationalPolicyTest { assertEquals("1", policy.getPolicyVersion()); policy.setContent("controlLoop%3A%0A%20%20"); assertTrue(policy.getContent().length() > 0); + policy.setControllerName("blah"); + assertEquals("blah", policy.getControllerName()); } } -- cgit 1.2.3-korg