diff options
author | Jorge Hernandez <jorge.hernandez-herrero@att.com> | 2019-02-04 08:54:50 -0600 |
---|---|---|
committer | Jorge Hernandez <jorge.hernandez-herrero@att.com> | 2019-02-04 08:54:50 -0600 |
commit | b695d1743c34e4fb1087c8766b8c41eb3aae926e (patch) | |
tree | eab1533ff148e78e82e440e56a91d6e384ee3775 /policy-management | |
parent | 74a683ac8836d793e7d33e0aef104676018c72cd (diff) |
Report KieBase names in rules artifacts.
The rule writer at design time can embed the domain base model(s) supported
at design time.
This information can be extracted at runtime to match a controller with the
domain/model functionality that it can support.
Change-Id: I7f7f1320d7d601d50949d0cd09bc48982c222333
Issue-ID: POLICY-1500
Signed-off-by: Jorge Hernandez <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'policy-management')
6 files changed, 42 insertions, 17 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java index c582a1c0..1e7b8c79 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java @@ -1,8 +1,8 @@ /* * ============LICENSE_START======================================================= - * policy-management + * ONAP * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -90,6 +90,13 @@ public interface DroolsController extends Startable, Lockable { public List<String> getCanonicalSessionNames(); /** + * get base domains. + * + * @return list of base domains. + */ + public List<String> getBaseDomainNames(); + + /** * offers an event to this controller for processing. * * @param topic topic associated with the event diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java index c707c8fc..6e9f04ed 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java @@ -1,8 +1,8 @@ /* * ============LICENSE_START======================================================= - * policy-management + * ONAP * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -704,6 +704,11 @@ public class MavenDroolsController implements DroolsController { return getSessionNames(false); } + @Override + public List<String> getBaseDomainNames() { + return new ArrayList<>(this.policyContainer.getKieContainer().getKieBaseNames()); + } + /** * provides the underlying core layer container sessions. * diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java index 2aaef916..45568678 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java @@ -1,8 +1,8 @@ /* * ============LICENSE_START======================================================= - * policy-management + * ONAP * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -21,10 +21,10 @@ package org.onap.policy.drools.controller.internal; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; - import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.core.PolicyContainer; @@ -101,6 +101,11 @@ public class NullDroolsController implements DroolsController { } @Override + public List<String> getBaseDomainNames() { + return Collections.emptyList(); + } + + @Override public boolean offer(String topic, String event) { return false; } diff --git a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.java b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.java index 5df6eb8d..dce38f9b 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -32,6 +32,7 @@ import org.onap.policy.drools.util.KieUtils; public class MavenDroolsControllerTest { public static final String JUNIT_ECHO_KSESSION = "echo"; + public static final String JUNIT_ECHO_KBASE = "onap.policies.test"; public static final String JUNIT_ECHO_KMODULE_DRL_PATH = "src/test/resources/echo.drl"; public static final String JUNIT_ECHO_KMODULE_POM_PATH = "src/test/resources/echo.pom"; public static final String JUNIT_ECHO_KMODULE_PATH = "src/test/resources/echo.kmodule"; @@ -55,17 +56,17 @@ public class MavenDroolsControllerTest { } @Test - public void stop() throws IOException, InterruptedException { + public void stop() throws InterruptedException { createDroolsController(10000L).stop(); } @Test - public void shutdown() throws IOException, InterruptedException { + public void shutdown() throws InterruptedException { createDroolsController(10000L).shutdown(); } @Test - public void lock() throws IOException, InterruptedException { + public void lock() throws InterruptedException { DroolsController controller = createDroolsController(30000L); controller.lock(); @@ -105,11 +106,13 @@ public class MavenDroolsControllerTest { /* courtesy timer to allow full initialization from local maven repository */ Thread.sleep(courtesyStartTimeMs); - Assert.assertTrue(controller.getSessionNames().size() == 1); + Assert.assertEquals(1, controller.getSessionNames().size()); Assert.assertEquals(JUNIT_ECHO_KSESSION, controller.getSessionNames().get(0)); - Assert.assertTrue(controller.getCanonicalSessionNames().size() == 1); + Assert.assertEquals(1, controller.getCanonicalSessionNames().size()); Assert.assertTrue(controller.getCanonicalSessionNames().get(0).contains(JUNIT_ECHO_KSESSION)); + Assert.assertEquals(JUNIT_ECHO_KBASE, String.join(",", controller.getBaseDomainNames())); + return controller; } } diff --git a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java index 09d9cae9..8cb754c1 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -98,6 +98,11 @@ public class NullDroolsControllerTest { Assert.assertNull(new NullDroolsController().getContainer()); } + @Test + public void getDomains() { + Assert.assertTrue(new NullDroolsController().getBaseDomainNames().isEmpty()); + } + @Test(expected = IllegalStateException.class) public void ownsCoder() { new NullDroolsController().ownsCoder(null, 0); diff --git a/policy-management/src/test/resources/echo.kmodule b/policy-management/src/test/resources/echo.kmodule index 437a91ca..496f7098 100644 --- a/policy-management/src/test/resources/echo.kmodule +++ b/policy-management/src/test/resources/echo.kmodule @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - archetype-closed-loop-demo-rules + ONAP ================================================================================ - Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2018-2019 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. @@ -20,7 +20,7 @@ --> <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"> - <kbase name="kbEcho"> + <kbase name="onap.policies.test"> <ksession name="echo"/> </kbase> </kmodule> |