From 1dff5ebe27cbe79de8f9d798e256d41ecccdaa8c Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 19 Dec 2018 17:48:47 +0000 Subject: Add example policy for HTTPS Added an example of how to configure HTTPS for an Apex policy. Issue-ID: POLICY-1222 Change-Id: Iea8a8accac32f6d25c64a8324e202ad5e6221c7a Signed-off-by: liamfallon --- examples/examples-decisionmaker/pom.xml | 28 +++++++++-- .../ApexConfigHealthCheckRESTClient.json | 57 +++++++++++++++++++++ .../src/main/resources/logic/HealthCheckTask.js | 26 ++++++++++ .../resources/policy/HealthCheckPolicyModel.apex | 58 ++++++++++++++++++++++ 4 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 examples/examples-decisionmaker/src/main/resources/examples/config/DecisionMaker/ApexConfigHealthCheckRESTClient.json create mode 100644 examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js create mode 100644 examples/examples-decisionmaker/src/main/resources/policy/HealthCheckPolicyModel.apex (limited to 'examples/examples-decisionmaker') diff --git a/examples/examples-decisionmaker/pom.xml b/examples/examples-decisionmaker/pom.xml index 245608ccf..1b25e20b5 100644 --- a/examples/examples-decisionmaker/pom.xml +++ b/examples/examples-decisionmaker/pom.xml @@ -30,7 +30,8 @@ Specific code for the APEX Decision Maker Example - DecisionMakerPolicyModel + DecisionMakerPolicyModel + HealthCheckPolicyModel ${project.basedir}/src @@ -50,7 +51,7 @@ exec-maven-plugin - generate-policy + generate-decisionmaker-policy compile java @@ -59,9 +60,26 @@ org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain compile - --command-file=${project.basedir}/src/main/resources/policy/${policymodel.name}.apex - --output-model-file=${project.build.directory}/classes/${policymodel.name}.json - --log-file=${project.build.directory}/${policymodel.name}_policygeneration.log + --command-file=${project.basedir}/src/main/resources/policy/${policymodel.decisionmaker.name}.apex + --output-model-file=${project.build.directory}/classes/${policymodel.decisionmaker.name}.json + --log-file=${project.build.directory}/${policymodel.decisionmaker.name}_policygeneration.log + --working-dir=${project.basedir} + + + + + generate-healthcheck-policy + compile + + java + + + org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain + compile + + --command-file=${project.basedir}/src/main/resources/policy/${policymodel.healthcheck.name}.apex + --output-model-file=${project.build.directory}/classes/${policymodel.healthcheck.name}.json + --log-file=${project.build.directory}/${policymodel.healthcheck.name}_policygeneration.log --working-dir=${project.basedir} diff --git a/examples/examples-decisionmaker/src/main/resources/examples/config/DecisionMaker/ApexConfigHealthCheckRESTClient.json b/examples/examples-decisionmaker/src/main/resources/examples/config/DecisionMaker/ApexConfigHealthCheckRESTClient.json new file mode 100644 index 000000000..ec7391afe --- /dev/null +++ b/examples/examples-decisionmaker/src/main/resources/examples/config/DecisionMaker/ApexConfigHealthCheckRESTClient.json @@ -0,0 +1,57 @@ +{ + "javaProperties" : [ + ["javax.net.ssl.trustStore", "/home/liam/tmp/distribution/etc/ssl/policy-truststore"], + ["javax.net.ssl.trustStorePassword", "UG9sMWN5XzBuYXA="] + ], + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12345, + "policyModelFileName": "/home/liam/git/onap/policy/apex-pdp/examples/examples-decisionmaker/target/classes/HealthCheckPolicyModel.json", + "engineParameters": { + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "HealthCheckConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "https://policy:6969/healthcheck", + "httpHeaders" : [ + ["Authorization", "Basic aGVhbHRoY2hlY2s6emIhWHp0RzM0"] + ] + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "nameAlias": "none", + "versionAlias": "version", + "sourceAlias": "from" + } + }, + "eventName": "HealthCheckEvent" + } + }, + "eventOutputParameters": { + "logProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "/tmp/EventsOut.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + } +} diff --git a/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js b/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js new file mode 100644 index 000000000..ebc0e6387 --- /dev/null +++ b/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js @@ -0,0 +1,26 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-decisionmaker/src/main/resources/policy/HealthCheckPolicyModel.apex b/examples/examples-decisionmaker/src/main/resources/policy/HealthCheckPolicyModel.apex new file mode 100644 index 000000000..c799a8f37 --- /dev/null +++ b/examples/examples-decisionmaker/src/main/resources/policy/HealthCheckPolicyModel.apex @@ -0,0 +1,58 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +model create name=HealthCheckPolicyModel + +schema create name=SimpleStringType flavour=Java schema=java.lang.String +schema create name=SimpleIntegerType flavour=Java schema=java.lang.Integer +schema create name=SimpleBooleanType flavour=Java schema=java.lang.Boolean + +event create name=HealthCheckEvent nameSpace=org.onap.policy.apex.domains.HealthCheck source=Distribution target=Apex +event parameter create name=HealthCheckEvent parName=name schemaName=SimpleStringType +event parameter create name=HealthCheckEvent parName=url schemaName=SimpleStringType +event parameter create name=HealthCheckEvent parName=healthy schemaName=SimpleBooleanType +event parameter create name=HealthCheckEvent parName=code schemaName=SimpleIntegerType +event parameter create name=HealthCheckEvent parName=message schemaName=SimpleStringType + +task create name=HealthCheckTask +task inputfield create name=HealthCheckTask fieldName=name schemaName=SimpleStringType +task inputfield create name=HealthCheckTask fieldName=url schemaName=SimpleStringType +task inputfield create name=HealthCheckTask fieldName=healthy schemaName=SimpleBooleanType +task inputfield create name=HealthCheckTask fieldName=code schemaName=SimpleIntegerType +task inputfield create name=HealthCheckTask fieldName=message schemaName=SimpleStringType + +task outputfield create name=HealthCheckTask fieldName=name schemaName=SimpleStringType +task outputfield create name=HealthCheckTask fieldName=url schemaName=SimpleStringType +task outputfield create name=HealthCheckTask fieldName=healthy schemaName=SimpleBooleanType +task outputfield create name=HealthCheckTask fieldName=code schemaName=SimpleIntegerType +task outputfield create name=HealthCheckTask fieldName=message schemaName=SimpleStringType + +task logic create name=HealthCheckTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/HealthCheckTask.js" +LE + +policy create name=HealthCheckPolicy template=freestyle firstState=HealthCheckState + +policy state create name=HealthCheckPolicy stateName=HealthCheckState triggerName=HealthCheckEvent defaultTaskName=HealthCheckTask +policy state output create name=HealthCheckPolicy stateName=HealthCheckState outputName=HealthCheckOutput eventName=HealthCheckEvent +policy state taskref create name=HealthCheckPolicy stateName=HealthCheckState taskName=HealthCheckTask outputType=DIRECT outputName=HealthCheckOutput + +validate + -- cgit 1.2.3-korg