From 0e16acf4d8579fd82349d6cd24e236275735a818 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Tue, 14 Feb 2017 19:45:48 -0500 Subject: Initial OpenECOMP policy/drools-pdp commit Change-Id: I0072ccab6f40ed32da39667f9f8523b6d6dad2e2 Signed-off-by: Pamela Dragosh --- .gitignore | 7 + .gitreview | 4 + LICENSE.txt | 16 + README.md | 3 + packages/base/.gitignore | 1 + packages/base/pom.xml | 95 ++ packages/base/src/assembly/zip.xml | 42 + .../base/src/files/bin/db_upgrade_droolspdp.sh | 154 ++ .../src/files/bin/db_upgrade_droolspdp_remote.sh | 151 ++ packages/base/src/files/bin/monitor.sh | 148 ++ packages/base/src/files/bin/policy.sh | 154 ++ .../mysql/160400_droolspdp_downgrade_script.sql | 23 + .../data/mysql/160400_droolspdp_upgrade_script.sql | 57 + .../mysql/160401_droolspdp_downgrade_script.sql | 30 + .../data/mysql/160401_droolspdp_upgrade_script.sql | 30 + .../mysql/160700_droolspdp_downgrade_script.sql | 25 + .../data/mysql/160700_droolspdp_upgrade_script.sql | 68 + .../mysql/161000_droolspdp_downgrade_script.sql | 47 + .../data/mysql/161000_droolspdp_upgrade_script.sql | 54 + .../mysql/161001_droolspdp_downgrade_script.sql | 56 + .../data/mysql/161001_droolspdp_upgrade_script.sql | 52 + .../mysql/161002_droolspdp_downgrade_script.sql | 21 + .../data/mysql/161002_droolspdp_upgrade_script.sql | 41 + .../mysql/161003_droolspdp_downgrade_script.sql | 22 + .../data/mysql/161003_droolspdp_upgrade_script.sql | 29 + .../mysql/161004_droolspdp_downgrade_script.sql | 2 + .../data/mysql/161004_droolspdp_upgrade_script.sql | 5 + .../mysql/170200_droolspdp_downgrade_script.sql | 21 + .../data/mysql/170200_droolspdp_upgrade_script.sql | 21 + packages/base/src/files/etc/cron.d/monitor.cron | 1 + packages/base/src/files/etc/monitor/monitor.cfg | 6 + packages/base/src/files/etc/profile.d/env.sh | 35 + packages/base/src/files/etc/profile.d/su.cfg | 1 + .../install/mysql/data/151000_downgrade_script.sql | 75 + .../install/mysql/data/151000_upgrade_script.sql | 1563 ++++++++++++++++++++ .../install/mysql/data/151001_downgrade_script.sql | 248 ++++ .../install/mysql/data/151001_upgrade_script.sql | 246 +++ .../install/mysql/data/151002_downgrade_script.sql | 21 + .../install/mysql/data/151002_upgrade_script.sql | 21 + .../install/mysql/data/151200_downgrade_script.sql | 43 + .../install/mysql/data/151200_upgrade_script.sql | 226 +++ .../install/mysql/data/160200_downgrade_script.sql | 39 + .../install/mysql/data/160200_upgrade_script.sql | 127 ++ .../install/mysql/data/160201_downgrade_script.sql | 43 + .../install/mysql/data/160201_upgrade_script.sql | 44 + .../install/mysql/data/160400_downgrade_script.sql | 33 + .../install/mysql/data/160400_upgrade_script.sql | 124 ++ packages/base/src/files/m2/settings.xml | 83 ++ packages/base/src/files/m2/standalone-settings.xml | 57 + packages/install/.gitignore | 1 + packages/install/pom.xml | 94 ++ packages/install/src/assembly/zip.xml | 39 + packages/install/src/files/base.conf | 68 + packages/install/src/files/policy-management.conf | 5 + packages/pom.xml | 43 + policy-core/pom.xml | 235 +++ policy-core/src/assembly/assemble_zip.xml | 85 ++ .../openecomp/policy/drools/core/FeatureAPI.java | 153 ++ .../policy/drools/core/PolicyContainer.java | 828 +++++++++++ .../policy/drools/core/PolicySession.java | 349 +++++ .../openecomp/policy/drools/core/jmx/PdpJmx.java | 47 + .../policy/drools/core/jmx/PdpJmxListener.java | 64 + .../policy/drools/core/jmx/PdpJmxMBean.java | 27 + .../policy/drools/properties/Lockable.java | 45 + .../policy/drools/properties/PolicyProperties.java | 96 ++ .../policy/drools/properties/Startable.java | 65 + .../src/main/resources/META-INF/jndi.properties | 21 + .../src/main/resources/META-INF/persistence.xml | 70 + policy-endpoints/pom.xml | 157 ++ .../openecomp/policy/drools/event/comm/Topic.java | 76 + .../policy/drools/event/comm/TopicEndpoint.java | 692 +++++++++ .../policy/drools/event/comm/TopicListener.java | 42 + .../drools/event/comm/TopicRegisterable.java | 42 + .../policy/drools/event/comm/TopicSink.java | 42 + .../policy/drools/event/comm/TopicSource.java | 40 + .../policy/drools/event/comm/bus/BusTopic.java | 26 + .../policy/drools/event/comm/bus/BusTopicSink.java | 47 + .../drools/event/comm/bus/BusTopicSource.java | 83 ++ .../drools/event/comm/bus/DmaapTopicSink.java | 30 + .../event/comm/bus/DmaapTopicSinkFactory.java | 308 ++++ .../drools/event/comm/bus/DmaapTopicSource.java | 29 + .../event/comm/bus/DmaapTopicSourceFactory.java | 380 +++++ .../policy/drools/event/comm/bus/UebTopicSink.java | 32 + .../drools/event/comm/bus/UebTopicSinkFactory.java | 292 ++++ .../drools/event/comm/bus/UebTopicSource.java | 34 + .../event/comm/bus/UebTopicSourceFactory.java | 362 +++++ .../event/comm/bus/internal/BusConsumer.java | 204 +++ .../event/comm/bus/internal/BusPublisher.java | 231 +++ .../event/comm/bus/internal/BusTopicBase.java | 112 ++ .../comm/bus/internal/InlineBusTopicSink.java | 284 ++++ .../comm/bus/internal/InlineDmaapTopicSink.java | 84 ++ .../comm/bus/internal/InlineUebTopicSink.java | 91 ++ .../bus/internal/SingleThreadedBusTopicSource.java | 477 ++++++ .../internal/SingleThreadedDmaapTopicSource.java | 120 ++ .../bus/internal/SingleThreadedUebTopicSource.java | 89 ++ .../policy/drools/http/client/HttpClient.java | 48 + .../drools/http/client/HttpClientFactory.java | 185 +++ .../drools/http/client/internal/JerseyClient.java | 242 +++ .../drools/http/server/HttpServletServer.java | 81 + .../http/server/HttpServletServerFactory.java | 206 +++ .../http/server/internal/JettyJerseyServer.java | 130 ++ .../http/server/internal/JettyServletServer.java | 353 +++++ .../resources/schema/pdpd-configuration.jsonschema | 61 + .../drools/http/server/test/HttpClientTest.java | 230 +++ .../drools/http/server/test/HttpServerTest.java | 181 +++ .../drools/http/server/test/RestEchoService.java | 19 + .../drools/http/server/test/RestEndpoints.java | 25 + .../http/server/test/RestMockHealthCheck.java | 28 + policy-healthcheck/pom.xml | 157 ++ policy-healthcheck/src/assembly/assemble_zip.xml | 85 ++ .../policy/drools/healthcheck/HealthCheck.java | 178 +++ .../drools/healthcheck/HealthCheckFeature.java | 92 ++ .../policy/drools/healthcheck/RestHealthCheck.java | 27 + .../org.openecomp.policy.drools.core.FeatureAPI | 1 + policy-management/config/policy-engine.properties | 26 + policy-management/config/policyLogger.properties | 44 + policy-management/pom.xml | 259 ++++ policy-management/src/assembly/assemble_zip.xml | 85 ++ .../policy/drools/controller/DroolsController.java | 170 +++ .../drools/controller/DroolsControllerFactory.java | 540 +++++++ .../controller/internal/MavenDroolsController.java | 718 +++++++++ .../controller/internal/NullDroolsController.java | 219 +++ .../drools/persistence/SystemPersistence.java | 255 ++++ .../drools/protocol/coders/EventProtocolCoder.java | 1451 ++++++++++++++++++ .../drools/protocol/coders/JsonProtocolFilter.java | 304 ++++ .../protocol/coders/ProtocolCoderToolset.java | 668 +++++++++ .../coders/TopicCoderFilterConfiguration.java | 309 ++++ .../configuration/ControllerConfiguration.java | 280 ++++ .../configuration/DroolsConfiguration.java | 278 ++++ .../protocol/configuration/PdpdConfiguration.java | 283 ++++ .../policy/drools/server/restful/RestManager.java | 1181 +++++++++++++++ .../org/openecomp/policy/drools/system/Main.java | 131 ++ .../policy/drools/system/PolicyController.java | 110 ++ .../drools/system/PolicyControllerFactory.java | 464 ++++++ .../policy/drools/system/PolicyEngine.java | 1182 +++++++++++++++ .../internal/AggregatedPolicyController.java | 462 ++++++ .../main/server-gen/bin/add-secured-participant.sh | 122 ++ .../src/main/server-gen/bin/create-api-key.sh | 76 + .../main/server-gen/bin/create-secured-topic.sh | 130 ++ policy-management/src/main/server-gen/bin/options | 125 ++ .../src/main/server-gen/bin/pdpd-configuration.sh | 200 +++ .../server-gen/bin/policy-management-controller | 191 +++ .../src/main/server-gen/bin/rest-add-controller.sh | 37 + .../main/server-gen/bin/rest-delete-controller.sh | 43 + .../main/server/config/IntegrityMonitor.properties | 81 + .../server/config/controller.properties.README | 153 ++ .../server/config/droolsPersistence.properties | 51 + .../src/main/server/config/log4j.properties | 48 + .../src/main/server/config/logback.xml | 211 +++ policy-management/src/main/server/config/makefile | 9 + .../main/server/config/policy-engine.properties | 46 + .../server/config/policy-healthcheck.properties | 23 + .../src/main/server/config/policyLogger.properties | 49 + .../src/main/server/config/system.properties | 31 + .../main/server/config/xacmlPersistence.properties | 43 + policy-persistence/config/policy-engine.properties | 33 + policy-persistence/config/policyLogger.properties | 44 + policy-persistence/pom.xml | 154 ++ policy-persistence/src/assembly/assemble_zip.xml | 85 ++ .../org/openecomp/policy/drools/core/DbAudit.java | 205 +++ .../drools/core/DroolsPDPIntegrityMonitor.java | 485 ++++++ .../drools/core/IntegrityMonitorProperties.java | 68 + .../policy/drools/core/RepositoryAudit.java | 524 +++++++ .../drools/im/PMStandbyStateChangeNotifier.java | 280 ++++ .../policy/drools/persistence/DroolsPdp.java | 45 + .../policy/drools/persistence/DroolsPdpEntity.java | 171 +++ .../policy/drools/persistence/DroolsPdpImpl.java | 115 ++ .../policy/drools/persistence/DroolsPdpObject.java | 97 ++ .../drools/persistence/DroolsPdpsConnector.java | 67 + .../persistence/DroolsPdpsElectionHandler.java | 948 ++++++++++++ .../persistence/DroolsPersistenceProperties.java | 64 + .../policy/drools/persistence/DroolsSession.java | 31 + .../drools/persistence/DroolsSessionEntity.java | 90 ++ .../drools/persistence/JpaDroolsPdpsConnector.java | 688 +++++++++ .../drools/persistence/PersistenceFeature.java | 614 ++++++++ .../drools/persistence/ThreadRunningChecker.java | 26 + .../persistence/XacmlPersistenceProperties.java | 65 + .../org.openecomp.policy.drools.core.FeatureAPI | 1 + .../test/IntegrityAuditIntegrationTest.java | 279 ++++ .../controller/test/ResiliencyTestCases.java | 1267 ++++++++++++++++ .../test/StandbyStateManagementTest.java | 887 +++++++++++ .../src/test/resources/IntegrityMonitor.properties | 67 + .../src/test/resources/META-INF/persistence.xml | 56 + .../test/resources/droolsPersistence.properties | 51 + .../src/test/resources/log4j.properties | 31 + policy-persistence/src/test/resources/logback.xml | 209 +++ .../src/test/resources/xacmlPersistence.properties | 43 + .../test/server/config/IntegrityMonitor.properties | 62 + .../server/config/droolsPersistence.properties | 35 + .../src/test/server/config/policyLogger.properties | 44 + .../test/server/config/xacmlPersistence.properties | 38 + policy-utils/pom.xml | 75 + .../policy/drools/utils/OrderedService.java | 35 + .../policy/drools/utils/OrderedServiceImpl.java | 117 ++ .../org/openecomp/policy/drools/utils/Pair.java | 51 + .../policy/drools/utils/PropertyUtil.java | 403 +++++ .../policy/drools/utils/ReflectionUtil.java | 92 ++ .../org/openecomp/policy/drools/utils/Triple.java | 45 + .../policy/drools/utils/PropertyUtilTest.java | 204 +++ policy-utils/src/test/resources/log4j.properties | 26 + pom.xml | 194 +++ project-configs/maven/conf/settings.xml | 162 ++ version.properties | 35 + 203 files changed, 33981 insertions(+) create mode 100644 .gitignore create mode 100644 .gitreview create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 packages/base/.gitignore create mode 100644 packages/base/pom.xml create mode 100644 packages/base/src/assembly/zip.xml create mode 100644 packages/base/src/files/bin/db_upgrade_droolspdp.sh create mode 100644 packages/base/src/files/bin/db_upgrade_droolspdp_remote.sh create mode 100644 packages/base/src/files/bin/monitor.sh create mode 100644 packages/base/src/files/bin/policy.sh create mode 100644 packages/base/src/files/data/mysql/160400_droolspdp_downgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/160400_droolspdp_upgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/160401_droolspdp_downgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/160401_droolspdp_upgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/160700_droolspdp_downgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/160700_droolspdp_upgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161000_droolspdp_downgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161000_droolspdp_upgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161001_droolspdp_downgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161001_droolspdp_upgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161002_droolspdp_downgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161002_droolspdp_upgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161003_droolspdp_downgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161003_droolspdp_upgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161004_droolspdp_downgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/161004_droolspdp_upgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/170200_droolspdp_downgrade_script.sql create mode 100644 packages/base/src/files/data/mysql/170200_droolspdp_upgrade_script.sql create mode 100755 packages/base/src/files/etc/cron.d/monitor.cron create mode 100644 packages/base/src/files/etc/monitor/monitor.cfg create mode 100644 packages/base/src/files/etc/profile.d/env.sh create mode 100644 packages/base/src/files/etc/profile.d/su.cfg create mode 100644 packages/base/src/files/install/mysql/data/151000_downgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/151000_upgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/151001_downgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/151001_upgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/151002_downgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/151002_upgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/151200_downgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/151200_upgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/160200_downgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/160200_upgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/160201_downgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/160201_upgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/160400_downgrade_script.sql create mode 100644 packages/base/src/files/install/mysql/data/160400_upgrade_script.sql create mode 100755 packages/base/src/files/m2/settings.xml create mode 100755 packages/base/src/files/m2/standalone-settings.xml create mode 100644 packages/install/.gitignore create mode 100644 packages/install/pom.xml create mode 100644 packages/install/src/assembly/zip.xml create mode 100644 packages/install/src/files/base.conf create mode 100644 packages/install/src/files/policy-management.conf create mode 100644 packages/pom.xml create mode 100644 policy-core/pom.xml create mode 100644 policy-core/src/assembly/assemble_zip.xml create mode 100644 policy-core/src/main/java/org/openecomp/policy/drools/core/FeatureAPI.java create mode 100644 policy-core/src/main/java/org/openecomp/policy/drools/core/PolicyContainer.java create mode 100644 policy-core/src/main/java/org/openecomp/policy/drools/core/PolicySession.java create mode 100644 policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmx.java create mode 100644 policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmxListener.java create mode 100644 policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmxMBean.java create mode 100644 policy-core/src/main/java/org/openecomp/policy/drools/properties/Lockable.java create mode 100644 policy-core/src/main/java/org/openecomp/policy/drools/properties/PolicyProperties.java create mode 100644 policy-core/src/main/java/org/openecomp/policy/drools/properties/Startable.java create mode 100644 policy-core/src/main/resources/META-INF/jndi.properties create mode 100644 policy-core/src/main/resources/META-INF/persistence.xml create mode 100644 policy-endpoints/pom.xml create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/Topic.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicEndpoint.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicListener.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicRegisterable.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicSink.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicSource.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopic.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopicSink.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopicSource.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSink.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSource.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSink.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSinkFactory.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSource.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSourceFactory.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusConsumer.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusPublisher.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusTopicBase.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClient.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClientFactory.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServer.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServerFactory.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyJerseyServer.java create mode 100644 policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyServletServer.java create mode 100644 policy-endpoints/src/main/resources/schema/pdpd-configuration.jsonschema create mode 100644 policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java create mode 100644 policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java create mode 100644 policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEchoService.java create mode 100644 policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEndpoints.java create mode 100644 policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestMockHealthCheck.java create mode 100644 policy-healthcheck/pom.xml create mode 100644 policy-healthcheck/src/assembly/assemble_zip.xml create mode 100644 policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java create mode 100644 policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java create mode 100644 policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java create mode 100644 policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI create mode 100644 policy-management/config/policy-engine.properties create mode 100644 policy-management/config/policyLogger.properties create mode 100644 policy-management/pom.xml create mode 100644 policy-management/src/assembly/assemble_zip.xml create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsControllerFactory.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/persistence/SystemPersistence.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/JsonProtocolFilter.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/ProtocolCoderToolset.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/ControllerConfiguration.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/DroolsConfiguration.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/PdpdConfiguration.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/server/restful/RestManager.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyController.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyControllerFactory.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java create mode 100644 policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java create mode 100644 policy-management/src/main/server-gen/bin/add-secured-participant.sh create mode 100644 policy-management/src/main/server-gen/bin/create-api-key.sh create mode 100644 policy-management/src/main/server-gen/bin/create-secured-topic.sh create mode 100644 policy-management/src/main/server-gen/bin/options create mode 100644 policy-management/src/main/server-gen/bin/pdpd-configuration.sh create mode 100644 policy-management/src/main/server-gen/bin/policy-management-controller create mode 100644 policy-management/src/main/server-gen/bin/rest-add-controller.sh create mode 100644 policy-management/src/main/server-gen/bin/rest-delete-controller.sh create mode 100644 policy-management/src/main/server/config/IntegrityMonitor.properties create mode 100644 policy-management/src/main/server/config/controller.properties.README create mode 100644 policy-management/src/main/server/config/droolsPersistence.properties create mode 100644 policy-management/src/main/server/config/log4j.properties create mode 100644 policy-management/src/main/server/config/logback.xml create mode 100644 policy-management/src/main/server/config/makefile create mode 100644 policy-management/src/main/server/config/policy-engine.properties create mode 100644 policy-management/src/main/server/config/policy-healthcheck.properties create mode 100644 policy-management/src/main/server/config/policyLogger.properties create mode 100644 policy-management/src/main/server/config/system.properties create mode 100644 policy-management/src/main/server/config/xacmlPersistence.properties create mode 100644 policy-persistence/config/policy-engine.properties create mode 100644 policy-persistence/config/policyLogger.properties create mode 100644 policy-persistence/pom.xml create mode 100644 policy-persistence/src/assembly/assemble_zip.xml create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/core/DbAudit.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/core/DroolsPDPIntegrityMonitor.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/core/IntegrityMonitorProperties.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/core/RepositoryAudit.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/im/PMStandbyStateChangeNotifier.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdp.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpEntity.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpImpl.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpObject.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpsConnector.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpsElectionHandler.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPersistenceProperties.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsSession.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsSessionEntity.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/JpaDroolsPdpsConnector.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/ThreadRunningChecker.java create mode 100644 policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/XacmlPersistenceProperties.java create mode 100644 policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI create mode 100644 policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/IntegrityAuditIntegrationTest.java create mode 100644 policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/ResiliencyTestCases.java create mode 100644 policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java create mode 100644 policy-persistence/src/test/resources/IntegrityMonitor.properties create mode 100644 policy-persistence/src/test/resources/META-INF/persistence.xml create mode 100644 policy-persistence/src/test/resources/droolsPersistence.properties create mode 100644 policy-persistence/src/test/resources/log4j.properties create mode 100644 policy-persistence/src/test/resources/logback.xml create mode 100644 policy-persistence/src/test/resources/xacmlPersistence.properties create mode 100644 policy-persistence/src/test/server/config/IntegrityMonitor.properties create mode 100644 policy-persistence/src/test/server/config/droolsPersistence.properties create mode 100644 policy-persistence/src/test/server/config/policyLogger.properties create mode 100644 policy-persistence/src/test/server/config/xacmlPersistence.properties create mode 100644 policy-utils/pom.xml create mode 100644 policy-utils/src/main/java/org/openecomp/policy/drools/utils/OrderedService.java create mode 100644 policy-utils/src/main/java/org/openecomp/policy/drools/utils/OrderedServiceImpl.java create mode 100644 policy-utils/src/main/java/org/openecomp/policy/drools/utils/Pair.java create mode 100644 policy-utils/src/main/java/org/openecomp/policy/drools/utils/PropertyUtil.java create mode 100644 policy-utils/src/main/java/org/openecomp/policy/drools/utils/ReflectionUtil.java create mode 100644 policy-utils/src/main/java/org/openecomp/policy/drools/utils/Triple.java create mode 100644 policy-utils/src/test/java/org/openecomp/policy/drools/utils/PropertyUtilTest.java create mode 100644 policy-utils/src/test/resources/log4j.properties create mode 100644 pom.xml create mode 100644 project-configs/maven/conf/settings.xml create mode 100644 version.properties diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..37cd4d1e --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.project +.settings +.classpath +.jupiter +.pydevproject +target +.metadata/ diff --git a/.gitreview b/.gitreview new file mode 100644 index 00000000..6a107fd8 --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=gerrit.openecomp.org +port=29418 +project=policy/drools-pdp.git diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..dde205e9 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,16 @@ +Copyright © 2017 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. + +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +License for the specific language governing permissions and limitations +under the License. + +ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property. diff --git a/README.md b/README.md new file mode 100644 index 00000000..6614ee66 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +This source repository contains the OpenECOMP Policy DroolsPDP code. The settings file only needs to support the standard Maven repositories (e.g. central = http://repo1.maven.org/maven2/), and any proxy settings needed in your environment. + +To build it using Maven 3, first build 'policy-common-modules' (which contains dependencies), and then run: mvn clean install diff --git a/packages/base/.gitignore b/packages/base/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/packages/base/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/packages/base/pom.xml b/packages/base/pom.xml new file mode 100644 index 00000000..80ba20b6 --- /dev/null +++ b/packages/base/pom.xml @@ -0,0 +1,95 @@ + + + + + 4.0.0 + + + org.openecomp.policy.drools-pdp + packages + 1.0.0-SNAPSHOT + + + base + pom + + Base Package + D2 ECOMP Policy Drools PDP Packaging + + + + + maven-assembly-plugin + + + + single + + package + + + src/assembly/zip.xml + + false + + + + + + + + + + unix_pe_version + + + !windows + + + + + + org.codehaus.mojo + exec-maven-plugin + + + create-version-file + + exec + + prepare-package + + /bin/bash + + -c + mkdir -p target ; echo -e 'version="${project.version}"\ndescription="Open ECOMP Drools PDP"\nbuildTag="'"${BUILD_TAG}"'"\ncommit="'"${GIT_COMMIT}"'"\ntimestamp="${maven.build.timestamp}"' >target/build.info + + + + + + + + + + + diff --git a/packages/base/src/assembly/zip.xml b/packages/base/src/assembly/zip.xml new file mode 100644 index 00000000..1f3b206f --- /dev/null +++ b/packages/base/src/assembly/zip.xml @@ -0,0 +1,42 @@ + + + + base + + tar.gz + + false + + + ${project.build.directory} + etc + build.info + 700 + 700 + + + src/files + . + 700 + 700 + + + diff --git a/packages/base/src/files/bin/db_upgrade_droolspdp.sh b/packages/base/src/files/bin/db_upgrade_droolspdp.sh new file mode 100644 index 00000000..738317de --- /dev/null +++ b/packages/base/src/files/bin/db_upgrade_droolspdp.sh @@ -0,0 +1,154 @@ +#!/bin/bash + +### +# ============LICENSE_START======================================================= +# Base Package +# ================================================================================ +# Copyright (C) 2017 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# db_upgrade_droolspdp.sh: Run this script to upgrade drools database to a given release level, +# it is recommended that you switch to the policy user to run this script +# +# Usage : db_upgrade_droolspdp.sh target_db_release_level db_user_id db_user_password +# Example: db_upgrade_droolspdp.sh 151000 policy_user password +# +# Assumption: 1. DB upgrade sql script in $POLICY_HOME/data/mysql folder with read permission +# 2. DB user has privilege to create/drop/alter database table +# +# Note: The default location for db release script is $POLICY_HOME/data/mysql +# The release level is represented as Two-digit-Year+Two-digit-Month+two-digit-Sub-release (151000, 151001) +# Drools database version is represented by record with the_key of 'DROOLS_VERSION' +# + +TARGET_RELEASE="" +CURRENT_RELEASE="" +DB_UPGRADE_USER="" +DB_UPGRADE_PASSWORD="" +DB_UPGRADE_DIR=$POLICY_HOME/data/mysql +DATE=`date +"%Y%m%d%H%M%S"` +LOG="" +ERR="" + +function get_current_release_level +{ + echo "Get current release level started ...@`date`" | tee -a $LOG + # display output vertical + query="select version from support.db_version where the_key = 'DROOLS_VERSION' \G" + CURRENT_RELEASE=`${MYSQL} --skip-column-names --execute "${query}" 2>$ERR | grep -v "*"` + echo "CURRENT_RELEASE: [$CURRENT_RELEASE]" | tee -a $LOG + echo "Get current release level completed ...@`date`" | tee -a $LOG +} + +function evaluate_upgrade_downgrade +{ + echo "CURRENT_RELEASE --> [$CURRENT_RELEASE]" | tee -a $LOG + echo "TARGET_RELEASE --> [$TARGET_RELEASE] " | tee -a $LOG + if [[ "${CURRENT_RELEASE}" < "${TARGET_RELEASE}" ]]; then + # perform db upgrade + UPGRADE_LIST=/tmp/db_upgrade_droolspdp_list.$$ + find ${DB_UPGRADE_DIR} -name "*_upgrade_script.sql" 2>/dev/null | grep "droolspdp" | sort > $UPGRADE_LIST + while read -r file + do + RELEASE=`basename $file | cut -d'_' -f1` + #echo "[$RELEASE] [$TARGET_RELEASE]" | tee -a $LOG + if [ "${RELEASE}" -gt "${CURRENT_RELEASE}" ] && [ "${RELEASE}" -le "${TARGET_RELEASE}" ]; then + run_script "UPGRADE" "${file}" 2>&1 | tee -a $LOG + fi + done < $UPGRADE_LIST + rm -f $UPGRADE_LIST + set_current_release_level $TARGET_RELEASE + elif [[ "${CURRENT_RELEASE}" > "${TARGET_RELEASE}" ]]; then + # perform db downgrade + DOWNGRADE_LIST=/tmp/db_downgrade_list.$$ + find ${DB_UPGRADE_DIR} -name "*_downgrade_script.sql" 2>/dev/null | grep "droolspdp" | sort -r > $DOWNGRADE_LIST + while read -r file + do + RELEASE=`basename $file | cut -d'_' -f1` + #echo "[$RELEASE] [$TARGET_RELEASE]" | tee -a $LOG + if [ "${RELEASE}" -le "${CURRENT_RELEASE}" ] && [ "${RELEASE}" -gt "${TARGET_RELEASE}" ]; then + run_script "DOWNGRADE" "${file}" + fi + done < $DOWNGRADE_LIST + rm -f $DOWNGRADE_LIST + set_current_release_level $TARGET_RELEASE + else + echo "CURRENT DB RELEASE LEVEL THE SAME AS TARGET RELEASE LEVEL, NO ACTION TAKEN ..." | tee -a $LOG + fi +} + +function run_script +{ + action="${1}" + script="${2}" + echo "Perform DB $action use $script ..." | tee -a $LOG + echo "--" | tee -a $LOG + ${MYSQL} --verbose < "${script}" 2>$ERR | tee -a $LOG + echo "--" | tee -a $LOG +} + +function set_current_release_level +{ + RELEASE="${1}" + echo "Set current release level to [$RELEASE] started ...@`date`" | tee -a $LOG + update_statement="insert into support.db_version (the_key, version) values ('DROOLS_VERSION', '${RELEASE}') on duplicate key update version='${RELEASE}';" + ${MYSQL} --execute "${update_statement}" + + echo "" | tee -a $LOG + echo "CURRENT_RELEASE set to: [$RELEASE]" | tee -a $LOG + echo "" | tee -a $LOG + echo "Set current release level completed ...@`date`" | tee -a $LOG +} + +function check_directory +{ + if [ ! -d $DB_UPGRADE_DIR ]; then + echo "ERROR, DIRECTORY NOT EXIST: $DB_UPGRADE_DIR, PROCESS EXIT ..." + exit; + else + if [ ! -d $DB_UPGRADE_DIR/logs ]; then + mkdir $DB_UPGRADE_DIR/logs + fi + fi +} + +# MAIN +#check_directory +LOG=$POLICY_HOME/logs/db_upgrade_droolspdp_$DATE.log +ERR=$POLICY_HOME/logs/db_upgrade_droolspdp_$DATE.err +echo "db_upgrade_droolspdp.sh started ..." | tee -a $LOG +if [ $# -eq 3 ]; then + TARGET_RELEASE="${1}" + DB_UPGRADE_USER="${2}" + DB_UPGRADE_PASSWORD="${3}" + echo "TARGET_RELEASE : $TARGET_RELEASE" | tee -a $LOG + echo "DB_UPGRADE_USER: $DB_UPGRADE_USER" | tee -a $LOG + echo "DB_UPGRADE_DIR : $DB_UPGRADE_DIR" | tee -a $LOG + # + if [ ${#TARGET_RELEASE} -ne 6 ]; then + echo "ERROR, TARGET_RELEASE MUST BE 6 DIGITS: $TARGET_RELEASE" | tee -a $LOG | tee -a $ERR + else + typeset -r MYSQL="mysql -u${DB_UPGRADE_USER} -p${DB_UPGRADE_PASSWORD} "; + get_current_release_level + evaluate_upgrade_downgrade + fi +else + echo "Usage : db_upgrade_droolspdp.sh target_release_level db_user_id db_user_password" | tee -a $LOG + echo "Example: db_upgrade_droolspdp.sh 151000 policy_user password" | tee -a $LOG +fi + +echo "db_upgrade_droolspdp.sh completed ..." | tee -a $LOG diff --git a/packages/base/src/files/bin/db_upgrade_droolspdp_remote.sh b/packages/base/src/files/bin/db_upgrade_droolspdp_remote.sh new file mode 100644 index 00000000..96cfda1c --- /dev/null +++ b/packages/base/src/files/bin/db_upgrade_droolspdp_remote.sh @@ -0,0 +1,151 @@ +#!/bin/bash +# +# db_upgrade_droolspdp_remote.sh: This script is to perform database schema upgrade on remote db, +# no shecma downgrade will be performed in case db_version is higher then target_version +# +# Logic: 1. Get target schema version from db scripts in $POLICY_HOME/data/mysql +# 2. Get current db schema version from support.db_version table (of target system) +# 3. Apply db upgrade script in order if target_version is HIGHER than db_version +# 4. Print out warning message if target_version is LOWER than db_version +# 4. Print out message if target_version is EQUAL to db_version +# +# +# Usage : db_upgrade_droolspdp_remote.sh db_user_id db_user_password hostname +# Example: db_upgrade_droolspdp_remote.sh policy_user password policydb +# +# Assumption: 1. DB schema upgrade script in $POLICY_HOME/data/mysql folder with read permission +# 2. DB user has privilege to create/drop/alter database table +# +# Note: The default location for db schema upgrade script is $POLICY_HOME/data/mysql +# The release level is represented as Two-digit-Year+Two-digit-Month+two-digit-Sub-release (151000, 151001) +# +# + +TARGET_SCHEMA_VERSION="" +CURRENT_SCHEMA_VERSION="" +DB_UPGRADE_USER="" +DB_UPGRADE_PASSWORD="" +DB_HOSTNAME="" +DB_UPGRADE_DIR=$POLICY_HOME/data/mysql +DATE=`date +"%Y%m%d%H%M%S"` +LOG="" +ERR="" + +function get_current_schema_version +{ + echo "Get current schema version from [${DB_HOSTNAME}] started ...@`date`" | tee -a $LOG + # display output vertical + query="select version from support.db_version where the_key = 'DROOLS_VERSION' \G" + CURRENT_SCHEMA_VERSION=`${MYSQL} --skip-column-names --execute "${query}" 2>$ERR | grep -v "*"` + error_msg=`cat $ERR | grep "doesn't exist"` + if [ "${error_msg}" != "" ]; then + echo "Create support.db_version table ..." | tee -a $LOG + sql="create table support.db_version(the_key varchar(20) not null, version varchar(20), primary key(the_key));" + ${MYSQL} --execute "${sql}" + CURRENT_SCHEMA_VERSION="00" + fi + echo "CURRENT_SCHEMA_VERSION: [$CURRENT_SCHEMA_VERSION]" | tee -a $LOG + echo "Get current schema version from [${DB_HOSTNAME}] completed ...@`date`" | tee -a $LOG +} + +function get_target_schema_version +{ + UPGRADE_LIST=/tmp/db_upgrade_list.$$ + find ${DB_UPGRADE_DIR} -name "*_upgrade_script.sql" 2>/dev/null | grep "droolspdp" | sort -r | head -1 > $UPGRADE_LIST + while read -r file + do + TARGET_SCHEMA_VERSION=`basename $file | cut -d'_' -f1` + echo "TARGET_SCHEMA_VERSION: [$TARGET_SCHEMA_VERSION]" | tee -a $LOG + break + done < $UPGRADE_LIST + rm -f $UPGRADE_LIST +} + +function evaluate_upgrade_downgrade +{ + echo "CURRENT_SCHEMA_VERSION --> [$CURRENT_SCHEMA_VERSION]" | tee -a $LOG + echo "TARGET_SCHEMA_VERSION --> [$TARGET_SCHEMA_VERSION] " | tee -a $LOG + if [[ "${CURRENT_SCHEMA_VERSION}" < "${TARGET_SCHEMA_VERSION}" ]]; then + # perform db upgrade + UPGRADE_LIST=/tmp/db_upgrade_list.$$ + find ${DB_UPGRADE_DIR} -name "*_upgrade_script.sql" 2>/dev/null | grep "droolspdp" | sort > $UPGRADE_LIST + while read -r file + do + DB_VERSION=`basename $file | cut -d'_' -f1` + #echo "[$DB_VERSION] [$TARGET_SCHEMA_VERSION]" | tee -a $LOG + if [ "${DB_VERSION}" -gt "${CURRENT_SCHEMA_VERSION}" ] && [ "${DB_VERSION}" -le "${TARGET_SCHEMA_VERSION}" ]; then + run_script "UPGRADE" "${file}" 2>&1 | tee -a $LOG + fi + done < $UPGRADE_LIST + rm -f $UPGRADE_LIST + set_current_release_level $TARGET_SCHEMA_VERSION + elif [[ "${CURRENT_SCHEMA_VERSION}" > "${TARGET_SCHEMA_VERSION}" ]]; then + # db downgrade + echo "WARNING: Target db schema version is LOWER than current db scema version, please run downgrade script manually." | tee -a $LOG | tee -a $ERR + else + echo "CURRENT SCHEMA VERSION THE SAME AS TARGET SCHEMA VERSION, NO ACTION TAKEN ..." | tee -a $LOG + fi +} + +function run_script +{ + action="${1}" + script="${2}" + echo "Perform DB $action on [${DB_HOSTNAME}] use $script ..." | tee -a $LOG + echo "--" | tee -a $LOG + ${MYSQL} --verbose < "${script}" 2>$ERR | tee -a $LOG + echo "--" | tee -a $LOG +} + +function set_current_release_level +{ + DB_VERSION="${1}" + echo "Set current release level on [${DB_HOSTNAME}] to [$DB_VERSION] started ...@`date`" | tee -a $LOG + update_statement="insert into support.db_version (the_key, version) values ('DROOLS_VERSION', '${DB_VERSION}') on duplicate key update version='${DB_VERSION}';" + ${MYSQL} --execute "${update_statement}" + + echo "" | tee -a $LOG + echo "CURRENT_SCHEMA_VERSION set to: [$DB_VERSION]" | tee -a $LOG + echo "" | tee -a $LOG + echo "Set current release level on [${DB_HOSTNAME}] to [$DB_VERSION] completed ...@`date`" | tee -a $LOG +} + +function check_directory +{ + if [ ! -d $DB_UPGRADE_DIR ]; then + echo "ERROR, DIRECTORY NOT EXIST: $DB_UPGRADE_DIR, PROCESS EXIT ..." + exit; + else + if [ ! -d $DB_UPGRADE_DIR/logs ]; then + mkdir $DB_UPGRADE_DIR/logs + fi + fi +} + +# MAIN +#check_directory +LOG=$POLICY_HOME/logs/db_upgrade_droolspdp_remote_$DATE.log +ERR=$POLICY_HOME/logs/db_upgrade_droolspdp_remote_$DATE.err +echo "db_upgrade_droolspdp_remote.sh started ..." | tee -a $LOG +if [ $# -eq 3 ]; then + DB_UPGRADE_USER="${1}" + DB_UPGRADE_PASSWORD="${2}" + DB_HOSTNAME="${3}" + echo "DB_UPGRADE_USER: $DB_UPGRADE_USER" | tee -a $LOG + echo "DB_UPGRADE_DIR : $DB_UPGRADE_DIR" | tee -a $LOG + echo "DB_HOSTNAME : $DB_HOSTNAME" | tee -a $LOG + # + typeset -r MYSQL="mysql -u${DB_UPGRADE_USER} -p${DB_UPGRADE_PASSWORD} -h ${DB_HOSTNAME}"; + get_target_schema_version + if [ ${#TARGET_SCHEMA_VERSION} -ne 6 ]; then + echo "ERROR, TARGET_SCHEMA_VERSION MUST BE 6 DIGITS: $TARGET_SCHEMA_VERSION" | tee -a $LOG | tee -a $ERR + else + get_current_schema_version + evaluate_upgrade_downgrade + fi +else + echo "Usage : db_upgrade_droolspdp_remote.sh db_user_id db_user_password db_hostname" | tee -a $LOG + echo "Example: db_upgrade_droolspdp_remote.sh policy_user password policydb" | tee -a $LOG +fi + +echo "db_upgrade_droolspdp_remote.sh completed ..." | tee -a $LOG diff --git a/packages/base/src/files/bin/monitor.sh b/packages/base/src/files/bin/monitor.sh new file mode 100644 index 00000000..f4fad486 --- /dev/null +++ b/packages/base/src/files/bin/monitor.sh @@ -0,0 +1,148 @@ +#!/bin/bash + +### +# ============LICENSE_START======================================================= +# Base Package +# ================================================================================ +# Copyright (C) 2017 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +function usage() { + echo -n "syntax: $(basename $0) " + echo "[--debug]" +} + +function log() { + echo "$(date +"%Y-%m-%d_%H-%M-%S") $1" >> ${POLICY_HOME}/logs/monitor.log +} + +function monitor() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + CONTROLLER=$1 + STATUS=$2 + + if [[ -z ${CONTROLLER} ]]; then + log "WARNING: invalid invocation: no component provided" + return + fi + + if [[ -z ${STATUS} ]]; then + log "WARNING: invalid invocation: no on/off/uninstalled switch provided for ${CONTROLLER}" + return + fi + + if [[ "${STATUS}" == "off" ]]; then + off ${CONTROLLER} + else + if [[ "${STATUS}" == "on" ]]; then + on ${CONTROLLER} + fi + fi +} + +function on() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + CONTROLLER=$1 + NAGIOS_COMPONENT_SERVICE="Check_${CONTROLLER}-AliveStatus_AP_24094" + + ${POLICY_HOME}/bin/${CONTROLLER} status + if [[ $? != 0 ]]; then + log "starting ${CONTROLLER}" + + # need to make sure we don't pass the lock file descriptor + ${POLICY_HOME}/bin/${CONTROLLER} umstart {cfg}>&- + else + log "OK: ${CONTROLLER} (UP)" + fi +} + +function off() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + CONTROLLER=$1 + NAGIOS_COMPONENT_SERVICE="Check_${CONTROLLER}-AliveStatus_AP_24094" + + ${POLICY_HOME}/bin/${CONTROLLER} status + if [[ $? != 0 ]]; then + log "OK: ${CONTROLLER} (DOWN)" + + else + log "stopping ${CONTROLLER}" + ${POLICY_HOME}/bin/${CONTROLLER} umstop + fi +} + +function process_config() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + CONF_FILE=${POLICY_HOME}/etc/monitor/monitor.cfg + while read line || [ -n "${line}" ]; do + if [[ -n ${line} ]] && [[ ${line} != *#* ]]; then + controller=$(echo "${line}" | awk -F = '{print $1;}') + status=$(echo "${line}" | awk -F = '{print $2;}') + if [[ -n ${controller} ]] && [[ -n ${status} ]]; then + monitor ${controller} ${status} + fi + fi + done < "${CONF_FILE}" + return 0 +} + +log "Enter monitor" + +DEBUG=n +until [[ -z "$1" ]]; do + case $1 in + -d|--debug|debug) DEBUG=y + set -x + ;; + *) usage + exit 1 + ;; + esac + shift +done + +if pidof -o %PPID -x $(basename $0) > /dev/null 2>&1; then + log "WARNING: $(basename $0) from the previous iteration still running. Exiting." + exit 1 +fi + +. ${POLICY_HOME}/etc/profile.d/env.sh + +if [[ ${NAGIOS_NRDP_DISABLED} == true ]]; then + log "Nagios NRDS is disabled." +fi + +if flock ${cfg} ; then + process_config +fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock + + diff --git a/packages/base/src/files/bin/policy.sh b/packages/base/src/files/bin/policy.sh new file mode 100644 index 00000000..67f56caf --- /dev/null +++ b/packages/base/src/files/bin/policy.sh @@ -0,0 +1,154 @@ +#!/bin/bash + +### +# ============LICENSE_START======================================================= +# Base Package +# ================================================================================ +# Copyright (C) 2017 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +function usage() { + echo -n "syntax: $(basename $0) " + echo -n "[--debug] " + echo "status|start|stop" +} + +function check_x_file() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + FILE=$1 + if [[ ! -f ${FILE} || ! -x ${FILE} ]]; then + return 1 + fi + + return 0 +} + +function policy_op() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + operation=$1 + + cd $POLICY_HOME + echo "[drools-pdp-controllers]" + for binScript in bin/*-controller; do + if check_x_file "${binScript}"; then + trap "rm -f /tmp/out$$" EXIT + ${binScript} ${operation} >/tmp/out$$ + echo " L [${controller}]: $(sed ':a;N;$!ba;s/\n/ /g' /tmp/out$$)" + else + echo " L [${controller}]: -" + fi + done +} + +function policy_status() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + policy_op "status" + + NUM_CRONS=$(crontab -l 2> /dev/null | wc -l) + echo " ${NUM_CRONS} cron jobs installed." + +} + +function policy_start() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + policy_op "start" +} + + +function policy_stop() { + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} --" + set -x + fi + + policy_op "stop" +} + +######################################################################### +## +## script execution body +## +######################################################################### + +DEBUG=n +OPERATION=none + +until [[ -z "$1" ]]; do + case $1 in + -d|--debug|debug) DEBUG=y + set -x + ;; + -i|--status|status) OPERATION=status + ;; + -s|--start|start) OPERATION=start + ;; + -h|--stop|stop|--halt|halt) OPERATION=halt + ;; + *) usage + exit 1 + ;; + esac + shift +done + +# operation validation +case $OPERATION in + status) ;; + start) ;; + halt) ;; + *) echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}"; + usage + exit 1 + ;; +esac + +if [[ -z ${POLICY_HOME} ]]; then + echo "error: POLICY_HOME is unset." + exit 1 +fi + +# operation validation +case $OPERATION in + status) + policy_status + ;; + start) + policy_start + ;; + halt) + policy_stop + ;; + *) echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}"; + usage + exit 1 + ;; +esac diff --git a/packages/base/src/files/data/mysql/160400_droolspdp_downgrade_script.sql b/packages/base/src/files/data/mysql/160400_droolspdp_downgrade_script.sql new file mode 100644 index 00000000..44f49198 --- /dev/null +++ b/packages/base/src/files/data/mysql/160400_droolspdp_downgrade_script.sql @@ -0,0 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.sessioninfo; +drop table if exists drools.WORKITEMINFO; +drop table if exists drools.droolspdpentity; diff --git a/packages/base/src/files/data/mysql/160400_droolspdp_upgrade_script.sql b/packages/base/src/files/data/mysql/160400_droolspdp_upgrade_script.sql new file mode 100644 index 00000000..03e96521 --- /dev/null +++ b/packages/base/src/files/data/mysql/160400_droolspdp_upgrade_script.sql @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +-- use BLOB instead of LONGVARBINARY +drop table if exists drools.sessioninfo; +CREATE TABLE drools.SESSIONINFO +( +ID BIGINT NOT NULL, +LASTMODIFICATIONDATE TIMESTAMP, +RULESBYTEARRAY BLOB, +STARTDATE TIMESTAMP default current_timestamp, +OPTLOCK INTEGER, +PRIMARY KEY (ID) +); + +drop table if exists drools.WORKITEMINFO; +CREATE TABLE drools.WORKITEMINFO +( +WORKITEMID BIGINT NOT NULL, +CREATIONDATE TIMESTAMP default current_timestamp, +`NAME` VARCHAR(500), +PROCESSINSTANCEID BIGINT, +STATE BIGINT, +OPTLOCK INTEGER, +WORKITEMBYTEARRAY BLOB, +PRIMARY KEY (WORKITEMID) +); + +drop table if exists drools.droolspdpentity; +CREATE TABLE drools.DROOLSPDPENTITY +( + PDPID VARCHAR(100) NOT NULL, + DESIGNATED BOOLEAN NOT NULL DEFAULT FALSE, + PRIORITY INT NOT NULL DEFAULT 0, + UPDATEDDATE DATE NOT NULL, + GROUPID VARCHAR(100) NOT NULL, + SESSIONID BIGINT NOT NULL +); + + diff --git a/packages/base/src/files/data/mysql/160401_droolspdp_downgrade_script.sql b/packages/base/src/files/data/mysql/160401_droolspdp_downgrade_script.sql new file mode 100644 index 00000000..c8bbe035 --- /dev/null +++ b/packages/base/src/files/data/mysql/160401_droolspdp_downgrade_script.sql @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.droolspdpentity; +CREATE TABLE drools.DROOLSPDPENTITY +( + PDPID VARCHAR(100) NOT NULL, + DESIGNATED BOOLEAN NOT NULL DEFAULT FALSE, + PRIORITY INT NOT NULL DEFAULT 0, + UPDATEDDATE DATE NOT NULL, + GROUPID VARCHAR(100) NOT NULL, + SESSIONID BIGINT NOT NULL +); diff --git a/packages/base/src/files/data/mysql/160401_droolspdp_upgrade_script.sql b/packages/base/src/files/data/mysql/160401_droolspdp_upgrade_script.sql new file mode 100644 index 00000000..e7d92216 --- /dev/null +++ b/packages/base/src/files/data/mysql/160401_droolspdp_upgrade_script.sql @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.droolspdpentity; +CREATE TABLE drools.DROOLSPDPENTITY +( + PDPID VARCHAR(100) NOT NULL, + DESIGNATED BOOLEAN NOT NULL DEFAULT FALSE, + PRIORITY INT NOT NULL DEFAULT 0, + UPDATEDDATE TIMESTAMP NOT NULL, + GROUPID VARCHAR(100) NOT NULL, + SESSIONID BIGINT NOT NULL +); diff --git a/packages/base/src/files/data/mysql/160700_droolspdp_downgrade_script.sql b/packages/base/src/files/data/mysql/160700_droolspdp_downgrade_script.sql new file mode 100644 index 00000000..c8613bb7 --- /dev/null +++ b/packages/base/src/files/data/mysql/160700_droolspdp_downgrade_script.sql @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.droolssessionentity; +drop table if exists drools.droolspdpentity; +drop table if exists drools.sessioninfo; +drop table if exists drools.WORKITEMINFO; + diff --git a/packages/base/src/files/data/mysql/160700_droolspdp_upgrade_script.sql b/packages/base/src/files/data/mysql/160700_droolspdp_upgrade_script.sql new file mode 100644 index 00000000..3350859e --- /dev/null +++ b/packages/base/src/files/data/mysql/160700_droolspdp_upgrade_script.sql @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.droolssessionentity; +drop table if exists drools.droolspdpentity; + +CREATE TABLE drools.DROOLSPDPENTITY +( + PDPID VARCHAR(100) NOT NULL, + DESIGNATED BOOLEAN NOT NULL DEFAULT FALSE, + PRIORITY INT NOT NULL DEFAULT 0, + UPDATEDDATE TIMESTAMP NOT NULL, + GROUPID VARCHAR(100) NOT NULL, + SESSIONID BIGINT NOT NULL, + PRIMARY KEY(PDPID) +); + +CREATE TABLE drools.DROOLSSESSIONENTITY +( + PDPID VARCHAR(100) NOT NULL, + SESSIONNAME VARCHAR(100) NOT NULL, + SESSIONID BIGINT NOT NULL, + PDPENTITY_pdpId BIGINT NOT NULL, + PRIMARY KEY(PDPID,SESSIONNAME) +); +ALTER TABLE drools.DROOLSSESSIONENTITY ADD CONSTRAINT FK_DROOLSSESSIONENTITY_DROOLSPDPENTITY_PDPID +FOREIGN KEY (PDPID) REFERENCES drools.DROOLSPDPENTITY (PDPID); + +drop table if exists drools.sessioninfo; +CREATE TABLE drools.SESSIONINFO +( +ID BIGINT NOT NULL, +LASTMODIFICATIONDATE TIMESTAMP, +RULESBYTEARRAY BLOB, +STARTDATE TIMESTAMP default current_timestamp, +OPTLOCK INTEGER, +PRIMARY KEY (ID) +); + +drop table if exists drools.WORKITEMINFO; +CREATE TABLE drools.WORKITEMINFO +( +WORKITEMID BIGINT NOT NULL, +CREATIONDATE TIMESTAMP default current_timestamp, +`NAME` VARCHAR(500), +PROCESSINSTANCEID BIGINT, +STATE BIGINT, +OPTLOCK INTEGER, +WORKITEMBYTEARRAY BLOB, +PRIMARY KEY (WORKITEMID) +); diff --git a/packages/base/src/files/data/mysql/161000_droolspdp_downgrade_script.sql b/packages/base/src/files/data/mysql/161000_droolspdp_downgrade_script.sql new file mode 100644 index 00000000..b1ab793c --- /dev/null +++ b/packages/base/src/files/data/mysql/161000_droolspdp_downgrade_script.sql @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.droolssessionentity; +drop table if exists drools.droolspdpentity; + +CREATE TABLE drools.DROOLSPDPENTITY +( + PDPID VARCHAR(100) NOT NULL, + DESIGNATED BOOLEAN NOT NULL DEFAULT FALSE, + PRIORITY INT NOT NULL DEFAULT 0, + UPDATEDDATE TIMESTAMP NOT NULL, + GROUPID VARCHAR(100) NOT NULL, + SESSIONID BIGINT NOT NULL, + PRIMARY KEY(PDPID) +); + +CREATE TABLE drools.DROOLSSESSIONENTITY +( + PDPID VARCHAR(100) NOT NULL, + SESSIONNAME VARCHAR(100) NOT NULL, + SESSIONID BIGINT NOT NULL, + PDPENTITY_pdpId BIGINT NOT NULL, + PRIMARY KEY(PDPID,SESSIONNAME) +); +ALTER TABLE drools.DROOLSSESSIONENTITY ADD CONSTRAINT FK_DROOLSSESSIONENTITY_DROOLSPDPENTITY_PDPID +FOREIGN KEY (PDPID) REFERENCES drools.DROOLSPDPENTITY (PDPID); + +drop table if exists drools.LastSiteEntity; + diff --git a/packages/base/src/files/data/mysql/161000_droolspdp_upgrade_script.sql b/packages/base/src/files/data/mysql/161000_droolspdp_upgrade_script.sql new file mode 100644 index 00000000..9ef24426 --- /dev/null +++ b/packages/base/src/files/data/mysql/161000_droolspdp_upgrade_script.sql @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +DROP TABLE if exists drools.DROOLSSESSIONENTITY; +DROP TABLE if exists drools.DROOLSPDPENTITY; + +CREATE TABLE if not exists drools.DROOLSPDPENTITY +( +pdpId VARCHAR(255) NOT NULL, +designated TINYINT(1) default 0 NOT NULL, +priority INTEGER NOT NULL, +site VARCHAR(50), +updatedDate DATETIME NOT NULL, +PRIMARY KEY (pdpId) +); + +CREATE TABLE if not exists drools.DROOLSSESSIONENTITY +( +sessionName VARCHAR(255) NOT NULL, +pdpId VARCHAR(255) NOT NULL, +sessionId BIGINT NOT NULL, +PDPENTITY_pdpId VARCHAR(255), +PRIMARY KEY (sessionName, pdpId) +); + +ALTER TABLE drools.DROOLSSESSIONENTITY ADD CONSTRAINT FK_DROOLSSESSIONENTITY_PDPENTITY_pdpId +FOREIGN KEY (PDPENTITY_pdpId) +REFERENCES drools.DROOLSPDPENTITY (pdpId); + +drop table if exists drools.LastSiteEntity; + +CREATE TABLE `drools`.`LastSiteEntity` +( `id` INT NOT NULL , +`siteName` VARCHAR(50) NOT NULL +); + + diff --git a/packages/base/src/files/data/mysql/161001_droolspdp_downgrade_script.sql b/packages/base/src/files/data/mysql/161001_droolspdp_downgrade_script.sql new file mode 100644 index 00000000..983a9f3c --- /dev/null +++ b/packages/base/src/files/data/mysql/161001_droolspdp_downgrade_script.sql @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +set foreign_key_checks=0; + +drop table if exists drools.LastSiteEntity; + +CREATE TABLE `drools`.`LastSiteEntity` +( `id` INT NOT NULL , +`siteName` VARCHAR(50) NOT NULL +); + +drop table if exists drools.DROOLSPDPENTITY; + +CREATE TABLE if not exists drools.DROOLSPDPENTITY +( +pdpId VARCHAR(255) NOT NULL, +designated TINYINT(1) default 0 NOT NULL, +priority INTEGER NOT NULL, +site VARCHAR(50), +updatedDate DATETIME NOT NULL, +PRIMARY KEY (pdpId) +); + +drop table if exists drools.DROOLSSESSIONENTITY; +CREATE TABLE if not exists drools.DROOLSSESSIONENTITY +( +sessionName VARCHAR(255) NOT NULL, +pdpId VARCHAR(255) NOT NULL, +sessionId BIGINT NOT NULL, +PDPENTITY_pdpId VARCHAR(255), +PRIMARY KEY (sessionName, pdpId) +); + +ALTER TABLE drools.DROOLSSESSIONENTITY ADD CONSTRAINT FK_DROOLSSESSIONENTITY_PDPENTITY_pdpId +FOREIGN KEY (PDPENTITY_pdpId) +REFERENCES drools.DROOLSPDPENTITY (pdpId); + +set foreign_key_checks=1; diff --git a/packages/base/src/files/data/mysql/161001_droolspdp_upgrade_script.sql b/packages/base/src/files/data/mysql/161001_droolspdp_upgrade_script.sql new file mode 100644 index 00000000..2731e1bd --- /dev/null +++ b/packages/base/src/files/data/mysql/161001_droolspdp_upgrade_script.sql @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +set foreign_key_checks=0; + +drop table if exists drools.LastSiteEntity; + +drop table if exists drools.DROOLSPDPENTITY; + +CREATE TABLE if not exists drools.DROOLSPDPENTITY +( +pdpId VARCHAR(255) NOT NULL, +designated TINYINT(1) default 0 NOT NULL, +priority INTEGER NOT NULL, +site VARCHAR(50), +updatedDate DATETIME NOT NULL, +designatedDate DATETIME NOT NULL, +PRIMARY KEY (pdpId) +); + +drop table if exists drools.DROOLSSESSIONENTITY; +CREATE TABLE if not exists drools.DROOLSSESSIONENTITY +( +sessionName VARCHAR(255) NOT NULL, +pdpId VARCHAR(255) NOT NULL, +sessionId BIGINT NOT NULL, +PDPENTITY_pdpId VARCHAR(255), +PRIMARY KEY (sessionName, pdpId) +); + +ALTER TABLE drools.DROOLSSESSIONENTITY ADD CONSTRAINT FK_DROOLSSESSIONENTITY_PDPENTITY_pdpId +FOREIGN KEY (PDPENTITY_pdpId) +REFERENCES drools.DROOLSPDPENTITY (pdpId); + +set foreign_key_checks=1; diff --git a/packages/base/src/files/data/mysql/161002_droolspdp_downgrade_script.sql b/packages/base/src/files/data/mysql/161002_droolspdp_downgrade_script.sql new file mode 100644 index 00000000..90ed6457 --- /dev/null +++ b/packages/base/src/files/data/mysql/161002_droolspdp_downgrade_script.sql @@ -0,0 +1,21 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.IntegrityAuditEntity; diff --git a/packages/base/src/files/data/mysql/161002_droolspdp_upgrade_script.sql b/packages/base/src/files/data/mysql/161002_droolspdp_upgrade_script.sql new file mode 100644 index 00000000..ff99d36a --- /dev/null +++ b/packages/base/src/files/data/mysql/161002_droolspdp_upgrade_script.sql @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.IntegrityAuditEntity; +create table if not exists drools.IntegrityAuditEntity +( + id int not null auto_increment, + persistenceUnit varchar(100) not null, + site varchar(100), + nodeType varchar(100), + resourceName varchar(100) not null, + designated boolean default false, + jdbcDriver varchar(100) not null, + jdbcUrl varchar(100) not null, + jdbcUser varchar(30) not null, + jdbcPassword varchar(30) not null, + createdDate TIMESTAMP NOT NULL default current_timestamp, + lastUpdated TIMESTAMP NOT NULL, + primary key(id) +); + +alter table drools.IntegrityAuditEntity add constraint resourceName_uniq unique(resourceName); + + diff --git a/packages/base/src/files/data/mysql/161003_droolspdp_downgrade_script.sql b/packages/base/src/files/data/mysql/161003_droolspdp_downgrade_script.sql new file mode 100644 index 00000000..ba9ac573 --- /dev/null +++ b/packages/base/src/files/data/mysql/161003_droolspdp_downgrade_script.sql @@ -0,0 +1,22 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.SEQUENCE; + diff --git a/packages/base/src/files/data/mysql/161003_droolspdp_upgrade_script.sql b/packages/base/src/files/data/mysql/161003_droolspdp_upgrade_script.sql new file mode 100644 index 00000000..7f8c17ca --- /dev/null +++ b/packages/base/src/files/data/mysql/161003_droolspdp_upgrade_script.sql @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists drools.SEQUENCE; +CREATE TABLE drools.SEQUENCE +( +SEQ_NAME VARCHAR(50) NOT NULL, +SEQ_COUNT NUMERIC(38), +PRIMARY KEY (SEQ_NAME) +); + +INSERT INTO drools.SEQUENCE (SEQ_NAME,SEQ_COUNT) VALUES ('SEQ_GEN',3050); diff --git a/packages/base/src/files/data/mysql/161004_droolspdp_downgrade_script.sql b/packages/base/src/files/data/mysql/161004_droolspdp_downgrade_script.sql new file mode 100644 index 00000000..0f756585 --- /dev/null +++ b/packages/base/src/files/data/mysql/161004_droolspdp_downgrade_script.sql @@ -0,0 +1,2 @@ +alter table drools.droolsPdpEntity modify updatedDate datetime not null; +alter table drools.droolsPdpEntity modify designatedDate datetime not null; diff --git a/packages/base/src/files/data/mysql/161004_droolspdp_upgrade_script.sql b/packages/base/src/files/data/mysql/161004_droolspdp_upgrade_script.sql new file mode 100644 index 00000000..f3a6cdda --- /dev/null +++ b/packages/base/src/files/data/mysql/161004_droolspdp_upgrade_script.sql @@ -0,0 +1,5 @@ +alter table drools.droolsPdpEntity modify updatedDate timestamp not null; +alter table drools.droolsPdpEntity modify designatedDate timestamp not null; + + + \ No newline at end of file diff --git a/packages/base/src/files/data/mysql/170200_droolspdp_downgrade_script.sql b/packages/base/src/files/data/mysql/170200_droolspdp_downgrade_script.sql new file mode 100644 index 00000000..928a584e --- /dev/null +++ b/packages/base/src/files/data/mysql/170200_droolspdp_downgrade_script.sql @@ -0,0 +1,21 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +alter table drools.IntegrityAuditEntity modify jdbcUrl varchar(100) not null; diff --git a/packages/base/src/files/data/mysql/170200_droolspdp_upgrade_script.sql b/packages/base/src/files/data/mysql/170200_droolspdp_upgrade_script.sql new file mode 100644 index 00000000..93bb69e3 --- /dev/null +++ b/packages/base/src/files/data/mysql/170200_droolspdp_upgrade_script.sql @@ -0,0 +1,21 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +alter table drools.IntegrityAuditEntity modify jdbcUrl varchar(200) not null; diff --git a/packages/base/src/files/etc/cron.d/monitor.cron b/packages/base/src/files/etc/cron.d/monitor.cron new file mode 100755 index 00000000..b7321720 --- /dev/null +++ b/packages/base/src/files/etc/cron.d/monitor.cron @@ -0,0 +1 @@ +* * * * * export POLICY_HOME=${{POLICY_HOME}}; ${{POLICY_HOME}}/bin/monitor.sh >/dev/null 2>&1 diff --git a/packages/base/src/files/etc/monitor/monitor.cfg b/packages/base/src/files/etc/monitor/monitor.cfg new file mode 100644 index 00000000..afc6c714 --- /dev/null +++ b/packages/base/src/files/etc/monitor/monitor.cfg @@ -0,0 +1,6 @@ +# Line Format: component=status where +# component=, e.g. policy-management-controller +# status=on|off where +# on: component is to be monitored and should started +# off: component is to be monitored and should stopped +# There should be no component duplicate lines diff --git a/packages/base/src/files/etc/profile.d/env.sh b/packages/base/src/files/etc/profile.d/env.sh new file mode 100644 index 00000000..be8e7471 --- /dev/null +++ b/packages/base/src/files/etc/profile.d/env.sh @@ -0,0 +1,35 @@ +### +# ============LICENSE_START======================================================= +# Base Package +# ================================================================================ +# Copyright (C) 2017 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +export POLICY_HOME=${{POLICY_HOME}} +export JAVA_HOME=${{JAVA_HOME}} +export ENGINE_MANAGEMENT_USER=${{ENGINE_MANAGEMENT_USER}} +export ENGINE_MANAGEMENT_PASSWORD=${{ENGINE_MANAGEMENT_PASSWORD}} +export ENGINE_MANAGEMENT_PORT=${{ENGINE_MANAGEMENT_PORT}} +export ENGINE_MANAGEMENT_HOST=${{ENGINE_MANAGEMENT_HOST}} + +for x in $POLICY_HOME/bin $JAVA_HOME/bin $HOME/bin ; do + if [ -d $x ] ; then + case ":$PATH:" in + *":$x:"*) :;; # already there + *) PATH="$x:$PATH";; + esac + fi +done diff --git a/packages/base/src/files/etc/profile.d/su.cfg b/packages/base/src/files/etc/profile.d/su.cfg new file mode 100644 index 00000000..9cacea38 --- /dev/null +++ b/packages/base/src/files/etc/profile.d/su.cfg @@ -0,0 +1 @@ +# name=value pairs for su purposes diff --git a/packages/base/src/files/install/mysql/data/151000_downgrade_script.sql b/packages/base/src/files/install/mysql/data/151000_downgrade_script.sql new file mode 100644 index 00000000..d336c5c0 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/151000_downgrade_script.sql @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +use xacml; + +DROP TABLE IF EXISTS XACML.SYSTEMLOGDB; +DROP TABLE IF EXISTS XACML.SEQUENCE; +DROP TABLE IF EXISTS XACML.RULEALGORITHMS; +DROP TABLE IF EXISTS XACML.ROLES; +DROP TABLE IF EXISTS XACML.POLICYALGORITHMS; +DROP TABLE IF EXISTS XACML.POLICY_MANANGEMENT; +DROP TABLE IF EXISTS XACML.PIPRESOLVERPARAMS; +DROP TABLE IF EXISTS XACML.PIPRESOLVER; +DROP TABLE IF EXISTS XACML.PIPCONFIGPARAMS; +DROP TABLE IF EXISTS XACML.PIPCONFIGURATION; +DROP TABLE IF EXISTS XACML.PIPTYPE; +DROP TABLE IF EXISTS XACML.OBADVICEEXPRESSIONS; +DROP TABLE IF EXISTS XACML.GLOBALROLESETTINGS; +DROP TABLE IF EXISTS XACML.FUNCTIONARGUMENTS; +DROP TABLE IF EXISTS XACML.FUNCTIONDEFINITION; +DROP TABLE IF EXISTS XACML.ECOMPNAME; +DROP TABLE IF EXISTS XACML.DECISIONSETTINGS; +DROP TABLE IF EXISTS XACML.ATTRIBUTEASSIGNMENT; +DROP TABLE IF EXISTS XACML.CONSTRAINTVALUES; +DROP TABLE IF EXISTS XACML.ATTRIBUTE; +DROP TABLE IF EXISTS XACML.OBADVICE; +DROP TABLE IF EXISTS XACML.CONSTRAINTTYPE; +DROP TABLE IF EXISTS XACML.CATEGORY; +DROP TABLE IF EXISTS XACML.DATATYPE; +DROP TABLE IF EXISTS XACML.ACTIONPOLICYDICT; +DROP TABLE IF EXISTS XACML.SERVICEGROUP; +DROP TABLE IF EXISTS XACML.SECURITYZONE; +DROP TABLE IF EXISTS XACML.POLICYENTITY; +DROP TABLE IF EXISTS XACML.CONFIGURATIONDATAENTITY; +DROP TABLE IF EXISTS XACML.POLICYDBDAOENTITY; + +DROP TABLE IF EXISTS XACML.POLICYSCORE; +DROP TABLE IF EXISTS XACML.ACTIONLIST; +DROP TABLE IF EXISTS XACML.PROTOCOLLIST; +DROP TABLE IF EXISTS XACML.TERM; +DROP TABLE IF EXISTS XACML.PREFIXLIST; +DROP TABLE IF EXISTS XACML.SCOPE; +DROP TABLE IF EXISTS XACML.ENFORCINGTYPE; +DROP TABLE IF EXISTS XACML.PORTLIST; +DROP TABLE IF EXISTS XACML.GROUPSERVICELIST; +DROP TABLE IF EXISTS XACML.VSCLACTION; +DROP TABLE IF EXISTS XACML.VNFTYPE; +DROP TABLE IF EXISTS XACML.ADDRESSGROUP; + +-- DROP SEQUENCE IF EXISTS XACML.SEQCONFIG; +-- DROP SEQUENCE IF EXISTS XACML.SEQPOLICY; + +DROP TABLE IF EXISTS LOG.SEQUENCE; +DROP TABLE IF EXISTS LOG.SYSTEMLOGDB; + +DROP VIEW IF EXISTS xacml.match_functions; +DROP VIEW IF EXISTS xacml.xacml.function_flattener; +DROP VIEW IF EXISTS xacml.xacml.higherorder_bag_functions; diff --git a/packages/base/src/files/install/mysql/data/151000_upgrade_script.sql b/packages/base/src/files/install/mysql/data/151000_upgrade_script.sql new file mode 100644 index 00000000..065d705f --- /dev/null +++ b/packages/base/src/files/install/mysql/data/151000_upgrade_script.sql @@ -0,0 +1,1563 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +use xacml; + +DROP TABLE IF EXISTS XACML.SYSTEMLOGDB; +DROP TABLE IF EXISTS XACML.SEQUENCE; +DROP TABLE IF EXISTS XACML.RULEALGORITHMS; +DROP TABLE IF EXISTS XACML.ROLES; +DROP TABLE IF EXISTS XACML.POLICYALGORITHMS; +DROP TABLE IF EXISTS XACML.POLICY_MANANGEMENT; +DROP TABLE IF EXISTS XACML.PIPRESOLVERPARAMS; +DROP TABLE IF EXISTS XACML.PIPRESOLVER; +DROP TABLE IF EXISTS XACML.PIPCONFIGPARAMS; +DROP TABLE IF EXISTS XACML.PIPCONFIGURATION; +DROP TABLE IF EXISTS XACML.PIPTYPE; +DROP TABLE IF EXISTS XACML.OBADVICEEXPRESSIONS; +DROP TABLE IF EXISTS XACML.GLOBALROLESETTINGS; +DROP TABLE IF EXISTS XACML.FUNCTIONARGUMENTS; +DROP TABLE IF EXISTS XACML.FUNCTIONDEFINITION; +DROP TABLE IF EXISTS XACML.ECOMPNAME; +DROP TABLE IF EXISTS XACML.DECISIONSETTINGS; +DROP TABLE IF EXISTS XACML.ATTRIBUTEASSIGNMENT; +DROP TABLE IF EXISTS XACML.CONSTRAINTVALUES; +DROP TABLE IF EXISTS XACML.ATTRIBUTE; +DROP TABLE IF EXISTS XACML.OBADVICE; +DROP TABLE IF EXISTS XACML.CONSTRAINTTYPE; +DROP TABLE IF EXISTS XACML.CATEGORY; +DROP TABLE IF EXISTS XACML.DATATYPE; +DROP TABLE IF EXISTS XACML.ACTIONPOLICYDICT; +DROP TABLE IF EXISTS XACML.SERVICEGROUP; +DROP TABLE IF EXISTS XACML.SECURITYZONE; +DROP TABLE IF EXISTS XACML.VSCLACTION; +DROP TABLE IF EXISTS XACML.VNFTYPE; +DROP TABLE IF EXISTS XACML.POLICYENTITY; +DROP TABLE IF EXISTS XACML.CONFIGURATIONDATAENTITY; +DROP TABLE IF EXISTS XACML.PolicyDBDaoEntity; + +DROP TABLE IF EXISTS XACML.POLICYSCORE; +DROP TABLE IF EXISTS XACML.ACTIONLIST; +DROP TABLE IF EXISTS XACML.PROTOCOLLIST; +DROP TABLE IF EXISTS XACML.TERM; +DROP TABLE IF EXISTS XACML.PREFIXLIST; +DROP TABLE IF EXISTS XACML.SCOPE; +DROP TABLE IF EXISTS XACML.GROUPSERVICELIST; +DROP TABLE IF EXISTS XACML.ENFORCINGTYPE; +DROP TABLE IF EXISTS XACML.PORTLIST; +DROP TABLE IF EXISTS XACML.ADDRESSGROUP; + +-- DROP SEQUENCE IF EXISTS XACML.SEQCONFIG; +-- DROP SEQUENCE IF EXISTS XACML.SEQPOLICY; +DROP TABLE IF EXISTS LOG.SEQUENCE; +DROP TABLE IF EXISTS LOG.SYSTEMLOGDB; + +DROP VIEW IF EXISTS xacml.match_functions; +DROP VIEW IF EXISTS xacml.function_flattener; +DROP VIEW IF EXISTS xacml.higherorder_bag_functions; + +DROP TABLE IF EXISTS XACML.GroupServiceList; + +CREATE TABLE XACML.GroupServiceList +( +id INTEGER NOT NULL, +name varchar(32), +serviceList varchar(255), +PRIMARY KEY (id) +) +; +CREATE INDEX IDX_GROUPSERVICELIST ON XACML.GROUPSERVICELIst(ID); + +DROP TABLE IF EXISTS XACML.PolicyAlgorithms; + +CREATE TABLE XACML.PolicyAlgorithms +( +id INTEGER NOT NULL, + is_standard CHAR NOT NULL, + short_name VARCHAR(64) NOT NULL, + xacml_id VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.AttributeAssignment; + +CREATE TABLE XACML.AttributeAssignment +( +id INTEGER NOT NULL, + attribute_id INTEGER, + expression VARCHAR(5000) NOT NULL, + OBADVICE_id INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.roles; +CREATE TABLE XACML.roles +( +id INTEGER NOT NULL, + attuid VARCHAR(45) NOT NULL, + role VARCHAR(45) NOT NULL, + scope VARCHAR(45), + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.POLICYSCORE; +CREATE TABLE XACML.POLICYSCORE +( +POLICY_NAME VARCHAR(200) NOT NULL, + POLICY_SCORE VARCHAR(100), + PRIMARY KEY (POLICY_NAME) +) +; + +DROP TABLE IF EXISTS XACML.GlobalRoleSettings; +CREATE TABLE XACML.GlobalRoleSettings +( +role VARCHAR(45) NOT NULL, + lockdown BOOLEAN, + PRIMARY KEY (role) +) +; + +DROP TABLE IF EXISTS XACML.PIPResolverParams; +CREATE TABLE XACML.PIPResolverParams +( +id INTEGER NOT NULL, + PARAM_DEFAULT VARCHAR(2048), + PARAM_NAME VARCHAR(1024) NOT NULL, + PARAM_VALUE VARCHAR(2048) NOT NULL, + REQUIRED CHAR NOT NULL, + ID_RESOLVER INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.Attribute; +CREATE TABLE XACML.Attribute +( +id INTEGER NOT NULL, + ATTRIBUTE_VALUE VARCHAR(255), + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + description VARCHAR(2048), + is_designator CHAR NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + PRIORITY VARCHAR(45), + selector_path VARCHAR(2048), + xacml_id VARCHAR(100) NOT NULL UNIQUE, + category INTEGER, + constraint_type INTEGER, + datatype INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.FunctionArguments; +CREATE TABLE XACML.FunctionArguments +( +id INTEGER NOT NULL, + arg_index INTEGER NOT NULL, + is_bag INTEGER NOT NULL, + datatype_id INTEGER, + function_id INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.actionlist; +CREATE TABLE XACML.actionlist +( +id INTEGER NOT NULL, + actionname VARCHAR(45) NOT NULL, + description VARCHAR(64), + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.Obadvice; +CREATE TABLE XACML.Obadvice +( +id INTEGER NOT NULL, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP NOT NULL, + description VARCHAR(2048), + fulfill_on VARCHAR(32), + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + type VARCHAR(100) NOT NULL, + xacml_id VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.ObadviceExpressions; +CREATE TABLE XACML.ObadviceExpressions +( +id INTEGER NOT NULL, + type VARCHAR(100) NOT NULL, + obadvice_id INTEGER, + attribute_id INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.RuleAlgorithms; +CREATE TABLE XACML.RuleAlgorithms +( +id INTEGER NOT NULL, + is_standard CHAR NOT NULL, + short_name VARCHAR(64) NOT NULL, + xacml_id VARCHAR(255) NOT NULL UNIQUE, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.ConstraintValues; +CREATE TABLE XACML.ConstraintValues +( +id INTEGER NOT NULL, + property VARCHAR(1000), + value VARCHAR(1000), + attribute_id INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.DecisionSettings; +CREATE TABLE XACML.DecisionSettings +( +id INTEGER NOT NULL, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + description VARCHAR(2048), + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + PRIORITY VARCHAR(45), + xacml_id VARCHAR(45) NOT NULL UNIQUE, + datatype INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.policy_manangement; +CREATE TABLE XACML.policy_manangement +( +id INTEGER NOT NULL, + CONFIG_NAME VARCHAR(45) NOT NULL, + CREATE_DATE_TIME TIMESTAMP NOT NULL, + CREATED_BY VARCHAR(45) NOT NULL, + ECOMP_NAME VARCHAR(45) NOT NULL, + POLICY_NAME VARCHAR(45) NOT NULL, + scope VARCHAR(45) NOT NULL, + UPDATE_DATE_TIME TIMESTAMP NOT NULL, + UPDATED_BY VARCHAR(45) NOT NULL, + XML text NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.PIPConfiguration; +CREATE TABLE XACML.PIPConfiguration +( +id INTEGER NOT NULL, + CLASSNAME VARCHAR(2048) NOT NULL, + CREATED_BY VARCHAR(255) NOT NULL, + CREATED_DATE TIMESTAMP NOT NULL, + DESCRIPTION VARCHAR(2048), + ISSUER VARCHAR(1024), + MODIFIED_BY VARCHAR(255) NOT NULL, + MODIFIED_DATE TIMESTAMP NOT NULL, + NAME VARCHAR(255) NOT NULL, + READ_ONLY CHAR NOT NULL, + REQUIRES_RESOLVER CHAR NOT NULL, + TYPE INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.protocollist; +CREATE TABLE XACML.protocollist +( +id INTEGER NOT NULL, + description VARCHAR(64), + protocolname VARCHAR(45) NOT NULL, + PRIMARY KEY (id) +) +; + + +DROP TABLE IF EXISTS XACML.FunctionDefinition; +CREATE TABLE XACML.FunctionDefinition +( +id INTEGER NOT NULL, + arg_lb INTEGER NOT NULL, + arg_ub INTEGER NOT NULL, + ho_arg_lb INTEGER, + ho_arg_ub INTEGER, + ho_primitive CHAR, + is_bag_return INTEGER NOT NULL, + is_higher_order INTEGER NOT NULL, + short_name VARCHAR(64) NOT NULL, + xacml_id VARCHAR(255) NOT NULL, + return_datatype INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.PIPResolver; +CREATE TABLE XACML.PIPResolver +( +id INTEGER NOT NULL, + CLASSNAME VARCHAR(2048) NOT NULL, + CREATED_BY VARCHAR(255) NOT NULL, + CREATED_DATE TIMESTAMP NOT NULL, + DESCRIPTION VARCHAR(2048), + ISSUER VARCHAR(1024), + MODIFIED_BY VARCHAR(255) NOT NULL, + MODIFIED_DATE TIMESTAMP NOT NULL, + NAME VARCHAR(255) NOT NULL, + READ_ONLY CHAR NOT NULL, + PIP_ID INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.TERM; +CREATE TABLE XACML.TERM +( +id INTEGER NOT NULL, + description VARCHAR(100), + action VARCHAR(100), + destIPList VARCHAR(100), + destPortList VARCHAR(100), + portList VARCHAR(100), + protocolList VARCHAR(100), + srcIPList VARCHAR(100), + srcPortList VARCHAR(100), + termName VARCHAR(45) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.PREFIXLIST; +CREATE TABLE XACML.PREFIXLIST +( +id INTEGER NOT NULL, + pl_name VARCHAR(45) NOT NULL, + pl_value VARCHAR(64) NOT NULL, + description VARCHAR(255), + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.Datatype; +CREATE TABLE XACML.Datatype +( +id INTEGER NOT NULL, + is_standard CHAR NOT NULL, + short_name VARCHAR(64) NOT NULL, + xacml_id VARCHAR(255) NOT NULL UNIQUE, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.PIPType; +CREATE TABLE XACML.PIPType +( +id INTEGER NOT NULL, + type VARCHAR(45) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.ActionPolicyDict; +CREATE TABLE XACML.ActionPolicyDict +( +id INTEGER NOT NULL, + ATTRIBUTE_NAME VARCHAR(45) NOT NULL, + Body VARCHAR(4096), + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + description VARCHAR(2048), + Headers VARCHAR(1024), + Method VARCHAR(45) NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + Type VARCHAR(45) NOT NULL, + URL VARCHAR(45) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.Category; +CREATE TABLE XACML.Category +( +id INTEGER NOT NULL, + grouping VARCHAR(64) NOT NULL, + is_standard CHAR NOT NULL, + short_name VARCHAR(64) NOT NULL, + xacml_id VARCHAR(255) NOT NULL UNIQUE, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.Scope; +CREATE TABLE XACML.Scope +( +scopeId BIGINT NOT NULL, + parentScope BIGINT, + scopeName VARCHAR(255) NOT NULL, + PRIMARY KEY (scopeId) +) +; +CREATE INDEX parentScope ON Scope (parentScope); + +DROP TABLE IF EXISTS XACML.EcompName; +CREATE TABLE XACML.EcompName +( +id INTEGER NOT NULL, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + description VARCHAR(2048), + ecomp_Name VARCHAR(100) NOT NULL UNIQUE, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.ConstraintType; +CREATE TABLE XACML.ConstraintType +( +id INTEGER NOT NULL, + constraint_type VARCHAR(64) NOT NULL, + description VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.EnforcingType; +CREATE TABLE XACML.EnforcingType +( +id INTEGER NOT NULL, + connectionQuery VARCHAR(255) NOT NULL, + enforcingType VARCHAR(255) NOT NULL UNIQUE, + script VARCHAR(255) NOT NULL, + valueQuery VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.PIPConfigParams; +CREATE TABLE XACML.PIPConfigParams +( +id INTEGER NOT NULL, + PARAM_DEFAULT VARCHAR(2048), + PARAM_NAME VARCHAR(1024) NOT NULL, + PARAM_VALUE VARCHAR(2048) NOT NULL, + REQUIRED CHAR NOT NULL, + PIP_ID INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.portlist; +CREATE TABLE XACML.portlist +( +id INTEGER NOT NULL, + description VARCHAR(64), + portname VARCHAR(45) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.SEQUENCE; +CREATE TABLE XACML.SEQUENCE +( +SEQ_NAME VARCHAR(50) NOT NULL, + SEQ_COUNT NUMERIC(38), + PRIMARY KEY (SEQ_NAME) +) +; +-- INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0); +-- CREATE SEQUENCE seq START WITH 1; + +DROP TABLE IF EXISTS XACML.SYSTEMLOGDB; +CREATE TABLE XACML.SYSTEMLOGDB +( + id INTEGER NOT NULL AUTO_INCREMENT, + system VARCHAR(255) NOT NULL, + description VARCHAR(2048), + remote VARCHAR(255) NOT NULL, + type VARCHAR(10) NOT NULL, + date TIMESTAMP NOT NULL, + logtype VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +) + +; + +DROP TABLE IF EXISTS LOG.SEQUENCE; +CREATE TABLE LOG.SEQUENCE +( +SEQ_NAME VARCHAR(50) NOT NULL, + SEQ_COUNT NUMERIC(38), + PRIMARY KEY (SEQ_NAME) +) +; + +DROP TABLE IF EXISTS LOG.SYSTEMLOGDB; +CREATE TABLE LOG.SYSTEMLOGDB +( + id INTEGER NOT NULL AUTO_INCREMENT, + system VARCHAR(255) NOT NULL, + description VARCHAR(2048), + remote VARCHAR(255) NOT NULL, + type VARCHAR(10) NOT NULL, + date TIMESTAMP NOT NULL, + logtype VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +) +; + +drop table if exists SUPPORT.DB_VERSION; +create table SUPPORT.DB_VERSION +( + the_key varchar(20) primary key not null, + version varchar(20) +) +; + +DROP TABLE IF EXISTS XACML.SERVICEGROUP; +CREATE TABLE XACML.SERVICEGROUP +( +id integer NOT NULL, +name varchar(32), +type varchar(16), +transportprotocol varchar(255), +appprotocol varchar(255), +ports varchar(255), +`desc` varchar(255), +primary key(id) +) +; + +DROP TABLE IF EXISTS XACML.SECURITYZONE; +CREATE TABLE XACML.SECURITYZONE +( +id integer NOT NULL, +name varchar(32), +value varchar(64), +primary key(id) +) +; + +CREATE TABLE XACML.VSCLACTION +( +ID INTEGER NOT NULL, +VSCL_ACTION VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +CREATE TABLE XACML.VNFTYPE +( +ID INTEGER NOT NULL, +VNF_TYPE VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +) +; + +DROP TABLE IF EXISTS XACML.POLICYENTITY; +CREATE TABLE XACML.PolicyEntity +( +policyId BIGINT NOT NULL, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + deleted BOOLEAN NOT NULL, + description VARCHAR(2048) NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + policyData TEXT, + policyName VARCHAR(255) NOT NULL, + scope VARCHAR(255) NOT NULL, + version INTEGER, + configurationDataId BIGINT, + PRIMARY KEY (policyId)) +; +CREATE INDEX scope ON XACML.PolicyEntity (scope); +CREATE INDEX policyName ON XACML.PolicyEntity (policyName); + +DROP TABLE IF EXISTS XACML.ConfigurationDataEntity; +CREATE TABLE XACML.ConfigurationDataEntity +( +configurationDataId BIGINT NOT NULL, + configBody TEXT, + configType VARCHAR(255) NOT NULL, + configurationName VARCHAR(255) NOT NULL, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + deleted BOOLEAN NOT NULL, + description VARCHAR(2048) NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + version INTEGER, + PRIMARY KEY (configurationDataId)) +; + +DROP TABLE IF EXISTS XACML.PolicyDBDaoEntity; +CREATE TABLE XACML.PolicyDBDaoEntity +( + policyDBDaoUrl VARCHAR(500) NOT NULL UNIQUE, + created_date TIMESTAMP, + description VARCHAR(2048) NOT NULL, + modified_date TIMESTAMP NOT NULL, + PRIMARY KEY (policyDBDaoUrl)) +; + +DROP TABLE IF EXISTS XACML.ADDRESSGROUP; +CREATE TABLE ADDRESSGROUP +( + id INTEGER NOT NULL, + name varchar(32), + description VARCHAR(64), + prefixlist varchar(255) +); + +create index idx_addressgroup on ADDRESSGROUP(ID); + + + +create or replace view xacml.match_functions +as select d.id as id, d.short_name as shortname, d.xacml_id as xacmlid, +d.return_datatype as return_datatype, d.is_bag_return as is_bag_return, +d.arg_lb as arg_lb, d.arg_ub as arg_ub, a1.is_bag as arg1_isbag, +a1.datatype_id as arg1_datatype, a2.is_bag as arg2_isbag, +a2.datatype_id as arg2_datatype +from (xacml.functiondefinition d +left join xacml.functionarguments a1 on (a1.function_id = d.id and a1.arg_index = 1) +left join xacml.functionarguments a2 on (a2.function_id = d.id and a2.arg_index = 2)) +where (d.arg_lb = 2 and d.arg_ub = 2 and d.return_datatype = 18 and a1.is_bag = 0) +order by d.short_name; + +create or replace view xacml.function_flattener +as select d.id as id, d.short_name as shortname, +d.return_datatype as return_datatype, d.is_bag_return as is_bag_return, +d.is_higher_order as is_higher_order, d.arg_lb as arg_lb, d.arg_ub as arg_ub, +a1.is_bag as arg1_isbag, a1.datatype_id as arg1_datatype, a2.is_bag as arg2_isbag, +a2.datatype_id as arg2_datatype, a3.is_bag as arg3_isbag, +a3.datatype_id as arg3_datatype +from (xacml.functiondefinition d left join xacml.functionarguments a1 +on (a1.function_id = d.id and a1.arg_index = 1) +left join xacml.functionarguments a2 on (a2.function_id = d.id and a2.arg_index = 2) +left join xacml.functionarguments a3 on (a3.function_id = d.id and a3.arg_index = 3)) +order by d.id; + +create or replace view xacml.higherorder_bag_functions +as select * from xacml.function_flattener +where is_higher_order = 1 and is_bag_return = 1 and return_datatype=18 +and arg_lb=2 and arg_ub=2 and arg1_isbag = 1 and (arg2_isbag = 1 or arg2_isbag is null); + +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.SYSTEMLOGDB TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.SEQUENCE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.RULEALGORITHMS TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.ROLES TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.POLICYALGORITHMS TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.POLICY_MANANGEMENT TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.PIPRESOLVERPARAMS TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.PIPRESOLVER TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.PIPCONFIGPARAMS TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.PIPCONFIGURATION TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.PIPTYPE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.OBADVICEEXPRESSIONS TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.GLOBALROLESETTINGS TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.FUNCTIONARGUMENTS TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.FUNCTIONDEFINITION TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.ECOMPNAME TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.DECISIONSETTINGS TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.ATTRIBUTEASSIGNMENT TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.CONSTRAINTVALUES TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.ATTRIBUTE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.OBADVICE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.CONSTRAINTTYPE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.CATEGORY TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.DATATYPE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.ACTIONPOLICYDICT TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.POLICYENTITY TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.CONFIGURATIONDATAENTITY TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.PolicyDBDaoEntity TO policy_user; + +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.POLICYSCORE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.ACTIONLIST TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.PROTOCOLLIST TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.TERM TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.PREFIXLIST TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.SCOPE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.ENFORCINGTYPE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.PORTLIST TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.GROUPSERVICELIST TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.VSCLACTION TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.VNFTYPE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON XACML.ADDRESSGROUP TO policy_user; + +GRANT SELECT, INSERT, UPDATE, DELETE ON LOG.SEQUENCE TO policy_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON LOG.SYSTEMLOGDB TO policy_user; + +grant insert, update, delete, select on support.db_version to policy_user; +grant select on xacml.match_functions to policy_user; +grant select on xacml.function_flattener to policy_user; +grant select on xacml.higherorder_bag_functions to policy_user; + + + +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1401,'super-admin',str_to_date('2015-05-11 19:56:54.930000','%Y-%m-%d %H:%i:%s.%f'),null,'1','super-admin',str_to_date('2015-05-11 19:56:54.930000','%Y-%m-%d %H:%i:%s.%f'),null,'true',5,null,18,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1455,'super-admin',str_to_date('2015-05-13 14:10:44.134000','%Y-%m-%d %H:%i:%s.%f'),null,'1','super-admin',str_to_date('2015-05-13 14:10:44.134000','%Y-%m-%d %H:%i:%s.%f'),null,'Test-Kat',5,null,26,'High',null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1551,'super-admin',str_to_date('2015-05-22 11:40:23.118000','%Y-%m-%d %H:%i:%s.%f'),null,'1','super-admin',str_to_date('2015-05-22 11:40:23.118000','%Y-%m-%d %H:%i:%s.%f'),null,'test',5,null,26,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1926,'super-admin',str_to_date('2015-06-09 11:42:16.580000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window starts (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:29:46.407000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Thursday_Start:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1927,'super-admin',str_to_date('2015-06-09 11:42:33.966000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window starts (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:29:24.841000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Friday_Start:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1928,'super-admin',str_to_date('2015-06-09 11:42:49.867000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window starts (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:29:32.730000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Saturday_Start:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1929,'super-admin',str_to_date('2015-06-09 11:43:11.486000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window starts (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:34:08.866000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Sunday_Start:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1954,'super-admin',str_to_date('2015-06-11 23:30:12.656000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window ends (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:30:39.869000','%Y-%m-%d %H:%i:%s.%f'),null,'Window _Monday_End:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1955,'super-admin',str_to_date('2015-06-11 23:30:46.701000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window ends (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:32:01.698000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Friday_End:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1956,'super-admin',str_to_date('2015-06-11 23:31:10.449000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window ends (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:31:42.361000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Saturday_End:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1957,'super-admin',str_to_date('2015-06-11 23:32:25.542000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window ends (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:32:45.215000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Sunday_End:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1958,'super-admin',str_to_date('2015-06-11 23:32:55.89000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window ends (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:33:11.766000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Thursday_End:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1959,'super-admin',str_to_date('2015-06-11 23:33:28.664000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window ends (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:33:47.905000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Tuesday_End:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (1960,'super-admin',str_to_date('2015-06-11 23:34:18.912000','%Y-%m-%d %H:%i:%s.%f'),'Hour when maintenance window ends (0 to 24)','1','super-admin',str_to_date('2015-06-11 23:35:12.283000','%Y-%m-%d %H:%i:%s.%f'),null,'Window_Wednesday_End:',5,null,12,null,null); +INSERT INTO XACML.ATTRIBUTE (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,IS_DESIGNATOR,MODIFIED_BY,MODIFIED_DATE,SELECTOR_PATH,XACML_ID,CATEGORY,CONSTRAINT_TYPE,DATATYPE,PRIORITY,ATTRIBUTE_VALUE) VALUES (2904,'super-admin',str_to_date('2015-08-24 18:06:29.370000','%Y-%m-%d %H:%i:%s.%f'),'Test','1','super-admin',str_to_date('2015-08-24 18:06:29.370000','%Y-%m-%d %H:%i:%s.%f'),null,'KK1:(0)',5,null,26,null,null); + + + + +INSERT INTO XACML.CATEGORY (ID,GROUPING,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (4,'subject','S','intermediary-subject','urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject'); +INSERT INTO XACML.CATEGORY (ID,GROUPING,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (5,'resource','S','resource','urn:oasis:names:tc:xacml:3.0:attribute-category:resource'); +INSERT INTO XACML.CATEGORY (ID,GROUPING,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (6,'subject','S','codebase','urn:oasis:names:tc:xacml:1.0:subject-category:codebase'); +INSERT INTO XACML.CATEGORY (ID,GROUPING,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (7,'action','S','action','urn:oasis:names:tc:xacml:3.0:attribute-category:action'); +INSERT INTO XACML.CATEGORY (ID,GROUPING,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (8,'subject','S','access-subject','urn:oasis:names:tc:xacml:1.0:subject-category:access-subject'); +INSERT INTO XACML.CATEGORY (ID,GROUPING,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (9,'environment','S','environment','urn:oasis:names:tc:xacml:3.0:attribute-category:environment'); +INSERT INTO XACML.CATEGORY (ID,GROUPING,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (10,'subject','S','requesting-machine','urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine'); +INSERT INTO XACML.CATEGORY (ID,GROUPING,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (11,'subject','S','recipient-subject','urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject'); + + +INSERT INTO XACML.CONSTRAINTTYPE (ID,CONSTRAINT_TYPE,DESCRIPTION) VALUES (1,'Range','Set a range of min and/or max integer/double values the attribute can be set to during policy creation.'); +INSERT INTO XACML.CONSTRAINTTYPE (ID,CONSTRAINT_TYPE,DESCRIPTION) VALUES (2,'Regular Expression','Define a regular expression the attribute must match against during policy creation.'); +INSERT INTO XACML.CONSTRAINTTYPE (ID,CONSTRAINT_TYPE,DESCRIPTION) VALUES (3,'Enumeration','Enumerate a set of values that the attribute may be set to during policy creation.'); + + + + + +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (12,'S','integer','http://www.w3.org/2001/XMLSchema#integer'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (13,'S','base64Binary','http://www.w3.org/2001/XMLSchema#base64Binary'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (14,'S','x500Name','urn:oasis:names:tc:xacml:1.0:data-type:x500Name'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (15,'S','dayTimeDuration','http://www.w3.org/2001/XMLSchema#dayTimeDuration'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (16,'S','time','http://www.w3.org/2001/XMLSchema#time'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (17,'S','dnsName','urn:oasis:names:tc:xacml:2.0:data-type:dnsName'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (18,'S','boolean','http://www.w3.org/2001/XMLSchema#boolean'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (19,'S','dateTime','http://www.w3.org/2001/XMLSchema#dateTime'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (20,'S','rfc822Name','urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (21,'S','date','http://www.w3.org/2001/XMLSchema#date'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (22,'S','ipAddress','urn:oasis:names:tc:xacml:2.0:data-type:ipAddress'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (23,'S','yearMonthDuration','http://www.w3.org/2001/XMLSchema#yearMonthDuration'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (24,'S','hexBinary','http://www.w3.org/2001/XMLSchema#hexBinary'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (25,'S','double','http://www.w3.org/2001/XMLSchema#double'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (26,'S','string','http://www.w3.org/2001/XMLSchema#string'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (27,'S','anyURI','http://www.w3.org/2001/XMLSchema#anyURI'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (28,'S','xpathExpression','urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression'); +INSERT INTO XACML.DATATYPE (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (29,'S','user',''); + + + + +INSERT INTO XACML.ECOMPNAME (ID,CREATED_BY,CREATED_DATE,DESCRIPTION,ECOMP_NAME,MODIFIED_BY,MODIFIED_DATE) VALUES (1456,'super-admin',str_to_date('2015-05-13 14:21:34.778000','%Y-%m-%d %H:%i:%s.%f'),'orchestrator','MSO','super-admin',str_to_date('2015-05-13 14:21:34.778000','%Y-%m-%d %H:%i:%s.%f')); + + +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (1,1,0,12,1); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (2,2,0,12,1); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (3,1,0,12,2); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (4,2,0,12,2); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (5,1,0,25,3); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (6,1,1,12,4); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (7,1,1,25,5); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (8,1,0,26,6); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (9,2,0,26,6); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (10,1,0,26,7); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (11,2,0,26,7); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (12,1,0,26,8); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (13,2,0,26,8); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (14,1,0,26,9); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (15,2,0,26,9); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (16,1,0,26,10); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (17,1,0,26,11); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (18,1,0,18,12); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (19,1,0,26,13); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (20,1,0,12,14); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (21,1,0,26,15); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (22,1,0,25,16); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (23,1,0,26,17); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (24,1,0,16,18); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (25,1,0,26,19); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (26,1,0,21,20); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (27,1,0,26,21); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (28,1,0,19,22); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (29,1,0,26,23); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (30,1,0,27,24); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (31,1,0,26,25); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (32,1,0,15,26); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (33,1,0,26,27); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (34,1,0,23,28); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (35,1,0,26,29); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (36,1,0,14,30); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (37,1,0,26,31); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (38,1,0,20,32); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (39,1,0,26,33); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (40,1,0,22,34); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (41,1,0,26,35); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (42,1,0,17,36); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (43,2,0,27,37); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (44,1,0,26,37); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (45,1,0,26,38); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (46,2,0,27,38); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (47,1,0,26,39); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (48,2,0,26,39); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (49,1,0,26,40); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (50,2,0,27,40); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (51,1,0,26,41); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (52,2,0,12,41); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (53,3,0,12,41); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (54,1,0,27,42); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (55,2,0,12,42); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (56,3,0,12,42); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (57,1,0,18,43); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (58,2,0,18,43); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (59,1,0,12,44); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (60,2,0,12,44); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (61,1,0,25,45); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (62,2,0,25,45); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (63,1,0,21,46); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (64,2,0,21,46); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (65,1,0,16,47); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (66,2,0,16,47); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (67,1,0,19,48); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (68,2,0,19,48); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (69,1,0,15,49); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (70,2,0,15,49); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (71,1,0,23,50); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (72,2,0,23,50); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (73,1,0,27,51); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (74,2,0,27,51); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (75,1,0,14,52); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (76,2,0,14,52); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (77,1,0,20,53); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (78,2,0,20,53); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (79,1,0,24,54); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (80,2,0,24,54); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (81,1,0,13,55); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (82,2,0,13,55); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (83,1,0,12,56); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (84,2,0,12,56); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (85,1,0,25,57); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (86,2,0,25,57); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (89,1,0,25,58); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (90,2,0,25,58); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (91,1,0,12,59); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (92,2,0,12,59); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (93,1,0,25,60); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (94,2,0,25,60); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (95,1,0,12,61); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (96,2,0,12,61); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (97,1,0,25,62); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (98,2,0,25,62); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (99,1,0,12,63); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (100,2,0,12,63); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (101,1,0,12,64); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (102,1,0,25,65); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (103,1,0,25,66); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (104,1,0,25,67); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (125,1,0,26,68); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (126,1,0,26,69); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (128,1,0,12,70); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (129,1,0,12,71); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (130,2,0,12,71); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (131,1,0,12,72); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (132,2,0,12,72); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (133,1,0,12,73); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (134,2,0,12,73); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (135,1,0,25,74); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (136,2,0,25,74); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (137,1,0,25,75); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (138,2,0,25,75); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (139,1,0,25,76); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (140,2,0,25,76); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (141,1,0,25,77); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (142,2,0,25,77); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (143,1,0,19,78); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (144,2,0,15,78); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (145,1,0,19,79); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (146,2,0,23,79); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (147,1,0,19,80); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (148,2,0,15,80); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (149,1,0,19,81); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (150,2,0,23,81); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (151,1,0,21,82); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (152,2,0,23,82); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (153,1,0,21,83); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (154,2,0,23,83); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (155,1,0,26,84); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (156,2,0,26,84); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (157,1,0,26,85); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (158,2,0,26,85); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (159,1,0,26,86); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (160,2,0,26,86); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (161,1,0,26,87); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (162,2,0,26,87); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (163,1,0,16,88); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (164,2,0,16,88); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (165,1,0,16,89); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (166,2,0,16,89); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (167,1,0,16,90); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (168,2,0,16,90); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (169,1,0,16,91); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (170,2,0,16,91); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (171,1,0,16,92); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (172,2,0,16,92); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (173,1,0,19,93); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (174,2,0,19,93); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (175,1,0,19,94); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (176,2,0,19,94); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (177,1,0,19,95); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (178,2,0,19,95); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (179,1,0,19,96); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (180,2,0,19,96); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (181,1,0,21,97); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (182,2,0,21,97); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (183,1,0,21,98); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (184,2,0,21,98); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (185,2,0,21,99); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (186,1,0,21,99); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (187,2,0,21,100); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (188,1,0,21,100); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (189,1,1,26,101); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (190,1,1,26,102); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (191,1,0,26,103); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (192,2,1,26,103); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (193,1,0,26,104); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (194,1,1,12,105); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (195,1,0,12,106); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (196,2,1,12,106); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (197,1,0,12,107); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (198,1,1,25,108); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (199,1,0,25,109); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (200,2,1,25,109); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (201,1,0,25,110); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (202,1,1,18,111); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (203,1,1,18,112); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (204,1,0,18,113); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (205,2,1,18,113); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (206,1,0,18,114); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (207,1,1,16,115); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (208,1,1,16,116); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (209,1,0,16,117); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (210,2,1,16,117); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (211,1,0,16,118); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (212,1,1,21,119); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (213,1,1,21,120); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (214,1,0,21,121); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (215,2,1,21,121); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (216,1,0,21,122); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (217,1,1,19,123); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (218,1,1,19,124); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (219,1,0,19,125); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (220,2,1,19,125); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (221,1,0,19,126); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (222,1,1,27,127); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (223,1,1,27,128); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (224,1,0,27,129); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (225,2,1,27,129); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (226,1,0,27,130); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (227,1,1,24,131); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (228,1,1,24,132); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (229,1,0,24,133); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (230,2,1,24,133); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (231,1,0,24,134); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (232,1,1,13,135); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (233,1,1,13,136); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (234,1,0,13,137); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (235,2,1,13,137); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (236,1,0,13,138); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (237,1,1,15,139); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (238,1,1,15,140); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (239,1,0,15,141); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (240,2,1,15,141); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (241,1,0,15,142); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (242,1,1,23,143); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (243,1,1,23,144); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (244,2,1,23,145); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (245,1,0,23,145); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (246,1,0,23,146); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (247,1,1,14,147); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (248,1,1,14,148); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (249,1,0,14,149); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (250,2,1,14,149); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (251,1,0,14,150); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (252,1,1,20,151); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (253,1,1,20,152); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (254,1,0,20,153); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (255,2,1,20,153); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (256,1,0,20,154); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (257,1,1,22,155); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (258,1,1,22,156); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (259,1,0,22,157); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (260,2,1,22,157); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (261,1,0,22,158); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (262,1,1,17,159); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (263,1,1,17,160); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (264,1,0,17,161); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (265,2,1,17,161); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (266,1,0,17,162); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (267,1,0,26,163); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (268,2,0,26,163); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (269,1,0,26,164); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (270,2,0,27,164); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (271,1,0,26,165); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (272,2,0,22,165); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (273,1,0,26,166); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (274,2,0,17,166); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (275,1,0,26,167); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (276,2,0,20,167); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (277,1,0,26,168); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (278,2,0,14,168); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (279,1,1,26,169); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (280,2,1,26,169); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (281,1,1,26,170); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (282,2,1,26,170); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (283,1,1,26,171); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (284,1,1,26,172); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (285,2,1,26,172); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (286,1,1,26,173); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (287,2,1,26,173); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (288,2,1,12,174); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (289,1,1,12,174); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (290,1,1,12,175); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (292,2,1,12,176); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (293,1,1,12,176); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (294,2,1,12,177); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (295,1,1,12,177); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (296,1,1,25,178); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (297,2,1,25,178); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (298,1,1,25,179); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (299,1,1,25,180); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (300,2,1,25,180); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (301,1,1,25,181); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (302,2,1,25,181); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (303,1,1,18,182); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (304,2,1,18,182); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (305,1,1,18,183); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (306,2,1,18,183); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (307,1,1,18,184); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (308,1,1,18,185); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (309,2,1,18,185); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (310,1,1,18,186); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (311,2,1,18,186); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (312,2,1,16,187); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (313,1,1,16,187); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (314,1,1,16,188); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (315,2,1,16,188); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (316,1,1,16,189); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (317,1,1,16,190); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (318,2,1,16,190); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (319,1,1,16,191); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (320,2,1,16,191); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (321,1,1,21,192); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (322,2,1,21,192); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (323,1,1,21,193); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (324,2,1,21,193); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (325,1,1,21,194); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (326,1,1,21,195); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (327,2,1,21,195); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (328,1,1,21,196); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (329,2,1,21,196); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (330,1,1,19,197); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (331,2,1,19,197); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (332,1,1,19,198); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (333,2,1,19,198); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (334,1,1,19,199); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (335,1,1,19,200); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (336,2,1,19,200); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (337,1,1,19,201); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (338,2,1,19,201); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (339,1,1,27,202); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (340,2,1,27,202); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (341,1,1,27,203); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (342,2,1,27,203); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (343,1,1,27,204); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (344,1,1,27,205); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (345,2,1,27,205); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (346,1,1,27,206); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (347,2,1,27,206); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (348,1,1,24,207); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (349,2,1,24,207); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (350,1,1,24,208); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (351,2,1,24,208); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (352,1,1,24,209); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (353,1,1,24,210); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (354,2,1,24,210); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (355,1,1,24,211); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (356,2,1,24,211); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (357,1,1,13,212); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (358,2,1,13,212); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (359,1,1,13,213); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (360,2,1,13,213); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (361,1,1,13,214); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (362,1,1,13,215); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (363,2,1,13,215); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (364,1,1,13,216); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (365,2,1,13,216); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (366,1,1,15,217); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (367,2,1,15,217); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (368,1,1,15,218); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (369,2,1,15,218); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (370,1,1,15,219); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (371,1,1,15,220); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (372,2,1,15,220); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (373,1,1,15,221); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (374,2,1,15,221); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (375,1,1,23,222); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (376,2,1,23,222); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (377,1,1,23,223); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (378,2,1,23,223); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (380,1,1,23,224); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (381,1,1,23,225); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (382,2,1,23,225); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (383,2,1,23,226); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (384,1,1,23,226); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (385,1,1,14,227); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (386,2,1,14,227); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (387,1,1,14,228); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (388,2,1,14,228); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (389,1,1,14,229); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (390,1,1,14,230); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (391,2,1,14,230); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (392,1,1,14,231); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (393,2,1,14,231); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (394,1,1,20,232); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (395,2,1,20,232); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (396,1,1,20,233); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (397,2,1,20,233); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (398,1,1,20,234); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (399,1,1,20,235); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (400,2,1,20,235); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (401,1,1,20,236); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (402,2,1,20,236); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (403,1,0,14,237); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (404,2,0,14,237); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (405,1,0,26,238); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (406,2,0,20,238); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (407,1,1,12,239); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (408,2,1,12,239); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (409,1,1,25,240); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (410,2,1,25,240); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (411,1,0,18,241); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (412,1,0,18,242); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (413,1,0,12,243); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (414,2,0,18,243); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (415,1,0,18,244); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (416,1,0,18,245); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (417,2,0,null,245); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (418,3,1,null,245); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (419,1,0,18,246); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (420,2,0,null,246); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (421,3,1,null,246); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (422,1,0,18,247); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (423,2,1,null,247); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (424,3,1,null,247); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (433,1,0,18,248); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (434,2,1,null,248); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (435,3,1,null,248); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (436,1,0,18,249); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (437,2,1,null,249); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (438,3,1,null,249); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (439,1,0,18,250); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (440,2,1,null,250); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (441,3,1,null,250); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (442,1,0,null,251); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (447,2,1,null,251); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (448,1,0,28,252); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (449,1,0,28,253); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (450,2,0,28,253); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (451,1,0,28,254); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (452,2,0,28,254); +INSERT INTO XACML.FUNCTIONARGUMENTS (ID,ARG_INDEX,IS_BAG,DATATYPE_ID,FUNCTION_ID) VALUES (453,3,0,16,92); + + +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (1,2,2,null,null,null,0,0,'integer-greater-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (2,2,2,null,null,null,0,0,'integer-subtract','urn:oasis:names:tc:xacml:1.0:function:integer-subtract',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (3,1,1,null,null,null,0,0,'double-to-integer','urn:oasis:names:tc:xacml:1.0:function:double-to-integer',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (4,1,1,null,null,null,0,0,'integer-one-and-only','urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (5,1,1,null,null,null,0,0,'double-one-and-only','urn:oasis:names:tc:xacml:1.0:function:double-one-and-only',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (6,2,2,null,null,null,0,0,'string-equal','urn:oasis:names:tc:xacml:1.0:function:string-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (7,2,2,null,null,null,0,0,'string-equal-ignore-case','urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (8,2,2,null,null,null,0,0,'string-starts-with','urn:oasis:names:tc:xacml:3.0:function:string-starts-with',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (9,2,2,null,null,null,0,0,'string-ends-with','urn:oasis:names:tc:xacml:3.0:function: string-ends-with',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (10,2,-1,null,null,null,0,0,'string-concatenate','urn:oasis:names:tc:xacml:2.0:function:string-concatenate',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (11,1,1,null,null,null,0,0,'boolean-from-string','urn:oasis:names:tc:xacml:3.0:function:boolean-from-string',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (12,1,1,null,null,null,0,0,'string-from-boolean','urn:oasis:names:tc:xacml:3.0:function:string-from-boolean',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (13,1,1,null,null,null,0,0,'integer-from-string','urn:oasis:names:tc:xacml:3.0:function:integer-from-string',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (14,1,1,null,null,null,0,0,'string-from-integer','urn:oasis:names:tc:xacml:3.0:function:string-from-integer',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (15,1,1,null,null,null,0,0,'double-from-string','urn:oasis:names:tc:xacml:3.0:function:double-from-string',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (16,1,1,null,null,null,0,0,'string-from-double','urn:oasis:names:tc:xacml:3.0:function:string-from-double',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (17,1,1,null,null,null,0,0,'time-from-string','urn:oasis:names:tc:xacml:3.0:function:time-from-string',16); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (18,1,1,null,null,null,0,0,'string-from-time','urn:oasis:names:tc:xacml:3.0:function:string-from-time',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (19,1,1,null,null,null,0,0,'date-from-string','urn:oasis:names:tc:xacml:3.0:function:date-from-string',21); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (20,1,1,null,null,null,0,0,'string-from-date','urn:oasis:names:tc:xacml:3.0:function:string-from-date',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (21,1,1,null,null,null,0,0,'dateTime-from-string','urn:oasis:names:tc:xacml:3.0:function:dateTime-from-string',19); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (22,1,1,null,null,null,0,0,'string-from-dateTime','urn:oasis:names:tc:xacml:3.0:function:string-from-dateTime',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (23,1,1,null,null,null,0,0,'anyURI-from-string','urn:oasis:names:tc:xacml:3.0:function:anyURI-from-string',27); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (24,1,1,null,null,null,0,0,'string-from-anyURI','urn:oasis:names:tc:xacml:3.0:function:string-from-anyURI',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (25,1,1,null,null,null,0,0,'dayTimeDuration-from-string','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-from-string',15); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (26,1,1,null,null,null,0,0,'string-from-dayTimeDuration','urn:oasis:names:tc:xacml:3.0:function:string-from-dayTimeDuration',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (27,1,1,null,null,null,0,0,'yearMonthDuration-from-string','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-from-string',23); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (28,1,1,null,null,null,0,0,'string-from-yearMonthDuration','urn:oasis:names:tc:xacml:3.0:function:string-from-yearMonthDuration',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (29,1,1,null,null,null,0,0,'x500Name-from-string','urn:oasis:names:tc:xacml:3.0:function:x500Name-from-string',14); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (30,1,1,null,null,null,0,0,'string-from-x500Name','urn:oasis:names:tc:xacml:3.0:function:string-from-x500Name',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (31,1,1,null,null,null,0,0,'rfc822Name-from-string','urn:oasis:names:tc:xacml:3.0:function:rfc822Name-from-string',20); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (32,1,1,null,null,null,0,0,'string-from-rfc822Name','urn:oasis:names:tc:xacml:3.0:function:string-from-rfc822Name',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (33,1,1,null,null,null,0,0,'ipAddress-from-string','urn:oasis:names:tc:xacml:3.0:function:ipAddress-from-string',22); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (34,1,1,null,null,null,0,0,'string-from-ipAddress','urn:oasis:names:tc:xacml:3.0:function:string-from-ipAddress',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (35,1,1,null,null,null,0,0,'dnsName-from-string','urn:oasis:names:tc:xacml:3.0:function:dnsName-from-string',17); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (36,1,1,null,null,null,0,0,'string-from-dnsName','urn:oasis:names:tc:xacml:3.0:function:string-from-dnsName',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (37,2,2,null,null,null,0,0,'anyURI-starts-with','urn:oasis:names:tc:xacml:3.0:function:anyURI-starts-with',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (38,2,2,null,null,null,0,0,'anyURI-ends-with','urn:oasis:names:tc:xacml:3.0:function:anyURI-ends-with',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (39,2,2,null,null,null,0,0,'string-contains','urn:oasis:names:tc:xacml:3.0:function:string-contains',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (40,2,2,null,null,null,0,0,'anyURI-contains','urn:oasis:names:tc:xacml:3.0:function:anyURI-contains',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (41,3,3,null,null,null,0,0,'string-substring','urn:oasis:names:tc:xacml:3.0:function:string-substring',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (42,3,3,null,null,null,0,0,'anyURI-substring','urn:oasis:names:tc:xacml:3.0:function:anyURI-substring',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (43,2,2,null,null,null,0,0,'boolean-equal','urn:oasis:names:tc:xacml:1.0:function:boolean-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (44,2,2,null,null,null,0,0,'integer-equal','urn:oasis:names:tc:xacml:1.0:function:integer-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (45,2,2,null,null,null,0,0,'double-equal','urn:oasis:names:tc:xacml:1.0:function:double-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (46,2,2,null,null,null,0,0,'date-equal','urn:oasis:names:tc:xacml:1.0:function:date-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (47,2,2,null,null,null,0,0,'time-equal','urn:oasis:names:tc:xacml:1.0:function:time-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (48,2,2,null,null,null,0,0,'dateTime-equal','urn:oasis:names:tc:xacml:1.0:function:dateTime-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (49,2,2,null,null,null,0,0,'dayTimeDuration-equal','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (50,2,2,null,null,null,0,0,'yearMonthDuration-equal','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (51,2,2,null,null,null,0,0,'anyURI-equal','urn:oasis:names:tc:xacml:1.0:function:anyURI-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (52,2,2,null,null,null,0,0,'x500Name-equal','urn:oasis:names:tc:xacml:1.0:function:x500Name-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (53,2,2,null,null,null,0,0,'rfc822Name-equal','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (54,2,2,null,null,null,0,0,'hexBinary-equal','urn:oasis:names:tc:xacml:1.0:function:hexBinary-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (55,2,2,null,null,null,0,0,'base64Binary-equal','urn:oasis:names:tc:xacml:1.0:function:base64Binary-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (56,2,2,null,null,null,0,0,'integer-add','urn:oasis:names:tc:xacml:1.0:function:integer-add',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (57,2,2,null,null,null,0,0,'double-add','urn:oasis:names:tc:xacml:1.0:function:double-add',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (58,2,2,null,null,null,0,0,'double-subtract','urn:oasis:names:tc:xacml:1.0:function:double-subtract',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (59,2,2,null,null,null,0,0,'integer-multiply','urn:oasis:names:tc:xacml:1.0:function:integer-multiply',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (60,2,2,null,null,null,0,0,'double-multiply','urn:oasis:names:tc:xacml:1.0:function:double-multiply',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (61,2,2,null,null,null,0,0,'integer-divide','urn:oasis:names:tc:xacml:1.0:function:integer-divide',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (62,2,2,null,null,null,0,0,'double-divide','urn:oasis:names:tc:xacml:1.0:function:double-divide',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (63,2,2,null,null,null,0,0,'integer-mod','urn:oasis:names:tc:xacml:1.0:function:integer-mod',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (64,1,1,null,null,null,0,0,'integer-abs','urn:oasis:names:tc:xacml:1.0:function:integer-abs',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (65,1,1,null,null,null,0,0,'double-abs','urn:oasis:names:tc:xacml:1.0:function:double-abs',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (66,1,1,null,null,null,0,0,'round','urn:oasis:names:tc:xacml:1.0:function:round',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (67,1,1,null,null,null,0,0,'floor','urn:oasis:names:tc:xacml:1.0:function:floor',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (68,1,1,null,null,null,0,0,'string-normalize-space','urn:oasis:names:tc:xacml:1.0:function:string-normalize-space',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (69,1,1,null,null,null,0,0,'string-normalize-to-lower-case','urn:oasis:names:tc:xacml:1.0:function:string-normalize-to-lower-case',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (70,1,1,null,null,null,0,0,'integer-to-double','urn:oasis:names:tc:xacml:1.0:function:integer-to-double',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (71,2,2,null,null,null,0,0,'integer-greater-than','urn:oasis:names:tc:xacml:1.0:function:integer-greater-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (72,2,2,null,null,null,0,0,'integer-less-than','urn:oasis:names:tc:xacml:1.0:function:integer-less-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (73,2,2,null,null,null,0,0,'integer-less-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:integer-less-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (74,2,2,null,null,null,0,0,'double-greater-than','urn:oasis:names:tc:xacml:1.0:function:double-greater-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (75,2,2,null,null,null,0,0,'double-greater-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:double-greater-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (76,2,2,null,null,null,0,0,'double-less-than','urn:oasis:names:tc:xacml:1.0:function:double-less-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (77,2,2,null,null,null,0,0,'double-less-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:double-less-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (78,2,2,null,null,null,0,0,'dateTime-add-dayTimeDuration','urn:oasis:names:tc:xacml:3.0:function:dateTime-add-dayTimeDuration',19); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (79,2,2,null,null,null,0,0,'dateTime-add-yearMonthDuration','urn:oasis:names:tc:xacml:3.0:function:dateTime-add-yearMonthDuration',19); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (80,2,2,null,null,null,0,0,'dateTime-subtract-dayTimeDuration','urn:oasis:names:tc:xacml:3.0:function:dateTime-subtract-dayTimeDuration',19); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (81,2,2,null,null,null,0,0,'dateTime-subtract-yearMonthDuration','urn:oasis:names:tc:xacml:3.0:function:dateTime-subtract-yearMonthDuration',19); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (82,2,2,null,null,null,0,0,'date-add-yearMonthDuration','urn:oasis:names:tc:xacml:3.0:function:date-add-yearMonthDuration',21); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (83,2,2,null,null,null,0,0,'date-subtract-yearMonthDuration','urn:oasis:names:tc:xacml:3.0:function:date-subtract-yearMonthDuration',21); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (84,2,2,null,null,null,0,0,'string-greater-than','urn:oasis:names:tc:xacml:1.0:function:string-greater-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (85,2,2,null,null,null,0,0,'string-greater-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:string-greater-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (86,2,2,null,null,null,0,0,'string-less-than','urn:oasis:names:tc:xacml:1.0:function:string-less-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (87,2,2,null,null,null,0,0,'string-less-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:string-less-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (88,2,2,null,null,null,0,0,'time-greater-than','urn:oasis:names:tc:xacml:1.0:function:time-greater-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (89,2,2,null,null,null,0,0,'time-greater-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:time-greater-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (90,2,2,null,null,null,0,0,'time-less-than','urn:oasis:names:tc:xacml:1.0:function:time-less-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (91,2,2,null,null,null,0,0,'time-less-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:time-less-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (92,3,3,null,null,null,0,0,'time-in-range','urn:oasis:names:tc:xacml:2.0:function:time-in-range',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (93,2,2,null,null,null,0,0,'dateTime-greater-than','urn:oasis:names:tc:xacml:1.0:function:dateTime-greater-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (94,2,2,null,null,null,0,0,'dateTime-greater-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:dateTime-greater-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (95,2,2,null,null,null,0,0,'dateTime-less-than','urn:oasis:names:tc:xacml:1.0:function:dateTime-less-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (96,2,2,null,null,null,0,0,'dateTime-less-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:dateTime-less-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (97,2,2,null,null,null,0,0,'date-greater-than','urn:oasis:names:tc:xacml:1.0:function:date-greater-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (98,2,2,null,null,null,0,0,'date-greater-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:date-greater-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (99,2,2,null,null,null,0,0,'date-less-than','urn:oasis:names:tc:xacml:1.0:function:date-less-than',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (100,2,2,null,null,null,0,0,'date-less-than-or-equal','urn:oasis:names:tc:xacml:1.0:function:date-less-than-or-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (101,1,1,null,null,null,0,0,'string-one-and-only','urn:oasis:names:tc:xacml:1.0:function:string-one-and-only',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (102,1,1,null,null,null,0,0,'string-bag-size','urn:oasis:names:tc:xacml:1.0:function:string-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (103,2,2,null,null,null,0,0,'string-is-in','urn:oasis:names:tc:xacml:1.0:function:string-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (104,1,-1,null,null,null,1,0,'string-bag','urn:oasis:names:tc:xacml:1.0:function:string-bag',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (105,1,1,null,null,null,0,0,'integer-bag-size','urn:oasis:names:tc:xacml:1.0:function:integer-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (106,2,2,null,null,null,0,0,'integer-is-in','urn:oasis:names:tc:xacml:1.0:function:integer-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (107,1,-1,null,null,null,1,0,'integer-bag','urn:oasis:names:tc:xacml:1.0:function:integer-bag',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (108,1,1,null,null,null,0,0,'double-bag-size','urn:oasis:names:tc:xacml:1.0:function:double-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (109,2,2,null,null,null,0,0,'double-is-in','urn:oasis:names:tc:xacml:1.0:function:double-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (110,1,-1,null,null,null,1,0,'double-bag','urn:oasis:names:tc:xacml:1.0:function:double-bag',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (111,1,1,null,null,null,0,0,'boolean-one-and-only','urn:oasis:names:tc:xacml:1.0:function:boolean-one-and-only',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (112,1,1,null,null,null,0,0,'boolean-bag-size','urn:oasis:names:tc:xacml:1.0:function:boolean-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (113,2,2,null,null,null,0,0,'boolean-is-in','urn:oasis:names:tc:xacml:1.0:function:boolean-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (114,1,-1,null,null,null,1,0,'boolean-bag','urn:oasis:names:tc:xacml:1.0:function:boolean-bag',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (115,1,1,null,null,null,0,0,'time-one-and-only','urn:oasis:names:tc:xacml:1.0:function:time-one-and-only',16); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (116,1,1,null,null,null,0,0,'time-bag-size','urn:oasis:names:tc:xacml:1.0:function:time-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (117,2,2,null,null,null,0,0,'time-is-in','urn:oasis:names:tc:xacml:1.0:function:time-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (118,1,-1,null,null,null,1,0,'time-bag','urn:oasis:names:tc:xacml:1.0:function:time-bag',16); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (119,1,1,null,null,null,0,0,'date-one-and-only','urn:oasis:names:tc:xacml:1.0:function:date-one-and-only',21); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (120,1,1,null,null,null,0,0,'date-bag-size','urn:oasis:names:tc:xacml:1.0:function:date-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (121,2,2,null,null,null,0,0,'date-is-in','urn:oasis:names:tc:xacml:1.0:function:date-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (122,1,-1,null,null,null,1,0,'date-bag','urn:oasis:names:tc:xacml:1.0:function:date-bag',21); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (123,1,1,null,null,null,0,0,'dateTime-one-and-only','urn:oasis:names:tc:xacml:1.0:function:dateTime-one-and-only',19); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (124,1,1,null,null,null,0,0,'dateTime-bag-size','urn:oasis:names:tc:xacml:1.0:function:dateTime-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (125,2,2,null,null,null,0,0,'dateTime-is-in','urn:oasis:names:tc:xacml:1.0:function:dateTime-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (126,1,-1,null,null,null,1,0,'dateTime-bag','urn:oasis:names:tc:xacml:1.0:function:dateTime-bag',19); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (127,1,1,null,null,null,0,0,'anyURI-one-and-only','urn:oasis:names:tc:xacml:1.0:function:anyURI-one-and-only',27); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (128,1,1,null,null,null,0,0,'anyURI-bag-size','urn:oasis:names:tc:xacml:1.0:function:anyURI-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (129,2,2,null,null,null,0,0,'anyURI-is-in','urn:oasis:names:tc:xacml:1.0:function:anyURI-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (130,1,-1,null,null,null,1,0,'anyURI-bag','urn:oasis:names:tc:xacml:1.0:function:anyURI-bag',27); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (131,1,1,null,null,null,0,0,'hexBinary-one-and-only','urn:oasis:names:tc:xacml:1.0:function:hexBinary-one-and-only',24); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (132,1,1,null,null,null,0,0,'hexBinary-bag-size','urn:oasis:names:tc:xacml:1.0:function:hexBinary-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (133,2,2,null,null,null,0,0,'hexBinary-is-in','urn:oasis:names:tc:xacml:1.0:function:hexBinary-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (134,1,-1,null,null,null,1,0,'hexBinary-bag','urn:oasis:names:tc:xacml:1.0:function:hexBinary-bag',24); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (135,1,1,null,null,null,0,0,'base64Binary-one-and-only','urn:oasis:names:tc:xacml:1.0:function:base64Binary-one-and-only',13); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (136,1,1,null,null,null,0,0,'base64Binary-bag-size','urn:oasis:names:tc:xacml:1.0:function:base64Binary-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (137,2,2,null,null,null,0,0,'base64Binary-is-in','urn:oasis:names:tc:xacml:1.0:function:base64Binary-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (138,1,-1,null,null,null,1,0,'base64Binary-bag','urn:oasis:names:tc:xacml:1.0:function:base64Binary-bag',13); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (139,1,1,null,null,null,0,0,'dayTimeDuration-one-and-only','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-one-and-only',15); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (140,1,1,null,null,null,0,0,'dayTimeDuration-bag-size','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (141,2,2,null,null,null,0,0,'dayTimeDuration-is-in','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (142,1,-1,null,null,null,1,0,'dayTimeDuration-bag','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-bag',15); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (143,1,1,null,null,null,0,0,'yearMonthDuration-one-and-only','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-one-and-only',23); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (144,1,1,null,null,null,0,0,'yearMonthDuration-bag-size','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (145,2,2,null,null,null,0,0,'yearMonthDuration-is-in','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (146,1,-1,null,null,null,1,0,'yearMonthDuration-bag','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-bag',23); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (147,1,1,null,null,null,0,0,'x500Name-one-and-only','urn:oasis:names:tc:xacml:1.0:function:x500Name-one-and-only',14); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (148,1,1,null,null,null,0,0,'x500Name-bag-size','urn:oasis:names:tc:xacml:1.0:function:x500Name-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (149,2,2,null,null,null,0,0,'x500Name-is-in','urn:oasis:names:tc:xacml:1.0:function:x500Name-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (150,1,-1,null,null,null,1,0,'x500Name-bag','urn:oasis:names:tc:xacml:1.0:function:x500Name-bag',14); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (151,1,1,null,null,null,0,0,'rfc822Name-one-and-only','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-one-and-only',20); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (152,1,1,null,null,null,0,0,'rfc822Name-bag-size','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (153,2,2,null,null,null,0,0,'rfc822Name-is-in','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (154,1,-1,null,null,null,1,0,'rfc822Name-bag','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-bag',20); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (155,1,1,null,null,null,0,0,'ipAddress-one-and-only','urn:oasis:names:tc:xacml:2.0:function:ipAddress-one-and-only',22); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (156,1,1,null,null,null,0,0,'ipAddress-bag-size','urn:oasis:names:tc:xacml:2.0:function:ipAddress-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (157,2,2,null,null,null,0,0,'ipAddress-is-in','urn:oasis:names:tc:xacml:2.0:function:ipAddress-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (158,1,-1,null,null,null,1,0,'ipAddress-bag','urn:oasis:names:tc:xacml:2.0:function:ipAddress-bag',22); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (159,1,1,null,null,null,0,0,'dnsName-one-and-only','urn:oasis:names:tc:xacml:2.0:function:dnsName-one-and-only',17); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (160,1,1,null,null,null,0,0,'dnsName-bag-size','urn:oasis:names:tc:xacml:2.0:function:dnsName-bag-size',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (161,2,2,null,null,null,0,0,'dnsName-is-in','urn:oasis:names:tc:xacml:2.0:function:dnsName-is-in',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (162,1,-1,null,null,null,1,0,'dnsName-bag','urn:oasis:names:tc:xacml:2.0:function:dnsName-bag',17); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (163,2,2,null,null,null,0,0,'string-regexp-match','urn:oasis:names:tc:xacml:1.0:function:string-regexp-match',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (164,2,2,null,null,null,0,0,'anyURI-regexp-match','urn:oasis:names:tc:xacml:2.0:function:anyURI-regexp-match',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (165,2,2,null,null,null,0,0,'ipAddress-regexp-match','urn:oasis:names:tc:xacml:2.0:function:ipAddress-regexp-match',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (166,2,2,null,null,null,0,0,'dnsName-regexp-match','urn:oasis:names:tc:xacml:2.0:function:dnsName-regexp-match',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (167,2,2,null,null,null,0,0,'rfc822Name-regexp-match','urn:oasis:names:tc:xacml:2.0:function:rfc822Name-regexp-match',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (168,2,2,null,null,null,0,0,'x500Name-regexp-match','urn:oasis:names:tc:xacml:2.0:function:x500Name-regexp-match',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (169,2,2,null,null,null,1,0,'string-intersection','urn:oasis:names:tc:xacml:1.0:function:string-intersection',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (170,2,2,null,null,null,0,0,'string-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (171,2,-1,null,null,null,1,0,'string-union','urn:oasis:names:tc:xacml:1.0:function:string-union',26); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (172,2,2,null,null,null,0,0,'string-subset','urn:oasis:names:tc:xacml:1.0:function:string-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (173,2,2,null,null,null,0,0,'string-set-equals','urn:oasis:names:tc:xacml:1.0:function:string-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (174,2,2,null,null,null,0,0,'integer-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:integer-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (175,2,-1,null,null,null,1,0,'integer-union','urn:oasis:names:tc:xacml:1.0:function:integer-union',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (176,2,2,null,null,null,0,0,'integer-subset','urn:oasis:names:tc:xacml:1.0:function:integer-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (177,2,2,null,null,null,0,0,'integer-set-equals','urn:oasis:names:tc:xacml:1.0:function:integer-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (178,2,2,null,null,null,0,0,'double-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:double-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (179,2,-1,null,null,null,1,0,'double-union','urn:oasis:names:tc:xacml:1.0:function:double-union',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (180,2,2,null,null,null,0,0,'double-subset','urn:oasis:names:tc:xacml:1.0:function:double-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (181,2,2,null,null,null,0,0,'double-set-equals','urn:oasis:names:tc:xacml:1.0:function:double-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (182,2,2,null,null,null,1,0,'boolean-intersection','urn:oasis:names:tc:xacml:1.0:function:boolean-intersection',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (183,2,2,null,null,null,0,0,'boolean-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:boolean-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (184,2,-1,null,null,null,1,0,'boolean-union','urn:oasis:names:tc:xacml:1.0:function:boolean-union',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (185,2,2,null,null,null,0,0,'boolean-subset','urn:oasis:names:tc:xacml:1.0:function:boolean-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (186,2,2,null,null,null,0,0,'boolean-set-equals','urn:oasis:names:tc:xacml:1.0:function:boolean-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (187,2,2,null,null,null,1,0,'time-intersection','urn:oasis:names:tc:xacml:1.0:function:time-intersection',16); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (188,2,2,null,null,null,0,0,'time-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:time-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (189,2,-1,null,null,null,1,0,'time-union','urn:oasis:names:tc:xacml:1.0:function:time-union',16); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (190,2,2,null,null,null,0,0,'time-subset','urn:oasis:names:tc:xacml:1.0:function:time-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (191,2,2,null,null,null,0,0,'time-set-equals','urn:oasis:names:tc:xacml:1.0:function:time-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (192,2,2,null,null,null,1,0,'date-intersection','urn:oasis:names:tc:xacml:1.0:function:date-intersection',21); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (193,2,2,null,null,null,0,0,'date-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:date-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (194,2,-1,null,null,null,1,0,'date-union','urn:oasis:names:tc:xacml:1.0:function:date-union',21); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (195,2,2,null,null,null,0,0,'date-subset','urn:oasis:names:tc:xacml:1.0:function:date-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (196,2,2,null,null,null,0,0,'date-set-equals','urn:oasis:names:tc:xacml:1.0:function:date-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (197,2,2,null,null,null,1,0,'dateTime-intersection','urn:oasis:names:tc:xacml:1.0:function:dateTime-intersection',19); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (198,2,2,null,null,null,0,0,'dateTime-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:dateTime-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (199,2,-1,null,null,null,1,0,'dateTime-union','urn:oasis:names:tc:xacml:1.0:function:dateTime-union',19); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (200,2,2,null,null,null,0,0,'dateTime-subset','urn:oasis:names:tc:xacml:1.0:function:dateTime-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (201,2,2,null,null,null,0,0,'dateTime-set-equals','urn:oasis:names:tc:xacml:1.0:function:dateTime-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (202,2,2,null,null,null,1,0,'anyURI-intersection','urn:oasis:names:tc:xacml:1.0:function:anyURI-intersection',27); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (203,2,2,null,null,null,0,0,'anyURI-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:anyURI-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (204,2,-1,null,null,null,1,0,'anyURI-union','urn:oasis:names:tc:xacml:1.0:function:anyURI-union',27); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (205,2,2,null,null,null,0,0,'anyURI-subset','urn:oasis:names:tc:xacml:1.0:function:anyURI-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (206,2,2,null,null,null,0,0,'anyURI-set-equals','urn:oasis:names:tc:xacml:1.0:function:anyURI-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (207,2,2,null,null,null,1,0,'hexBinary-intersection','urn:oasis:names:tc:xacml:1.0:function:hexBinary-intersection',24); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (208,2,2,null,null,null,0,0,'hexBinary-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:hexBinary-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (209,2,-1,null,null,null,1,0,'hexBinary-union','urn:oasis:names:tc:xacml:1.0:function:hexBinary-union',24); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (210,2,2,null,null,null,0,0,'hexBinary-subset','urn:oasis:names:tc:xacml:1.0:function:hexBinary-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (211,2,2,null,null,null,0,0,'hexBinary-set-equals','urn:oasis:names:tc:xacml:1.0:function:hexBinary-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (212,2,2,null,null,null,1,0,'base64Binary-intersection','urn:oasis:names:tc:xacml:1.0:function:base64Binary-intersection',13); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (213,2,2,null,null,null,0,0,'base64Binary-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:base64Binary-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (214,2,-1,null,null,null,1,0,'base64Binary-union','urn:oasis:names:tc:xacml:1.0:function:base64Binary-union',13); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (215,2,2,null,null,null,0,0,'base64Binary-subset','urn:oasis:names:tc:xacml:1.0:function:base64Binary-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (216,2,2,null,null,null,0,0,'base64Binary-set-equals','urn:oasis:names:tc:xacml:1.0:function:base64Binary-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (217,2,2,null,null,null,1,0,'dayTimeDuration-intersection','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-intersection',15); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (218,2,2,null,null,null,0,0,'dayTimeDuration-at-least-one-member-of','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (219,2,-1,null,null,null,1,0,'dayTimeDuration-union','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-union',15); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (220,2,2,null,null,null,0,0,'dayTimeDuration-subset','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (221,2,2,null,null,null,0,0,'dayTimeDuration-set-equals','urn:oasis:names:tc:xacml:3.0:function:dayTimeDuration-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (222,2,2,null,null,null,1,0,'yearMonthDuration-intersection','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-intersection',23); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (223,2,2,null,null,null,0,0,'yearMonthDuration-at-least-one-member-of','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (224,2,-1,null,null,null,1,0,'yearMonthDuration-union','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-union',23); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (225,2,2,null,null,null,0,0,'yearMonthDuration-subset','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (226,2,2,null,null,null,0,0,'yearMonthDuration-set-equals','urn:oasis:names:tc:xacml:3.0:function:yearMonthDuration-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (227,2,2,null,null,null,1,0,'x500Name-intersection','urn:oasis:names:tc:xacml:1.0:function:x500Name-intersection',14); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (228,2,2,null,null,null,0,0,'x500Name-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:x500Name-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (229,2,-1,null,null,null,1,0,'x500Name-union','urn:oasis:names:tc:xacml:1.0:function:x500Name-union',14); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (230,2,2,null,null,null,0,0,'x500Name-subset','urn:oasis:names:tc:xacml:1.0:function:x500Name-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (231,2,2,null,null,null,0,0,'x500Name-set-equals','urn:oasis:names:tc:xacml:1.0:function:x500Name-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (232,2,2,null,null,null,1,0,'rfc822Name-intersection','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-intersection',20); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (233,2,2,null,null,null,0,0,'rfc822Name-at-least-one-member-of','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-at-least-one-member-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (234,2,-1,null,null,null,1,0,'rfc822Name-union','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-union',20); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (235,2,2,null,null,null,0,0,'rfc822Name-subset','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-subset',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (236,2,2,null,null,null,0,0,'rfc822Name-set-equals','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-set-equals',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (237,2,2,null,null,null,0,0,'x500Name-match','urn:oasis:names:tc:xacml:1.0:function:x500Name-match',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (238,2,2,null,null,null,0,0,'rfc822Name-match','urn:oasis:names:tc:xacml:1.0:function:rfc822Name-match',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (239,2,2,null,null,null,1,0,'integer-intersection','urn:oasis:names:tc:xacml:1.0:function:integer-intersection',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (240,2,2,null,null,null,1,0,'double-intersection','urn:oasis:names:tc:xacml:1.0:function:double-intersection',25); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (241,0,-1,null,null,null,0,0,'or','urn:oasis:names:tc:xacml:1.0:function:or',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (242,0,-1,null,null,null,0,0,'and','urn:oasis:names:tc:xacml:1.0:function:and',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (243,2,-1,null,null,null,0,0,'n-of','urn:oasis:names:tc:xacml:1.0:function:n-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (244,1,1,null,null,null,0,0,'not','urn:oasis:names:tc:xacml:1.0:function:not',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (245,2,-1,1,-1,'1',0,1,'any-of','urn:oasis:names:tc:xacml:3.0:function:any-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (246,2,-1,1,-1,'1',0,1,'all-of','urn:oasis:names:tc:xacml:3.0:function:all-of',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (247,2,-1,1,-1,'0',0,1,'any-of-any','urn:oasis:names:tc:xacml:3.0:function:any-of-any',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (248,3,3,2,2,'1',0,1,'all-of-any','urn:oasis:names:tc:xacml:1.0:function:all-of-any',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (249,3,3,2,2,'1',0,1,'any-of-all','urn:oasis:names:tc:xacml:1.0:function:any-of-all',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (250,3,3,2,2,'1',0,1,'all-of-all','urn:oasis:names:tc:xacml:1.0:function:all-of-all',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (251,2,-1,1,-1,'1',1,1,'map','urn:oasis:names:tc:xacml:3.0:function:map',null); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (252,1,1,null,null,null,0,0,'xpath-node-count','urn:oasis:names:tc:xacml:3.0:function:xpath-node-count',12); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (253,2,2,null,null,null,0,0,'xpath-node-equal','urn:oasis:names:tc:xacml:3.0:function:xpath-node-equal',18); +INSERT INTO XACML.FUNCTIONDEFINITION (ID,ARG_LB,ARG_UB,HO_ARG_LB,HO_ARG_UB,HO_PRIMITIVE,IS_BAG_RETURN,IS_HIGHER_ORDER,SHORT_NAME,XACML_ID,RETURN_DATATYPE) VALUES (254,2,2,null,null,null,0,0,'xpath-node-match','urn:oasis:names:tc:xacml:3.0:function:xpath-node-match',18); + + +INSERT INTO XACML.GLOBALROLESETTINGS (ROLE,LOCKDOWN) VALUES ('super-admin',0); + + +INSERT INTO XACML.PIPCONFIGPARAMS (ID,PARAM_DEFAULT,PARAM_NAME,PARAM_VALUE,REQUIRED,PIP_ID) VALUES (1711,null,'type','jdbc','0',1709); +INSERT INTO XACML.PIPCONFIGPARAMS (ID,PARAM_DEFAULT,PARAM_NAME,PARAM_VALUE,REQUIRED,PIP_ID) VALUES (1712,null,'jdbc.url','jdbc:h2:file:/','0',1709); +INSERT INTO XACML.PIPCONFIGPARAMS (ID,PARAM_DEFAULT,PARAM_NAME,PARAM_VALUE,REQUIRED,PIP_ID) VALUES (1713,null,'jdbc.driver','org.h2.Driver','0',1709); +INSERT INTO XACML.PIPCONFIGPARAMS (ID,PARAM_DEFAULT,PARAM_NAME,PARAM_VALUE,REQUIRED,PIP_ID) VALUES (1714,null,'jdbc.conn.password','smil3yfc','0',1709); + + + + + + + + +INSERT INTO XACML.PIPTYPE (ID,TYPE) VALUES (500,'SQL'); +INSERT INTO XACML.PIPTYPE (ID,TYPE) VALUES (501,'LDAP'); +INSERT INTO XACML.PIPTYPE (ID,TYPE) VALUES (502,'CSV'); +INSERT INTO XACML.PIPTYPE (ID,TYPE) VALUES (503,'Hyper-CSV'); +INSERT INTO XACML.PIPTYPE (ID,TYPE) VALUES (504,'Custom'); + + +INSERT INTO XACML.POLICYALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (29,'S','ordered-deny-overrides','urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:ordered-deny-overrides'); +INSERT INTO XACML.POLICYALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (30,'S','on-permit-apply-second','urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:on-permit-apply-second'); +INSERT INTO XACML.POLICYALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (31,'S','deny-overrides','urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:deny-overrides'); +INSERT INTO XACML.POLICYALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (32,'S','permit-unless-deny','urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:permit-unless-deny'); +INSERT INTO XACML.POLICYALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (33,'S','deny-unless-permit','urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:deny-unless-permit'); +INSERT INTO XACML.POLICYALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (34,'S','permit-overrides','urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:permit-overrides'); +INSERT INTO XACML.POLICYALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (35,'S','only-one-applicable','urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:only-one-applicable'); +INSERT INTO XACML.POLICYALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (36,'S','first-applicable','urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:first-applicable'); +INSERT INTO XACML.POLICYALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (37,'S','ordered-permit-overrides','urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:ordered-permit-overrides'); + + + + + + +INSERT INTO XACML.RULEALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (38,'S','permit-unless-deny','urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny'); +INSERT INTO XACML.RULEALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (39,'S','permit-overrides','urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides'); +INSERT INTO XACML.RULEALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (40,'S','deny-overrides','urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides'); +INSERT INTO XACML.RULEALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (41,'S','ordered-permit-overrides','urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:ordered-permit-overrides'); +INSERT INTO XACML.RULEALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (42,'S','deny-unless-permit','urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-unless-permit'); +INSERT INTO XACML.RULEALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (43,'S','ordered-deny-overrides','urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:ordered-deny-overrides'); +INSERT INTO XACML.RULEALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (44,'S','only-one-applicable','urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:only-one-applicable'); +INSERT INTO XACML.RULEALGORITHMS (ID,IS_STANDARD,SHORT_NAME,XACML_ID) VALUES (45,'S','first-applicable','urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable'); + + +INSERT INTO XACML.SEQUENCE (SEQ_NAME,SEQ_COUNT) VALUES ('SEQ_GEN',3050); + + + +ALTER TABLE XACML.AttributeAssignment ADD CONSTRAINT FK_AttributeAssignment_OBADVICE_id +FOREIGN KEY (OBADVICE_id) REFERENCES XACML.Obadvice (id); +ALTER TABLE XACML.PIPResolverParams ADD CONSTRAINT FK_PIPResolverParams_ID_RESOLVER +FOREIGN KEY (ID_RESOLVER) REFERENCES XACML.PIPResolver (id); +ALTER TABLE XACML.Attribute ADD CONSTRAINT FK_Attribute_category +FOREIGN KEY (category) REFERENCES XACML.Category (id); +ALTER TABLE XACML.Attribute ADD CONSTRAINT FK_Attribute_constraint_type +FOREIGN KEY (constraint_type) REFERENCES XACML.ConstraintType (id); +ALTER TABLE XACML.Attribute ADD CONSTRAINT FK_Attribute_datatype +FOREIGN KEY (datatype) REFERENCES XACML.Datatype (id); +ALTER TABLE XACML.FunctionArguments ADD CONSTRAINT FK_FunctionArguments_function_id +FOREIGN KEY (function_id) REFERENCES XACML.FunctionDefinition (id); +ALTER TABLE XACML.FunctionArguments ADD CONSTRAINT FK_FunctionArguments_datatype_id +FOREIGN KEY (datatype_id) REFERENCES XACML.Datatype (id); +ALTER TABLE XACML.ObadviceExpressions ADD CONSTRAINT FK_ObadviceExpressions_obadvice_id +FOREIGN KEY (obadvice_id) REFERENCES XACML.Obadvice (id); +ALTER TABLE XACML.ObadviceExpressions ADD CONSTRAINT FK_ObadviceExpressions_attribute_id +FOREIGN KEY (attribute_id) REFERENCES XACML.Attribute (id); +ALTER TABLE XACML.ConstraintValues ADD CONSTRAINT FK_ConstraintValues_attribute_id +FOREIGN KEY (attribute_id) REFERENCES XACML.Attribute (id); +ALTER TABLE XACML.DecisionSettings ADD CONSTRAINT FK_DecisionSettings_datatype +FOREIGN KEY (datatype) REFERENCES XACML.Datatype (id); +ALTER TABLE XACML.PIPConfiguration ADD CONSTRAINT FK_PIPConfiguration_TYPE +FOREIGN KEY (TYPE) REFERENCES XACML.PIPType (id); + +ALTER TABLE FunctionDefinition ADD CONSTRAINT FK_FunctionDefinition_return_datatype +FOREIGN KEY (return_datatype) REFERENCES XACML.Datatype (id); +ALTER TABLE PIPResolver ADD CONSTRAINT FK_PIPResolver_PIP_ID +FOREIGN KEY (PIP_ID) REFERENCES XACML.PIPConfiguration (id); +ALTER TABLE PIPConfigParams ADD CONSTRAINT FK_PIPConfigParams_PIP_ID +FOREIGN KEY (PIP_ID) REFERENCES XACML.PIPConfiguration (id); + +ALTER TABLE XACML.PolicyEntity ADD CONSTRAINT UNQ_PolicyEntity_0 UNIQUE (policyName, scope, deleted); +ALTER TABLE XACML.PolicyEntity ADD CONSTRAINT FK_PolicyEntity_configurationDataId FOREIGN KEY (configurationDataId) + REFERENCES XACML.ConfigurationDataEntity (configurationDataId); diff --git a/packages/base/src/files/install/mysql/data/151001_downgrade_script.sql b/packages/base/src/files/install/mysql/data/151001_downgrade_script.sql new file mode 100644 index 00000000..06cf389a --- /dev/null +++ b/packages/base/src/files/install/mysql/data/151001_downgrade_script.sql @@ -0,0 +1,248 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +SET FOREIGN_KEY_CHECKS=0; +DROP TABLE IF EXISTS XACML.ENFORCINGTYPE; +DROP TABLE IF EXISTS XACML.ACTIONPOLICYDICT; +DROP TABLE IF EXISTS XACML.TERM; +DROP TABLE IF EXISTS XACML.PROTOCOLLIST; +DROP TABLE IF EXISTS XACML.PORTLIST; +DROP TABLE IF EXISTS XACML.PREFIXLIST; +DROP TABLE IF EXISTS XACML.ADDRESSGROUP; +DROP TABLE IF EXISTS XACML.POLICYSCORE; +DROP TABLE IF EXISTS XACML.VSCLACTION; +DROP TABLE IF EXISTS XACML.VNFTYPE; +DROP TABLE IF EXISTS XACML.ATTRIBUTE; +DROP TABLE IF EXISTS XACML.DECISIONSETTINGS; +DROP TABLE IF EXISTS XACML.POLICY_MANAGEMENT; +DROP TABLE IF EXISTS XACML.SCOPES; + +DROP TABLE IF EXISTS XACML.SERVICEGROUP; +CREATE TABLE XACML.SERVICEGROUP +( +id integer NOT NULL, +name varchar(32), +type varchar(16), +transportprotocol varchar(255), +appprotocol varchar(255), +ports varchar(255), +`desc` varchar(255), +primary key(id) +) +; + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.SERVICEGROUP TO POLICY_USER; + + +DROP TABLE IF EXISTS XACML.EnforcingType; +CREATE TABLE XACML.EnforcingType +( +id INTEGER NOT NULL, + connectionQuery VARCHAR(255) NOT NULL, + enforcingType VARCHAR(255) NOT NULL UNIQUE, + script VARCHAR(255) NOT NULL, + valueQuery VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.ActionPolicyDict; +CREATE TABLE XACML.ActionPolicyDict +( +id INTEGER NOT NULL, + ATTRIBUTE_NAME VARCHAR(45) NOT NULL, + Body VARCHAR(4096), + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + description VARCHAR(2048), + Headers VARCHAR(1024), + Method VARCHAR(45) NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + Type VARCHAR(45) NOT NULL, + URL VARCHAR(45) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.TERM; +CREATE TABLE XACML.TERM +( +id INTEGER NOT NULL, + description VARCHAR(100), + action VARCHAR(100), + destIPList VARCHAR(100), + destPortList VARCHAR(100), + portList VARCHAR(100), + protocolList VARCHAR(100), + srcIPList VARCHAR(100), + srcPortList VARCHAR(100), + termName VARCHAR(45) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.PROTOCOLLIST; +CREATE TABLE XACML.PROTOCOLLIST +( +id INTEGER NOT NULL, + description VARCHAR(64), + protocolname VARCHAR(45) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.PORTLIST; +CREATE TABLE XACML.PORTLIST +( +id INTEGER NOT NULL, + description VARCHAR(64), + portname VARCHAR(45) NOT NULL, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.PREFIXLIST; +CREATE TABLE XACML.PREFIXLIST +( +id INTEGER NOT NULL, + pl_name VARCHAR(45) NOT NULL, + pl_value VARCHAR(64) NOT NULL, + description VARCHAR(255), + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.ADDRESSGROUP; +CREATE TABLE ADDRESSGROUP +( + id INTEGER NOT NULL, + name varchar(32), + description VARCHAR(64), + prefixlist varchar(255) +); + +CREATE INDEX idx_addressgroup on XACML.ADDRESSGROUP(ID); + +DROP TABLE IF EXISTS XACML.POLICYSCORE; +CREATE TABLE XACML.POLICYSCORE +( +POLICY_NAME VARCHAR(200) NOT NULL, + POLICY_SCORE VARCHAR(100), + PRIMARY KEY (POLICY_NAME) +) +; + +CREATE TABLE XACML.VSCLACTION +( +ID INTEGER NOT NULL, +VSCL_ACTION VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +CREATE TABLE XACML.VNFTYPE +( +ID INTEGER NOT NULL, +VNF_TYPE VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +) +; + +DROP TABLE IF EXISTS XACML.ATTRIBUTE; +CREATE TABLE XACML.ATTRIBUTE +( +id INTEGER NOT NULL, + ATTRIBUTE_VALUE VARCHAR(255), + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + description VARCHAR(2048), + is_designator CHAR NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + PRIORITY VARCHAR(45), + selector_path VARCHAR(2048), + xacml_id VARCHAR(100) NOT NULL UNIQUE, + category INTEGER, + constraint_type INTEGER, + datatype INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.DECISIONSETTINGS; +CREATE TABLE XACML.DECISIONSETTINGS +( +id INTEGER NOT NULL, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + description VARCHAR(2048), + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + PRIORITY VARCHAR(45), + xacml_id VARCHAR(45) NOT NULL UNIQUE, + datatype INTEGER, + PRIMARY KEY (id) +) +; + +DROP TABLE IF EXISTS XACML.POLICY_MANANGEMENT; +CREATE TABLE XACML.POLICY_MANANGEMENT +( +id INTEGER NOT NULL, + CONFIG_NAME VARCHAR(45) NOT NULL, + CREATE_DATE_TIME TIMESTAMP NOT NULL, + CREATED_BY VARCHAR(45) NOT NULL, + ECOMP_NAME VARCHAR(45) NOT NULL, + POLICY_NAME VARCHAR(45) NOT NULL, + scope VARCHAR(45) NOT NULL, + UPDATE_DATE_TIME TIMESTAMP NOT NULL, + UPDATED_BY VARCHAR(45) NOT NULL, + XML text NOT NULL, + PRIMARY KEY (id) +) +; + +GRANT INSERT, UPDATE, DELETE, SELECT XACML.ENFORCINGTYPE; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.ACTIONPOLICYDICT; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.TERM; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.PROTOCOLLIST; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.PORTLIST; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.PREFIXLIST; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.ADDRESSGROUP; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.POLICYSCORE; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.VSCLACTION; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.VNFTYPE; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.ATTRIBUTE; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.DECISIONSETTINGS; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.POLICY_MANAGEMENT; +GRANT INSERT, UPDATE, DELETE, SELECT XACML.SCOPES; + + +set foreign_key_checks=1; diff --git a/packages/base/src/files/install/mysql/data/151001_upgrade_script.sql b/packages/base/src/files/install/mysql/data/151001_upgrade_script.sql new file mode 100644 index 00000000..9708fd42 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/151001_upgrade_script.sql @@ -0,0 +1,246 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +set foreign_key_checks=0; +DROP TABLE IF EXISTS XACML.SERVICEGROUP; +CREATE TABLE XACML.SERVICEGROUP +( +id integer NOT NULL, +name varchar(32), +type varchar(16), +transportprotocol varchar(255), +appprotocol varchar(255), +ports varchar(255), +description varchar(255), +primary key(id) +) +; + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.SERVICEGROUP TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.ENFORCINGTYPE; +CREATE TABLE XACML.ENFORCINGTYPE +( +ID INTEGER NOT NULL, +ENFORCINGTYPE VARCHAR(255) NOT NULL, +SCRIPT VARCHAR(5000) NOT NULL, +CONNECTIONQUERY VARCHAR(1000) NOT NULL, +VALUEQUERY VARCHAR(1000) NOT NULL, +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.ENFORCINGTYPE TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.ACTIONPOLICYDICT; +CREATE TABLE XACML.ACTIONPOLICYDICT +( +ID INTEGER NOT NULL, +TYPE VARCHAR(45) NOT NULL, +URL VARCHAR(45) NOT NULL, +METHOD VARCHAR(45) NOT NULL, +HEADERS VARCHAR(1024) NOT NULL, +BODY VARCHAR(4096) NOT NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +ATTRIBUTE_NAME VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(1024), +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.ACTIONPOLICYDICT TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.TERM; +CREATE TABLE XACML.TERM +( +ID INTEGER NOT NULL, +TERMNAME VARCHAR(45) NOT NULL, +SRCIPLIST VARCHAR(100), +DESTIPLIST VARCHAR(100), +PROTOCOLLIST VARCHAR(100), +PORTLIST VARCHAR(100), +SRCPORTLIST VARCHAR(100), +DESTPORTLIST VARCHAR(100), +ACTION VARCHAR(100), +DESCRIPTION VARCHAR(100), +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.TERM TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.PROTOCOLLIST; +CREATE TABLE XACML.PROTOCOLLIST +( +ID INTEGER NOT NULL, +PROTOCOLNAME VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(64), +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.PROTOCOLLIST TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.PORTLIST; +CREATE TABLE XACML.PORTLIST +( +ID INTEGER NOT NULL, +PORTNAME VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(64), +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.PORTLIST TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.PREFIXLIST; +CREATE TABLE XACML.PREFIXLIST +( +ID INTEGER NOT NULL, +PL_NAME VARCHAR(45) NOT NULL, +PL_VALUE VARCHAR(64), +DESCRIPTION VARCHAR(255) NULL, +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.PREFIXLIST TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.ADDRESSGROUP; +CREATE TABLE XACML.ADDRESSGROUP +( + ID INTEGER NOT NULL, + NAME VARCHAR(32), + DESCRIPTION VARCHAR(64), + PREFIXLIST VARCHAR(255), + PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.ADDRESSGROUP TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.POLICYSCORE; +CREATE TABLE XACML.POLICYSCORE +( +POLICY_NAME VARCHAR(100) NOT NULL, +POLICY_SCORE VARCHAR(100), +PRIMARY KEY(POLICY_NAME) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.POLICYSCORE TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.VSCLACTION; +CREATE TABLE XACML.VSCLACTION +( +ID INTEGER NOT NULL, +VSCL_ACTION VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.VSCLACTION TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.VNFTYPE; +CREATE TABLE XACML.VNFTYPE +( +ID INTEGER NOT NULL, +VNF_TYPE VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.VNFTYPE TO POLICY_USER; + +SET FOREIGN_KEY_CHECKS=0; + +DROP TABLE IF EXISTS XACML.ATTRIBUTE; +CREATE TABLE XACML.ATTRIBUTE +( +ID INTEGER NOT NULL, +CREATED_BY VARCHAR(255) NOT NULL, +CREATED_DATE TIMESTAMP, +DESCRIPTION VARCHAR(2048), +IS_DESIGNATOR CHAR(1) NOT NULL, +MODIFIED_BY VARCHAR(255) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +SELECTOR_PATH VARCHAR(2048), +XACML_ID VARCHAR(500) NOT NULL, +CATEGORY INTEGER, +CONSTRAINT_TYPE INTEGER, +DATATYPE INTEGER, +PRIORITY VARCHAR(45), +ATTRIBUTE_VALUE VARCHAR(45), +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.ATTRIBUTE TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.DECISIONSETTINGS; +CREATE TABLE XACML.DECISIONSETTINGS +( + ID INTEGER NOT NULL, + XACML_ID VARCHAR(45) NOT NULL, + DESCRIPTION VARCHAR(45), + DATATYPE VARCHAR(45) NOT NULL, + CREATED_BY VARCHAR(45) NOT NULL, + MODIFIED_DATE TIMESTAMP NOT NULL, + MODIFIED_BY VARCHAR(45) NOT NULL, + PRIORITY VARCHAR(45), + CREATED_DATE TIMESTAMP NOT NULL, + PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.DECISIONSETTINGS TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.POLICY_MANAGEMENT; +CREATE TABLE XACML.POLICY_MANAGEMENT +( + ID INTEGER NOT NULL, + CONFIG_NAME VARCHAR(45) NOT NULL, + CREATE_DATE_TIME TIMESTAMP, + CREATED_BY VARCHAR(45) NOT NULL, + ECOMP_NAME VARCHAR(45) NOT NULL, + POLICY_NAME VARCHAR(45) NOT NULL, + SCOPE VARCHAR(45) NOT NULL, + UPDATE_DATE_TIME TIMESTAMP NOT NULL, + UPDATED_BY VARCHAR(45) NOT NULL, + XML TEXT NOT NULL, + PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.POLICY_MANAGEMENT TO POLICY_USER; + +DROP TABLE IF EXISTS XACML.SCOPES; +CREATE TABLE XACML.SCOPES +( + ID INTEGER NOT NULL, + SCOPE VARCHAR(45) NOT NULL, + PARENT_SCOPE INTEGER, + PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.SCOPES TO POLICY_USER; + + +set foreign_key_checks=1; diff --git a/packages/base/src/files/install/mysql/data/151002_downgrade_script.sql b/packages/base/src/files/install/mysql/data/151002_downgrade_script.sql new file mode 100644 index 00000000..66cdf302 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/151002_downgrade_script.sql @@ -0,0 +1,21 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +REVOKE INSERT, UPDATE, DELETE, SELECT ON XACML.SECURITYZONE from policy_user; diff --git a/packages/base/src/files/install/mysql/data/151002_upgrade_script.sql b/packages/base/src/files/install/mysql/data/151002_upgrade_script.sql new file mode 100644 index 00000000..3b4d27e4 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/151002_upgrade_script.sql @@ -0,0 +1,21 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.SECURITYZONE TO policy_user; diff --git a/packages/base/src/files/install/mysql/data/151200_downgrade_script.sql b/packages/base/src/files/install/mysql/data/151200_downgrade_script.sql new file mode 100644 index 00000000..a3147223 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/151200_downgrade_script.sql @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +set foreign_key_checks=0; + +DROP TABLE IF EXISTS xacml.PolicyEntity; +DROP TABLE IF EXISTS xacml.ConfigurationDataEntity; +DROP TABLE IF EXISTS xacml.PolicyDBDaoEntity; +DROP TABLE IF EXISTS xacml.GroupEntity; +DROP TABLE IF EXISTS xacml.PdpEntity; +DROP TABLE IF EXISTS xacml.ActionBodyEntity; +DROP TABLE IF EXISTS xacml.DatabaseLockEntity; +DROP TABLE IF EXISTS xacml.PolicyGroupEntity; + +ALTER TABLE XACML.TERM DROP COLUMN FROMZONE; +ALTER TABLE XACML.TERM DROP COLUMN TOZONE; + +ALTER TABLE XACML.ACTIONPOLICYDICT DROP INDEX ACTIONPOLICYDICT_UNIQUE; + +DROP TABLE IF EXISTS XACML.ZONE; + +DROP TABLE IF EXISTS XACML.POLICYVERSION; + +ALTER TABLE XACML.VSCLACTION DROP INDEX VSCLACTION_VSCL_ACTION_UNIQUE; + +set foreign_key_checks=1; diff --git a/packages/base/src/files/install/mysql/data/151200_upgrade_script.sql b/packages/base/src/files/install/mysql/data/151200_upgrade_script.sql new file mode 100644 index 00000000..ecb23da0 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/151200_upgrade_script.sql @@ -0,0 +1,226 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +set foreign_key_checks=0; + +DROP TABLE IF EXISTS xacml.PolicyEntity; +CREATE TABLE xacml.PolicyEntity +( +policyId BIGINT NOT NULL AUTO_INCREMENT, +created_by VARCHAR(255) NOT NULL, +created_date TIMESTAMP, +deleted BOOLEAN NOT NULL, +description VARCHAR(2048) NOT NULL, +modified_by VARCHAR(255) NOT NULL, +modified_date TIMESTAMP NOT NULL, +policyData TEXT, +policyName VARCHAR(255) NOT NULL, +policyVersion INTEGER, +scope VARCHAR(255) NOT NULL, +version INTEGER, +actionBodyId BIGINT, +configurationDataId BIGINT, +PRIMARY KEY (policyId) +); + +CREATE INDEX scope ON xacml.PolicyEntity (scope); +CREATE INDEX policyName ON xacml.PolicyEntity (policyName); + +GRANT INSERT, UPDATE, DELETE, SELECT on xacml.PolicyEntity to policy_user; + +DROP TABLE IF EXISTS xacml.ConfigurationDataEntity; +CREATE TABLE xacml.ConfigurationDataEntity +( + configurationDataId BIGINT NOT NULL AUTO_INCREMENT, + configBody TEXT, + configType VARCHAR(255) NOT NULL, + configurationName VARCHAR(255) NOT NULL, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + deleted BOOLEAN NOT NULL, + description VARCHAR(2048) NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + version INTEGER, + PRIMARY KEY (configurationDataId) +); + +GRANT INSERT, UPDATE, DELETE, SELECT on xacml.ConfigurationDataEntity to policy_user; + +DROP TABLE IF EXISTS xacml.PolicyDBDaoEntity; +CREATE TABLE xacml.PolicyDBDaoEntity +( + policyDBDaoUrl VARCHAR(500) NOT NULL, + created_date TIMESTAMP, + description VARCHAR(2048) NOT NULL, + modified_date TIMESTAMP NOT NULL, + password VARCHAR(100), + username VARCHAR(100), + PRIMARY KEY (policyDBDaoUrl) +); + +GRANT INSERT, UPDATE, DELETE, SELECT on xacml.PolicyDBDaoEntity to policy_user; + +DROP TABLE IF EXISTS xacml.GroupEntity; +CREATE TABLE xacml.GroupEntity +( +groupKey BIGINT NOT NULL AUTO_INCREMENT, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + defaultGroup BOOLEAN NOT NULL, + deleted BOOLEAN NOT NULL, + description VARCHAR(2048) NOT NULL, + groupId VARCHAR(100) NOT NULL, + groupName VARCHAR(255) NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + version INTEGER, + PRIMARY KEY (groupKey) +); + +GRANT INSERT, UPDATE, DELETE, SELECT on xacml.GroupEntity to policy_user; + +DROP TABLE IF EXISTS xacml.PdpEntity; +CREATE TABLE xacml.PdpEntity +( +pdpKey BIGINT NOT NULL AUTO_INCREMENT, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + deleted BOOLEAN NOT NULL, + description VARCHAR(2048) NOT NULL, + jmxPort INTEGER NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + pdpId VARCHAR(255) NOT NULL, + pdpName VARCHAR(255) NOT NULL, + groupKey BIGINT, + PRIMARY KEY (pdpKey) +); + +GRANT INSERT, UPDATE, DELETE, SELECT on xacml.PdpEntity to policy_user; + +DROP TABLE IF EXISTS xacml.ActionBodyEntity; +CREATE TABLE xacml.ActionBodyEntity +( +actionBodyId BIGINT NOT NULL AUTO_INCREMENT, + actionBody TEXT, + actionBodyName VARCHAR(255) NOT NULL, + created_by VARCHAR(255) NOT NULL, + created_date TIMESTAMP, + deleted BOOLEAN NOT NULL, + modified_by VARCHAR(255) NOT NULL, + modified_date TIMESTAMP NOT NULL, + version INTEGER, + PRIMARY KEY (actionBodyId) +); + +GRANT INSERT, UPDATE, DELETE, SELECT on xacml.ActionBodyEntity to policy_user; + +DROP TABLE IF EXISTS xacml.DatabaseLockEntity; +CREATE TABLE xacml.DatabaseLockEntity +( + lock_key INTEGER NOT NULL, + PRIMARY KEY (lock_key) +); + +GRANT INSERT, UPDATE, DELETE, SELECT on xacml.DatabaseLockEntity to policy_user; + +DROP TABLE IF EXISTS xacml.PolicyGroupEntity; +CREATE TABLE xacml.PolicyGroupEntity +( +groupKey BIGINT NOT NULL AUTO_INCREMENT, + policyId BIGINT NOT NULL, + PRIMARY KEY (groupKey,policyId) +); + +GRANT INSERT, UPDATE, DELETE, SELECT on xacml.PolicyGroupEntity to policy_user; + +ALTER TABLE xacml.PolicyEntity ADD CONSTRAINT UNQ_PolicyEntity_0 UNIQUE (policyName, scope); +ALTER TABLE xacml.PolicyEntity ADD CONSTRAINT FK_PolicyEntity_configurationDataId FOREIGN KEY (configurationDataId) +REFERENCES xacml.ConfigurationDataEntity (configurationDataId); +ALTER TABLE xacml.PolicyEntity ADD CONSTRAINT FK_PolicyEntity_actionBodyId FOREIGN KEY (actionBodyId) +REFERENCES xacml.ActionBodyEntity (actionBodyId); +ALTER TABLE xacml.PdpEntity ADD CONSTRAINT FK_PdpEntity_groupKey FOREIGN KEY (groupKey) +REFERENCES xacml.GroupEntity (groupKey); + +ALTER TABLE xacml.PolicyGroupEntity ADD CONSTRAINT FK_PolicyGroupEntity_policyId FOREIGN KEY (policyId) +REFERENCES xacml.PolicyEntity (policyId); + +ALTER TABLE xacml.PolicyGroupEntity ADD CONSTRAINT FK_PolicyGroupEntity_groupKey FOREIGN KEY (groupKey) +REFERENCES xacml.GroupEntity (groupKey); + +-- CREATE SEQUENCE xacml.seqActBody START WITH 1; +-- CREATE SEQUENCE xacml.seqGroup INCREMENT BY 50 START WITH 50; +-- CREATE SEQUENCE xacml.seqConfig START WITH 1; +-- CREATE SEQUENCE xacml.seqPolicy START WITH 1; +-- CREATE SEQUENCE xacml.seqPdp INCREMENT BY 50 START WITH 50; + +DROP TABLE IF EXISTS XACML.TERM; +CREATE TABLE XACML.TERM +( + ID int NOT NULL, + termName VARCHAR(45) NOT NULL, + fromzone VARCHAR(100), + tozone VARCHAR(100), + srcIPList VARCHAR(100), + destIPList VARCHAR(100) , + protocolList VARCHAR(100) , + portList VARCHAR(100) , + srcPortList VARCHAR(100) , + destPortList VARCHAR(100) , + action VARCHAR(100), + DESCRIPTION VARCHAR(100), + PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.TERM TO policy_user; + +ALTER TABLE XACML.ACTIONPOLICYDICT add constraint ACTIONPOLICYDICT_UNIQUE UNIQUE(ATTRIBUTE_NAME); + +DROP TABLE IF EXISTS XACML.ZONE; +CREATE TABLE XACML.ZONE +( + ID INTEGER NOT NULL, + zonename VARCHAR(45) NOT NULL, + zonevalue VARCHAR(64) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.ZONE TO policy_user; + +DROP TABLE IF EXISTS XACML.POLICYVERSION; + +CREATE TABLE XACML.POLICYVERSION +( +ID INTEGER NOT NULL, +POLICY_NAME VARCHAR(255) NOT NULL, +ACTIVE_VERSION INTEGER NULL, +HIGHEST_VERSION INTEGER NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +GRANT INSERT, UPDATE, DELETE, SELECT ON XACML.POLICYVERSION to policy_user; + +ALTER TABLE XACML.VSCLACTION ADD CONSTRAINT VSCLACTION_VSCL_ACTION_UNIQUE UNIQUE(VSCL_ACTION); + +set foreign_key_checks=1; diff --git a/packages/base/src/files/install/mysql/data/160200_downgrade_script.sql b/packages/base/src/files/install/mysql/data/160200_downgrade_script.sql new file mode 100644 index 00000000..41baaa92 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/160200_downgrade_script.sql @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists xacml.DCAEuuid; +drop table if exists xacml.MicroServiceLocation; +drop table if exists xacml.DCAEUsers; +drop table if exists xacml.microserviceconfigname; +drop table if exists xacml.vmType; + +alter table xacml.term drop column created_by; +alter table xacml.term drop column created_date; +alter table xacml.term drop column modified_by; +alter table xacml.term drop column modified_date; + +drop table if exists xacml.pepoptions; +drop table if exists xacml.VarbindDictionary; +drop table if exists xacml.GocEventAlarm; +drop table if exists xacml.GocTraversal; +drop table if exists xacml.BRMSParamTemplate; + +alter table xacml.roles drop column name; + diff --git a/packages/base/src/files/install/mysql/data/160200_upgrade_script.sql b/packages/base/src/files/install/mysql/data/160200_upgrade_script.sql new file mode 100644 index 00000000..46629a94 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/160200_upgrade_script.sql @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists xacml.DCAEuuid; +CREATE TABLE xacml.DCAEuuid ( + ID int NOT NULL, + name VARCHAR(45) NOT NULL, + description VARCHAR(64) + ); + +drop table if exists xacml.MicroServiceLocation; +CREATE TABLE xacml.MicroServiceLocation ( + ID int NOT NULL, + name VARCHAR(45) NOT NULL, + description VARCHAR(64) + ); + +drop table if exists xacml.DCAEUsers; +CREATE TABLE xacml.DCAEUsers ( + ID int NOT NULL, + name VARCHAR(45) NOT NULL, + description VARCHAR(64) + ); + +drop table if exists xacml.microserviceconfigname; +CREATE TABLE xacml.microserviceconfigname ( + ID int NOT NULL, + name VARCHAR(45) NOT NULL, + description VARCHAR(64) + ); + +drop table if exists xacml.vmType; +CREATE TABLE xacml.vmType ( + ID int NOT NULL, + name VARCHAR(45) NOT NULL, + description VARCHAR(64) + ); + +alter table xacml.term add created_by varchar(100); +alter table xacml.term add created_date date; +alter table xacml.term add modified_by varchar(100); +alter table xacml.term add modified_date date; + +drop table if exists xacml.pepoptions; +CREATE TABLE xacml.PEPOPTIONS ( +ID INT NOT NULL, +PEP_NAME VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(1024), +Actions VARCHAR(1024) NOT NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +drop table if exists xacml.VarbindDictionary; +CREATE TABLE xacml.VarbindDictionary ( +Id INT NOT NULL, +created_by VARCHAR(255) NOT NULL, +created_date TIMESTAMP, +modified_by VARCHAR(255) NOT NULL, +modified_date TIMESTAMP NOT NULL, +varbind_Description VARCHAR(2048), +varbind_Name VARCHAR(45) NOT NULL UNIQUE, +varbind_oid VARCHAR(45) NOT NULL, +PRIMARY KEY (Id) +); + +drop table if exists xacml.GocEventAlarm; +CREATE TABLE xacml.GocEventAlarm( +Id INT NOT NULL, +Event VARCHAR(45) NOT NULL, +description VARCHAR(1024), +Alarm VARCHAR(1024) NOT NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +drop table if exists xacml.GocTraversal; +CREATE TABLE xacml.GocTraversal( +ID INT NOT NULL, +TRAVERSAL VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +drop table if exists xacml.BRMSParamTemplate; +CREATE TABLE xacml.BRMSParamTemplate( +ID INT NOT NULL, +param_template_name VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45), +rule LONGTEXT NOT NULL, +CREATED_DATE TIMESTAMP NOT NULL, +CREATED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +alter table xacml.roles add name varchar(45); + + + + diff --git a/packages/base/src/files/install/mysql/data/160201_downgrade_script.sql b/packages/base/src/files/install/mysql/data/160201_downgrade_script.sql new file mode 100644 index 00000000..5f6381af --- /dev/null +++ b/packages/base/src/files/install/mysql/data/160201_downgrade_script.sql @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +alter table xacml.attribute modify created_date timestamp; +alter table xacml.obadvice modify created_date timestamp; +alter table xacml.decisionsettings modify created_date timestamp; +alter table xacml.actionpolicydict modify created_date timestamp; +alter table xacml.ecompname modify created_date timestamp; +alter table xacml.policyentity modify created_date timestamp; +alter table xacml.configurationdataentity modify created_date timestamp; +alter table xacml.policydbdaoentity modify created_date timestamp; + +alter table xacml.actionpolicydict modify created_date timestamp; +alter table xacml.vsclaction modify created_date timestamp; +alter table xacml.vnftype modify created_date timestamp; + +alter table xacml.groupentity modify created_date timestamp; +alter table xacml.pdpentity modify created_date timestamp; +alter table xacml.actionbodyentity modify created_date timestamp; + +alter table xacml.term modify created_date timestamp; +alter table xacml.varbinddictionary modify created_date timestamp; +alter table xacml.pepoptions modify created_date timestamp; +alter table xacml.goceventalarm modify created_date timestamp; +alter table xacml.goctraversal modify created_date timestamp; +alter table xacml.brmsparamtemplate modify created_date timestamp; diff --git a/packages/base/src/files/install/mysql/data/160201_upgrade_script.sql b/packages/base/src/files/install/mysql/data/160201_upgrade_script.sql new file mode 100644 index 00000000..70ddf791 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/160201_upgrade_script.sql @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +alter table xacml.attribute modify created_date timestamp default current_timestamp; +alter table xacml.obadvice modify created_date timestamp default current_timestamp; +alter table xacml.decisionsettings modify created_date timestamp default current_timestamp; +alter table xacml.actionpolicydict modify created_date timestamp default current_timestamp; +alter table xacml.ecompname modify created_date timestamp default current_timestamp; +alter table xacml.policyentity modify created_date timestamp default current_timestamp; +alter table xacml.configurationdataentity modify created_date timestamp default current_timestamp; +alter table xacml.policydbdaoentity modify created_date timestamp default current_timestamp; + +alter table xacml.actionpolicydict modify created_date timestamp default current_timestamp; +alter table xacml.vsclaction modify created_date timestamp default current_timestamp; +alter table xacml.vnftype modify created_date timestamp default current_timestamp; + +alter table xacml.groupentity modify created_date timestamp default current_timestamp; +alter table xacml.pdpentity modify created_date timestamp default current_timestamp; +alter table xacml.actionbodyentity modify created_date timestamp default current_timestamp; + +alter table xacml.term modify created_date timestamp default current_timestamp; +alter table xacml.term modify modified_date timestamp not null; +alter table xacml.varbinddictionary modify created_date timestamp default current_timestamp; +alter table xacml.pepoptions modify created_date timestamp default current_timestamp; +alter table xacml.goceventalarm modify created_date timestamp default current_timestamp; +alter table xacml.goctraversal modify created_date timestamp default current_timestamp; +alter table xacml.brmsparamtemplate modify created_date timestamp default current_timestamp; diff --git a/packages/base/src/files/install/mysql/data/160400_downgrade_script.sql b/packages/base/src/files/install/mysql/data/160400_downgrade_script.sql new file mode 100644 index 00000000..d5a990fc --- /dev/null +++ b/packages/base/src/files/install/mysql/data/160400_downgrade_script.sql @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists xacml.MicroServiceModels; +drop table if exists xacml.GocRCAlarm; +drop table if exists xacml.xacmlGocVnfType; +drop table if exists xacml.CLOSEDLOOPD2SERVICES; +drop table if exists xacml.CLOSEDLOOPSITE; +drop table if exists xacml.USERINFO; + +drop table if exists drools.sessioninfo; +drop table if exists drools.WORKITEMINFO; +drop table if exists drools.droolspdpentity; + + + diff --git a/packages/base/src/files/install/mysql/data/160400_upgrade_script.sql b/packages/base/src/files/install/mysql/data/160400_upgrade_script.sql new file mode 100644 index 00000000..745b4715 --- /dev/null +++ b/packages/base/src/files/install/mysql/data/160400_upgrade_script.sql @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * Base Package + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +drop table if exists xacml.MicroServiceModels; +CREATE TABLE xacml.MicroServiceModels ( +ID INTEGER NOT NULL, +modelName VARCHAR(75) NOT NULL, +DESCRIPTION VARCHAR(45), +Dependency VARCHAR(255), +imported_by VARCHAR(45) NOT NULL, +attributes LONGTEXT, +ref_attributes LONGTEXT, +PRIMARY KEY(ID) +); + +drop table if exists xacml.GocRCAlarm; +CREATE TABLE xacml.GocRCAlarm( +ID int NOT NULL, +alarmName VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL default current_timestamp, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +drop table if exists xacml.xacmlGocVnfType; +CREATE TABLE xacml.xacmlGocVnfType( +ID int NOT NULL, +vnfName VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL default current_timestamp, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +drop table if exists xacml.CLOSEDLOOPD2SERVICES; +CREATE TABLE xacml.CLOSEDLOOPD2SERVICES( +ID INTEGER NOT NULL, +SERVICE_NAME VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL default current_timestamp, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +drop table if exists xacml.CLOSEDLOOPSITE; +CREATE TABLE xacml.CLOSEDLOOPSITE( +ID INTEGER NOT NULL, +SITE_NAME VARCHAR(45) NOT NULL, +DESCRIPTION VARCHAR(45) NULL, +CREATED_DATE TIMESTAMP NOT NULL default current_timestamp, +CREATED_BY VARCHAR(45) NOT NULL, +MODIFIED_DATE TIMESTAMP NOT NULL, +MODIFIED_BY VARCHAR(45) NOT NULL, +PRIMARY KEY(ID) +); + +drop table if exists xacml.USERINFO; +CREATE TABLE xacml.USERINFO( +ATTUID VARCHAR(45) NOT NULL, +NAME VARCHAR(45) NOT NULL, +PRIMARY KEY(ATTUID) +); + +-- use BLOB instead of LONGVARBINARY +drop table if exists drools.sessioninfo; +CREATE TABLE drools.SESSIONINFO +( +ID BIGINT NOT NULL, +LASTMODIFICATIONDATE TIMESTAMP, +RULESBYTEARRAY BLOB, +STARTDATE TIMESTAMP default current_timestamp, +OPTLOCK INTEGER, +PRIMARY KEY (ID) +); + +drop table if exists drools.WORKITEMINFO; +CREATE TABLE drools.WORKITEMINFO +( +WORKITEMID BIGINT NOT NULL, +CREATIONDATE TIMESTAMP default current_timestamp, +`NAME` VARCHAR(500), +PROCESSINSTANCEID BIGINT, +STATE BIGINT, +OPTLOCK INTEGER, +WORKITEMBYTEARRAY BLOB, +PRIMARY KEY (WORKITEMID) +); + +drop table if exists drools.droolspdpentity; +CREATE TABLE drools.DROOLSPDPENTITY +( + PDPID VARCHAR(100) NOT NULL, + DESIGNATED BOOLEAN NOT NULL DEFAULT FALSE, + PRIORITY INT NOT NULL DEFAULT 0, + UPDATEDDATE DATE NOT NULL, + GROUPID VARCHAR(100) NOT NULL, + SESSIONID BIGINT NOT NULL +); + + diff --git a/packages/base/src/files/m2/settings.xml b/packages/base/src/files/m2/settings.xml new file mode 100755 index 00000000..f7b3c9e5 --- /dev/null +++ b/packages/base/src/files/m2/settings.xml @@ -0,0 +1,83 @@ + + + + + + + + + policy-profile + + true + + + + + ${{snapshotRepositoryID}} + ${{snapshotRepositoryUrl}} + + false + always + + + true + always + + + + + ${{releaseRepositoryID}} + ${{releaseRepositoryUrl}} + + true + always + + + false + always + + + + + + + + + policy-profile + + + + + ${{snapshotRepositoryID}} + ${{repositoryUsername}} + ${{repositoryPassword}} + + + ${{releaseRepositoryID}} + ${{repositoryUsername}} + ${{repositoryPassword}} + + + + + diff --git a/packages/base/src/files/m2/standalone-settings.xml b/packages/base/src/files/m2/standalone-settings.xml new file mode 100755 index 00000000..277113c2 --- /dev/null +++ b/packages/base/src/files/m2/standalone-settings.xml @@ -0,0 +1,57 @@ + + + + + + + + + policy-profile + + true + + + + + ${{fileRepoID}} + ${{fileRepoUrl}} + + true + always + + + true + always + + + + + + + + + policy-profile + + + + diff --git a/packages/install/.gitignore b/packages/install/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/packages/install/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/packages/install/pom.xml b/packages/install/pom.xml new file mode 100644 index 00000000..2ed29546 --- /dev/null +++ b/packages/install/pom.xml @@ -0,0 +1,94 @@ + + + + + 4.0.0 + + + org.openecomp.policy.drools-pdp + packages + 1.0.0-SNAPSHOT + + + install-drools + pom + + Installation Package + D2 ECOMP Policy Drools PDP Installation Package + + + + + maven-assembly-plugin + + + + single + + package + + + src/assembly/zip.xml + + false + + + + + + + + + + + org.openecomp.policy.drools-pdp + base + ${project.version} + tar.gz + + + org.openecomp.policy.drools-pdp + policy-core + ${project.version} + zip + + + org.openecomp.policy.drools-pdp + policy-management + ${project.version} + zip + + + org.openecomp.policy.drools-pdp + policy-persistence + ${project.version} + zip + + + org.openecomp.policy.drools-pdp + policy-healthcheck + ${project.version} + zip + + + + diff --git a/packages/install/src/assembly/zip.xml b/packages/install/src/assembly/zip.xml new file mode 100644 index 00000000..48b82d40 --- /dev/null +++ b/packages/install/src/assembly/zip.xml @@ -0,0 +1,39 @@ + + + + zipfile + + zip + + false + + + src/files + . + 755 + + + + + false + + + diff --git a/packages/install/src/files/base.conf b/packages/install/src/files/base.conf new file mode 100644 index 00000000..90128e91 --- /dev/null +++ b/packages/install/src/files/base.conf @@ -0,0 +1,68 @@ +POLICY_HOME=/opt/app/policy +JAVA_HOME=/opt/jdk1.8.0_77 +M2_HOME=/opt/app/policy/3rdparty/apache-maven-3.3.1 + +ENGINE_MANAGEMENT_PORT=9696 +ENGINE_MANAGEMENT_HOST=localhost +ENGINE_MANAGEMENT_USER=@1b3rt +ENGINE_MANAGEMENT_PASSWORD=31nst@1n + +ENGINE_HEALTHCHECK_HOST=0.0.0.0 +ENGINE_HEALTHCHECK_PORT=9697 + +JDBC_DRIVER=org.mariadb.jdbc.Driver +JDBC_URL=jdbc:mysql://localhost:3306/xacml +JDBC_DROOLS_URL=jdbc:mysql://localhost:3306/drools +JDBC_USER=policy_user +JDBC_PASSWORD= + +NAGIOS_CONFIG_NAME=policy +NAGIOS_NRDP_URL= +NAGIOS_NRDP_TOKEN=bbpguvsohehj +NAGIOS_NRDP_DISABLED=true + +# Integrity Monitor properties +site_name=site_1 +fp_monitor_interval=30 +failed_counter_threshold=3 +test_trans_interval=20 +write_fpc_interval=5 +max_fpc_update_interval=60 +test_via_jmx=false +node_type=pdp_drools +# Dependency groups are groups of resources upon which a node operational state is dependent upon. +# Each group is a comma-separated list of resource names and groups are separated by a semicolon. +dependency_groups=site_1.pap_1,site_1.pap_2;site_1.pdp_1,site_1.pdp_2 +resource_name=pdpd_1 + +# The (optional) period of time in seconds between executions of the integrity audit. +# Value < 0 : Audit does not run (default value if property is not present = -1) +# Value = 0 : Audit runs continuously +# Value > 0 : The period of time in seconds between execution of the audit on a particular node +integrity_audit_period_seconds=-1 + +host_port=0.0.0.0:9981 + +# To use a Nexus repository for rules artifacts, +# following properties must be uncommented and set: +#repositoryID=policy-nexus +#repositoryUrl=http://....(URL for the repository goes here) +#repositoryUsername=(nexus username goes here) +#repositoryPassword=(password goes here) + +# just for testing purposes, modify at installation +PDPD_CONFIGURATION_TOPIC=PDPD_CONFIGURATION +PDPD_CONFIGURATION_SERVERS= +PDPD_CONFIGURATION_API_KEY= +PDPD_CONFIGURATION_API_SECRET= +PDPD_CONFIGURATION_CONSUMER_GROUP= +PDPD_CONFIGURATION_CONSUMER_INSTANCE= +PDPD_CONFIGURATION_PARTITION_KEY= + +PAP_HOST= +PAP_USERNAME= +PAP_PASSWORD= + +PDP_HOST= +PDP_USERNAME= +PDP_PASSWORD= diff --git a/packages/install/src/files/policy-management.conf b/packages/install/src/files/policy-management.conf new file mode 100644 index 00000000..609aa868 --- /dev/null +++ b/packages/install/src/files/policy-management.conf @@ -0,0 +1,5 @@ +CONTROLLER_ARTIFACT_ID=policy-management +CONTROLLER_NAME=policy-management-controller +CONTROLLER_PORT=9696 +RULES_ARTIFACT=org.openecomp.policy:dummy-artifact:1.0.0-SNAPSHOT +UEB_TOPIC=policyengine-develop diff --git a/packages/pom.xml b/packages/pom.xml new file mode 100644 index 00000000..3cde69cd --- /dev/null +++ b/packages/pom.xml @@ -0,0 +1,43 @@ + + + + + 4.0.0 + + + org.openecomp.policy.drools-pdp + drools-pdp + 1.0.0-SNAPSHOT + + + packages + pom + + Policy Packages + D2 ECOMP Policy Drools PDP Installation Packages + + + base + + install + + diff --git a/policy-core/pom.xml b/policy-core/pom.xml new file mode 100644 index 00000000..3e4bc681 --- /dev/null +++ b/policy-core/pom.xml @@ -0,0 +1,235 @@ + + + + + 4.0.0 + + org.openecomp.policy.drools-pdp + policy-core + + org.openecomp.policy.drools-pdp + drools-pdp + 1.0.0-SNAPSHOT + + + + + + maven-assembly-plugin + 2.6 + + + zipfile + + single + + package + + true + ${project.artifactId}-${project.version} + + src/assembly/assemble_zip.xml + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.8 + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/lib + false + true + true + false + false + false + org.opendaylight,com.brocade.odl + provided + + + + + + maven-resources-plugin + 2.6 + + + copy-version + + copy-resources + + validate + + ${basedir}/target/versions + + + src/main/resources/versions + + version.properties + + true + + + + + + copy-resources + + copy-resources + + validate + + ${basedir}/target/etc/bvc-extensions + + + src/main/resources/etc/bvc-extensions + + feature_config_template.cfg + feature_custom.install + + true + + + + + + + + + + + + log4j + log4j + 1.2.17 + + + org.kie + kie-api + 6.3.0.Final + + + org.kie + kie-ci + 6.3.0.Final + runtime + + + org.drools + drools-core + 6.3.0.Final + runtime + + + org.drools + drools-persistence-jpa + 6.3.0.Final + + + + org.openecomp.policy.drools-pdp + policy-utils + 1.0.0-SNAPSHOT + + + org.openecomp.policy.common + ECOMP-Logging + ${common-modules.version} + + + org.openecomp.policy.common + integrity-monitor + ${common-modules.version} + + + org.openecomp.policy.common + integrity-audit + ${common-modules.version} + + + org.mariadb.jdbc + mariadb-java-client + 1.2.3 + runtime + + + com.h2database + h2 + [1.4.186,) + runtime + + + org.apache.httpcomponents + httpcore + 4.4.1 + + + junit + junit + 4.11 + test + + + org.codehaus.btm + btm + 2.1.4 + + + org.eclipse.persistence + eclipselink + 2.6.2 + + + org.hibernate + hibernate-entitymanager + 5.0.7.Final + + + + org.json + json + 20160810 + + + + + + + org.apache.httpcomponents + httpclient + 4.5 + + + + diff --git a/policy-core/src/assembly/assemble_zip.xml b/policy-core/src/assembly/assemble_zip.xml new file mode 100644 index 00000000..447a5271 --- /dev/null +++ b/policy-core/src/assembly/assemble_zip.xml @@ -0,0 +1,85 @@ + + + + + + runtime + + zip + + + + false + + + + target + lib + + policy-core-${project.version}.jar + + + + target/assembly/ + . + + + + + . + lib + + *.jar + + + + src/main/server-gen/bin + bin + 0744 + + + + + src/main/server/bin + bin + 0744 + + + + + src/main/server-gen/scripts + scripts + + + src/main/server/scripts + scripts + + + src/main/server/config + config + + + + diff --git a/policy-core/src/main/java/org/openecomp/policy/drools/core/FeatureAPI.java b/policy-core/src/main/java/org/openecomp/policy/drools/core/FeatureAPI.java new file mode 100644 index 00000000..a14c6547 --- /dev/null +++ b/policy-core/src/main/java/org/openecomp/policy/drools/core/FeatureAPI.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.core; + +import java.util.Properties; + +import org.kie.api.runtime.KieSession; + +import org.openecomp.policy.drools.utils.OrderedService; +import org.openecomp.policy.drools.utils.OrderedServiceImpl; + +/** + * This interface provides a way to invoke optional features at various + * points in the code. At appropriate points in the + * application, the code iterates through this list, invoking these optional + * methods. Most of the methods here are notification only -- these tend to + * return a 'void' value. In other cases, such as 'activatePolicySession', + * may + */ +public interface FeatureAPI extends OrderedService +{ + /** + * 'FeatureAPI.impl.getList()' returns an ordered list of objects + * implementing the 'FeatureAPI' interface. + */ + static public OrderedServiceImpl impl = + new OrderedServiceImpl(FeatureAPI.class); + + /** + * This method is called during initialization at a point right after + * 'PolicyContainer' initialization has completed. + * + * @param args standard 'main' arguments, which are currently ignored + * @param configDir the relative directory containing configuration files + */ + public void globalInit(String args[], String configDir); + + /** + * This method is used to create a 'KieSession' as part of a + * 'PolicyContainer'. The caller of this method will iterate over the + * implementers of this interface until one returns a non-null value. + * + * @param policyContainer the 'PolicyContainer' instance containing this + * session + * @param name the name of the KieSession (which is also the name of + * the associated PolicySession) + * @param kieBaseName the name of the 'KieBase' instance containing + * this session + * @return a new KieSession, if one was created, or 'null' if not + * (this depends on the capabilities and state of the object implementing + * this interface) + */ + public KieSession activatePolicySession + (PolicyContainer policyContainer, String name, String kieBaseName); + + /** + * This method is called after 'KieSession.dispose()' is called + * + * @param policySession the 'PolicySession' object that wrapped the + * 'KieSession' + */ + public void disposeKieSession(PolicySession policySession); + + /** + * This method is called after 'KieSession.destroy()' is called + * + * @param policySession the 'PolicySession' object that wrapped the + * 'KieSession' + */ + public void destroyKieSession(PolicySession policySession); + + /** + * called before the Policy Engine is started + */ + public void beforeStartEngine() throws IllegalStateException; + + /** + * called immediately after the Policy Engine is started + */ + public void afterStartEngine(); + + /** + * called before the Policy Engine is shut down + */ + public void beforeShutdownEngine(); + + /** + * called after the Policy Engine is shut down + */ + public void afterShutdownEngine(); + + /** + * called before creating a controller with name 'name' + * + * @param name name of the the controller + * @param properties configuration properties + */ + public void beforeCreateController(String name, Properties properties); + + /** + * NOTE: temporary, should pass the Policy Controller already created + * + * called after creating a controller with name 'name' + * + * @param name name of the the controller + * @param properties configuration properties + */ + public void afterCreateController(String name); + + /** + * NOTE: temporary, should pass the Policy Controller + * + * called before starting a controller with name 'name' + * + * @param name name of the the controller + */ + public void beforeStartController(String name); + + /** + * NOTE: temporary, should pass the Policy Controller + * + * called after starting a controller with name 'name' + * + * @param name name of the the controller + */ + public void afterStartController(String name); + + /** + * NOTE: this method is probably temporary + * + * @return 'true' if persistence is enabled, and 'false' if not, or if + * this feature is not related to persistence. + */ + public boolean isPersistenceEnabled(); +} diff --git a/policy-core/src/main/java/org/openecomp/policy/drools/core/PolicyContainer.java b/policy-core/src/main/java/org/openecomp/policy/drools/core/PolicyContainer.java new file mode 100644 index 00000000..ae7cd622 --- /dev/null +++ b/policy-core/src/main/java/org/openecomp/policy/drools/core/PolicyContainer.java @@ -0,0 +1,828 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.core; + +import java.io.IOException; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; + +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import org.eclipse.persistence.config.PersistenceUnitProperties; +import org.kie.api.KieBase; +import org.kie.api.KieServices; +import org.kie.api.builder.KieScanner; +import org.kie.api.builder.Message; +import org.kie.api.builder.ReleaseId; +import org.kie.api.builder.Results; +import org.kie.api.runtime.Environment; +import org.kie.api.runtime.EnvironmentName; +import org.kie.api.runtime.KieContainer; +import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.KieSessionConfiguration; + +import bitronix.tm.Configuration; +import bitronix.tm.TransactionManagerServices; +import bitronix.tm.resource.jdbc.PoolingDataSource; + +import org.openecomp.policy.common.ia.IntegrityAudit; +import org.openecomp.policy.common.ia.IntegrityAuditProperties; +import org.openecomp.policy.drools.properties.Startable; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.PropertyUtil; + +/** + * This class is a wrapper around 'KieContainer', which adds the ability + * to automatically create and track KieSession instances. + */ +public class PolicyContainer implements Startable +{ + // get an instance of logger + private static Logger logger = FlexLogger.getLogger(PolicyContainer.class); + // 'KieServices' singleton + static private KieServices kieServices = KieServices.Factory.get(); + + // set of all 'PolicyContainer' instances + static private HashSet containers = + new HashSet(); + + // maps feature objects to per-PolicyContainer data + private ConcurrentHashMap adjuncts = + new ConcurrentHashMap(); + + // 'KieContainer' associated with this 'PolicyContainer' + private KieContainer kieContainer; + + // indicates whether the PolicyContainer is 'started' + // (started = sessions created, threads running) + private volatile boolean isStarted = false; + + // maps session name into the associated 'PolicySession' instance + private HashMap sessions = + new HashMap(); + + // if not null, this is a 'KieScanner' looking for updates + private KieScanner scanner = null; + + // indicates whether the scanner has been started + // (it can block for a long time) + private boolean scannerStarted = false; + + // Used to set relative pathing to config files for unit test environment + public static boolean isUnitTesting = false; + + /** + * uses 'groupId', 'artifactId' and 'version', and fetches the associated + * artifact and remaining dependencies from the Maven repository to create + * the 'PolicyContainer' and associated 'KieContainer'. + * + * An exception occurs if the creation of the 'KieContainer' fails. + * + * @param groupId the 'groupId' associated with the artifact + * @param artifactId the artifact name + * @param version a comma-separated list of possible versions + */ + public PolicyContainer(String groupId, String artifactId, String version) + { + this(kieServices.newReleaseId(groupId, artifactId, version)); + } + + /** + * uses the 'groupId', 'artifactId' and 'version' information in 'ReleaseId', + * and fetches the associated artifact and remaining dependencies from the + * Maven repository to create the 'PolicyContainer' and associated + * 'KieContainer'. + * + * An exception occurs if the creation of the 'KieContainer' fails. + * + * @param releaseId indicates the artifact that is to be installed in this + * container + */ + public PolicyContainer(ReleaseId releaseId) + { + if (releaseId.getVersion().contains(",")) + { + // this is actually a comma-separated list of release ids + releaseId = loadArtifact(releaseId.getGroupId(), + releaseId.getArtifactId(), + releaseId.getVersion()); + } + else + { + kieContainer = kieServices.newKieContainer(releaseId); + } + synchronized(containers) + { + if(releaseId != null){ + logger.info("Add a new kieContainer in containers: releaseId: " + releaseId.toString()); + }else{ + logger.warn("input releaseId is null"); + } + containers.add(this); + } + startScanner(releaseId); + } + + /** + * Load an artifact into a new KieContainer. This method handles the + * case where the 'version' is actually a comma-separated list of + * versions. + * + * @param groupId the 'groupId' associated with the artifact + * @param artifactId the artifact name + * @param version a comma-separated list of possible versions + */ + private ReleaseId loadArtifact + (String groupId, String artifactId, String version) + { + String[] versions = version.split(","); + if (versions.length > 1) + { + logger.info("Multiple KieContainer versions are specified: " + + version); + } + + // indicates a 'newKieContainer' call failed + RuntimeException exception = null; + + // set prior to every 'newKieContainer' invocation + // (if we are able to create the container, it will be the last + // one that was successful) + ReleaseId releaseId = null; + for (String ver : versions) + { + try + { + // Create a 'ReleaseId' object describing the artifact, and + // create a 'KieContainer' based upon it. + logger.info("Create new KieContainer start, version = " + + ver + " ..."); + + releaseId = kieServices.newReleaseId(groupId, artifactId, ver); + kieContainer = kieServices.newKieContainer(releaseId); + + // clear any exception, and break out of the loop + exception = null; + break; + } + catch (RuntimeException e) + { + exception = e; + } + } + if (exception != null) + { + // all of the 'newKieContainer' invocations failed -- throw the + // most recent exception + throw(exception); + } + return(releaseId); + } + + /** + * @return the name of the container, which is the String equivalent of + * the 'ReleaseId'. It has the form: + * + * (groupId + ":" + artifactId + ":" + version) + * + * Note that the name changes after a successful call to 'updateToVersion', + * although typically only the 'version' part changes. + */ + public String getName() + { + return(kieContainer.getReleaseId().toString()); + } + + /** + * @return the associated 'KieContainer' instance + */ + public KieContainer getKieContainer() + { + return(kieContainer); + } + + /** + * @return the 'ClassLoader' associated with the 'KieContainer' instance + */ + public ClassLoader getClassLoader() + { + return(kieContainer.getClassLoader()); + } + + /** + * @return the Maven GroupId of the top-level artifact wrapped + * by the container. + */ + public String getGroupId() + { + return(kieContainer.getReleaseId().getGroupId()); + } + + /** + * @return the Maven ArtifactId of the top-level artifact wrapped + * by the container. + */ + public String getArtifactId() + { + return(kieContainer.getReleaseId().getArtifactId()); + } + + /** + * @return the version of the top-level artifact wrapped by the + * container (this may change as updates occur) + */ + public String getVersion() + { + return(kieContainer.getReleaseId().getVersion()); + } + + /** + * Fetch the named 'PolicySession'. + * + * @param name the name of the KieSession (which is also the name of + * the associated PolicySession) + * @return a PolicySession if found, 'null' if not + */ + public PolicySession getPolicySession(String name) + { + return(sessions.get(name)); + } + + /** + * Internal method to create a PolicySession, possibly restoring it + * from persistent storage. + * + * @param name of the KieSession and PolicySession + * @param kieBaseName name of the associated 'KieBase' instance + * @return a new or existing PolicySession, or 'null' if not found + */ + private PolicySession activatePolicySession(String name, String kieBaseName) + { + synchronized(sessions) + { + logger.info("activatePolicySession:name :" + name); + PolicySession session = sessions.get(name); + if (session == null) + { + KieSession kieSession = null; + + // loop through all of the features, and give each one + // a chance to create the 'KieSession' + for (FeatureAPI feature : FeatureAPI.impl.getList()) + { + if ((kieSession = feature.activatePolicySession + (this, name, kieBaseName)) != null) + break; + } + + // if none of the features created the session, create one now + if (kieSession == null) + { + kieSession = kieContainer.newKieSession(name); + } + + if (kieSession != null) + { + // creation of 'KieSession' was successful - build + // a PolicySession + session = new PolicySession(name, this, kieSession); + sessions.put(name, session); + logger.info("activatePolicySession:new session was added in sessions with name " + name); + } + } + logger.info("activatePolicySession:session - " + + (session == null ? "null" : session.getFullName()) + + " is returned."); + return(session); + } + } + + /** + * This creates a 'PolicySession' instance within this 'PolicyContainer', + * and ties it to the specified 'KieSession'. 'name' must not currently + * exist within the 'PolicyContainer', and the 'KieBase' object associated + * with 'KieSession' must belong to the 'KieContainer'. This method provides + * a way for 'KieSession' instances that are created programmatically to fit + * into this framework. + * + * @param name the name for the new 'PolicySession' + * @param kieSession a 'KieSession' instance, that will be included in + * this infrastructure + * @return the new 'PolicySession' + * @throws IllegalArgumentException if 'kieSession' does not reside within + * this container + * @throws IllegalStateException if a 'PolicySession' already exists + * with this name + */ + public PolicySession adoptKieSession(String name, KieSession kieSession) + throws IllegalArgumentException, IllegalStateException + { + + if(name == null){ + logger.warn("adoptKieSession:input name is null"); + }else if(kieSession == null){ + logger.warn("adoptKieSession:input kieSession is null"); + }else { + logger.info("adoptKieSession:name: " + name + " kieSession: " + kieSession); + } + // fetch KieBase, and verify it belongs to this KieContainer + boolean match = false; + KieBase kieBase = kieSession.getKieBase(); + logger.info("adoptKieSession:kieBase: " + kieBase); + for (String kieBaseName : kieContainer.getKieBaseNames()) + { + logger.info("adoptKieSession:kieBaseName: " + kieBaseName); + if (kieBase == kieContainer.getKieBase(kieBaseName)) + { + match = true; + break; + } + } + logger.info("adoptKieSession:match " + match); + // if we don't have a match yet, the last chance is to look at the + // default KieBase, if it exists + if (!match && kieBase != kieContainer.getKieBase()) + { + throw(new IllegalArgumentException + ("KieSession '" + name + "' does not reside within container " + + getName())); + } + + synchronized (sessions) + { + if (sessions.get(name) != null) + { + throw(new IllegalStateException + ("PolicySession '" + name + "' already exists")); + } + + // create the new 'PolicySession', add it to the table, + // and return the object to the caller + logger.info("adoptKieSession:create a new policySession with name " + name); + PolicySession policySession = + new PolicySession(name, this, kieSession); + sessions.put(name, policySession); + return(policySession); + } + } + + /** + * This call 'KieContainer.updateToVersion()', and returns the associated + * response as a String. If successful, the name of this 'PolicyContainer' + * changes to match the new version. + * + * @param newVersion this is the version to update to (the 'groupId' + * and 'artifactId' remain the same) + * @return the list of messages associated with the update (not sure if + * this can be 'null', or how to determine success/failure) + */ + public String updateToVersion(String newVersion) + { + ReleaseId releaseId = kieContainer.getReleaseId(); + Results results = this.updateToVersion + (kieServices.newReleaseId(releaseId.getGroupId(), + releaseId.getArtifactId(), + newVersion)); + + List messages = (results == null ? null : results.getMessages()); + return(messages == null ? null : messages.toString()); + } + + /** + * This calls 'KieContainer.updateToVersion()', and returns the associated + * response. If successful, the name of this 'PolicyContainer' changes to + * match the new version. + * + * @param releaseId the new artifact (usually new version) to be installed + * @return the 'Results' parameter from 'KieContainer.updateToVersion' + */ + public Results updateToVersion(ReleaseId releaseId) + { + if(releaseId == null){ + logger.warn("updateToVersion:input releaseId is null"); + }else { + logger.info("updateToVersion:releaseId " + releaseId.toString()); + } + return(kieContainer.updateToVersion(releaseId)); + } + + /** + * @return all existing 'PolicyContainer' instances + */ + public static Collection getPolicyContainers() + { + synchronized(containers) + { + return(new HashSet(containers)); + } + } + + /** + * @return all of the 'PolicySession' instances + */ + public Collection getPolicySessions() + { + // KLUDGE WARNING: this is a temporary workaround -- if there are + // no features, we don't have persistence, and 'activate' is never + // called. In this case, make sure the container is started. + if (FeatureAPI.impl.getList().size() == 0) + { + start(); + } + + // return current set of PolicySessions + synchronized(sessions) + { + return(new HashSet(sessions.values())); + } + } + + /** + * This method will start a 'KieScanner' (if not currently running), + * provided that the ReleaseId version is 'LATEST' or 'RELEASE', + * or refers to a SNAPSHOT version. + * + * @param releaseId the release id used to create the container + */ + public synchronized void startScanner(ReleaseId releaseId) + { + String version = releaseId.getVersion(); + if (scannerStarted == false && scanner == null && version != null + && (version.equals("LATEST") || version.equals("RELEASE") + || version.endsWith("-SNAPSHOT"))) + { + // create the scanner, and poll at 60 second intervals + try + { + scannerStarted = true; + + // start this in a separate thread -- it can block for a long time + new Thread("Scanner Starter " + getName()) + { + public void run() + { + scanner = kieServices.newKieScanner(kieContainer); + scanner.start(60000L); + } + }.start(); + } + catch (Exception e) + { + // sometimes the scanner initialization fails for some reason + logger.error(MessageCodes.EXCEPTION_ERROR, e, "main", "startServer"); + } + } + } + + /** + * Insert a fact into a specific named session + * + * @param name this is the session name + * @param object this is the fact to be inserted into the session + * @return 'true' if the named session was found, 'false' if not + */ + public boolean insert(String name, Object object) + { + // TODO: Should the definition of 'name' be expanded to include an + // alternate entry point as well? For example, 'name.entryPoint' (or + // something other than '.' if that is a problem). + synchronized (sessions) + { + PolicySession session = sessions.get(name); + if (session != null) + { + session.getKieSession().insert(object); + return(true); + } + } + return(false); + } + + /** + * Insert a fact into all sessions associated with this container + * + * @param object this is the fact to be inserted into the sessions + * @return 'true' if the fact was inserted into at least one session, + * 'false' if not + */ + public boolean insertAll(Object object) + { + boolean rval = false; + synchronized (sessions) + { + for (PolicySession session : sessions.values()) + { + session.getKieSession().insert(object); + rval = true; + } + } + return(rval); + } + + /*************************/ + /* 'Startable' interface */ + /*************************/ + + /** + * {@inheritDoc} + */ + public synchronized boolean start() + { + if (!isStarted) + { + // This will create all 'PolicySession' instances specified in the + // 'kmodule.xml' file that don't exist yet + for (String kieBaseName : kieContainer.getKieBaseNames()) + { + for (String kieSessionName : + kieContainer.getKieSessionNamesInKieBase(kieBaseName)) + { + // if the 'PolicySession' does not currently exist, this method + // call will attempt to create it + PolicySession session = + activatePolicySession(kieSessionName, kieBaseName); + if (session != null) + { + session.startThread(); + } + } + } + isStarted = true; + } + return(true); + } + + /** + * {@inheritDoc} + */ + public synchronized boolean stop() + { + if (isStarted) + { + Collection localSessions; + + synchronized (sessions) + { + // local set containing all of the sessions + localSessions = new HashSet(sessions.values()); + + // clear the 'name->session' map in 'PolicyContainer' + sessions.clear(); + } + for (PolicySession session : localSessions) + { + // stop session thread + session.stopThread(); + + // free KieSession resources + session.getKieSession().dispose(); + + // notify features + for (FeatureAPI feature : FeatureAPI.impl.getList()) + { + feature.disposeKieSession(session); + } + } + isStarted = false; + } + return(true); + } + + /** + * {@inheritDoc} + */ + public synchronized void shutdown() + { + // Note that this method does not call 'destroy' on the 'KieSession' + // instances, which would remove any associated information in persistent + // storage. Should it do this? + + stop(); + synchronized(containers) + { + containers.remove(this); + } + + // How do we free the resources associated with the KieContainer? + // Is garbage collection sufficient? + } + + /** + * {@inheritDoc} + */ + public boolean isAlive() + { + return(isStarted); + } + + /*************************/ + + /** + * This method is similar to 'shutdown', but it also frees any persistence + * resources as well. + */ + public synchronized void destroy() + { + // we need all KieSession instances running in order to free + // resources associated with persistence + start(); + Collection localSessions; + + synchronized (sessions) + { + // local set containing all of the sessions + localSessions = new HashSet(sessions.values()); + + // clear the 'name->session' map in 'PolicyContainer' + sessions.clear(); + } + for (PolicySession session : localSessions) + { + // stop session thread + session.stopThread(); + + // free KieSession resources + session.getKieSession().destroy(); + + // notify features + for (FeatureAPI feature : FeatureAPI.impl.getList()) + { + feature.destroyKieSession(session); + } + } + isStarted = false; + + synchronized(containers) + { + containers.remove(this); + } + + // How do we free the resources associated with the KieContainer? + // Is garbage collection sufficient? + } + + /** + * This method is called when the host goes from the 'standby->active' state. + */ + static public void activate() + { + // start all of the 'PolicyContainer' instances + for (PolicyContainer container : containers) + { + try + { + container.start(); + } + catch (Exception e) + { + e.printStackTrace(); + logger.error(MessageCodes.EXCEPTION_ERROR, e, + "activate", + "PolicyContainer.start()"); + } + } + } + + /** + * This method is called when the host goes from the 'active->standby' state. + */ + static public void deactivate() + { + // deactivate all of the 'PolicyContainer' instances + for (PolicyContainer container : containers) + { + try + { + container.stop(); + } + catch (Exception e) + { + e.printStackTrace(); + logger.error(MessageCodes.EXCEPTION_ERROR, e, + "deactivate", + "PolicyContainer.stop()"); + } + } + } + + /** + * This method does the following: + * + * 1) Initializes logging + * 2) Starts the DroolsPDP Integrity Monitor + * 3) Initilaizes persistence + * + * It no longer reads in properties files, o creates 'PolicyContainer' + * instances. + * + * @param args standard 'main' arguments, which are currently ignored + */ + public static void globalInit(String args[]) + { + + /* + * When JUnit testing, working directory should be + * "../policy-management". In test environment, command line argument + * should specify the relative path from this directory to the config + * directory ("src/test/server/config") + */ + String configDir = "config"; + if (isUnitTesting) { + configDir = "src/test/server/config"; + } + System.out.println("PolicyContainer.main: configDir=" + configDir); + + logger.info("Calling initlogger"); + + initlogger(configDir); + logger.info("initlogger returned"); + + // invoke 'globalInit' on all of the features + for (FeatureAPI feature : FeatureAPI.impl.getList()) + { + feature.globalInit(args, configDir); + } + } + + /** + * Read in the logger properties + */ + private static void initlogger(String configDir){ + try { + Properties properties = + PropertyUtil.getProperties(configDir + "/policyLogger.properties"); + try { + + PolicyLogger.init(properties); + + } catch (Exception e) { + logger.error(MessageCodes.MISS_PROPERTY_ERROR, e, "initlogger"); + } + } catch (IOException e1) { + logger.error(MessageCodes.MISS_PROPERTY_ERROR, e1, "initlogger"); + } + } + + /** + * Fetch the adjunct object associated with a given feature + * + * @param object this is typically the singleton feature object that is + * used as a key, but it might also be useful to use nested objects + * within the feature as keys. + * @return a feature-specific object associated with the key, or 'null' + * if it is not found. + */ + public Object getAdjunct(Object object) + { + return(adjuncts.get(object)); + } + + /** + * Store the adjunct object associated with a given feature + * + * @param object this is typically the singleton feature object that is + * used as a key, but it might also be useful to use nested objects + * within the feature as keys. + * @param value a feature-specific object associated with the key, or 'null' + * if the feature-specific object should be removed + */ + public void setAdjunct(Object object, Object value) + { + if (value == null) + { + adjuncts.remove(object); + } + else + { + adjuncts.put(object, value); + } + } +} diff --git a/policy-core/src/main/java/org/openecomp/policy/drools/core/PolicySession.java b/policy-core/src/main/java/org/openecomp/policy/drools/core/PolicySession.java new file mode 100644 index 00000000..89341d6b --- /dev/null +++ b/policy-core/src/main/java/org/openecomp/policy/drools/core/PolicySession.java @@ -0,0 +1,349 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.core; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Properties; + +import org.kie.api.runtime.KieSession; +import org.kie.api.event.rule.AfterMatchFiredEvent; +import org.kie.api.event.rule.AgendaEventListener; +import org.kie.api.event.rule.AgendaGroupPoppedEvent; +import org.kie.api.event.rule.AgendaGroupPushedEvent; +import org.kie.api.event.rule.BeforeMatchFiredEvent; +import org.kie.api.event.rule.MatchCancelledEvent; +import org.kie.api.event.rule.MatchCreatedEvent; +import org.kie.api.event.rule.ObjectDeletedEvent; +import org.kie.api.event.rule.ObjectInsertedEvent; +import org.kie.api.event.rule.ObjectUpdatedEvent; +import org.kie.api.event.rule.RuleRuntimeEventListener; +import org.kie.api.event.rule.RuleFlowGroupActivatedEvent; +import org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent; + +import org.openecomp.policy.drools.core.jmx.PdpJmx; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.common.logging.eelf.MessageCodes; + +/** + * This class is a wrapper around 'KieSession', which adds the following: + * + * 1) A thread running 'KieSession.fireUntilHalt()' + * 2) Access to UEB + * 3) Logging of events + */ +public class PolicySession + implements AgendaEventListener, RuleRuntimeEventListener +{ + // get an instance of logger + private static Logger logger = FlexLogger.getLogger(PolicySession.class); + // name of the 'PolicySession' and associated 'KieSession' + private String name; + + // the associated 'PolicyContainer', which may have additional + // 'PolicySession' instances in addition to this one + private PolicyContainer container; + + // associated 'KieSession' instance + private KieSession kieSession; + + // if not 'null', this is the thread running 'kieSession.fireUntilHalt()' + private Thread thread = null; + + // supports 'getCurrentSession()' method + static private ThreadLocal policySession = + new ThreadLocal(); + + /** + * Internal constructor - create a 'PolicySession' instance + * + * @param name the name of this 'PolicySession' (and 'kieSession') + * @param container the 'PolicyContainer' instance containing this session + * @param kieSession the associated 'KieSession' instance + */ + protected PolicySession(String name, + PolicyContainer container, KieSession kieSession) + { + this.name = name; + this.container = container; + this.kieSession = kieSession; + kieSession.addEventListener((AgendaEventListener)this); + kieSession.addEventListener((RuleRuntimeEventListener)this); + } + + /** + * @return the 'PolicyContainer' object containing this session + */ + public PolicyContainer getPolicyContainer() + { + return(container); + } + + /** + * @return the associated 'KieSession' instance + */ + public KieSession getKieSession() + { + return(kieSession); + } + + /** + * @return the local name of this session, which should either match the + * name specified in 'kmodule.xml' file associated with this session, or the + * name passed on the 'PolicyContainer.adoptKieSession' method. + */ + public String getName() + { + return(name); + } + + /** + * @return the 'PolicyContainer' name, followed by ':', followed by the + * local name of the session. It should be useful in log messages. + */ + public String getFullName() + { + return(container.getName() + ":" + name); + } + + /** + * this starts a separate thread, which invokes 'KieSession.fireUntilHalt()'. + * It does nothing if the thread already exists. + */ + public synchronized void startThread() + { + if (thread == null) + { + logger.info("startThread with name " + getFullName()); + thread = new Thread("Session " + getFullName()) + { + public void run() + { + // set thread local variable + policySession.set(PolicySession.this); + + // We want to continue, despite any exceptions that occur + // while rules are fired. + boolean repeat = true; + while (repeat) + { + if(this.isInterrupted()){ + break; + } + try + { + kieSession.fireAllRules(); + + } + catch (Throwable e) + { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "startThread", "kieSession.fireUntilHalt"); + } + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + break; + } + } + logger.info("fireUntilHalt() returned"); + } + }; + thread.start(); + } + } + + /** + * if a thread is currently running, this invokes 'KieSession.halt()' to + * stop it. + */ + public synchronized void stopThread() + { + if (thread != null) + { + // this should cause the thread to exit + thread.interrupt(); + try + { + // wait for the thread to stop + thread.join(); + } + catch (Exception e) + { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "stopThread", "thread.join"); + } + thread = null; + } + } + + /** + * @return the 'PolicySession' instance associated with the current thread + * (Note that this only works if the current thread is the one running + * 'kieSession.fireUntilHalt()'.) + */ + public static PolicySession getCurrentSession() + { + return(policySession.get()); + } + + /***********************************/ + /* 'AgendaEventListener' interface */ + /***********************************/ + + /** + * {@inheritDoc} + */ + @Override + public void afterMatchFired(AfterMatchFiredEvent event) + { + logger.debug("afterMatchFired: " + getFullName() + + ": AgendaEventListener.afterMatchFired(" + event + ")"); + PdpJmx.getInstance().ruleFired(); + } + + /** + * {@inheritDoc} + */ + @Override + public void afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) + { + logger.debug("afterRuleFlowGroupActivated: " + getFullName() + + ": AgendaEventListener.afterRuleFlowGroupActivated(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void afterRuleFlowGroupDeactivated + (RuleFlowGroupDeactivatedEvent event) + { + logger.debug("afterRuleFlowGroupDeactivated: " + getFullName() + + ": AgendaEventListener.afterRuleFlowGroupDeactivated(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void agendaGroupPopped(AgendaGroupPoppedEvent event) + { + logger.debug("agendaGroupPopped: " + getFullName() + + ": AgendaEventListener.agendaGroupPopped(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void agendaGroupPushed(AgendaGroupPushedEvent event) + { + logger.debug("agendaGroupPushed: " + getFullName() + + ": AgendaEventListener.agendaGroupPushed(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void beforeMatchFired(BeforeMatchFiredEvent event) + { + logger.debug("beforeMatchFired: " + getFullName() + + ": AgendaEventListener.beforeMatchFired(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void beforeRuleFlowGroupActivated + (RuleFlowGroupActivatedEvent event) + { + logger.debug("beforeRuleFlowGroupActivated: " + getFullName() + + ": AgendaEventListener.beforeRuleFlowGroupActivated(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void beforeRuleFlowGroupDeactivated + (RuleFlowGroupDeactivatedEvent event) + { + logger.debug("beforeRuleFlowGroupDeactivated: " + getFullName() + + ": AgendaEventListener.beforeRuleFlowGroupDeactivated(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void matchCancelled(MatchCancelledEvent event) + { + logger.debug("matchCancelled: " + getFullName() + + ": AgendaEventListener.matchCancelled(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void matchCreated(MatchCreatedEvent event) + { + logger.debug("matchCreated: " + getFullName() + + ": AgendaEventListener.matchCreated(" + event + ")"); + } + + /****************************************/ + /* 'RuleRuntimeEventListener' interface */ + /****************************************/ + + /** + * {@inheritDoc} + */ + @Override + public void objectDeleted(ObjectDeletedEvent event) + { + logger.debug("objectDeleted: " + getFullName() + + ": AgendaEventListener.objectDeleted(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void objectInserted(ObjectInsertedEvent event) + { + logger.debug("objectInserted: " + getFullName() + + ": AgendaEventListener.objectInserted(" + event + ")"); + } + + /** + * {@inheritDoc} + */ + @Override + public void objectUpdated(ObjectUpdatedEvent event) + { + logger.debug("objectUpdated: " + getFullName() + + ": AgendaEventListener.objectUpdated(" + event + ")"); + } +} diff --git a/policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmx.java b/policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmx.java new file mode 100644 index 00000000..7fa0dd0a --- /dev/null +++ b/policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmx.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.core.jmx; + +import java.util.concurrent.atomic.AtomicLong; + +public class PdpJmx implements PdpJmxMBean { + + private static PdpJmx instance = new PdpJmx(); + private final AtomicLong updates = new AtomicLong(); + private final AtomicLong actions = new AtomicLong(); + + public static PdpJmx getInstance() { + return instance; + } + + public long getUpdates(){ + return updates.longValue(); + } + public long getRulesFired(){ + return actions.longValue(); + } + public void updateOccured(){ + updates.incrementAndGet(); + } + public void ruleFired(){ + actions.incrementAndGet(); + } +} diff --git a/policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmxListener.java b/policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmxListener.java new file mode 100644 index 00000000..4b48da07 --- /dev/null +++ b/policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmxListener.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.core.jmx; + +import java.lang.management.ManagementFactory; + +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanRegistrationException; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.NotCompliantMBeanException; +import javax.management.ObjectName; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.common.logging.eelf.MessageCodes; + +public class PdpJmxListener { + + public static final Logger logger = FlexLogger.getLogger(PdpJmxListener.class); + + public static void stop() { + final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + try { + server.unregisterMBean(new ObjectName("PolicyEngine:type=PdpJmx")); + } catch (MBeanRegistrationException | InstanceNotFoundException + | MalformedObjectNameException e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PdpJmxListener.stop()", "Could not unregister PolicyEngine:type=PdpJmx MBean with the MBean server"); + } + + } + + + public static void start() { + final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + try { + server.registerMBean(PdpJmx.getInstance(), new ObjectName("PolicyEngine:type=PdpJmx")); + } catch (InstanceAlreadyExistsException | MBeanRegistrationException + | NotCompliantMBeanException | MalformedObjectNameException e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PdpJmxListener.start()", "Could not register PolicyEngine:type=PdpJmx MBean with the MBean server"); + } + + } + +} diff --git a/policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmxMBean.java b/policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmxMBean.java new file mode 100644 index 00000000..a947e82b --- /dev/null +++ b/policy-core/src/main/java/org/openecomp/policy/drools/core/jmx/PdpJmxMBean.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.core.jmx; + +public interface PdpJmxMBean { + + public long getRulesFired(); + public long getUpdates(); +} diff --git a/policy-core/src/main/java/org/openecomp/policy/drools/properties/Lockable.java b/policy-core/src/main/java/org/openecomp/policy/drools/properties/Lockable.java new file mode 100644 index 00000000..fd8681c3 --- /dev/null +++ b/policy-core/src/main/java/org/openecomp/policy/drools/properties/Lockable.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.properties; + +/** + * Marks a entity as able to lock and unlock. + */ +public interface Lockable { + + /** + * locks this entity + * @return true is the lock operation was successful, false otherwise + */ + public boolean lock(); + + /** + * unlocks this entity + * @return true is the unlock operation was successful, false otherwise + */ + public boolean unlock(); + + /** + * is this entity locked? + * @return true if the entity is in a locked state, false otherwise + */ + public boolean isLocked(); +} diff --git a/policy-core/src/main/java/org/openecomp/policy/drools/properties/PolicyProperties.java b/policy-core/src/main/java/org/openecomp/policy/drools/properties/PolicyProperties.java new file mode 100644 index 00000000..13580219 --- /dev/null +++ b/policy-core/src/main/java/org/openecomp/policy/drools/properties/PolicyProperties.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.properties; + +public interface PolicyProperties { + + /* Controller Properties */ + + public static final String PROPERTY_CONTROLLER_NAME = "controller.name"; + + /* Generic property suffixes */ + + public static final String PROPERTY_TOPIC_SERVERS_SUFFIX = ".servers"; + public static final String PROPERTY_TOPIC_API_KEY_SUFFIX = ".apiKey"; + public static final String PROPERTY_TOPIC_API_SECRET_SUFFIX = ".apiSecret"; + public static final String PROPERTY_TOPIC_AAF_MECHID_SUFFIX = ".aafMechId"; + public static final String PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX = ".aafPassword"; + public static final String PROPERTY_TOPIC_EVENTS_SUFFIX =".events"; + public static final String PROPERTY_TOPIC_EVENTS_FILTER_SUFFIX =".filter"; + public static final String PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_GSON_SUFFIX =".events.custom.gson"; + public static final String PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_JACKSON_SUFFIX =".events.custom.jackson"; + + public static final String PROPERTY_TOPIC_SOURCE_CONSUMER_GROUP_SUFFIX = ".consumerGroup"; + public static final String PROPERTY_TOPIC_SOURCE_CONSUMER_INSTANCE_SUFFIX = ".consumerInstance"; + public static final String PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX = ".fetchTimeout"; + public static final String PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX = ".fetchLimit"; + public static final String PROPERTY_MANAGED_SUFFIX =".managed"; + + public static final String PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX =".partitionKey"; + + /* UEB Properties */ + + public static final String PROPERTY_UEB_SOURCE_TOPICS = "ueb.source.topics"; + public static final String PROPERTY_UEB_SINK_TOPICS = "ueb.sink.topics"; + + /* DMAAP Properties */ + + public static final String PROPERTY_DMAAP_SOURCE_TOPICS = "dmaap.source.topics"; + public static final String PROPERTY_DMAAP_SINK_TOPICS = "dmaap.sink.topics"; + + /* HTTP Server Properties */ + + public static final String PROPERTY_HTTP_SERVER_SERVICES = "http.server.services"; + + public static final String PROPERTY_HTTP_HOST_SUFFIX = ".host"; + public static final String PROPERTY_HTTP_PORT_SUFFIX = ".port"; + public static final String PROPERTY_HTTP_CONTEXT_URIPATH_SUFFIX = ".contextUriPath"; + + public static final String PROPERTY_HTTP_AUTH_USERNAME_SUFFIX = ".userName"; + public static final String PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX = ".password"; + public static final String PROPERTY_HTTP_AUTH_URIPATH_SUFFIX = ".authUriPath"; + + public static final String PROPERTY_HTTP_REST_CLASSES_SUFFIX = ".restClasses"; + public static final String PROPERTY_HTTP_REST_PACKAGES_SUFFIX = ".restPackages"; + public static final String PROPERTY_HTTP_REST_URIPATH_SUFFIX = ".restUriPath"; + + public static final String PROPERTY_HTTP_HTTPS_SUFFIX = ".https"; + + /* HTTP Client Properties */ + + public static final String PROPERTY_HTTP_CLIENT_SERVICES = "http.client.services"; + + public static final String PROPERTY_HTTP_URL_SUFFIX = PROPERTY_HTTP_CONTEXT_URIPATH_SUFFIX; + + /* Drools Properties */ + + public static final String RULES_GROUPID = "rules.groupId"; + public static final String RULES_ARTIFACTID = "rules.artifactId"; + public static final String RULES_VERSION = "rules.version"; + + /* Management Server Properties */ + + public static final String ENV_MANAGEMENT_SERVER_PORT = "ENGINE_MANAGEMENT_PORT"; + public static final String ENV_MANAGEMENT_SERVER_HOST = "ENGINE_MANAGEMENT_HOST"; + public static final String ENV_MANAGEMENT_AUTH_USER = "ENGINE_MANAGEMENT_USER"; + public static final String ENV_MANAGEMENT_AUTH_PASSWD = "ENGINE_MANAGEMENT_PASSWORD"; + +} diff --git a/policy-core/src/main/java/org/openecomp/policy/drools/properties/Startable.java b/policy-core/src/main/java/org/openecomp/policy/drools/properties/Startable.java new file mode 100644 index 00000000..bb6334a2 --- /dev/null +++ b/policy-core/src/main/java/org/openecomp/policy/drools/properties/Startable.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.properties; + +/** + * Declares the Startable property of any class class implementing + * this interface. This implies that the implementing class supports + * start-like operations. + */ +public interface Startable { + + /** + * Start operation. This operation starts the entity. + * + * @return boolean. true if the start operation was successful, + * otherwise false. + * @throws IllegalStateException. if the element is in a state that + * conflicts with the start operation. + */ + public boolean start() throws IllegalStateException; + + /** + * Stop operation. The entity can be restarted again by invoking + * the start operation. + * + * @return boolean. true if the stop operation was successful, + * otherwise false. + * @throws IllegalStateException. if the element is in a state that + * conflicts with the stop operation. + */ + public boolean stop()throws IllegalStateException; + + /** + * shutdown operation. The terminate operation yields the entity + * unusuable. It cannot be (re)started. + * + * @throws IllegalStateException. if the element is in a state that + * conflicts with the stop operation. + */ + public void shutdown()throws IllegalStateException; + + /** + * is it alive? + * @return boolean. true if alive, otherwise false + */ + public boolean isAlive(); +} diff --git a/policy-core/src/main/resources/META-INF/jndi.properties b/policy-core/src/main/resources/META-INF/jndi.properties new file mode 100644 index 00000000..033a08aa --- /dev/null +++ b/policy-core/src/main/resources/META-INF/jndi.properties @@ -0,0 +1,21 @@ +### +# ============LICENSE_START======================================================= +# policy-core +# ================================================================================ +# Copyright (C) 2017 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory diff --git a/policy-core/src/main/resources/META-INF/persistence.xml b/policy-core/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000..34685b0e --- /dev/null +++ b/policy-core/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,70 @@ + + + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + org.openecomp.policy.common.im.jpa.StateManagementEntity + org.openecomp.policy.drools.persistence.DroolsPdpEntity + org.openecomp.policy.drools.persistence.DroolsSessionEntity + org.drools.persistence.info.SessionInfo + org.drools.persistence.info.WorkItemInfo + org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + org.drools.persistence.info.SessionInfo + org.drools.persistence.info.WorkItemInfo + + + + + + + + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + org.drools.persistence.info.SessionInfo + org.drools.persistence.info.WorkItemInfo + org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity + + + + + + + + diff --git a/policy-endpoints/pom.xml b/policy-endpoints/pom.xml new file mode 100644 index 00000000..e62853c5 --- /dev/null +++ b/policy-endpoints/pom.xml @@ -0,0 +1,157 @@ + + + + + 4.0.0 + + + org.openecomp.policy.drools-pdp + drools-pdp + 1.0.0-SNAPSHOT + + + policy-endpoints + + policy-endpoints + Policy UEB support + + + 1.8 + 1.8 + 0.0.1 + 0.2.12 + 9.3.14.v20161028 + 2.22.1 + 2.8.4 + + + + + + com.att.nsa + cambriaClient + ${cambria.version} + + + org.slf4j + slf4j-log4j12 + + + com.att.nsa + saClientLibrary + + + + + com.att.nsa + dmaapClient + ${dmaap.version} + + + org.slf4j + slf4j-log4j12 + + + + + org.eclipse.jetty + jetty-server + ${jetty.version} + + + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + + + + org.glassfish.jersey.core + jersey-server + ${jersey.version} + + + + org.glassfish.jersey.containers + jersey-container-servlet-core + ${jersey.version} + + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + + + + org.glassfish.jersey.containers + jersey-container-jetty-http + ${jersey.version} + + + org.eclipse.jetty + jetty-util + + + + + + org.glassfish.jersey.core + jersey-client + ${jersey.version} + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + + + + org.apache.httpcomponents + httpcore + 4.4.4 + + + org.apache.httpcomponents + httpclient + 4.5 + + + org.apache.commons + commons-collections4 + 4.1 + + + org.openecomp.policy.drools-pdp + policy-core + 1.0.0-SNAPSHOT + + + + diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/Topic.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/Topic.java new file mode 100644 index 00000000..d38bab5a --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/Topic.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm; + +import java.util.List; + +/** + * Essential Topic Data + */ +public interface Topic { + + public static final String NETWORK_LOGGER = "networkLogger"; + + /** + * Underlying Communication infrastructure Types + */ + public enum CommInfrastructure { + /** + * UEB Communication Infrastructure + */ + UEB, + /** + * DMAAP Communication Infrastructure + */ + DMAAP, + /** + * REST Communication Infrastructure + */ + REST + } + + /** + * gets the topic name + * + * @return topic name + */ + public String getTopic(); + + /** + * gets the communication infrastructure type + * @return + */ + public CommInfrastructure getTopicCommInfrastructure(); + + /** + * return list of servers + * @return bus servers + */ + public List getServers(); + + /** + * get the more recent events in this topic entity + * + * @return list of most recent events + */ + public String[] getRecentEvents(); + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicEndpoint.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicEndpoint.java new file mode 100644 index 00000000..b3f236f7 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicEndpoint.java @@ -0,0 +1,692 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSink; +import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSource; +import org.openecomp.policy.drools.event.comm.bus.UebTopicSink; +import org.openecomp.policy.drools.event.comm.bus.UebTopicSource; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.drools.properties.Lockable; +import org.openecomp.policy.drools.properties.Startable; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * Abstraction to managed the system's Networked Topic Endpoints, + * sources of all events input into the System. + */ +public interface TopicEndpoint extends Startable, Lockable { + + /** + * Add Topic Sources to the communication infrastructure initialized per + * properties + * + * @param properties properties for Topic Source construction + * @return a generic Topic Source + * @throws IllegalArgumentException when invalid arguments are provided + */ + public List addTopicSources(Properties properties) + throws IllegalArgumentException; + + /** + * Add Topic Sinks to the communication infrastructure initialized per + * properties + * + * @param properties properties for Topic Sink construction + * @return a generic Topic Sink + * @throws IllegalArgumentException when invalid arguments are provided + */ + public List addTopicSinks(Properties properties) + throws IllegalArgumentException; + + /** + * gets all Topic Sources + * @return the Topic Source List + */ + List getTopicSources(); + + /** + * get the Topic Sources for the given topic name + * + * @param topicName the topic name + * + * @return the Topic Source List + * @throws IllegalStateException if the entity is in an invalid state + * @throws IllegalArgumentException if invalid parameters are present + */ + public List getTopicSources(List topicNames) + throws IllegalStateException, IllegalArgumentException; + + /** + * gets the Topic Source for the given topic name and + * underlying communication infrastructure type + * + * @param commType communication infrastructure type + * @param topicName the topic name + * + * @return the Topic Source + * @throws IllegalStateException if the entity is in an invalid state, for + * example multiple TopicReaders for a topic name and communication infrastructure + * @throws IllegalArgumentException if invalid parameters are present + * @throws UnsupportedOperationException if the operation is not supported. + */ + public TopicSource getTopicSource(Topic.CommInfrastructure commType, + String topicName) + throws IllegalStateException, IllegalArgumentException, + UnsupportedOperationException; + + /** + * get the UEB Topic Source for the given topic name + * + * @param topicName the topic name + * + * @return the UEB Topic Source + * @throws IllegalStateException if the entity is in an invalid state, for + * example multiple TopicReaders for a topic name and communication infrastructure + * @throws IllegalArgumentException if invalid parameters are present + */ + public UebTopicSource getUebTopicSource(String topicName) + throws IllegalStateException, IllegalArgumentException; + + /** + * get the DMAAP Topic Source for the given topic name + * + * @param topicName the topic name + * + * @return the DMAAP Topic Source + * @throws IllegalStateException if the entity is in an invalid state, for + * example multiple TopicReaders for a topic name and communication infrastructure + * @throws IllegalArgumentException if invalid parameters are present + */ + public DmaapTopicSource getDmaapTopicSource(String topicName) + throws IllegalStateException, IllegalArgumentException; + + /** + * get the Topic Sinks for the given topic name + * + * @param topicNames the topic names + * @return the Topic Sink List + * @throws IllegalStateException + * @throws IllegalArgumentException + */ + public List getTopicSinks(List topicNames) + throws IllegalStateException, IllegalArgumentException; + + /** + * get the Topic Sinks for the given topic name and + * underlying communication infrastructure type + * + * @param topicName the topic name + * @param commType communication infrastructure type + * + * @return the Topic Sink List + * @throws IllegalStateException if the entity is in an invalid state, for + * example multiple TopicWriters for a topic name and communication infrastructure + * @throws IllegalArgumentException if invalid parameters are present + */ + public TopicSink getTopicSink(Topic.CommInfrastructure commType, + String topicName) + throws IllegalStateException, IllegalArgumentException, + UnsupportedOperationException; + + /** + * get the Topic Sinks for the given topic name and + * all the underlying communication infrastructure type + * + * @param topicName the topic name + * @param commType communication infrastructure type + * + * @return the Topic Sink List + * @throws IllegalStateException if the entity is in an invalid state, for + * example multiple TopicWriters for a topic name and communication infrastructure + * @throws IllegalArgumentException if invalid parameters are present + */ + public List getTopicSinks(String topicName) + throws IllegalStateException, IllegalArgumentException; + + /** + * get the UEB Topic Source for the given topic name + * + * @param topicName the topic name + * + * @return the Topic Source + * @throws IllegalStateException if the entity is in an invalid state, for + * example multiple TopicReaders for a topic name and communication infrastructure + * @throws IllegalArgumentException if invalid parameters are present + */ + public UebTopicSink getUebTopicSink(String topicName) + throws IllegalStateException, IllegalArgumentException; + + /** + * get the DMAAP Topic Source for the given topic name + * + * @param topicName the topic name + * + * @return the Topic Source + * @throws IllegalStateException if the entity is in an invalid state, for + * example multiple TopicReaders for a topic name and communication infrastructure + * @throws IllegalArgumentException if invalid parameters are present + */ + public DmaapTopicSink getDmaapTopicSink(String topicName) + throws IllegalStateException, IllegalArgumentException; + + /** + * gets only the UEB Topic Sources + * @return the UEB Topic Source List + */ + public List getUebTopicSources(); + + /** + * gets only the DMAAP Topic Sources + * @return the DMAAP Topic Source List + */ + public List getDmaapTopicSources(); + + /** + * gets all Topic Sinks + * @return the Topic Sink List + */ + public List getTopicSinks(); + + /** + * gets only the UEB Topic Sinks + * @return the UEB Topic Sink List + */ + public List getUebTopicSinks(); + + /** + * gets only the DMAAP Topic Sinks + * @return the DMAAP Topic Sink List + */ + public List getDmaapTopicSinks(); + + /** + * singleton for global access + */ + public static final TopicEndpoint manager = new ProxyTopicEndpointManager(); +} + +/* + * ----------------- implementation ------------------- + */ + +/** + * This implementation of the Topic Endpoint Manager, proxies operations to appropriate + * implementations according to the communication infrastructure that are supported + */ +class ProxyTopicEndpointManager implements TopicEndpoint { + // get an instance of logger + private static Logger logger = FlexLogger.getLogger(ProxyTopicEndpointManager.class); + /** + * Is this element locked? + */ + protected volatile boolean locked = false; + + /** + * Is this element alive? + */ + protected volatile boolean alive = false; + + /** + * {@inheritDoc} + */ + @Override + public List addTopicSources(Properties properties) throws IllegalArgumentException { + + // 1. Create UEB Sources + // 2. Create DMAAP Sources + + List sources = new ArrayList(); + + sources.addAll(UebTopicSource.factory.build(properties)); + sources.addAll(DmaapTopicSource.factory.build(properties)); + + if (this.isLocked()) { + for (TopicSource source : sources) { + source.lock(); + } + } + + return sources; + } + + /** + * {@inheritDoc} + */ + @Override + public List addTopicSinks(Properties properties) throws IllegalArgumentException { + // 1. Create UEB Sinks + // 2. Create DMAAP Sinks + + List sinks = new ArrayList(); + + sinks.addAll(UebTopicSink.factory.build(properties)); + sinks.addAll(DmaapTopicSink.factory.build(properties)); + + if (this.isLocked()) { + for (TopicSink sink : sinks) { + sink.lock(); + } + } + + return sinks; + } + + /** + * {@inheritDoc} + */ + @Override + public List getTopicSources() { + + List sources = new ArrayList(); + + sources.addAll(UebTopicSource.factory.inventory()); + sources.addAll(DmaapTopicSource.factory.inventory()); + + return sources; + } + + /** + * {@inheritDoc} + */ + @Override + public List getTopicSinks() { + + List sinks = new ArrayList(); + + sinks.addAll(UebTopicSink.factory.inventory()); + sinks.addAll(DmaapTopicSink.factory.inventory()); + + return sinks; + } + + /** + * {@inheritDoc} + */ + @JsonIgnore + @Override + public List getUebTopicSources() { + return UebTopicSource.factory.inventory(); + } + + /** + * {@inheritDoc} + */ + @JsonIgnore + @Override + public List getDmaapTopicSources() { + return DmaapTopicSource.factory.inventory(); + } + + /** + * {@inheritDoc} + */ + @JsonIgnore + @Override + public List getUebTopicSinks() { + return UebTopicSink.factory.inventory(); + } + + /** + * {@inheritDoc} + */ + @JsonIgnore + @Override + public List getDmaapTopicSinks() { + return DmaapTopicSink.factory.inventory(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean start() throws IllegalStateException { + + synchronized (this) { + if (this.locked) { + throw new IllegalStateException(this + " is locked"); + } + + if (this.alive) { + return true; + } + + this.alive = true; + } + + List endpoints = getEndpoints(); + + boolean success = true; + for (Startable endpoint: endpoints) { + try { + success = endpoint.start() && success; + } catch (Exception e) { + success = false; + logger.error(MessageCodes.EXCEPTION_ERROR, e, endpoint.toString(), this.toString()); + } + } + + return success; + } + + + /** + * {@inheritDoc} + */ + @Override + public boolean stop() throws IllegalStateException { + + /* + * stop regardless if it is locked, in other + * words, stop operation has precedence over + * locks. + */ + synchronized (this) { + this.alive = false; + } + + List endpoints = getEndpoints(); + + boolean success = true; + for (Startable endpoint: endpoints) { + try { + success = endpoint.stop() && success; + } catch (Exception e) { + success = false; + logger.error(MessageCodes.EXCEPTION_ERROR, e, endpoint.toString(), this.toString()); + } + } + + return success; + } + + /** + * + * @return list of managed endpoints + */ + @JsonIgnore + protected List getEndpoints() { + List endpoints = new ArrayList(); + + endpoints.addAll(this.getTopicSources()); + endpoints.addAll(this.getTopicSinks()); + + return endpoints; + } + + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() throws IllegalStateException { + UebTopicSource.factory.destroy(); + UebTopicSink.factory.destroy(); + + DmaapTopicSource.factory.destroy(); + DmaapTopicSink.factory.destroy(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAlive() { + return this.alive; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean lock() { + + synchronized (this) { + if (locked) + return true; + + this.locked = true; + } + + for (TopicSource source: this.getTopicSources()) { + source.lock(); + } + + for (TopicSink sink: this.getTopicSinks()) { + sink.lock(); + } + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean unlock() { + synchronized (this) { + if (!locked) + return true; + + this.locked = false; + } + + for (TopicSource source: this.getTopicSources()) { + source.unlock(); + } + + for (TopicSink sink: this.getTopicSinks()) { + sink.unlock(); + } + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLocked() { + return this.locked; + } + + /** + * {@inheritDoc} + */ + @Override + public List getTopicSources(List topicNames) + throws IllegalStateException, IllegalArgumentException { + + if (topicNames == null) { + throw new IllegalArgumentException("must provide a list of topics"); + } + + List sources = new ArrayList(); + for (String topic: topicNames) { + try { + TopicSource uebSource = this.getUebTopicSource(topic); + if (uebSource != null) + sources.add(uebSource); + } catch (Exception e) { + logger.info("No UEB source for topic: " + topic); + } + + try { + TopicSource dmaapSource = this.getDmaapTopicSource(topic); + if (dmaapSource != null) + sources.add(dmaapSource); + } catch (Exception e) { + logger.info("No DMAAP source for topic: " + topic); + } + } + return sources; + } + + /** + * {@inheritDoc} + */ + @Override + public List getTopicSinks(List topicNames) + throws IllegalStateException, IllegalArgumentException { + + if (topicNames == null) { + throw new IllegalArgumentException("must provide a list of topics"); + } + + List sinks = new ArrayList(); + for (String topic: topicNames) { + try { + TopicSink uebSink = this.getUebTopicSink(topic); + if (uebSink != null) + sinks.add(uebSink); + } catch (Exception e) { + logger.info("No UEB sink for topic: " + topic); + } + + try { + TopicSink dmaapSink = this.getDmaapTopicSink(topic); + if (dmaapSink != null) + sinks.add(dmaapSink); + } catch (Exception e) { + logger.info("No DMAAP sink for topic: " + topic); + } + } + return sinks; + } + + /** + * {@inheritDoc} + */ + @Override + public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName) + throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { + + if (commType == null) { + throw new IllegalArgumentException + ("Invalid parameter: a communication infrastructure required to fetch " + topicName); + } + + if (topicName == null) { + throw new IllegalArgumentException + ("Invalid parameter: a communication infrastructure required to fetch " + topicName); + } + + switch (commType) { + case UEB: + return this.getUebTopicSource(topicName); + case DMAAP: + return this.getDmaapTopicSource(topicName); + case REST: + default: + throw new UnsupportedOperationException("Unsupported " + commType.name()); + } + } + + /** + * {@inheritDoc} + */ + @Override + public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName) + throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { + if (commType == null) { + throw new IllegalArgumentException + ("Invalid parameter: a communication infrastructure required to fetch " + topicName); + } + + if (topicName == null) { + throw new IllegalArgumentException + ("Invalid parameter: a communication infrastructure required to fetch " + topicName); + } + + switch (commType) { + case UEB: + return this.getUebTopicSink(topicName); + case DMAAP: + return this.getDmaapTopicSink(topicName); + case REST: + default: + throw new UnsupportedOperationException("Unsupported " + commType.name()); + } + } + + /** + * {@inheritDoc} + */ + @Override + public List getTopicSinks(String topicName) + throws IllegalStateException, IllegalArgumentException { + + if (topicName == null) { + throw new IllegalArgumentException + ("Invalid parameter: a communication infrastructure required to fetch " + topicName); + } + + List sinks = new ArrayList(); + + try { + sinks.add(this.getUebTopicSink(topicName)); + } catch (Exception e) { + ; + } + + try { + sinks.add(this.getDmaapTopicSink(topicName)); + } catch (Exception e) { + ; + } + + return sinks; + } + + /** + * {@inheritDoc} + */ + @Override + public UebTopicSource getUebTopicSource(String topicName) throws IllegalStateException, IllegalArgumentException { + return UebTopicSource.factory.get(topicName); + } + + /** + * {@inheritDoc} + */ + @Override + public UebTopicSink getUebTopicSink(String topicName) throws IllegalStateException, IllegalArgumentException { + return UebTopicSink.factory.get(topicName); + } + + @Override + public DmaapTopicSource getDmaapTopicSource(String topicName) + throws IllegalStateException, IllegalArgumentException { + return DmaapTopicSource.factory.get(topicName); + } + + @Override + public DmaapTopicSink getDmaapTopicSink(String topicName) throws IllegalStateException, IllegalArgumentException { + return DmaapTopicSink.factory.get(topicName); + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicListener.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicListener.java new file mode 100644 index 00000000..7a2e9711 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicListener.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm; + +/** + * Listener for event messages entering the Policy Engine + */ +public interface TopicListener { + + /** + * Notification of a new Event over a given Topic + * + * @param commType communication infrastructure type + * @param topic topic name + * @param event event message as a string + * + * @return boolean. True if the invoking event dispatcher should continue + * dispatching the event to subsequent listeners. False if it is requested + * to the invoking event dispatcher to stop dispatching the same event to + * other listeners of less priority. This mechanism is generally not used. + */ + public boolean onTopicEvent(Topic.CommInfrastructure commType, String topic, String event); + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicRegisterable.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicRegisterable.java new file mode 100644 index 00000000..2ce8e9e7 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicRegisterable.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm; + +/** + * Marks a Topic entity as registerable + */ +public interface TopicRegisterable { + + /** + * Register for notification of events with this Topic Entity + * + * @param topicListener the listener of events + */ + public void register(TopicListener topicListener); + + /** + * Unregisters for notification of events with this Topic Entity + * + * @param topicListener the listener of events + */ + public void unregister(TopicListener topicListener); + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicSink.java new file mode 100644 index 00000000..2250b1ea --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicSink.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm; + +import org.openecomp.policy.drools.properties.Lockable; +import org.openecomp.policy.drools.properties.Startable; + +/** + * Marks a given Topic Endpoint as able to send messages over a topic + */ +public interface TopicSink extends Topic, Startable, Lockable { + + /** + * Sends a string message over this Topic Endpoint + * + * @param message message to send + * @return true if the send operation succeeded, false otherwise + * @throws IllegalArgumentException an invalid message has been provided + * @throws IllegalStateException the entity is in an state that prevents + * it from sending messages, for example, locked or stopped. + */ + public boolean send(String message) throws IllegalArgumentException, IllegalStateException; + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicSource.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicSource.java new file mode 100644 index 00000000..0dfbe1c4 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/TopicSource.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm; + +import org.openecomp.policy.drools.properties.Lockable; +import org.openecomp.policy.drools.properties.Startable; + +/** + * Marker for a Topic Entity, indicating that the entity is able to read + * over a topic + */ +public interface TopicSource extends TopicRegisterable, Topic, Startable, Lockable { + + /** + * pushes an event into the source programatically + * + * @param event the event in json format + * @return true if it can be processed correctly, false otherwise + */ + public boolean offer(String event); + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopic.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopic.java new file mode 100644 index 00000000..c38f627e --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopic.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +public interface BusTopic { + public String getApiKey(); + public String getApiSecret(); +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopicSink.java new file mode 100644 index 00000000..30978c27 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopicSink.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +import org.openecomp.policy.drools.event.comm.TopicSink; + +/** + * Topic Sink over Bus Infrastructure (DMAAP/UEB) + */ +public interface BusTopicSink extends BusTopic, TopicSink { + /** + * Log Failures after X number of retries + */ + public static final int DEFAULT_LOG_SEND_FAILURES_AFTER = 1; + + /** + * Sets the UEB partition key for published messages + * + * @param partitionKey the partition key + */ + public void setPartitionKey(String partitionKey); + + /** + * return the partition key in used by the system to publish messages + * + * @return the partition key + */ + public String getPartitionKey(); +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopicSource.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopicSource.java new file mode 100644 index 00000000..e6a46d2f --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/BusTopicSource.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +import org.openecomp.policy.drools.event.comm.TopicSource; + +/** + * Generic Topic Source for UEB/DMAAP Communication Infrastructure + * + */ +public interface BusTopicSource extends BusTopic, TopicSource { + + /** + * Default Consumer Instance Value + */ + public static String DEFAULT_CONSUMER_INSTANCE = "0"; + + /** + * Default Timeout fetching in milliseconds + */ + public static int DEFAULT_TIMEOUT_MS_FETCH = 15000; + + /** + * Default maximum number of messages fetch at the time + */ + public static int DEFAULT_LIMIT_FETCH = 100; + + /** + * Definition of No Timeout fetching + */ + public static int NO_TIMEOUT_MS_FETCH = -1; + + /** + * Definition of No limit fetching + */ + public static int NO_LIMIT_FETCH = -1; + + /** + * gets the consumer group + * + * @return consumer group + */ + public String getConsumerGroup(); + + /** + * gets the consumer instance + * + * @return consumer instance + */ + public String getConsumerInstance(); + + /** + * gets the fetch timeout + * + * @return fetch timeout + */ + public int getFetchTimeout(); + + /** + * gets the fetch limit + * + * @return fetch limit + */ + public int getFetchLimit(); +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSink.java new file mode 100644 index 00000000..3c55c9f3 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSink.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +public interface DmaapTopicSink extends BusTopicSink { + + /** + * Factory of UebTopicWriter for instantiation and management purposes + */ + + public static final DmaapTopicSinkFactory factory = new IndexedDmaapTopicSinkFactory(); +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java new file mode 100644 index 00000000..5b4cfd42 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java @@ -0,0 +1,308 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.event.comm.bus.internal.InlineDmaapTopicSink; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.properties.PolicyProperties; + +/** + * DMAAP Topic Sink Factory + */ +public interface DmaapTopicSinkFactory { + + /** + * Instantiates a new DMAAP Topic Sink + * + * @param servers list of servers + * @param topic topic name + * @param apiKey API Key + * @param apiSecret API Secret + * @param userName AAF user name + * @param password AAF password + * @param partitionKey Consumer Group + * @param managed is this sink endpoint managed? + * + * @return an DMAAP Topic Sink + * @throws IllegalArgumentException if invalid parameters are present + */ + public DmaapTopicSink build(List servers, + String topic, + String apiKey, + String apiSecret, + String userName, + String password, + String partitionKey, + boolean managed) + throws IllegalArgumentException; + + /** + * Creates an DMAAP Topic Sink based on properties files + * + * @param properties Properties containing initialization values + * + * @return an DMAAP Topic Sink + * @throws IllegalArgumentException if invalid parameters are present + */ + public List build(Properties properties) + throws IllegalArgumentException; + + /** + * Instantiates a new DMAAP Topic Sink + * + * @param servers list of servers + * @param topic topic name + * + * @return an DMAAP Topic Sink + * @throws IllegalArgumentException if invalid parameters are present + */ + public DmaapTopicSink build(List servers, String topic) + throws IllegalArgumentException; + + /** + * Destroys an DMAAP Topic Sink based on a topic + * + * @param topic topic name + * @throws IllegalArgumentException if invalid parameters are present + */ + public void destroy(String topic); + + /** + * gets an DMAAP Topic Sink based on topic name + * @param topic the topic name + * + * @return an DMAAP Topic Sink with topic name + * @throws IllegalArgumentException if an invalid topic is provided + * @throws IllegalStateException if the DMAAP Topic Reader is + * an incorrect state + */ + public DmaapTopicSink get(String topic) + throws IllegalArgumentException, IllegalStateException; + + /** + * Provides a snapshot of the DMAAP Topic Sinks + * @return a list of the DMAAP Topic Sinks + */ + public List inventory(); + + /** + * Destroys all DMAAP Topic Sinks + */ + public void destroy(); +} + +/* ------------- implementation ----------------- */ + +/** + * Factory of DMAAP Reader Topics indexed by topic name + */ +class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { + // get an instance of logger + private static Logger logger = FlexLogger.getLogger(IndexedDmaapTopicSinkFactory.class); + + /** + * DMAAP Topic Name Index + */ + protected HashMap dmaapTopicWriters = + new HashMap(); + + /** + * {@inheritDoc} + */ + @Override + public DmaapTopicSink build(List servers, + String topic, + String apiKey, + String apiSecret, + String userName, + String password, + String partitionKey, + boolean managed) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + synchronized (this) { + if (dmaapTopicWriters.containsKey(topic)) { + return dmaapTopicWriters.get(topic); + } + + DmaapTopicSink dmaapTopicSink = + new InlineDmaapTopicSink(servers, topic, + apiKey, apiSecret, + userName, password, + partitionKey); + + if (managed) + dmaapTopicWriters.put(topic, dmaapTopicSink); + return dmaapTopicSink; + } + } + + + /** + * {@inheritDoc} + */ + @Override + public DmaapTopicSink build(List servers, String topic) throws IllegalArgumentException { + return this.build(servers, topic, null, null, null, null, null, true); + } + + + /** + * {@inheritDoc} + */ + @Override + public List build(Properties properties) throws IllegalArgumentException { + + String writeTopics = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS); + if (writeTopics == null || writeTopics.isEmpty()) { + logger.warn("No topic for DMAAP Sink " + properties); + return new ArrayList(); + } + List writeTopicList = new ArrayList(Arrays.asList(writeTopics.split("\\s*,\\s*"))); + + synchronized(this) { + List dmaapTopicWriters = new ArrayList(); + for (String topic: writeTopicList) { + + String servers = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + "." + + topic + + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX); + if (servers == null || servers.isEmpty()) { + logger.error("No DMAAP servers provided in " + properties); + continue; + } + + List serverList = new ArrayList(Arrays.asList(servers.split("\\s*,\\s*"))); + + String apiKey = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_API_KEY_SUFFIX); + String apiSecret = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_API_SECRET_SUFFIX); + + String aafMechId = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_AAF_MECHID_SUFFIX); + String aafPassword = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX); + + String partitionKey = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX); + + String managedString = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS + "." + topic + + PolicyProperties.PROPERTY_MANAGED_SUFFIX); + boolean managed = true; + if (managedString != null && !managedString.isEmpty()) { + managed = Boolean.parseBoolean(managedString); + } + + DmaapTopicSink dmaapTopicSink = this.build(serverList, topic, + apiKey, apiSecret, aafMechId, aafPassword, + partitionKey, managed); + dmaapTopicWriters.add(dmaapTopicSink); + } + return dmaapTopicWriters; + } + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy(String topic) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + DmaapTopicSink dmaapTopicWriter; + synchronized(this) { + if (!dmaapTopicWriters.containsKey(topic)) { + return; + } + + dmaapTopicWriter = dmaapTopicWriters.remove(topic); + } + + dmaapTopicWriter.shutdown(); + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy() { + List writers = this.inventory(); + for (DmaapTopicSink writer: writers) { + writer.shutdown(); + } + + synchronized(this) { + this.dmaapTopicWriters.clear(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public DmaapTopicSink get(String topic) + throws IllegalArgumentException, IllegalStateException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + synchronized(this) { + if (dmaapTopicWriters.containsKey(topic)) { + return dmaapTopicWriters.get(topic); + } else { + throw new IllegalStateException("DmaapTopicSink for " + topic + " not found"); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized List inventory() { + List writers = + new ArrayList(this.dmaapTopicWriters.values()); + return writers; + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSource.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSource.java new file mode 100644 index 00000000..8da7906a --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSource.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +public interface DmaapTopicSource extends BusTopicSource { + + /** + * factory for managing and tracking DMAAP sources + */ + public static DmaapTopicSourceFactory factory = new IndexedDmaapTopicSourceFactory(); +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java new file mode 100644 index 00000000..f8d85eb7 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java @@ -0,0 +1,380 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.event.comm.bus.internal.SingleThreadedDmaapTopicSource; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.properties.PolicyProperties; +/** + * DMAAP Topic Source Factory + */ +public interface DmaapTopicSourceFactory { + + /** + * Creates an DMAAP Topic Source based on properties files + * + * @param properties Properties containing initialization values + * + * @return an DMAAP Topic Source + * @throws IllegalArgumentException if invalid parameters are present + */ + public List build(Properties properties) + throws IllegalArgumentException; + + /** + * Instantiates a new DMAAP Topic Source + * + * @param servers list of servers + * @param topic topic name + * @param apiKey API Key + * @param apiSecret API Secret + * @param userName user name + * @param password password + * @param consumerGroup Consumer Group + * @param consumerInstance Consumer Instance + * @param fetchTimeout Read Fetch Timeout + * @param fetchLimit Fetch Limit + * @param managed is this endpoind managed? + * + * @return an DMAAP Topic Source + * @throws IllegalArgumentException if invalid parameters are present + */ + public DmaapTopicSource build(List servers, + String topic, + String apiKey, + String apiSecret, + String userName, + String password, + String consumerGroup, + String consumerInstance, + int fetchTimeout, + int fetchLimit, + boolean managed) + throws IllegalArgumentException; + + /** + * Instantiates a new DMAAP Topic Source + * + * @param servers list of servers + * @param topic topic name + * @param apiKey API Key + * @param apiSecret API Secret + * + * @return an DMAAP Topic Source + * @throws IllegalArgumentException if invalid parameters are present + */ + public DmaapTopicSource build(List servers, + String topic, + String apiKey, + String apiSecret) + throws IllegalArgumentException; + + /** + * Instantiates a new DMAAP Topic Source + * + * @param uebTopicReaderType Implementation type + * @param servers list of servers + * @param topic topic name + * + * @return an DMAAP Topic Source + * @throws IllegalArgumentException if invalid parameters are present + */ + public DmaapTopicSource build(List servers, + String topic) + throws IllegalArgumentException; + + /** + * Destroys an DMAAP Topic Source based on a topic + * + * @param topic topic name + * @throws IllegalArgumentException if invalid parameters are present + */ + public void destroy(String topic); + + /** + * Destroys all DMAAP Topic Sources + */ + public void destroy(); + + /** + * gets an DMAAP Topic Source based on topic name + * @param topic the topic name + * @return an DMAAP Topic Source with topic name + * @throws IllegalArgumentException if an invalid topic is provided + * @throws IllegalStateException if the DMAAP Topic Source is + * an incorrect state + */ + public DmaapTopicSource get(String topic) + throws IllegalArgumentException, IllegalStateException; + + /** + * Provides a snapshot of the DMAAP Topic Sources + * @return a list of the DMAAP Topic Sources + */ + public List inventory(); +} + + +/* ------------- implementation ----------------- */ + +/** + * Factory of DMAAP Source Topics indexed by topic name + */ + +class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { + // get an instance of logger + private static Logger logger = FlexLogger.getLogger(IndexedDmaapTopicSourceFactory.class); + /** + * UEB Topic Name Index + */ + protected HashMap dmaapTopicSources = + new HashMap(); + + /** + * {@inheritDoc} + */ + @Override + public DmaapTopicSource build(List servers, + String topic, + String apiKey, + String apiSecret, + String userName, + String password, + String consumerGroup, + String consumerInstance, + int fetchTimeout, + int fetchLimit, + boolean managed) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + synchronized(this) { + if (dmaapTopicSources.containsKey(topic)) { + return dmaapTopicSources.get(topic); + } + + DmaapTopicSource dmaapTopicSource = + new SingleThreadedDmaapTopicSource(servers, topic, + apiKey, apiSecret, userName, password, + consumerGroup, consumerInstance, + fetchTimeout, fetchLimit); + + if (managed) + dmaapTopicSources.put(topic, dmaapTopicSource); + + return dmaapTopicSource; + } + } + + /** + * {@inheritDoc} + */ + @Override + public List build(Properties properties) + throws IllegalArgumentException { + + String readTopics = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS); + if (readTopics == null || readTopics.isEmpty()) { + logger.warn("No topic for UEB Source " + properties); + return new ArrayList(); + } + List readTopicList = new ArrayList(Arrays.asList(readTopics.split("\\s*,\\s*"))); + + List dmaapTopicSource_s = new ArrayList(); + synchronized(this) { + for (String topic: readTopicList) { + + String servers = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + + topic + + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX); + + if (servers == null || servers.isEmpty()) { + logger.error("No UEB servers provided in " + properties); + continue; + } + + List serverList = new ArrayList(Arrays.asList(servers.split("\\s*,\\s*"))); + + String apiKey = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_API_KEY_SUFFIX); + + String apiSecret = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_API_SECRET_SUFFIX); + + String aafMechId = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_AAF_MECHID_SUFFIX); + + String aafPassword = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX); + + String consumerGroup = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SOURCE_CONSUMER_GROUP_SUFFIX); + + String consumerInstance = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SOURCE_CONSUMER_INSTANCE_SUFFIX); + + String fetchTimeoutString = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX); + int fetchTimeout = DmaapTopicSource.DEFAULT_TIMEOUT_MS_FETCH; + if (fetchTimeoutString != null && !fetchTimeoutString.isEmpty()) { + try { + fetchTimeout = Integer.parseInt(fetchTimeoutString); + } catch (NumberFormatException nfe) { + logger.warn("Fetch Timeout in invalid format for topic " + topic + ": " + fetchTimeoutString); + } + } + + String fetchLimitString = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX); + int fetchLimit = DmaapTopicSource.DEFAULT_LIMIT_FETCH; + if (fetchLimitString != null && !fetchLimitString.isEmpty()) { + try { + fetchLimit = Integer.parseInt(fetchLimitString); + } catch (NumberFormatException nfe) { + logger.warn("Fetch Limit in invalid format for topic " + topic + ": " + fetchLimitString); + } + } + + String managedString = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_MANAGED_SUFFIX); + boolean managed = true; + if (managedString != null && !managedString.isEmpty()) { + managed = Boolean.parseBoolean(managedString); + } + + DmaapTopicSource uebTopicSource = this.build(serverList, topic, + apiKey, apiSecret, aafMechId, aafPassword, + consumerGroup, consumerInstance, + fetchTimeout, fetchLimit, managed); + dmaapTopicSource_s.add(uebTopicSource); + } + } + return dmaapTopicSource_s; + } + + /** + * {@inheritDoc} + */ + @Override + public DmaapTopicSource build(List servers, + String topic, + String apiKey, + String apiSecret) { + return this.build(servers, topic, + apiKey, apiSecret, null, null, + null, null, + DmaapTopicSource.DEFAULT_TIMEOUT_MS_FETCH, + DmaapTopicSource.DEFAULT_LIMIT_FETCH, + true); + } + + /** + * {@inheritDoc} + */ + @Override + public DmaapTopicSource build(List servers, String topic) { + return this.build(servers, topic, null, null); + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy(String topic) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + DmaapTopicSource uebTopicSource; + + synchronized(this) { + if (!dmaapTopicSources.containsKey(topic)) { + return; + } + + uebTopicSource = dmaapTopicSources.remove(topic); + } + + uebTopicSource.shutdown(); + } + + /** + * {@inheritDoc} + */ + @Override + public DmaapTopicSource get(String topic) + throws IllegalArgumentException, IllegalStateException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + synchronized(this) { + if (dmaapTopicSources.containsKey(topic)) { + return dmaapTopicSources.get(topic); + } else { + throw new IllegalArgumentException("DmaapTopicSource for " + topic + " not found"); + } + } + } + + @Override + public synchronized List inventory() { + List readers = + new ArrayList(this.dmaapTopicSources.values()); + return readers; + } + + @Override + public void destroy() { + List readers = this.inventory(); + for (DmaapTopicSource reader: readers) { + reader.shutdown(); + } + + synchronized(this) { + this.dmaapTopicSources.clear(); + } + } + +} + diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSink.java new file mode 100644 index 00000000..efa4dc5e --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSink.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +/** + * Topic Writer over UEB Infrastructure + */ +public interface UebTopicSink extends BusTopicSink { + + /** + * Factory of UebTopicWriter for instantiation and management purposes + */ + public static final UebTopicSinkFactory factory = new IndexedUebTopicSinkFactory(); +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSinkFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSinkFactory.java new file mode 100644 index 00000000..85b98838 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSinkFactory.java @@ -0,0 +1,292 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.event.comm.bus.internal.InlineUebTopicSink; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.properties.PolicyProperties; + +/** + * UEB Topic Sink Factory + */ +public interface UebTopicSinkFactory { + + /** + * Instantiates a new UEB Topic Writer + * + * @param servers list of servers + * @param topic topic name + * @param apiKey API Key + * @param apiSecret API Secret + * @param partitionKey Consumer Group + * @param managed is this sink endpoint managed? + * + * @return an UEB Topic Writer + * @throws IllegalArgumentException if invalid parameters are present + */ + public UebTopicSink build(List servers, + String topic, + String apiKey, + String apiSecret, + String partitionKey, + boolean managed) + throws IllegalArgumentException; + + /** + * Creates an UEB Topic Writer based on properties files + * + * @param properties Properties containing initialization values + * + * @return an UEB Topic Writer + * @throws IllegalArgumentException if invalid parameters are present + */ + public List build(Properties properties) + throws IllegalArgumentException; + + /** + * Instantiates a new UEB Topic Writer + * + * @param servers list of servers + * @param topic topic name + * + * @return an UEB Topic Writer + * @throws IllegalArgumentException if invalid parameters are present + */ + public UebTopicSink build(List servers, String topic) + throws IllegalArgumentException; + + /** + * Destroys an UEB Topic Writer based on a topic + * + * @param topic topic name + * @throws IllegalArgumentException if invalid parameters are present + */ + public void destroy(String topic); + + /** + * gets an UEB Topic Writer based on topic name + * @param topic the topic name + * + * @return an UEB Topic Writer with topic name + * @throws IllegalArgumentException if an invalid topic is provided + * @throws IllegalStateException if the UEB Topic Reader is + * an incorrect state + */ + public UebTopicSink get(String topic) + throws IllegalArgumentException, IllegalStateException; + + /** + * Provides a snapshot of the UEB Topic Writers + * @return a list of the UEB Topic Writers + */ + public List inventory(); + + /** + * Destroys all UEB Topic Writers + */ + public void destroy(); +} + +/* ------------- implementation ----------------- */ + +/** + * Factory of UEB Reader Topics indexed by topic name + */ +class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { + // get an instance of logger + private static Logger logger = FlexLogger.getLogger(IndexedUebTopicSinkFactory.class); + /** + * UEB Topic Name Index + */ + protected HashMap uebTopicSinks = + new HashMap(); + + /** + * {@inheritDoc} + */ + @Override + public UebTopicSink build(List servers, + String topic, + String apiKey, + String apiSecret, + String partitionKey, + boolean managed) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + synchronized (this) { + if (uebTopicSinks.containsKey(topic)) { + return uebTopicSinks.get(topic); + } + + UebTopicSink uebTopicWriter = + new InlineUebTopicSink(servers, topic, + apiKey, apiSecret,partitionKey); + + if (managed) + uebTopicSinks.put(topic, uebTopicWriter); + + return uebTopicWriter; + } + } + + + /** + * {@inheritDoc} + */ + @Override + public UebTopicSink build(List servers, String topic) throws IllegalArgumentException { + return this.build(servers, topic, null, null, null, true); + } + + + /** + * {@inheritDoc} + */ + @Override + public List build(Properties properties) throws IllegalArgumentException { + + String writeTopics = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS); + if (writeTopics == null || writeTopics.isEmpty()) { + logger.warn("No topic for UEB Sink " + properties); + return new ArrayList(); + } + List writeTopicList = new ArrayList(Arrays.asList(writeTopics.split("\\s*,\\s*"))); + + synchronized(this) { + List uebTopicWriters = new ArrayList(); + for (String topic: writeTopicList) { + + String servers = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS + "." + + topic + + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX); + if (servers == null || servers.isEmpty()) { + logger.error("No UEB servers provided in " + properties); + continue; + } + + List serverList = new ArrayList(Arrays.asList(servers.split("\\s*,\\s*"))); + + String apiKey = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_API_KEY_SUFFIX); + String apiSecret = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_API_SECRET_SUFFIX); + String partitionKey = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SINK_PARTITION_KEY_SUFFIX); + + String managedString = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS + "." + topic + + PolicyProperties.PROPERTY_MANAGED_SUFFIX); + boolean managed = true; + if (managedString != null && !managedString.isEmpty()) { + managed = Boolean.parseBoolean(managedString); + } + + UebTopicSink uebTopicWriter = this.build(serverList, topic, + apiKey, apiSecret, + partitionKey, managed); + uebTopicWriters.add(uebTopicWriter); + } + return uebTopicWriters; + } + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy(String topic) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + UebTopicSink uebTopicWriter; + synchronized(this) { + if (!uebTopicSinks.containsKey(topic)) { + return; + } + + uebTopicWriter = uebTopicSinks.remove(topic); + } + + uebTopicWriter.shutdown(); + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy() { + List writers = this.inventory(); + for (UebTopicSink writer: writers) { + writer.shutdown(); + } + + synchronized(this) { + this.uebTopicSinks.clear(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public UebTopicSink get(String topic) + throws IllegalArgumentException, IllegalStateException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + synchronized(this) { + if (uebTopicSinks.containsKey(topic)) { + return uebTopicSinks.get(topic); + } else { + throw new IllegalStateException("UebTopicSink for " + topic + " not found"); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized List inventory() { + List writers = + new ArrayList(this.uebTopicSinks.values()); + return writers; + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSource.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSource.java new file mode 100644 index 00000000..4da01302 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSource.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +/** + * Topic Source for UEB Communication Infrastructure + * + */ +public interface UebTopicSource extends BusTopicSource { + + /** + * factory for managing and tracking UEB readers + */ + public static UebTopicSourceFactory factory = + new IndexedUebTopicSourceFactory(); +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSourceFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSourceFactory.java new file mode 100644 index 00000000..bf2a4038 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/UebTopicSourceFactory.java @@ -0,0 +1,362 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.event.comm.bus.internal.SingleThreadedUebTopicSource; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.properties.PolicyProperties; + +/** + * UEB Topic Source Factory + */ +public interface UebTopicSourceFactory { + + /** + * Creates an UEB Topic Source based on properties files + * + * @param properties Properties containing initialization values + * + * @return an UEB Topic Source + * @throws IllegalArgumentException if invalid parameters are present + */ + public List build(Properties properties) + throws IllegalArgumentException; + + /** + * Instantiates a new UEB Topic Source + * + * @param servers list of servers + * @param topic topic name + * @param apiKey API Key + * @param apiSecret API Secret + * @param consumerGroup Consumer Group + * @param consumerInstance Consumer Instance + * @param fetchTimeout Read Fetch Timeout + * @param fetchLimit Fetch Limit + * @param managed is this source endpoint managed? + * + * @return an UEB Topic Source + * @throws IllegalArgumentException if invalid parameters are present + */ + public UebTopicSource build(List servers, + String topic, + String apiKey, + String apiSecret, + String consumerGroup, + String consumerInstance, + int fetchTimeout, + int fetchLimit, + boolean managed) + throws IllegalArgumentException; + + /** + * Instantiates a new UEB Topic Source + * + * @param servers list of servers + * @param topic topic name + * @param apiKey API Key + * @param apiSecret API Secret + * + * @return an UEB Topic Source + * @throws IllegalArgumentException if invalid parameters are present + */ + public UebTopicSource build(List servers, + String topic, + String apiKey, + String apiSecret) + throws IllegalArgumentException; + + /** + * Instantiates a new UEB Topic Source + * + * @param uebTopicSourceType Implementation type + * @param servers list of servers + * @param topic topic name + * + * @return an UEB Topic Source + * @throws IllegalArgumentException if invalid parameters are present + */ + public UebTopicSource build(List servers, + String topic) + throws IllegalArgumentException; + + /** + * Destroys an UEB Topic Source based on a topic + * + * @param topic topic name + * @throws IllegalArgumentException if invalid parameters are present + */ + public void destroy(String topic); + + /** + * Destroys all UEB Topic Sources + */ + public void destroy(); + + /** + * gets an UEB Topic Source based on topic name + * @param topic the topic name + * @return an UEB Topic Source with topic name + * @throws IllegalArgumentException if an invalid topic is provided + * @throws IllegalStateException if the UEB Topic Source is + * an incorrect state + */ + public UebTopicSource get(String topic) + throws IllegalArgumentException, IllegalStateException; + + /** + * Provides a snapshot of the UEB Topic Sources + * @return a list of the UEB Topic Sources + */ + public List inventory(); +} + +/* ------------- implementation ----------------- */ + +/** + * Factory of UEB Source Topics indexed by topic name + */ +class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { + // get an instance of logger + private static Logger logger = FlexLogger.getLogger(IndexedUebTopicSourceFactory.class); + /** + * UEB Topic Name Index + */ + protected HashMap uebTopicSources = + new HashMap(); + + /** + * {@inheritDoc} + */ + @Override + public UebTopicSource build(List servers, + String topic, + String apiKey, + String apiSecret, + String consumerGroup, + String consumerInstance, + int fetchTimeout, + int fetchLimit, + boolean managed) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + synchronized(this) { + if (uebTopicSources.containsKey(topic)) { + return uebTopicSources.get(topic); + } + + UebTopicSource uebTopicSource = + new SingleThreadedUebTopicSource(servers, topic, + apiKey, apiSecret, + consumerGroup, consumerInstance, + fetchTimeout, fetchLimit); + + if (managed) + uebTopicSources.put(topic, uebTopicSource); + + return uebTopicSource; + } + } + + /** + * {@inheritDoc} + */ + @Override + public List build(Properties properties) + throws IllegalArgumentException { + + String readTopics = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS); + if (readTopics == null || readTopics.isEmpty()) { + logger.warn("No topic for UEB Source " + properties); + return new ArrayList(); + } + List readTopicList = new ArrayList(Arrays.asList(readTopics.split("\\s*,\\s*"))); + + List uebTopicSources = new ArrayList(); + synchronized(this) { + for (String topic: readTopicList) { + + String servers = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + "." + + topic + + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX); + + if (servers == null || servers.isEmpty()) { + logger.error("No UEB servers provided in " + properties); + continue; + } + + List serverList = new ArrayList(Arrays.asList(servers.split("\\s*,\\s*"))); + + String apiKey = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_API_KEY_SUFFIX); + + String apiSecret = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_API_SECRET_SUFFIX); + + String consumerGroup = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SOURCE_CONSUMER_GROUP_SUFFIX); + + String consumerInstance = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SOURCE_CONSUMER_INSTANCE_SUFFIX); + + String fetchTimeoutString = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX); + int fetchTimeout = UebTopicSource.DEFAULT_TIMEOUT_MS_FETCH; + if (fetchTimeoutString != null && !fetchTimeoutString.isEmpty()) { + try { + fetchTimeout = Integer.parseInt(fetchTimeoutString); + } catch (NumberFormatException nfe) { + logger.warn("Fetch Timeout in invalid format for topic " + topic + ": " + fetchTimeoutString); + } + } + + String fetchLimitString = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + + "." + topic + + PolicyProperties.PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX); + int fetchLimit = UebTopicSource.DEFAULT_LIMIT_FETCH; + if (fetchLimitString != null && !fetchLimitString.isEmpty()) { + try { + fetchLimit = Integer.parseInt(fetchLimitString); + } catch (NumberFormatException nfe) { + logger.warn("Fetch Limit in invalid format for topic " + topic + ": " + fetchLimitString); + } + } + + String managedString = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + "." + + topic + PolicyProperties.PROPERTY_MANAGED_SUFFIX); + boolean managed = true; + if (managedString != null && !managedString.isEmpty()) { + managed = Boolean.parseBoolean(managedString); + } + + UebTopicSource uebTopicSource = this.build(serverList, topic, + apiKey, apiSecret, + consumerGroup, consumerInstance, + fetchTimeout, fetchLimit, managed); + uebTopicSources.add(uebTopicSource); + } + } + return uebTopicSources; + } + + /** + * {@inheritDoc} + */ + @Override + public UebTopicSource build(List servers, + String topic, + String apiKey, + String apiSecret) { + return this.build(servers, topic, + apiKey, apiSecret, + null, null, + UebTopicSource.DEFAULT_TIMEOUT_MS_FETCH, + UebTopicSource.DEFAULT_LIMIT_FETCH, true); + } + + /** + * {@inheritDoc} + */ + @Override + public UebTopicSource build(List servers, String topic) { + return this.build(servers, topic, null, null); + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy(String topic) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + UebTopicSource uebTopicSource; + + synchronized(this) { + if (!uebTopicSources.containsKey(topic)) { + return; + } + + uebTopicSource = uebTopicSources.remove(topic); + } + + uebTopicSource.shutdown(); + } + + /** + * {@inheritDoc} + */ + @Override + public UebTopicSource get(String topic) + throws IllegalArgumentException, IllegalStateException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("A topic must be provided"); + } + + synchronized(this) { + if (uebTopicSources.containsKey(topic)) { + return uebTopicSources.get(topic); + } else { + throw new IllegalStateException("UebTopiceSource for " + topic + " not found"); + } + } + } + + @Override + public synchronized List inventory() { + List readers = + new ArrayList(this.uebTopicSources.values()); + return readers; + } + + @Override + public void destroy() { + List readers = this.inventory(); + for (UebTopicSource reader: readers) { + reader.shutdown(); + } + + synchronized(this) { + this.uebTopicSources.clear(); + } + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusConsumer.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusConsumer.java new file mode 100644 index 00000000..6fee5ce0 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusConsumer.java @@ -0,0 +1,204 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus.internal; + +import java.net.MalformedURLException; +import java.security.GeneralSecurityException; +import java.util.List; +import java.util.Properties; + +import com.att.nsa.cambria.client.CambriaClientBuilders; +import com.att.nsa.cambria.client.CambriaConsumer; +import com.att.nsa.mr.client.impl.MRConsumerImpl; +import com.att.nsa.mr.test.clients.ProtocolTypeConstants; +import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder; + +/** + * Wrapper around libraries to consume from message bus + * + */ +public interface BusConsumer { + + /** + * fetch messages + * + * @return list of messages + * @throws Exception when error encountered by underlying libraries + */ + public Iterable fetch() throws Exception; + + /** + * close underlying library consumer + */ + public void close(); + + /** + * Cambria based consumer + */ + public static class CambriaConsumerWrapper implements BusConsumer { + /** + * Cambria client + */ + protected CambriaConsumer consumer; + + /** + * Cambria Consumer Wrapper + * + * @param servers messaging bus hosts + * @param topic topic + * @param apiKey API Key + * @param apiSecret API Secret + * @param consumerGroup Consumer Group + * @param consumerInstance Consumer Instance + * @param fetchTimeout Fetch Timeout + * @param fetchLimit Fetch Limit + * @throws GeneralSecurityException + * @throws MalformedURLException + */ + public CambriaConsumerWrapper(List servers, String topic, + String apiKey, String apiSecret, + String consumerGroup, String consumerInstance, + int fetchTimeout, int fetchLimit) + throws IllegalArgumentException { + + ConsumerBuilder builder = + new CambriaClientBuilders.ConsumerBuilder(); + + builder.knownAs(consumerGroup, consumerInstance) + .usingHosts(servers) + .onTopic(topic) + .waitAtServer(fetchTimeout) + .receivingAtMost(fetchLimit); + + if (apiKey != null && !apiKey.isEmpty() && + apiSecret != null && !apiSecret.isEmpty()) { + builder.authenticatedBy(apiKey, apiSecret); + } + + try { + this.consumer = builder.build(); + } catch (MalformedURLException | GeneralSecurityException e) { + throw new IllegalArgumentException(e); + } + } + + /** + * {@inheritDoc} + */ + public Iterable fetch() throws Exception { + return this.consumer.fetch(); + } + + /** + * {@inheritDoc} + */ + public void close() { + this.consumer.close(); + } + + @Override + public String toString() { + return "CambriaConsumerWrapper []"; + } + } + + /** + * MR based consumer + */ + public static class DmaapConsumerWrapper implements BusConsumer { + + /** + * MR Consumer + */ + protected MRConsumerImpl consumer; + + /** + * MR Consumer Wrapper + * + * @param servers messaging bus hosts + * @param topic topic + * @param apiKey API Key + * @param apiSecret API Secret + * @param aafLogin AAF Login + * @param aafPassword AAF Password + * @param consumerGroup Consumer Group + * @param consumerInstance Consumer Instance + * @param fetchTimeout Fetch Timeout + * @param fetchLimit Fetch Limit + */ + public DmaapConsumerWrapper(List servers, String topic, + String apiKey, String apiSecret, + String aafLogin, String aafPassword, + String consumerGroup, String consumerInstance, + int fetchTimeout, int fetchLimit) + throws Exception { + + this.consumer = new MRConsumerImpl(servers, topic, + consumerGroup, consumerInstance, + fetchTimeout, fetchLimit, + null, apiKey, apiSecret); + + this.consumer.setUsername(aafLogin); + this.consumer.setPassword(aafPassword); + + this.consumer.setProtocolFlag(ProtocolTypeConstants.AAF_AUTH.getValue()); + + Properties props = new Properties(); + props.setProperty("Protocol", "http"); + this.consumer.setProps(props); + this.consumer.setHost(servers.get(0) + ":3904");; + } + + /** + * {@inheritDoc} + */ + public Iterable fetch() throws Exception { + return this.consumer.fetch(); + } + + /** + * {@inheritDoc} + */ + public void close() { + this.consumer.close(); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder. + append("DmaapConsumerWrapper ["). + append("consumer.getAuthDate()=").append(consumer.getAuthDate()). + append(", consumer.getAuthKey()=").append(consumer.getAuthKey()). + append(", consumer.getHost()=").append(consumer.getHost()). + append(", consumer.getProtocolFlag()=").append(consumer.getProtocolFlag()). + append(", consumer.getUsername()=").append(consumer.getUsername()). + append("]"); + return builder.toString(); + } + } + + +} + + + + diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusPublisher.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusPublisher.java new file mode 100644 index 00000000..798bf989 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusPublisher.java @@ -0,0 +1,231 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus.internal; + +import java.net.MalformedURLException; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaClientBuilders; +import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder; +import com.att.nsa.mr.client.impl.MRSimplerBatchPublisher; +import com.att.nsa.mr.test.clients.ProtocolTypeConstants; +import com.fasterxml.jackson.annotation.JsonIgnore; + +public interface BusPublisher { + + /** + * sends a message + * + * @param partition id + * @param message the message + * @return true if success, false otherwise + * @throws IllegalArgumentException if no message provided + */ + public boolean send(String partitionId, String message) throws IllegalArgumentException; + + /** + * closes the publisher + */ + public void close(); + + /** + * Cambria based library publisher + */ + public static class CambriaPublisherWrapper implements BusPublisher { + + /** + * The actual Cambria publisher + */ + @JsonIgnore + protected volatile CambriaBatchingPublisher publisher; + + public CambriaPublisherWrapper(List servers, String topic, + String apiKey, + String apiSecret) + throws IllegalArgumentException { + PublisherBuilder builder = new CambriaClientBuilders.PublisherBuilder(); + + builder.usingHosts(servers) + .onTopic(topic); + + // Only supported in 0.2.4 version + // .logSendFailuresAfter(DEFAULT_LOG_SEND_FAILURES_AFTER); + + if (apiKey != null && !apiKey.isEmpty() && + apiSecret != null && !apiSecret.isEmpty()) { + builder.authenticatedBy(apiKey, apiSecret); + } + + try { + this.publisher = builder.build(); + } catch (MalformedURLException | GeneralSecurityException e) { + throw new IllegalArgumentException(e); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean send(String partitionId, String message) + throws IllegalArgumentException { + if (message == null) + throw new IllegalArgumentException("No message provided"); + + try { + this.publisher.send(partitionId, message); + } catch (Exception e) { + PolicyLogger.warn(CambriaPublisherWrapper.class.getName(), + "SEND of " + message + " IN " + + this + " cannot be performed because of " + + e.getMessage()); + return false; + } + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public void close() { + if (PolicyLogger.isInfoEnabled()) + PolicyLogger.info(CambriaPublisherWrapper.class.getName(), + "CREATION: " + this); + + try { + this.publisher.close(); + } catch (Exception e) { + PolicyLogger.warn(CambriaPublisherWrapper.class.getName(), + "CLOSE on " + this + " FAILED because of " + + e.getMessage()); + } + } + + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CambriaPublisherWrapper ["). + append("publisher.getPendingMessageCount()="). + append(publisher.getPendingMessageCount()). + append("]"); + return builder.toString(); + } + + } + + /** + * DmaapClient library wrapper + */ + public static class DmaapPublisherWrapper implements BusPublisher { + /** + * MR based Publisher + */ + protected MRSimplerBatchPublisher publisher; + + public DmaapPublisherWrapper(List servers, String topic, + String aafLogin, + String aafPassword) { + + ArrayList dmaapServers = new ArrayList(); + for (String server: servers) { + dmaapServers.add(server + ":3904"); + } + + this.publisher = + new MRSimplerBatchPublisher.Builder(). + againstUrls(dmaapServers). + onTopic(topic). + build(); + + this.publisher.setProtocolFlag(ProtocolTypeConstants.AAF_AUTH.getValue()); + + this.publisher.setUsername(aafLogin); + this.publisher.setPassword(aafPassword); + + Properties props = new Properties(); + props.setProperty("Protocol", "http"); + props.setProperty("contenttype", "application/json"); + + this.publisher.setProps(props); + + this.publisher.setHost(servers.get(0)); + + if (PolicyLogger.isInfoEnabled()) + PolicyLogger.info(DmaapPublisherWrapper.class.getName(), + "CREATION: " + this); + } + + /** + * {@inheritDoc} + */ + @Override + public void close() { + if (PolicyLogger.isInfoEnabled()) + PolicyLogger.info(DmaapPublisherWrapper.class.getName(), + "CREATION: " + this); + + try { + this.publisher.close(1, TimeUnit.SECONDS); + } catch (Exception e) { + PolicyLogger.warn(DmaapPublisherWrapper.class.getName(), + "CLOSE: " + this + " because of " + + e.getMessage()); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean send(String partitionId, String message) + throws IllegalArgumentException { + if (message == null) + throw new IllegalArgumentException("No message provided"); + + this.publisher.send(partitionId, message); + return true; + + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("DmaapPublisherWrapper ["). + append("publisher.getAuthDate()=").append(publisher.getAuthDate()). + append(", publisher.getAuthKey()=").append(publisher.getAuthKey()). + append(", publisher.getHost()=").append(publisher.getHost()). + append(", publisher.getProtocolFlag()=").append(publisher.getProtocolFlag()). + append(", publisher.getUsername()=").append(publisher.getUsername()). + append(", publisher.getPendingMessageCount()=").append(publisher.getPendingMessageCount()). + append("]"); + return builder.toString(); + } + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusTopicBase.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusTopicBase.java new file mode 100644 index 00000000..e36e3afc --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/BusTopicBase.java @@ -0,0 +1,112 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus.internal; + +import java.util.List; + +import org.apache.commons.collections4.queue.CircularFifoQueue; + +import org.openecomp.policy.drools.event.comm.Topic; +import org.openecomp.policy.drools.event.comm.bus.BusTopic; + +public abstract class BusTopicBase implements BusTopic, Topic { + + protected List servers; + + protected String topic; + + protected String apiKey; + protected String apiSecret; + + protected CircularFifoQueue recentEvents = new CircularFifoQueue(10); + + public BusTopicBase(List servers, + String topic, + String apiKey, + String apiSecret) + throws IllegalArgumentException { + + if (servers == null || servers.isEmpty()) { + throw new IllegalArgumentException("UEB Server(s) must be provided"); + } + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("An UEB Topic must be provided"); + } + + this.servers = servers; + this.topic = topic; + + this.apiKey = apiKey; + this.apiSecret = apiSecret; + } + + /** + * {@inheritDoc} + */ + @Override + public String getTopic() { + return topic; + } + + /** + * {@inheritDoc} + */ + @Override + public List getServers() { + return servers; + } + + /** + * {@inheritDoc} + */ + @Override + public String getApiKey() { + return apiKey; + } + + /** + * {@inheritDoc} + */ + @Override + public String getApiSecret() { + return apiSecret; + } + + /** + * @return the recentEvents + */ + @Override + public synchronized String[] getRecentEvents() { + String[] events = new String[recentEvents.size()]; + return recentEvents.toArray(events); + } + + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("UebTopicBase [servers=").append(servers).append(", topic=").append(topic).append(", apiKey=") + .append(apiKey).append(", apiSecret=").append(apiSecret).append("]"); + return builder.toString(); + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java new file mode 100644 index 00000000..bd88818b --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java @@ -0,0 +1,284 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus.internal; + +import java.util.List; +import java.util.UUID; + +import org.apache.log4j.Logger; + +import org.openecomp.policy.drools.event.comm.bus.BusTopicSink; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.eelf.MessageCodes; + +/** + * Transport Agnostic Bus Topic Sink to carry out the core functionality + * to interact with a sink regardless if it is UEB or DMaaP. + * + */ +public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopicSink { + + /** + * logger + */ + private static org.openecomp.policy.common.logging.flexlogger.Logger logger = + FlexLogger.getLogger(InlineBusTopicSink.class); + + /** + * Not to be converted to PolicyLogger. + * This will contain all in/out traffic and only that in a single file in a concise format. + */ + protected static final Logger networkLogger = Logger.getLogger(NETWORK_LOGGER); + + /** + * The partition key to publish to + */ + protected String partitionId; + + /** + * Am I running? + * reflects invocation of start()/stop() + * !locked & start() => alive + * stop() => !alive + */ + protected volatile boolean alive = false; + + /** + * Am I locked? + * reflects invocation of lock()/unlock() operations + * locked => !alive (but not in the other direction necessarily) + * locked => !offer, !run, !start, !stop (but this last one is obvious + * since locked => !alive) + */ + protected volatile boolean locked = false; + + /** + * message bus publisher + */ + protected BusPublisher publisher; + + /** + * constructor for abstract sink + * + * @param servers servers + * @param topic topic + * @param apiKey api secret + * @param apiSecret api secret + * @param partitionId partition id + * @throws IllegalArgumentException in invalid parameters are passed in + */ + public InlineBusTopicSink(List servers, String topic, + String apiKey, String apiSecret, String partitionId) + throws IllegalArgumentException { + + super(servers, topic, apiKey, apiSecret); + + if (partitionId == null || partitionId.isEmpty()) { + this.partitionId = UUID.randomUUID ().toString(); + } + } + + /** + * Initialize the Bus publisher + */ + public abstract void init(); + + /** + * {@inheritDoc} + */ + @Override + public boolean start() throws IllegalStateException { + + if (logger.isInfoEnabled()) + logger.info("START: " + this); + + synchronized(this) { + + if (this.alive) + return true; + + if (locked) + throw new IllegalStateException(this + " is locked."); + + this.alive = true; + } + + this.init(); + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean stop() { + + BusPublisher publisherCopy; + synchronized(this) { + this.alive = false; + publisherCopy = this.publisher; + this.publisher = null; + } + + if (publisherCopy != null) { + try { + publisherCopy.close(); + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, "PUBLISHER.CLOSE", this.toString()); + e.printStackTrace(); + } + } else { + logger.warn("No publisher to close: " + this); + return false; + } + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean lock() { + + if (logger.isInfoEnabled()) + logger.info("LOCK: " + this); + + synchronized (this) { + if (this.locked) + return true; + + this.locked = true; + } + + return this.stop(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean unlock() { + + if (logger.isInfoEnabled()) + logger.info("UNLOCK: " + this); + + synchronized(this) { + if (!this.locked) + return true; + + this.locked = false; + } + + try { + return this.start(); + } catch (Exception e) { + logger.warn("can't start after unlocking " + this + + " because of " + e.getMessage()); + e.printStackTrace(); + return false; + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLocked() { + return this.locked; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAlive() { + return this.alive; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean send(String message) throws IllegalArgumentException, IllegalStateException { + + if (message == null || message.isEmpty()) { + throw new IllegalArgumentException("Message to send is empty"); + } + + if (!this.alive) { + throw new IllegalStateException(this + " is stopped"); + } + + try { + synchronized (this) { + this.recentEvents.add(message); + } + + if (networkLogger.isInfoEnabled()) { + networkLogger.info("[OUT|" + this.getTopicCommInfrastructure() + "|" + + this.topic + "]:" + + message); + } + + publisher.send(this.partitionId, message); + } catch (Exception e) { + logger.error("can't start after unlocking " + this + + " because of " + e.getMessage()); + e.printStackTrace(); + return false; + } + + return true; + } + + + /** + * {@inheritDoc} + */ + @Override + public void setPartitionKey(String partitionKey) { + this.partitionId = partitionKey; + } + + /** + * {@inheritDoc} + */ + @Override + public String getPartitionKey() { + return this.partitionId; + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() throws IllegalStateException { + this.stop(); + } + + /** + * {@inheritDoc} + */ + @Override + public abstract CommInfrastructure getTopicCommInfrastructure(); + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java new file mode 100644 index 00000000..417c6d47 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus.internal; + +import java.util.List; + +import org.openecomp.policy.drools.event.comm.Topic; +import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSink; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * This implementation publishes events for the associated DMAAP topic, + * inline with the calling thread. + */ +public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTopicSink { + + protected static Logger logger = + FlexLogger.getLogger(InlineDmaapTopicSink.class); + + protected final String userName; + protected final String password; + + public InlineDmaapTopicSink(List servers, String topic, + String apiKey, String apiSecret, + String userName, String password, + String partitionKey) + throws IllegalArgumentException { + + super(servers, topic, apiKey, apiSecret, partitionKey); + + this.userName = userName; + this.password = password; + } + + + @Override + public void init() { + this.publisher = + new BusPublisher.DmaapPublisherWrapper(this.servers, + this.topic, + this.userName, + this.password); + if (logger.isInfoEnabled()) + logger.info("DMAAP SINK TOPIC created " + this); + } + + /** + * {@inheritDoc} + */ + @Override + public CommInfrastructure getTopicCommInfrastructure() { + return Topic.CommInfrastructure.DMAAP; + } + + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("InlineDmaapTopicSink [userName=").append(userName).append(", password=").append(password) + .append(", getTopicCommInfrastructure()=").append(getTopicCommInfrastructure()).append(", toString()=") + .append(super.toString()).append("]"); + return builder.toString(); + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java new file mode 100644 index 00000000..2d4b1552 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus.internal; + +import java.util.List; + +import org.openecomp.policy.drools.event.comm.Topic; +import org.openecomp.policy.drools.event.comm.bus.UebTopicSink; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; + +/** + * This implementation publishes events for the associated UEB topic, + * inline with the calling thread. + */ +public class InlineUebTopicSink extends InlineBusTopicSink implements UebTopicSink { + + /** + * logger + */ + private static org.openecomp.policy.common.logging.flexlogger.Logger logger = + FlexLogger.getLogger(InlineUebTopicSink.class); + + /** + * Argument-based UEB Topic Writer instantiation + * + * @param servers list of UEB servers available for publishing + * @param topic the topic to publish to + * @param apiKey the api key (optional) + * @param apiSecret the api secret (optional) + * @param partitionId the partition key (optional, autogenerated if not provided) + * + * @throws IllegalArgumentException if invalid arguments are detected + */ + public InlineUebTopicSink(List servers, + String topic, + String apiKey, + String apiSecret, + String partitionId) + throws IllegalArgumentException { + super(servers, topic, apiKey, apiSecret, partitionId); + } + + /** + * Instantiation of internal resources + */ + @Override + public void init() { + + this.publisher = + new BusPublisher.CambriaPublisherWrapper(this.servers, + this.topic, + this.apiKey, + this.apiSecret); + if (logger.isInfoEnabled()) + logger.info("UEB SINK TOPIC created " + this); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("InlineUebTopicSink [getTopicCommInfrastructure()=").append(getTopicCommInfrastructure()) + .append(", toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + + /** + * {@inheritDoc} + */ + @Override + public CommInfrastructure getTopicCommInfrastructure() { + return Topic.CommInfrastructure.UEB; + } +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java new file mode 100644 index 00000000..f37c349e --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java @@ -0,0 +1,477 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus.internal; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.apache.log4j.Logger; + +import org.openecomp.policy.drools.event.comm.TopicListener; +import org.openecomp.policy.drools.event.comm.bus.BusTopicSource; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +/** + * This topic source implementation specializes in reading messages + * over a bus topic source and notifying its listeners + */ +public abstract class SingleThreadedBusTopicSource + extends BusTopicBase + implements Runnable, BusTopicSource { + + private String className = SingleThreadedBusTopicSource.class.getName(); + /** + * Not to be converted to PolicyLogger. + * This will contain all instract /out traffic and only that in a single file in a concise format. + */ + protected static final Logger networkLogger = Logger.getLogger(NETWORK_LOGGER); + + /** + * Bus consumer group + */ + protected final String consumerGroup; + + /** + * Bus consumer instance + */ + protected final String consumerInstance; + + /** + * Bus fetch timeout + */ + protected final int fetchTimeout; + + /** + * Bus fetch limit + */ + protected final int fetchLimit; + + /** + * Message Bus Consumer + */ + protected BusConsumer consumer; + + /** + * Am I running? + * reflects invocation of start()/stop() + * !locked & start() => alive + * stop() => !alive + */ + protected volatile boolean alive = false; + + /** + * Am I locked? + * reflects invocation of lock()/unlock() operations + * locked => !alive (but not in the other direction necessarily) + * locked => !offer, !run, !start, !stop (but this last one is obvious + * since locked => !alive) + */ + protected volatile boolean locked = false; + + /** + * Independent thread reading message over my topic + */ + protected Thread busPollerThread; + + /** + * All my subscribers for new message notifications + */ + protected final ArrayList topicListeners = new ArrayList(); + + /** + * + * @param servers Bus servers + * @param topic Bus Topic to be monitored + * @param apiKey Bus API Key (optional) + * @param apiSecret Bus API Secret (optional) + * @param consumerGroup Bus Reader Consumer Group + * @param consumerInstance Bus Reader Instance + * @param fetchTimeout Bus fetch timeout + * @param fetchLimit Bus fetch limit + * @throws IllegalArgumentException An invalid parameter passed in + */ + public SingleThreadedBusTopicSource(List servers, + String topic, + String apiKey, + String apiSecret, + String consumerGroup, + String consumerInstance, + int fetchTimeout, + int fetchLimit) + throws IllegalArgumentException { + + super(servers, topic, apiKey, apiSecret); + + if (consumerGroup == null || consumerGroup.isEmpty()) { + this.consumerGroup = UUID.randomUUID ().toString(); + } else { + this.consumerGroup = consumerGroup; + } + + if (consumerInstance == null || consumerInstance.isEmpty()) { + this.consumerInstance = DEFAULT_CONSUMER_INSTANCE; + } else { + this.consumerInstance = consumerInstance; + } + + if (fetchTimeout <= 0) { + this.fetchTimeout = NO_TIMEOUT_MS_FETCH; + } else { + this.fetchTimeout = fetchTimeout; + } + + if (fetchLimit <= 0) { + this.fetchLimit = NO_LIMIT_FETCH; + } else { + this.fetchLimit = fetchLimit; + } + } + + /** + * Initialize the Bus client + */ + public abstract void init() throws Exception; + + /** + * {@inheritDoc} + */ + @Override + public void register(TopicListener topicListener) + throws IllegalArgumentException { + + PolicyLogger.info(className,"REGISTER: " + topicListener + " INTO " + this); + + synchronized(this) { + if (topicListener == null) + throw new IllegalArgumentException("TopicListener must be provided"); + + /* check that this listener is not registered already */ + for (TopicListener listener: this.topicListeners) { + if (listener == topicListener) { + // already registered + return; + } + } + + this.topicListeners.add(topicListener); + } + + try { + this.start(); + } catch (Exception e) { + PolicyLogger.info(className, "new registration of " + topicListener + + ",but can't start source because of " + e.getMessage()); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void unregister(TopicListener topicListener) { + + PolicyLogger.info(className, "UNREGISTER: " + topicListener + " FROM " + this); + + boolean stop = false; + synchronized (this) { + if (topicListener == null) + throw new IllegalArgumentException("TopicListener must be provided"); + + this.topicListeners.remove(topicListener); + stop = (this.topicListeners.isEmpty()); + } + + if (stop) { + this.stop(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean lock() { + PolicyLogger.info(className, "LOCK: " + this); + + synchronized (this) { + if (this.locked) + return true; + + this.locked = true; + } + + return this.stop(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean unlock() { + PolicyLogger.info(className, "UNLOCK: " + this); + + synchronized(this) { + if (!this.locked) + return true; + + this.locked = false; + } + + try { + return this.start(); + } catch (Exception e) { + PolicyLogger.warn("can't start after unlocking " + this + + " because of " + e.getMessage()); + return false; + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean start() throws IllegalStateException { + + PolicyLogger.info(className, "START: " + this); + + synchronized(this) { + + if (alive) { + return true; + } + + if (locked) { + throw new IllegalStateException(this + " is locked."); + } + + if (this.busPollerThread == null || + !this.busPollerThread.isAlive() || + this.consumer == null) { + + try { + this.init(); + this.alive = true; + this.busPollerThread = new Thread(this); + this.busPollerThread.setName(this.getTopicCommInfrastructure() + "-source-" + this.getTopic()); + busPollerThread.start(); + } catch (Exception e) { + e.printStackTrace(); + throw new IllegalStateException(e); + } + } + } + + return this.alive; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean stop() { + PolicyLogger.info(className, "STOP: " + this); + + synchronized(this) { + BusConsumer consumerCopy = this.consumer; + + this.alive = false; + this.consumer = null; + + if (consumerCopy != null) { + try { + consumerCopy.close(); + } catch (Exception e) { + PolicyLogger.warn(MessageCodes.EXCEPTION_ERROR, e, "CONSUMER.CLOSE", this.toString()); + } + } + } + + Thread.yield(); + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLocked() { + return this.locked; + } + + /** + * broadcast event to all listeners + * + * @param message the event + * @return true if all notifications are performed with no error, false otherwise + */ + protected boolean broadcast(String message) { + + /* take a snapshot of listeners */ + List snapshotListeners = this.snapshotTopicListeners(); + + boolean success = true; + for (TopicListener topicListener: snapshotListeners) { + try { + topicListener.onTopicEvent(this.getTopicCommInfrastructure(), this.topic, message); + } catch (Exception e) { + PolicyLogger.warn(this.className, "ERROR notifying " + topicListener.toString() + + " because of " + e.getMessage() + " @ " + this.toString()); + success = false; + } + } + return success; + } + + /** + * take a snapshot of current topic listeners + * + * @return the topic listeners + */ + protected synchronized List snapshotTopicListeners() { + @SuppressWarnings("unchecked") + List listeners = (List) topicListeners.clone(); + return listeners; + } + + /** + * Run thread method for the Bus Reader + */ + @Override + public void run() { + while (this.alive) { + try { + for (String event: this.consumer.fetch()) { + synchronized (this) { + this.recentEvents.add(event); + } + + if (networkLogger.isInfoEnabled()) { + networkLogger.info("IN[" + this.getTopicCommInfrastructure() + "|" + + this.topic + "]:" + + event); + } + + PolicyLogger.info(className, this.topic + " <-- " + event); + broadcast(event); + + if (!this.alive) + break; + } + } catch (Exception e) { + PolicyLogger.error( MessageCodes.EXCEPTION_ERROR, className, e, "CONSUMER.FETCH", this.toString()); + } + } + + PolicyLogger.warn(this.className, "Exiting: " + this); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean offer(String event) { + PolicyLogger.info(className, "OFFER: " + event + " TO " + this); + + if (!this.alive) { + throw new IllegalStateException(this + " is not alive."); + } + + synchronized (this) { + this.recentEvents.add(event); + } + + if (networkLogger.isInfoEnabled()) { + networkLogger.info("IN[" + this.getTopicCommInfrastructure() + "|" + + this.topic + "]:" + + event); + } + + + return broadcast(event); + } + + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SingleThreadedBusTopicSource [consumerGroup=").append(consumerGroup) + .append(", consumerInstance=").append(consumerInstance).append(", fetchTimeout=").append(fetchTimeout) + .append(", fetchLimit=").append(fetchLimit) + .append(", consumer=").append(this.consumer).append(", alive=") + .append(alive).append(", locked=").append(locked).append(", uebThread=").append(busPollerThread) + .append(", topicListeners=").append(topicListeners.size()).append(", toString()=").append(super.toString()) + .append("]"); + return builder.toString(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAlive() { + return alive; + } + + /** + * {@inheritDoc} + */ + @Override + public String getConsumerGroup() { + return consumerGroup; + } + + /** + * {@inheritDoc} + */ + @Override + public String getConsumerInstance() { + return consumerInstance; + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() throws IllegalStateException { + this.stop(); + this.topicListeners.clear(); + } + + /** + * {@inheritDoc} + */ + @Override + public int getFetchTimeout() { + return fetchTimeout; + } + + /** + * {@inheritDoc} + */ + @Override + public int getFetchLimit() { + return fetchLimit; + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java new file mode 100644 index 00000000..e65d44a7 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus.internal; + +import java.util.List; + +import org.openecomp.policy.drools.event.comm.Topic; +import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSource; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +/** + * This topic reader implementation specializes in reading messages + * over DMAAP topic and notifying its listeners + */ +public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource + implements DmaapTopicSource, Runnable { + + protected final String userName; + protected final String password; + private String className = SingleThreadedDmaapTopicSource.class.getName(); + + /** + * + * @param servers DMaaP servers + * @param topic DMaaP Topic to be monitored + * @param apiKey DMaaP API Key (optional) + * @param apiSecret DMaaP API Secret (optional) + * @param consumerGroup DMaaP Reader Consumer Group + * @param consumerInstance DMaaP Reader Instance + * @param fetchTimeout DMaaP fetch timeout + * @param fetchLimit DMaaP fetch limit + * @throws IllegalArgumentException An invalid parameter passed in + */ + public SingleThreadedDmaapTopicSource(List servers, String topic, + String apiKey, String apiSecret, + String userName, String password, + String consumerGroup, String consumerInstance, + int fetchTimeout, int fetchLimit) + throws IllegalArgumentException { + + + super(servers, topic, apiKey, apiSecret, + consumerGroup, consumerInstance, + fetchTimeout, fetchLimit); + + this.userName = userName; + this.password = password; + + try { + this.init(); + } catch (Exception e) { + e.printStackTrace(); + throw new IllegalArgumentException(e); + } + } + + + /** + * Initialize the Cambria or MR Client + */ + @Override + public void init() throws Exception { + + if (this.userName == null || this.userName.isEmpty() || + this.password == null || this.password.isEmpty()) { + this.consumer = + new BusConsumer.CambriaConsumerWrapper(this.servers, this.topic, + this.apiKey, this.apiSecret, + this.consumerGroup, this.consumerInstance, + this.fetchTimeout, this.fetchLimit); + } else { + this.consumer = + new BusConsumer.DmaapConsumerWrapper(this.servers, this.topic, + this.apiKey, this.apiSecret, + this.userName, this.password, + this.consumerGroup, this.consumerInstance, + this.fetchTimeout, this.fetchLimit); + } + + PolicyLogger.info(className, "CREATION: " + this); + } + + /** + * {@inheritDoc} + */ + @Override + public CommInfrastructure getTopicCommInfrastructure() { + return Topic.CommInfrastructure.DMAAP; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SingleThreadedDmaapTopicSource [userName=").append(userName).append(", password=") + .append((password == null || password.isEmpty()) ? "-" : password.length()) + .append(", getTopicCommInfrastructure()=").append(getTopicCommInfrastructure()) + .append(", toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java new file mode 100644 index 00000000..edb55c75 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.event.comm.bus.internal; + +import java.util.List; + +import org.openecomp.policy.drools.event.comm.Topic; +import org.openecomp.policy.drools.event.comm.bus.UebTopicSource; + +/** + * This topic source implementation specializes in reading messages + * over an UEB Bus topic source and notifying its listeners + */ +public class SingleThreadedUebTopicSource extends SingleThreadedBusTopicSource + implements UebTopicSource { + + /** + * + * @param servers UEB servers + * @param topic UEB Topic to be monitored + * @param apiKey UEB API Key (optional) + * @param apiSecret UEB API Secret (optional) + * @param consumerGroup UEB Reader Consumer Group + * @param consumerInstance UEB Reader Instance + * @param fetchTimeout UEB fetch timeout + * @param fetchLimit UEB fetch limit + * @throws IllegalArgumentException An invalid parameter passed in + */ + public SingleThreadedUebTopicSource(List servers, String topic, + String apiKey, String apiSecret, + String consumerGroup, String consumerInstance, + int fetchTimeout, int fetchLimit) + throws IllegalArgumentException { + + super(servers, topic, apiKey, apiSecret, + consumerGroup, consumerInstance, + fetchTimeout, fetchLimit); + + + this.init(); + } + + /** + * Initialize the Cambria client + */ + @Override + public void init() { + this.consumer = + new BusConsumer.CambriaConsumerWrapper(this.servers, this.topic, + this.apiKey, this.apiSecret, + this.consumerGroup, this.consumerInstance, + this.fetchTimeout, this.fetchLimit); + } + + /** + * {@inheritDoc} + */ + @Override + public CommInfrastructure getTopicCommInfrastructure() { + return Topic.CommInfrastructure.UEB; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SingleThreadedUebTopicSource [getTopicCommInfrastructure()=") + .append(getTopicCommInfrastructure()).append(", toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClient.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClient.java new file mode 100644 index 00000000..2e81b2c8 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClient.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.drools.http.client; + +import javax.ws.rs.core.Response; + +import org.openecomp.policy.drools.properties.Startable; + +public interface HttpClient extends Startable { + + public Response get(String path); + + public Response get(); + + public static T getBody(Response response, Class entityType) { + return response.readEntity(entityType); + } + + public String getName(); + public boolean isHttps(); + public boolean isSelfSignedCerts(); + public String getHostname(); + public int getPort(); + public String getBasePath(); + public String getUserName(); + public String getPassword(); + public String getBaseUrl(); + + + public static final HttpClientFactory factory = new IndexedHttpClientFactory(); +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClientFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClientFactory.java new file mode 100644 index 00000000..53a8c2b2 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/HttpClientFactory.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.drools.http.client; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.http.client.internal.JerseyClient; +import org.openecomp.policy.drools.properties.PolicyProperties; + +public interface HttpClientFactory { + + public HttpClient build(String name, boolean https, + boolean selfSignedCerts, + String hostname, int port, + String baseUrl, String userName, + String password, boolean managed) + throws Exception; + + public ArrayList build(Properties properties) throws Exception; + + public HttpClient get(String name); + + public List inventory(); + + public void destroy(String name); + + public void destroy(); +} + +class IndexedHttpClientFactory implements HttpClientFactory { + + protected HashMap clients = new HashMap(); + + @Override + public synchronized HttpClient build(String name, boolean https, boolean selfSignedCerts, + String hostname, int port, + String baseUrl, String userName, String password, + boolean managed) + throws Exception { + if (clients.containsKey(name)) + return clients.get(name); + + JerseyClient client = + new JerseyClient(name, https, selfSignedCerts, hostname, port, baseUrl, userName, password); + + if (managed) + clients.put(name, client); + + return client; + } + + @Override + public synchronized ArrayList build(Properties properties) throws Exception { + ArrayList clientList = new ArrayList(); + + String clientNames = properties.getProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES); + if (clientNames == null || clientNames.isEmpty()) { + return clientList; + } + + List clientNameList = + new ArrayList(Arrays.asList(clientNames.split("\\s*,\\s*"))); + + for (String clientName : clientNameList) { + String httpsString = properties.getProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + + clientName + + PolicyProperties.PROPERTY_HTTP_HTTPS_SUFFIX); + boolean https = false; + if (httpsString != null && !httpsString.isEmpty()) { + https = Boolean.parseBoolean(httpsString); + } + + String hostName = properties.getProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + + clientName + + PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX); + + String servicePortString = properties.getProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + + clientName + + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX); + int port; + try { + if (servicePortString == null || servicePortString.isEmpty()) { + continue; + } + port = Integer.parseInt(servicePortString); + } catch (NumberFormatException nfe) { + nfe.printStackTrace(); + continue; + } + + String baseUrl = properties.getProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + + clientName + + PolicyProperties.PROPERTY_HTTP_URL_SUFFIX); + + String userName = properties.getProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + + clientName + + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX); + + String password = properties.getProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + + clientName + + PolicyProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX); + + String managedString = properties.getProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + + clientName + + PolicyProperties.PROPERTY_MANAGED_SUFFIX); + boolean managed = true; + if (managedString != null && !managedString.isEmpty()) { + managed = Boolean.parseBoolean(managedString); + } + + try { + HttpClient client = + this.build(clientName, https, https, hostName, port, baseUrl, + userName, password, managed); + clientList.add(client); + } catch (Exception e) { + e.printStackTrace(); + } + } + + return clientList; + } + + @Override + public synchronized HttpClient get(String name) { + if (clients.containsKey(name)) { + return clients.get(name); + } + + throw new IllegalArgumentException("Http Client " + name + " not found"); + } + + @Override + public synchronized List inventory() { + return new ArrayList(this.clients.values()); + } + + @Override + public synchronized void destroy(String name) { + if (!clients.containsKey(name)) { + return; + } + + HttpClient client = clients.remove(name); + try { + client.shutdown(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void destroy() { + List clientsInventory = this.inventory(); + for (HttpClient client: clientsInventory) { + client.shutdown(); + } + + synchronized(this) { + this.clients.clear(); + } + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java new file mode 100644 index 00000000..4fa59dc8 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/client/internal/JerseyClient.java @@ -0,0 +1,242 @@ +/*- + * ============LICENSE_START======================================================= + * policy-healthcheck + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.http.client.internal; + +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; + +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import org.openecomp.policy.drools.http.client.HttpClient; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class JerseyClient implements HttpClient { + + protected final String name; + protected final boolean https; + protected final boolean selfSignedCerts; + protected final String hostname; + protected final int port; + protected final String basePath; + protected final String userName; + protected final String password; + + protected final Client client; + protected final String baseUrl; + + protected boolean alive = true; + + + public JerseyClient(String name, boolean https, + boolean selfSignedCerts, + String hostname, int port, + String basePath, String userName, + String password) + throws Exception { + + super(); + + if (name == null || name.isEmpty()) + throw new IllegalArgumentException("Name must be provided"); + + if (hostname == null || hostname.isEmpty()) + throw new IllegalArgumentException("Hostname must be provided"); + + if (port <= 0 && port >= 65535) + throw new IllegalArgumentException("Invalid Port provided: " + port); + + this.name = name; + this.https = https; + this.hostname = hostname; + this.port = port; + this.basePath = basePath; + this.userName = userName; + this.password = password; + this.selfSignedCerts = selfSignedCerts; + + StringBuffer tmpBaseUrl = new StringBuffer(); + if (this.https) { + tmpBaseUrl.append("https://"); + ClientBuilder clientBuilder; + SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); + if (this.selfSignedCerts) { + sslContext.init(null, new TrustManager[]{new X509TrustManager() { + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {} + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {} + @Override + public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } + + }}, new SecureRandom()); + clientBuilder = ClientBuilder.newBuilder().sslContext(sslContext).hostnameVerifier(new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) {return true;} + }); + } else { + sslContext.init(null, null, null); + clientBuilder = ClientBuilder.newBuilder().sslContext(sslContext); + } + this.client = clientBuilder.build(); + } else { + tmpBaseUrl.append("http://"); + this.client = ClientBuilder.newClient(); + } + + if (this.userName != null && !this.userName.isEmpty() && + this.password != null && !this.password.isEmpty()) { + HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basic(userName, password); + this.client.register(authFeature); + } + + this.baseUrl = tmpBaseUrl.append(this.hostname).append(":"). + append(this.port).append("/"). + append((this.basePath == null) ? "" : this.basePath). + toString(); + } + + @Override + public Response get(String path) { + if (path != null && !path.isEmpty()) + return this.client.target(this.baseUrl).path(path).request().get(); + else + return this.client.target(this.baseUrl).request().get(); + } + + @Override + public Response get() { + return this.client.target(this.baseUrl).request().get(); + } + + + @Override + public boolean start() throws IllegalStateException { + return alive; + } + + @Override + public boolean stop() throws IllegalStateException { + return !alive; + } + + @Override + public void shutdown() throws IllegalStateException { + synchronized(this) { + alive = false; + } + + try { + this.client.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public synchronized boolean isAlive() { + return this.alive; + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isHttps() { + return https; + } + + @Override + public boolean isSelfSignedCerts() { + return selfSignedCerts; + } + + @Override + public String getHostname() { + return hostname; + } + + public int getPort() { + return port; + } + + @Override + public String getBasePath() { + return basePath; + } + + @Override + public String getUserName() { + return userName; + } + + @JsonIgnore + @Override + public String getPassword() { + return password; + } + + @Override + public String getBaseUrl() { + return baseUrl; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("JerseyClient [name="); + builder.append(name); + builder.append(", https="); + builder.append(https); + builder.append(", selfSignedCerts="); + builder.append(selfSignedCerts); + builder.append(", hostname="); + builder.append(hostname); + builder.append(", port="); + builder.append(port); + builder.append(", basePath="); + builder.append(basePath); + builder.append(", userName="); + builder.append(userName); + builder.append(", password="); + builder.append(password); + builder.append(", client="); + builder.append(client); + builder.append(", baseUrl="); + builder.append(baseUrl); + builder.append(", alive="); + builder.append(alive); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServer.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServer.java new file mode 100644 index 00000000..5f5dd787 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServer.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.drools.http.server; + +import org.openecomp.policy.drools.properties.Startable; + +/** + * A Jetty Server to server REST Requests + */ +public interface HttpServletServer extends Startable { + + /** + * + * @return port + */ + public int getPort(); + + /** + * enables basic authentication with user and password on the the relative path relativeUriPath + * + * @param user + * @param password + * @param relativeUriPath + */ + public void setBasicAuthentication(String user, String password, String relativeUriPath); + + /** + * adds a JAX-RS servlet class to serve REST requests + * + * @param servletPath + * @param restClass + * @throws IllegalArgumentException + * @throws IllegalStateException + */ + public void addServletClass(String servletPath, String restClass) + throws IllegalArgumentException, IllegalStateException; + + /** + * adds a package containing JAX-RS classes to serve REST requests + * + * @param servletPath + * @param restPackage + * @throws IllegalArgumentException + * @throws IllegalStateException + */ + public void addServletPackage(String servletPath, String restPackage) + throws IllegalArgumentException, IllegalStateException; + + /** + * blocking start of the http server + * + * @param maxWaitTime max time to wait for the start to take place + * @return true if start was successful + * + * @throws IllegalArgumentException if arguments are invalid + */ + public boolean waitedStart(long maxWaitTime) throws IllegalArgumentException; + + + /** + * factory for managing and tracking DMAAP sources + */ + public static HttpServletServerFactory factory = new IndexedHttpServletServerFactory(); +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServerFactory.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServerFactory.java new file mode 100644 index 00000000..bd5ae242 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/HttpServletServerFactory.java @@ -0,0 +1,206 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.drools.http.server; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.http.server.internal.JettyJerseyServer; +import org.openecomp.policy.drools.properties.PolicyProperties; + +/** + * Jetty Server Factory + */ +public interface HttpServletServerFactory { + + public HttpServletServer build(String name, String host, int port, String contextPath, boolean managed) + throws IllegalArgumentException; + + public ArrayList build(Properties properties) throws IllegalArgumentException; + + public HttpServletServer get(int port); + public List inventory(); + public void destroy(int port); + public void destroy(); +} + +class IndexedHttpServletServerFactory implements HttpServletServerFactory { + + protected static Logger logger = FlexLogger.getLogger(IndexedHttpServletServerFactory.class); + + protected HashMap servers = new HashMap(); + + @Override + public synchronized HttpServletServer build(String name, String host, int port, + String contextPath, boolean managed) + throws IllegalArgumentException { + + if (servers.containsKey(port)) + return servers.get(port); + + JettyJerseyServer server = new JettyJerseyServer(name, host, port, contextPath); + if (managed) + servers.put(port, server); + + return server; + } + + @Override + public synchronized ArrayList build(Properties properties) + throws IllegalArgumentException { + + ArrayList serviceList = new ArrayList(); + + String serviceNames = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES); + if (serviceNames == null || serviceNames.isEmpty()) { + logger.warn("No topic for HTTP Service " + properties); + return serviceList; + } + + List serviceNameList = + new ArrayList(Arrays.asList(serviceNames.split("\\s*,\\s*"))); + + for (String serviceName : serviceNameList) { + String servicePortString = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX); + + int servicePort; + try { + if (servicePortString == null || servicePortString.isEmpty()) { + if (logger.isWarnEnabled()) + logger.warn("No HTTP port for service in " + serviceName); + continue; + } + servicePort = Integer.parseInt(servicePortString); + } catch (NumberFormatException nfe) { + if (logger.isWarnEnabled()) + logger.warn("No HTTP port for service in " + serviceName); + continue; + } + + String hostName = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX); + + String contextUriPath = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_HTTP_CONTEXT_URIPATH_SUFFIX); + + String userName = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX); + + String password = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX); + + String authUriPath = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_HTTP_AUTH_URIPATH_SUFFIX); + + String restClasses = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX); + + String restPackages = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_HTTP_REST_PACKAGES_SUFFIX); + String restUriPath = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_HTTP_REST_URIPATH_SUFFIX); + + String managedString = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + serviceName + + PolicyProperties.PROPERTY_MANAGED_SUFFIX); + boolean managed = true; + if (managedString != null && !managedString.isEmpty()) { + managed = Boolean.parseBoolean(managedString); + } + + HttpServletServer service = build(serviceName, hostName, servicePort, contextUriPath, managed); + if (userName != null && !userName.isEmpty() && password != null && !password.isEmpty()) { + service.setBasicAuthentication(userName, password, authUriPath); + } + + if (restClasses != null && !restClasses.isEmpty()) { + List restClassesList = + new ArrayList(Arrays.asList(restClasses.split("\\s*,\\s*"))); + for (String restClass : restClassesList) + service.addServletClass(restUriPath, restClass); + } + + if (restPackages != null && !restPackages.isEmpty()) { + List restPackageList = + new ArrayList(Arrays.asList(restPackages.split("\\s*,\\s*"))); + for (String restPackage : restPackageList) + service.addServletPackage(restUriPath, restPackage); + } + + serviceList.add(service); + } + + return serviceList; + } + + @Override + public synchronized HttpServletServer get(int port) throws IllegalArgumentException { + + if (servers.containsKey(port)) { + return servers.get(port); + } + + throw new IllegalArgumentException("Http Server for " + port + " not found"); + } + + @Override + public synchronized List inventory() { + return new ArrayList(this.servers.values()); + } + + @Override + public synchronized void destroy(int port) throws IllegalArgumentException, IllegalStateException { + + if (!servers.containsKey(port)) { + return; + } + + HttpServletServer server = servers.remove(port); + server.shutdown(); + } + + @Override + public synchronized void destroy() throws IllegalArgumentException, IllegalStateException { + List servers = this.inventory(); + for (HttpServletServer server: servers) { + server.shutdown(); + } + + synchronized(this) { + this.servers.clear(); + } + } + +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyJerseyServer.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyJerseyServer.java new file mode 100644 index 00000000..4914a4cb --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyJerseyServer.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.drools.http.server.internal; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.eclipse.jetty.servlet.ServletHolder; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * REST Jetty Server using Jersey + */ +public class JettyJerseyServer extends JettyServletServer { + + protected static final String JERSEY_PACKAGES_PARAM = "jersey.config.server.provider.packages"; + protected static final String JERSEY_CLASSNAMES_PARAM = "jersey.config.server.provider.classnames"; + + protected static Logger logger = FlexLogger.getLogger(JettyJerseyServer.class); + + protected ArrayList packages = new ArrayList(); + protected HashMap servlets = + new HashMap(); + + public JettyJerseyServer(String name, String host, int port, String contextPath) + throws IllegalArgumentException { + super(name, host, port, contextPath); + } + + protected synchronized ServletHolder getServlet(String servletPath) + throws IllegalArgumentException { + + if (servletPath == null || servletPath.isEmpty()) + servletPath = "/*"; + + ServletHolder jerseyServlet = servlets.get(servletPath); + if (jerseyServlet == null) { + jerseyServlet = context.addServlet + (org.glassfish.jersey.servlet.ServletContainer.class, servletPath); + jerseyServlet.setInitOrder(0); + String initPackages = + jerseyServlet.getInitParameter(JERSEY_PACKAGES_PARAM); + if (initPackages == null) { + jerseyServlet.setInitParameter( + JERSEY_PACKAGES_PARAM, + "com.jersey.jaxb,com.fasterxml.jackson.jaxrs.json"); + } + this.servlets.put(servletPath, jerseyServlet); + } + + return jerseyServlet; + } + + @Override + public synchronized void addServletPackage(String servletPath, String restPackage) + throws IllegalArgumentException, IllegalStateException { + + if (restPackage == null || restPackage.isEmpty()) + throw new IllegalArgumentException("No discoverable REST package provided"); + + ServletHolder jerseyServlet = this.getServlet(servletPath); + if (jerseyServlet == null) + throw new IllegalStateException("Unexpected, no Jersey Servlet class"); + + String initPackages = + jerseyServlet.getInitParameter(JERSEY_PACKAGES_PARAM); + if (initPackages == null) + throw new IllegalStateException("Unexpected, no Init Parameters loaded"); + + jerseyServlet.setInitParameter( + JERSEY_PACKAGES_PARAM, + initPackages + "," + restPackage); + + if (logger.isDebugEnabled()) + logger.debug(this + "Added REST Package: " + jerseyServlet.dump()); + } + + @Override + public synchronized void addServletClass(String servletPath, String restClass) + throws IllegalArgumentException, IllegalStateException { + + if (restClass == null || restClass.isEmpty()) + throw new IllegalArgumentException("No discoverable REST class provided"); + + ServletHolder jerseyServlet = this.getServlet(servletPath); + if (jerseyServlet == null) + throw new IllegalStateException("Unexpected, no Jersey Servlet class"); + + String initClasses = + jerseyServlet.getInitParameter(JERSEY_CLASSNAMES_PARAM); + if (initClasses == null) + initClasses = restClass; + else + initClasses = initClasses + "," + restClass; + + jerseyServlet.setInitParameter( + JERSEY_CLASSNAMES_PARAM, + initClasses); + + if (logger.isDebugEnabled()) + logger.debug(this + "Added REST Class: " + jerseyServlet.dump()); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("JerseyJettyServer [packages=").append(packages).append(", servlets=").append(servlets) + .append(", toString()=").append(super.toString()).append("]"); + return builder.toString(); + } +} diff --git a/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyServletServer.java b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyServletServer.java new file mode 100644 index 00000000..74360e80 --- /dev/null +++ b/policy-endpoints/src/main/java/org/openecomp/policy/drools/http/server/internal/JettyServletServer.java @@ -0,0 +1,353 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.drools.http.server.internal; + +import org.eclipse.jetty.security.ConstraintMapping; +import org.eclipse.jetty.security.ConstraintSecurityHandler; +import org.eclipse.jetty.security.HashLoginService; +import org.eclipse.jetty.security.authentication.BasicAuthenticator; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.util.security.Constraint; +import org.eclipse.jetty.util.security.Credential; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.http.server.HttpServletServer; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * Http Server implementation using Embedded Jetty + */ +public abstract class JettyServletServer implements HttpServletServer, Runnable { + + private static Logger logger = FlexLogger.getLogger(JettyServletServer.class); + + protected final String name; + + protected final String host; + protected final int port; + + protected String user; + protected String password; + + protected final String contextPath; + + protected final Server jettyServer; + protected final ServletContextHandler context; + protected final ServerConnector connector; + + protected volatile Thread jettyThread; + + protected Object startCondition = new Object(); + + public JettyServletServer(String name, String host, int port, String contextPath) + throws IllegalArgumentException { + + if (name == null || name.isEmpty()) + name = "http-" + port; + + if (port <= 0 && port >= 65535) + throw new IllegalArgumentException("Invalid Port provided: " + port); + + if (host == null || host.isEmpty()) + host = "localhost"; + + if (contextPath == null || contextPath.isEmpty()) + contextPath = "/"; + + this.name = name; + + this.host = host; + this.port = port; + + this.contextPath = contextPath; + + this.context = new ServletContextHandler(ServletContextHandler.SESSIONS); + this.context.setContextPath(contextPath); + + this.jettyServer = new Server(); + + this.connector = new ServerConnector(this.jettyServer); + this.connector.setName(name); + this.connector.setReuseAddress(true); + this.connector.setPort(port); + this.connector.setHost(host); + + this.jettyServer.addConnector(this.connector); + this.jettyServer.setHandler(context); + } + + /** + * {@inheritDoc} + */ + @Override + public void setBasicAuthentication(String user, String password, String servletPath) { + if (user == null || user.isEmpty() || password == null || password.isEmpty()) + throw new IllegalArgumentException("Missing user and/or password"); + + if (servletPath == null || servletPath.isEmpty()) + servletPath = "/*"; + + HashLoginService hashLoginService = new HashLoginService(); + hashLoginService.putUser(user, + Credential.getCredential(password), + new String[] {"user"}); + hashLoginService.setName(this.connector.getName() + "-login-service"); + + Constraint constraint = new Constraint(); + constraint.setName(Constraint.__BASIC_AUTH); + constraint.setRoles(new String[]{"user"}); + constraint.setAuthenticate(true); + + ConstraintMapping constraintMapping = new ConstraintMapping(); + constraintMapping.setConstraint(constraint); + constraintMapping.setPathSpec(servletPath); + + ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); + securityHandler.setAuthenticator(new BasicAuthenticator()); + securityHandler.setRealmName(this.connector.getName() + "-realm"); + securityHandler.addConstraintMapping(constraintMapping); + securityHandler.setLoginService(hashLoginService); + + this.context.setSecurityHandler(securityHandler); + + this.user = user; + this.password = password; + } + + /** + * Jetty Server Execution + */ + @Override + public void run() { + try { + if (logger.isInfoEnabled()) + logger.info(this + " STARTING " + this.jettyServer.dump()); + + this.jettyServer.start(); + + synchronized(this.startCondition) { + this.startCondition.notifyAll(); + } + + this.jettyServer.join(); + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + "Error found while running management server", this.toString()); + } + } + + @Override + public boolean waitedStart(long maxWaitTime) throws IllegalArgumentException { + + if (maxWaitTime < 0) + throw new IllegalArgumentException("max-wait-time cannot be negative"); + + long pendingWaitTime = maxWaitTime; + + if (!this.start()) + return false; + + synchronized (this.startCondition) { + + while (!this.jettyServer.isRunning()) { + try { + long startTs = System.currentTimeMillis(); + + this.startCondition.wait(pendingWaitTime); + + if (maxWaitTime == 0) + /* spurious notification */ + continue; + + long endTs = System.currentTimeMillis(); + pendingWaitTime = pendingWaitTime - (endTs - startTs); + + if (logger.isInfoEnabled()) + logger.info(this + "Pending time is " + pendingWaitTime + + " ms."); + + if (pendingWaitTime <= 0) + return false; + + } catch (InterruptedException e) { + logger.warn("waited-start has been interrupted"); + return false; + } + } + + return (this.jettyServer.isRunning()); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean start() throws IllegalStateException { + if (logger.isDebugEnabled()) + logger.debug(this + "START"); + + synchronized(this) { + if (jettyThread == null || + !this.jettyThread.isAlive()) { + + this.jettyThread = new Thread(this); + this.jettyThread.setName(this.name + "-" + this.port); + this.jettyThread.start(); + } + } + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean stop() throws IllegalStateException { + logger.info(this + "STOP"); + + synchronized(this) { + if (jettyThread == null) { + return true; + } + + if (!jettyThread.isAlive()) { + this.jettyThread = null; + } + + try { + this.connector.stop(); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, + "Error while stopping management server", this.toString()); + e.printStackTrace(); + } + + try { + this.jettyServer.stop(); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, + "Error while stopping management server", this.toString()); + return false; + } + + Thread.yield(); + } + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() throws IllegalStateException { + logger.info(this + "SHUTDOWN"); + + this.stop(); + + if (this.jettyThread == null) + return; + + Thread jettyThreadCopy = this.jettyThread; + + if (jettyThreadCopy.isAlive()) { + try { + jettyThreadCopy.join(1000L); + } catch (InterruptedException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + "Error while shutting down management server", this.toString()); + } + if (!jettyThreadCopy.isInterrupted()) { + try { + jettyThreadCopy.interrupt(); + } catch(Exception e) { + // do nothing + logger.warn("exception while shutting down (OK)"); + } + } + } + + this.jettyServer.destroy(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAlive() { + if (this.jettyThread != null) + return this.jettyThread.isAlive(); + + return false; + } + + @Override + public int getPort() { + return this.port; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the host + */ + public String getHost() { + return host; + } + + /** + * @return the user + */ + public String getUser() { + return user; + } + + /** + * @return the password + */ + @JsonIgnore + public String getPassword() { + return password; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("JettyServer [name=").append(name).append(", host=").append(host).append(", port=").append(port) + .append(", user=").append(user).append(", password=").append((password != null)).append(", contextPath=") + .append(contextPath).append(", jettyServer=").append(jettyServer).append(", context=").append(this.context) + .append(", connector=").append(connector).append(", jettyThread=").append(jettyThread) + .append("]"); + return builder.toString(); + } + +} diff --git a/policy-endpoints/src/main/resources/schema/pdpd-configuration.jsonschema b/policy-endpoints/src/main/resources/schema/pdpd-configuration.jsonschema new file mode 100644 index 00000000..34ee199a --- /dev/null +++ b/policy-endpoints/src/main/resources/schema/pdpd-configuration.jsonschema @@ -0,0 +1,61 @@ +{ + "title": "ENGINE-CONFIGURATION", + "type":"object", + "$schema": "http://json-schema.org/draft-03/schema", + "required":false, + "properties":{ + "requestID": { + "description": "Unique Transaction ID. This is an UUID.", + "type":"string", + "required":true + }, + "entity": { + "description": "Set of entities on which configuration can be performed: controller", + "type":"string", + "required":true + }, + "controllers": { + "description": "Controller Information, only applicable when the entity is set to controller", + "type":"array", + "required":false, + "items": { + "description": "Drools Related Information", + "type":"object", + "required":true, + "properties":{ + "name": { + "type":"string", + "required":true + }, + "operation": { + "description": "Set of operations that can be applied to a controller: create, lock", + "type":"string", + "required":true + }, + "drools": { + "description": "Maven Related Information", + "type":"object", + "required":false, + "properties":{ + "artifactId": { + "description": "Maven Artifact ID", + "type":"string", + "required":true + }, + "groupId": { + "description": "Maven Group ID", + "type":"string", + "required":true + }, + "version": { + "description": "Maven Version", + "type":"string", + "required":true + } + } + } + } + } + } + } +} diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java new file mode 100644 index 00000000..ced3dcf4 --- /dev/null +++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java @@ -0,0 +1,230 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.http.server.test; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Properties; + +import javax.ws.rs.core.Response; + +import org.junit.Test; +import org.openecomp.policy.drools.http.client.HttpClient; +import org.openecomp.policy.drools.http.server.HttpServletServer; +import org.openecomp.policy.drools.properties.PolicyProperties; + +public class HttpClientTest { + + @Test + public void testHttpNoAuthClient() throws Exception { + System.out.println("-- testHttpNoAuthClient() --"); + + HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", true); + server.addServletPackage("/*", this.getClass().getPackage().getName()); + server.waitedStart(5000); + + HttpClient client = HttpClient.factory.build("testHttpNoAuthClient", false, false, + "localhost", 6666, "junit/echo", + null, null, true); + Response response = client.get("hello"); + String body = HttpClient.getBody(response, String.class); + + assertTrue(response.getStatus() == 200); + assertTrue(body.equals("hello")); + + HttpServletServer.factory.destroy(); + HttpClient.factory.destroy(); + } + + @Test + public void testHttpAuthClient() throws Exception { + System.out.println("-- testHttpAuthClient() --"); + + HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", true); + server.setBasicAuthentication("x", "y", null); + server.addServletPackage("/*", this.getClass().getPackage().getName()); + server.waitedStart(5000); + + HttpClient client = HttpClient.factory.build("testHttpAuthClient",false, false, + "localhost", 6666, "junit/echo", + "x", "y", true); + Response response = client.get("hello"); + String body = HttpClient.getBody(response, String.class); + + assertTrue(response.getStatus() == 200); + assertTrue(body.equals("hello")); + + HttpServletServer.factory.destroy(); + HttpClient.factory.destroy(); + } + + @Test + public void testHttpAuthClient401() throws Exception { + System.out.println("-- testHttpAuthClient401() --"); + + HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", true); + server.setBasicAuthentication("x", "y", null); + server.addServletPackage("/*", this.getClass().getPackage().getName()); + server.waitedStart(5000); + + HttpClient client = HttpClient.factory.build("testHttpAuthClient401",false, false, + "localhost", 6666, "junit/echo", + null, null, true); + Response response = client.get("hello"); + assertTrue(response.getStatus() == 401); + + HttpServletServer.factory.destroy(); + HttpClient.factory.destroy(); + } + + //@Test + public void testHttpAuthClientHttps() throws Exception { + System.out.println("-- testHttpAuthClientHttps() --"); + + HttpClient client = HttpClient.factory.build("testHttpAuthClientHttps", true, true, "somehost.somewhere.com", + 9091, "pap/test", "testpap", "alpha123", true); + Response response = client.get(); + assertTrue(response.getStatus() == 200); + + HttpClient client2 = HttpClient.factory.build("testHttpAuthClientHttps2", true, true, "somehost.somewhere.com", + 8081, "pdp", "testpdp", "alpha123", true); + Response response2 = client2.get("test"); + assertTrue(response2.getStatus() == 500); + + HttpServletServer.factory.destroy(); + HttpClient.factory.destroy(); + } + + @Test + public void testHttpAuthClientProps() throws Exception { + System.out.println("-- testHttpAuthClientProps() --"); + + Properties httpProperties = new Properties(); + + httpProperties.setProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES, "PAP,PDP"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX, + "localhost"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, + "9091"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, + "testpap"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, + "alpha123"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, + "org.openecomp.policy.drools.http.server.test.RestMockHealthCheck"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_MANAGED_SUFFIX, + "true"); + + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX, + "localhost"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, + "8081"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, + "testpdp"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, + "alpha123"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, + "org.openecomp.policy.drools.http.server.test.RestMockHealthCheck"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_MANAGED_SUFFIX, + "true"); + + httpProperties.setProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES, "PAP,PDP"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX, + "localhost"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, + "9091"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_URL_SUFFIX, + "pap/test"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_HTTPS_SUFFIX, + "false"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, + "testpap"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, + "alpha123"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_MANAGED_SUFFIX, + "true"); + + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX, + "localhost"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, + "8081"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_URL_SUFFIX, + "pdp"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_HTTPS_SUFFIX, + "false"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, + "testpdp"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, + "alpha123"); + httpProperties.setProperty + (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_MANAGED_SUFFIX, + "true"); + + ArrayList servers = HttpServletServer.factory.build(httpProperties); + assertTrue(servers.size() == 2); + + ArrayList clients = HttpClient.factory.build(httpProperties); + assertTrue(clients.size() == 2); + + for (HttpServletServer server: servers) { + server.waitedStart(5000); + } + + HttpClient clientPAP = HttpClient.factory.get("PAP"); + Response response = clientPAP.get(); + assertTrue(response.getStatus() == 200); + + HttpClient clientPDP = HttpClient.factory.get("PDP"); + Response response2 = clientPDP.get("test"); + assertTrue(response2.getStatus() == 500); + + HttpServletServer.factory.destroy(); + HttpClient.factory.destroy(); + } + + +} diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java new file mode 100644 index 00000000..94f29804 --- /dev/null +++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.drools.http.server.test; + +import static org.junit.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.UUID; + +import org.junit.Test; +import org.openecomp.policy.drools.http.server.HttpServletServer; + +/** + * + */ +public class HttpServerTest { + + @Test + public void testSingleServer() throws Exception { + System.out.println("-- testSingleServer() --"); + + HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 5678, "/", true); + server.addServletPackage("/*", this.getClass().getPackage().getName()); + server.waitedStart(5000); + + assertTrue(HttpServletServer.factory.get(5678).isAlive()); + + String echo = "hello"; + URL url = new URL("http://localhost:5678/junit/echo/" + echo); + String response = response(url); + System.out.println("Received .. " + response); + assertTrue(response.equals(echo)); + + HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.inventory().size() == 0); + } + + @Test + public void testMultipleServers() throws Exception { + System.out.println("-- testMultipleServers() --"); + + HttpServletServer server1 = HttpServletServer.factory.build("echo-1", "localhost", 5678, "/", true); + server1.addServletPackage("/*", this.getClass().getPackage().getName()); + server1.waitedStart(5000); + + HttpServletServer server2 = HttpServletServer.factory.build("echo-2", "localhost", 5679, "/", true); + server2.addServletPackage("/*", this.getClass().getPackage().getName()); + server2.waitedStart(5000); + + assertTrue(HttpServletServer.factory.get(5678).isAlive()); + assertTrue(HttpServletServer.factory.get(5679).isAlive()); + + String echo = "hello"; + + URL url1 = new URL("http://localhost:5678/junit/echo/" + echo); + String response1 = response(url1); + System.out.println("Received .. " + response1); + assertTrue(response1.equals(echo)); + + URL url2 = new URL("http://localhost:5679/junit/echo/" + echo); + String response2 = response(url2); + System.out.println("Received .. " + response2); + assertTrue(response2.equals(echo)); + + HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.inventory().size() == 0); + } + + @Test + public void testMultiServicePackage() throws Exception { + System.out.println("-- testMultiServicePackage() --"); + + String randomName = UUID.randomUUID().toString(); + + HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5678, "/", true); + server.addServletPackage("/*", this.getClass().getPackage().getName()); + server.waitedStart(5000); + + assertTrue(HttpServletServer.factory.get(5678).isAlive()); + + String echo = "hello"; + URL urlService1 = new URL("http://localhost:5678/junit/echo/" + echo); + String responseService1 = response(urlService1); + System.out.println("Received .. " + responseService1); + assertTrue(responseService1.equals(echo)); + + URL urlService2 = new URL("http://localhost:5678/junit/endpoints/http/servers"); + String responseService2 = response(urlService2); + System.out.println("Received .. " + responseService2); + assertTrue(responseService2.contains(randomName)); + + HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.inventory().size() == 0); + } + + @Test + public void testServiceClass() throws Exception { + System.out.println("-- testServiceClass() --"); + String randomName = UUID.randomUUID().toString(); + + HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5678, "/", true); + server.addServletClass("/*", RestEchoService.class.getCanonicalName()); + server.waitedStart(5000); + + assertTrue(HttpServletServer.factory.get(5678).isAlive()); + + String echo = "hello"; + URL urlService1 = new URL("http://localhost:5678/junit/echo/" + echo); + String responseService1 = response(urlService1); + System.out.println("Received .. " + responseService1); + assertTrue(responseService1.equals(echo)); + + HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.inventory().size() == 0); + } + + @Test + public void testMultiServiceClass() throws Exception { + System.out.println("-- testMultiServiceClass() --"); + + String randomName = UUID.randomUUID().toString(); + + HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5678, "/", true); + server.addServletClass("/*", RestEchoService.class.getCanonicalName()); + server.addServletClass("/*", RestEndpoints.class.getCanonicalName()); + server.waitedStart(5000); + + assertTrue(HttpServletServer.factory.get(5678).isAlive()); + + String echo = "hello"; + URL urlService1 = new URL("http://localhost:5678/junit/echo/" + echo); + String responseService1 = response(urlService1); + System.out.println("Received .. " + responseService1); + assertTrue(responseService1.equals(echo)); + + URL urlService2 = new URL("http://localhost:5678/junit/endpoints/http/servers"); + String responseService2 = response(urlService2); + System.out.println("Received .. " + responseService2); + assertTrue(responseService2.contains(randomName)); + + HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.inventory().size() == 0); + } + + /** + * @param url + * @throws IOException + */ + protected String response(URL url) throws IOException { + BufferedReader ioReader = new BufferedReader(new InputStreamReader(url.openStream())); + String response = ""; + String line; + while ((line = ioReader.readLine()) != null) { + response += line; + } + return response; + } + + + +} diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEchoService.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEchoService.java new file mode 100644 index 00000000..a0320a09 --- /dev/null +++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEchoService.java @@ -0,0 +1,19 @@ +package org.openecomp.policy.drools.http.server.test; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/junit/echo") +public class RestEchoService { + + @GET + @Path("{word}") + @Produces(MediaType.TEXT_PLAIN) + public String echo(@PathParam("word") String word) { + return word; + } + +} diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEndpoints.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEndpoints.java new file mode 100644 index 00000000..a00f2ffd --- /dev/null +++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEndpoints.java @@ -0,0 +1,25 @@ +package org.openecomp.policy.drools.http.server.test; + +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.openecomp.policy.drools.http.server.HttpServletServer; + +@Path("/junit/endpoints") +public class RestEndpoints { + + @GET + @Path("http/servers") + @Produces(MediaType.TEXT_PLAIN) + public String httpServers() { + List servers = + HttpServletServer.factory.inventory(); + return servers.toString(); + } + + +} diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestMockHealthCheck.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestMockHealthCheck.java new file mode 100644 index 00000000..ff1b4980 --- /dev/null +++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestMockHealthCheck.java @@ -0,0 +1,28 @@ +package org.openecomp.policy.drools.http.server.test; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +@Path("/") +public class RestMockHealthCheck { + + @GET + @Path("pap/test") + @Produces(MediaType.APPLICATION_JSON) + public Response papHealthCheck() { + return Response.status(Status.OK).entity("All Alive").build(); + } + + @GET + @Path("pdp/test") + @Produces(MediaType.APPLICATION_JSON) + public Response pdpHealthCheck() { + return Response.status(Status.INTERNAL_SERVER_ERROR).entity("At least some Dead").build(); + } + + +} diff --git a/policy-healthcheck/pom.xml b/policy-healthcheck/pom.xml new file mode 100644 index 00000000..c279cd1d --- /dev/null +++ b/policy-healthcheck/pom.xml @@ -0,0 +1,157 @@ + + + + + 4.0.0 + + + org.openecomp.policy.drools-pdp + drools-pdp + 1.0.0-SNAPSHOT + + + policy-healthcheck + + policy-healthcheck + Separately loadable module with healthcheck code + + + 1.8 + 1.8 + + + + + + maven-assembly-plugin + 2.6 + + + zipfile + + single + + package + + true + ${project.artifactId}-${project.version} + + src/assembly/assemble_zip.xml + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.8 + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/lib + false + true + true + false + false + false + org.opendaylight,com.brocade.odl + provided + + + + + + maven-resources-plugin + 2.6 + + + copy-version + + copy-resources + + validate + + ${basedir}/target/versions + + + src/main/resources/versions + + version.properties + + true + + + + + + copy-resources + + copy-resources + + validate + + ${basedir}/target/etc/bvc-extensions + + + src/main/resources/etc/bvc-extensions + + feature_config_template.cfg + feature_custom.install + + true + + + + + + + + + + + + org.openecomp.policy.drools-pdp + policy-core + 1.0.0-SNAPSHOT + + + org.openecomp.policy.drools-pdp + policy-endpoints + 1.0.0-SNAPSHOT + + + org.openecomp.policy.drools-pdp + policy-management + 1.0.0-SNAPSHOT + + + + diff --git a/policy-healthcheck/src/assembly/assemble_zip.xml b/policy-healthcheck/src/assembly/assemble_zip.xml new file mode 100644 index 00000000..266e1d0a --- /dev/null +++ b/policy-healthcheck/src/assembly/assemble_zip.xml @@ -0,0 +1,85 @@ + + + + + + runtime + + zip + + + + false + + + + target + lib/opt + + policy-healthcheck-${project.version}.jar + + + + target/assembly/ + . + + + + + . + lib + + *.jar + + + + src/main/server-gen/bin + bin + 0744 + + + + + src/main/server/bin + bin + 0744 + + + + + src/main/server-gen/scripts + scripts + + + src/main/server/scripts + scripts + + + src/main/server/config + config + + + + diff --git a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java new file mode 100644 index 00000000..2ed2e075 --- /dev/null +++ b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java @@ -0,0 +1,178 @@ +package org.openecomp.policy.drools.healthcheck; + +import java.util.ArrayList; +import java.util.Properties; + +import javax.ws.rs.core.Response; + +import org.openecomp.policy.drools.http.client.HttpClient; +import org.openecomp.policy.drools.http.server.HttpServletServer; +import org.openecomp.policy.drools.persistence.SystemPersistence; +import org.openecomp.policy.drools.properties.Startable; +import org.openecomp.policy.drools.system.PolicyEngine; + +public interface HealthCheck extends Startable { + + public static class Report { + public String name; + public String url; + public boolean healthy; + public int code; + public String message; + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Report [name="); + builder.append(name); + builder.append(", url="); + builder.append(url); + builder.append(", healthy="); + builder.append(healthy); + builder.append(", code="); + builder.append(code); + builder.append(", message="); + builder.append(message); + builder.append("]"); + return builder.toString(); + } + } + + public static class Reports { + public boolean healthy; + public ArrayList details = new ArrayList<>(); + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Reports [healthy="); + builder.append(healthy); + builder.append(", details="); + builder.append(details); + builder.append("]"); + return builder.toString(); + } + } + + public Reports healthCheck(); + + public static final HealthCheck monitor = new HealthCheckMonitor(); +} + +class HealthCheckMonitor implements HealthCheck { + + protected volatile ArrayList servers = new ArrayList<>(); + protected volatile ArrayList clients = new ArrayList<>(); + protected volatile Properties healthCheckProperties = null; + + public Reports healthCheck() { + Reports reports = new Reports(); + reports.healthy = PolicyEngine.manager.isAlive(); + + HealthCheck.Report engineReport = new Report(); + engineReport.healthy = PolicyEngine.manager.isAlive(); + engineReport.name = "PDP-D"; + engineReport.url = "self"; + engineReport.code = (PolicyEngine.manager.isAlive()) ? 200 : 500; + engineReport.message = (PolicyEngine.manager.isAlive()) ? "alive" : "not alive"; + reports.details.add(engineReport); + + for (HttpClient client : clients) { + HealthCheck.Report report = new Report(); + report.name = client.getName(); + report.url = client.getBaseUrl(); + report.healthy = true; + try { + Response response = client.get(); + report.code = response.getStatus(); + if (report.code != 200) { + report.healthy = false; + reports.healthy = false; + } + + try { + report.message = HttpClient.getBody(response, String.class); + } catch (Exception e) { + e.printStackTrace(); + } + } catch (Exception e) { + report.healthy = false; + reports.healthy = false; + } + reports.details.add(report); + } + return reports; + } + + @Override + public boolean start() throws IllegalStateException { + try { + this.healthCheckProperties = SystemPersistence.manager.getProperties(HealthCheckFeature.CONFIGURATION_PROPERTIES_NAME); + this.servers = HttpServletServer.factory.build(healthCheckProperties); + this.clients = HttpClient.factory.build(healthCheckProperties); + + for (HttpServletServer server : servers) { + try { + server.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + return false; + } + + return true; + } + + @Override + public boolean stop() throws IllegalStateException { + for (HttpServletServer server : servers) { + try { + server.stop(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + for (HttpClient client : clients) { + try { + client.stop(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + return true; + } + + @Override + public void shutdown() throws IllegalStateException { + this.stop(); + } + + @Override + public synchronized boolean isAlive() { + return this.healthCheckProperties != null; + } + + public ArrayList getServers() { + return this.servers; + } + + public ArrayList getClients() { + return this.clients; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("HealthCheckMonitor [servers="); + builder.append(servers); + builder.append(", clients="); + builder.append(clients); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java new file mode 100644 index 00000000..ce1dd90b --- /dev/null +++ b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java @@ -0,0 +1,92 @@ +package org.openecomp.policy.drools.healthcheck; + +import java.util.Properties; + +import org.kie.api.runtime.KieSession; +import org.openecomp.policy.drools.core.FeatureAPI; +import org.openecomp.policy.drools.core.PolicyContainer; +import org.openecomp.policy.drools.core.PolicySession; + +public class HealthCheckFeature implements FeatureAPI { + + public static final String CONFIGURATION_PROPERTIES_NAME = "policy-healthcheck"; + + @Override + public int getSequenceNumber() { + return 2; + } + + @Override + public void globalInit(String[] args, String configDir) { + return; + } + + @Override + public KieSession activatePolicySession(PolicyContainer policyContainer, String name, String kieBaseName) { + return null; + } + + @Override + public void disposeKieSession(PolicySession policySession) { + return; + } + + @Override + public void destroyKieSession(PolicySession policySession) { + return; + } + + @Override + public void beforeStartEngine() throws IllegalStateException { + return; + } + + @Override + public void afterStartEngine() { + try { + HealthCheck.monitor.start(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void beforeShutdownEngine() { + return; + } + + @Override + public void afterShutdownEngine() { + try { + HealthCheck.monitor.stop(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + + @Override + public void beforeCreateController(String name, Properties properties) { + return; + } + + @Override + public void afterCreateController(String name) { + return; + } + + @Override + public void beforeStartController(String name) { + return; + } + + @Override + public void afterStartController(String name) { + return; + } + + @Override + public boolean isPersistenceEnabled() { + return false; + } + +} diff --git a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java new file mode 100644 index 00000000..e37e758a --- /dev/null +++ b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java @@ -0,0 +1,27 @@ +package org.openecomp.policy.drools.healthcheck; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.openecomp.policy.drools.healthcheck.HealthCheck.Reports; + +@Path("/") +public class RestHealthCheck { + + @GET + @Path("{a:healthcheck|test}") + @Produces(MediaType.APPLICATION_JSON) + public Reports healthcheck() { + Reports reports = HealthCheck.monitor.healthCheck(); + return reports; + } + + @GET + @Path("healthcheck/configuration") + @Produces(MediaType.APPLICATION_JSON) + public HealthCheck configuration() { + return HealthCheck.monitor; + } +} diff --git a/policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI b/policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI new file mode 100644 index 00000000..7e307d08 --- /dev/null +++ b/policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI @@ -0,0 +1 @@ +org.openecomp.policy.drools.healthcheck.HealthCheckFeature diff --git a/policy-management/config/policy-engine.properties b/policy-management/config/policy-engine.properties new file mode 100644 index 00000000..41456c27 --- /dev/null +++ b/policy-management/config/policy-engine.properties @@ -0,0 +1,26 @@ +# Policy Engine Configuration + +# Configuration Channel Settings: PDPD_CONFIGURATION + +ueb.source.topics=PDPD_CONFIGURATION +ueb.source.topics.PDPD_CONFIGURATION.servers= +ueb.source.topics.PDPD_CONFIGURATION.apiKey= +ueb.source.topics.PDPD_CONFIGURATION.apiSecret= +ueb.source.topics.PDPD_CONFIGURATION.consumerGroup= +ueb.source.topics.PDPD_CONFIGURATION.consumerInstance= +ueb.source.topics.PDPD_CONFIGURATION.managed=false + +ueb.sink.topics=PDPD_CONFIGURATION +ueb.sink.topics.PDPD_CONFIGURATION.servers= +ueb.sink.topics.PDPD_CONFIGURATION.apiKey= +ueb.sink.topics.PDPD_CONFIGURATION.apiSecret= +ueb.sink.topics.PDPD_CONFIGURATION.partitionKey= +ueb.sink.topics.PDPD_CONFIGURATION.managed=false + +http.server.services=CONFIG +http.server.services.CONFIG.host=localhost +http.server.services.CONFIG.port=9696 +http.server.services.CONFIG.userName=x +http.server.services.CONFIG.password=y +http.server.services.CONFIG.restPackages=org.openecomp.policy.drools.server.restful +http.server.services.CONFIG.managed=false diff --git a/policy-management/config/policyLogger.properties b/policy-management/config/policyLogger.properties new file mode 100644 index 00000000..f8f31d8f --- /dev/null +++ b/policy-management/config/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# policy-management +# ================================================================================ +# Copyright (C) 2017 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/policy-management/pom.xml b/policy-management/pom.xml new file mode 100644 index 00000000..2983f1f4 --- /dev/null +++ b/policy-management/pom.xml @@ -0,0 +1,259 @@ + + + + + 4.0.0 + + + org.openecomp.policy.drools-pdp + drools-pdp + 1.0.0-SNAPSHOT + + + policy-management + + policy-management + Policy Management + + + 1.8 + 1.8 + 9.3.8.v20160314 + 2.22.2 + 2.8.4 + 2.8.0 + + + + + + + maven-assembly-plugin + 2.6 + + + zipfile + + single + + package + + true + ${project.artifactId}-${project.version} + + src/assembly/assemble_zip.xml + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.8 + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/lib + false + true + true + false + false + false + org.opendaylight,com.brocade.odl + provided + + + + + + maven-resources-plugin + 2.6 + + + copy-version + + copy-resources + + validate + + ${basedir}/target/versions + + + src/main/resources/versions + + version.properties + + true + + + + + + copy-resources + + copy-resources + + validate + + ${basedir}/target/etc/bvc-extensions + + + src/main/resources/etc/bvc-extensions + + feature_config_template.cfg + feature_custom.install + + true + + + + + + + + + + + + + org.openecomp.policy.drools-pdp + policy-core + 1.0.0-SNAPSHOT + + + + org.openecomp.policy.drools-pdp + policy-endpoints + 1.0.0-SNAPSHOT + + + + org.eclipse.jetty + jetty-server + ${jetty.version} + + + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + + + + org.glassfish.jersey.core + jersey-server + ${jersey.version} + + + + org.glassfish.jersey.containers + jersey-container-servlet-core + ${jersey.version} + + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + + + + org.glassfish.jersey.containers + jersey-container-jetty-http + ${jersey.version} + + + org.eclipse.jetty + jetty-util + + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + + com.google.code.gson + gson + ${gson.version} + + + + com.fatboyindustrial.gson-javatime-serialisers + gson-javatime-serialisers + 1.1.1 + + + + org.apache.commons + commons-collections4 + 4.1 + + + + + org.apache.commons + commons-lang3 + 3.4 + + + + log4j + log4j + 1.2.17 + + + + junit + junit + 4.11 + test + + + + + diff --git a/policy-management/src/assembly/assemble_zip.xml b/policy-management/src/assembly/assemble_zip.xml new file mode 100644 index 00000000..85a1dbfa --- /dev/null +++ b/policy-management/src/assembly/assemble_zip.xml @@ -0,0 +1,85 @@ + + + + + + runtime + + zip + + + + false + + + + target + lib + + policy-management-${project.version}.jar + + + + target/assembly/ + . + + + + + . + lib + + *.jar + + + + src/main/server-gen/bin + bin + 0744 + + + + + src/main/server/bin + bin + 0744 + + + + + src/main/server-gen/scripts + scripts + + + src/main/server/scripts + scripts + + + src/main/server/config + config + + + + diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java new file mode 100644 index 00000000..72f8e0b2 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java @@ -0,0 +1,170 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.controller; + +import java.util.List; + +import org.openecomp.policy.drools.event.comm.TopicSink; +import org.openecomp.policy.drools.properties.Lockable; +import org.openecomp.policy.drools.properties.Startable; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration; + +/** + * Drools Controller is the abstractions that wraps the + * drools layer (policy-core) + */ +public interface DroolsController extends Startable, Lockable { + + /** + * No Group ID identifier + */ + public static final String NO_GROUP_ID = "NO-GROUP-ID"; + + /** + * No Artifact ID identifier + */ + public static final String NO_ARTIFACT_ID = "NO-ARTIFACT-ID"; + + /** + * No version identifier + */ + public static final String NO_VERSION = "NO-VERSION"; + + /** + * get group id + * @return group id + */ + public String getGroupId(); + + /** + * get artifact id + * @return artifact id + */ + public String getArtifactId(); + + /** + * get version + * @return version + */ + public String getVersion(); + + + /** + * return the policy session names + * + * @return policy session + */ + public List getSessionNames(); + + /** + * offers an event to this controller for processing + * + * @param topic topic associated with the event + * @param event the event + * + * @return true if the operation was successful + */ + public boolean offer(String topic, String event); + + /** + * delivers "event" to "sink" + * + * @param sink destination + * @param event + * @return true if successful, false if a failure has occurred. + * @throws IllegalArgumentException when invalid or insufficient + * properties are provided + * @throws IllegalStateException when the engine is in a state where + * this operation is not permitted (ie. locked or stopped). + * @throws UnsupportedOperationException when the engine cannot deliver due + * to the functionality missing (ie. communication infrastructure + * not supported. + */ + public boolean deliver(TopicSink sink, Object event) + throws IllegalArgumentException, IllegalStateException, + UnsupportedOperationException; + + /** + * + * @return the most recent received events + */ + public Object[] getRecentSourceEvents(); + + /** + * + * @return the most recent delivered events + */ + public String[] getRecentSinkEvents(); + + /** + * Supports this encoder? + * + * @param encodedObject + * @return + */ + public boolean ownsCoder(Class coderClass, int modelHash) throws IllegalStateException; + + /** + * fetches a class from the model + * + * @param className the class to fetch + * @return the actual class object, or null if not found + */ + public Class fetchModelClass(String className) throws IllegalArgumentException; + + /** + * is this controller Smart? + */ + public boolean isBrained(); + + /** + * update the new version of the maven jar rules file + * + * @param newGroupId - new group id + * @param newArtifactId - new artifact id + * @param newVersion - new version + * @param decoderConfigurations - decoder configurations + * @param encoderConfigurations - encoder configurations + * + * @throws Exception from within drools libraries + * @throws LinkageError from within drools libraries + * @throws ArgumentException bad parameter passed in + */ + public void updateToVersion(String newGroupId, String newArtifactId, String newVersion, + List decoderConfigurations, + List encoderConfigurations) + throws IllegalArgumentException, LinkageError, Exception; + + + /** + * halts and permanently releases all resources + * @throws IllegalStateException + */ + public void halt() throws IllegalStateException; + + /** + * Factory to track and manage drools controllers + */ + public static final DroolsControllerFactory factory = + new IndexedDroolsControllerFactory(); + + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsControllerFactory.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsControllerFactory.java new file mode 100644 index 00000000..d94e773c --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsControllerFactory.java @@ -0,0 +1,540 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.controller; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.controller.internal.MavenDroolsController; +import org.openecomp.policy.drools.controller.internal.NullDroolsController; +import org.openecomp.policy.drools.event.comm.Topic; +import org.openecomp.policy.drools.event.comm.Topic.CommInfrastructure; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.event.comm.TopicSource; +import org.openecomp.policy.drools.event.comm.TopicSink; +import org.openecomp.policy.drools.properties.PolicyProperties; +import org.openecomp.policy.drools.protocol.coders.JsonProtocolFilter; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.PotentialCoderFilter; +import org.openecomp.policy.drools.utils.Pair; + +/** + * Drools Controller Factory to manage controller creation, destruction, + * and retrieval for management interfaces + */ +public interface DroolsControllerFactory { + + /** + * Constructs a Drools Controller based on properties + * + * @param properties properties containing initialization parameters + * @param eventSources list of event sources + * @param eventSinks list of event sinks + * + * @return the instantiated Drools Controller + * @throws IllegalArgumentException with invalid parameters + * @throws LinkageError Failure to link rules and models in Drools Libraries + * @throws Exception Exception from Drools Libraries + */ + public DroolsController build(Properties properties, + List eventSources, + List eventSinks) + throws IllegalArgumentException, LinkageError, Exception; + + /** + * Explicit construction of a Drools Controller + * + * @param groupId maven group id of drools artifact + * @param artifactId maven artifact id of drools artifact + * @param version maven version id of drools artifact + * @param decoderConfigurations list of decoder configurations + * @param encoderConfigurations list of encoder configurations + * + * @return the instantiated Drools Controller + * @throws IllegalArgumentException with invalid parameters + * @throws LinkageError Failure to link rules and models in Drools Libraries + * @throws Exception Exception from Drools Libraries + */ + public DroolsController build(String groupId, + String artifactId, + String version, + List decoderConfigurations, + List encoderConfigurations) + throws IllegalArgumentException, LinkageError, Exception; + + /** + * Releases the Drools Controller from operation + * + * @param controller the Drools Controller to shut down + */ + public void shutdown(DroolsController controller); + + /** + * Disables all Drools Controllers from operation + */ + public void shutdown(); + + /** + * Destroys and releases resources for a Drools Controller + * + * @param controller the Drools Controller to destroy + */ + public void destroy(DroolsController controller); + + /** + * Destroys all Drools Controllers + */ + public void destroy(); + + /** + * Gets the Drools Controller associated with the maven group + * and artifact id + * + * @param groupId maven group id of drools artifact + * @param artifactId maven artifact id of drools artifact + * @param version maven version id of drools artifact + * + * @return the Drools Controller + * @throws IllegalArgumentException with invalid parameters + */ + public DroolsController get(String groupId, + String artifactId, + String version) + throws IllegalArgumentException; + + /** + * returns the current inventory of Drools Controllers + * + * @return a list of Drools Controllers + */ + public List inventory(); +} + +/* ---------------- implementation -----------------*/ + +/** + * Factory of Drools Controllers indexed by the Maven coordinates + */ +class IndexedDroolsControllerFactory implements DroolsControllerFactory { + + /** + * logger + */ + private static Logger logger = FlexLogger.getLogger(MavenDroolsController.class); + + /** + * Policy Controller Name Index + */ + protected HashMap droolsControllers = + new HashMap(); + + /** + * Null Drools Controller + */ + protected NullDroolsController nullDroolsController = new NullDroolsController(); + + + public IndexedDroolsControllerFactory() { + + /* Add a NULL controller which will always be present in the hash */ + + DroolsController controller = new NullDroolsController(); + String controllerId = controller.getGroupId() + ":" + controller.getArtifactId(); + + synchronized(this) { + droolsControllers.put(controllerId, controller); + } + } + + /** + * {@inheritDoc} + */ + @Override + public DroolsController build(Properties properties, + List eventSources, + List eventSinks) + throws IllegalArgumentException, LinkageError, Exception { + + String groupId = properties.getProperty(PolicyProperties.RULES_GROUPID); + if (groupId == null || groupId.isEmpty()) + groupId = DroolsController.NO_GROUP_ID; + + String artifactId = properties.getProperty(PolicyProperties.RULES_ARTIFACTID); + if (artifactId == null || artifactId.isEmpty()) + artifactId = DroolsController.NO_ARTIFACT_ID; + + String version = properties.getProperty(PolicyProperties.RULES_VERSION); + if (version == null || version.isEmpty()) + version = DroolsController.NO_VERSION; + + List + topics2DecodedClasses2Filters = codersAndFilters(properties, eventSources); + + List + topics2EncodedClasses2Filters = codersAndFilters(properties, eventSinks); + + return this.build(groupId, artifactId, version, + topics2DecodedClasses2Filters, + topics2EncodedClasses2Filters); + } + + /** + * find out decoder classes and filters + * + * @param properties properties with information about decoders + * @param topicEntities topic sources + * @return list of topics, each with associated decoder classes, each + * with a list of associated filters + * @throws IllegalArgumentException invalid input data + */ + protected List codersAndFilters + (Properties properties, List topicEntities) + throws IllegalArgumentException { + + String PROPERTY_TOPIC_ENTITY_PREFIX; + + List + topics2DecodedClasses2Filters = + new ArrayList(); + + if (topicEntities.isEmpty()) + return topics2DecodedClasses2Filters; + + for (Topic topic: topicEntities) { + + /* source or sink ? ueb or dmaap? */ + boolean isSource = (topic instanceof TopicSource); + CommInfrastructure commInfra = topic.getTopicCommInfrastructure(); + if (commInfra == CommInfrastructure.UEB) { + if (isSource) { + PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + "."; + } else { + PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_UEB_SINK_TOPICS + "."; + } + } else if (commInfra == CommInfrastructure.DMAAP) { + if (isSource) { + PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "."; + } else { + PROPERTY_TOPIC_ENTITY_PREFIX = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + "."; + } + } else { + throw new IllegalArgumentException("Invalid Communication Infrastructure: " + commInfra); + } + + // 1. first the topic + + String aTopic = topic.getTopic(); + + // 2. check if there is a custom decoder for this topic that the user prefers to use + // instead of the ones provided in the platform + + String customGson = properties.getProperty + (PROPERTY_TOPIC_ENTITY_PREFIX + + aTopic + + PolicyProperties.PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_GSON_SUFFIX); + + CustomGsonCoder customGsonCoder = null; + if (customGson != null && !customGson.isEmpty()) { + try { + customGsonCoder = new CustomGsonCoder(customGson); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + + String customJackson = properties.getProperty + (PROPERTY_TOPIC_ENTITY_PREFIX + + aTopic + + PolicyProperties.PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_JACKSON_SUFFIX); + + CustomJacksonCoder customJacksonCoder = null; + if (customJackson != null && !customJackson.isEmpty()) { + try { + customJacksonCoder = new CustomJacksonCoder(customJackson); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + + // 3. second the list of classes associated with each topic + + String eventClasses = + properties.getProperty(PROPERTY_TOPIC_ENTITY_PREFIX + aTopic + PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX); + + if (eventClasses == null || eventClasses.isEmpty()) { + // TODO warn + continue; + } + + List classes2Filters = new ArrayList(); + + List aTopicClasses = + new ArrayList(Arrays.asList(eventClasses.split("\\s*,\\s*"))); + + for (String aClass: aTopicClasses) { + + + // 4. third, for each coder class, get the list of field filters + + String filter = properties.getProperty + (PROPERTY_TOPIC_ENTITY_PREFIX + + aTopic + + PolicyProperties.PROPERTY_TOPIC_EVENTS_SUFFIX + + "." + aClass + + PolicyProperties.PROPERTY_TOPIC_EVENTS_FILTER_SUFFIX); + + List> filters = new ArrayList>(); + + if (filter == null || filter.isEmpty()) { + // 4. topic -> class -> with no filters + + JsonProtocolFilter protocolFilter = JsonProtocolFilter.fromRawFilters(filters); + PotentialCoderFilter class2Filters = + new PotentialCoderFilter(aClass, protocolFilter); + classes2Filters.add(class2Filters); + continue; + } + + // There are filters associated with the applicability of + // this class for decoding. + List listOfFilters = + new ArrayList(Arrays.asList(filter.split("\\s*,\\s*"))); + + for (String nameValue: listOfFilters) { + String fieldName; + String regexValue; + + String[] nameValueSplit = nameValue.split("\\s*=\\s*"); + if (nameValueSplit.length <= 0 || nameValueSplit.length > 2) { + // TODO warn + // skip + continue; + } + + if (nameValueSplit.length == 2) { + fieldName = nameValueSplit[0]; + regexValue = nameValueSplit[1]; + } else if (nameValueSplit.length == 1) { + fieldName = nameValueSplit[0]; + regexValue = null; + } else { + // unreachable + continue; + } + + filters.add(new Pair(fieldName, regexValue)); + } + + JsonProtocolFilter protocolFilter = JsonProtocolFilter.fromRawFilters(filters); + PotentialCoderFilter class2Filters = + new PotentialCoderFilter(aClass, protocolFilter); + classes2Filters.add(class2Filters); + } + + TopicCoderFilterConfiguration topic2Classes2Filters = + new TopicCoderFilterConfiguration(aTopic,classes2Filters, customGsonCoder, customJacksonCoder); + topics2DecodedClasses2Filters.add(topic2Classes2Filters); + } + + return topics2DecodedClasses2Filters; + } + + /** + * {@inheritDoc} + * @param decoderConfiguration + */ + @Override + public DroolsController build(String newGroupId, + String newArtifactId, + String newVersion, + List decoderConfigurations, + List encoderConfigurations) + throws IllegalArgumentException, LinkageError, Exception { + + if (newGroupId == null || newArtifactId == null || newVersion == null || + newGroupId.isEmpty() || newArtifactId.isEmpty() || newVersion.isEmpty()) { + throw new IllegalArgumentException("Missing maven coordinates: " + + newGroupId + ":" + newArtifactId + ":" + + newVersion); + } + + String controllerId = newGroupId + ":" + newArtifactId; + DroolsController controllerCopy = null; + synchronized (this) { + /* + * The Null Drools Controller for no maven coordinates is always here + * so when no coordinates present, this is the return point + * + * assert (controllerCopy instanceof NullDroolsController) + */ + if (droolsControllers.containsKey(controllerId)) { + controllerCopy = droolsControllers.get(controllerId); + if (controllerCopy.getVersion().equalsIgnoreCase(newVersion)) { + return controllerCopy; + } + } + } + + if (controllerCopy != null) { + /* + * a controller keyed by group id + artifact id exists + * but with different version => version upgrade/downgrade + */ + + controllerCopy.updateToVersion(newGroupId, newArtifactId, newVersion, + decoderConfigurations, encoderConfigurations); + + return controllerCopy; + } + + /* new drools controller */ + + DroolsController controller = new MavenDroolsController + (newGroupId, newArtifactId, newVersion, + decoderConfigurations, + encoderConfigurations); + + synchronized(this) { + droolsControllers.put(controllerId, controller); + } + + return controller; + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy(DroolsController controller) throws IllegalArgumentException { + unmanage(controller); + controller.halt(); + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy() { + List controllers = this.inventory(); + for (DroolsController controller: controllers) { + controller.halt(); + } + + synchronized(this) { + this.droolsControllers.clear(); + } + } + + /** + * unmanage the drools controller + * + * @param controller + * @return + * @throws IllegalArgumentException + */ + protected void unmanage(DroolsController controller) throws IllegalArgumentException { + if (controller == null) { + throw new IllegalArgumentException("No controller provided"); + } + + if (!controller.isBrained()) { + logger.info("Drools Controller is NOT OPERATIONAL - nothing to destroy"); + return; + } + + String controllerId = controller.getGroupId() + ":" + controller.getArtifactId(); + synchronized(this) { + if (!this.droolsControllers.containsKey(controllerId)) { + return; + } + + droolsControllers.remove(controllerId); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown(DroolsController controller) throws IllegalArgumentException { + this.unmanage(controller); + controller.shutdown(); + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() { + List controllers = this.inventory(); + for (DroolsController controller: controllers) { + controller.shutdown(); + } + + synchronized(this) { + this.droolsControllers.clear(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public DroolsController get(String groupId, + String artifactId, + String version) + throws IllegalArgumentException, IllegalStateException { + + if (groupId == null || artifactId == null || + groupId.isEmpty() || artifactId.isEmpty()) { + throw new IllegalArgumentException("Missing maven coordinates: " + + groupId + ":" + artifactId); + } + + String controllerId = groupId + ":" + artifactId; + + synchronized(this) { + if (this.droolsControllers.containsKey(controllerId)) { + return droolsControllers.get(controllerId); + } else { + throw new IllegalStateException("DroolController for " + + controllerId + " not found"); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public List inventory() { + List controllers = + new ArrayList(this.droolsControllers.values()); + return controllers; + } + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java new file mode 100644 index 00000000..2c5708d3 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java @@ -0,0 +1,718 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.controller.internal; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.collections4.queue.CircularFifoQueue; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.drools.core.PolicyContainer; +import org.openecomp.policy.drools.core.PolicySession; +import org.openecomp.policy.drools.core.jmx.PdpJmx; +import org.openecomp.policy.drools.event.comm.TopicSink; +import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder; +import org.openecomp.policy.drools.protocol.coders.JsonProtocolFilter; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.PotentialCoderFilter; +import org.openecomp.policy.drools.utils.ReflectionUtil; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * Maven-based Drools Controller that interacts with the + * policy-core PolicyContainer and PolicySession to manage + * Drools containers instantiated using Maven. + */ +public class MavenDroolsController implements DroolsController { + + /** + * logger + */ + private static Logger logger = FlexLogger.getLogger(MavenDroolsController.class); + + /** + * Policy Container, the access object to the policy-core layer + */ + @JsonIgnore + protected final PolicyContainer policyContainer; + + /** + * alive status of this drools controller, + * reflects invocation of start()/stop() only + */ + protected volatile boolean alive = false; + + /** + * locked status of this drools controller, + * reflects if i/o drools related operations are permitted, + * more specifically: offer() and deliver(). + * It does not affect the ability to start and stop + * underlying drools infrastructure + */ + protected volatile boolean locked = false; + + /** + * list of topics, each with associated decoder classes, each + * with a list of associated filters. + */ + protected List decoderConfigurations; + + /** + * list of topics, each with associated encoder classes, each + * with a list of associated filters. + */ + protected List encoderConfigurations; + + /** + * recent source events processed + */ + protected final CircularFifoQueue recentSourceEvents = new CircularFifoQueue(10); + + /** + * recent sink events processed + */ + protected final CircularFifoQueue recentSinkEvents = new CircularFifoQueue(10); + + /** + * original Drools Model/Rules classloader hash + */ + protected int modelClassLoaderHash; + + /** + * Expanded version of the constructor + * + * @param groupId maven group id + * @param artifactId maven artifact id + * @param version maven version + * @param decoderConfiguration list of topic -> decoders -> filters mapping + * @param encoderConfiguration list of topic -> encoders -> filters mapping + * + * @throws IllegalArgumentException invalid arguments passed in + */ + public MavenDroolsController(String groupId, + String artifactId, + String version, + List decoderConfigurations, + List encoderConfigurations) + throws IllegalArgumentException { + + if (logger.isInfoEnabled()) + logger.info("DROOLS CONTROLLER: instantiation " + this + + " -> {" + groupId + ":" + artifactId + ":" + version + "}"); + + if (groupId == null || artifactId == null || version == null || + groupId.isEmpty() || artifactId.isEmpty() || version.isEmpty()) { + throw new IllegalArgumentException("Missing maven coordinates: " + + groupId + ":" + artifactId + ":" + + version); + } + + this.policyContainer= new PolicyContainer(groupId, artifactId, version); + this.init(decoderConfigurations, encoderConfigurations); + + if (logger.isInfoEnabled()) + logger.info("DROOLS CONTROLLER: instantiation completed " + this); + } + + /** + * init encoding/decoding configuration + * @param decoderConfiguration list of topic -> decoders -> filters mapping + * @param encoderConfiguration list of topic -> encoders -> filters mapping + */ + protected void init(List decoderConfigurations, + List encoderConfigurations) { + + this.decoderConfigurations = decoderConfigurations; + this.encoderConfigurations = encoderConfigurations; + + this.initCoders(decoderConfigurations, true); + this.initCoders(encoderConfigurations, false); + + this.modelClassLoaderHash = this.policyContainer.getClassLoader().hashCode(); + } + + /** + * {@inheritDoc} + */ + @Override + public void updateToVersion(String newGroupId, String newArtifactId, String newVersion, + List decoderConfigurations, + List encoderConfigurations) + throws IllegalArgumentException, LinkageError, Exception { + + if (logger.isInfoEnabled()) + logger.info("UPDATE-TO-VERSION: " + this + " -> {" + newGroupId + ":" + newArtifactId + ":" + newVersion + "}"); + + if (newGroupId == null || newArtifactId == null || newVersion == null || + newGroupId.isEmpty() || newArtifactId.isEmpty() || newVersion.isEmpty()) { + throw new IllegalArgumentException("Missing maven coordinates: " + + newGroupId + ":" + newArtifactId + ":" + + newVersion); + } + + if (newGroupId.equalsIgnoreCase(DroolsController.NO_GROUP_ID) || + newArtifactId.equalsIgnoreCase(DroolsController.NO_ARTIFACT_ID) || + newVersion.equalsIgnoreCase(DroolsController.NO_VERSION)) { + throw new IllegalArgumentException("BRAINLESS maven coordinates provided: " + + newGroupId + ":" + newArtifactId + ":" + + newVersion); + } + + if (newGroupId.equalsIgnoreCase(this.getGroupId()) && + newArtifactId.equalsIgnoreCase(this.getArtifactId()) && + newVersion.equalsIgnoreCase(this.getVersion())) { + logger.warn("Al in the right version: " + newGroupId + ":" + + newArtifactId + ":" + newVersion + " vs. " + this); + return; + } + + if (!newGroupId.equalsIgnoreCase(this.getGroupId()) || + !newArtifactId.equalsIgnoreCase(this.getArtifactId())) { + throw new IllegalArgumentException("Group ID and Artifact ID maven coordinates must be identical for the upgrade: " + + newGroupId + ":" + newArtifactId + ":" + + newVersion + " vs. " + this); + } + + /* upgrade */ + String messages = this.policyContainer.updateToVersion(newVersion); + if (logger.isWarnEnabled()) + logger.warn(this + "UPGRADE results: " + messages); + + /* + * If all sucessful (can load new container), now we can remove all coders from previous sessions + */ + this.removeCoders(); + + /* + * add the new coders + */ + this.init(decoderConfigurations, encoderConfigurations); + + if (logger.isInfoEnabled()) + logger.info("UPDATE-TO-VERSION: completed " + this); + } + + /** + * initialize decoders for all the topics supported by this controller + * Note this is critical to be done after the Policy Container is + * instantiated to be able to fetch the corresponding classes. + * + * @param decoderConfiguration list of topic -> decoders -> filters mapping + */ + protected void initCoders(List coderConfigurations, + boolean decoder) + throws IllegalArgumentException { + + if (logger.isInfoEnabled()) + logger.info("INIT-CODERS: " + this); + + if (coderConfigurations == null) { + return; + } + + + for (TopicCoderFilterConfiguration coderConfig: coderConfigurations) { + String topic = coderConfig.getTopic(); + + CustomGsonCoder customGsonCoder = coderConfig.getCustomGsonCoder(); + if (coderConfig.getCustomGsonCoder() != null && + coderConfig.getCustomGsonCoder().getClassContainer() != null && + !coderConfig.getCustomGsonCoder().getClassContainer().isEmpty()) { + + String customGsonCoderClass = coderConfig.getCustomGsonCoder().getClassContainer(); + if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), + customGsonCoderClass)) { + logger.error(customGsonCoderClass + " cannot be retrieved"); + throw new IllegalArgumentException(customGsonCoderClass + " cannot be retrieved"); + } else { + if (logger.isInfoEnabled()) + logger.info("CLASS FETCHED " + customGsonCoderClass); + } + } + + CustomJacksonCoder customJacksonCoder = coderConfig.getCustomJacksonCoder(); + if (coderConfig.getCustomJacksonCoder() != null && + coderConfig.getCustomJacksonCoder().getClassContainer() != null && + !coderConfig.getCustomJacksonCoder().getClassContainer().isEmpty()) { + + String customJacksonCoderClass = coderConfig.getCustomJacksonCoder().getClassContainer(); + if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), + customJacksonCoderClass)) { + logger.error(customJacksonCoderClass + " cannot be retrieved"); + throw new IllegalArgumentException(customJacksonCoderClass + " cannot be retrieved"); + } else { + if (logger.isInfoEnabled()) + logger.info("CLASS FETCHED " + customJacksonCoderClass); + } + } + + List coderFilters = coderConfig.getCoderFilters(); + if (coderFilters == null || coderFilters.isEmpty()) { + continue; + } + + for (PotentialCoderFilter coderFilter : coderFilters) { + String potentialCodedClass = coderFilter.getCodedClass(); + JsonProtocolFilter protocolFilter = coderFilter.getFilter(); + + if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), + potentialCodedClass)) { + logger.error(potentialCodedClass + " cannot be retrieved"); + throw new IllegalArgumentException(potentialCodedClass + " cannot be retrieved"); + } else { + if (logger.isInfoEnabled()) + logger.info("CLASS FETCHED " + potentialCodedClass); + } + + if (decoder) + EventProtocolCoder.manager.addDecoder(this.getGroupId(), this.getArtifactId(), + topic, potentialCodedClass, protocolFilter, + customGsonCoder, + customJacksonCoder, + this.policyContainer.getClassLoader().hashCode()); + else + EventProtocolCoder.manager.addEncoder(this.getGroupId(), this.getArtifactId(), + topic, potentialCodedClass, protocolFilter, + customGsonCoder, + customJacksonCoder, + this.policyContainer.getClassLoader().hashCode()); + } + } + } + + + /** + * remove decoders. + */ + protected void removeDecoders() + throws IllegalArgumentException { + if (logger.isInfoEnabled()) + logger.info("REMOVE-DECODERS: " + this); + + if (this.decoderConfigurations == null) { + return; + } + + + for (TopicCoderFilterConfiguration coderConfig: decoderConfigurations) { + String topic = coderConfig.getTopic(); + EventProtocolCoder.manager.removeDecoders + (this.getGroupId(), this.getArtifactId(), topic); + } + } + + /** + * remove decoders. + */ + protected void removeEncoders() + throws IllegalArgumentException { + + if (logger.isInfoEnabled()) + logger.info("REMOVE-ENCODERS: " + this); + + if (this.encoderConfigurations == null) + return; + + + for (TopicCoderFilterConfiguration coderConfig: encoderConfigurations) { + String topic = coderConfig.getTopic(); + EventProtocolCoder.manager.removeEncoders + (this.getGroupId(), this.getArtifactId(), topic); + } + } + + + /** + * {@inheritDoc} + */ + @Override + public boolean ownsCoder(Class coderClass, int modelHash) throws IllegalStateException { + if (!ReflectionUtil.isClass + (this.policyContainer.getClassLoader(), coderClass.getCanonicalName())) { + logger.error(this + coderClass.getCanonicalName() + " cannot be retrieved. "); + return false; + } + + if (modelHash == this.modelClassLoaderHash) { + if (logger.isInfoEnabled()) + logger.info(coderClass.getCanonicalName() + + this + " class loader matches original drools controller rules classloader " + + coderClass.getClassLoader()); + return true; + } else { + if (logger.isWarnEnabled()) + logger.warn(this + coderClass.getCanonicalName() + " class loaders don't match " + + coderClass.getClassLoader() + " vs " + + this.policyContainer.getClassLoader()); + return false; + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean start() { + + if (logger.isInfoEnabled()) + logger.info("START: " + this); + + synchronized (this) { + if (this.alive) + return true; + + this.alive = true; + } + + return this.policyContainer.start(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean stop() { + + logger.info("STOP: " + this); + + synchronized (this) { + if (!this.alive) + return true; + + this.alive = false; + } + + return this.policyContainer.stop(); + } + + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() throws IllegalStateException { + + if (logger.isInfoEnabled()) + logger.info(this + "SHUTDOWN"); + + try { + this.stop(); + this.removeCoders(); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "stop", this.toString()); + } finally { + this.policyContainer.shutdown(); + } + + } + + + /** + * {@inheritDoc} + */ + @Override + public void halt() throws IllegalStateException { + if (logger.isInfoEnabled()) + logger.info(this + "SHUTDOWN"); + + try { + this.stop(); + this.removeCoders(); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "halt", this.toString()); + } finally { + this.policyContainer.destroy(); + } + } + + /** + * removes this drools controllers and encoders and decoders from operation + */ + protected void removeCoders() { + + if (logger.isInfoEnabled()) + logger.info(this + "REMOVE-CODERS"); + + try { + this.removeDecoders(); + } catch (IllegalArgumentException e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "removeDecoders", this.toString()); + } + + try { + this.removeEncoders(); + } catch (IllegalArgumentException e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "removeEncoders", this.toString()); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAlive() { + return this.alive; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean offer(String topic, String event) { + + if (logger.isInfoEnabled()) + logger.info("OFFER: " + topic + ":" + event + " INTO " + this); + + if (this.locked) + return true; + + if (!this.alive) + return true; + + // 0. Check if the policy container has any sessions + + if (this.policyContainer.getPolicySessions().size() <= 0) { + // no sessions + return true; + } + + // 1. Now, check if this topic has a decoder: + + if (!EventProtocolCoder.manager.isDecodingSupported(this.getGroupId(), + this.getArtifactId(), + topic)) { + + logger.warn("DECODING-UNSUPPORTED: " + ":" + this.getGroupId() + + ":" + this.getArtifactId() + ":" + topic + " IN " + this); + return true; + } + + // 2. Decode + + Object anEvent; + try { + anEvent = EventProtocolCoder.manager.decode(this.getGroupId(), + this.getArtifactId(), + topic, + event); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, + "DECODE:"+ this.getGroupId() + ":" + + this.getArtifactId() + ":" + topic + ":" + event, + this.toString()); + return true; + } + + synchronized(this.recentSourceEvents) { + this.recentSourceEvents.add(anEvent); + } + + // increment event count for Nagios monitoring + PdpJmx.getInstance().updateOccured(); + + // Broadcast + + if (logger.isInfoEnabled()) + logger.info(this + "BROADCAST-INJECT of " + event + " FROM " + topic + " INTO " + this.policyContainer.getName()); + + if (!this.policyContainer.insertAll(anEvent)) + logger.warn(this + "Failed to inject into PolicyContainer " + this.getSessionNames()); + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean deliver(TopicSink sink, Object event) + throws IllegalArgumentException, + IllegalStateException, + UnsupportedOperationException { + + if (logger.isInfoEnabled()) + logger.info(this + "DELIVER: " + event + " FROM " + this + " TO " + sink); + + if (sink == null) + throw new IllegalArgumentException + (this + " invalid sink"); + + if (event == null) + throw new IllegalArgumentException + (this + " invalid event"); + + if (this.locked) + throw new IllegalStateException + (this + " is locked"); + + if (!this.alive) + throw new IllegalStateException + (this + " is stopped"); + + String json = + EventProtocolCoder.manager.encode(sink.getTopic(), event, this); + + synchronized(this.recentSinkEvents) { + this.recentSinkEvents.add(json); + } + + return sink.send(json); + + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return this.policyContainer.getVersion(); + } + + /** + * {@inheritDoc} + */ + @Override + public String getArtifactId() { + return this.policyContainer.getArtifactId(); + } + + /** + * {@inheritDoc} + */ + @Override + public String getGroupId() { + return this.policyContainer.getGroupId(); + } + + /** + * @return the modelClassLoaderHash + */ + public int getModelClassLoaderHash() { + return modelClassLoaderHash; + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized boolean lock() { + logger.info("LOCK: " + this); + + this.locked = true; + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized boolean unlock() { + logger.info("UNLOCK: " + this); + + this.locked = false; + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLocked() { + return this.locked; + } + + @Override + public List getSessionNames() { + List sessionNames = new ArrayList(); + try { + for (PolicySession session: this.policyContainer.getPolicySessions()) { + sessionNames.add(session.getFullName()); + } + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + "Can't retrieve POLICY-CORE sessions: " + e.getMessage(), + this.toString()); + sessionNames.add(e.getMessage()); + } + return sessionNames; + } + + /** + * {@inheritDoc} + */ + @Override + public Class fetchModelClass(String className) throws IllegalStateException { + Class modelClass = + ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className); + return modelClass; + } + + /** + * @return the recentSourceEvents + */ + @Override + public Object[] getRecentSourceEvents() { + synchronized(this.recentSourceEvents) { + Object[] events = new Object[recentSourceEvents.size()]; + return recentSourceEvents.toArray(events); + } + } + + /** + * @return the recentSinkEvents + */ + @Override + public String[] getRecentSinkEvents() { + synchronized(this.recentSinkEvents) { + String[] events = new String[recentSinkEvents.size()]; + return recentSinkEvents.toArray(events); + } + } + + + /** + * {@inheritDoc} + */ + @Override + public boolean isBrained() { + return true; + } + + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MavenDroolsController [policyContainer=") + .append((policyContainer != null) ? policyContainer.getName() : "NULL").append(":") + .append(", alive=") + .append(alive).append(", locked=").append(locked).append(", decoderConfigurations=") + .append(decoderConfigurations).append(", encoderConfigurations=").append(encoderConfigurations) + .append(", modelClassLoaderHash=").append(modelClassLoaderHash).append("]"); + return builder.toString(); + } + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java new file mode 100644 index 00000000..f0c0f474 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java @@ -0,0 +1,219 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.controller.internal; + +import java.util.ArrayList; +import java.util.List; + +import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.drools.event.comm.TopicSink; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration; + +/** + * no-op Drools Controller + */ +public class NullDroolsController implements DroolsController { + + /** + * empty cached events + */ + protected static final String[] emptyRecentEvents = new String[0]; + + /** + * empty session names + */ + protected static final List emptySessionNames = new ArrayList(); + + /** + * {@inheritDoc} + */ + @Override + public boolean start() throws IllegalStateException { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean stop() throws IllegalStateException { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() throws IllegalStateException { + return; + } + + /** + * {@inheritDoc} + */ + @Override + public void halt() throws IllegalStateException { + return; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAlive() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean lock() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean unlock() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLocked() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public String getGroupId() { + return NO_GROUP_ID; + } + + /** + * {@inheritDoc} + */ + @Override + public String getArtifactId() { + return NO_ARTIFACT_ID; + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return NO_VERSION; + } + + /** + * {@inheritDoc} + */ + @Override + public List getSessionNames() { + return new ArrayList(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean offer(String topic, String event) { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean deliver(TopicSink sink, Object event) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked"); + } + + /** + * {@inheritDoc} + */ + @Override + public Object[] getRecentSourceEvents() { + return NullDroolsController.emptyRecentEvents; + } + + /** + * {@inheritDoc} + */ + @Override + public String[] getRecentSinkEvents() { + return NullDroolsController.emptyRecentEvents; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean ownsCoder(Class coderClass, int modelHash) throws IllegalStateException { + throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked"); + } + + /** + * {@inheritDoc} + */ + @Override + public Class fetchModelClass(String className) throws IllegalArgumentException { + throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked"); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isBrained() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("NullDroolsController []"); + return builder.toString(); + } + + /** + * {@inheritDoc} + */ + @Override + public void updateToVersion(String newGroupId, String newArtifactId, String newVersion, + List decoderConfigurations, + List encoderConfigurations) + throws IllegalArgumentException, LinkageError, Exception { + throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked"); + } + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/persistence/SystemPersistence.java b/policy-management/src/main/java/org/openecomp/policy/drools/persistence/SystemPersistence.java new file mode 100644 index 00000000..6bb1185d --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/persistence/SystemPersistence.java @@ -0,0 +1,255 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.persistence; + +import java.io.File; +import java.io.FileWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Properties; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.drools.utils.PropertyUtil; + +public interface SystemPersistence { + + /** + * configuration directory + */ + public static String CONFIG_DIR_NAME = "config"; + + /** + * policy controllers suffix + */ + public final static String CONTROLLER_SUFFIX_IDENTIFIER = "-controller"; + + /** + * policy controller properties file suffix + */ + public final static String PROPERTIES_FILE_CONTROLLER_SUFFIX = + CONTROLLER_SUFFIX_IDENTIFIER + ".properties"; + + /** + * policy engine properties file name + */ + public final static String PROPERTIES_FILE_ENGINE = "policy-engine.properties"; + + + /** + * backs up a controller configuration. + * + * @param controllerName the controller name + * @return true if the configuration is backed up + */ + public boolean backupController(String controllerName); + + /** + * persists controller configuration + * + * @param controllerName the controller name + * @param configuration object containing the configuration + * @return true if storage is succesful, false otherwise + * @throws IllegalArgumentException if the configuration cannot be handled by the persistence manager + */ + public boolean storeController(String controllerName, Object configuration) + throws IllegalArgumentException; + + /** + * delete controller configuration + * + * @param controllerName the controller name + * @return true if storage is succesful, false otherwise + */ + public boolean deleteController(String controllerName); + + /** + * get controller properties + * + * @param controllerName controller name + * @return properties for this controller + * @throws IllegalArgumentException if the controller name does not lead to a properties configuration + */ + public Properties getControllerProperties(String controllerName) + throws IllegalArgumentException; + + /** + * get properties by name + * + * @param name + * @return properties + * @throws IllegalArgumentException if the name does not lead to a properties configuration + */ + public Properties getProperties(String name) throws IllegalArgumentException; + + /** + * Persistence Manager. For now it is a file-based properties management, + * In the future, it will probably be DB based, so manager implementation + * will change. + */ + public static final SystemPersistence manager = new SystemPropertiesPersistence(); +} + +/** + * Properties based Persistence + */ +class SystemPropertiesPersistence implements SystemPersistence { + + /** + * logger + */ + private static Logger logger = FlexLogger.getLogger(SystemPropertiesPersistence.class); + + /** + * backs up the properties-based controller configuration + * @param controllerName the controller name + * @return true if the configuration is backed up in disk or back up does not apply, false otherwise. + */ + @Override + public boolean backupController(String controllerName) { + Path controllerPropertiesPath = + Paths.get(CONFIG_DIR_NAME, controllerName + PROPERTIES_FILE_CONTROLLER_SUFFIX); + + if (Files.exists(controllerPropertiesPath)) { + try { + logger.warn("There is an existing configuration file at " + + controllerPropertiesPath.toString() + + " with contents: " + Files.readAllBytes(controllerPropertiesPath)); + Path controllerPropertiesBakPath = + Paths.get(CONFIG_DIR_NAME, controllerName + + PROPERTIES_FILE_CONTROLLER_SUFFIX + ".bak"); + Files.copy(controllerPropertiesPath, + controllerPropertiesBakPath, StandardCopyOption.REPLACE_EXISTING); + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, "SystemPersistenceProperties"); + return false; + } + } + + return true; + } + + /** + * persists properties-based controller configuration and makes a backup if necessary + * @param controllerName the controller name + * @return true if the properties has been stored in disk, false otherwise + */ + @Override + public boolean storeController(String controllerName, Object configuration) { + if (!(configuration instanceof Properties)) { + throw new IllegalArgumentException("configuration must be of type properties to be handled by this manager"); + } + + Properties properties = (Properties) configuration; + + Path controllerPropertiesPath = + Paths.get(CONFIG_DIR_NAME, controllerName + PROPERTIES_FILE_CONTROLLER_SUFFIX); + if (Files.exists(controllerPropertiesPath)) { + try { + Properties oldProperties = PropertyUtil.getProperties(controllerPropertiesPath.toFile()); + if (oldProperties.equals(properties)) { + logger.info("A properties file with the same contents already exists for controller " + + controllerName + + ". No action is taken"); + return true; + } else { + this.backupController(controllerName); + } + } catch (Exception e) { + logger.info("No existing Properties"); + // continue + } + } + + try { + File controllerPropertiesFile = controllerPropertiesPath.toFile(); + FileWriter writer = new FileWriter(controllerPropertiesFile); + properties.store(writer, "Machine created Policy Controller Configuration"); + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, "SystemPersistenceProperties"); + return false; + } + + return true; + } + + /** + * deletes properties-based controller configuration + * @param controllerName the controller name + * @return true if the properties has been deleted from disk, false otherwise + */ + @Override + public boolean deleteController(String controllerName) { + + Path controllerPropertiesPath = + Paths.get(CONFIG_DIR_NAME, + controllerName + PROPERTIES_FILE_CONTROLLER_SUFFIX); + + if (Files.exists(controllerPropertiesPath)) { + try { + Path controllerPropertiesBakPath = + Paths.get(CONFIG_DIR_NAME, controllerName + + PROPERTIES_FILE_CONTROLLER_SUFFIX + ".bak"); + Files.move(controllerPropertiesPath, + controllerPropertiesBakPath, + StandardCopyOption.REPLACE_EXISTING); + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, "SystemPersistenceProperties"); + return false; + } + } + + return true; + } + + @Override + public Properties getControllerProperties(String controllerName) throws IllegalArgumentException { + return this.getProperties(controllerName + CONTROLLER_SUFFIX_IDENTIFIER); + } + + @Override + public Properties getProperties(String name) throws IllegalArgumentException { + Path propertiesPath = + Paths.get(CONFIG_DIR_NAME, name + ".properties"); + + if (!Files.exists(propertiesPath)) { + throw new IllegalArgumentException("properties for " + name + " are not persisted."); + } + + try { + return PropertyUtil.getProperties(propertiesPath.toFile()); + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + name, "SystemPersistenceProperties can't retrieved properties for " + + propertiesPath); + e.printStackTrace(); + throw new IllegalArgumentException("can't read properties for " + + name + " @ " + + propertiesPath); + } + } +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java new file mode 100644 index 00000000..8f8a4ba7 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/EventProtocolCoder.java @@ -0,0 +1,1451 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.protocol.coders; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder; +import org.openecomp.policy.drools.utils.Pair; + +/** + * Coder (Encoder/Decoder) of Events. + */ +public interface EventProtocolCoder { + + public static class CoderFilters { + + /** + * coder class + */ + protected String factClass; + + /** + * filters to apply to the selection of the decodedClass; + */ + protected JsonProtocolFilter filter; + + /** + * classloader hash + */ + protected int modelClassLoaderHash; + + + /** + * constructor + * + * @param codedClass coder class + * @param filter filters to apply + */ + public CoderFilters(String codedClass, JsonProtocolFilter filter, int modelClassLoaderHash) { + this.factClass = codedClass; + this.filter = filter; + this.modelClassLoaderHash = modelClassLoaderHash; + } + + /** + * @return the codedClass + */ + public String getCodedClass() { + return factClass; + } + + /** + * @param codedClass the decodedClass to set + */ + public void setCodedClass(String codedClass) { + this.factClass = codedClass; + } + + /** + * @return the filter + */ + public synchronized JsonProtocolFilter getFilter() { + return filter; + } + + /** + * @param filter the filter to set + */ + public synchronized void setFilter(JsonProtocolFilter filter) { + this.filter = filter; + } + + public int getModelClassLoaderHash() { + return modelClassLoaderHash; + } + + public void setFromClassLoaderHash(int fromClassLoaderHash) { + this.modelClassLoaderHash = fromClassLoaderHash; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CoderFilters [factClass=").append(factClass).append(", filter=").append(filter) + .append(", modelClassLoaderHash=").append(modelClassLoaderHash).append("]"); + return builder.toString(); + } + + } + + /** + * Adds a Decoder class to decode the protocol over this topic + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic the topic + * @param eventClass the event class + * @param protocolFilter filters to selectively choose a particular decoder + * when there are multiples + * + * @throw IllegalArgumentException if an invalid parameter is passed + */ + public void addDecoder(String groupId, String artifactId, + String topic, + String eventClass, + JsonProtocolFilter protocolFilter, + CustomGsonCoder customGsonCoder, + CustomJacksonCoder customJacksonCoder, + int modelClassLoaderHash) + throws IllegalArgumentException; + + /** + * removes all decoders associated with the controller id + * @param groupId of the controller + * @param artifactId of the controller + * @param topic of the controller + * + * @throws IllegalArgumentException if invalid arguments have been provided + */ + void removeEncoders(String groupId, String artifactId, String topic) throws IllegalArgumentException; + + /** + * removes decoders associated with the controller id and topic + * @param groupId of the controller + * @param artifactId of the controller + * @param topic the topic + * + * @throws IllegalArgumentException if invalid arguments have been provided + */ + public void removeDecoders(String groupId, String artifactId, String topic) throws IllegalArgumentException; + + /** + * Given a controller id and a topic, it gives back its filters + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic the topic + * + * return list of decoders + * + * @throw IllegalArgumentException if an invalid parameter is passed + */ + public List getDecoderFilters(String groupId, String artifactId, String topic) + throws IllegalArgumentException; + + + /** + * Given a controller id and a topic, it gives back the decoding configuration + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic the topic + * + * return decoding toolset + * + * @throw IllegalArgumentException if an invalid parameter is passed + */ + public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) + throws IllegalArgumentException; + + /** + * Given a controller id and a topic, it gives back all the decoding configurations + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic the topic + * + * return decoding toolset + * + * @throw IllegalArgumentException if an invalid parameter is passed + */ + public List getDecoders(String groupId, String artifactId) + throws IllegalArgumentException; + + + /** + * gets all decoders associated with the group and artifact ids + * @param groupId of the controller + * @param artifactId of the controller + * + * @throws IllegalArgumentException if invalid arguments have been provided + */ + public List getDecoderFilters(String groupId, String artifactId) throws IllegalArgumentException; + + + /** + * Given a controller id and a topic, it gives back the classes that implements the encoding + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic the topic + * + * return list of decoders + * + * @throw IllegalArgumentException if an invalid parameter is passed + */ + public List getEncoderFilters(String groupId, String artifactId, String topic) + throws IllegalArgumentException; + + /** + * gets all encoders associated with the group and artifact ids + * @param groupId of the controller + * @param artifactId of the controller + * + * @throws IllegalArgumentException if invalid arguments have been provided + */ + public List getEncoderFilters(String groupId, String artifactId) throws IllegalArgumentException; + + /** + * Given a controller id, a topic, and a classname, it gives back the classes that implements the decoding + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic the topic + * @param classname classname + * + * return list of decoders + * + * @throw IllegalArgumentException if an invalid parameter is passed + */ + public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname) + throws IllegalArgumentException; + + /** + * is there a decoder supported for the controller id and topic + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic protocol + * @return true if supported + */ + public boolean isDecodingSupported(String groupId, String artifactId, String topic); + + /** + * Adds a Encoder class to encode the protocol over this topic + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic the topic + * @param eventClass the event class + * @param protocolFilter filters to selectively choose a particular decoder + * when there are multiples + * + * @throw IllegalArgumentException if an invalid parameter is passed + */ + public void addEncoder(String groupId, String artifactId, String topic, + String eventClass, + JsonProtocolFilter protocolFilter, + CustomGsonCoder customGsonCoder, + CustomJacksonCoder customJacksonCoder, + int modelClassLoaderHash) + throws IllegalArgumentException; + + /** + * is there an encoder supported for the controller id and topic + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic protocol + * @return true if supported + */ + public boolean isEncodingSupported(String groupId, String artifactId, String topic); + + /** + * get encoder based on coordinates and classname + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic protocol + * @param json event string + * @return + * @throws IllegalArgumentException invalid arguments passed in + */ + public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname) + throws IllegalArgumentException; + + /** + * get encoder based on topic and encoded class + * + * @param topic topic + * @param encodedClass encoded class + * @return + * @throws IllegalArgumentException invalid arguments passed in + */ + public List getReverseEncoderFilters(String topic, String encodedClass) + throws IllegalArgumentException; + + /** + * gets the identifier of the creator of the encoder + * + * @param topic topic + * @param encodedClass encoded class + * @return a drools controller + * @throws IllegalArgumentException invalid arguments passed in + */ + public DroolsController getDroolsController(String topic, Object encodedClass) + throws IllegalArgumentException; + + /** + * gets the identifier of the creator of the encoder + * + * @param topic topic + * @param encodedClass encoded class + * @return list of drools controllers + * @throws IllegalArgumentException invalid arguments passed in + */ + public List getDroolsControllers(String topic, Object encodedClass) + throws IllegalArgumentException; + + /** + * decode topic's stringified event (json) to corresponding Event Object. + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic protocol + * @param json event string + * @return + * @throws IllegalArgumentException invalid arguments passed in + * @throws UnsupportedOperationException if the operation is not supported + * @throws IllegalStateException if the system is in an illegal state + */ + public Object decode(String groupId, String artifactId, String topic, String json) + throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException; + + /** + * encodes topic's stringified event (json) to corresponding Event Object. + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic protocol + * @param event Object + * + * @throws IllegalArgumentException invalid arguments passed in + */ + public String encode(String groupId, String artifactId, String topic, Object event) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException; + + /** + * encodes topic's stringified event (json) to corresponding Event Object. + * + * @param topic topic + * @param event event object + * + * @throws IllegalArgumentException invalid arguments passed in + * @throws UnsupportedOperationException operation cannot be performed + */ + public String encode(String topic, Object event) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException; + + /** + * encodes topic's stringified event (json) to corresponding Event Object. + * + * @param topic topic + * @param event event object + * @param droolsController + * + * @throws IllegalArgumentException invalid arguments passed in + * @throws UnsupportedOperationException operation cannot be performed + */ + public String encode(String topic, Object event, DroolsController droolsController) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException; + + /** + * singleton reference to the global event protocol coder + */ + public static EventProtocolCoder manager = new MultiplexorEventProtocolCoder(); +} + +/** + * Protocol Coder that does its best attempt to decode/encode, selecting the best + * class and best fitted json parsing tools. + */ +class MultiplexorEventProtocolCoder implements EventProtocolCoder { + // get an instance of logger + private static Logger logger = FlexLogger.getLogger(MultiplexorEventProtocolCoder.class); + /** + * Decoders + */ + protected EventProtocolDecoder decoders = new EventProtocolDecoder(); + + /** + * Encoders + */ + protected EventProtocolEncoder encoders = new EventProtocolEncoder(); + + + /** + * {@inheritDoc} + */ + @Override + public void addDecoder(String groupId, String artifactId, String topic, + String eventClass, + JsonProtocolFilter protocolFilter, + CustomGsonCoder customGsonCoder, + CustomJacksonCoder customJacksonCoder, + int modelClassLoaderHash) + throws IllegalArgumentException { + logger.info("ADD-DECODER: " + groupId + ":" + artifactId + ":" + + topic + ":" + eventClass + ":" + + protocolFilter + ":" + customGsonCoder + + ":" + customJacksonCoder + ":" + modelClassLoaderHash + + " INTO " + this); + this.decoders.add(groupId, artifactId, topic, eventClass, protocolFilter, + customGsonCoder, customJacksonCoder, modelClassLoaderHash); + } + + /** + * {@inheritDoc} + */ + @Override + public void addEncoder(String groupId, String artifactId, String topic, + String eventClass, + JsonProtocolFilter protocolFilter, + CustomGsonCoder customGsonCoder, + CustomJacksonCoder customJacksonCoder, + int modelClassLoaderHash) + throws IllegalArgumentException { + logger.info("ADD-ENCODER: " + groupId + ":" + artifactId + ":" + + topic + ":" + eventClass + ":" + + protocolFilter + ":" + customGsonCoder + + ":" + customJacksonCoder + ":" + modelClassLoaderHash + + " INTO " + this); + this.encoders.add(groupId, artifactId, topic, eventClass, protocolFilter, + customGsonCoder, customJacksonCoder, modelClassLoaderHash); + } + + /** + * {@inheritDoc} + */ + @Override + public void removeDecoders(String groupId, String artifactId, String topic) + throws IllegalArgumentException { + logger.info("REMOVE-DECODER: " + groupId + ":" + artifactId + ":" + + topic + " FROM " + this); + this.decoders.remove(groupId, artifactId, topic); + } + + /** + * {@inheritDoc} + */ + @Override + public void removeEncoders(String groupId, String artifactId, String topic) + throws IllegalArgumentException { + logger.info("REMOVE-ENCODER: " + groupId + ":" + artifactId + ":" + + topic + " FROM " + this); + this.encoders.remove(groupId, artifactId, topic); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isDecodingSupported(String groupId, String artifactId, String topic) { + return this.decoders.isCodingSupported(groupId, artifactId, topic); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isEncodingSupported(String groupId, String artifactId, String topic) { + return this.encoders.isCodingSupported(groupId, artifactId, topic); + } + + /** + * {@inheritDoc} + */ + @Override + public Object decode(String groupId, String artifactId, String topic, String json) + throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { + logger.info("DECODE: " + groupId + ":" + artifactId + ":" + + topic + ":" + json + " WITH " + this); + return this.decoders.decode(groupId, artifactId, topic, json); + } + + /** + * {@inheritDoc} + */ + @Override + public String encode(String groupId, String artifactId, String topic, Object event) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + logger.info("ENCODE: " + groupId + ":" + artifactId + ":" + + topic + ":" + event + " WITH " + this); + return this.encoders.encode(groupId, artifactId, topic, event); + } + + /** + * {@inheritDoc} + */ + @Override + public String encode(String topic, Object event) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + logger.info("ENCODE: " + topic + ":" + event + " WITH " + this); + return this.encoders.encode(topic, event); + } + + /** + * {@inheritDoc} + */ + @Override + public String encode(String topic, Object event, DroolsController droolsController) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + logger.info("ENCODE: " + topic + ":" + event + ":" + droolsController + " WITH " + this); + return this.encoders.encode(topic, event, droolsController); + } + + /** + * {@inheritDoc} + */ + @Override + public List getDecoderFilters(String groupId, String artifactId, String topic) + throws IllegalArgumentException { + + return this.decoders.getFilters(groupId, artifactId, topic); + } + + /** + * {@inheritDoc} + */ + @Override + public ProtocolCoderToolset getDecoders(String groupId, String artifactId, String topic) + throws IllegalArgumentException { + + Pair decoderToolsets = this.decoders.getCoders(groupId, artifactId, topic); + if (decoderToolsets == null) + throw new IllegalArgumentException("Decoders not found for " + groupId + ":" + artifactId + ":" + topic); + + return decoderToolsets.first(); + } + + /** + * {@inheritDoc} + */ + @Override + public List getEncoderFilters(String groupId, String artifactId, String topic) + throws IllegalArgumentException { + + return this.encoders.getFilters(groupId, artifactId, topic); + } + + /** + * {@inheritDoc} + */ + @Override + public CoderFilters getDecoderFilters(String groupId, String artifactId, String topic, String classname) + throws IllegalArgumentException { + + return this.decoders.getFilters(groupId, artifactId, topic, classname); + } + + /** + * {@inheritDoc} + */ + @Override + public CoderFilters getEncoderFilters(String groupId, String artifactId, String topic, String classname) + throws IllegalArgumentException { + + return this.encoders.getFilters(groupId, artifactId, topic, classname); + } + + /** + * {@inheritDoc} + */ + @Override + public List getReverseEncoderFilters(String topic, String encodedClass) throws IllegalArgumentException { + return this.encoders.getReverseFilters(topic, encodedClass); + } + + /** + * get all deocders by maven coordinates and topic + * + * @param groupId group id + * @param artifactId artifact id + * + * @return list of decoders + * @throws IllegalArgumentException if invalid input + */ + @Override + public List getDecoders(String groupId, String artifactId) + throws IllegalArgumentException { + + List> decoderToolsets = this.decoders.getCoders(groupId, artifactId); + if (decoderToolsets == null) + throw new IllegalArgumentException("Decoders not found for " + groupId + ":" + artifactId); + + List parser1CoderToolset = new ArrayList<>(); + for (Pair coderToolsetPair : decoderToolsets) { + parser1CoderToolset.add(coderToolsetPair.first()); + } + + return parser1CoderToolset; + } + + /** + * {@inheritDoc} + */ + @Override + public List getDecoderFilters(String groupId, String artifactId) throws IllegalArgumentException { + return this.decoders.getFilters(groupId, artifactId); + + } + + /** + * {@inheritDoc} + */ + @Override + public List getEncoderFilters(String groupId, String artifactId) throws IllegalArgumentException { + return this.encoders.getFilters(groupId, artifactId); + } + + /** + * {@inheritDoc} + */ + @Override + public DroolsController getDroolsController(String topic, Object encodedClass) throws IllegalArgumentException { + return this.encoders.getDroolsController(topic, encodedClass); + } + + /** + * {@inheritDoc} + */ + @Override + public List getDroolsControllers(String topic, Object encodedClass) throws IllegalArgumentException { + return this.encoders.getDroolsControllers(topic, encodedClass); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MultiplexorEventProtocolCoder [decoders=").append(decoders).append(", encoders=") + .append(encoders).append("]"); + return builder.toString(); + } +} + +/** + * This protocol Coder that does its best attempt to decode/encode, selecting the best + * class and best fitted json parsing tools. + */ +abstract class GenericEventProtocolCoder { + private static Logger logger = FlexLogger.getLogger(GenericEventProtocolCoder.class); + + /** + * Mapping topic:controller-id -> + * where protocol-coder-toolset-pair contains both a jackson-protocol-coder-toolset + * and a gson-protocol-coder-toolset. The first value of the pair will the + * protocol coder toolset most likely to be successful with the encoding or decoding, + * and consequently the second value will be the less likely. + */ + protected final HashMap> coders = + new HashMap>(); + + /** + * Mapping topic + classname -> Protocol Set + */ + protected final HashMap>> reverseCoders = + new HashMap>>(); + + protected boolean multipleToolsetRetries = false; + + GenericEventProtocolCoder(boolean multipleToolsetRetries) { + this.multipleToolsetRetries = multipleToolsetRetries; + } + + /** + * Index a new coder + * + * @param groupId of the controller + * @param artifactId of the controller + * @param topic the topic + * @param eventClass the event class + * @param protocolFilter filters to selectively choose a particular decoder + * when there are multiples + * + * @throw IllegalArgumentException if an invalid parameter is passed + */ + public void add(String groupId, String artifactId, + String topic, + String eventClass, + JsonProtocolFilter protocolFilter, + CustomGsonCoder customGsonCoder, + CustomJacksonCoder customJacksonCoder, + int modelClassLoaderHash) + throws IllegalArgumentException { + if (groupId == null || groupId.isEmpty()) { + throw new IllegalArgumentException("Invalid group id"); + } + + if (artifactId == null || artifactId.isEmpty()) { + throw new IllegalArgumentException("Invalid artifact id"); + } + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("Invalid Topic"); + } + + if (eventClass == null) { + throw new IllegalArgumentException("Invalid Event Class"); + } + + String key = this.codersKey(groupId, artifactId, topic); + String reverseKey = this.reverseCodersKey(topic, eventClass); + + synchronized(this) { + if (coders.containsKey(key)) { + Pair toolsets = coders.get(key); + + if (logger.isInfoEnabled()) + logger.info("ADDING CODER TO EXISTING: " + toolsets + " for " + key); + + toolsets.first().addCoder(eventClass, protocolFilter, modelClassLoaderHash); + toolsets.second().addCoder(eventClass, protocolFilter, modelClassLoaderHash); + + if (!reverseCoders.containsKey(reverseKey)) { + if (logger.isInfoEnabled()) + logger.info("Multiple coder classes case: " + toolsets.first() + + " for " + reverseKey + " - " + key); + + List> reverseMappings = + new ArrayList>(); + reverseMappings.add(toolsets); + reverseCoders.put(reverseKey, reverseMappings); + } + return; + } + + GsonProtocolCoderToolset gsonCoderTools = + new GsonProtocolCoderToolset + (topic, key, + groupId, artifactId, + eventClass, protocolFilter, + customGsonCoder, + modelClassLoaderHash); + + JacksonProtocolCoderToolset jacksonCoderTools = + new JacksonProtocolCoderToolset + (topic, key, + groupId, artifactId, + eventClass, protocolFilter, + customJacksonCoder, + modelClassLoaderHash); + + // Use Gson as the first priority encoding/decoding toolset, and Jackson + // as second. This is because it has been observed that they can diverge + // somewhat in the encoding/decoding data types, which can produce json + // that may result incompatible with what some network elements are + // expecting. As decoding takes place, this element will reconfigure + // itself to set the jackson one as the favoured one first, if errors + // are detected in the gson encoding + + Pair coderTools = + new Pair(gsonCoderTools, + jacksonCoderTools); + + logger.info("ADDED TOOLSET: " + key + " : " + + coderTools + ":" + this); + + coders.put(key, coderTools); + + if (reverseCoders.containsKey(reverseKey)) { + // There is another controller (different group id/artifact id/topic) + // that shares the class and the topic. + + List> toolsets = + reverseCoders.get(reverseKey); + boolean present = false; + for (Pair parserSet: toolsets) { + // just doublecheck + present = parserSet.first().getControllerId().equals(key); + if (present) { + /* anomaly */ + logger.error("UNEXPECTED TOOLSET REVERSE MAPPING FOUND: " + parserSet.first() + + " for " + reverseKey + " - " + key); + } + } + + if (present) { + return; + } else { + logger.info("ADDING TOOLSET REVERSE MAPPING: " + reverseKey + " : " + + toolsets + ":" + coderTools + ":" + this); + toolsets.add(coderTools); + } + } else { + List> toolsets = + new ArrayList>(); + logger.info("ADDING TOOLSET REVERSE MAPPING: " + reverseKey + " : " + + toolsets + ":" + coderTools + ":" + this); + toolsets.add(coderTools); + reverseCoders.put(reverseKey, toolsets); + } + + } + } + + /** + * produces key for indexing toolset entries + * + * @param group group id + * @param artifactId artifact id + * @param topic topic + * @return index key + */ + protected String codersKey(String groupId, String artifactId, String topic) { + return groupId + ":" + artifactId + ":" + topic; + } + + /** + * produces a key for the reverse index + * + * @param topic topic + * @param eventClass coded class + * @return reverse index key + */ + protected String reverseCodersKey(String topic, String eventClass) { + return topic + ":" + eventClass; + } + + /** + * remove coder + * + * @param groupId group id + * @param artifactId artifact id + * @param topic topic + * @throws IllegalArgumentException if invalid input + */ + public void remove(String groupId, String artifactId, String topic) + throws IllegalArgumentException { + + if (groupId == null || groupId.isEmpty()) { + throw new IllegalArgumentException("Invalid group id"); + } + + if (artifactId == null || artifactId.isEmpty()) { + throw new IllegalArgumentException("Invalid artifact id"); + } + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("Invalid Topic"); + } + + String key = this.codersKey(groupId, artifactId, topic); + + synchronized(this) { + if (coders.containsKey(key)) { + Pair p = coders.remove(key); + logger.info("REMOVED TOOLSET: " + key + " : " + p + " FROM " + + coders + " : " + this); + + for (CoderFilters codeFilter : p.first().getCoders()) { + String className = codeFilter.getCodedClass(); + String reverseKey = this.reverseCodersKey(topic, className); + if (this.reverseCoders.containsKey(reverseKey) ) { + List> toolsets = + this.reverseCoders.get(reverseKey); + Iterator> toolsetsIter = + toolsets.iterator(); + while (toolsetsIter.hasNext()) { + Pair toolset = toolsetsIter.next(); + if (toolset.first().getControllerId().equals(key)) { + logger.info("REMOVED CODER FROM REVERSE MAPPING of TOOLSET: " + reverseKey + " : " + toolset + " FROM " + + reverseCoders); + toolsetsIter.remove(); + } + } + + if (this.reverseCoders.get(reverseKey).isEmpty()) { + logger.info("REMOVE FULL REVERSE MAPPING of TOOLSET: " + reverseKey + " FROM " + + reverseCoders); + this.reverseCoders.remove(reverseKey); + } + } + } + } + } + } + + /** + * does it support coding? + * + * @param groupId group id + * @param artifactId artifact id + * @param topic topic + * @return true if its is codable + */ + public boolean isCodingSupported(String groupId, String artifactId, String topic) { + + if (groupId == null || groupId.isEmpty()) { + throw new IllegalArgumentException("Invalid group id"); + } + + if (artifactId == null || artifactId.isEmpty()) { + throw new IllegalArgumentException("Invalid artifact id"); + } + + if (topic == null || topic.isEmpty()) + return false; + + String key = this.codersKey(groupId, artifactId, topic); + synchronized(this) { + return (coders.containsKey(key)); + } + } + + /** + * decode a json string into an Object + * + * @param groupId group id + * @param artifactId artifact id + * @param topic topic + * @param json json string to convert to object + * @return the decoded object + * @throws IllegalArgumentException if invalid argument is provided + * @throws UnsupportedOperationException if the operation cannot be performed + */ + public Object decode(String groupId, String artifactId, String topic, String json) + throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { + + if (!isCodingSupported(groupId, artifactId, topic)) { + throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic) + " for encoding"); + } + + String key = this.codersKey(groupId, artifactId, topic); + Pair coderTools = coders.get(key); + try { + Object event = coderTools.first().decode(json); + if (event != null) + return event; + } catch (Exception e) { + // TODO Auto-generated catch block + logger.warn("Can't decode @ " + this); + } + + if (multipleToolsetRetries) { + // try the less favored toolset + try { + Object event = coderTools.second().decode(json); + if (event != null) { + // change the priority of the toolset + synchronized(this) { + ProtocolCoderToolset first = coderTools.first(); + ProtocolCoderToolset second = coderTools.second(); + coderTools.first(second); + coderTools.second(first); + } + + return event; + } + } catch (Exception e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + throw new UnsupportedOperationException(e2); + } + } + + throw new UnsupportedOperationException("Cannot decode neither with gson or jackson"); + } + + /** + * encode an object into a json string + * + * @param groupId group id + * @param artifactId artifact id + * @param topic topic + * @param event object to convert to string + * @return the json string + * @throws IllegalArgumentException if invalid argument is provided + * @throws UnsupportedOperationException if the operation cannot be performed + */ + public String encode(String groupId, String artifactId, String topic, Object event) + throws IllegalArgumentException, UnsupportedOperationException { + + if (!isCodingSupported(groupId, artifactId, topic)) { + throw new IllegalArgumentException + ("Unsupported:" + codersKey(groupId, artifactId, topic)); + } + + if (event == null) { + throw new IllegalArgumentException("Unsupported topic:" + topic); + } + + // reuse the decoder set, since there must be affinity in the model + String key = this.codersKey(groupId, artifactId, topic); + return this.encodeInternal(key, event); + } + + /** + * encode an object into a json string + * + * @param key identifier + * @param event object to convert to string + * @return the json string + * @throws IllegalArgumentException if invalid argument is provided + * @throws UnsupportedOperationException if the operation cannot be performed + */ + protected String encodeInternal(String key, Object event) + throws IllegalArgumentException, UnsupportedOperationException { + + logger.debug("ENCODE: " + key + ":" + event + this); + + Pair coderTools = coders.get(key); + try { + String json = coderTools.first().encode(event); + if (json != null && !json.isEmpty()) + return json; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "FIRST-ENCODE-INTERNAL: " + + key + ":" + event, this.toString()); + } + + if (multipleToolsetRetries) { + // try the less favored toolset + try { + String json = coderTools.second().encode(event); + if (json != null) { + // change the priority of the toolset + synchronized(this) { + ProtocolCoderToolset first = coderTools.first(); + ProtocolCoderToolset second = coderTools.second(); + coderTools.first(second); + coderTools.second(first); + } + + return json; + } + } catch (Exception e2) { + // TODO Auto-generated catch block + logger.error(MessageCodes.EXCEPTION_ERROR, e2, "SECOND-ENCODE-INTERNAL: " + + key + ":" + event, this.toString()); + throw new UnsupportedOperationException(e2); + } + } + + throw new UnsupportedOperationException("Cannot decode neither with gson or jackson"); + } + + /** + * encode an object into a json string + * + * @param topic topic + * @param encodedClass object to convert to string + * @return the json string + * @throws IllegalArgumentException if invalid argument is provided + * @throws UnsupportedOperationException if the operation cannot be performed + */ + public String encode(String topic, Object encodedClass) + throws IllegalArgumentException, IllegalArgumentException, UnsupportedOperationException { + + if (encodedClass == null) { + throw new IllegalArgumentException("Invalid encoded class"); + } + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("Invalid topic"); + } + + logger.info("ENCODE: " + topic + ":" + + encodedClass.getClass().getCanonicalName() + ":" + + encodedClass); + + List droolsControllers = droolsCreators(topic, encodedClass); + if (droolsControllers.size() > 1) { + // unexpected + logger.warn("MULTIPLE DROOLS CONTROLLERS FOUND for: " + topic + ":" + + encodedClass.getClass().getCanonicalName() + ":" + + droolsControllers + " IN " + this); + // continue + } + + String key = codersKey(droolsControllers.get(0).getGroupId(), droolsControllers.get(0).getArtifactId(), topic); + return this.encodeInternal(key, encodedClass); + } + + /** + * encode an object into a json string + * + * @param topic topic + * @param encodedClass object to convert to string + * @return the json string + * @throws IllegalArgumentException if invalid argument is provided + * @throws UnsupportedOperationException if the operation cannot be performed + */ + public String encode(String topic, Object encodedClass, DroolsController droolsController) + throws IllegalArgumentException, IllegalArgumentException, UnsupportedOperationException { + + if (encodedClass == null) { + throw new IllegalArgumentException("Invalid encoded class"); + } + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("Invalid topic"); + } + + logger.info("ENCODE: " + topic + ":" + + encodedClass.getClass().getCanonicalName() + ":" + + encodedClass + ":" + droolsController); + + String key = codersKey(droolsController.getGroupId(), droolsController.getArtifactId(), topic); + return this.encodeInternal(key, encodedClass); + } + + /** + * @param topic + * @param encodedClass + * @param reverseKey + * @return + * @throws IllegalStateException + * @throws IllegalArgumentException + */ + protected List droolsCreators(String topic, Object encodedClass) + throws IllegalStateException, IllegalArgumentException { + + List droolsControllers = new ArrayList(); + + String reverseKey = this.reverseCodersKey(topic, encodedClass.getClass().getCanonicalName()); + if (!this.reverseCoders.containsKey(reverseKey)) { + logger.warn("NO MAPPING for REVERSE KEY: " + topic + ":" + + encodedClass.getClass().getCanonicalName() + ":" + + encodedClass + ":" + reverseKey + " : " + this); + return droolsControllers; + } + + List> + toolsets = this.reverseCoders.get(reverseKey); + + // There must be multiple toolset pairs associated with reverseKey + // case 2 different controllers use the same models and register the same encoder for + // the same topic. This is assumed not to occur often but for the purpose of encoding + // but there should be no side-effects. Ownership is crosscheck against classname and + // classloader reference. + + if (toolsets == null || toolsets.isEmpty()) { + logger.warn("ENCODE: " + topic + ":" + + encodedClass.getClass().getCanonicalName() + ":" + + encodedClass + " ENCODER NOT FOUND"); + throw new IllegalStateException("No Encoders toolsets available for topic "+ topic + + " encoder " + encodedClass.getClass().getCanonicalName()); + } + + for (Pair encoderSet : toolsets) { + // figure out the right toolset + String groupId = encoderSet.first().getGroupId(); + String artifactId = encoderSet.first().getArtifactId(); + List coders = encoderSet.first().getCoders(); + for (CoderFilters coder : coders) { + if (coder.getCodedClass().equals(encodedClass.getClass().getCanonicalName())) { + DroolsController droolsController = + DroolsController.factory.get(groupId, artifactId, ""); + if (droolsController.ownsCoder(encodedClass.getClass(), coder.getModelClassLoaderHash())) { + droolsControllers.add(droolsController); + } + } + } + } + + if (droolsControllers.isEmpty()) { + throw new IllegalStateException("No Encoders toolsets available for topic "+ topic + + " : encoder " + encodedClass.getClass().getCanonicalName()); + } + return droolsControllers; + } + + + /** + * get all filters by maven coordinates and topic + * + * @param groupId group id + * @param artifactId artifact id + * @param topic topic + * @return list of coders + * @throws IllegalArgumentException if invalid input + */ + public List getFilters(String groupId, String artifactId, String topic) + throws IllegalArgumentException { + + if (!isCodingSupported(groupId, artifactId, topic)) { + throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); + } + + String key = this.codersKey(groupId, artifactId, topic); + Pair coderTools = coders.get(key); + return coderTools.first().getCoders(); + } + + /** + * get all coders by maven coordinates and topic + * + * @param groupId group id + * @param artifactId artifact id + * @param topic topic + * @return list of coders + * @throws IllegalArgumentException if invalid input + */ + public Pair getCoders(String groupId, String artifactId, String topic) + throws IllegalArgumentException { + + if (!isCodingSupported(groupId, artifactId, topic)) { + throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); + } + + String key = this.codersKey(groupId, artifactId, topic); + Pair coderTools = coders.get(key); + return coderTools; + } + + /** + * get all coders by maven coordinates and topic + * + * @param groupId group id + * @param artifactId artifact id + * @return list of coders + * @throws IllegalArgumentException if invalid input + */ + public List getFilters(String groupId, String artifactId) + throws IllegalArgumentException { + + if (groupId == null || groupId.isEmpty()) { + throw new IllegalArgumentException("Invalid group id"); + } + + if (artifactId == null || artifactId.isEmpty()) { + throw new IllegalArgumentException("Invalid artifact id"); + } + + String key = this.codersKey(groupId, artifactId, ""); + + List codersFilters = new ArrayList(); + for (Map.Entry> entry : coders.entrySet()) { + if (entry.getKey().startsWith(key)) { + codersFilters.addAll(entry.getValue().first().getCoders()); + } + } + + return codersFilters; + } + + /** + * get all coders by maven coordinates and topic + * + * @param groupId group id + * @param artifactId artifact id + * @return list of coders + * @throws IllegalArgumentException if invalid input + */ + public List> getCoders(String groupId, String artifactId) + throws IllegalArgumentException { + + if (groupId == null || groupId.isEmpty()) { + throw new IllegalArgumentException("Invalid group id"); + } + + if (artifactId == null || artifactId.isEmpty()) { + throw new IllegalArgumentException("Invalid artifact id"); + } + + String key = this.codersKey(groupId, artifactId, ""); + + List> coderToolset = new ArrayList>(); + for (Map.Entry> entry : coders.entrySet()) { + if (entry.getKey().startsWith(key)) { + coderToolset.add(entry.getValue()); + } + } + + return coderToolset; + } + + + /** + * get all filters by maven coordinates, topic, and classname + * + * @param groupId group id + * @param artifactId artifact id + * @param topic topic + * @param classname + * @return list of coders + * @throws IllegalArgumentException if invalid input + */ + public CoderFilters getFilters(String groupId, String artifactId, String topic, String classname) + throws IllegalArgumentException { + + if (!isCodingSupported(groupId, artifactId, topic)) { + throw new IllegalArgumentException("Unsupported:" + codersKey(groupId, artifactId, topic)); + } + + if (classname == null || classname.isEmpty()) { + throw new IllegalArgumentException("classname must be provided"); + } + + String key = this.codersKey(groupId, artifactId, topic); + Pair coderTools = coders.get(key); + return coderTools.first().getCoder(classname); + } + + /** + * get coded based on class and topic + * + * @param topic + * @param codedClass + * @return + * @throws IllegalArgumentException + */ + public List getReverseFilters(String topic, String codedClass) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("Unsupported"); + } + + if (codedClass == null) { + throw new IllegalArgumentException("class must be provided"); + } + + String key = this.reverseCodersKey(topic, codedClass); + List> toolsets = this.reverseCoders.get(key); + if (toolsets == null) + throw new IllegalArgumentException("No Coder found for " + key); + + + List coders = new ArrayList(); + for (Pair toolset: toolsets) { + coders.addAll(toolset.first().getCoders()); + } + + return coders; + } + + /** + * returns group and artifact id of the creator of the encoder + * + * @param topic + * @param fact + * @return + * @throws IllegalArgumentException + */ + DroolsController getDroolsController(String topic, Object fact) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("Unsupported"); + } + + if (fact == null) { + throw new IllegalArgumentException("class must be provided"); + } + + List droolsControllers = droolsCreators(topic, fact); + if (droolsControllers.size() > 1) { + // unexpected + logger.warn("MULTIPLE DROOLS CONTROLLERS FOUND for: " + topic + ":" + + fact.getClass().getCanonicalName() + ":" + + droolsControllers + " IN " + this); + // continue + } + return droolsControllers.get(0); + } + + /** + * returns group and artifact id of the creator of the encoder + * + * @param topic + * @param fact + * @return + * @throws IllegalArgumentException + */ + List getDroolsControllers(String topic, Object fact) + throws IllegalArgumentException { + + if (topic == null || topic.isEmpty()) { + throw new IllegalArgumentException("Unsupported"); + } + + if (fact == null) { + throw new IllegalArgumentException("class must be provided"); + } + + List droolsControllers = droolsCreators(topic, fact); + if (droolsControllers.size() > 1) { + // unexpected + logger.warn("MULTIPLE DROOLS CONTROLLERS FOUND for: " + topic + ":" + + fact.getClass().getCanonicalName() + ":" + + droolsControllers + " IN " + this); + // continue + } + return droolsControllers; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GenericEventProtocolCoder [coders=").append(coders.keySet()).append(", reverseCoders=") + .append(reverseCoders.keySet()).append("]"); + return builder.toString(); + } +} + +class EventProtocolDecoder extends GenericEventProtocolCoder { + + public EventProtocolDecoder(){super(false);} + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("EventProtocolDecoder [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + +} + +class EventProtocolEncoder extends GenericEventProtocolCoder { + + public EventProtocolEncoder(){super(false);} + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("EventProtocolEncoder [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } +} \ No newline at end of file diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/JsonProtocolFilter.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/JsonProtocolFilter.java new file mode 100644 index 00000000..a2ce3123 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/JsonProtocolFilter.java @@ -0,0 +1,304 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.protocol.coders; + +import java.util.ArrayList; +import java.util.List; + +import org.openecomp.policy.drools.utils.Pair; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +/** + * JSON Protocol Filter. Evaluates an JSON string and evaluates if it + * passes its filters. + */ +public class JsonProtocolFilter { + + /** + * Helper class to collect Filter information + */ + public static class FilterRule { + /** + * Field name + */ + protected String name; + + /** + * Field Value regex + */ + protected String regex; + + /** + * Filter Constructor + * + * @param name field name + * @param regex field regex value + */ + public FilterRule(String name, String regex) { + this.name = name; + this.regex = regex; + } + + /** + * Default constructor (for serialization only) + */ + public FilterRule() { + super(); + } + + /** + * gets name + * + * @return + */ + public String getName() { + return name; + } + + /** + * gets regex + * + * @return + */ + public String getRegex() { + return regex; + } + + /** + * sets field name + * @param name field name + */ + public void setName(String name) { + this.name = name; + } + + /** + * sets regex name + * @param regex + */ + public void setRegex(String regex) { + this.regex = regex; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Filter [name=").append(name).append(", regex=").append(regex).append("]"); + return builder.toString(); + } + } + + /** + * all the filters to be applied + */ + protected List rules = new ArrayList(); + + /** + * + * @param rawFilters raw filter initialization + * + * @throws IllegalArgumentException an invalid input has been provided + */ + public static JsonProtocolFilter fromRawFilters(List> rawFilters) + throws IllegalArgumentException { + + if (rawFilters == null) { + throw new IllegalArgumentException("No raw filters provided"); + } + + List filters = new ArrayList(); + for (Pair filterPair: rawFilters) { + if (filterPair.first() == null || filterPair.first().isEmpty()) { + // TODO: warn + continue; + } + + filters.add(new FilterRule(filterPair.first(), filterPair.second())); + } + return new JsonProtocolFilter(filters); + } + + /** + * Create a Protocol Filter + * + * @throws IllegalArgumentException an invalid input has been provided + */ + public JsonProtocolFilter() throws IllegalArgumentException {} + + /** + * + * @param rawFilters raw filter initialization + * + * @throws IllegalArgumentException an invalid input has been provided + */ + public JsonProtocolFilter(List filters) throws IllegalArgumentException { + this.rules = filters; + } + + /** + * are there any filters? + * + * @return true if there are filters, false otherwise + */ + public boolean isRules() { + return !this.rules.isEmpty(); + } + + /** + * accept a JSON string as conformant it if passes all filters + * + * @param json json is a JSON object + * @return true if json string is conformant + * + * @throws IllegalArgumentException an invalid input has been provided + */ + public synchronized boolean accept(JsonElement json) throws IllegalArgumentException { + if (json == null) { + throw new IllegalArgumentException("no JSON provided"); + } + + if (rules.isEmpty()) { + return true; + } + + try { + if (json == null || !json.isJsonObject()) { + return false; + } + + JsonObject event = json.getAsJsonObject(); + for (FilterRule filter: rules) { + if (filter.regex == null || + filter.regex.isEmpty() || + filter.regex.equals(".*")) { + + // Only check for presence + if (!event.has(filter.name)) { + return false; + } + } else { + JsonElement field = event.get(filter.name); + if (field == null) { + return false; + } + + String fieldValue = field.getAsString(); + if (!fieldValue.matches(filter.regex)) { + return false; + } + } + } + return true; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new IllegalArgumentException(e); + } + } + + /** + * accept a JSON string as conformant it if passes all filters + * + * @param json json string + * @return true if json string is conformant + * + * @throws IllegalArgumentException an invalid input has been provided + */ + public synchronized boolean accept(String json) throws IllegalArgumentException { + if (json == null || json.isEmpty()) { + throw new IllegalArgumentException("no JSON provided"); + } + + if (rules.isEmpty()) { + return true; + } + + try { + JsonElement element = new JsonParser().parse(json); + if (element == null || !element.isJsonObject()) { + return false; + } + + return this.accept(element.getAsJsonObject()); + } catch (IllegalArgumentException ile) { + throw ile; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new IllegalArgumentException(e); + } + } + + public List getRules() { + return rules; + } + + public synchronized void setRules(List rulesFilters) { + this.rules = rulesFilters; + } + + public synchronized void deleteRules(String name) { + for (FilterRule rule : new ArrayList<>(this.rules)) { + if (rule.name.equals(name)) { + this.rules.remove(rule); + } + } + } + + public List getRules(String name) { + ArrayList temp = new ArrayList<>(); + for (FilterRule rule : new ArrayList<>(this.rules)) { + if (rule.name.equals(name)) { + temp.add(rule); + } + } + return temp; + } + + public synchronized void deleteRule(String name, String regex) { + for (FilterRule rule : new ArrayList<>(this.rules)) { + if (rule.name.equals(name) && rule.regex.equals(regex)) { + this.rules.remove(rule); + } + } + } + + public synchronized void addRule(String name, String regex) { + for (FilterRule rule : new ArrayList<>(this.rules)) { + if (rule.name.equals(name) && rule.regex.equals(regex)) { + return; + } + } + + this.rules.add(new FilterRule(name,regex)); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("JsonProtocolFilter [rules=").append(rules).append("]"); + return builder.toString(); + } + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/ProtocolCoderToolset.java new file mode 100644 index 00000000..9e079ff5 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/ProtocolCoderToolset.java @@ -0,0 +1,668 @@ +package org.openecomp.policy.drools.protocol.coders; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.time.Instant; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomCoder; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder; +import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +/** + * Protocol Coding/Decoding Toolset + */ +public abstract class ProtocolCoderToolset { + + /** + * topic + */ + protected final String topic; + + /** + * controller id + */ + protected final String controllerId; + + /** + * group id + */ + protected final String groupId; + + /** + * artifact id + */ + protected final String artifactId; + + /** + * Protocols and associated Filters + */ + protected final List coders = new ArrayList(); + + /** + * Tree model (instead of class model) generic parsing to be able to inspect elements + */ + protected JsonParser filteringParser = new JsonParser(); + + /** + * custom coder + */ + protected CustomCoder customCoder; + + /** + * Constructor + * + * @param topic the topic + * @param controllerId the controller id + * @param codedClass the decoded class + * @param filters list of filters that apply to the + * selection of this decodedClass in case of multiplicity + * @throws IllegalArgumentException if invalid data has been passed in + */ + public ProtocolCoderToolset(String topic, + String controllerId, + String groupId, + String artifactId, + String codedClass, + JsonProtocolFilter filters, + CustomCoder customCoder, + int modelClassLoaderHash) + throws IllegalArgumentException { + + if (topic == null || controllerId == null || + groupId == null || artifactId == null || + codedClass == null || filters == null || + topic.isEmpty() || controllerId.isEmpty()) { + // TODO + throw new IllegalArgumentException("Invalid input"); + } + + this.topic = topic; + this.controllerId = controllerId; + this.groupId = groupId; + this.artifactId = artifactId; + this.coders.add(new CoderFilters(codedClass, filters, modelClassLoaderHash)); + this.customCoder = customCoder; + } + + /** + * gets the coder + filters associated with this class name + * + * @param classname class name + * @return the decoder filters or null if not found + */ + public CoderFilters getCoder(String classname) { + for (CoderFilters decoder: this.coders) { + if (decoder.factClass.equals(classname)) { + return decoder; + } + } + return null; + } + + /** + * get all coder filters in use + * + * @return coder filters + */ + public List getCoders() { + return this.coders; + } + + /** + * add coder or replace it exists + * + * @param eventClass decoder + * @param filter filter + */ + public void addCoder(String eventClass, JsonProtocolFilter filter, int modelClassLoaderHash) { + synchronized(this) { + for (CoderFilters coder: this.coders) { + if (coder.factClass.equals(eventClass)) { + // this is a better check than checking pointers, just + // in case classloader is different and this is just an update + coder.factClass = eventClass; + coder.filter = filter; + coder.modelClassLoaderHash = modelClassLoaderHash; + return; + } + } + } + + this.coders.add(new CoderFilters(eventClass, filter, modelClassLoaderHash)); + } + + /** + * remove coder + * + * @param eventClass decoder + * @param filter filter + */ + public void removeCoders(String eventClass) { + synchronized(this) { + Iterator codersIt = this.coders.iterator(); + while (codersIt.hasNext()) { + CoderFilters coder = codersIt.next(); + if (coder.factClass.equals(eventClass)) { + codersIt.remove(); + } + } + } + } + + /** + * gets the topic + * + * @return the topic + */ + public String getTopic() {return topic;} + + /** + * gets the controller id + * + * @return the controller id + */ + public String getControllerId() {return controllerId;} + + /** + * @return the groupId + */ + public String getGroupId() { + return groupId; + } + + /** + * @return the artifactId + */ + public String getArtifactId() { + return artifactId; + } + + /** + * @return the customCoder + */ + public CustomCoder getCustomCoder() { + return customCoder; + } + + /** + * @param customCoder the customCoder to set + */ + public void setCustomCoder(CustomCoder customCoder) { + this.customCoder = customCoder; + } + + /** + * performs filtering on a json string + * + * @param json json string + * @return the decoder that passes the filter, otherwise null + * @throws UnsupportedOperationException can't filter + * @throws IllegalArgumentException invalid input + */ + protected CoderFilters filter(String json) + throws UnsupportedOperationException, IllegalArgumentException, IllegalStateException { + + + // 1. Get list of decoding classes for this controller Id and topic + // 2. If there are no classes, return error + // 3. Otherwise, from the available classes for decoding, pick the first one that + // passes the filters + + // Don't parse if it is not necessary + + if (this.coders.isEmpty()) { + // TODO this is an error + throw new IllegalStateException("No coders available"); + } + + if (this.coders.size() == 1) { + JsonProtocolFilter filter = this.coders.get(0).getFilter(); + if (!filter.isRules()) { + return this.coders.get(0); + } + } + + JsonElement event; + try { + event = this.filteringParser.parse(json); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new UnsupportedOperationException(e); + } + + for (CoderFilters decoder: this.coders) { + try { + boolean accepted = decoder.getFilter().accept(event); + if (accepted) { + return decoder; + } + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + } + + return null; + } + + /** + * Decode json into a POJO object + * @param json json string + * + * @return a POJO object for the json string + * @throws IllegalArgumentException if an invalid parameter has been received + * @throws UnsupportedOperationException if parsing into POJO is not possible + */ + public abstract Object decode(String json) + throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException; + + /** + * Encodes a POJO object into a JSON String + * + * @param event JSON POJO event to be converted to String + * @return JSON string version of POJO object + * @throws IllegalArgumentException if an invalid parameter has been received + * @throws UnsupportedOperationException if parsing into POJO is not possible + */ + public abstract String encode(Object event) + throws IllegalArgumentException, UnsupportedOperationException; + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ProtocolCoderToolset [topic=").append(topic).append(", controllerId=").append(controllerId) + .append(", groupId=").append(groupId).append(", artifactId=").append(artifactId).append(", coders=") + .append(coders).append(", filteringParser=").append(filteringParser).append(", customCoder=") + .append(customCoder).append("]"); + return builder.toString(); + } +} + +/** + * Tools used for encoding/decoding using Jackson + */ +class JacksonProtocolCoderToolset extends ProtocolCoderToolset { + private static Logger logger = FlexLogger.getLogger(JacksonProtocolCoderToolset.class); + /** + * decoder + */ + @JsonIgnore + protected final ObjectMapper decoder = new ObjectMapper(); + + /** + * encoder + */ + @JsonIgnore + protected final ObjectMapper encoder = new ObjectMapper(); + + /** + * Toolset to encode/decode tools associated with a topic + * + * @param topic topic + * @param decodedClass decoded class of an event + * @param filter + */ + public JacksonProtocolCoderToolset(String topic, String controllerId, + String groupId, String artifactId, + String decodedClass, + JsonProtocolFilter filter, + CustomJacksonCoder customJacksonCoder, + int modelClassLoaderHash) { + super(topic, controllerId, groupId, artifactId, decodedClass, filter, customJacksonCoder, modelClassLoaderHash); + decoder.registerModule(new JavaTimeModule()); + decoder.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, + false); + } + + /** + * gets the Jackson decoder + * + * @return the Jackson decoder + */ + @JsonIgnore + protected ObjectMapper getDecoder() {return decoder;} + + /** + * gets the Jackson encoder + * + * @return the Jackson encoder + */ + @JsonIgnore + protected ObjectMapper getEncoder() {return encoder;} + + /** + * {@inheritDoc} + */ + @Override + public Object decode(String json) + throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { + + // 0. Use custom coder if available + + if (this.customCoder != null) { + throw new UnsupportedOperationException + ("Jackon Custom Decoder is not supported at this time"); + } + + DroolsController droolsController = + DroolsController.factory.get(groupId, artifactId, ""); + if (droolsController == null) { + String error = "NO-DROOLS-CONTROLLER for: " + json + " IN " + this; + logger.warn(error); + throw new IllegalStateException(error); + } + + CoderFilters decoderFilter = filter(json); + if (decoderFilter == null) { + String error = "NO-DECODER for: " + json + " IN " + this; + logger.warn(error); + throw new UnsupportedOperationException(error); + } + + Class decoderClass; + try { + decoderClass = + droolsController.fetchModelClass(decoderFilter.getCodedClass()); + if (decoderClass == null) { + String error = "DECODE-ERROR FETCHING MODEL CLASS: " + ":" + json + ":" + this; + logger.error(error); + throw new IllegalStateException(error); + } + } catch (Exception e) { + String error = "DECODE-ERROR FETCHING MODEL CLASS: "+ e.getMessage() + ":" + json + ":" + this; + logger.warn(MessageCodes.EXCEPTION_ERROR, e, error); + throw new UnsupportedOperationException(error, e); + } + + + try { + Object fact = this.decoder.readValue(json, decoderClass); + return fact; + } catch (Exception e) { + String error = "DECODE-ERROR FROM PDP-D FRAMEWORK: "+ json + ":" + e.getMessage() + ":" + this; + logger.error(MessageCodes.EXCEPTION_ERROR, e, error); + throw new UnsupportedOperationException(error, e); + } + } + + /** + * {@inheritDoc} + */ + @Override + public String encode(Object event) + throws IllegalArgumentException, UnsupportedOperationException { + + // 0. Use custom coder if available + + if (this.customCoder != null) { + throw new UnsupportedOperationException + ("Jackon Custom Encoder is not supported at this time"); + } + + try { + String encodedEvent = this.encoder.writeValueAsString(event); + return encodedEvent; + } catch (JsonProcessingException e) { + String error = "ENCODE-ERROR: "+ event + " IN " + this; + logger.error(MessageCodes.EXCEPTION_ERROR, e, error); + throw new UnsupportedOperationException(error, e); + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("JacksonProtocolCoderToolset [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + +} + +/** + * Tools used for encoding/decoding using Jackson + */ +class GsonProtocolCoderToolset extends ProtocolCoderToolset { + + private static Logger logger = FlexLogger.getLogger(GsonProtocolCoderToolset.class); + /** + * Formatter for JSON encoding/decoding + */ + @JsonIgnore + public static DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + + @JsonIgnore + public static DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT; + + /** + * Adapter for ZonedDateTime + */ + + public static class GsonUTCAdapter implements JsonSerializer, JsonDeserializer { + + public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) + throws JsonParseException { + try { + return ZonedDateTime.parse(element.getAsString(), format); + } catch (Exception e) { + System.err.println(e); + } + return null; + } + + public JsonElement serialize(ZonedDateTime datetime, Type type, JsonSerializationContext context) { + return new JsonPrimitive(datetime.format(format)); + } + } + + public static class GsonInstantAdapter implements JsonSerializer, JsonDeserializer { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return Instant.ofEpochMilli(json.getAsLong()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } + + } + + + /** + * decoder + */ + @JsonIgnore + protected final Gson decoder = new GsonBuilder().disableHtmlEscaping(). + registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter()). + create(); + + /** + * encoder + */ + @JsonIgnore + protected final Gson encoder = new GsonBuilder().disableHtmlEscaping(). + registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter()). + create(); + + /** + * Toolset to encode/decode tools associated with a topic + * + * @param topic topic + * @param decodedClass decoded class of an event + * @param filter + */ + public GsonProtocolCoderToolset(String topic, String controllerId, + String groupId, String artifactId, + String decodedClass, + JsonProtocolFilter filter, + CustomGsonCoder customGsonCoder, + int modelClassLoaderHash) { + super(topic, controllerId, groupId, artifactId, decodedClass, filter, customGsonCoder, modelClassLoaderHash); + } + + /** + * gets the Gson decoder + * + * @return the Gson decoder + */ + @JsonIgnore + protected Gson getDecoder() {return decoder;} + + /** + * gets the Gson encoder + * + * @return the Gson encoder + */ + @JsonIgnore + protected Gson getEncoder() {return encoder;} + + /** + * {@inheritDoc} + */ + @Override + public Object decode(String json) + throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException { + + DroolsController droolsController = + DroolsController.factory.get(groupId, artifactId, ""); + if (droolsController == null) { + String error = "NO-DROOLS-CONTROLLER for: " + json + " IN " + this; + logger.warn(error); + throw new IllegalStateException(error); + } + + CoderFilters decoderFilter = filter(json); + if (decoderFilter == null) { + String error = "NO-DECODER for: " + json + " IN " + this; + logger.warn(error); + throw new UnsupportedOperationException(error); + } + + Class decoderClass; + try { + decoderClass = + droolsController.fetchModelClass(decoderFilter.getCodedClass()); + if (decoderClass == null) { + String error = "DECODE-ERROR FETCHING MODEL CLASS: " + ":" + json + ":" + this; + logger.error(error); + throw new IllegalStateException(error); + } + } catch (Exception e) { + String error = "DECODE-ERROR FETCHING MODEL CLASS: "+ e.getMessage() + ":" + json + ":" + this; + logger.warn(MessageCodes.EXCEPTION_ERROR, e, error); + throw new UnsupportedOperationException(error, e); + } + + if (this.customCoder != null) { + try { + Class gsonClassContainer = + droolsController.fetchModelClass(this.customCoder.getClassContainer()); + Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField); + Object gsonObject = gsonField.get(null); + Method fromJsonMethod = gsonObject.getClass(). + getDeclaredMethod + ("fromJson", new Class[]{String.class, Class.class}); + Object fact = fromJsonMethod.invoke(gsonObject, json, decoderClass); + return fact; + } catch (NoSuchFieldException | SecurityException | IllegalAccessException | + NoSuchMethodException | InvocationTargetException e) { + String error = "DECODE-ERROR-FROM-CUSTOM-CODER: " + e.getMessage() + ":" + json + ":" + this; + logger.error(MessageCodes.EXCEPTION_ERROR, e, error); + throw new UnsupportedOperationException(error, e); + } + } else { + try { + Object fact = this.decoder.fromJson(json, decoderClass); + return fact; + } catch (Exception e) { + String error = "DECODE-ERROR FROM PDP-D FRAMEWORK: "+ json + ":" + e.getMessage() + ":" + this; + logger.error(MessageCodes.EXCEPTION_ERROR, e, error); + throw new UnsupportedOperationException(error, e); + } + } + } + + + + /** + * {@inheritDoc} + */ + @Override + public String encode(Object event) + throws IllegalArgumentException, UnsupportedOperationException { + + DroolsController droolsController = + DroolsController.factory.get(groupId, artifactId, ""); + if (droolsController == null) { + String error = "NO-DROOLS-CONTROLLER for: " + event + " IN " + this; + logger.warn(error); + throw new IllegalStateException(error); + } + + if (this.customCoder != null) { + try { + Class gsonClassContainer = + droolsController.fetchModelClass(this.customCoder.getClassContainer()); + Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField); + Object gsonObject = gsonField.get(null); + Method toJsonMethod = gsonObject.getClass(). + getDeclaredMethod + ("toJson", new Class[]{Object.class}); + String encodedJson = (String) toJsonMethod.invoke(gsonObject, event); + return encodedJson; + } catch (NoSuchFieldException | SecurityException | IllegalAccessException | + NoSuchMethodException | InvocationTargetException e) { + String error = "DECODE-ERROR-FROM-CUSTOM-CODER: " + e.getMessage() + ":" + event + ":" + this; + logger.error(MessageCodes.EXCEPTION_ERROR, e, error); + throw new UnsupportedOperationException(error, e); + } + } else { + try { + String encodedEvent = this.encoder.toJson(event); + return encodedEvent; + } catch (Exception e) { + String error = "ENCODE-ERROR: "+ event + " IN " + this; + logger.error(MessageCodes.EXCEPTION_ERROR, e, error); + throw new UnsupportedOperationException(error, e); + } + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GsonProtocolCoderToolset [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java new file mode 100644 index 00000000..3c112573 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java @@ -0,0 +1,309 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.protocol.coders; + +import java.util.List; + +public class TopicCoderFilterConfiguration { + + /** + * Custom coder, contains class and static field to access parser that the controller + * desires to use instead of the framework provided parser + */ + public static abstract class CustomCoder { + protected String className; + protected String staticCoderField; + + /** + * create custom coder from raw string in the following format + * (typically embedded in a property file): + * + * Note this is to support decoding/encoding of partial structures that are + * only known by the model. + * + * @param rawCustomCoder with format: , + */ + public CustomCoder(String rawCustomCoder) throws IllegalArgumentException { + if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) { + + this.className = rawCustomCoder.substring(0,rawCustomCoder.indexOf(",")); + if (this.className == null || this.className.isEmpty()) { + throw new IllegalArgumentException("No classname to create CustomCoder cannot be created"); + } + + this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",")+1); + if (this.staticCoderField == null || this.staticCoderField.isEmpty()) { + throw new IllegalArgumentException + ("No staticCoderField to create CustomCoder cannot be created for class " + + className); + } + + } + } + /** + * @param classContainer + * @param staticCoderField + */ + public CustomCoder(String className, String staticCoderField) throws IllegalArgumentException { + if (className == null || className.isEmpty()) { + throw new IllegalArgumentException("No classname to create CustomCoder cannot be created"); + } + + if (staticCoderField == null || staticCoderField.isEmpty()) { + throw new IllegalArgumentException + ("No staticCoderField to create CustomCoder cannot be created for class " + + className); + } + + this.className = className; + this.staticCoderField = staticCoderField; + } + + /** + * @return the className + */ + public String getClassContainer() { + return className; + } + + /** + * @param className the className to set + */ + public void setClassContainer(String className) { + this.className = className; + } + + /** + * @return the staticCoderField + */ + public String getStaticCoderField() { + return staticCoderField; + } + + /** + * @param staticCoderField the staticGson to set + */ + public void setStaticCoderField(String staticCoderField) { + this.staticCoderField = staticCoderField; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CustomCoder [className=").append(className).append(", staticCoderField=") + .append(staticCoderField).append("]"); + return builder.toString(); + } + } + + public static class CustomGsonCoder extends CustomCoder { + + public CustomGsonCoder(String className, String staticCoderField) { + super(className, staticCoderField); + } + + public CustomGsonCoder(String customGson) throws IllegalArgumentException { + super(customGson); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CustomGsonCoder [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + + } + + public static class CustomJacksonCoder extends CustomCoder { + + public CustomJacksonCoder(String className, String staticCoderField) { + super(className, staticCoderField); + } + + public CustomJacksonCoder(String customJackson) throws IllegalArgumentException { + super(customJackson); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CustomJacksonCoder [toString()=").append(super.toString()).append("]"); + return builder.toString(); + } + + } + + /** + * Coder/Decoder class and Filter container. The decoder class is potential, + * in order to be operational needs to be fetched from an available + * class loader. + * + */ + public static class PotentialCoderFilter { + + /** + * decoder class (pending from being able to be fetched and found + * in some class loader) + */ + protected String codedClass; + + /** + * filters to apply to the selection of the decodedClass; + */ + protected JsonProtocolFilter filter; + + /** + * constructor + * + * @param codedClass decoder class + * @param filter filters to apply + */ + public PotentialCoderFilter(String codedClass, JsonProtocolFilter filter) { + this.codedClass = codedClass; + this.filter = filter; + } + + /** + * @return the decodedClass + */ + public String getCodedClass() { + return codedClass; + } + + /** + * @param decodedClass the decodedClass to set + */ + public void setCodedClass(String decodedClass) { + this.codedClass = decodedClass; + } + + /** + * @return the filter + */ + public JsonProtocolFilter getFilter() { + return filter; + } + + /** + * @param filter the filter to set + */ + public void setFilter(JsonProtocolFilter filter) { + this.filter = filter; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("PotentialCoderFilter [codedClass=").append(codedClass).append(", filter=").append(filter) + .append("]"); + return builder.toString(); + } + } + + /** + * the source topic + */ + protected final String topic; + + /** + * List of decoder -> filters + */ + protected final List coderFilters; + + /** + * custom gson coder that this controller prefers to use instead of the framework ones + */ + protected CustomGsonCoder customGsonCoder; + + /** + * custom jackson coder that this controller prefers to use instead of the framework ones + */ + protected CustomJacksonCoder customJacksonCoder; + + /** + * Constructor + * + * @param decoderFilters list of decoders and associated filters + * @param topic the topic + */ + public TopicCoderFilterConfiguration(String topic, List decoderFilters, + CustomGsonCoder customGsonCoder, + CustomJacksonCoder customJacksonCoder) { + this.coderFilters = decoderFilters; + this.topic = topic; + this.customGsonCoder = customGsonCoder; + this.customJacksonCoder = customJacksonCoder; + } + + /** + * @return the topic + */ + public String getTopic() { + return topic; + } + + /** + * @return the decoderFilters + */ + public List getCoderFilters() { + return coderFilters; + } + + /** + * @return the customGsonCoder + */ + public CustomGsonCoder getCustomGsonCoder() { + return customGsonCoder; + } + + /** + * @param customGsonCoder the customGsonCoder to set + */ + public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) { + this.customGsonCoder = customGsonCoder; + } + + /** + * @return the customJacksonCoder + */ + public CustomJacksonCoder getCustomJacksonCoder() { + return customJacksonCoder; + } + + /** + * @param customJacksonCoder the customJacksonCoder to set + */ + public void setCustomJacksonCoder(CustomJacksonCoder customJacksonCoder) { + this.customJacksonCoder = customJacksonCoder; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("TopicCoderFilterConfiguration [topic=").append(topic).append(", coderFilters=") + .append(coderFilters).append(", customGsonCoder=").append(customGsonCoder) + .append(", customJacksonCoder=").append(customJacksonCoder).append("]"); + return builder.toString(); + } + + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/ControllerConfiguration.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/ControllerConfiguration.java new file mode 100644 index 00000000..98af02ee --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/ControllerConfiguration.java @@ -0,0 +1,280 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.protocol.configuration; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + + +/** + * Drools Related Information + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ControllerConfiguration { + + public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create"; + public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update"; + public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock"; + public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock"; + + /** + * + * (Required) + * + */ + @JsonProperty("name") + private String name; + /** + * Set of operations that can be applied to a controller: create, lock + * (Required) + * + */ + @JsonProperty("operation") + private String operation; + /** + * Maven Related Information + * + */ + @JsonProperty("drools") + private DroolsConfiguration drools; + @JsonIgnore + private Map additionalProperties = new HashMap(); + protected final static Object NOT_FOUND_VALUE = new Object(); + + /** + * No args constructor for use in serialization + * + */ + public ControllerConfiguration() { + } + + /** + * + * @param name + * @param drools + * @param operation + */ + public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) { + this.name = name; + this.operation = operation; + this.drools = drools; + } + + /** + * + * (Required) + * + * @return + * The name + */ + @JsonProperty("name") + public String getName() { + return name; + } + + /** + * + * (Required) + * + * @param name + * The name + */ + @JsonProperty("name") + public void setName(String name) { + this.name = name; + } + + public ControllerConfiguration withName(String name) { + this.name = name; + return this; + } + + /** + * Set of operations that can be applied to a controller: create, lock + * (Required) + * + * @return + * The operation + */ + @JsonProperty("operation") + public String getOperation() { + return operation; + } + + /** + * Set of operations that can be applied to a controller: create, lock + * (Required) + * + * @param operation + * The operation + */ + @JsonProperty("operation") + public void setOperation(String operation) { + this.operation = operation; + } + + public ControllerConfiguration withOperation(String operation) { + this.operation = operation; + return this; + } + + /** + * Maven Related Information + * + * @return + * The drools + */ + @JsonProperty("drools") + public DroolsConfiguration getDrools() { + return drools; + } + + /** + * Maven Related Information + * + * @param drools + * The drools + */ + @JsonProperty("drools") + public void setDrools(DroolsConfiguration drools) { + this.drools = drools; + } + + public ControllerConfiguration withDrools(DroolsConfiguration drools) { + this.drools = drools; + return this; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + public ControllerConfiguration withAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + return this; + } + + protected boolean declaredProperty(String name, Object value) { + switch (name) { + case "name": + if (value instanceof String) { + setName(((String) value)); + } else { + throw new IllegalArgumentException(("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + return true; + case "operation": + if (value instanceof String) { + setOperation(((String) value)); + } else { + throw new IllegalArgumentException(("property \"operation\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + return true; + case "drools": + if (value instanceof DroolsConfiguration) { + setDrools(((DroolsConfiguration) value)); + } else { + throw new IllegalArgumentException(("property \"drools\" is of type \"org.openecomp.policy.drools.protocol.configuration.Drools\", but got "+ value.getClass().toString())); + } + return true; + default: + return false; + } + } + + protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) { + switch (name) { + case "name": + return getName(); + case "operation": + return getOperation(); + case "drools": + return getDrools(); + default: + return notFoundValue; + } + } + + @SuppressWarnings({ + "unchecked" + }) + publicT get(String name) { + Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE); + if (ControllerConfiguration.NOT_FOUND_VALUE!= value) { + return ((T) value); + } else { + return ((T) getAdditionalProperties().get(name)); + } + } + + public void set(String name, Object value) { + if (!declaredProperty(name, value)) { + getAdditionalProperties().put(name, ((Object) value)); + } + } + + public ControllerConfiguration with(String name, Object value) { + if (!declaredProperty(name, value)) { + getAdditionalProperties().put(name, ((Object) value)); + } + return this; + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof ControllerConfiguration) == false) { + return false; + } + ControllerConfiguration rhs = ((ControllerConfiguration) other); + return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/DroolsConfiguration.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/DroolsConfiguration.java new file mode 100644 index 00000000..87cf2348 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/DroolsConfiguration.java @@ -0,0 +1,278 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.protocol.configuration; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + + +/** + * Maven Related Information + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class DroolsConfiguration { + + /** + * Maven Artifact ID + * (Required) + * + */ + @JsonProperty("artifactId") + private String artifactId; + /** + * Maven Group ID + * (Required) + * + */ + @JsonProperty("groupId") + private String groupId; + /** + * Maven Version + * (Required) + * + */ + @JsonProperty("version") + private String version; + @JsonIgnore + private Map additionalProperties = new HashMap(); + protected final static Object NOT_FOUND_VALUE = new Object(); + + /** + * No args constructor for use in serialization + * + */ + public DroolsConfiguration() { + } + + /** + * + * @param groupId + * @param artifactId + * @param version + */ + public DroolsConfiguration(String artifactId, String groupId, String version) { + this.artifactId = artifactId; + this.groupId = groupId; + this.version = version; + } + + /** + * Maven Artifact ID + * (Required) + * + * @return + * The artifactId + */ + @JsonProperty("artifactId") + public String getArtifactId() { + return artifactId; + } + + /** + * Maven Artifact ID + * (Required) + * + * @param artifactId + * The artifactId + */ + @JsonProperty("artifactId") + public void setArtifactId(String artifactId) { + this.artifactId = artifactId; + } + + public DroolsConfiguration withArtifactId(String artifactId) { + this.artifactId = artifactId; + return this; + } + + /** + * Maven Group ID + * (Required) + * + * @return + * The groupId + */ + @JsonProperty("groupId") + public String getGroupId() { + return groupId; + } + + /** + * Maven Group ID + * (Required) + * + * @param groupId + * The groupId + */ + @JsonProperty("groupId") + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public DroolsConfiguration withGroupId(String groupId) { + this.groupId = groupId; + return this; + } + + /** + * Maven Version + * (Required) + * + * @return + * The version + */ + @JsonProperty("version") + public String getVersion() { + return version; + } + + /** + * Maven Version + * (Required) + * + * @param version + * The version + */ + @JsonProperty("version") + public void setVersion(String version) { + this.version = version; + } + + public DroolsConfiguration withVersion(String version) { + this.version = version; + return this; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + public DroolsConfiguration withAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + return this; + } + + protected boolean declaredProperty(String name, Object value) { + switch (name) { + case "artifactId": + if (value instanceof String) { + setArtifactId(((String) value)); + } else { + throw new IllegalArgumentException(("property \"artifactId\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + return true; + case "groupId": + if (value instanceof String) { + setGroupId(((String) value)); + } else { + throw new IllegalArgumentException(("property \"groupId\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + return true; + case "version": + if (value instanceof String) { + setVersion(((String) value)); + } else { + throw new IllegalArgumentException(("property \"version\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + return true; + default: + return false; + } + } + + protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) { + switch (name) { + case "artifactId": + return getArtifactId(); + case "groupId": + return getGroupId(); + case "version": + return getVersion(); + default: + return notFoundValue; + } + } + + @SuppressWarnings({ + "unchecked" + }) + publicT get(String name) { + Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE); + if (DroolsConfiguration.NOT_FOUND_VALUE!= value) { + return ((T) value); + } else { + return ((T) getAdditionalProperties().get(name)); + } + } + + public void set(String name, Object value) { + if (!declaredProperty(name, value)) { + getAdditionalProperties().put(name, ((Object) value)); + } + } + + public DroolsConfiguration with(String name, Object value) { + if (!declaredProperty(name, value)) { + getAdditionalProperties().put(name, ((Object) value)); + } + return this; + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof DroolsConfiguration) == false) { + return false; + } + DroolsConfiguration rhs = ((DroolsConfiguration) other); + return new EqualsBuilder().append(artifactId, rhs.artifactId).append(groupId, rhs.groupId).append(version, rhs.version).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/PdpdConfiguration.java b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/PdpdConfiguration.java new file mode 100644 index 00000000..65de6656 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/protocol/configuration/PdpdConfiguration.java @@ -0,0 +1,283 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.protocol.configuration; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + + +/** + * ENGINE-CONFIGURATION + *

+ * + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class PdpdConfiguration { + + /** + * Controller Entity ID + */ + public static final String CONFIG_ENTITY_CONTROLLER = "controller"; + + /** + * Unique Transaction ID. This is an UUID. + * (Required) + * + */ + @JsonProperty("requestID") + private String requestID; + /** + * Set of entities on which configuration can be performed: controller + * (Required) + * + */ + @JsonProperty("entity") + private String entity; + /** + * Controller Information, only applicable when the entity is set to controller + * + */ + @JsonProperty("controllers") + private List controllers = new ArrayList(); + @JsonIgnore + private Map additionalProperties = new HashMap(); + protected final static Object NOT_FOUND_VALUE = new Object(); + + /** + * No args constructor for use in serialization + * + */ + public PdpdConfiguration() { + } + + /** + * + * @param controller + * @param requestID + * @param entity + */ + public PdpdConfiguration(String requestID, String entity, List controllers) { + this.requestID = requestID; + this.entity = entity; + this.controllers = controllers; + } + + /** + * Unique Transaction ID. This is an UUID. + * (Required) + * + * @return + * The requestID + */ + @JsonProperty("requestID") + public String getRequestID() { + return requestID; + } + + /** + * Unique Transaction ID. This is an UUID. + * (Required) + * + * @param requestID + * The requestID + */ + @JsonProperty("requestID") + public void setRequestID(String requestID) { + this.requestID = requestID; + } + + public PdpdConfiguration withRequestID(String requestID) { + this.requestID = requestID; + return this; + } + + /** + * Set of entities on which configuration can be performed: controller + * (Required) + * + * @return + * The entity + */ + @JsonProperty("entity") + public String getEntity() { + return entity; + } + + /** + * Set of entities on which configuration can be performed: controller + * (Required) + * + * @param entity + * The entity + */ + @JsonProperty("entity") + public void setEntity(String entity) { + this.entity = entity; + } + + public PdpdConfiguration withEntity(String entity) { + this.entity = entity; + return this; + } + + /** + * Controller Information, only applicable when the entity is set to controller + * + * @return + * The controller + */ + @JsonProperty("controller") + public List getControllers() { + return controllers; + } + + /** + * Controller Information, only applicable when the entity is set to controller + * + * @param controller + * The controller + */ + @JsonProperty("controller") + public void setControllers(List controllers) { + this.controllers = controllers; + } + + public PdpdConfiguration withController(List controllers) { + this.controllers = controllers; + return this; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + public PdpdConfiguration withAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + return this; + } + + @SuppressWarnings("unchecked") + protected boolean declaredProperty(String name, Object value) { + switch (name) { + case "requestID": + if (value instanceof String) { + setRequestID(((String) value)); + } else { + throw new IllegalArgumentException(("property \"requestID\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + return true; + case "entity": + if (value instanceof String) { + setEntity(((String) value)); + } else { + throw new IllegalArgumentException(("property \"entity\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + return true; + case "controllers": + if (value instanceof List) { + setControllers(((List ) value)); + } else { + throw new IllegalArgumentException(("property \"controllers\" is of type \"java.util.List\", but got "+ value.getClass().toString())); + } + return true; + default: + return false; + } + } + + protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) { + switch (name) { + case "requestID": + return getRequestID(); + case "entity": + return getEntity(); + case "controllers": + return getControllers(); + default: + return notFoundValue; + } + } + + @SuppressWarnings({ + "unchecked" + }) + publicT get(String name) { + Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE); + if (PdpdConfiguration.NOT_FOUND_VALUE!= value) { + return ((T) value); + } else { + return ((T) getAdditionalProperties().get(name)); + } + } + + public void set(String name, Object value) { + if (!declaredProperty(name, value)) { + getAdditionalProperties().put(name, ((Object) value)); + } + } + + public PdpdConfiguration with(String name, Object value) { + if (!declaredProperty(name, value)) { + getAdditionalProperties().put(name, ((Object) value)); + } + return this; + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(requestID).append(entity).append(controllers).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof PdpdConfiguration) == false) { + return false; + } + PdpdConfiguration rhs = ((PdpdConfiguration) other); + return new EqualsBuilder().append(requestID, rhs.requestID).append(entity, rhs.entity).append(controllers, rhs.controllers).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/server/restful/RestManager.java b/policy-management/src/main/java/org/openecomp/policy/drools/server/restful/RestManager.java new file mode 100644 index 00000000..48e6313a --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/server/restful/RestManager.java @@ -0,0 +1,1181 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.server.restful; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.UUID; +import java.util.regex.Pattern; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.drools.event.comm.TopicEndpoint; +import org.openecomp.policy.drools.event.comm.TopicSink; +import org.openecomp.policy.drools.event.comm.TopicSource; +import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSink; +import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSource; +import org.openecomp.policy.drools.event.comm.bus.UebTopicSink; +import org.openecomp.policy.drools.event.comm.bus.UebTopicSource; +import org.openecomp.policy.drools.properties.PolicyProperties; +import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder; +import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters; +import org.openecomp.policy.drools.protocol.coders.JsonProtocolFilter; +import org.openecomp.policy.drools.protocol.coders.JsonProtocolFilter.FilterRule; +import org.openecomp.policy.drools.protocol.coders.ProtocolCoderToolset; +import org.openecomp.policy.drools.protocol.configuration.ControllerConfiguration; +import org.openecomp.policy.drools.protocol.configuration.PdpdConfiguration; +import org.openecomp.policy.drools.system.PolicyController; +import org.openecomp.policy.drools.system.PolicyEngine; + + +/** + * REST Endpoint for management of the Drools PDP + */ +@Path("/policy/pdp") +public class RestManager { + /** + * Logger + */ + private static Logger logger = FlexLogger.getLogger(RestManager.class); + + /** + * gets the Policy Engine + * + * @return the Policy Engine + */ + @GET + @Path("engine") + @Produces(MediaType.APPLICATION_JSON) + public PolicyEngine engine() { + return PolicyEngine.manager; + } + + + /** + * Updates the Policy Engine + * + * @param configuration configuration + * @return Policy Engine + */ + @PUT + @Path("engine") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response updateEngine(PdpdConfiguration configuration) { + PolicyController controller = null; + boolean success = true; + try { + success = PolicyEngine.manager.configure(configuration); + } catch (Exception e) { + success = false; + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + "PolicyEngine", this.toString()); + } + + if (!success) + return Response.status(Response.Status.NOT_ACCEPTABLE). + entity(new Error("cannot perform operation")).build(); + else + return Response.status(Response.Status.OK).entity(controller).build(); + } + + /** + * Activates the Policy Engine + * + * @param configuration configuration + * @return Policy Engine + */ + @PUT + @Path("engine/activation") + @Produces(MediaType.APPLICATION_JSON) + public Response activateEngine() { + boolean success = true; + try { + PolicyEngine.manager.activate(); + } catch (Exception e) { + success = false; + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + "PolicyEngine", this.toString()); + } + + if (!success) + return Response.status(Response.Status.NOT_ACCEPTABLE). + entity(new Error("cannot perform operation")).build(); + else + return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build(); + } + + /** + * Activates the Policy Engine + * + * @param configuration configuration + * @return Policy Engine + */ + @PUT + @Path("engine/deactivation") + @Produces(MediaType.APPLICATION_JSON) + public Response deactivateEngine() { + boolean success = true; + try { + PolicyEngine.manager.deactivate(); + } catch (Exception e) { + success = false; + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + "PolicyEngine", this.toString()); + } + + if (!success) + return Response.status(Response.Status.NOT_ACCEPTABLE). + entity(new Error("cannot perform operation")).build(); + else + return Response.status(Response.Status.OK).entity(PolicyEngine.manager).build(); + } + + @DELETE + @Path("engine") + @Produces(MediaType.APPLICATION_JSON) + public Response engineShutdown() { + try { + PolicyEngine.manager.shutdown(); + } catch (IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + "shutdown: " + PolicyEngine.manager); + return Response.status(Response.Status.BAD_REQUEST). + entity(PolicyEngine.manager). + build(); + } + + return Response.status(Response.Status.OK). + entity(PolicyEngine.manager). + build(); + } + + @PUT + @Path("engine/lock") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response lockEngine() { + boolean success = PolicyEngine.manager.lock(); + if (success) + return Response.status(Status.OK). + entity("Policy Engine is locked"). + build(); + else + return Response.status(Status.SERVICE_UNAVAILABLE). + entity("Policy Engine cannot be locked"). + build(); + } + + @DELETE + @Path("engine/unlock") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response unlockEngine() { + boolean success = PolicyEngine.manager.unlock(); + if (success) + return Response.status(Status.OK). + entity("Policy Engine is unlocked"). + build(); + else + return Response.status(Status.SERVICE_UNAVAILABLE). + entity("Policy Engine cannot be unlocked"). + build(); + } + + @GET + @Path("engine/controllers") + @Produces(MediaType.APPLICATION_JSON) + public List controllers() { + return PolicyEngine.manager.getPolicyControllers(); + } + + @POST + @Path("engine/controllers") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response addController(Properties config) { + if (config == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error("A configuration must be provided")). + build(); + + String controllerName = config.getProperty(PolicyProperties.PROPERTY_CONTROLLER_NAME); + if (controllerName == null || controllerName.isEmpty()) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error + ("Configuration must have an entry for " + + PolicyProperties.PROPERTY_CONTROLLER_NAME)). + build(); + + PolicyController controller; + try { + controller = PolicyController.factory.get(controllerName); + if (controller != null) + return Response.status(Response.Status.NOT_MODIFIED). + entity(controller). + build(); + } catch (IllegalArgumentException e) { + // This is OK + } catch (IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.NOT_ACCEPTABLE). + entity(new Error(controllerName + " not found")).build(); + } + + try { + controller = PolicyEngine.manager.createPolicyController + (config.getProperty(PolicyProperties.PROPERTY_CONTROLLER_NAME), config); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + + try { + boolean success = controller.start(); + if (!success) { + logger.warn("Can't start " + controllerName + ": " + controller.toString()); + return Response.status(Response.Status.PARTIAL_CONTENT). + entity(new Error(controllerName + " can't be started")).build(); + } + } catch (IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.PARTIAL_CONTENT). + entity(controller).build(); + } + + return Response.status(Response.Status.CREATED). + entity(controller). + build(); + } + + @GET + @Path("engine/controllers/{controllerName}") + @Produces(MediaType.APPLICATION_JSON) + public Response controller(@PathParam("controllerName") String controllerName) { + PolicyController controller = null; + try { + controller = PolicyController.factory.get(controllerName); + } catch (IllegalArgumentException e) { + logger.info("Can't retrieve controller " + controllerName + + ". Reason: " + e.getMessage()); + } catch (IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.NOT_ACCEPTABLE). + entity(new Error(controllerName + " not acceptable")).build(); + } + + if (controller != null) + return Response.status(Response.Status.OK). + entity(controller).build(); + else + return Response.status(Response.Status.NOT_FOUND). + entity(new Error(controllerName + " not found")).build(); + } + + @DELETE + @Path("engine/controllers/{controllerName}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response deleteController(@PathParam("controllerName") String controllerName) { + + if (controllerName == null || controllerName.isEmpty()) + return Response.status(Response.Status.BAD_REQUEST). + entity("A controller name must be provided"). + build(); + + PolicyController controller; + try { + controller = + PolicyController.factory.get(controllerName); + if (controller == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + " does not exist")). + build(); + } catch (IllegalArgumentException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + " not found: " + e.getMessage())). + build(); + } catch (IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.NOT_ACCEPTABLE). + entity(new Error(controllerName + " not acceptable")).build(); + } + + try { + PolicyEngine.manager.removePolicyController(controllerName); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName + controller); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR). + entity(new Error(e.getMessage())). + build(); + } + + return Response.status(Response.Status.OK). + entity(controller). + build(); + } + + /** + * Updates the Policy Engine + * + * @param configuration configuration + * @return Policy Engine + */ + @PUT + @Path("engine/controllers/{controllerName}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response updateController(@PathParam("controllerName") String controllerName, + ControllerConfiguration controllerConfiguration) { + + if (controllerName == null || controllerName.isEmpty() || + controllerConfiguration == null || + controllerConfiguration.getName().intern() != controllerName) + return Response.status(Response.Status.BAD_REQUEST). + entity("A valid or matching controller names must be provided"). + build(); + + PolicyController controller; + try { + controller = PolicyEngine.manager.updatePolicyController(controllerConfiguration); + if (controller == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + " does not exist")). + build(); + } catch (IllegalArgumentException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + " not found: " + e.getMessage())). + build(); + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.NOT_ACCEPTABLE). + entity(new Error(controllerName + " not acceptable")).build(); + } + + return Response.status(Response.Status.OK). + entity(controller). + build(); + } + + public DroolsController getDroolsController(String controllerName) throws IllegalArgumentException { + PolicyController controller = PolicyController.factory.get(controllerName); + if (controller == null) + throw new IllegalArgumentException(controllerName + " does not exist"); + + DroolsController drools = controller.getDrools(); + if (drools == null) + throw new IllegalArgumentException(controllerName + " has no drools configuration"); + + return drools; + } + + @GET + @Path("engine/controllers/{controllerName}/decoders") + @Produces(MediaType.APPLICATION_JSON) + public Response decoders(@PathParam("controllerName") String controllerName) { + try { + DroolsController drools = getDroolsController(controllerName); + List decoders = EventProtocolCoder.manager.getDecoders + (drools.getGroupId(), drools.getArtifactId()); + return Response.status(Response.Status.OK). + entity(decoders). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @GET + @Path("engine/controllers/{controllerName}/decoders/filters") + @Produces(MediaType.APPLICATION_JSON) + public Response decoderFilters(@PathParam("controllerName") String controllerName) { + try { + DroolsController drools = getDroolsController(controllerName); + List filters = EventProtocolCoder.manager.getDecoderFilters + (drools.getGroupId(), drools.getArtifactId()); + return Response.status(Response.Status.OK). + entity(filters). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @GET + @Path("engine/controllers/{controllerName}/decoders/{topicName}") + @Produces(MediaType.APPLICATION_JSON) + public Response decoder(@PathParam("controllerName") String controllerName, + @PathParam("topicName") String topicName) { + try { + DroolsController drools = getDroolsController(controllerName); + ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders + (drools.getGroupId(), drools.getArtifactId(), topicName); + return Response.status(Response.Status.OK). + entity(decoder). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @GET + @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters") + @Produces(MediaType.APPLICATION_JSON) + public Response decoderFilter(@PathParam("controllerName") String controllerName, + @PathParam("topicName") String topicName) { + try { + DroolsController drools = getDroolsController(controllerName); + ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders + (drools.getGroupId(), drools.getArtifactId(), topicName); + if (decoder == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(topicName + " does not exist")). + build(); + else + return Response.status(Response.Status.OK). + entity(decoder.getCoders()). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @GET + @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}") + @Produces(MediaType.APPLICATION_JSON) + public Response decoderFilter(@PathParam("controllerName") String controllerName, + @PathParam("topicName") String topicName, + @PathParam("factClassName") String factClass) { + try { + DroolsController drools = getDroolsController(controllerName); + ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders + (drools.getGroupId(), drools.getArtifactId(), topicName); + CoderFilters filters = decoder.getCoder(factClass); + if (filters == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(topicName + ":" + factClass + " does not exist")). + build(); + else + return Response.status(Response.Status.OK). + entity(filters). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @POST + @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response decoderFilter(@PathParam("controllerName") String controllerName, + @PathParam("topicName") String topicName, + @PathParam("factClassName") String factClass, + JsonProtocolFilter configFilters) { + + if (configFilters == null) { + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error("Configuration Filters not provided")). + build(); + } + + try { + DroolsController drools = getDroolsController(controllerName); + ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders + (drools.getGroupId(), drools.getArtifactId(), topicName); + CoderFilters filters = decoder.getCoder(factClass); + if (filters == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(topicName + ":" + factClass + " does not exist")). + build(); + filters.setFilter(configFilters); + return Response.status(Response.Status.OK). + entity(filters). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @GET + @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}/rules") + @Produces(MediaType.APPLICATION_JSON) + public Response decoderFilterRules(@PathParam("controllerName") String controllerName, + @PathParam("topicName") String topicName, + @PathParam("factClassName") String factClass) { + try { + DroolsController drools = getDroolsController(controllerName); + ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders + (drools.getGroupId(), drools.getArtifactId(), topicName); + + CoderFilters filters = decoder.getCoder(factClass); + if (filters == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + " does not exist")). + build(); + + JsonProtocolFilter filter = filters.getFilter(); + if (filter == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + " no filters")). + build(); + + return Response.status(Response.Status.OK). + entity(filter.getRules()). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @GET + @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}/rules/{ruleName}") + @Produces(MediaType.APPLICATION_JSON) + public Response decoderFilterRules(@PathParam("controllerName") String controllerName, + @PathParam("topicName") String topicName, + @PathParam("factClassName") String factClass, + @PathParam("ruleName") String ruleName) { + try { + DroolsController drools = getDroolsController(controllerName); + ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders + (drools.getGroupId(), drools.getArtifactId(), topicName); + + CoderFilters filters = decoder.getCoder(factClass); + if (filters == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + " does not exist")). + build(); + + JsonProtocolFilter filter = filters.getFilter(); + if (filter == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + " no filters")). + build(); + + return Response.status(Response.Status.OK). + entity(filter.getRules(ruleName)). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @DELETE + @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}/rules/{ruleName}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response deleteDecoderFilterRule(@PathParam("controllerName") String controllerName, + @PathParam("topicName") String topicName, + @PathParam("factClassName") String factClass, + @PathParam("ruleName") String ruleName, + FilterRule rule) { + + try { + DroolsController drools = getDroolsController(controllerName); + ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders + (drools.getGroupId(), drools.getArtifactId(), topicName); + + CoderFilters filters = decoder.getCoder(factClass); + if (filters == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + " does not exist")). + build(); + + JsonProtocolFilter filter = filters.getFilter(); + if (filter == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + " no filters")). + build(); + + if (rule == null) { + filter.deleteRules(ruleName); + return Response.status(Response.Status.OK). + entity(filter.getRules()). + build(); + } + + if (rule.getName() == null || !rule.getName().equals(ruleName)) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + ":" + ruleName + + " rule name request inconsistencies (" + rule.getName() + ")")). + build(); + + filter.deleteRule(ruleName, rule.getRegex()); + return Response.status(Response.Status.OK). + entity(filter.getRules()). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @PUT + @Path("engine/controllers/{controllerName}/decoders/{topicName}/filters/{factClassName}/rules") + @Produces(MediaType.APPLICATION_JSON) + public Response decoderFilterRule(@PathParam("controllerName") String controllerName, + @PathParam("topicName") String topicName, + @PathParam("factClassName") String factClass, + JsonProtocolFilter.FilterRule rule) { + + try { + DroolsController drools = getDroolsController(controllerName); + ProtocolCoderToolset decoder = EventProtocolCoder.manager.getDecoders + (drools.getGroupId(), drools.getArtifactId(), topicName); + + CoderFilters filters = decoder.getCoder(factClass); + if (filters == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + " does not exist")). + build(); + + JsonProtocolFilter filter = filters.getFilter(); + if (filter == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + " no filters")). + build(); + + if (rule.getName() == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + ":" + topicName + ":" + factClass + + " rule name request inconsistencies (" + rule.getName() + ")")). + build(); + + filter.addRule(rule.getName(), rule.getRegex()); + return Response.status(Response.Status.OK). + entity(filter.getRules()). + build(); + } catch (IllegalArgumentException | IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @GET + @Path("engine/controllers/{controllerName}/encoders") + @Produces(MediaType.APPLICATION_JSON) + public Response encoderFilters(@PathParam("controllerName") String controllerName) { + List encoders; + try { + PolicyController controller = PolicyController.factory.get(controllerName); + if (controller == null) + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + " does not exist")). + build(); + DroolsController drools = controller.getDrools(); + if (drools == null) + return Response.status(Response.Status.INTERNAL_SERVER_ERROR). + entity(new Error(controllerName + " has not drools component")). + build(); + encoders = EventProtocolCoder.manager.getEncoderFilters + (drools.getGroupId(), drools.getArtifactId()); + } catch (IllegalArgumentException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(controllerName + " not found: " + e.getMessage())). + build(); + } catch (IllegalStateException e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + controllerName, this.toString()); + return Response.status(Response.Status.NOT_ACCEPTABLE). + entity(new Error(controllerName + " is not accepting the request")).build(); + } + + return Response.status(Response.Status.OK). + entity(encoders). + build(); + } + + @POST + @Path("engine/controllers/{controllerName}/decoders/{topic}") + @Produces(MediaType.APPLICATION_JSON) + public Response decode(@PathParam("controllerName") String controllerName, + @PathParam("topic") String topic, + String json) { + + PolicyController policyController = PolicyController.factory.get(controllerName); + + CodingResult result = new CodingResult(); + result.decoding = false; + result.encoding = false; + result.jsonEncoding = null; + + Object event; + try { + event = EventProtocolCoder.manager.decode + (policyController.getDrools().getGroupId(), + policyController.getDrools().getArtifactId(), + topic, + json); + result.decoding = true; + } catch (Exception e) { + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + + try { + result.jsonEncoding = EventProtocolCoder.manager.encode(topic, event); + result.encoding = true; + } catch (Exception e) { + return Response.status(Response.Status.OK). + entity(result). + build(); + } + + return Response.status(Response.Status.OK). + entity(result). + build(); + } + + @GET + @Path("engine/topics") + @Produces(MediaType.APPLICATION_JSON) + public TopicEndpoint topics() { + return TopicEndpoint.manager; + } + + @SuppressWarnings("unchecked") + @GET + @Path("engine/topics/sources") + @Produces(MediaType.APPLICATION_JSON) + public List sources() { + return (List) TopicEndpoint.manager.getTopicSources(); + } + + @SuppressWarnings("unchecked") + @GET + @Path("engine/topics/sinks") + @Produces(MediaType.APPLICATION_JSON) + public List sinks() { + return (List) TopicEndpoint.manager.getTopicSinks(); + } + + @GET + @Path("engine/topics/sources/ueb") + @Produces(MediaType.APPLICATION_JSON) + public List uebSources() { + return TopicEndpoint.manager.getUebTopicSources(); + } + + @GET + @Path("engine/topics/sinks/ueb") + @Produces(MediaType.APPLICATION_JSON) + public List uebSinks() { + return (List) TopicEndpoint.manager.getUebTopicSinks(); + } + + @GET + @Path("engine/topics/sources/dmaap") + @Produces(MediaType.APPLICATION_JSON) + public List dmaapSources() { + return TopicEndpoint.manager.getDmaapTopicSources(); + } + + @GET + @Path("engine/topics/sinks/dmaap") + @Produces(MediaType.APPLICATION_JSON) + public List dmaapSinks() { + return (List) TopicEndpoint.manager.getDmaapTopicSinks(); + } + + @SuppressWarnings("unchecked") + @GET + @Path("engine/topics/{topic}/sources") + @Produces(MediaType.APPLICATION_JSON) + public List sourceTopic(@PathParam("topic") String topic) { + List topics = new ArrayList(); + topics.add(topic); + + return (List) TopicEndpoint.manager.getTopicSources(topics); + } + + @SuppressWarnings("unchecked") + @GET + @Path("engine/topics/{topic}/sinks") + @Produces(MediaType.APPLICATION_JSON) + public List sinkTopic(@PathParam("topic") String topic) { + List topics = new ArrayList(); + topics.add(topic); + + return (List) TopicEndpoint.manager.getTopicSinks(topics); + } + + + @GET + @Path("engine/topics/{topic}/ueb/source") + @Produces(MediaType.APPLICATION_JSON) + public UebTopicSource uebSourceTopic(@PathParam("topic") String topic) { + return TopicEndpoint.manager.getUebTopicSource(topic); + } + + @GET + @Path("engine/topics/{topic}/ueb/sink") + @Produces(MediaType.APPLICATION_JSON) + public UebTopicSink uebSinkTopic(@PathParam("topic") String topic) { + return TopicEndpoint.manager.getUebTopicSink(topic); + } + + @GET + @Path("engine/topics/{topic}/dmaap/source") + @Produces(MediaType.APPLICATION_JSON) + public DmaapTopicSource dmaapSourceTopic(@PathParam("topic") String topic) { + return TopicEndpoint.manager.getDmaapTopicSource(topic); + } + + @GET + @Path("engine/topics/{topic}/dmaap/sink") + @Produces(MediaType.APPLICATION_JSON) + public DmaapTopicSink dmaapSinkTopic(@PathParam("topic") String topic) { + return TopicEndpoint.manager.getDmaapTopicSink(topic); + } + + @GET + @Path("engine/topics/{topic}/ueb/source/events") + @Produces(MediaType.APPLICATION_JSON) + public Response uebSourceEvent(@PathParam("topic") String topicName) { + + UebTopicSource uebReader = TopicEndpoint.manager.getUebTopicSource(topicName); + String[] events = uebReader.getRecentEvents(); + return Response.status(Status.OK). + entity(events). + build(); + } + + @GET + @Path("engine/topics/{topic}/ueb/sink/events") + @Produces(MediaType.APPLICATION_JSON) + public Response uebSinkEvent(@PathParam("topic") String topicName) { + + UebTopicSink uebSink = TopicEndpoint.manager.getUebTopicSink(topicName); + String[] events = uebSink.getRecentEvents(); + return Response.status(Status.OK). + entity(events). + build(); + } + + @GET + @Path("engine/topics/{topic}/dmaap/source/events") + @Produces(MediaType.APPLICATION_JSON) + public Response dmaapSourcevent(@PathParam("topic") String topicName) { + + DmaapTopicSource uebReader = TopicEndpoint.manager.getDmaapTopicSource(topicName); + String[] events = uebReader.getRecentEvents(); + return Response.status(Status.OK). + entity(events). + build(); + } + + @GET + @Path("engine/topics/{topic}/dmaap/sink/events") + @Produces(MediaType.APPLICATION_JSON) + public Response dmaapSinkEvent(@PathParam("topic") String topicName) { + + DmaapTopicSink uebSink = TopicEndpoint.manager.getDmaapTopicSink(topicName); + String[] events = uebSink.getRecentEvents(); + return Response.status(Status.OK). + entity(events). + build(); + } + + @PUT + @Path("engine/topics/{topic}/ueb/sources/events") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.APPLICATION_JSON) + public Response uebOffer(@PathParam("topic") String topicName, + String json) { + try { + UebTopicSource uebReader = TopicEndpoint.manager.getUebTopicSource(topicName); + boolean success = uebReader.offer(json); + if (success) + return Response.status(Status.OK). + entity("Successfully injected event over " + topicName). + build(); + else + return Response.status(Status.NOT_ACCEPTABLE). + entity("Failure to inject event over " + topicName). + build(); + } catch (Exception e) { + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @PUT + @Path("engine/topics/{topic}/dmaap/sources/events") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.APPLICATION_JSON) + public Response dmaapOffer(@PathParam("topic") String topicName, + String json) { + try { + DmaapTopicSource dmaapReader = TopicEndpoint.manager.getDmaapTopicSource(topicName); + boolean success = dmaapReader.offer(json); + if (success) + return Response.status(Status.OK). + entity("Successfully injected event over " + topicName). + build(); + else + return Response.status(Status.NOT_ACCEPTABLE). + entity("Failure to inject event over " + topicName). + build(); + } catch (Exception e) { + return Response.status(Response.Status.BAD_REQUEST). + entity(new Error(e.getMessage())). + build(); + } + } + + @PUT + @Path("engine/topics/lock") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response lockTopics() { + boolean success = TopicEndpoint.manager.lock(); + if (success) + return Response.status(Status.OK). + entity("Endpoints are locked"). + build(); + else + return Response.status(Status.SERVICE_UNAVAILABLE). + entity("Endpoints cannot be locked"). + build(); + } + + @DELETE + @Path("engine/topics/lock") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response unlockTopics() { + boolean success = TopicEndpoint.manager.unlock(); + if (success) + return Response.status(Status.OK). + entity("Endpoints are unlocked"). + build(); + else + return Response.status(Status.SERVICE_UNAVAILABLE). + entity("Endpoints cannot be unlocked"). + build(); + } + + @PUT + @Path("engine/topics/{topic}/ueb/sources/lock") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response lockTopic(@PathParam("topic") String topicName) { + UebTopicSource reader = TopicEndpoint.manager.getUebTopicSource(topicName); + boolean success = reader.lock(); + if (success) + return Response.status(Status.OK). + entity("Endpoints are unlocked"). + build(); + else + return Response.status(Status.SERVICE_UNAVAILABLE). + entity("Endpoints cannot be unlocked"). + build(); + } + + @PUT + @Path("engine/topics/{topic}/ueb/sources/unlock") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response unlockTopic(@PathParam("topic") String topicName) { + UebTopicSource reader = TopicEndpoint.manager.getUebTopicSource(topicName); + boolean success = reader.unlock(); + if (success) + return Response.status(Status.OK). + entity("Endpoints are unlocked"). + build(); + else + return Response.status(Status.SERVICE_UNAVAILABLE). + entity("Endpoints cannot be unlocked"). + build(); + } + + @PUT + @Path("engine/controllers/{controllerName}/lock") + @Produces(MediaType.APPLICATION_JSON) + public Response lockController(@PathParam("controllerName") String controllerName) { + PolicyController policyController = PolicyController.factory.get(controllerName); + boolean success = policyController.lock(); + if (success) + return Response.status(Status.OK). + entity("Controller " + controllerName + " is now locked"). + build(); + else + return Response.status(Status.SERVICE_UNAVAILABLE). + entity("Controller " + controllerName + " cannot be locked"). + build(); + } + + @DELETE + @Path("engine/controllers/{controllerName}/lock") + @Produces(MediaType.APPLICATION_JSON) + public Response unlockController(@PathParam("controllerName") String controllerName) { + PolicyController policyController = PolicyController.factory.get(controllerName); + boolean success = policyController.unlock(); + if (success) + return Response.status(Status.OK). + entity("Controller " + controllerName + " is now unlocked"). + build(); + else + return Response.status(Status.SERVICE_UNAVAILABLE). + entity("Controller " + controllerName + " cannot be unlocked"). + build(); + } + + @POST + @Path("engine/util/coders/filters/rules/{ruleName}") + @Produces(MediaType.APPLICATION_JSON) + public Response rules(@DefaultValue("false") @QueryParam("negate") boolean negate, + @PathParam("ruleName") String name, + String regex) { + String literalRegex = Pattern.quote(regex); + if (negate) + literalRegex = "^(?!" + literalRegex + "$).*"; + + return Response.status(Status.OK). + entity(new JsonProtocolFilter.FilterRule(name,literalRegex)). + build(); + } + + @GET + @Path("engine/util/uuid") + public Response uuid() { + return Response.status(Status.OK). + entity(UUID.randomUUID().toString()). + build(); + } + + /* + * Helper classes for aggregation of results + */ + + + public static class Endpoints { + public List sources; + public List sinks; + + public Endpoints(List sources, + List sinks) { + this.sources = sources; + this.sinks = sinks; + } + } + + public static class Endpoint { + public TopicSource source; + public TopicSink sink; + + public Endpoint(TopicSource source, + TopicSink sink) { + this.source = source; + this.sink = sink; + } + } + + public static class CodingResult { + public String jsonEncoding; + public Boolean encoding; + public Boolean decoding; + } + + public static class Error { + public String error; + + /** + * @param error + */ + public Error(String error) { + this.error = error; + } + } +} + diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java new file mode 100644 index 00000000..108600b2 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/Main.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.system; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.core.PolicyContainer; +import org.openecomp.policy.drools.persistence.SystemPersistence; +import org.openecomp.policy.drools.utils.PropertyUtil; + +/** + * Programmatic entry point to the management layer + */ +public class Main { + + /** + * logger + */ + private static Logger logger = FlexLogger.getLogger(Main.class, true); + + public static void main(String args[]) { + + File configDir = new File(SystemPersistence.CONFIG_DIR_NAME); + + if (!configDir.isDirectory()) { + throw new IllegalArgumentException + ("config directory: " + configDir.getAbsolutePath() + + " not found"); + } + + + /* 0. Start the CORE layer first */ + + try { + PolicyContainer.globalInit(args); + } catch (Exception e) { + System.out.println("policy-core startup failed"); + logger.warn("policy-core startup failed"); + e.printStackTrace(); + } + + /* 1. Configure the Engine */ + + try { + Path policyEnginePath = Paths.get(configDir.toPath().toString(), SystemPersistence.PROPERTIES_FILE_ENGINE); + Properties properties = PropertyUtil.getProperties(policyEnginePath.toFile()); + PolicyEngine.manager.configure(properties); + } catch (Exception e) { + String msg = "Policy Engine cannot be configured with properties: " + e.getMessage() + " : " + PolicyEngine.manager; + System.out.println(msg); + logger.warn(msg); + } + + /* 2. Start the Engine with the basic services only (no Policy Controllers) */ + + try { + boolean success = PolicyEngine.manager.start(); + if (!success) { + System.out.println("Policy Engine found some problems starting some components: " + PolicyEngine.manager); + logger.warn("Policy Engine is in an invalid state: " + PolicyEngine.manager); + } + } catch (IllegalStateException e) { + String msg = "Policy Engine is starting in an unexpected state: " + e.getMessage() + " : " + PolicyEngine.manager; + System.out.println(msg); + logger.warn(msg); + } catch (Exception e) { + String msg = "Unexpected Situation. Policy Engine cannot be started: " + e.getMessage() + " : " + PolicyEngine.manager; + System.out.println(msg); + e.printStackTrace(); + System.exit(1); + } + + /* 3. Create and start the controllers */ + + File[] controllerFiles = configDir.listFiles(); + for (File config : controllerFiles) { + + if (config.getName().endsWith(SystemPersistence.PROPERTIES_FILE_CONTROLLER_SUFFIX)) { + int idxSuffix = + config.getName().indexOf(SystemPersistence.PROPERTIES_FILE_CONTROLLER_SUFFIX); + int lastIdxSuffix = + config.getName().lastIndexOf(SystemPersistence.PROPERTIES_FILE_CONTROLLER_SUFFIX); + if (idxSuffix != lastIdxSuffix) { + throw new IllegalArgumentException + ("Improper naming of controller properties file: " + + "Expected " + + SystemPersistence.PROPERTIES_FILE_CONTROLLER_SUFFIX); + } + + String name = + config.getName().substring(0, lastIdxSuffix); + try { + Properties properties = PropertyUtil.getProperties(config); + PolicyController controller = PolicyEngine.manager.createPolicyController(name, properties); + controller.start(); + } catch (Exception e) { + System.out.println("can't instantiate Policy Controller based on properties file: " + + config + " with message " + e.getMessage()); + e.printStackTrace(); + } catch (LinkageError le) { + System.out.println("can't instantiate Policy Controller based on properties file: " + + config + ". A Linkage Error has been encountered: " + le.getMessage()); + le.printStackTrace(); + } + } + } + } +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyController.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyController.java new file mode 100644 index 00000000..543fd0e3 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyController.java @@ -0,0 +1,110 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.system; + +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.drools.event.comm.TopicSource; +import org.openecomp.policy.drools.event.comm.Topic.CommInfrastructure; +import org.openecomp.policy.drools.event.comm.TopicSink; +import org.openecomp.policy.drools.properties.Lockable; +import org.openecomp.policy.drools.properties.Startable; +import org.openecomp.policy.drools.protocol.configuration.DroolsConfiguration; + +/** + * A Policy Controller is the higher level unit of control. It corresponds to + * the ncomp equivalent of a controller. It provides management of underlying + * resources associated with the policy controller, which is a) communication + * infrastructure, and b) policy-core (drools) session infrastructure + * + */ +public interface PolicyController extends Startable, Lockable { + + /** + * name of this Policy Controller + */ + public String getName(); + + /** + * Get the topic readers of interest for this controller + */ + public List getTopicSources(); + + /** + * Get the topic readers of interest for this controller + */ + public List getTopicSinks(); + + /** + * Get the Drools Controller + */ + public DroolsController getDrools(); + + /** + * update maven configuration + * + * @param newDroolsConfiguration new drools configuration + * @return true if the update was successful, false otherwise + */ + public boolean updateDrools(DroolsConfiguration newDroolsConfiguration); + + /** + * Get the Initialization Properties + */ + public Properties getInitializationProperties(); + + /** + * Attempts delivering of an String over communication + * infrastructure "busType" + * + * @param eventBus Communication infrastructure identifier + * @param topic topic + * @param event the event object to send + * + * @return true if successful, false if a failure has occurred. + * @throws IllegalArgumentException when invalid or insufficient + * properties are provided + * @throws IllegalStateException when the engine is in a state where + * this operation is not permitted (ie. locked or stopped). + * @throws UnsupportedOperationException when the engine cannot deliver due + * to the functionality missing (ie. communication infrastructure + * not supported. + */ + public boolean deliver(CommInfrastructure busType, String topic, + Object event) + throws IllegalArgumentException, IllegalStateException, + UnsupportedOperationException; + + /** + * halts and permanently releases all resources + * @throws IllegalStateException + */ + public void halt() throws IllegalStateException; + + /** + * Factory that tracks and manages Policy Controllers + */ + public static PolicyControllerFactory factory = + new IndexedPolicyControllerFactory(); + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyControllerFactory.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyControllerFactory.java new file mode 100644 index 00000000..e105bbb9 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyControllerFactory.java @@ -0,0 +1,464 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.system; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.protocol.configuration.DroolsConfiguration; +import org.openecomp.policy.drools.system.internal.AggregatedPolicyController; + +/** + * Policy Controller Factory to manage controller creation, destruction, + * and retrieval for management interfaces + */ +public interface PolicyControllerFactory { + /** + * Build a controller from a properties file + * + * @param name the global name of this controller + * @param properties input parameters in form of properties for controller + * initialization. + * + * @return a Policy Controller + * + * @throws IllegalArgumentException invalid values provided in properties + */ + public PolicyController build(String name, Properties properties) + throws IllegalArgumentException; + + /** + * patches (updates) a controller from a critical configuration update. + * + * @param name + * @param configController + * + * @return a Policy Controller + */ + public PolicyController patch(String name, DroolsConfiguration configController); + + /** + * rebuilds (updates) a controller from a configuration update. + * + * @param controller + * @param configController + * + * @return a Policy Controller + */ + public PolicyController patch(PolicyController controller, + DroolsConfiguration configController); + + /** + * get PolicyController from DroolsController + * + * @param droolsController + * @return + * @throws IllegalArgumentException + * @throws IllegalStateException + */ + public PolicyController get(DroolsController droolsController) + throws IllegalArgumentException, IllegalStateException; + + /** + * Makes the Policy Controller identified by controllerName not operational, but + * does not delete its associated data + * + * @param controllerName name of the policy controller + * @throws IllegalArgumentException invalid arguments + */ + public void shutdown(String controllerName) throws IllegalArgumentException;; + + /** + * Makes the Policy Controller identified by controller not operational, but + * does not delete its associated data + * + * @param controller a Policy Controller + * @throws IllegalArgumentException invalid arguments + */ + public void shutdown(PolicyController controller) throws IllegalArgumentException; + + /** + * Releases all Policy Controllers from operation + */ + public void shutdown(); + + /** + * Destroys this Policy Controller + * + * @param controllerName name of the policy controller + * @throws IllegalArgumentException invalid arguments + */ + public void destroy(String controllerName) throws IllegalArgumentException;; + + /** + * Destroys this Policy Controller + * + * @param controller a Policy Controller + * @throws IllegalArgumentException invalid arguments + */ + public void destroy(PolicyController controller) throws IllegalArgumentException; + + /** + * Releases all Policy Controller resources + */ + public void destroy(); + + /** + * gets the Policy Controller identified by its name + * + * @param policyControllerName + * @return + * @throws IllegalArgumentException + * @throws IllegalStateException + */ + public PolicyController get(String policyControllerName) + throws IllegalArgumentException, IllegalStateException; + + /** + * gets the Policy Controller identified by group and artifact ids + * + * @param groupId group id + * @param artifactId artifact id + * @return + * @throws IllegalArgumentException + * @throws IllegalStateException + */ + public PolicyController get(String groupId, String artifactId) + throws IllegalArgumentException, IllegalStateException; + + /** + * returns the current inventory of Policy Controllers + * + * @return a list of Policy Controllers + */ + public List inventory(); +} + +/** + * Factory of Policy Controllers indexed by the name of the Policy Controller + */ +class IndexedPolicyControllerFactory implements PolicyControllerFactory { + // get an instance of logger + private static Logger logger = FlexLogger.getLogger(PolicyControllerFactory.class); + + /** + * Policy Controller Name Index + */ + protected HashMap policyControllers = + new HashMap(); + + /** + * Group/Artifact Ids Index + */ + protected HashMap coordinates2Controller = + new HashMap(); + + /** + * produces key for indexing controller names + * + * @param group group id + * @param artifactId artifact id + * @return index key + */ + protected String toKey(String groupId, String artifactId) { + return groupId + ":" + artifactId; + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized PolicyController build(String name, Properties properties) + throws IllegalArgumentException { + + if (this.policyControllers.containsKey(name)) { + return this.policyControllers.get(name); + } + + /* A PolicyController does not exist */ + + PolicyController controller = + new AggregatedPolicyController(name, properties); + + String coordinates = toKey(controller.getDrools().getGroupId(), + controller.getDrools().getArtifactId()); + + this.policyControllers.put(name, controller); + + + if (controller.getDrools().isBrained()) + this.coordinates2Controller.put(coordinates, controller); + + return controller; + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized PolicyController patch(String name, DroolsConfiguration droolsConfig) + throws IllegalArgumentException { + + if (name == null || name.isEmpty() || !this.policyControllers.containsKey(name)) { + throw new IllegalArgumentException("Invalid " + name); + } + + if (droolsConfig == null) + throw new IllegalArgumentException("Invalid Drools Configuration"); + + PolicyController controller = this.get(name); + + if (controller == null) { + logger.warn("A POLICY CONTROLLER of name " + name + + "does not exist for patch operation: " + droolsConfig); + + throw new IllegalArgumentException("Not a valid controller of name " + name); + } + + this.patch(controller, droolsConfig); + + if (logger.isInfoEnabled()) + logger.info("UPDATED drools configuration: " + droolsConfig + " on " + this); + + return controller; + } + + + /** + * {@inheritDoc} + */ + @Override + public PolicyController patch(PolicyController controller, DroolsConfiguration droolsConfig) + throws IllegalArgumentException { + + if (controller == null) + throw new IllegalArgumentException("Not a valid controller: null"); + + if (!controller.updateDrools(droolsConfig)) { + logger.warn("Cannot update drools configuration: " + droolsConfig + " on " + this); + throw new IllegalArgumentException("Cannot update drools configuration Drools Configuration"); + } + + if (logger.isInfoEnabled()) + logger.info("UPDATED drools configuration: " + droolsConfig + " on " + this); + + String coordinates = toKey(controller.getDrools().getGroupId(), + controller.getDrools().getArtifactId()); + + if (controller.getDrools().isBrained()) + this.coordinates2Controller.put(coordinates, controller); + + return controller; + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown(String controllerName) throws IllegalArgumentException { + + if (controllerName == null || controllerName.isEmpty()) { + throw new IllegalArgumentException("Invalid " + controllerName); + } + + synchronized(this) { + if (!this.policyControllers.containsKey(controllerName)) { + return; + } + + PolicyController controller = this.policyControllers.get(controllerName); + this.shutdown(controller); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown(PolicyController controller) throws IllegalArgumentException { + this.unmanage(controller); + controller.shutdown(); + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() { + List controllers = this.inventory(); + for (PolicyController controller: controllers) { + controller.shutdown(); + } + + synchronized(this) { + this.policyControllers.clear(); + this.coordinates2Controller.clear(); + } + } + + /** + * unmanage the controller + * + * @param controller + * @return + * @throws IllegalArgumentException + */ + protected void unmanage(PolicyController controller) throws IllegalArgumentException { + if (controller == null) { + throw new IllegalArgumentException("Invalid Controller"); + } + + synchronized(this) { + if (!this.policyControllers.containsKey(controller.getName())) { + return; + } + controller = this.policyControllers.remove(controller.getName()); + + String coordinates = toKey(controller.getDrools().getGroupId(), + controller.getDrools().getArtifactId()); + this.coordinates2Controller.remove(coordinates); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy(String controllerName) throws IllegalArgumentException { + + if (controllerName == null || controllerName.isEmpty()) { + throw new IllegalArgumentException("Invalid " + controllerName); + } + + synchronized(this) { + if (!this.policyControllers.containsKey(controllerName)) { + return; + } + + PolicyController controller = this.policyControllers.get(controllerName); + this.destroy(controller); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy(PolicyController controller) throws IllegalArgumentException { + this.unmanage(controller); + controller.halt(); + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy() { + List controllers = this.inventory(); + for (PolicyController controller: controllers) { + controller.halt(); + } + + synchronized(this) { + this.policyControllers.clear(); + this.coordinates2Controller.clear(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public PolicyController get(String name) throws IllegalArgumentException, IllegalStateException { + + if (name == null || name.isEmpty()) { + throw new IllegalArgumentException("Invalid " + name); + } + + synchronized(this) { + if (this.policyControllers.containsKey(name)) { + return this.policyControllers.get(name); + } else { + throw new IllegalArgumentException("Invalid " + name); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public PolicyController get(String groupId, String artifactId) + throws IllegalArgumentException, IllegalStateException { + + if (groupId == null || groupId.isEmpty() || + artifactId == null || artifactId.isEmpty()) { + throw new IllegalArgumentException("Invalid group/artifact ids"); + } + + synchronized(this) { + String key = toKey(groupId,artifactId); + if (this.coordinates2Controller.containsKey(key)) { + return this.coordinates2Controller.get(key); + } else { + throw new IllegalArgumentException("Invalid " + key); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public PolicyController get(DroolsController droolsController) + throws IllegalArgumentException, IllegalStateException { + + if (droolsController == null) { + throw new IllegalArgumentException("No Drools Controller provided"); + } + + synchronized(this) { + String key = toKey(droolsController.getGroupId(), droolsController.getArtifactId()); + if (this.coordinates2Controller.containsKey(key)) { + return this.coordinates2Controller.get(key); + } else { + logger.error("Drools Controller not associated with Policy Controller " + droolsController + ":" + this); + throw new IllegalStateException("Drools Controller not associated with Policy Controller " + droolsController + ":" + this); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public List inventory() { + List controllers = + new ArrayList(this.policyControllers.values()); + return controllers; + } + +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java new file mode 100644 index 00000000..33f2a098 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java @@ -0,0 +1,1182 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.system; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.drools.core.FeatureAPI; +import org.openecomp.policy.drools.core.jmx.PdpJmxListener; +import org.openecomp.policy.drools.event.comm.Topic; +import org.openecomp.policy.drools.event.comm.Topic.CommInfrastructure; +import org.openecomp.policy.drools.event.comm.TopicEndpoint; +import org.openecomp.policy.drools.event.comm.TopicListener; +import org.openecomp.policy.drools.event.comm.TopicSink; +import org.openecomp.policy.drools.event.comm.TopicSource; +import org.openecomp.policy.drools.http.server.HttpServletServer; +import org.openecomp.policy.drools.persistence.SystemPersistence; +import org.openecomp.policy.drools.properties.Lockable; +import org.openecomp.policy.drools.properties.PolicyProperties; +import org.openecomp.policy.drools.properties.Startable; +import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder; +import org.openecomp.policy.drools.protocol.configuration.ControllerConfiguration; +import org.openecomp.policy.drools.protocol.configuration.PdpdConfiguration; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Policy Engine, the top abstraction for the Drools PDP Policy Engine. + * It abstracts away a Drools PDP Engine from management purposes. + * This is the best place to looking at the code from a top down approach. + * Other managed entities can be obtained from the PolicyEngine, hierarchically. + *
+ * PolicyEngine 1 --- * PolicyController 1 --- 1 DroolsController 1 --- 1 PolicyContainer 1 --- * PolicySession + *
+ * PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicReader 1 --- 1 UebTopicReader + *
+ * PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicReader 1 --- 1 DmaapTopicReader + *
+ * PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicWriter 1 --- 1 DmaapTopicWriter + *
+ * PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicReader 1 --- 1 RestTopicReader + *
+ * PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicWriter 1 --- 1 RestTopicWriter + *
+ * PolicyEngine 1 --- 1 ManagementServer + */ +public interface PolicyEngine extends Startable, Lockable, TopicListener { + + /** + * Default Config Server Port + */ + public static final int CONFIG_SERVER_DEFAULT_PORT = 9696; + + /** + * Default Config Server Hostname + */ + public static final String CONFIG_SERVER_DEFAULT_HOST = "localhost"; + + /** + * configure the policy engine according to the given properties + * + * @param properties Policy Engine properties + * @throws IllegalArgumentException when invalid or insufficient + * properties are provided + */ + public void configure(Properties properties) throws IllegalArgumentException; + + /** + * registers a new Policy Controller with the Policy Engine + * initialized per properties. + * + * @param controller name + * @param properties properties to initialize the Policy Controller + * @throws IllegalArgumentException when invalid or insufficient + * properties are provided + * @throws IllegalStateException when the engine is in a state where + * this operation is not permitted. + * @return the newly instantiated Policy Controller + */ + public PolicyController createPolicyController(String name, Properties properties) + throws IllegalArgumentException, IllegalStateException; + + /** + * updates the Policy Engine with the given configuration + * + * @param configuration the configuration + * @return success or failure + * @throws IllegalArgumentException if invalid argument provided + * @throws IllegalStateException if the system is in an invalid state + */ + public boolean configure(PdpdConfiguration configuration) + throws IllegalArgumentException, IllegalStateException; + + /** + * updates a set of Policy Controllers with configuration information + * + * @param configuration + * @return + * @throws IllegalArgumentException + * @throws IllegalStateException + */ + public List updatePolicyControllers(List configuration) + throws IllegalArgumentException, IllegalStateException; + + /** + * updates an already existing Policy Controller with configuration information + * + * @param configuration configuration + * + * @return the updated Policy Controller + * @throws IllegalArgumentException in the configuration is invalid + * @throws IllegalStateException if the controller is in a bad state + * @throws Exception any other reason + */ + public PolicyController updatePolicyController(ControllerConfiguration configuration) + throws Exception; + + /** + * removes the Policy Controller identified by its name from the Policy Engine + * + * @param name name of the Policy Controller + * @return the removed Policy Controller + */ + public void removePolicyController(String name); + + /** + * removes a Policy Controller from the Policy Engine + * @param controller the Policy Controller to remove from the Policy Engine + */ + public void removePolicyController(PolicyController controller); + + /** + * returns a list of the available Policy Controllers + * + * @return list of Policy Controllers + */ + public List getPolicyControllers(); + + /** + * get unmanaged sources + * + * @return unmanaged sources + */ + public List getSources(); + + /** + * get unmanaged sinks + * + * @return unmanaged sinks + */ + public List getSinks(); + + /** + * get unmmanaged http servers list + * @return http servers + */ + public List getHttpServers(); + + /** + * get properties configuration + * + * @return properties objects + */ + public Properties getProperties(); + + /** + * Attempts the dispatching of an "event" object + * + * @param topic topic + * @param event the event object to send + * + * @return true if successful, false if a failure has occurred. + * @throws IllegalArgumentException when invalid or insufficient + * properties are provided + * @throws IllegalStateException when the engine is in a state where + * this operation is not permitted (ie. locked or stopped). + */ + public boolean deliver(String topic, Object event) + throws IllegalArgumentException, IllegalStateException; + + /** + * Attempts the dispatching of an "event" object over communication + * infrastructure "busType" + * + * @param eventBus Communication infrastructure identifier + * @param topic topic + * @param event the event object to send + * + * @return true if successful, false if a failure has occurred. + * @throws IllegalArgumentException when invalid or insufficient + * properties are provided + * @throws IllegalStateException when the engine is in a state where + * this operation is not permitted (ie. locked or stopped). + * @throws UnsupportedOperationException when the engine cannot deliver due + * to the functionality missing (ie. communication infrastructure + * not supported. + */ + public boolean deliver(String busType, String topic, Object event) + throws IllegalArgumentException, IllegalStateException, + UnsupportedOperationException; + + /** + * Attempts the dispatching of an "event" object over communication + * infrastructure "busType" + * + * @param eventBus Communication infrastructure enum + * @param topic topic + * @param event the event object to send + * + * @return true if successful, false if a failure has occurred. + * @throws IllegalArgumentException when invalid or insufficient + * properties are provided + * @throws IllegalStateException when the engine is in a state where + * this operation is not permitted (ie. locked or stopped). + * @throws UnsupportedOperationException when the engine cannot deliver due + * to the functionality missing (ie. communication infrastructure + * not supported. + */ + public boolean deliver(CommInfrastructure busType, String topic, Object event) + throws IllegalArgumentException, IllegalStateException, + UnsupportedOperationException; + + /** + * Attempts delivering of an String over communication + * infrastructure "busType" + * + * @param eventBus Communication infrastructure identifier + * @param topic topic + * @param event the event object to send + * + * @return true if successful, false if a failure has occurred. + * @throws IllegalArgumentException when invalid or insufficient + * properties are provided + * @throws IllegalStateException when the engine is in a state where + * this operation is not permitted (ie. locked or stopped). + * @throws UnsupportedOperationException when the engine cannot deliver due + * to the functionality missing (ie. communication infrastructure + * not supported. + */ + public boolean deliver(CommInfrastructure busType, String topic, + String event) + throws IllegalArgumentException, IllegalStateException, + UnsupportedOperationException; + + /** + * Invoked when the host goes into the active state. + */ + public void activate(); + + /** + * Invoked when the host goes into the standby state. + */ + public void deactivate(); + + /** + * get policy controller names + * + * @return list of controller names + */ + public List getControllers(); + + /** + * Policy Engine Manager + */ + public final static PolicyEngine manager = new PolicyEngineManager(); +} + +/** + * Policy Engine Manager Implementation + */ +class PolicyEngineManager implements PolicyEngine { + /** + * logger + */ + private static Logger logger = FlexLogger.getLogger(PolicyEngineManager.class); + + /** + * Is the Policy Engine running? + */ + protected boolean alive = false; + + /** + * Is the engine locked? + */ + protected boolean locked = false; + + /** + * Properties used to initialize the engine + */ + protected Properties properties; + + /** + * Policy Engine Sources + */ + protected List sources = new ArrayList<>(); + + /** + * Policy Engine Sinks + */ + protected List sinks = new ArrayList<>(); + + /** + * Policy Engine HTTP Servers + */ + protected List httpServers = new ArrayList(); + + protected Gson decoder = new GsonBuilder().disableHtmlEscaping().create(); + + /** + * {@inheritDoc} + */ + @Override + public void configure(Properties properties) throws IllegalArgumentException { + + if (properties == null) { + logger.warn("No properties provided"); + throw new IllegalArgumentException("No properties provided"); + } + + this.properties = properties; + + try { + this.sources = TopicEndpoint.manager.addTopicSources(properties); + for (TopicSource source: this.sources) { + source.register(this); + } + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "configure"); + } + + try { + this.sinks = TopicEndpoint.manager.addTopicSinks(properties); + } catch (IllegalArgumentException e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "configure"); + } + + try { + this.httpServers = HttpServletServer.factory.build(properties); + } catch (IllegalArgumentException e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "configure"); + } + + return; + } + + /** + * {@inheritDoc} + */ + @Override + public PolicyController createPolicyController(String name, Properties properties) + throws IllegalArgumentException, IllegalStateException { + + // check if a PROPERTY_CONTROLLER_NAME property is present + // if so, override the given name + + String propertyControllerName = properties.getProperty(PolicyProperties.PROPERTY_CONTROLLER_NAME); + if (propertyControllerName != null && !propertyControllerName.isEmpty()) { + if (!propertyControllerName.equals(name)) { + throw new IllegalStateException("Proposed name (" + name + + ") and properties name (" + propertyControllerName + + ") don't match"); + } + name = propertyControllerName; + } + + // feature hook + for (FeatureAPI feature : FeatureAPI.impl.getList()) { + feature.beforeCreateController(name, properties); + } + + PolicyController controller = PolicyController.factory.build(name, properties); + if (this.isLocked()) + controller.lock(); + + // feature hook + for (FeatureAPI feature : FeatureAPI.impl.getList()) { + // NOTE: this should change to the actual controller object + feature.afterCreateController(name); + } + + return controller; + } + + + /** + * {@inheritDoc} + */ + @Override + public boolean configure(PdpdConfiguration config) throws IllegalArgumentException, IllegalStateException { + + if (config == null) + throw new IllegalArgumentException("No configuration provided"); + + String entity = config.getEntity(); + + switch (entity) { + case PdpdConfiguration.CONFIG_ENTITY_CONTROLLER: + /* only this one supported for now */ + List configControllers = config.getControllers(); + if (configControllers == null || configControllers.isEmpty()) { + if (logger.isInfoEnabled()) + logger.info("No controller configuration provided: " + config); + return false; + } + List policyControllers = this.updatePolicyControllers(config.getControllers()); + if (policyControllers == null || policyControllers.isEmpty()) + return false; + else if (policyControllers.size() == configControllers.size()) + return true; + + return false; + default: + String msg = "Configuration Entity is not supported: " + entity; + logger.warn(msg); + throw new IllegalArgumentException(msg); + } + } + + /** + * {@inheritDoc} + */ + @Override + public List updatePolicyControllers(List configControllers) + throws IllegalArgumentException, IllegalStateException { + + List policyControllers = new ArrayList(); + if (configControllers == null || configControllers.isEmpty()) { + if (logger.isInfoEnabled()) + logger.info("No controller configuration provided: " + configControllers); + return policyControllers; + } + + for (ControllerConfiguration configController: configControllers) { + try { + PolicyController policyController = this.updatePolicyController(configController); + policyControllers.add(policyController); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "updatePolicyControllers"); + } + } + + return policyControllers; + } + + /** + * {@inheritDoc} + */ + @Override + public PolicyController updatePolicyController(ControllerConfiguration configController) + throws Exception { + + if (configController == null) + throw new IllegalArgumentException("No controller configuration has been provided"); + + String controllerName = configController.getName(); + if (controllerName == null || controllerName.isEmpty()) { + logger.warn("controller-name must be provided"); + throw new IllegalArgumentException("No controller configuration has been provided"); + } + + PolicyController policyController = null; + try { + String operation = configController.getOperation(); + if (operation == null || operation.isEmpty()) { + logger.warn("operation must be provided"); + throw new IllegalArgumentException("operation must be provided"); + } + + try { + policyController = PolicyController.factory.get(controllerName); + } catch (IllegalArgumentException e) { + // not found + logger.warn("Policy Controller " + controllerName + " not found"); + } + + if (policyController == null) { + + if (operation.equalsIgnoreCase(ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_LOCK) || + operation.equalsIgnoreCase(ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_UNLOCK)) { + throw new IllegalArgumentException(controllerName + " is not available for operation " + operation); + } + + /* Recovery case */ + + logger.warn("controller " + controllerName + " does not exist. " + + "Attempting recovery from disk"); + + Properties properties = + SystemPersistence.manager.getControllerProperties(controllerName); + + /* + * returned properties cannot be null (per implementation) + * assert (properties != null) + */ + + if (properties == null) { + throw new IllegalArgumentException(controllerName + " is invalid"); + } + + logger.warn("controller " + controllerName + " being recovered. " + + "Reset controller's bad maven coordinates to brainless"); + + /* + * try to bring up bad controller in brainless mode, + * after having it working, apply the new create/update operation. + */ + properties.setProperty(PolicyProperties.RULES_GROUPID, DroolsController.NO_GROUP_ID); + properties.setProperty(PolicyProperties.RULES_ARTIFACTID, DroolsController.NO_ARTIFACT_ID); + properties.setProperty(PolicyProperties.RULES_VERSION, DroolsController.NO_VERSION); + + policyController = PolicyEngine.manager.createPolicyController(controllerName, properties); + + /* fall through to do brain update operation*/ + } + + switch (operation) { + case ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_CREATE: + PolicyController.factory.patch(policyController, configController.getDrools()); + break; + case ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_UPDATE: + policyController.unlock(); + PolicyController.factory.patch(policyController, configController.getDrools()); + break; + case ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_LOCK: + policyController.lock(); + break; + case ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_UNLOCK: + policyController.unlock(); + break; + default: + String msg = "Controller Operation Configuration is not supported: " + + operation + " for " + controllerName; + logger.warn(msg); + throw new IllegalArgumentException(msg); + } + + return policyController; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "updatePolicyController " + e.getMessage()); + throw e; + } catch (LinkageError e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "updatePolicyController " + e.getMessage()); + throw new IllegalStateException(e); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean start() throws IllegalStateException { + + if (this.locked) { + throw new IllegalStateException("Engine is locked"); + } + + // Features hook + for (FeatureAPI feature : FeatureAPI.impl.getList()) { + feature.beforeStartEngine(); + } + + synchronized(this) { + this.alive = true; + } + + boolean success = true; + + /* Start Policy Engine exclusively-owned (unmanaged) http servers */ + + for (HttpServletServer httpServer: this.httpServers) { + try { + if (!httpServer.start()) + success = false; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, httpServer.toString(), this.toString()); + } + } + /* Start Policy Engine exclusively-owned (unmanaged) sources */ + + for (TopicSource source: this.sources) { + try { + if (!source.start()) + success = false; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, source.toString(), this.toString()); + } + } + + /* Start Policy Engine owned (unmanaged) sinks */ + + for (TopicSink sink: this.sinks) { + try { + if (!sink.start()) + success = false; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, sink.toString(), this.toString()); + } + } + + /* Start Policy Controllers */ + + List controllers = PolicyController.factory.inventory(); + for (PolicyController controller : controllers) { + try { + if (!controller.start()) + success = false; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, controller.toString(), this.toString()); + success = false; + } + } + + /* Start managed Topic Endpoints */ + + try { + if (!TopicEndpoint.manager.start()) + success = false; + } catch (IllegalStateException e) { + String msg = "Topic Endpoint Manager is in an invalid state: " + e.getMessage() + " : " + this; + logger.warn(msg); + } + + + // Start the JMX listener + + PdpJmxListener.start(); + + // Features hook + for (FeatureAPI feature : FeatureAPI.impl.getList()) { + feature.afterStartEngine(); + } + + return success; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean stop() { + + /* stop regardless of the lock state */ + + synchronized(this) { + if (!this.alive) + return true; + + this.alive = false; + } + + boolean success = true; + List controllers = PolicyController.factory.inventory(); + for (PolicyController controller : controllers) { + try { + if (!controller.stop()) + success = false; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, controller.toString(), this.toString()); + success = false; + } + } + + /* Stop Policy Engine owned (unmanaged) sources */ + for (TopicSource source: this.sources) { + try { + if (!source.stop()) + success = false; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, source.toString(), this.toString()); + } + } + + /* Stop Policy Engine owned (unmanaged) sinks */ + for (TopicSink sink: this.sinks) { + try { + if (!sink.stop()) + success = false; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, sink.toString(), this.toString()); + } + } + + /* stop all managed topics sources and sinks */ + if (!TopicEndpoint.manager.stop()) + success = false; + + /* stop all unmanaged http servers */ + for (HttpServletServer httpServer: this.httpServers) { + try { + if (!httpServer.stop()) + success = false; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, httpServer.toString(), this.toString()); + } + } + + return success; + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() throws IllegalStateException { + + synchronized(this) { + this.alive = false; + } + + // feature hook reporting that the Policy Engine is being shut down + for (FeatureAPI feature : FeatureAPI.impl.getList()) { + feature.beforeShutdownEngine(); + } + + /* Shutdown Policy Engine owned (unmanaged) sources */ + for (TopicSource source: this.sources) { + try { + source.shutdown(); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, source.toString(), this.toString()); + } + } + + /* Shutdown Policy Engine owned (unmanaged) sinks */ + for (TopicSink sink: this.sinks) { + try { + sink.shutdown(); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, sink.toString(), this.toString()); + } + } + + /* Shutdown managed resources */ + PolicyController.factory.shutdown(); + TopicEndpoint.manager.shutdown(); + HttpServletServer.factory.destroy(); + + // Stop the JMX listener + + PdpJmxListener.stop(); + + // feature hook reporting that the Policy Engine has being shut down + for (FeatureAPI feature : FeatureAPI.impl.getList()) { + feature.afterShutdownEngine(); + } + + new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(5000L); + } catch (InterruptedException e) { + logger.warn("InterruptedException while shutting down management server: " + this.toString()); + } + + /* shutdown all unmanaged http servers */ + for (HttpServletServer httpServer: getHttpServers()) { + try { + httpServer.shutdown(); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, httpServer.toString(), this.toString()); + } + } + + try { + Thread.sleep(5000L); + } catch (InterruptedException e) { + logger.warn("InterruptedException while shutting down management server: " + this.toString()); + } + + System.exit(0); + } + }).start(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAlive() { + return this.alive; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean lock() { + + synchronized(this) { + if (this.locked) + return true; + + this.locked = true; + } + + boolean success = true; + List controllers = PolicyController.factory.inventory(); + for (PolicyController controller : controllers) { + try { + success = controller.lock() && success; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, controller.toString(), this.toString()); + success = false; + } + } + + success = TopicEndpoint.manager.lock(); + return success; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean unlock() { + synchronized(this) { + if (!this.locked) + return true; + + this.locked = false; + } + + boolean success = true; + List controllers = PolicyController.factory.inventory(); + for (PolicyController controller : controllers) { + try { + success = controller.unlock() && success; + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, controller.toString(), this.toString()); + success = false; + } + } + + success = TopicEndpoint.manager.unlock(); + return success; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLocked() { + return this.locked; + } + + /** + * {@inheritDoc} + */ + @Override + public void removePolicyController(String name) { + PolicyController.factory.destroy(name); + } + + /** + * {@inheritDoc} + */ + @Override + public void removePolicyController(PolicyController controller) { + PolicyController.factory.destroy(controller); + } + + /** + * {@inheritDoc} + */ + @JsonIgnore + @Override + public List getPolicyControllers() { + return PolicyController.factory.inventory(); + } + + /** + * {@inheritDoc} + */ + @Override + public List getControllers() { + List controllerNames = new ArrayList(); + for (PolicyController controller: PolicyController.factory.inventory()) { + controllerNames.add(controller.getName()); + } + return controllerNames; + } + + /** + * {@inheritDoc} + */ + @Override + public Properties getProperties() { + return this.properties; + } + + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public List getSources() { + return (List) this.sources; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public List getSinks() { + return (List) this.sinks; + } + + /** + * {@inheritDoc} + */ + @Override + public List getHttpServers() { + return this.httpServers; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean onTopicEvent(CommInfrastructure commType, String topic, String event) { + /* configuration request */ + try { + PdpdConfiguration configuration = this.decoder.fromJson(event, PdpdConfiguration.class); + this.configure(configuration); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "CONFIGURATION ERROR IN PDP-D POLICY ENGINE: "+ event + ":" + e.getMessage() + ":" + this); + } + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean deliver(String topic, Object event) + throws IllegalArgumentException, IllegalStateException { + + /* + * Note this entry point is usually from the DRL + */ + + if (topic == null || topic.isEmpty()) + throw new IllegalArgumentException("Invalid Topic"); + + if (event == null) + throw new IllegalArgumentException("Invalid Event"); + + if (!this.isAlive()) + throw new IllegalStateException("Policy Engine is stopped"); + + if (this.isLocked()) + throw new IllegalStateException("Policy Engine is locked"); + + List sinks = + TopicEndpoint.manager.getTopicSinks(topic); + if (sinks == null || sinks.isEmpty() || sinks.size() > 1) + throw new IllegalStateException + ("Cannot ensure correct delivery on topic " + topic + ": " + sinks); + + return this.deliver(sinks.get(0).getTopicCommInfrastructure(), + topic, event); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean deliver(String busType, String topic, Object event) + throws IllegalArgumentException, IllegalStateException, + UnsupportedOperationException { + + /* + * Note this entry point is usually from the DRL (one of the reasons + * busType is String. + */ + + if (busType == null || busType.isEmpty()) + throw new IllegalArgumentException + ("Invalid Communication Infrastructure"); + + if (topic == null || topic.isEmpty()) + throw new IllegalArgumentException("Invalid Topic"); + + if (event == null) + throw new IllegalArgumentException("Invalid Event"); + + boolean valid = false; + for (Topic.CommInfrastructure comm: Topic.CommInfrastructure.values()) { + if (comm.name().equals(busType)) { + valid = true; + } + } + + if (!valid) + throw new IllegalArgumentException + ("Invalid Communication Infrastructure: " + busType); + + + if (!this.isAlive()) + throw new IllegalStateException("Policy Engine is stopped"); + + if (this.isLocked()) + throw new IllegalStateException("Policy Engine is locked"); + + + return this.deliver(Topic.CommInfrastructure.valueOf(busType), + topic, event); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean deliver(Topic.CommInfrastructure busType, + String topic, Object event) + throws IllegalArgumentException, IllegalStateException, + UnsupportedOperationException { + + if (topic == null || topic.isEmpty()) + throw new IllegalArgumentException("Invalid Topic"); + + if (event == null) + throw new IllegalArgumentException("Invalid Event"); + + if (!this.isAlive()) + throw new IllegalStateException("Policy Engine is stopped"); + + if (this.isLocked()) + throw new IllegalStateException("Policy Engine is locked"); + + /* Try to send through the controller, this is the + * preferred way, since it may want to apply additional + * processing + */ + try { + DroolsController droolsController = + EventProtocolCoder.manager.getDroolsController(topic, event); + PolicyController controller = PolicyController.factory.get(droolsController); + if (controller != null) + return controller.deliver(busType, topic, event); + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + busType + ":" + topic + " :" + event, this.toString()); + /* continue (try without routing through the controller) */ + } + + /* + * cannot route through the controller, send directly through + * the topic sink + */ + try { + String json = EventProtocolCoder.manager.encode(topic, event); + return this.deliver(busType, topic, json); + + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + busType + ":" + topic + " :" + event, this.toString()); + throw e; + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean deliver(Topic.CommInfrastructure busType, + String topic, String event) + throws IllegalArgumentException, IllegalStateException, + UnsupportedOperationException { + + if (topic == null || topic.isEmpty()) + throw new IllegalArgumentException("Invalid Topic"); + + if (event == null || event.isEmpty()) + throw new IllegalArgumentException("Invalid Event"); + + if (!this.isAlive()) + throw new IllegalStateException("Policy Engine is stopped"); + + if (this.isLocked()) + throw new IllegalStateException("Policy Engine is locked"); + + try { + TopicSink sink = + TopicEndpoint.manager.getTopicSink + (busType, topic); + + if (sink == null) + throw new IllegalStateException("Inconsistent State: " + this); + + return sink.send(event); + + } catch (Exception e) { + logger.warn(MessageCodes.EXCEPTION_ERROR, e, + busType + ":" + topic + " :" + event, this.toString()); + throw e; + } + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized void activate() { + + // activate 'policy-management' + for (PolicyController policyController : getPolicyControllers()) { + try { + policyController.unlock(); + policyController.start(); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine.activate: cannot start " + + policyController + " because of " + e.getMessage()); + } catch (LinkageError e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine.activate: cannot start " + + policyController + " because of " + e.getMessage()); + } + } + + this.unlock(); + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized void deactivate() { + + this.lock(); + + for (PolicyController policyController : getPolicyControllers()) { + try { + policyController.stop(); + } catch (Exception e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine.deactivate: cannot stop " + + policyController + " because of " + e.getMessage()); + } catch (LinkageError e) { + logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine.deactivate: cannot start " + + policyController + " because of " + e.getMessage()); + } + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("PolicyEngineManager [alive=").append(alive).append(", locked=").append(locked).append("]"); + return builder.toString(); + } + +} + + diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java new file mode 100644 index 00000000..96f9e5bf --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java @@ -0,0 +1,462 @@ +/*- + * ============LICENSE_START======================================================= + * policy-management + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.system.internal; + +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.drools.controller.DroolsController; +import org.openecomp.policy.drools.event.comm.Topic; +import org.openecomp.policy.drools.event.comm.TopicEndpoint; +import org.openecomp.policy.drools.event.comm.TopicListener; +import org.openecomp.policy.drools.event.comm.TopicSink; +import org.openecomp.policy.drools.event.comm.TopicSource; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.drools.persistence.SystemPersistence; +import org.openecomp.policy.drools.properties.PolicyProperties; +import org.openecomp.policy.drools.protocol.configuration.DroolsConfiguration; +import org.openecomp.policy.drools.system.PolicyController; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * This implementation of the Policy Controller merely aggregates and tracks for + * management purposes all underlying resources that this controller depends upon. + */ +public class AggregatedPolicyController implements PolicyController, + TopicListener { + + /** + * Logger + */ + private static Logger logger = FlexLogger.getLogger(AggregatedPolicyController.class); + + /** + * identifier for this policy controller + */ + protected final String name; + + /** + * Abstracted Event Sources List regardless communication + * technology + */ + protected final List sources; + + /** + * Abstracted Event Sinks List regardless communication + * technology + */ + protected final List sinks; + + /** + * Mapping topics to sinks + */ + @JsonIgnore + protected final HashMap topic2Sinks = + new HashMap(); + + /** + * Is this Policy Controller running (alive) ? + * reflects invocation of start()/stop() only + */ + protected volatile boolean alive; + + /** + * Is this Policy Controller locked ? + * reflects if i/o controller related operations and start + * are permitted, + * more specifically: start(), deliver() and onTopicEvent(). + * It does not affect the ability to stop the + * underlying drools infrastructure + */ + protected volatile boolean locked; + + /** + * Policy Drools Controller + */ + protected volatile DroolsController droolsController; + + /** + * Properties used to initialize controller + */ + protected final Properties properties; + + /** + * Constructor version mainly used for bootstrapping at initialization time + * a policy engine controller + * + * @param name controller name + * @param properties + * + * @throws IllegalArgumentException when invalid arguments are provided + */ + public AggregatedPolicyController(String name, Properties properties) + throws IllegalArgumentException { + + this.name = name; + + /* + * 1. Register read topics with network infrastructure (ueb, dmaap, rest) + * 2. Register write topics with network infrastructure (ueb, dmaap, rest) + * 3. Register with drools infrastructure + */ + + // Create/Reuse Readers/Writers for all event sources endpoints + + this.sources = TopicEndpoint.manager.addTopicSources(properties); + this.sinks = TopicEndpoint.manager.addTopicSinks(properties); + + initDrools(properties); + initSinks(); + + /* persist new properties */ + SystemPersistence.manager.storeController(name, properties); + this.properties = properties; + } + + /** + * initialize drools layer + * @throws IllegalArgumentException if invalid parameters are passed in + */ + protected void initDrools(Properties properties) throws IllegalArgumentException { + try { + // Register with drools infrastructure + this.droolsController = DroolsController.factory.build(properties, sources, sinks); + } catch (Exception | LinkageError e) { + logger.error("BUILD-INIT-DROOLS: " + e.getMessage()); + e.printStackTrace(); + + // throw back exception as input properties cause problems + throw new IllegalArgumentException(e); + } + } + + /** + * initialize sinks + * @throws IllegalArgumentException if invalid parameters are passed in + */ + protected void initSinks() throws IllegalArgumentException { + this.topic2Sinks.clear(); + for (TopicSink sink: sinks) { + this.topic2Sinks.put(sink.getTopic(), sink); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean updateDrools(DroolsConfiguration newDroolsConfiguration) { + + DroolsConfiguration oldDroolsConfiguration = + new DroolsConfiguration(this.droolsController.getArtifactId(), + this.droolsController.getGroupId(), + this.droolsController.getVersion()); + + if (oldDroolsConfiguration.getGroupId().equalsIgnoreCase(newDroolsConfiguration.getGroupId()) && + oldDroolsConfiguration.getArtifactId().equalsIgnoreCase(newDroolsConfiguration.getArtifactId()) && + oldDroolsConfiguration.getVersion().equalsIgnoreCase(newDroolsConfiguration.getVersion())) { + logger.warn("UPDATE-DROOLS: nothing to do: identical configuration: " + oldDroolsConfiguration + + " <=> " + newDroolsConfiguration); + return true; + } + + try { + /* Drools Controller created, update initialization properties for restarts */ + + this.properties.setProperty(PolicyProperties.RULES_GROUPID, newDroolsConfiguration.getGroupId()); + this.properties.setProperty(PolicyProperties.RULES_ARTIFACTID, newDroolsConfiguration.getArtifactId()); + this.properties.setProperty(PolicyProperties.RULES_VERSION, newDroolsConfiguration.getVersion()); + + SystemPersistence.manager.storeController(name, this.properties); + + this.initDrools(this.properties); + + /* set drools controller to current locked status */ + + if (this.isLocked()) + this.droolsController.lock(); + else + this.droolsController.unlock(); + + /* set drools controller to current alive status */ + + if (this.isAlive()) + this.droolsController.start(); + else + this.droolsController.stop(); + + } catch (IllegalArgumentException e) { + logger.warn("INIT-DROOLS: " + e.getMessage()); + e.printStackTrace(); + return false; + } + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public String getName() { + return this.name; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean start() throws IllegalStateException { + if (logger.isInfoEnabled()) + logger.info("START: " + this); + + if (this.isLocked()) + throw new IllegalStateException("Policy Controller " + name + " is locked"); + + synchronized(this) { + if (this.alive) + return true; + + this.alive = true; + } + + boolean success = this.droolsController.start(); + + // register for events + + for (TopicSource source: sources) { + source.register(this); + } + + for (TopicSink sink: sinks) { + try { + sink.start(); + } catch (Exception e) { + logger.warn("can't start sink: " + sink + " because of " + e.getMessage()); + e.printStackTrace(); + } + } + + return success; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean stop() { + + logger.info("STOP: " + this); + + /* stop regardless locked state */ + + synchronized(this) { + if (!this.alive) + return true; + + this.alive = false; + } + + // 1. Stop registration + + for (TopicSource source: sources) { + source.unregister(this); + } + + boolean success = this.droolsController.stop(); + return success; + } + + /** + * {@inheritDoc} + */ + @Override + public void shutdown() throws IllegalStateException { + if (logger.isInfoEnabled()) + logger.info(this + "SHUTDOWN"); + + this.stop(); + + DroolsController.factory.shutdown(this.droolsController); + } + + /** + * {@inheritDoc} + */ + @Override + public void halt() throws IllegalStateException { + if (logger.isInfoEnabled()) + logger.info(this + "HALT"); + + this.stop(); + DroolsController.factory.destroy(this.droolsController); + SystemPersistence.manager.deleteController(this.name); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean onTopicEvent(Topic.CommInfrastructure commType, + String topic, String event) { + + logger.info("EVENT NOTIFICATION: " + commType + ":" + topic + ":" + event + " INTO " + this); + + if (this.locked) + return false; + + if (!this.alive) + return true; + + return this.droolsController.offer(topic, event); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean deliver(Topic.CommInfrastructure commType, + String topic, Object event) + throws IllegalArgumentException, IllegalStateException, + UnsupportedOperationException { + + logger.info("DELIVER: " + commType + ":" + topic + ":" + event + " FROM " + this); + + if (topic == null || topic.isEmpty()) + throw new IllegalArgumentException("Invalid Topic"); + + if (event == null) + throw new IllegalArgumentException("Invalid Event"); + + if (!this.isAlive()) + throw new IllegalStateException("Policy Engine is stopped"); + + if (this.isLocked()) + throw new IllegalStateException("Policy Engine is locked"); + + if (!this.topic2Sinks.containsKey(topic)) { + logger.error("UNDELIVERED: " + commType + ":" + topic + ":" + event + " FROM " + this); + throw new IllegalArgumentException + ("Unsuported topic " + topic + " for delivery"); + } + + return this.droolsController.deliver + (this.topic2Sinks.get(topic), event); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAlive() { + return this.alive; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean lock() { + logger.info("LOCK: " + this); + + synchronized(this) { + if (this.locked) + return true; + + this.locked = true; + } + + // it does not affect associated sources/sinks, they are + // autonomous entities + + return this.droolsController.lock(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean unlock() { + logger.info("UNLOCK: " + this); + + synchronized(this) { + if (!this.locked) + return true; + + this.locked = false; + } + + return this.droolsController.unlock(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLocked() { + return this.locked; + } + + /** + * {@inheritDoc} + */ + @Override + public List getTopicSources() { + return this.sources; + } + + /** + * {@inheritDoc} + */ + @Override + public List getTopicSinks() { + return this.sinks; + } + + /** + * {@inheritDoc} + */ + @Override + public DroolsController getDrools() { + return this.droolsController; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("AggregatedPolicyController [name=").append(name).append(", sources=").append(sources) + .append(", sinks=").append(sinks).append(", alive=").append(alive).append(", locked=").append(locked) + .append(", droolsController=").append(droolsController).append("]"); + return builder.toString(); + } + + /** + * {@inheritDoc} + */ + @Override + public Properties getInitializationProperties() { + return this.properties; + } + +} + diff --git a/policy-management/src/main/server-gen/bin/add-secured-participant.sh b/policy-management/src/main/server-gen/bin/add-secured-participant.sh new file mode 100644 index 00000000..d6843fee --- /dev/null +++ b/policy-management/src/main/server-gen/bin/add-secured-participant.sh @@ -0,0 +1,122 @@ +#! /bin/bash + +### +# ============LICENSE_START======================================================= +# policy-management +# ================================================================================ +# Copyright (C) 2017 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +function usage() { + echo -n "Usage: $(basename $0) " + echo -n "[(-d|--debug)] " + echo -n "(-h|--host) " + echo -n "[(-p|--port) ] " + echo -n "(-k|--key) " + echo -n "(-s|--secret) " + echo -n "(-P|--producer-key) " + echo -n "(-C|--consumer-key) " + echo "(-t|--topic) " +} + +BUS_PORT=3904 + +# command line options parsing +until [[ -z "$1" ]]; do + case $1 in + -d|--debug) set -x + ;; + -h|--host) shift + BUS_HOST=$1 + ;; + -p|--port) shift + BUS_PORT=$1 + ;; + -k|--key) shift + API_KEY=$1 + ;; + -s|--secret) shift + API_SECRET=$1 + ;; + -t|--topic) shift + TOPIC=$1 + ;; + -P|--producer-key) shift + URL_CONTEXT="producers" + PRODUCER_KEY=$1 + KEY=$1 + ;; + -C|--consumer-key) shift + URL_CONTEXT="consumers" + CONSUMER_KEY=$1 + KEY=$1 + ;; + *) usage + exit 1 + ;; + esac + shift +done + +if [[ -z ${BUS_HOST} ]]; then + echo "An UEB/DMAAP server must be provided." + echo + usage + exit 1 +fi + +if [[ -z ${API_KEY} ]]; then + echo "The API Key must be provided." + usage + exit 2 +fi + +if [[ -z ${API_SECRET} ]]; then + echo "The API Secret must be provided." + usage + exit 3 +fi + +if [[ -z ${TOPIC} ]]; then + echo "The Topic Name must be provided." + usage + exit 3 +fi + +if [[ -z ${PRODUCER_KEY} && -z ${CONSUMER_KEY} ]]; then + echo "Either the Producer or Consumer options must be provided." + usage + exit 4 +fi + +if [[ -n ${PRODUCER_KEY} && -n ${CONSUMER_KEY} ]]; then + echo "Only and only one of the Producer or Consumer options must be provided." + usage + exit 5 +fi + + +DATE=$(date) +DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) + +unset http_proxy +curl --silent -X PUT \ + --header "Accept:" \ + --header "X-CambriaDate: ${DATE}" \ + --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ + --header "Content-Type: application/json" \ + --data "{}" \ + http://${BUS_HOST}:${BUS_PORT}/topics/${TOPIC}/${URL_CONTEXT}/${KEY} diff --git a/policy-management/src/main/server-gen/bin/create-api-key.sh b/policy-management/src/main/server-gen/bin/create-api-key.sh new file mode 100644 index 00000000..ea0ec7ad --- /dev/null +++ b/policy-management/src/main/server-gen/bin/create-api-key.sh @@ -0,0 +1,76 @@ +#! /bin/bash + +### +# ============LICENSE_START======================================================= +# policy-management +# ================================================================================ +# Copyright (C) 2017 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +function usage() { + echo -n "Usage: $(basename $0) " + echo -n "[(-d|--debug)] " + echo -n "(-h|--host) " + echo -n "[(-p|--port) ] " + echo "(-e|--email) " +} + +BUS_PORT=3904 + +# command line options parsing +until [[ -z "$1" ]]; do + case $1 in + -d|--debug) set -x + ;; + -h|--host) shift + BUS_HOST=$1 + ;; + -p|--port) shift + BUS_PORT=$1 + ;; + -e|--email) shift + EMAIL=$1 + ;; + *) usage + exit 1 + ;; + esac + shift +done + +if [[ -z ${BUS_HOST} ]]; then + echo "An UEB/DMAAP server must be provided." + echo + usage + exit 1 +fi + +if [[ -z ${EMAIL} ]]; then + echo "An email address must be provided." + usage + exit 2 +fi + +REQUEST_API_KEY_BODY=$(< <(cat < " + echo -n "[(-p|--port) ] " + echo -n "(-k|--key) " + echo -n "(-s|--secret) " + echo -n "[(-P|--partition) ] " + echo -n "[(-R|--replication) ] " + echo "(-t|--topic) " + echo "" +} + +BUS_PORT=3904 +PARTITION_COUNT=1 +REPLICATION_COUNT=1 + +# command line options parsing +until [[ -z "$1" ]]; do + case $1 in + -d|--debug) set -x + ;; + -h|--host) shift + BUS_HOST=$1 + ;; + -p|--port) shift + BUS_PORT=$1 + ;; + -k|--key) shift + API_KEY=$1 + ;; + -s|--secret) shift + API_SECRET=$1 + ;; + -t|--topic) shift + TOPIC=$1 + ;; + -P|--partition-count) shift + PARTITION_COUNT=$1 + ;; + -R|--replication-count) shift + REPLICATION_COUNT=$1 + ;; + *) usage + exit 1 + ;; + esac + shift +done + +if [[ -z ${BUS_HOST} ]]; then + echo "An UEB/DMAAP server must be provided." + echo + usage + exit 1 +fi + +if [[ -z ${API_KEY} ]]; then + echo "The API Key must be provided." + usage + exit 2 +fi + +if [[ -z ${API_SECRET} ]]; then + echo "The API Secret must be provided." + usage + exit 3 +fi + +if [[ -z ${TOPIC} ]]; then + echo "The Topic Name must be provided." + usage + exit 3 +fi + +if [[ -z ${PARTITION_COUNT} ]]; then + echo "The Partition Count must be provided." + usage + exit 4 +fi + +if [[ -z ${REPLICATION_COUNT} ]]; then + echo "The Replication Count must be provided." + usage + exit 5 +fi + +REQUEST_API_KEY_BODY=$(< <(cat < nameLength )) ; then + nameLength="${#name}" + fi + if (( "${#version}" > versionLength )) ; then + versionLength="${#version}" + fi +done + +# dump out status information +function status +{ + local tmp name version status + local format="%-${nameLength}s %-${versionLength}s %s\n" + + printf "${format}" "name" "version" "status" + printf "${format}" "----" "-------" "------" + for jar in $(ls) ; do + # get file name without 'jar' suffix + tmp="${jar%\.jar}" + + # get feature name by removing the version portion + name="${tmp%%-[0-9]*}" + + # extract version portion of name + version="${tmp#${name}-}" + + # determine status + status=disabled + if [[ -e "${lib}/${jar}" ]] ; then + status=enabled + fi + printf "${format}" "${name}" "${version}" "${status}" + done +} + +case "$1" in + status) + { + # dump out status information + status + };; + + enable) + { + # enable the specified options + shift + match= + for name in "$@" ; do + # look for matches - 'file' has the full path name + file=$(ls ${opt}/"${name}"-[0-9]* 2>/dev/null) + if [[ "$?" != 0 ]] ; then + # no matching file + echo "${name}: no such option" + else + # found a match (handle multiple matches, just in case) + match=true + ln -s -f ${file} "${lib}/" + fi + done + if [[ "${match}" ]] ; then + echo + status + fi + };; + + disable) + { + # disable the specified options + shift + match= + for name in "$@" ; do + # look for matches -- 'file' has the last segment of the path name + file=$(ls "${name}"-[0-9]* 2>/dev/null) + if [[ "$?" != 0 ]] ; then + echo "${name}: no such option" + else + # found a match (handle multiple matches, just in case) + match=true + (cd ${lib} ; rm -f ${file}) + fi + done + if [[ "${match}" ]] ; then + echo + status + fi + };; + + *) + { + # print out usage information + cat >&2 <<-'EOF' + Usage: options status + Get enabled/disabled status on all options + options enable