diff --git a/deployment/apex-gui.yaml b/deployment/apex-gui.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d96e9db150c8fc59d7b125819c69aef1a272e9ab --- /dev/null +++ b/deployment/apex-gui.yaml @@ -0,0 +1,55 @@ +--- +kind: Service +apiVersion: v1 +metadata: + name: apex-gui +spec: + selector: + app: apex + ports: + - name: ssh + protocol: "TCP" + # Port accessible inside cluster + port: 4122 + # Port to forward to inside the pod + targetPort: ssh-port + # Port accessible outside cluster + nodePort: 30100 + - name: tcp + protocol: "TCP" + # Port accessible inside cluster + port: 4171 + # Port to forward to inside the pod + targetPort: tcp-port + # Port accessible outside cluster + nodePort: 30101 + type: NodePort #LoadBalancer +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: apex-gui + labels: + app: apex-gui +spec: + selector: + matchLabels: + app: apex-gui + replicas: 1 + template: + metadata: + labels: + app: apex-gui + spec: + containers: + - name: ubuntu + image: gitlab-registry.eps.surrey.ac.uk/noc/ubuntu:ping + command: ["sh", "-c", "while true; do sleep 3600; done"] + ports: + - name: ssh-port + containerPort: 22 + - name: tcp-port + containerPort: 71 + imagePullPolicy: IfNotPresent + restartPolicy: Always + diff --git a/deployment/customisation/Dockerfile b/deployment/customisation/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..b1a8d6408d5d15ab540649badf1a65694de11779 --- /dev/null +++ b/deployment/customisation/Dockerfile @@ -0,0 +1,33 @@ +FROM gitlab-registry.eps.surrey.ac.uk/noc/apex:2.5.3 +WORKDIR /apex + +USER root +COPY ./policy-apex/* ./policy-apex/ +RUN mkdir -p policy-json +#COPY ./policy-json/* ./policy-json/ +COPY ./logic/* ./logic/ +COPY ./config/* ./config/ +COPY ./logs/logback.xml /opt/app/policy/apex-pdp/etc/ +COPY ./tosca-template/* ./tosca-template/ + +COPY ./scripts/* ./ +RUN chmod +x ./start.sh +# Add bash shell +RUN apk update +RUN apk upgrade +RUN apk add bash +RUN apk add bash-completion +RUN apk add nano +RUN apk add yajl-tools + +# Customise PS1 +RUN touch /root/.bashrc +RUN echo "[ -z \"\$PS1\" ] && return">> /root/.bashrc +RUN echo "PS1=\"\\[\\033[35m\\][\\u@\\h \\w]:\\[\\033[37m\\]\"">>/root/.bashrc + +EXPOSE 12345 18989 23324 8080 + +RUN apexCLIToscaEditor.sh -c policy-apex/Policy.apex -ot policy-json/Policy.json -l ./test.log -ac config/config.json -t ./tosca-template/ToscaTemplate.json +CMD ["./start.sh"] + +#CMD ["./startTest.sh"] diff --git a/deployment/customisation/config/config.json b/deployment/customisation/config/config.json new file mode 100644 index 0000000000000000000000000000000000000000..ef26c691f8f2c94c83c6add7d22ce49480756be2 --- /dev/null +++ b/deployment/customisation/config/config.json @@ -0,0 +1,61 @@ +{ + "engineServiceParameters": { + "name": "APEX-Engine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12345, + "policyModelFileName": "policy-json/Policy.json", + "engineParameters": { + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "RestServerConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTSERVER", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restserver.RestServerCarrierTechnologyParameters", + "parameters": { + "standalone": true, + "host": "0.0.0.0", + "port": 23324 + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "synchronousMode": true, + "synchronousPeer": "RestServerProducer", + "synchronousTimeout": 1000 + } + }, + "eventOutputParameters": { + "IOProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "standardIo": true + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "RestServerProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTSERVER", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restserver.RestServerCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "synchronousMode": true, + "synchronousPeer": "RestServerConsumer", + "synchronousTimeout": 1000 + } + } +} diff --git a/deployment/customisation/events/Example_Event.json b/deployment/customisation/events/Example_Event.json new file mode 100644 index 0000000000000000000000000000000000000000..ef38f0ffdebb29f1aff4562aea43fb9471ce0c4c --- /dev/null +++ b/deployment/customisation/events/Example_Event.json @@ -0,0 +1,8 @@ +{ + "name": "Example_Event_Input", + "version": "0.0.1", + "nameSpace": "example.apex.event", + "source": "external", + "target": "apex", + "input": "Hello World" +} \ No newline at end of file diff --git a/deployment/customisation/logic/Example_TL.js b/deployment/customisation/logic/Example_TL.js new file mode 100644 index 0000000000000000000000000000000000000000..201fdb0756f61897343e8bade3b4ea2486f21ae1 --- /dev/null +++ b/deployment/customisation/logic/Example_TL.js @@ -0,0 +1,20 @@ +var logger = executor.logger; +var time = new Date(); + +logger.info("##START## Example_TL"); + +var input = executor.inFields.get("input"); +logger.info("~~input: " + input); + +executor.getContextAlbum("Context_Album").put(input, time.toString()); +logger.info("~~Time of input stored: " + time + " in Context_Album"); + +var contextAlbumData = executor.getContextAlbum("Context_Album").get(input); +logger.info("~~Grab time from Context Album"); + +executor.outFields.put("output", contextAlbumData); + +logger.info("##END## Example_TL"); + +var returnValue = true; +returnValue; diff --git a/deployment/customisation/logs/logback.xml b/deployment/customisation/logs/logback.xml new file mode 100644 index 0000000000000000000000000000000000000000..83261220c99d66110c6788dc4d74bac0a87a166c --- /dev/null +++ b/deployment/customisation/logs/logback.xml @@ -0,0 +1,103 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2020 Bell Canada. 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========================================================= +--> + +<configuration scan="true" scanPeriod="30 seconds" debug="false"> + + <appender name="ErrorOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>/var/log/onap/policy/apex-pdp/error.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> + <fileNamePattern>/var/log/onap/policy/apex-pdp/error.%d{yyyy-MM-dd}.%i.log.zip + </fileNamePattern> + <maxFileSize>50MB</maxFileSize> + <maxHistory>30</maxHistory> + <totalSizeCap>10GB</totalSizeCap> + </rollingPolicy> + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> + <level>WARN</level> + </filter> + <encoder> + <pattern>[%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%level|%logger{0}|%thread] %msg%n</pattern> + </encoder> + </appender> + + <appender name="AsyncErrorOut" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="ErrorOut" /> + </appender> + + <appender name="DebugOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>/var/log/onap/policy/apex-pdp/debug.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> + <fileNamePattern>/var/log/onap/policy/apex-pdp/debug.%d{yyyy-MM-dd}.%i.log.zip + </fileNamePattern> + <maxFileSize>50MB</maxFileSize> + <maxHistory>30</maxHistory> + <totalSizeCap>10GB</totalSizeCap> + </rollingPolicy> + <encoder> + <pattern>[%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%level|%logger{0}|%thread] %msg%n</pattern> + </encoder> + </appender> + + <appender name="AsyncDebugOut" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="DebugOut" /> + </appender> + + <appender name="NetworkOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>/var/log/onap/policy/apex-pdp/network.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> + <fileNamePattern>/var/log/onap/policy/apex-pdp/network.%d{yyyy-MM-dd}.%i.log.zip + </fileNamePattern> + <maxFileSize>50MB</maxFileSize> + <maxHistory>30</maxHistory> + <totalSizeCap>10GB</totalSizeCap> + </rollingPolicy> + <encoder> + <pattern>[%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%t]%m%n</pattern> + </encoder> + </appender> + + <appender name="AsyncNetworkOut" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="NetworkOut" /> + </appender> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> + </encoder> + </appender> + + <appender name="AsyncStdOut" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="STDOUT" /> + </appender> + + <logger name="network" level="INFO" additivity="false"> + <appender-ref ref="AsyncNetworkOut" /> + <appender-ref ref="AsyncStdOut" /> + </logger> + + <logger name="org.eclipse.jetty.server.RequestLog" level="info" additivity="false"> + <appender-ref ref="AsyncNetworkOut" /> + <appender-ref ref="AsyncStdOut" /> + </logger> + + <root level="INFO"> + <appender-ref ref="AsyncDebugOut" /> + <appender-ref ref="AsyncErrorOut" /> + <appender-ref ref="AsyncStdOut" /> + </root> + +</configuration> \ No newline at end of file diff --git a/deployment/customisation/policy-apex/MorningBoozeCheck.js b/deployment/customisation/policy-apex/MorningBoozeCheck.js new file mode 100644 index 0000000000000000000000000000000000000000..ff7cf30cb983173a2832c3b4bd6df4b2a7f1ecba --- /dev/null +++ b/deployment/customisation/policy-apex/MorningBoozeCheck.js @@ -0,0 +1,74 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'"); + +executor.outFields.put("amount" , executor.inFields.get("amount")); +executor.outFields.put("assistant_ID", executor.inFields.get("assistant_ID")); +executor.outFields.put("notes" , executor.inFields.get("notes")); +executor.outFields.put("quantity" , executor.inFields.get("quantity")); +executor.outFields.put("branch_ID" , executor.inFields.get("branch_ID")); +executor.outFields.put("item_ID" , executor.inFields.get("item_ID")); +executor.outFields.put("time" , executor.inFields.get("time")); +executor.outFields.put("sale_ID" , executor.inFields.get("sale_ID")); + +item_id = executor.inFields.get("item_ID"); + +//All times in this script are in GMT/UTC since the policy and events assume time is in GMT. +var timenow_gmt = new Date(Number(executor.inFields.get("time"))); + +var midnight_gmt = new Date(Number(executor.inFields.get("time"))); +midnight_gmt.setUTCHours(0,0,0,0); + +var eleven30_gmt = new Date(Number(executor.inFields.get("time"))); +eleven30_gmt.setUTCHours(11,30,0,0); + +var timeformatter = new java.text.SimpleDateFormat("HH:mm:ss z"); + +var itemisalcohol = false; +if(item_id != null && item_id >=1000 && item_id < 2000) + itemisalcohol = true; + +if( itemisalcohol + && timenow_gmt.getTime() >= midnight_gmt.getTime() + && timenow_gmt.getTime() < eleven30_gmt.getTime()) { + + executor.outFields.put("authorised", false); + executor.outFields.put("message", "Sale not authorised by policy task " + + executor.subject.taskName+ " for time " + timeformatter.format(timenow_gmt.getTime()) + + ". Alcohol can not be sold between " + timeformatter.format(midnight_gmt.getTime()) + + " and " + timeformatter.format(eleven30_gmt.getTime())); +} +else{ + executor.outFields.put("authorised", true); + executor.outFields.put("message", "Sale authorised by policy task " + + executor.subject.taskName + " for time "+timeformatter.format(timenow_gmt.getTime())); +} + +/* +This task checks if a sale request is for an item that is an alcoholic drink. +If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not +authorised. Otherwise the sale is authorised. +In this implementation we assume that items with item_ID value between 1000 and +2000 are all alcoholic drinks :-) +*/ + +true; diff --git a/deployment/customisation/policy-apex/MorningBoozeCheck.mvel b/deployment/customisation/policy-apex/MorningBoozeCheck.mvel new file mode 100644 index 0000000000000000000000000000000000000000..3bcf3689a14a843a0231c84028f864742bba55a3 --- /dev/null +++ b/deployment/customisation/policy-apex/MorningBoozeCheck.mvel @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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========================================================= + */ +import java.util.Date; +import java.util.Calendar; +import java.util.TimeZone; +import java.text.SimpleDateFormat; + +logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'"); + +outFields.put("amount" , inFields.get("amount")); +outFields.put("assistant_ID", inFields.get("assistant_ID")); +outFields.put("notes" , inFields.get("notes")); +outFields.put("quantity" , inFields.get("quantity")); +outFields.put("branch_ID" , inFields.get("branch_ID")); +outFields.put("item_ID" , inFields.get("item_ID")); +outFields.put("time" , inFields.get("time")); +outFields.put("sale_ID" , inFields.get("sale_ID")); + +item_id = inFields.get("item_ID"); + +//The events used later to test this task use GMT timezone! +gmt = TimeZone.getTimeZone("GMT"); +timenow = Calendar.getInstance(gmt); +df = new SimpleDateFormat("HH:mm:ss z"); +df.setTimeZone(gmt); +timenow.setTimeInMillis(inFields.get("time")); + +midnight = timenow.clone(); +midnight.set( + timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH), + timenow.get(Calendar.DATE),0,0,0); +eleven30 = timenow.clone(); +eleven30.set( + timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH), + timenow.get(Calendar.DATE),11,30,0); + +itemisalcohol = false; +if(item_id != null && item_id >=1000 && item_id < 2000) + itemisalcohol = true; + +if( itemisalcohol + && timenow.after(midnight) && timenow.before(eleven30)){ + outFields.put("authorised", false); + outFields.put("message", "Sale not authorised by policy task "+subject.taskName+ + " for time "+df.format(timenow.getTime())+ + ". Alcohol can not be sold between "+df.format(midnight.getTime())+ + " and "+df.format(eleven30.getTime())); + return true; +} +else{ + outFields.put("authorised", true); + outFields.put("message", "Sale authorised by policy task "+subject.taskName+ + " for time "+df.format(timenow.getTime())); + return true; +} + +/* +This task checks if a sale request is for an item that is an alcoholic drink. +If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not +authorised. Otherwise the sale is authorised. +In this implementation we assume that items with item_ID value between 1000 and +2000 are all alcoholic drinks :-) +*/ diff --git a/deployment/customisation/policy-apex/MyFirstPolicyModelJavascript_0.0.1.apex b/deployment/customisation/policy-apex/MyFirstPolicyModelJavascript_0.0.1.apex new file mode 100644 index 0000000000000000000000000000000000000000..68a7d31541a12440d96bc681579518a026db754e --- /dev/null +++ b/deployment/customisation/policy-apex/MyFirstPolicyModelJavascript_0.0.1.apex @@ -0,0 +1,97 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. All rights reserved. +# Modifications Copyright (C) 2020 Nordix Foundation. +# ================================================================================ +# 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=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model." + +schema create name=assistant_ID_type version=0.0.1 uuid=36df4c71-9616-4206-8b53-976a5cd4bd87 description="A type for 'assistant_ID' values" flavour=Java schema=java.lang.Long + +schema create name=authorised_type version=0.0.1 uuid=d48b619e-d00d-4008-b884-02d76ea4350b description="A type for 'authorised' values" flavour=Java schema=java.lang.Boolean + +schema create name=branch_ID_type version=0.0.1 uuid=6468845f-4122-4128-8e49-0f52c26078b5 description="A type for 'branch_ID' values" flavour=Java schema=java.lang.Long + +schema create name=item_ID_type version=0.0.1 uuid=4f227ff1-aee0-453a-b6b6-9a4b2e0da932 description="A type for 'item_ID' values" flavour=Java schema=java.lang.Long + +schema create name=message_type version=0.0.1 uuid=ad1431bb-3155-4e73-b5a3-b89bee498749 description="A type for 'message' values" flavour=Java schema=java.lang.String + +schema create name=notes_type version=0.0.1 uuid=eecfde90-896c-4343-8f9c-2603ced94e2d description="A type for 'notes' values" flavour=Java schema=java.lang.String + +schema create name=price_type version=0.0.1 uuid=52c2fc45-fd8c-463c-bd6f-d91b0554aea7 description="A type for 'amount'/'price' values" flavour=Java schema=java.lang.Long + +schema create name=quantity_type version=0.0.1 uuid=ac3d9842-80af-4a98-951c-bd79a431c613 description="A type for 'quantity' values" flavour=Java schema=java.lang.Integer + +schema create name=sale_ID_type version=0.0.1 uuid=cca47d74-7754-4a61-b163-ca31f66b157b description="A type for 'sale_ID' values" flavour=Java schema=java.lang.Long + +schema create name=timestamp_type version=0.0.1 uuid=fd594e88-411d-4a94-b2be-697b3a0d7adf description="A type for 'time' values" flavour=Java schema=java.lang.Long + +task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS +This task checks if the sales request is for an item that contains alcohol. +If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised. +In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-) +LE +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true + +task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"policy-apex/MorningBoozeCheck.js" +LE + +event create name=SALE_AUTH version=0.0.1 uuid=c4500941-3f98-4080-a9cc-5b9753ed050b description="An event emitted by the Policy to indicate whether the sale of an item has been authorised" nameSpace=com.hyperm source="APEX" target="POS" +event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true +event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true +event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1 + +event create name=SALE_INPUT version=0.0.1 uuid=4f04aa98-e917-4f4a-882a-c75ba5a99374 description="An event raised by the PoS system each time an item is scanned for purchase" nameSpace=com.hyperm source="POS" target="APEX" +event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true +event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1 + +policy create name=MyFirstPolicy version=0.0.1 uuid=6c5e410f-489a-46ff-964e-982ce6e8b6d0 description="This is my first Apex policy. It checks if a sale should be authorised or not." template=FREEFORM firstState=BoozeAuthDecide +policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1 +policy state output create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide outputName=MorningBoozeCheck_Output_Direct eventName=SALE_AUTH eventVersion=0.0.1 nextState=NULL +policy state taskref create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide taskLocalName=MorningBoozeCheck taskName=MorningBoozeCheck taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct diff --git a/deployment/customisation/policy-apex/MyFirstPolicyModelMvel_0.0.1.apex b/deployment/customisation/policy-apex/MyFirstPolicyModelMvel_0.0.1.apex new file mode 100644 index 0000000000000000000000000000000000000000..3ba2342100ba4be18e81fdab9db5d3d648945242 --- /dev/null +++ b/deployment/customisation/policy-apex/MyFirstPolicyModelMvel_0.0.1.apex @@ -0,0 +1,97 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. All rights reserved. +# Modifications Copyright (C) 2020 Nordix Foundation. +# ================================================================================ +# 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=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model." + +schema create name=assistant_ID_type version=0.0.1 uuid=36df4c71-9616-4206-8b53-976a5cd4bd87 description="A type for 'assistant_ID' values" flavour=Java schema=java.lang.Long + +schema create name=authorised_type version=0.0.1 uuid=d48b619e-d00d-4008-b884-02d76ea4350b description="A type for 'authorised' values" flavour=Java schema=java.lang.Boolean + +schema create name=branch_ID_type version=0.0.1 uuid=6468845f-4122-4128-8e49-0f52c26078b5 description="A type for 'branch_ID' values" flavour=Java schema=java.lang.Long + +schema create name=item_ID_type version=0.0.1 uuid=4f227ff1-aee0-453a-b6b6-9a4b2e0da932 description="A type for 'item_ID' values" flavour=Java schema=java.lang.Long + +schema create name=message_type version=0.0.1 uuid=ad1431bb-3155-4e73-b5a3-b89bee498749 description="A type for 'message' values" flavour=Java schema=java.lang.String + +schema create name=notes_type version=0.0.1 uuid=eecfde90-896c-4343-8f9c-2603ced94e2d description="A type for 'notes' values" flavour=Java schema=java.lang.String + +schema create name=price_type version=0.0.1 uuid=52c2fc45-fd8c-463c-bd6f-d91b0554aea7 description="A type for 'amount'/'price' values" flavour=Java schema=java.lang.Long + +schema create name=quantity_type version=0.0.1 uuid=ac3d9842-80af-4a98-951c-bd79a431c613 description="A type for 'quantity' values" flavour=Java schema=java.lang.Integer + +schema create name=sale_ID_type version=0.0.1 uuid=cca47d74-7754-4a61-b163-ca31f66b157b description="A type for 'sale_ID' values" flavour=Java schema=java.lang.Long + +schema create name=timestamp_type version=0.0.1 uuid=fd594e88-411d-4a94-b2be-697b3a0d7adf description="A type for 'time' values" flavour=Java schema=java.lang.Long + +task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS +This task checks if the sales request is for an item that contains alcohol. +If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised. +In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-) +LE +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1 +task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1 +task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true + +task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS +#MACROFILE:"policy-apex/MorningBoozeCheck.mvel" +LE + +event create name=SALE_AUTH version=0.0.1 uuid=c4500941-3f98-4080-a9cc-5b9753ed050b description="An event emitted by the Policy to indicate whether the sale of an item has been authorised" nameSpace=com.hyperm source="APEX" target="POS" +event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true +event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true +event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1 + +event create name=SALE_INPUT version=0.0.1 uuid=4f04aa98-e917-4f4a-882a-c75ba5a99374 description="An event raised by the PoS system each time an item is scanned for purchase" nameSpace=com.hyperm source="POS" target="APEX" +event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true +event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1 +event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1 + +policy create name=MyFirstPolicy version=0.0.1 uuid=6c5e410f-489a-46ff-964e-982ce6e8b6d0 description="This is my first Apex policy. It checks if a sale should be authorised or not." template=FREEFORM firstState=BoozeAuthDecide +policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1 +policy state output create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide outputName=MorningBoozeCheck_Output_Direct eventName=SALE_AUTH eventVersion=0.0.1 nextState=NULL +policy state taskref create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide taskLocalName=MorningBoozeCheck taskName=MorningBoozeCheck taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct diff --git a/deployment/customisation/policy-apex/Policy.apex b/deployment/customisation/policy-apex/Policy.apex new file mode 100644 index 0000000000000000000000000000000000000000..c535d4c990cb39d0d00723d2f9ea7a10ec94758a --- /dev/null +++ b/deployment/customisation/policy-apex/Policy.apex @@ -0,0 +1,51 @@ + +#---------------------------------------------------------------------------------------------------------------------------------------------------------------- + +model create name=Test_Policy_Model + +#---------------------------------------------------------------------------------------------------------------------------------------------------------------- + +##-- Primitive Types --## + +schema create name=String_Type flavour=Java schema=java.lang.String + +#---------------------------------------------------------------------------------------------------------------------------------------------------------------- + +##-- Events --## + +event create name=Example_Event_Input nameSpace=example.apex.event source="external" target="apex" +event parameter create name=Example_Event_Input parName=input schemaName=String_Type + +event create name=Example_Event_Output +event parameter create name=Example_Event_Output parName=output schemaName=String_Type + +#---------------------------------------------------------------------------------------------------------------------------------------------------------------- + +##-- Albums --## +album create name=Context_Album scope=GLOBAL writable=true schemaName=String_Type + +#---------------------------------------------------------------------------------------------------------------------------------------------------------------- + +##-- TASKS --## + +task create name=Example_Task +task inputfield create name=Example_Task fieldName=input schemaName=String_Type +task outputfield create name=Example_Task fieldName=output schemaName=String_Type +task contextref create name=Example_Task albumName=Context_Album +task logic create name=Example_Task logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"logic/Example_TL.js" +LE + +#---------------------------------------------------------------------------------------------------------------------------------------------------------------- + +##-- POLICIES --## + +policy create name=Example_Policy template=FREEFORM firstState=Example_State + +policy state create name=Example_Policy stateName=Example_State triggerName=Example_Event_Input defaultTaskName=Example_Task + +policy state output create name=Example_Policy stateName=Example_State outputName=example_output eventName=Example_Event_Output + +policy state taskref create name=Example_Policy stateName=Example_State taskName=Example_Task outputType=DIRECT outputName=example_output + +#------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/deployment/customisation/run.bat b/deployment/customisation/run.bat new file mode 100644 index 0000000000000000000000000000000000000000..f2a597aa5ca68357d4b642610779ed4d14c2549b --- /dev/null +++ b/deployment/customisation/run.bat @@ -0,0 +1,5 @@ +docker build --no-cache -t myapex . + +docker run -it -p 23324:23324 --name apex-engine --rm myapex + +pause diff --git a/deployment/customisation/scripts/start.sh b/deployment/customisation/scripts/start.sh new file mode 100644 index 0000000000000000000000000000000000000000..ee4b62285759688f52302385894d6b675d4b50a3 --- /dev/null +++ b/deployment/customisation/scripts/start.sh @@ -0,0 +1,2 @@ + #!/bin/bash + apexApps.sh engine -p policy-json/Policy.json \ No newline at end of file diff --git a/deployment/customisation/scripts/startTest.sh b/deployment/customisation/scripts/startTest.sh new file mode 100644 index 0000000000000000000000000000000000000000..25a0592c20ee19cf8c9566e3441b269700a253d3 --- /dev/null +++ b/deployment/customisation/scripts/startTest.sh @@ -0,0 +1,2 @@ + #!/bin/bash +apexCLIEditor.sh -c ./policy-apex/Policy.apex -o ./examples/policy-json/Policy.json \ No newline at end of file diff --git a/deployment/customisation/tosca-template/ToscaTemplate.json b/deployment/customisation/tosca-template/ToscaTemplate.json new file mode 100644 index 0000000000000000000000000000000000000000..87f0047351d31c611b35824e6877fc5da9d04bf5 --- /dev/null +++ b/deployment/customisation/tosca-template/ToscaTemplate.json @@ -0,0 +1,17 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "topology_template": { + "policies": [ + { + "native.sampledomain": { + "type": "onap.policies.native.Apex", + "type_version": "1.0.0", + "name": "native.sampledomain", + "version": "1.0.0", + "properties": { + } + } + } + ] + } +} \ No newline at end of file diff --git a/deployment/noc-apex.yaml b/deployment/noc-apex.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3c3ea5d690a5fc5a500a5e82d16d95aeaa9e4b4e --- /dev/null +++ b/deployment/noc-apex.yaml @@ -0,0 +1,77 @@ +--- +kind: Service +apiVersion: v1 +metadata: + name: noc-apex-svc +spec: + selector: + app: noc-apex + ports: + - name: ui + protocol: "TCP" + # Port accessible inside cluster + port: 8080 + # Port to forward to inside the pod + targetPort: http + # Port accessible outside cluster + nodePort: 30080 + - name: tcp-1 + protocol: "TCP" + # Port accessible inside cluster + port: 12345 + # Port to forward to inside the pod + targetPort: tcp1 + # Port accessible outside cluster + nodePort: 32345 + - name: tcp-2 + protocol: "TCP" + # Port accessible inside cluster + port: 18989 + # Port to forward to inside the pod + targetPort: tcp2 + # Port accessible outside cluster + nodePort: 28989 + - name: tcp-3 + protocol: "TCP" + # Port accessible inside cluster + port: 23324 + # Port to forward to inside the pod + targetPort: tcp3 + # Port accessible outside cluster + nodePort: 23324 + type: NodePort #LoadBalancer +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: noc-apex + labels: + app: noc-apex +spec: + selector: + matchLabels: + app: noc-apex + replicas: 1 + template: + metadata: + labels: + app: noc-apex + spec: + containers: + - name: noc-apex + image: gitlab-registry.eps.surrey.ac.uk/noc/apex:2.5.3b-noc + #command: ["sh", "-c", "while true; do sleep 3600; done"] + command: ["sh", "-c", "/apex/start.sh"] + ports: + - name: http + containerPort: 8080 + - name: tcp1 + containerPort: 12345 + - name: tcp2 + containerPort: 18989 + - name: tcp3 + containerPort: 23324 + imagePullPolicy: IfNotPresent + restartPolicy: Always +