diff options
103 files changed, 15689 insertions, 436 deletions
diff --git a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CGCliEditor.java b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CGCliEditor.java index ca41e5f5f..30e883aae 100644 --- a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CGCliEditor.java +++ b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CGCliEditor.java @@ -20,6 +20,60 @@ package org.onap.policy.apex.auth.clicodegen; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.ALBUM_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.ALBUM_VERSION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.CONTEXT_REFS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.CTX_REFS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.DECLARATION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.DEFAULT_TASK; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.DEFAULT_TASK_VERSION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.DEFAULT_VALUE; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.DEFINITIONS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.DESCRIPTION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.EVENT_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.EVENT_VERSION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.FIELDS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.FIELD_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.FIELD_SCHEMA; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.FIELD_SCHEMA_VERSION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.FINALIZER_LOGICS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.FINALIZER_LOGIC_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.FIRST_STATE; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.FLAVOUR; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.INFIELDS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.LOGIC; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.LOGIC_FLAVOUR; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.NAME_SPACE; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.NEXT_STATE; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.OPTIONAL; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.OUTFIELDS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.OUTPUTS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.OUTPUT_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.OUTPUT_TYPE; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.PARAMS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.PAR_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.POLICY_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.SCHEMA; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.SCHEMA_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.SCHEMA_VERSION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.SCOPE; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.SOURCE; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.STATES; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.STATE_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.TARGET; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.TASKS; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.TASK_LOCAL_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.TASK_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.TASK_VERSION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.TEMPLATE; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.TRIGGER_NAME; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.TRIGGER_VERSION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.TS_LOGIC; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.UUID; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.VERSION; +import static org.onap.policy.apex.auth.clicodegen.CliEditorContants.WRITABLE; + import java.util.List; import org.stringtemplate.v4.ST; @@ -31,6 +85,7 @@ import org.stringtemplate.v4.STGroupFile; * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ public class CGCliEditor { + // CHECKSTYLE:OFF: ParameterNumber /** The name of the STG file for the code generator. */ @@ -70,10 +125,10 @@ public class CGCliEditor { throw new IllegalArgumentException("model description should not be blank"); } - model.add("name", name); - model.add("version", version); - model.add("uuid", uuid); - model.add("description", description); + model.add(NAME, name); + model.add(VERSION, version); + model.add(UUID, uuid); + model.add(DESCRIPTION, description); } /** @@ -109,13 +164,13 @@ public class CGCliEditor { public void addSchemaDeclaration(final String name, final String version, final String uuid, final String description, final String flavour, final String schema) { final ST st = stg.getInstanceOf("schemaDecl"); - st.add("name", name); - st.add("version", version); - st.add("uuid", uuid); - st.add("description", description); - st.add("flavour", flavour); - st.add("schema", schema); - model.add("declarations", st); + st.add(NAME, name); + st.add(VERSION, version); + st.add(UUID, uuid); + st.add(DESCRIPTION, description); + st.add(FLAVOUR, flavour); + st.add(SCHEMA, schema); + model.add(DECLARATION, st); } /** @@ -134,15 +189,15 @@ public class CGCliEditor { final String description, final String scope, final boolean writable, final String schemaName, final String schemaVersion) { final ST st = stg.getInstanceOf("ctxAlbumDecl"); - st.add("name", name); - st.add("version", version); - st.add("uuid", uuid); - st.add("description", description); - st.add("scope", scope); - st.add("writable", writable); - st.add("schemaName", schemaName); - st.add("schemaVersion", schemaVersion); - model.add("declarations", st); + st.add(NAME, name); + st.add(VERSION, version); + st.add(UUID, uuid); + st.add(DESCRIPTION, description); + st.add(SCOPE, scope); + st.add(WRITABLE, writable); + st.add(SCHEMA_NAME, schemaName); + st.add(SCHEMA_VERSION, schemaVersion); + model.add(DECLARATION, st); } /** @@ -159,12 +214,12 @@ public class CGCliEditor { public ST createEventFieldDefinition(final String eventName, final String version, final String fieldName, final String fieldSchema, final String fieldSchemaVersion, final boolean optional) { final ST st = stg.getInstanceOf("eventDefField"); - st.add("eventName", eventName); - st.add("version", version); - st.add("fieldName", fieldName); - st.add("fieldSchema", fieldSchema); - st.add("fieldSchemaVersion", fieldSchemaVersion); - st.add("optional", optional); + st.add(EVENT_NAME, eventName); + st.add(VERSION, version); + st.add(FIELD_NAME, fieldName); + st.add(FIELD_SCHEMA, fieldSchema); + st.add(FIELD_SCHEMA_VERSION, fieldSchemaVersion); + st.add(OPTIONAL, optional); return st; } @@ -181,10 +236,10 @@ public class CGCliEditor { public ST createTaskDefLogic(final String taskName, final String version, final String flavour, final String logic) { final ST st = stg.getInstanceOf("taskDefLogic"); - st.add("taskName", taskName); - st.add("version", version); - st.add("flavour", flavour); - st.add("logic", logic); + st.add(TASK_NAME, taskName); + st.add(VERSION, version); + st.add(FLAVOUR, flavour); + st.add(LOGIC, logic); return st; } @@ -204,21 +259,21 @@ public class CGCliEditor { final String description, final String nameSpace, final String source, final String target, final List<ST> fields) { final ST st = stg.getInstanceOf("eventDecl"); - st.add("name", name); - st.add("version", version); - st.add("uuid", uuid); - st.add("description", description); - st.add("source", source); - st.add("target", target); - st.add("fields", fields); + st.add(NAME, name); + st.add(VERSION, version); + st.add(UUID, uuid); + st.add(DESCRIPTION, description); + st.add(SOURCE, source); + st.add(TARGET, target); + st.add(FIELDS, fields); if (nameSpace != null) { - st.add("nameSpace", nameSpace); + st.add(NAME_SPACE, nameSpace); } else if (defaultNamespace != null) { - st.add("nameSpace", defaultNamespace); + st.add(NAME_SPACE, defaultNamespace); } - model.add("declarations", st); + model.add(DECLARATION, st); } /** @@ -238,16 +293,16 @@ public class CGCliEditor { final List<ST> infields, final List<ST> outfields, final ST logic, final List<ST> parameters, final List<ST> contextRefs) { final ST st = stg.getInstanceOf("taskDecl"); - st.add("name", name); - st.add("version", version); - st.add("uuid", uuid); - st.add("description", description); - st.add("infields", infields); - st.add("outfields", outfields); - st.add("logic", logic); - st.add("parameters", parameters); - st.add("contextRefs", contextRefs); - model.add("declarations", st); + st.add(NAME, name); + st.add(VERSION, version); + st.add(UUID, uuid); + st.add(DESCRIPTION, description); + st.add(INFIELDS, infields); + st.add(OUTFIELDS, outfields); + st.add(LOGIC, logic); + st.add(PARAMS, parameters); + st.add(CONTEXT_REFS, contextRefs); + model.add(DECLARATION, st); } /** @@ -264,14 +319,14 @@ public class CGCliEditor { public void addPolicyDefinition(final String name, final String version, final String uuid, final String description, final String template, final String firstState, final List<ST> states) { final ST st = stg.getInstanceOf("policyDef"); - st.add("name", name); - st.add("version", version); - st.add("uuid", uuid); - st.add("description", description); - st.add("template", template); - st.add("firstState", firstState); - st.add("states", states); - model.add("definitions", st); + st.add(NAME, name); + st.add(VERSION, version); + st.add(UUID, uuid); + st.add(DESCRIPTION, description); + st.add(TEMPLATE, template); + st.add(FIRST_STATE, firstState); + st.add(STATES, states); + model.add(DEFINITIONS, st); } /** @@ -287,11 +342,11 @@ public class CGCliEditor { public ST createTaskDefinitionInfields(final String taskName, final String version, final String fieldName, final String fieldSchema, final String fieldSchemaVersion) { final ST st = stg.getInstanceOf("taskDefInputFields"); - st.add("taskName", taskName); - st.add("version", version); - st.add("fieldName", fieldName); - st.add("fieldSchema", fieldSchema); - st.add("fieldSchemaVersion", fieldSchemaVersion); + st.add(TASK_NAME, taskName); + st.add(VERSION, version); + st.add(FIELD_NAME, fieldName); + st.add(FIELD_SCHEMA, fieldSchema); + st.add(FIELD_SCHEMA_VERSION, fieldSchemaVersion); return st; } @@ -308,11 +363,11 @@ public class CGCliEditor { public ST createTaskDefinitionOutfields(final String taskName, final String version, final String fieldName, final String fieldSchema, final String fieldSchemaVersion) { final ST st = stg.getInstanceOf("taskDefOutputFields"); - st.add("taskName", taskName); - st.add("version", version); - st.add("fieldName", fieldName); - st.add("fieldSchema", fieldSchema); - st.add("fieldSchemaVersion", fieldSchemaVersion); + st.add(TASK_NAME, taskName); + st.add(VERSION, version); + st.add(FIELD_NAME, fieldName); + st.add(FIELD_SCHEMA, fieldSchema); + st.add(FIELD_SCHEMA_VERSION, fieldSchemaVersion); return st; } @@ -328,10 +383,10 @@ public class CGCliEditor { public ST createTaskDefinitionParameters(final String name, final String version, final String parName, final String defaultValue) { final ST st = stg.getInstanceOf("taskDefParameter"); - st.add("name", name); - st.add("version", version); - st.add("parName", parName); - st.add("defaultValue", defaultValue); + st.add(NAME, name); + st.add(VERSION, version); + st.add(PAR_NAME, parName); + st.add(DEFAULT_VALUE, defaultValue); return st; } @@ -347,10 +402,10 @@ public class CGCliEditor { public ST createTaskDefinitionContextRef(final String name, final String version, final String albumName, final String albumVersion) { final ST st = stg.getInstanceOf("taskDefCtxRef"); - st.add("name", name); - st.add("version", version); - st.add("albumName", albumName); - st.add("albumVersion", albumVersion); + st.add(NAME, name); + st.add(VERSION, version); + st.add(ALBUM_NAME, albumName); + st.add(ALBUM_VERSION, albumVersion); return st; } @@ -372,14 +427,14 @@ public class CGCliEditor { final String taskLocalName, final String taskName, final String taskVersion, final String outputType, final String outputName) { final ST st = stg.getInstanceOf("policyStateTask"); - st.add("policyName", policyName); - st.add("version", version); - st.add("stateName", stateName); - st.add("taskLocalName", taskLocalName); - st.add("taskName", taskName); - st.add("taskVersion", taskVersion); - st.add("outputType", outputType); - st.add("outputName", outputName); + st.add(POLICY_NAME, policyName); + st.add(VERSION, version); + st.add(STATE_NAME, stateName); + st.add(TASK_LOCAL_NAME, taskLocalName); + st.add(TASK_NAME, taskName); + st.add(TASK_VERSION, taskVersion); + st.add(OUTPUT_TYPE, outputType); + st.add(OUTPUT_NAME, outputName); return st; } @@ -398,13 +453,13 @@ public class CGCliEditor { public ST createPolicyStateOutput(final String policyName, final String version, final String stateName, final String outputName, final String eventName, final String eventVersion, final String nextState) { final ST st = stg.getInstanceOf("policyStateOutput"); - st.add("policyName", policyName); - st.add("version", version); - st.add("stateName", stateName); - st.add("outputName", outputName); - st.add("eventName", eventName); - st.add("eventVersion", eventVersion); - st.add("nextState", nextState); + st.add(POLICY_NAME, policyName); + st.add(VERSION, version); + st.add(STATE_NAME, stateName); + st.add(OUTPUT_NAME, outputName); + st.add(EVENT_NAME, eventName); + st.add(EVENT_VERSION, eventVersion); + st.add(NEXT_STATE, nextState); return st; } @@ -430,18 +485,18 @@ public class CGCliEditor { final String defaultTaskVersion, final List<ST> outputs, final List<ST> tasks, final List<ST> tsLogic, final List<ST> finalizerLogics, final List<ST> ctxRefs) { final ST st = stg.getInstanceOf("policyStateDef"); - st.add("policyName", policyName); - st.add("version", version); - st.add("stateName", stateName); - st.add("triggerName", triggerName); - st.add("triggerVersion", triggerVersion); - st.add("defaultTask", defaultTask); - st.add("defaultTaskVersion", defaultTaskVersion); - st.add("outputs", outputs); - st.add("tasks", tasks); - st.add("tsLogic", tsLogic); - st.add("finalizerLogics", finalizerLogics); - st.add("ctxRefs", ctxRefs); + st.add(POLICY_NAME, policyName); + st.add(VERSION, version); + st.add(STATE_NAME, stateName); + st.add(TRIGGER_NAME, triggerName); + st.add(TRIGGER_VERSION, triggerVersion); + st.add(DEFAULT_TASK, defaultTask); + st.add(DEFAULT_TASK_VERSION, defaultTaskVersion); + st.add(OUTPUTS, outputs); + st.add(TASKS, tasks); + st.add(TS_LOGIC, tsLogic); + st.add(FINALIZER_LOGICS, finalizerLogics); + st.add(CTX_REFS, ctxRefs); return st; } @@ -459,11 +514,11 @@ public class CGCliEditor { public ST createPolicyStateDefTaskSelLogic(final String name, final String version, final String stateName, final String logicFlavour, final String logic) { final ST st = stg.getInstanceOf("policyStateTaskSelectionLogic"); - st.add("name", name); - st.add("version", version); - st.add("stateName", stateName); - st.add("logicFlavour", logicFlavour); - st.add("logic", logic); + st.add(NAME, name); + st.add(VERSION, version); + st.add(STATE_NAME, stateName); + st.add(LOGIC_FLAVOUR, logicFlavour); + st.add(LOGIC, logic); return st; } @@ -482,12 +537,12 @@ public class CGCliEditor { public ST createPolicyStateDefFinalizerLogic(final String name, final String version, final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) { final ST st = stg.getInstanceOf("policyStateFinalizerLogic"); - st.add("name", name); - st.add("version", version); - st.add("stateName", stateName); - st.add("finalizerLogicName", finalizerLogicName); - st.add("logicFlavour", logicFlavour); - st.add("logic", logic); + st.add(NAME, name); + st.add(VERSION, version); + st.add(STATE_NAME, stateName); + st.add(FINALIZER_LOGIC_NAME, finalizerLogicName); + st.add(LOGIC_FLAVOUR, logicFlavour); + st.add(LOGIC, logic); return st; } @@ -504,11 +559,11 @@ public class CGCliEditor { public ST createPolicyStateDefContextRef(final String name, final String version, final String stateName, final String albumName, final String albumVersion) { final ST st = stg.getInstanceOf("policyStateContextRef"); - st.add("name", name); - st.add("version", version); - st.add("stateName", stateName); - st.add("albumName", albumName); - st.add("albumVersion", albumVersion); + st.add(NAME, name); + st.add(VERSION, version); + st.add(STATE_NAME, stateName); + st.add(ALBUM_NAME, albumName); + st.add(ALBUM_VERSION, albumVersion); return st; } diff --git a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CliEditorContants.java b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CliEditorContants.java new file mode 100644 index 000000000..3a82af796 --- /dev/null +++ b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CliEditorContants.java @@ -0,0 +1,132 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.auth.clicodegen; + +public class CliEditorContants { + + public static final String FINALIZER_LOGIC_NAME = "finalizerLogicName"; + + public static final String LOGIC_FLAVOUR = "logicFlavour"; + + public static final String CTX_REFS = "ctxRefs"; + + public static final String FINALIZER_LOGICS = "finalizerLogics"; + + public static final String TS_LOGIC = "tsLogic"; + + public static final String TASKS = "tasks"; + + public static final String OUTPUTS = "outputs"; + + public static final String DEFAULT_TASK_VERSION = "defaultTaskVersion"; + + public static final String DEFAULT_TASK = "defaultTask"; + + public static final String TRIGGER_VERSION = "triggerVersion"; + + public static final String TRIGGER_NAME = "triggerName"; + + public static final String NEXT_STATE = "nextState"; + + public static final String EVENT_VERSION = "eventVersion"; + + public static final String OUTPUT_NAME = "outputName"; + + public static final String OUTPUT_TYPE = "outputType"; + + public static final String TASK_VERSION = "taskVersion"; + + public static final String TASK_LOCAL_NAME = "taskLocalName"; + + public static final String STATE_NAME = "stateName"; + + public static final String POLICY_NAME = "policyName"; + + public static final String ALBUM_VERSION = "albumVersion"; + + public static final String ALBUM_NAME = "albumName"; + + public static final String DEFAULT_VALUE = "defaultValue"; + + public static final String PAR_NAME = "parName"; + + public static final String CONTEXT_REFS = "contextRefs"; + + public static final String PARAMS = "parameters"; + + public static final String OUTFIELDS = "outfields"; + + public static final String INFIELDS = "infields"; + + public static final String NAME_SPACE = "nameSpace"; + + public static final String FIELDS = "fields"; + + public static final String TARGET = "target"; + + public static final String SOURCE = "source"; + + public static final String LOGIC = "logic"; + + public static final String TASK_NAME = "taskName"; + + public static final String OPTIONAL = "optional"; + + public static final String FIELD_SCHEMA_VERSION = "fieldSchemaVersion"; + + public static final String FIELD_SCHEMA = "fieldSchema"; + + public static final String FIELD_NAME = "fieldName"; + + public static final String EVENT_NAME = "eventName"; + + public static final String DECLARATION = "declarations"; + + public static final String SCHEMA = "schema"; + + public static final String FLAVOUR = "flavour"; + + public static final String DESCRIPTION = "description"; + + public static final String UUID = "uuid"; + + public static final String VERSION = "version"; + + public static final String NAME = "name"; + + public static final String SCHEMA_VERSION = "schemaVersion"; + + public static final String SCHEMA_NAME = "schemaName"; + + public static final String WRITABLE = "writable"; + + public static final String STATES = "states"; + + public static final String FIRST_STATE = "firstState"; + + public static final String TEMPLATE = "template"; + + public static final String SCOPE = "scope"; + + public static final String DEFINITIONS = "definitions"; + + private CliEditorContants() {} +} diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java index 4a2635efa..0d36d2daa 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCLIEditorMain.java @@ -68,7 +68,7 @@ public class ApexCLIEditorMain { } parameters.validate(); } catch (final Exception e) { - LOGGER.error("start of Apex command line editor failed, " + e.getMessage()); + LOGGER.error("start of Apex command line editor failed, ", e); errorCount++; return; } @@ -78,28 +78,27 @@ public class ApexCLIEditorMain { // Read the command definitions try { commands = new JSONHandler<CLICommands>().read(CLICommands.class, parameters.getMetadataStream()); - LOGGER.debug("found " + commands.getCommandSet().size() + " commands"); } catch (final Exception e) { LOGGER.error("start of Apex command line editor failed, error reading command metadata from " - + parameters.getMetadataLocation()); - LOGGER.error(e.getMessage()); + + parameters.getMetadataLocation(), e); errorCount++; return; } // The JSON processing returns null if there is an empty file - if (null == commands) { + if (commands == null || commands.getCommandSet().isEmpty()) { LOGGER.error("start of Apex command line editor failed, no commands found in " + parameters.getApexPropertiesLocation()); errorCount++; return; } + LOGGER.debug("found " + commands.getCommandSet().size() + " commands"); + // Read the Apex properties try { apexModelProperties = new JSONHandler<ApexModelProperties>().read(ApexModelProperties.class, parameters.getApexPropertiesStream()); - LOGGER.debug("model properties are: " + apexModelProperties.toString()); } catch (final Exception e) { LOGGER.error("start of Apex command line editor failed, error reading Apex model properties from " + parameters.getApexPropertiesLocation()); @@ -116,6 +115,8 @@ public class ApexCLIEditorMain { return; } + LOGGER.debug("model properties are: " + apexModelProperties.toString()); + // Find the system commands final Set<KeywordNode> systemCommandNodes = new TreeSet<>(); for (final CLICommand command : commands.getCommandSet()) { @@ -137,7 +138,7 @@ public class ApexCLIEditorMain { modelHandler = new ApexModelHandler(apexModelProperties.getProperties(), parameters.getInputModelFileName()); } catch (final Exception e) { - LOGGER.error("execution of Apex command line editor failed: " + e.getMessage()); + LOGGER.error("execution of Apex command line editor failed: ", e); errorCount++; return; } diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java index 560648901..4eacde04b 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIEditorLoop.java @@ -20,6 +20,8 @@ package org.onap.policy.apex.auth.clieditor; +import static org.onap.policy.apex.model.utilities.TreeMapUtils.findMatchingEntries; + import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -170,7 +172,7 @@ public class CLIEditorLoop { try { // Parse the line into a list of commands and arguments - final ArrayList<String> commandWords = parser.parse(line, logicBlock); + final List<String> commandWords = parser.parse(line, logicBlock); // Find the command, if the command is null, then we are simply changing position in // the hierarchy @@ -240,7 +242,7 @@ public class CLIEditorLoop { * @return The found command */ - private CLICommand findCommand(final ArrayList<String> commandWords) { + private CLICommand findCommand(final List<String> commandWords) { CLICommand command = null; final KeywordNode startKeywordNode = keywordNodeDeque.peek(); @@ -258,8 +260,8 @@ public class CLIEditorLoop { // If the node entries found is not equal to one, then we have either no command or more // than one command matching final List<Entry<String, KeywordNode>> foundNodeEntries = - TreeMapUtils.findMatchingEntries(searchKeywordNode.getChildren(), commandWords.get(i)); - if (foundNodeEntries.size() == 0) { + findMatchingEntries(searchKeywordNode.getChildren(), commandWords.get(i)); + if (foundNodeEntries.isEmpty()) { unwindStack(startKeywordNode); throw new CLIException("command not found: " + stringAL2String(commandWords)); } else if (foundNodeEntries.size() > 1) { @@ -311,7 +313,7 @@ public class CLIEditorLoop { * @return the argument values */ private TreeMap<String, CLIArgumentValue> getArgumentValues(final CLICommand command, - final ArrayList<String> commandWords) { + final List<String> commandWords) { final TreeMap<String, CLIArgumentValue> argumentValues = new TreeMap<>(); for (final CLIArgument argument : command.getArgumentList()) { if (argument != null) { @@ -338,13 +340,11 @@ public class CLIEditorLoop { // Now check all mandatory arguments are set for (final CLIArgumentValue argumentValue : argumentValues.values()) { - if (!argumentValue.isSpecified()) { - // Argument values are null by default so if this argument is not nullable it is - // mandatory - if (!argumentValue.getCliArgument().isNullable()) { - throw new CLIException("command " + stringAL2String(commandWords) + ": " + " mandatory argument \"" - + argumentValue.getCliArgument().getArgumentName() + "\" not specified"); - } + // Argument values are null by default so if this argument is not nullable it is + // mandatory + if (!argumentValue.isSpecified() && !argumentValue.getCliArgument().isNullable()) { + throw new CLIException("command " + stringAL2String(commandWords) + ": " + " mandatory argument \"" + + argumentValue.getCliArgument().getArgumentName() + "\" not specified"); } } @@ -358,7 +358,7 @@ public class CLIEditorLoop { * @param commandWords The command words entered by the user * @return the arguments as an entry array list */ - private ArrayList<Entry<String, String>> getCommandArguments(final ArrayList<String> commandWords) { + private ArrayList<Entry<String, String>> getCommandArguments(final List<String> commandWords) { final ArrayList<Entry<String, String>> arguments = new ArrayList<>(); // Iterate over the command words, arguments are of the format name=value @@ -398,11 +398,11 @@ public class CLIEditorLoop { * @return the result of execution of the command */ private ApexAPIResult exceuteSystemCommand(final CLICommand command, final PrintWriter writer) { - if (command.getName().equals("back")) { + if ("back".equals(command.getName())) { return executeBackCommand(); - } else if (command.getName().equals("help")) { + } else if ("help".equals(command.getName())) { return executeHelpCommand(writer); - } else if (command.getName().equals("quit")) { + } else if ("quit".equals(command.getName())) { return executeQuitCommand(); } else { return new ApexAPIResult(RESULT.SUCCESS); diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLILineParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLILineParser.java index fd4541f28..502eb48c5 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLILineParser.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLILineParser.java @@ -21,6 +21,7 @@ package org.onap.policy.apex.auth.clieditor; import java.util.ArrayList; +import java.util.List; /** * This class chops a command line up into commands, parameters and arguments. @@ -43,7 +44,7 @@ public class CLILineParser { * @param logicBlock A block of logic code to be taken literally * @return the string array list */ - public ArrayList<String> parse(final String line, final String logicBlock) { + public List<String> parse(final String line, final String logicBlock) { return checkFormat( mergeArguments(mergeEquals( splitOnEquals(stripAndSplitWords(mergeQuotes(splitOnChar(stripComments(line), '\"')))))), @@ -78,12 +79,12 @@ public class CLILineParser { final ArrayList<String> wordsWithQuotesMerged = new ArrayList<>(); for (int i = 0; i < wordsSplitOnQuotes.size();) { - if (wordsSplitOnQuotes.get(i).equals("\"")) { + if ("\"".equals(wordsSplitOnQuotes.get(i))) { String quotedWord = wordsSplitOnQuotes.get(i++); for (; i < wordsSplitOnQuotes.size(); i++) { quotedWord += wordsSplitOnQuotes.get(i); - if (wordsSplitOnQuotes.get(i).equals("\"")) { + if ("\"".equals(wordsSplitOnQuotes.get(i))) { i++; break; } @@ -147,7 +148,7 @@ public class CLILineParser { continue; } - if (wordsSplitOnEquals.get(i).equals("=")) { + if ("=".equals(wordsSplitOnEquals.get(i))) { if (i < wordsSplitOnEquals.size() - 1 && !wordsSplitOnEquals.get(i + 1).startsWith("=")) { wordsWithEqualsMerged.add(wordsSplitOnEquals.get(i) + wordsSplitOnEquals.get(i + 1)); i += 2; diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIParameters.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIParameters.java index 476d17e3f..5f363cfa7 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIParameters.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CLIParameters.java @@ -216,7 +216,7 @@ public class CLIParameters { try { theFile.createNewFile(); } catch (final IOException e) { - throw new CLIException("file " + fileName + " cannot be created: " + e.getMessage()); + throw new CLIException("file " + fileName + " cannot be created: ", e); } } } diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java index 06579e073..6be5c6846 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java @@ -22,6 +22,7 @@ package org.onap.policy.apex.auth.clieditor; import java.util.ArrayList; import java.util.List; +import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; @@ -70,7 +71,7 @@ public class KeywordNode implements Comparable<KeywordNode> { * @param incomingCommand the command */ public void processKeywords(final List<String> keywordList, final CLICommand incomingCommand) { - if (keywordList.size() <= 0) { + if (keywordList.isEmpty()) { this.command = incomingCommand; return; } @@ -118,7 +119,7 @@ public class KeywordNode implements Comparable<KeywordNode> { * * @return the children of this keyword node */ - public TreeMap<String, KeywordNode> getChildren() { + public NavigableMap<String, KeywordNode> getChildren() { return children; } diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java index 43238d63d..4b8dbd23b 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java @@ -24,8 +24,12 @@ import static org.junit.Assert.assertEquals; import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.utilities.TextFileUtils; @@ -35,6 +39,25 @@ import org.onap.policy.apex.model.utilities.TextFileUtils; public class TestCLIEditorEventsContext { // CHECKSTYLE:OFF: MagicNumber + private static final Path SRC_MAIN_FOLDER = Paths.get("src/main/resources/"); + private static final Path SRC_TEST_FOLDER = Paths.get("src/test/resources/"); + + private static final Path SUB_FOLDER = SRC_MAIN_FOLDER.resolve("examples/scripts/"); + + private static final String SPACES = "\\s+"; + private static final String EMPTY_STRING = ""; + + private static final Path APEX_AVRO_POLICY_FILE = SUB_FOLDER.resolve("TestPolicyAvroEventContext.apex"); + private static final Path APEX_JAVA_POLICY_FILE = SUB_FOLDER.resolve("TestPolicyJavaEventContext.apex"); + + private static final String FILE_NAME = "TestPolicyJavaEventsAndContext"; + private static final String JSON_FILE = FILE_NAME + ".json"; + private static final String LOG_FILE = FILE_NAME + ".log"; + + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + /** * Test java context model. * @@ -43,12 +66,12 @@ public class TestCLIEditorEventsContext { */ @Test public void testJavaContextModel() throws IOException, ApexModelException { - final File tempLogFile = File.createTempFile("TestPolicyJavaEventsAndContext", ".log"); - final File tempModelFile = File.createTempFile("TestPolicyJavaEventsAndContext", ".json"); - final String[] cliArgs = - new String[] {"-c", "src/main/resources/examples/scripts/TestPolicyJavaEventContext.apex", "-l", - tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + + final String[] cliArgs = new String[] {"-c", APEX_JAVA_POLICY_FILE.toString(), "-l", + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -58,14 +81,11 @@ public class TestCLIEditorEventsContext { final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); // As a sanity check, count the number of non white space characters in log and model files - final int logCharCount = logString.replaceAll("\\s+", "").length(); - final int modelCharCount = modelString.replaceAll("\\s+", "").length(); + final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); + final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); assertEquals(25911, logCharCount); assertEquals(46138, modelCharCount); - - tempLogFile.delete(); - tempModelFile.delete(); } /** @@ -76,12 +96,12 @@ public class TestCLIEditorEventsContext { */ @Test public void testAvroContextModel() throws IOException, ApexModelException { - final File tempLogFile = File.createTempFile("TestPolicyAvroEventsAndContext", ".log"); - final File tempModelFile = File.createTempFile("TestPolicyAvroEventsAndContext", ".json"); - final String[] cliArgs = - new String[] {"-c", "src/main/resources/examples/scripts/TestPolicyAvroEventContext.apex", "-l", - tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + + final String[] cliArgs = new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -91,13 +111,51 @@ public class TestCLIEditorEventsContext { final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); // As a sanity check, count the number of non white space characters in log and model files - final int logCharCount = logString.replaceAll("\\s+", "").length(); - final int modelCharCount = modelString.replaceAll("\\s+", "").length(); + final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); + final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); assertEquals(30315, logCharCount); assertEquals(52930, modelCharCount); - tempLogFile.delete(); - tempModelFile.delete(); } + + @Test + public void test_emptyMetadataCommandFileWithEmptyJsonTag_errorcountGreaterThanOne() throws IOException { + + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + + final String modelFile = SRC_TEST_FOLDER.resolve("model").resolve("empty_commands.json").toString(); + final String apexPropertiesLocation = + SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString(); + + final String[] cliArgs = + new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", + tempModelFile.getAbsolutePath(), "-m", modelFile, "-a", apexPropertiesLocation}; + + final ApexCLIEditorMain objUnderTest = new ApexCLIEditorMain(cliArgs); + assertEquals(1, objUnderTest.getErrorCount()); + + } + + @Test + public void test_emptyMetadataCommandFile_errorcountGreaterThanOne() throws IOException { + + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + + final File modelFile = temporaryFolder.newFile("empty_commands.json"); + + final String apexPropertiesLocation = + SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString(); + + final String[] cliArgs = new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath(), "-m", modelFile.getAbsolutePath(), + "-a", apexPropertiesLocation}; + + final ApexCLIEditorMain objUnderTest = new ApexCLIEditorMain(cliArgs); + assertEquals(1, objUnderTest.getErrorCount()); + + } + } diff --git a/auth/cli-editor/src/test/resources/model/empty_commands.json b/auth/cli-editor/src/test/resources/model/empty_commands.json new file mode 100644 index 000000000..49d1a202f --- /dev/null +++ b/auth/cli-editor/src/test/resources/model/empty_commands.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/context/context-test/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java b/context/context-test/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java index 6ffacbb6c..42e3e0978 100644 --- a/context/context-test/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java +++ b/context/context-test/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextThread.java @@ -138,14 +138,8 @@ public class ConcurrentContextThread implements Runnable { item = new TestContextItem003(0L); } lTypeAlbum.put("testValue", item); - } catch (final Exception exception) { - throw exception; } finally { - try { - lTypeAlbum.unlockForWriting("testValue"); - } catch (final ContextException contextException) { - throw contextException; - } + lTypeAlbum.unlockForWriting("testValue"); } } } diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java index c2a19a167..5fc7dc8c6 100644 --- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java +++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/DeploymentClient.java @@ -20,8 +20,6 @@ package org.onap.policy.apex.core.deployment; -import com.google.common.eventbus.Subscribe; - import java.net.URI; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -37,10 +35,13 @@ import org.onap.policy.apex.core.protocols.Message; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; +import com.google.common.eventbus.Subscribe; + /** - * The Class DeploymentClient handles the client side of an EngDep communication session with an Apex server. It runs a - * thread to handle message sending and session monitoring. It uses a sending queue to queue messages for sending by the - * client thread and a receiving queue to queue messages received from the Apex engine. + * The Class DeploymentClient handles the client side of an EngDep communication session with an + * Apex server. It runs a thread to handle message sending and session monitoring. It uses a sending + * queue to queue messages for sending by the client thread and a receiving queue to queue messages + * received from the Apex engine. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -90,7 +91,8 @@ public class DeploymentClient implements Runnable { thisThread.setName(DeploymentClient.class.getName() + "-" + host + ":" + port); try { - // Establish a connection to the Apex server for EngDep message communication over Web Sockets + // Establish a connection to the Apex server for EngDep message communication over Web + // Sockets service = factory.createClient(new URI("ws://" + host + ":" + port)); service.addMessageListener(new DeploymentClientListener()); @@ -101,7 +103,6 @@ public class DeploymentClient implements Runnable { LOGGER.error("engine<-->deployment client thread exception", e); return; } - // Loop forever, sending messages as they appear on the queue while (true) { try { @@ -110,6 +111,8 @@ public class DeploymentClient implements Runnable { } catch (final InterruptedException e) { // Message sending has been interrupted, we are finished LOGGER.debug("engine<-->deployment client interrupted"); + // restore the interrupt status + thisThread.interrupt(); break; } } @@ -169,10 +172,11 @@ public class DeploymentClient implements Runnable { } /** - * The listener interface for receiving deploymentClient events. The class that is interested in processing a - * deploymentClient event implements this interface, and the object created with that class is registered with a - * component using the component's {@code addDeploymentClientListener} method. When the deploymentClient event - * occurs, that object's appropriate method is invoked. + * The listener interface for receiving deploymentClient events. The class that is interested in + * processing a deploymentClient event implements this interface, and the object created with + * that class is registered with a component using the component's + * {@code addDeploymentClientListener} method. When the deploymentClient event occurs, that + * object's appropriate method is invoked. * * @see DeploymentClientEvent */ @@ -180,8 +184,9 @@ public class DeploymentClient implements Runnable { /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(org.onap.policy.apex.core. - * infrastructure.messaging.impl.ws.messageblock. MessageBlock) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(org.onap. + * policy.apex.core. infrastructure.messaging.impl.ws.messageblock. MessageBlock) */ @Subscribe @Override @@ -192,7 +197,9 @@ public class DeploymentClient implements Runnable { /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(java.lang.String) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(java.lang. + * String) */ @Override public void onMessage(final String messageString) { diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java index d954feaa3..11e870c9c 100644 --- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java +++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java @@ -50,11 +50,12 @@ import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * The Class Deployer deploys an Apex model held as an XML file onto an Apex engine. It uses the EngDep protocol to - * communicate with the engine, with the EngDep protocol being carried on Java web sockets. + * The Class Deployer deploys an Apex model held as an XML file onto an Apex engine. It uses the + * EngDep protocol to communicate with the engine, with the EngDep protocol being carried on Java + * web sockets. * - * This deployer is a simple command line deployer that reads the communication parameters and the location of the XML - * model file as arguments. + * This deployer is a simple command line deployer that reads the communication parameters and the + * location of the XML model file as arguments. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -62,7 +63,8 @@ public class EngineServiceFacade { // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(EngineServiceFacade.class); - // The default message timeout and timeout increment (the amount of time between polls) in milliseconds + // The default message timeout and timeout increment (the amount of time between polls) in + // milliseconds private static final int CLIENT_START_WAIT_INTERVAL = 100; private static final int REPLY_MESSAGE_TIMEOUT_DEFAULT = 10000; private static final int REPLY_MESSAGE_TIMEOUT_INCREMENT = 100; @@ -100,7 +102,8 @@ public class EngineServiceFacade { try { LOGGER.debug("handshaking with server {}:{} . . .", hostName, port); - // Use the deployment client to handle the EngDep communication towards the Apex server. It runs a thread to + // Use the deployment client to handle the EngDep communication towards the Apex server. + // It runs a thread to // monitor the session and to send // messages client = new DeploymentClient(hostName, port); @@ -184,7 +187,8 @@ public class EngineServiceFacade { * * @param modelFileName the name of the model file containing the model to deploy * @param ignoreConflicts true if conflicts between context in polices is to be ignored - * @param force true if the model is to be applied even if it is incompatible with the existing model + * @param force true if the model is to be applied even if it is incompatible with the existing + * model * @throws ApexException on Apex errors * @throws IOException on IO exceptions from the operating system */ @@ -215,7 +219,8 @@ public class EngineServiceFacade { * @param modelFileName the name of the model file containing the model to deploy * @param modelInputStream the stream that holds the Apex model * @param ignoreConflicts true if conflicts between context in polices is to be ignored - * @param force true if the model is to be applied even if it is incompatible with the existing model + * @param force true if the model is to be applied even if it is incompatible with the existing + * model * @throws ApexException on model deployment errors */ public void deployModel(final String modelFileName, final InputStream modelInputStream, @@ -238,7 +243,8 @@ public class EngineServiceFacade { * * @param apexPolicyModel the name of the model to deploy * @param ignoreConflicts true if conflicts between context in polices is to be ignored - * @param force true if the model is to be applied even if it is incompatible with the existing model + * @param force true if the model is to be applied even if it is incompatible with the existing + * model * @throws ApexException on model deployment errors */ public void deployModel(final AxPolicyModel apexPolicyModel, final boolean ignoreConflicts, final boolean force) @@ -436,6 +442,8 @@ public class EngineServiceFacade { try { receivedMessage = client.getReceiveQueue().poll(REPLY_MESSAGE_TIMEOUT_INCREMENT, TimeUnit.MILLISECONDS); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.warn("reception of response from server interrupted {}:{}", hostName, port, e); throw new ApexDeploymentException( "reception of response from server interrupted " + hostName + ':' + port, e); diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateOutput.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateOutput.java index 2274b7c23..aaec71b47 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateOutput.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateOutput.java @@ -34,7 +34,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput; import org.onap.policy.apex.model.utilities.Assertions; /** - * This class is the output of a state, and is used by the engine to decide what the next state for execution is. + * This class is the output of a state, and is used by the engine to decide what the next state for + * execution is. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -115,15 +116,11 @@ public class StateOutput { for (final Entry<String, Object> incomingFieldEntry : eventFieldMap.entrySet()) { final String fieldName = incomingFieldEntry.getKey(); final AxField fieldDef = incomingFieldDefinitionMap.get(fieldName); - try { - - // Check if this field is a field in the event - if (!outputEventDef.getFields().contains(fieldDef)) { - throw new StateMachineException( - "field \"" + fieldName + "\" does not exist on event \"" + outputEventDef.getID() + "\""); - } - } catch (final Exception e) { - e.printStackTrace(); + + // Check if this field is a field in the event + if (!outputEventDef.getFields().contains(fieldDef)) { + throw new StateMachineException( + "field \"" + fieldName + "\" does not exist on event \"" + outputEventDef.getID() + "\""); } // Set the value in the output event @@ -132,8 +129,8 @@ public class StateOutput { } /** - * This method copies any fields that exist on the input event that also exist on the output event if they are not - * set on the output event. + * This method copies any fields that exist on the input event that also exist on the output + * event if they are not set on the output event. * * @param incomingEvent The incoming event to copy from */ diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacade.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacade.java index 226f06ade..80d7e651b 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacade.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacade.java @@ -40,7 +40,7 @@ public class AxStateFacade { // CHECKSTYLE:OFF: checkstyle:visibilityModifier Logic has access to this field /** The full definition information for the state. */ - public AxState state; + public final AxState state; // CHECKSTYLE:ON: checkstyle:visibilityModifier diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacade.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacade.java index 015f3ae80..85bf96c8d 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacade.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacade.java @@ -46,7 +46,7 @@ public class AxTaskFacade { * The full definition of the task we are presenting a facade to, executing logic has full access to the task * definition. */ - public AxTask task; + public final AxTask task; // CHECKSTYLE:ON: checkstyle:visibilityModifier diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java index 2e5971142..874d4def1 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java @@ -70,7 +70,7 @@ public class StateFinalizerExecutionContext { * fields to determine what state output to select. Once a state finalizer has selected a state output, it must * marshal these fields so that they match the fields required for the event defined in the state output. */ - public Map<String, Object> fields; + public final Map<String, Object> fields; // A message specified in the logic private String message; diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java index 534bee8af..7e9a31a4f 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java @@ -20,8 +20,6 @@ package org.onap.policy.apex.core.infrastructure.messaging.impl.ws; -import com.google.common.eventbus.Subscribe; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; @@ -40,9 +38,11 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; +import com.google.common.eventbus.Subscribe; + /** - * The Class RawMessageHandler handles raw messages being received on a Java web socket and forwards the messages to the - * DataHandler instance that has subscribed to the RawMessageHandler instance. + * The Class RawMessageHandler handles raw messages being received on a Java web socket and forwards + * the messages to the DataHandler instance that has subscribed to the RawMessageHandler instance. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) * @param <MESSAGE> the generic type of message being received @@ -85,33 +85,35 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS return; } - // Read the messages from the web socket and place them on the message queue for handling by the queue + // Read the messages from the web socket and place them on the message queue for handling by + // the queue // processing thread - ObjectInputStream ois = null; - try { - ois = new ObjectInputStream(new ByteArrayInputStream(dataByteBuffer.array())); + + try (final ByteArrayInputStream stream = new ByteArrayInputStream(dataByteBuffer.array()); + final ObjectInputStream ois = new ObjectInputStream(stream);) { @SuppressWarnings("unchecked") final MessageHolder<MESSAGE> messageHolder = (MessageHolder<MESSAGE>) ois.readObject(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug("message {} recieved from the client {} ", messageHolder.toString(), + LOGGER.debug("message {} recieved from the client {} ", messageHolder, messageHolder == null ? "Apex Engine " : messageHolder.getSenderHostAddress()); } - final List<MESSAGE> messages = messageHolder.getMessages(); - if (messages != null) { - messageBlockQueue.add(new MessageBlock<MESSAGE>(messages, incomingData.getConn())); + if (messageHolder != null) { + final List<MESSAGE> messages = messageHolder.getMessages(); + if (messages != null) { + messageBlockQueue.add(new MessageBlock<MESSAGE>(messages, incomingData.getConn())); + } } - } catch (IOException | ClassNotFoundException e) { + } catch (final IOException | ClassNotFoundException e) { LOGGER.error("Failed to process message received"); LOGGER.catching(e); - } finally { - closeObjectStream(ois); } } /** - * This method is called when a string message is received on a web socket and is to be forwarded to a listener. + * This method is called when a string message is received on a web socket and is to be + * forwarded to a listener. * * @param messageString the message string */ @@ -128,21 +130,6 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS } /** - * Close the {@link ObjectInputStream} stream. - * - * @param ois is an instance of {@link ObjectInputStream} - */ - private void closeObjectStream(final ObjectInputStream ois) { - if (ois != null) { - try { - ois.close(); - } catch (final IOException e) { - LOGGER.catching(e); - } - } - } - - /** * This thread monitors the message queue and processes messages as they appear on the queue. * * @see java.lang.Runnable#run() @@ -161,6 +148,8 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS dataHandler.post(messageBlock); } } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.debug("raw message listening has been interrupted"); break; } @@ -172,6 +161,8 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS dataHandler.post(stringMessage); } } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.debug("raw message listening has been interrupted"); break; } @@ -180,6 +171,8 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS try { Thread.sleep(QUEUE_POLL_TIMEOUT); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.debug("raw message listening has been interrupted"); break; } @@ -206,7 +199,8 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS } /** - * This method is called when a message is received on a web socket and is to be forwarded to a listener. + * This method is called when a message is received on a web socket and is to be forwarded to a + * listener. * * @param data the message data containing a message */ @@ -246,8 +240,5 @@ public class RawMessageHandler<MESSAGE> implements WebSocketMessageListener<MESS if (listener == null) { throw new IllegalArgumentException("The listener object cannot be null"); } - if (dataHandler == null) { - throw new IllegalStateException("Data handler not initialized"); - } } } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/MessagingClient.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/MessagingClient.java index 4a756d6f0..36ad3b163 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/MessagingClient.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/MessagingClient.java @@ -29,8 +29,8 @@ import org.onap.policy.apex.core.infrastructure.messaging.util.MessagingUtils; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; /** - * The Class MessagingClient is the class that wraps web socket handling, message sending, and message reception on the - * client side of a web socket in Apex. + * The Class MessagingClient is the class that wraps web socket handling, message sending, and + * message reception on the client side of a web socket in Apex. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) * @param <MESSAGE> the generic type @@ -39,12 +39,13 @@ public class MessagingClient<MESSAGE> extends InternalMessageBusClient<MESSAGE> // The length of time to wait for a connection to a web socket server before aborting private static final int CONNECTION_TIMEOUT_TIME_MS = 3000; - // The length of time to wait before checking if a connection to a web socket server has worked or not + // The length of time to wait before checking if a connection to a web socket server has worked + // or not private static final int CONNECTION_TRY_INTERVAL_MS = 100; /** - * Constructor of this class, uses its {@link InternalMessageBusClient} superclass to set up the web socket and - * handle incoming message forwarding. + * Constructor of this class, uses its {@link InternalMessageBusClient} superclass to set up the + * web socket and handle incoming message forwarding. * * @param serverUri The URI of the service */ @@ -80,7 +81,11 @@ public class MessagingClient<MESSAGE> extends InternalMessageBusClient<MESSAGE> public void startConnection() { // Open the web socket final WebSocket connection = super.getConnection(); - if (connection != null && !connection.isOpen()) { + + if (connection == null) { + throw new IllegalStateException("Could not connect to the server"); + } + if (!connection.isOpen()) { connect(); } @@ -129,8 +134,9 @@ public class MessagingClient<MESSAGE> extends InternalMessageBusClient<MESSAGE> /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(org.onap.policy.apex.core. - * infrastructure. messaging.MessageHolder) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(org.onap.policy.apex + * .core. infrastructure. messaging.MessageHolder) */ @Override public void send(final MessageHolder<MESSAGE> commands) { @@ -142,7 +148,8 @@ public class MessagingClient<MESSAGE> extends InternalMessageBusClient<MESSAGE> /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(java.lang.String) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(java.lang.String) */ @Override public void send(final String messageString) { diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java index fc401576f..ee6e1a329 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java @@ -98,6 +98,8 @@ public class MessageServerImpl<MESSAGE> extends InternalMessageBusServer<MESSAGE } catch (final IOException ioe) { LOGGER.catching(ioe); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); // This can happen in normal operation so ignore } isStarted = false; @@ -119,8 +121,9 @@ public class MessageServerImpl<MESSAGE> extends InternalMessageBusServer<MESSAGE /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(org.onap.policy.apex.core. - * infrastructure. messaging.MessageHolder) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(org.onap.policy.apex + * .core. infrastructure. messaging.MessageHolder) */ @Override public void send(final MessageHolder<MESSAGE> message) { @@ -134,7 +137,8 @@ public class MessageServerImpl<MESSAGE> extends InternalMessageBusServer<MESSAGE /* * (non-Javadoc) * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(java.lang.String) + * @see + * org.onap.policy.apex.core.infrastructure.messaging.MessagingService#send(java.lang.String) */ @Override public void send(final String messageString) { diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java index d15f86c8a..44b3c7fab 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java @@ -33,8 +33,8 @@ import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * The Class MessagingUtils is a class with static methods used in IPC messaging for finding free ports, translating - * host names to addresses, serializing objects and flushing object streams. + * The Class MessagingUtils is a class with static methods used in IPC messaging for finding free + * ports, translating host names to addresses, serializing objects and flushing object streams. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) */ @@ -42,6 +42,11 @@ public final class MessagingUtils { // The port number of the lowest user port, ports 0-1023 are system ports private static final int LOWEST_USER_PORT = 1024; + /** + * Port number is an unsigned 16-bit integer, so maximum port is 65535 + */ + private static final int MAX_PORT_RANGE = 65535; + // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(MessagingUtils.class); @@ -51,8 +56,8 @@ public final class MessagingUtils { private MessagingUtils() {} /** - * This method searches the availability of the port, if the requested port not available, this method will throw an - * exception. + * This method searches the availability of the port, if the requested port not available, this + * method will throw an exception. * * @param port the port to check * @return the port verified as being free @@ -61,33 +66,18 @@ public final class MessagingUtils { public static int checkPort(final int port) { LOGGER.entry("Checking availability of port {}", port); - Socket s = null; - try { - // Try to connect to the port, if we can connect then the port is occupied - s = new Socket("localhost", port); - LOGGER.debug("Port {} is not available", port); - - throw new RuntimeException("could not allocate requested port: " + port); - } catch (final IOException e) { - // We found a free port + if (isPortAvailable(port)) { LOGGER.debug("Port {} is available ", port); return port; - } finally { - // Close the socket used to check if the port was free - if (s != null) { - try { - s.close(); - } catch (final IOException e) { - LOGGER.catching(e); - LOGGER.warn("could not allocate requested port " + port, e); - } - } } + LOGGER.debug("Port {} is not available", port); + throw new RuntimeException("could not allocate requested port: " + port); } /** - * This method searches the availability of the port, if the requested port not available,this method will increment - * the port number and check the availability of that port, this process will continue until it find port available. + * This method searches the availability of the port, if the requested port not available,this + * method will increment the port number and check the availability of that port, this process + * will continue until it reaches max port range which is {@link MAX_PORT_RANGE}. * * @param port the first port to check * @return the port that was found @@ -96,29 +86,31 @@ public final class MessagingUtils { public static int findPort(final int port) { LOGGER.entry("Checking availability of port {}", port); - Socket s = null; - try { - // Try to connect to the port, if we can connect then the port is occupied - s = new Socket("localhost", port); - LOGGER.debug("Port {} is not available", port); + int availablePort = port; - // Recurse and try the next port - return findPort(port + 1); - } catch (final IOException e) { - // We found a free port - LOGGER.debug("Port {} is available ", port); - return port; - } finally { - // Close the socket used to check if the port was free - if (s != null) { - try { - s.close(); - } catch (final IOException e) { - LOGGER.catching(e); - LOGGER.warn("could not allocate requested port " + port, e); - throw new RuntimeException("could not allocate requested port " + port, e); - } + while (availablePort <= MAX_PORT_RANGE) { + if (isPortAvailable(availablePort)) { + LOGGER.debug("Port {} is available ", availablePort); + return availablePort; } + LOGGER.debug("Port {} is not available", availablePort); + availablePort++; + } + throw new RuntimeException("could not find free available"); + } + + /** + * Check if port is available or not + * + * @param port + * @return true if port is available + */ + public static boolean isPortAvailable(final int port) { + try (final Socket socket = new Socket("localhost", port)) { + return false; + } catch (final IOException ignoredException) { + LOGGER.trace("Port {} is available", port, ignoredException); + return true; } } @@ -136,8 +128,9 @@ public final class MessagingUtils { } /** - * This method searches the availability of the port, if the requested port not available,this method will increment - * the port number and check the availability, this process will continue until it find port available. + * This method searches the availability of the port, if the requested port not available,this + * method will increment the port number and check the availability, this process will continue + * until it find port available. * * @param port the first port to check * @return the port that was found diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ThreadUtilities.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ThreadUtilities.java index 56b903f38..b5663e452 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ThreadUtilities.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ThreadUtilities.java @@ -42,6 +42,8 @@ public final class ThreadUtilities { try { Thread.sleep(milliseconds); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); return false; } diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TextFileUtils.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TextFileUtils.java index d119a3a35..97face9bd 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TextFileUtils.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/TextFileUtils.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -26,11 +26,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.file.Files; -import java.nio.file.Paths; /** - * The Class TextFileUtils is class that provides useful functions for handling text files. - * Functions to read and wrtie text files to strings and strings are provided. + * The Class TextFileUtils is class that provides useful functions for handling text files. Functions to read and wrtie + * text files to strings and strings are provided. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -49,7 +48,8 @@ public abstract class TextFileUtils { * @throws IOException on errors reading text from the file */ public static String getTextFileAsString(final String textFilePath) throws IOException { - return new String(Files.readAllBytes(Paths.get(textFilePath))); + final File textFile = new File(textFilePath); + return new String(Files.readAllBytes(textFile.toPath())); } /** diff --git a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java index 803d99adc..1a2076f10 100644 --- a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java +++ b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java @@ -20,14 +20,11 @@ package org.onap.policy.apex.plugins.context.distribution.infinispan; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; +import java.io.IOException; import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.EmbeddedCacheManager; import org.onap.policy.apex.context.ContextException; -import org.onap.policy.apex.model.utilities.ResourceUtils; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -53,31 +50,16 @@ public class InfinispanManager { setSystemProperties(infinispanDistributorParameters); - // First, try and open a local input stream for Infinispan configuration - InputStream infinispanConfigStream = - getLocalInfinispanConfigurationStream(infinispanDistributorParameters.getConfigFile()); - - // Check if a local file was found, if not then go to the class path - if (infinispanConfigStream == null) { - // If a local file is not specified, then check for an infinispan configuration file on - // the class path - infinispanConfigStream = - getClasspathInfinispanConfigurationStream(infinispanDistributorParameters.getConfigFile()); - } - - // Check if we found configuration for Infinispan - if (infinispanConfigStream == null) { + try { + LOGGER.debug("starting infinispan cache manager using specified configuration . . ."); + cacheManager = new DefaultCacheManager(infinispanDistributorParameters.getConfigFile()); + LOGGER.debug("started infinispan cache manager using specified configuration"); + } catch (final IOException ioException) { final String errorMessage = "failed to start infinispan cache manager, no infinispan configuration found on local file system or in classpath, " + "try setting Infinspan \"configFile\" parameter"; LOGGER.error(errorMessage); - throw new ContextException(errorMessage); - } - - try { - LOGGER.debug("starting infinispan cache manager using specified configuration . . ."); - cacheManager = new DefaultCacheManager(infinispanConfigStream); - LOGGER.debug("started infinispan cache manager using specified configuration"); + throw new ContextException(errorMessage, ioException); } catch (final Exception e) { LOGGER.error("failed to start infinispan cache manager using specified configuration", e); throw new ContextException("failed to start infinispan cache manager using specified configuration", e); @@ -124,62 +106,6 @@ public class InfinispanManager { } /** - * Get an Infinispan configuration stream from the local file system. - * - * @param infinispanConfigFileName The file name to open - * @return The file opened as a stream - * @throws ContextException If the local file could not be found or is invalid - */ - private InputStream getLocalInfinispanConfigurationStream(final String infinispanConfigFileName) - throws ContextException { - LOGGER.debug("checking infinispan configuration file exists at \"" + infinispanConfigFileName + "\". . ."); - - // Check if the file exists - final File infinispanConfigFile = new File(infinispanConfigFileName); - if (!infinispanConfigFile.exists()) { - return null; - } - - // Check the file - if (!infinispanConfigFile.isFile() || !infinispanConfigFile.canRead()) { - LOGGER.error("infinispan configuration file at \"" + infinispanConfigFileName - + "\" does not exist or is invalid"); - throw new ContextException("infinispan configuration file at \"" + infinispanConfigFileName - + "\" does not exist or is invalid"); - } - - try { - final InputStream infinispanConfigStream = new FileInputStream(infinispanConfigFile); - LOGGER.debug("infinispan configuration file exists at \"" + infinispanConfigFileName + "\""); - return infinispanConfigStream; - } catch (final Exception e) { - LOGGER.error("infinispan configuration file at \"" + infinispanConfigFileName - + "\" does not exist or is invalid", e); - throw new ContextException("infinispan configuration file at \"" + infinispanConfigFileName - + "\" does not exist or is invalid", e); - } - } - - /** - * Get an Infinispan configuration stream from the class path. - * - * @param apexInfinispanConfigFile the apex infinispan config file - * @return The file opened as a stream - */ - private InputStream getClasspathInfinispanConfigurationStream(final String apexInfinispanConfigFile) { - LOGGER.debug( - "checking infinispan configuration file exists at resource \"" + apexInfinispanConfigFile + "\". . ."); - final InputStream infinispanConfigStream = ResourceUtils.getResourceAsStream(apexInfinispanConfigFile); - - if (infinispanConfigStream != null) { - LOGGER.debug("infinispan configuration file exists at resource \"" + apexInfinispanConfigFile + "\""); - } else { - LOGGER.debug("infinispan configuration file at resource \"" + apexInfinispanConfigFile + "\" not found"); - } - return infinispanConfigStream; - } - - /** * Private class to implement the shutdown hook for this infinispan manager. */ public class InfinspanManagerShutdownHook extends Thread { diff --git a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java b/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java index d0cc842fd..477a010fa 100644 --- a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java +++ b/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java @@ -105,6 +105,8 @@ public class CuratorLockManager extends AbstractLockManager { lockParameters.getZookeeperConnectSleepTime() * lockParameters.getZookeeperContextRetries(), TimeUnit.MILLISECONDS); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.warn("could not connect to Zookeeper server at \"" + curatorZookeeperAddress + "\", wait for connection timed out"); throw new ContextException("could not connect to Zookeeper server at \"" + curatorZookeeperAddress diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java index dd55f447d..22152a8da 100644 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java +++ b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java @@ -90,7 +90,7 @@ public class AvroObjectMapperFactory { if (Schema.Type.NULL.equals(schema.getType())) { schema = types.get(1); } - if (Schema.Type.NULL.equals(schema.getType()) || Schema.Type.NULL.equals(schema.getType())) { + if (Schema.Type.NULL.equals(schema.getType())) { final String resultSting = userKey.getID() + ": Apex currently only supports UNION schema2 with 2 options, only one can be NULL, and the other cannot be another UNION"; LOGGER.warn(resultSting); diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java index 2543dd154..b4cc38602 100644 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java +++ b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java @@ -127,19 +127,42 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { return object; } - // Check that the incoming object is a string, the incoming object must be a string - // containing Json - String objectString; + String objectString = getStringObject(object); + + // Translate illegal characters in incoming JSON keys to legal Avro values + objectString = AvroSchemaKeyTranslationUtilities.translateIllegalKeys(objectString, false); + + // Decode the object + Object decodedObject; try { - if (object == null) { - objectString = null; - } - if (object != null && avroSchema.getType().equals(Schema.Type.STRING)) { - objectString = object.toString().trim(); + final JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(avroSchema, objectString); + decodedObject = new GenericDatumReader<GenericRecord>(avroSchema).read(null, jsonDecoder); + } catch (final Exception e) { + final String returnString = getUserKey().getID() + ": object \"" + objectString + + "\" Avro unmarshalling failed: " + e.getMessage(); + LOGGER.warn(returnString, e); + throw new ContextRuntimeException(returnString, e); + } + + // Now map the decoded object into something we can handle + return avroObjectMapper.mapFromAvro(decodedObject); + } + + /** + * Check that the incoming object is a string, the incoming object must be a string containing + * Json + * + * @param object incoming object + * @return object as String + */ + private String getStringObject(final Object object) { + try { + if (isObjectString(object)) { + String objectString = object.toString().trim(); if (objectString.length() == 0) { - objectString = "\"\""; + return "\"\""; } else if (objectString.length() == 1) { - objectString = "\"" + objectString + "\""; + return "\"" + objectString + "\""; } else { // All strings must be quoted for decoding if (objectString.charAt(0) != '"') { @@ -149,35 +172,22 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { objectString += '"'; } } + return objectString; } else { - objectString = (String) object; + return (String) object; } } catch (final ClassCastException e) { - final String returnString = getUserKey().getID() + ": object \"" + object.toString() + "\" of type \"" - + object.getClass().getCanonicalName() + "\" must be assignable to \"" + final String returnString = getUserKey().getID() + ": object \"" + object + "\" of type \"" + + (object != null ? object.getClass().getCanonicalName() : "null") + "\" must be assignable to \"" + getSchemaClass().getCanonicalName() + "\" or be a Json string representation of it for Avro unmarshalling"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } + } - // Translate illegal characters in incoming JSON keys to legal Avro values - objectString = AvroSchemaKeyTranslationUtilities.translateIllegalKeys(objectString, false); - - // Decode the object - Object decodedObject; - try { - final JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(avroSchema, objectString); - decodedObject = new GenericDatumReader<GenericRecord>(avroSchema).read(null, jsonDecoder); - } catch (final Exception e) { - final String returnString = getUserKey().getID() + ": object \"" + objectString - + "\" Avro unmarshalling failed: " + e.getMessage(); - LOGGER.warn(returnString, e); - throw new ContextRuntimeException(returnString, e); - } - - // Now map the decoded object into something we can handle - return avroObjectMapper.mapFromAvro(decodedObject); + private boolean isObjectString(final Object object) { + return object != null && avroSchema.getType().equals(Schema.Type.STRING); } @Override @@ -185,21 +195,25 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { // Condition the object for Avro encoding final Object conditionedObject = avroObjectMapper.mapToAvro(object); - final ByteArrayOutputStream output = new ByteArrayOutputStream(); - try { + final String jsonString = getJsonString(object, conditionedObject); + + return AvroSchemaKeyTranslationUtilities.translateIllegalKeys(jsonString, true); + } + + private String getJsonString(final Object object, final Object conditionedObject) { + + try (final ByteArrayOutputStream output = new ByteArrayOutputStream();) { final DatumWriter<Object> writer = new GenericDatumWriter<>(avroSchema); final JsonEncoder jsonEncoder = EncoderFactory.get().jsonEncoder(avroSchema, output, true); writer.write(conditionedObject, jsonEncoder); jsonEncoder.flush(); - output.close(); + return new String(output.toByteArray()); } catch (final Exception e) { final String returnString = getUserKey().getID() + ": object \"" + object + "\" Avro marshalling failed: " + e.getMessage(); LOGGER.warn(returnString); throw new ContextRuntimeException(returnString, e); } - - return AvroSchemaKeyTranslationUtilities.translateIllegalKeys(new String(output.toByteArray()), true); } @Override diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/pom.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/pom.xml new file mode 100644 index 000000000..61abf52b4 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/pom.xml @@ -0,0 +1,54 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId> + <artifactId>plugins-event-carrier</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>plugins-event-carrier-jms</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] Plugin for handling events being transported over JMS</description> + + <properties> + <apex-plugins-event-carrier-jms-dir>${project.basedir}/src</apex-plugins-event-carrier-jms-dir> + </properties> + + <dependencies> + <dependency> + <groupId>org.jboss</groupId> + <artifactId>jboss-remote-naming</artifactId> + <version>2.0.4.Final</version> + </dependency> + <dependency> + <groupId>org.jboss.xnio</groupId> + <artifactId>xnio-nio</artifactId> + <version>3.2.0.Final</version> + </dependency> + <dependency> + <groupId>org.hornetq</groupId> + <artifactId>hornetq-jms-client</artifactId> + <version>2.3.25.Final</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSConsumer.java new file mode 100644 index 000000000..745a1e98c --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSConsumer.java @@ -0,0 +1,295 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.jms; + +import java.util.EnumMap; +import java.util.Map; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.Session; +import javax.jms.Topic; +import javax.naming.InitialContext; + +import org.onap.policy.apex.core.infrastructure.threading.ApplicationThreadFactory; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.service.engine.event.ApexEventConsumer; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class implements an Apex event consumer that receives events using JMS. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexJMSConsumer implements MessageListener, ApexEventConsumer, Runnable { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexJMSConsumer.class); + + // The Apex and JMS parameters read from the parameter service + private JMSCarrierTechnologyParameters jmsConsumerProperties; + + // The event receiver that will receive events from this consumer + private ApexEventReceiver eventReceiver; + + // The consumer thread and stopping flag + private Thread consumerThread; + private boolean stopOrderedFlag = false; + + // The connection to the JMS server + private Connection connection; + + // The topic on which we receive events from JMS + private Topic jmsIncomingTopic; + + // The name for this consumer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + @Override + public void init(final String consumerName, final EventHandlerParameters consumerParameters, + final ApexEventReceiver incomingEventReceiver) throws ApexEventException { + this.eventReceiver = incomingEventReceiver; + + this.name = consumerName; + + // Check and get the JMS Properties + if (!(consumerParameters.getCarrierTechnologyParameters() instanceof JMSCarrierTechnologyParameters)) { + final String errorMessage = "specified consumer properties of type \"" + + consumerParameters.getCarrierTechnologyParameters().getClass().getCanonicalName() + + "\" are not applicable to a JMS consumer"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + jmsConsumerProperties = (JMSCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); + + // Look up the JMS connection factory + InitialContext jmsContext = null; + ConnectionFactory connectionFactory = null; + try { + jmsContext = new InitialContext(jmsConsumerProperties.getJMSConsumerProperties()); + connectionFactory = (ConnectionFactory) jmsContext.lookup(jmsConsumerProperties.getConnectionFactory()); + + // Check if we actually got a connection factory + if (connectionFactory == null) { + throw new NullPointerException( + "JMS context lookup of \"" + jmsConsumerProperties.getConnectionFactory() + "\" returned null"); + } + } catch (final Exception e) { + final String errorMessage = "lookup of JMS connection factory \"" + + jmsConsumerProperties.getConnectionFactory() + "\" failed for JMS consumer properties \"" + + jmsConsumerProperties.getJMSConsumerProperties() + "\""; + LOGGER.warn(errorMessage, e); + throw new ApexEventException(errorMessage, e); + } + + // Lookup the topic on which we will receive events + try { + jmsIncomingTopic = (Topic) jmsContext.lookup(jmsConsumerProperties.getConsumerTopic()); + + // Check if we actually got a topic + if (jmsIncomingTopic == null) { + throw new NullPointerException( + "JMS context lookup of \"" + jmsConsumerProperties.getConsumerTopic() + "\" returned null"); + } + } catch (final Exception e) { + final String errorMessage = "lookup of JMS topic \"" + jmsConsumerProperties.getConsumerTopic() + + "\" failed for JMS consumer properties \"" + jmsConsumerProperties.getJMSConsumerProperties() + + "\""; + LOGGER.warn(errorMessage, e); + throw new ApexEventException(errorMessage, e); + } + + // Create and start a connection to the JMS server + try { + connection = connectionFactory.createConnection(jmsConsumerProperties.getSecurityPrincipal(), + jmsConsumerProperties.getSecurityCredentials()); + connection.start(); + } catch (final Exception e) { + final String errorMessage = "connection to the JMS server failed for JMS properties \"" + + jmsConsumerProperties.getJMSConsumerProperties() + "\""; + LOGGER.warn(errorMessage, e); + throw new ApexEventException(errorMessage, e); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#start() + */ + @Override + public void start() { + // Configure and start the event reception thread + final String threadName = this.getClass().getName() + ":" + this.name; + consumerThread = new ApplicationThreadFactory(threadName).newThread(this); + consumerThread.setDaemon(true); + consumerThread.start(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#setPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + // JMS session and message consumer for receiving messages + Session jmsSession = null; + MessageConsumer messageConsumer = null; + + // Create a session to the JMS server + try { + jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + } catch (final Exception e) { + final String errorMessage = "failed to create a JMS session towards the JMS server for receiving messages"; + LOGGER.warn(errorMessage, e); + throw new ApexEventRuntimeException(errorMessage, e); + } + + // Create a message consumer for reception of messages and set this class as a message listener + try { + messageConsumer = jmsSession.createConsumer(jmsIncomingTopic); + messageConsumer.setMessageListener(this); + } catch (final Exception e) { + final String errorMessage = "failed to create a JMS message consumer for receiving messages"; + LOGGER.warn(errorMessage, e); + throw new ApexEventRuntimeException(errorMessage, e); + } + + // Everything is now set up + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("event receiver " + this.getClass().getName() + ":" + this.name + " subscribed to JMS topic: " + + jmsConsumerProperties.getConsumerTopic()); + } + + // The endless loop that receives events over JMS + while (consumerThread.isAlive() && !stopOrderedFlag) { + ThreadUtilities.sleep(jmsConsumerProperties.getConsumerWaitTime()); + } + + // Close the message consumer + try { + messageConsumer.close(); + } catch (final Exception e) { + final String errorMessage = "failed to close the JMS message consumer for receiving messages"; + LOGGER.warn(errorMessage, e); + } + + // Close the session + try { + jmsSession.close(); + } catch (final Exception e) { + final String errorMessage = "failed to close the JMS session for receiving messages"; + LOGGER.warn(errorMessage, e); + } + } + + /* + * (non-Javadoc) + * + * @see javax.jms.MessageListener#onMessage(javax.jms.Message) + */ + @Override + public void onMessage(final Message jmsMessage) { + try { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("event received for {} for forwarding to Apex engine : {} {}", + this.getClass().getName() + ":" + this.name, jmsMessage.getJMSMessageID(), + jmsMessage.getJMSType()); + } + + eventReceiver.receiveEvent(jmsMessage); + } catch (final Exception e) { + final String errorMessage = "failed to receive message from JMS"; + LOGGER.warn(errorMessage, e); + throw new ApexEventRuntimeException(errorMessage, e); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.producer.ApexEventProducer#stop() + */ + @Override + public void stop() { + stopOrderedFlag = true; + + while (consumerThread.isAlive()) { + ThreadUtilities.sleep(jmsConsumerProperties.getConsumerWaitTime()); + } + + // Close the connection to the JMS server + try { + if (connection != null) { + connection.close(); + } + } catch (final Exception e) { + final String errorMessage = "close of connection to the JMS server failed"; + LOGGER.warn(errorMessage, e); + } + } + +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSProducer.java new file mode 100644 index 000000000..017f07f6f --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSProducer.java @@ -0,0 +1,289 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.jms; + +import java.io.Serializable; +import java.util.EnumMap; +import java.util.Map; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Message; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.Topic; +import javax.naming.InitialContext; + +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Concrete implementation of an Apex event producer that sends events using JMS. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexJMSProducer implements ApexEventProducer { + + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexJMSProducer.class); + + // The JMS parameters read from the parameter service + private JMSCarrierTechnologyParameters jmsProducerProperties; + + // The connection to the JMS server + private Connection connection; + + // The topic on which we send events to JMS + private Topic jmsOutgoingTopic; + + // The JMS session on which we will send events + private Session jmsSession; + + // The producer on which we will send events + private MessageProducer messageProducer; + + // The name for this producer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#init(java.lang.String, + * org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters) + */ + @Override + public void init(final String producerName, final EventHandlerParameters producerParameters) + throws ApexEventException { + this.name = producerName; + + // Check and get the JMS Properties + if (!(producerParameters.getCarrierTechnologyParameters() instanceof JMSCarrierTechnologyParameters)) { + LOGGER.warn("specified producer properties are not applicable to a JMS producer (" + this.name + ")"); + throw new ApexEventException( + "specified producer properties are not applicable to a JMS producer (" + this.name + ")"); + } + jmsProducerProperties = (JMSCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + + // Look up the JMS connection factory + InitialContext jmsContext = null; + ConnectionFactory connectionFactory = null; + try { + jmsContext = new InitialContext(jmsProducerProperties.getJMSProducerProperties()); + connectionFactory = (ConnectionFactory) jmsContext.lookup(jmsProducerProperties.getConnectionFactory()); + + // Check if we actually got a connection factory + if (connectionFactory == null) { + throw new NullPointerException("JMS context lookup of \"" + jmsProducerProperties.getConnectionFactory() + + "\" returned null for producer (" + this.name + ")"); + } + } catch (final Exception e) { + final String errorMessage = "lookup of JMS connection factory \"" + + jmsProducerProperties.getConnectionFactory() + "\" failed for JMS producer properties \"" + + jmsProducerProperties.getJMSConsumerProperties() + "\" for producer (" + this.name + ")"; + LOGGER.warn(errorMessage, e); + throw new ApexEventException(errorMessage, e); + } + + // Lookup the topic on which we will send events + try { + jmsOutgoingTopic = (Topic) jmsContext.lookup(jmsProducerProperties.getProducerTopic()); + + // Check if we actually got a topic + if (jmsOutgoingTopic == null) { + throw new NullPointerException("JMS context lookup of \"" + jmsProducerProperties.getProducerTopic() + + "\" returned null for producer (" + this.name + ")"); + } + } catch (final Exception e) { + final String errorMessage = "lookup of JMS topic \"" + jmsProducerProperties.getProducerTopic() + + "\" failed for JMS producer properties \"" + jmsProducerProperties.getJMSProducerProperties() + + "\" for producer (" + this.name + ")"; + LOGGER.warn(errorMessage, e); + throw new ApexEventException(errorMessage, e); + } + + // Create and start a connection to the JMS server + try { + connection = connectionFactory.createConnection(jmsProducerProperties.getSecurityPrincipal(), + jmsProducerProperties.getSecurityCredentials()); + connection.start(); + } catch (final Exception e) { + final String errorMessage = "connection to JMS server failed for JMS properties \"" + + jmsProducerProperties.getJMSConsumerProperties() + "\" for producer (" + this.name + ")"; + LOGGER.warn(errorMessage, e); + throw new ApexEventException(errorMessage, e); + } + + // Create a JMS session for sending events + try { + jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + } catch (final Exception e) { + final String errorMessage = "creation of session to JMS server failed for JMS properties \"" + + jmsProducerProperties.getJMSConsumerProperties() + "\" for producer (" + this.name + ")"; + LOGGER.warn(errorMessage, e); + throw new ApexEventException(errorMessage, e); + } + + // Create a JMS message producer for sending events + try { + messageProducer = jmsSession.createProducer(jmsOutgoingTopic); + } catch (final Exception e) { + final String errorMessage = + "creation of producer for sending events to JMS server failed for JMS properties \"" + + jmsProducerProperties.getJMSConsumerProperties() + "\""; + LOGGER.warn(errorMessage, e); + throw new ApexEventException(errorMessage, e); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#setPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#sendEvent(long, java.lang.String, + * java.lang.Object) + */ + @Override + public void sendEvent(final long executionId, final String eventname, final Object eventObject) { + // Check if this is a synchronized event, if so we have received a reply + final SynchronousEventCache synchronousEventCache = + (SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS); + if (synchronousEventCache != null) { + synchronousEventCache.removeCachedEventToApexIfExists(executionId); + } + + // Check if the object to be sent is serializable + if (!Serializable.class.isAssignableFrom(eventObject.getClass())) { + final String errorMessage = "could not send event \"" + eventname + "\" on JMS message producer " + + this.name + ", object of type \"" + eventObject.getClass().getCanonicalName() + + "\" is not serializable"; + LOGGER.warn(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + + // The JMS message to send is constructed using the JMS session + Message jmsMessage = null; + + // Check the type of JMS message to send + if (jmsProducerProperties.isObjectMessageSending()) { + // We should send a JMS Object Message + try { + jmsMessage = jmsSession.createObjectMessage((Serializable) eventObject); + } catch (final Exception e) { + final String errorMessage = "could not send event \"" + eventname + "\" on JMS message producer " + + this.name + ", could not create JMS Object Message for object \"" + eventObject; + LOGGER.warn(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + } else { + // We should send a JMS Text Message + try { + jmsMessage = jmsSession.createTextMessage(eventObject.toString()); + } catch (final Exception e) { + final String errorMessage = "could not send event \"" + eventname + "\" on JMS message producer " + + this.name + ", could not create JMS Text Message for object \"" + eventObject; + LOGGER.warn(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + } + + try { + messageProducer.send(jmsMessage); + } catch (final Exception e) { + final String errorMessage = "could not send event \"" + eventname + "\" on JMS message producer " + + this.name + ", send failed for object \"" + eventObject; + LOGGER.warn(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.producer.ApexEventProducer#stop() + */ + @Override + public void stop() { + // Close the message producer + try { + messageProducer.close(); + } catch (final Exception e) { + final String errorMessage = "failed to close JMS message producer " + this.name + " for sending messages"; + LOGGER.warn(errorMessage, e); + } + + // Close the session + try { + jmsSession.close(); + } catch (final Exception e) { + final String errorMessage = "failed to close the JMS session for " + this.name + " for sending messages"; + LOGGER.warn(errorMessage, e); + } + + // Close the connection to the JMS server + try { + connection.close(); + } catch (final Exception e) { + final String errorMessage = "close of connection to the JMS server for " + this.name + " failed"; + LOGGER.warn(errorMessage, e); + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/JMSCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/JMSCarrierTechnologyParameters.java new file mode 100644 index 000000000..48f5fe267 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/JMSCarrierTechnologyParameters.java @@ -0,0 +1,368 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.jms; + +import java.util.Properties; + +import javax.naming.Context; + +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; + +/** + * Apex parameters for JMS as an event carrier technology. + * <p> + * The parameters for this plugin are: + * <ol> + * <li>initialContextFactory: JMS uses a naming {@link Context} object to look up the locations of JMS servers and JMS + * topics. An Initial Context Factory is used to when creating a {@link Context} object that can be used for JMS + * lookups. The value of this parameter is passed to the {@link Context} with the label + * {@link Context#INITIAL_CONTEXT_FACTORY}. Its value must be the full canonical path to a class that implements the + * {@code javax.naming.spi.InitialContextFactory} interface. The parameter defaults to the string value + * {@code org.jboss.naming.remote.client.InitialContextFactory}. + * <li>providerURL: The location of the server to use for naming context lookups. The value of this parameter is passed + * to the {@link Context} with the label {@link Context#PROVIDER_URL}. Its value must be a URL that identifies the JMS + * naming server. The parameter defaults to the string value {@code remote://localhost:4447}. + * <li>securityPrincipal: The user name to use for JMS access. The value of this parameter is passed to the + * {@link Context} with the label {@link Context#SECURITY_PRINCIPAL}. Its value must be the user name of a user defined + * on the JMS server. The parameter defaults to the string value {@code userid}. + * <li>securityCredentials:The password to use for JMS access. The value of this parameter is passed to the + * {@link Context} with the label {@link Context#SECURITY_CREDENTIALS}. Its value must be the password of a suer defined + * on the JMS server. The parameter defaults to the string value {@code password}. + * <li>connectionFactory: JMS uses a {@link javax.jms.ConnectionFactory} instance to create connections towards a JMS + * server. The connection factory to use is held in the JMS {@link Context} object. This parameter specifies the label + * to use to look up the {@link javax.jms.ConnectionFactory} instance from the JMS {@link Context}. + * <li>producerTopic: JMS uses a {@link javax.jms.Topic} instance to for sending and receiving messages. The topic to + * use for sending events to JMS from an Apex producer is held in the JMS {@link Context} object. This parameter + * specifies the label to use to look up the {@link javax.jms.Topic} instance in the JMS {@link Context} for the JMS + * server. The topic must, of course, also be defined on the JMS server. The parameter defaults to the string value + * {@code apex-out}. + * <li>consumerTopic: The topic to use for receiving events from JMS in an Apex consumer is held in the JMS + * {@link Context} object. This parameter specifies the label to use to look up the {@link javax.jms.Topic} instance in + * the JMS {@link Context} for the JMS server. The topic must, of course, also be defined on the JMS server. The + * parameter defaults to the string value {@code apex-in}. + * <li>consumerWaitTime: The amount of milliseconds a JMS consumer should wait between checks of its thread execution + * status. The parameter defaults to the long value {@code 100}. + * <li>objectMessageSending: A flag that indicates whether Apex producers should send JMS messages as + * {@link javax.jms.ObjectMessage} instances for java objects (value {@code true}) or as {@link javax.jms.TextMessage} + * instances for strings (value {@code false}) . The parameter defaults to the boolean value {@code true}. + * </ol> + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class JMSCarrierTechnologyParameters extends CarrierTechnologyParameters { + /** The label of this carrier technology. */ + public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS"; + + /** The producer plugin class for the JMS carrier technology. */ + public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = ApexJMSProducer.class.getCanonicalName(); + + /** The consumer plugin class for the JMS carrier technology. */ + public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJMSConsumer.class.getCanonicalName(); + + // @formatter:off + + // Default parameter values + private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory"; + private static final String DEFAULT_INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory"; + private static final String DEFAULT_PROVIDER_URL = "remote://localhost:4447"; + private static final String DEFAULT_SECURITY_PRINCIPAL = "userid"; + private static final String DEFAULT_SECURITY_CREDENTIALS = "password"; + private static final String DEFAULT_CONSUMER_TOPIC = "apex-in"; + private static final String DEFAULT_PRODUCER_TOPIC = "apex-out"; + private static final int DEFAULT_CONSUMER_WAIT_TIME = 100; + private static final boolean DEFAULT_TO_OBJECT_MESSAGE_SENDING = true; + + // Parameter property map tokens + private static final String PROPERTY_INITIAL_CONTEXT_FACTORY = Context.INITIAL_CONTEXT_FACTORY; + private static final String PROPERTY_PROVIDER_URL = Context.PROVIDER_URL; + private static final String PROPERTY_SECURITY_PRINCIPAL = Context.SECURITY_PRINCIPAL; + private static final String PROPERTY_SECURITY_CREDENTIALS = Context.SECURITY_CREDENTIALS; + + // JMS carrier parameters + private String connectionFactory = DEFAULT_CONNECTION_FACTORY; + private String initialContextFactory = DEFAULT_INITIAL_CONTEXT_FACTORY; + private String providerURL = DEFAULT_PROVIDER_URL; + private String securityPrincipal = DEFAULT_SECURITY_PRINCIPAL; + private String securityCredentials = DEFAULT_SECURITY_CREDENTIALS; + private String producerTopic = DEFAULT_PRODUCER_TOPIC; + private String consumerTopic = DEFAULT_CONSUMER_TOPIC; + private int consumerWaitTime = DEFAULT_CONSUMER_WAIT_TIME; + private boolean objectMessageSending = DEFAULT_TO_OBJECT_MESSAGE_SENDING; + // @formatter:on + + /** + * Constructor to create a jms carrier technology parameters instance and register the instance with the parameter + * service. + */ + public JMSCarrierTechnologyParameters() { + super(JMSCarrierTechnologyParameters.class.getCanonicalName()); + + // Set the carrier technology properties for the JMS carrier technology + this.setLabel(JMS_CARRIER_TECHNOLOGY_LABEL); + this.setEventProducerPluginClass(JMS_EVENT_PRODUCER_PLUGIN_CLASS); + this.setEventConsumerPluginClass(JMS_EVENT_CONSUMER_PLUGIN_CLASS); + } + + /** + * Gets the JMS producer properties. + * + * @return the JMS producer properties + */ + public Properties getJMSProducerProperties() { + final Properties jmsProperties = new Properties(); + + jmsProperties.put(PROPERTY_INITIAL_CONTEXT_FACTORY, initialContextFactory); + jmsProperties.put(PROPERTY_PROVIDER_URL, providerURL); + jmsProperties.put(PROPERTY_SECURITY_PRINCIPAL, securityPrincipal); + jmsProperties.put(PROPERTY_SECURITY_CREDENTIALS, securityCredentials); + + return jmsProperties; + } + + /** + * Gets the jms consumer properties. + * + * @return the jms consumer properties + */ + public Properties getJMSConsumerProperties() { + final Properties jmsProperties = new Properties(); + + jmsProperties.put(PROPERTY_INITIAL_CONTEXT_FACTORY, initialContextFactory); + jmsProperties.put(PROPERTY_PROVIDER_URL, providerURL); + jmsProperties.put(PROPERTY_SECURITY_PRINCIPAL, securityPrincipal); + jmsProperties.put(PROPERTY_SECURITY_CREDENTIALS, securityCredentials); + + return jmsProperties; + } + + /** + * Gets the connection factory. + * + * @return the connection factory + */ + public String getConnectionFactory() { + return connectionFactory; + } + + /** + * Gets the initial context factory. + * + * @return the initial context factory + */ + public String getInitialContextFactory() { + return initialContextFactory; + } + + /** + * Gets the provider URL. + * + * @return the provider URL + */ + public String getProviderURL() { + return providerURL; + } + + /** + * Gets the security principal. + * + * @return the security principal + */ + public String getSecurityPrincipal() { + return securityPrincipal; + } + + /** + * Gets the security credentials. + * + * @return the security credentials + */ + public String getSecurityCredentials() { + return securityCredentials; + } + + /** + * Gets the producer topic. + * + * @return the producer topic + */ + public String getProducerTopic() { + return producerTopic; + } + + /** + * Gets the consumer topic. + * + * @return the consumer topic + */ + public String getConsumerTopic() { + return consumerTopic; + } + + /** + * Gets the consumer wait time. + * + * @return the consumer wait time + */ + public long getConsumerWaitTime() { + return consumerWaitTime; + } + + /** + * Sets the connection factory. + * + * @param connectionFactory the connection factory + */ + public void setConnectionFactory(final String connectionFactory) { + this.connectionFactory = connectionFactory; + } + + /** + * Sets the initial context factory. + * + * @param initialContextFactory the initial context factory + */ + public void setInitialContextFactory(final String initialContextFactory) { + this.initialContextFactory = initialContextFactory; + } + + /** + * Sets the provider URL. + * + * @param providerURL the provider URL + */ + public void setProviderURL(final String providerURL) { + this.providerURL = providerURL; + } + + /** + * Sets the security principal. + * + * @param securityPrincipal the security principal + */ + public void setSecurityPrincipal(final String securityPrincipal) { + this.securityPrincipal = securityPrincipal; + } + + /** + * Sets the security credentials. + * + * @param securityCredentials the security credentials + */ + public void setSecurityCredentials(final String securityCredentials) { + this.securityCredentials = securityCredentials; + } + + /** + * Sets the producer topic. + * + * @param producerTopic the producer topic + */ + public void setProducerTopic(final String producerTopic) { + this.producerTopic = producerTopic; + } + + /** + * Sets the consumer topic. + * + * @param consumerTopic the consumer topic + */ + public void setConsumerTopic(final String consumerTopic) { + this.consumerTopic = consumerTopic; + } + + /** + * Sets the consumer wait time. + * + * @param consumerWaitTime the consumer wait time + */ + public void setConsumerWaitTime(final int consumerWaitTime) { + this.consumerWaitTime = consumerWaitTime; + } + + /** + * Checks if is object message sending. + * + * @return true, if checks if is object message sending + */ + public boolean isObjectMessageSending() { + return objectMessageSending; + } + + /** + * Sets the object message sending. + * + * @param objectMessageSending the object message sending + */ + public void setObjectMessageSending(final boolean objectMessageSending) { + this.objectMessageSending = objectMessageSending; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate() + */ + @Override + public String validate() { + final StringBuilder errorMessageBuilder = new StringBuilder(); + + errorMessageBuilder.append(super.validate()); + + if (initialContextFactory == null || initialContextFactory.trim().length() == 0) { + errorMessageBuilder + .append(" initialContextFactory not specified, must be specified as a string that is a class" + + " that implements the interface org.jboss.naming.remote.client.InitialContextFactory\n"); + } + + if (providerURL == null || providerURL.trim().length() == 0) { + errorMessageBuilder.append( + " providerURL not specified, must be specified as a URL string that specifies the location of " + + "configuration information for the service provider to use such as remote://localhost:4447\n"); + } + + if (securityPrincipal == null || securityPrincipal.trim().length() == 0) { + errorMessageBuilder.append( + " securityPrincipal not specified, must be specified the identity of the principal for authenticating the caller to the service\n"); + } + + if (securityCredentials == null || securityCredentials.trim().length() == 0) { + errorMessageBuilder.append(" securityCredentials not specified, must be specified as " + + "the credentials of the principal for authenticating the caller to the service\n"); + } + + if (producerTopic == null || producerTopic.trim().length() == 0) { + errorMessageBuilder.append( + " producerTopic not specified, must be a string that identifies the JMS topic on which Apex will send events\n"); + } + + if (consumerTopic == null || consumerTopic.trim().length() == 0) { + errorMessageBuilder.append( + " consumerTopic not specified, must be a string that identifies the JMS topic on which Apex will recieve events\n"); + } + + if (consumerWaitTime < 0) { + errorMessageBuilder.append(" consumerWaitTime [" + consumerWaitTime + + "] invalid, must be specified as consumerWaitTime >= 0\n"); + } + + return errorMessageBuilder.toString(); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/package-info.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/package-info.java new file mode 100644 index 000000000..115bc5009 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============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========================================================= + */ + +/** + * Implements the APEX event carrier technology plugin for JMS. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ + +package org.onap.policy.apex.plugins.event.carrier.jms; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/pom.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/pom.xml new file mode 100644 index 000000000..cd015bb64 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/pom.xml @@ -0,0 +1,44 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId> + <artifactId>plugins-event-carrier</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>plugins-event-carrier-kafka</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] Plugin for handling events being transported over Kafka</description> + + <properties> + <apex-plugins-event-carrier-kafka-dir>${project.basedir}/src</apex-plugins-event-carrier-kafka-dir> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.kafka</groupId> + <artifactId>kafka-clients</artifactId> + <version>0.10.2.1</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumer.java new file mode 100644 index 000000000..3351a58e9 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumer.java @@ -0,0 +1,198 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.kafka; + +import java.util.EnumMap; +import java.util.Map; + +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.onap.policy.apex.core.infrastructure.threading.ApplicationThreadFactory; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.service.engine.event.ApexEventConsumer; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class implements an Apex event consumer that receives events using Kafka. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexKafkaConsumer implements ApexEventConsumer, Runnable { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexKafkaConsumer.class); + + // The Kafka parameters read from the parameter service + private KAFKACarrierTechnologyParameters kafkaConsumerProperties; + + // The event receiver that will receive events from this consumer + private ApexEventReceiver eventReceiver; + + // The Kafka consumer used to receive events using Kafka + private KafkaConsumer<String, String> kafkaConsumer; + + // The name for this consumer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + // The consumer thread and stopping flag + private Thread consumerThread; + private boolean stopOrderedFlag = false; + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#init(java.lang.String, + * org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters, + * org.onap.policy.apex.service.engine.event.ApexEventReceiver) + */ + @Override + public void init(final String consumerName, final EventHandlerParameters consumerParameters, + final ApexEventReceiver incomingEventReceiver) throws ApexEventException { + this.eventReceiver = incomingEventReceiver; + this.name = consumerName; + + // Check and get the Kafka Properties + if (!(consumerParameters.getCarrierTechnologyParameters() instanceof KAFKACarrierTechnologyParameters)) { + LOGGER.warn("specified consumer properties of type \"" + + consumerParameters.getCarrierTechnologyParameters().getClass().getCanonicalName() + + "\" are not applicable to a Kafka consumer"); + throw new ApexEventException("specified consumer properties of type \"" + + consumerParameters.getCarrierTechnologyParameters().getClass().getCanonicalName() + + "\" are not applicable to a Kafka consumer"); + } + kafkaConsumerProperties = + (KAFKACarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); + + // Kick off the Kafka consumer + kafkaConsumer = new KafkaConsumer<String, String>(kafkaConsumerProperties.getKafkaConsumerProperties()); + kafkaConsumer.subscribe(kafkaConsumerProperties.getConsumerTopicList()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("event receiver for " + this.getClass().getName() + ":" + this.name + " subscribed to topics: " + + kafkaConsumerProperties.getConsumerTopicList()); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#start() + */ + @Override + public void start() { + // Configure and start the event reception thread + final String threadName = this.getClass().getName() + ":" + this.name; + consumerThread = new ApplicationThreadFactory(threadName).newThread(this); + consumerThread.setDaemon(true); + consumerThread.start(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getPeeredReference(org.onap.policy.apex.service. + * parameters.eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#setPeeredReference(org.onap.policy.apex.service. + * parameters.eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + // Kick off the Kafka consumer + kafkaConsumer = new KafkaConsumer<String, String>(kafkaConsumerProperties.getKafkaConsumerProperties()); + kafkaConsumer.subscribe(kafkaConsumerProperties.getConsumerTopicList()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("event receiver for " + this.getClass().getName() + ":" + this.name + " subscribed to topics: " + + kafkaConsumerProperties.getConsumerTopicList()); + } + + // The endless loop that receives events over Kafka + while (consumerThread.isAlive() && !stopOrderedFlag) { + try { + final ConsumerRecords<String, String> records = + kafkaConsumer.poll(kafkaConsumerProperties.getConsumerPollTime()); + for (final ConsumerRecord<String, String> record : records) { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("event received for {} for forwarding to Apex engine : {} {}", + this.getClass().getName() + ":" + this.name, record.key(), record.value()); + } + eventReceiver.receiveEvent(record.value()); + } + } catch (final Exception e) { + LOGGER.warn("error receiving events on thread {}", consumerThread.getName(), e); + } + } + + if (!consumerThread.isInterrupted()) { + kafkaConsumer.close(); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#stop() + */ + @Override + public void stop() { + stopOrderedFlag = true; + + while (consumerThread.isAlive()) { + ThreadUtilities.sleep(kafkaConsumerProperties.getConsumerPollTime()); + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducer.java new file mode 100644 index 000000000..fb851bc70 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducer.java @@ -0,0 +1,151 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.kafka; + +import java.util.EnumMap; +import java.util.Map; + +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Concrete implementation of an Apex event producer that sends events using Kafka. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexKafkaProducer implements ApexEventProducer { + + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexKafkaProducer.class); + + // The Kafka parameters read from the parameter service + private KAFKACarrierTechnologyParameters kafkaProducerProperties; + + // The Kafka Producer used to send events using Kafka + private Producer<String, Object> kafkaProducer; + + // The name for this producer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + @Override + public void init(final String producerName, final EventHandlerParameters producerParameters) + throws ApexEventException { + this.name = producerName; + + // Check and get the Kafka Properties + if (!(producerParameters.getCarrierTechnologyParameters() instanceof KAFKACarrierTechnologyParameters)) { + LOGGER.warn("specified producer properties are not applicable to a Kafka producer (" + this.name + ")"); + throw new ApexEventException( + "specified producer properties are not applicable to a Kafka producer (" + this.name + ")"); + } + kafkaProducerProperties = + (KAFKACarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getPeeredReference(org.onap.policy.apex.service. + * parameters.eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#setPeeredReference(org.onap.policy.apex.service. + * parameters.eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.producer.ApexEventProducer#sendEvent(long, java.lang.String, + * java.lang.Object) + */ + @Override + public void sendEvent(final long executionId, final String eventName, final Object event) { + // Check if this is a synchronized event, if so we have received a reply + final SynchronousEventCache synchronousEventCache = + (SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS); + if (synchronousEventCache != null) { + synchronousEventCache.removeCachedEventToApexIfExists(executionId); + } + + // Kafka producer must be started in the same thread as it is stopped, so we must start it here + if (kafkaProducer == null) { + // Kick off the Kafka producer + kafkaProducer = new KafkaProducer<String, Object>(kafkaProducerProperties.getKafkaProducerProperties()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("event producer " + this.name + " is ready to send to topics: " + + kafkaProducerProperties.getProducerTopic()); + } + } + + kafkaProducer.send(new ProducerRecord<String, Object>(kafkaProducerProperties.getProducerTopic(), name, event)); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("event sent from engine using {} to topic {} : {} ", this.name, + kafkaProducerProperties.getProducerTopic(), event); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.producer.ApexEventProducer#stop() + */ + @Override + public void stop() { + if (kafkaProducer != null) { + kafkaProducer.flush(); + kafkaProducer.close(); + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KAFKACarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KAFKACarrierTechnologyParameters.java new file mode 100644 index 000000000..2357b1807 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KAFKACarrierTechnologyParameters.java @@ -0,0 +1,396 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.kafka; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Properties; + +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; + +/** + * Apex parameters for Kafka as an event carrier technology. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class KAFKACarrierTechnologyParameters extends CarrierTechnologyParameters { + // @formatter:off + /** The label of this carrier technology. */ + public static final String KAFKA_CARRIER_TECHNOLOGY_LABEL = "KAFKA"; + + /** The producer plugin class for the Kafka carrier technology. */ + public static final String KAFKA_EVENT_PRODUCER_PLUGIN_CLASS = ApexKafkaProducer.class.getCanonicalName(); + + /** The consumer plugin class for the Kafka carrier technology. */ + public static final String KAFKA_EVENT_CONSUMER_PLUGIN_CLASS = ApexKafkaConsumer.class.getCanonicalName(); + + // Default parameter values + private static final String DEFAULT_ACKS = "all"; + private static final String DEFAULT_BOOTSTRAP_SERVERS = "localhost:9092"; + private static final int DEFAULT_RETRIES = 0; + private static final int DEFAULT_BATCH_SIZE = 16384; + private static final int DEFAULT_LINGER_TIME = 1; + private static final long DEFAULT_BUFFER_MEMORY = 33554432; + private static final String DEFAULT_GROUP_ID = "default-group-id"; + private static final boolean DEFAULT_ENABLE_AUTO_COMMIT = true; + private static final int DEFAULT_AUTO_COMMIT_TIME = 1000; + private static final int DEFAULT_SESSION_TIMEOUT = 30000; + private static final String DEFAULT_PRODUCER_TOPIC = "apex-out"; + private static final int DEFAULT_CONSUMER_POLL_TIME = 100; + private static final String[] DEFAULT_CONSUMER_TOPIC_LIST = {"apex-in"}; + private static final String DEFAULT_KEY_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer"; + private static final String DEFAULT_VALUE_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer"; + private static final String DEFAULT_KEY_DESERIALIZER = "org.apache.kafka.common.serialization.StringDeserializer"; + private static final String DEFAULT_VALUE_DESERIALIZER = "org.apache.kafka.common.serialization.StringDeserializer"; + + // Parameter property map tokens + private static final String PROPERTY_BOOTSTRAP_SERVERS = "bootstrap.servers"; + private static final String PROPERTY_ACKS = "acks"; + private static final String PROPERTY_RETRIES = "retries"; + private static final String PROPERTY_BATCH_SIZE = "batch.size"; + private static final String PROPERTY_LINGER_TIME = "linger.ms"; + private static final String PROPERTY_BUFFER_MEMORY = "buffer.memory"; + private static final String PROPERTY_GROUP_ID = "group.id"; + private static final String PROPERTY_ENABLE_AUTO_COMMIT = "enable.auto.commit"; + private static final String PROPERTY_AUTO_COMMIT_TIME = "auto.commit.interval.ms"; + private static final String PROPERTY_SESSION_TIMEOUT = "session.timeout.ms"; + private static final String PROPERTY_KEY_SERIALIZER = "key.serializer"; + private static final String PROPERTY_VALUE_SERIALIZER = "value.serializer"; + private static final String PROPERTY_KEY_DESERIALIZER = "key.deserializer"; + private static final String PROPERTY_VALUE_DESERIALIZER = "value.deserializer"; + + // kafka carrier parameters + private String bootstrapServers = DEFAULT_BOOTSTRAP_SERVERS; + private String acks = DEFAULT_ACKS; + private int retries = DEFAULT_RETRIES; + private int batchSize = DEFAULT_BATCH_SIZE; + private int lingerTime = DEFAULT_LINGER_TIME; + private long bufferMemory = DEFAULT_BUFFER_MEMORY; + private String groupId = DEFAULT_GROUP_ID; + private boolean enableAutoCommit = DEFAULT_ENABLE_AUTO_COMMIT; + private int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME; + private int sessionTimeout = DEFAULT_SESSION_TIMEOUT; + private String producerTopic = DEFAULT_PRODUCER_TOPIC; + private int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME; + private String[] consumerTopicList = DEFAULT_CONSUMER_TOPIC_LIST; + private String keySerializer = DEFAULT_KEY_SERIALIZER; + private String valueSerializer = DEFAULT_VALUE_SERIALIZER; + private String keyDeserializer = DEFAULT_KEY_DESERIALIZER; + private String valueDeserializer = DEFAULT_VALUE_DESERIALIZER; + // @formatter:on + + /** + * Constructor to create a kafka carrier technology parameters instance and register the instance with the parameter + * service. + */ + public KAFKACarrierTechnologyParameters() { + super(KAFKACarrierTechnologyParameters.class.getCanonicalName()); + + // Set the carrier technology properties for the kafka carrier technology + this.setLabel(KAFKA_CARRIER_TECHNOLOGY_LABEL); + this.setEventProducerPluginClass(KAFKA_EVENT_PRODUCER_PLUGIN_CLASS); + this.setEventConsumerPluginClass(KAFKA_EVENT_CONSUMER_PLUGIN_CLASS); + } + + /** + * Gets the kafka producer properties. + * + * @return the kafka producer properties + */ + public Properties getKafkaProducerProperties() { + final Properties kafkaProperties = new Properties(); + + kafkaProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers); + kafkaProperties.put(PROPERTY_ACKS, acks); + kafkaProperties.put(PROPERTY_RETRIES, retries); + kafkaProperties.put(PROPERTY_BATCH_SIZE, batchSize); + kafkaProperties.put(PROPERTY_LINGER_TIME, lingerTime); + kafkaProperties.put(PROPERTY_BUFFER_MEMORY, bufferMemory); + kafkaProperties.put(PROPERTY_KEY_SERIALIZER, keySerializer); + kafkaProperties.put(PROPERTY_VALUE_SERIALIZER, valueSerializer); + + return kafkaProperties; + } + + /** + * Gets the kafka consumer properties. + * + * @return the kafka consumer properties + */ + public Properties getKafkaConsumerProperties() { + final Properties kafkaProperties = new Properties(); + + kafkaProperties.put(PROPERTY_BOOTSTRAP_SERVERS, bootstrapServers); + kafkaProperties.put(PROPERTY_GROUP_ID, groupId); + kafkaProperties.put(PROPERTY_ENABLE_AUTO_COMMIT, enableAutoCommit); + kafkaProperties.put(PROPERTY_AUTO_COMMIT_TIME, autoCommitTime); + kafkaProperties.put(PROPERTY_SESSION_TIMEOUT, sessionTimeout); + kafkaProperties.put(PROPERTY_KEY_DESERIALIZER, keyDeserializer); + kafkaProperties.put(PROPERTY_VALUE_DESERIALIZER, valueDeserializer); + + return kafkaProperties; + } + + /** + * Gets the bootstrap servers. + * + * @return the bootstrap servers + */ + public String getBootstrapServers() { + return bootstrapServers; + } + + /** + * Gets the acks. + * + * @return the acks + */ + public String getAcks() { + return acks; + } + + /** + * Gets the retries. + * + * @return the retries + */ + public int getRetries() { + return retries; + } + + /** + * Gets the batch size. + * + * @return the batch size + */ + public int getBatchSize() { + return batchSize; + } + + /** + * Gets the linger time. + * + * @return the linger time + */ + public int getLingerTime() { + return lingerTime; + } + + /** + * Gets the buffer memory. + * + * @return the buffer memory + */ + public long getBufferMemory() { + return bufferMemory; + } + + /** + * Gets the group id. + * + * @return the group id + */ + public String getGroupId() { + return groupId; + } + + /** + * Checks if is enable auto commit. + * + * @return true, if checks if is enable auto commit + */ + public boolean isEnableAutoCommit() { + return enableAutoCommit; + } + + /** + * Gets the auto commit time. + * + * @return the auto commit time + */ + public int getAutoCommitTime() { + return autoCommitTime; + } + + /** + * Gets the session timeout. + * + * @return the session timeout + */ + public int getSessionTimeout() { + return sessionTimeout; + } + + /** + * Gets the producer topic. + * + * @return the producer topic + */ + public String getProducerTopic() { + return producerTopic; + } + + /** + * Gets the consumer poll time. + * + * @return the consumer poll time + */ + public long getConsumerPollTime() { + return consumerPollTime; + } + + /** + * Gets the consumer topic list. + * + * @return the consumer topic list + */ + public Collection<String> getConsumerTopicList() { + return Arrays.asList(consumerTopicList); + } + + /** + * Gets the key serializer. + * + * @return the key serializer + */ + public String getKeySerializer() { + return keySerializer; + } + + /** + * Gets the value serializer. + * + * @return the value serializer + */ + public String getValueSerializer() { + return valueSerializer; + } + + /** + * Gets the key deserializer. + * + * @return the key deserializer + */ + public String getKeyDeserializer() { + return keyDeserializer; + } + + /** + * Gets the value deserializer. + * + * @return the value deserializer + */ + public String getValueDeserializer() { + return valueDeserializer; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate() + */ + @Override + public String validate() { + final StringBuilder errorMessageBuilder = new StringBuilder(); + + errorMessageBuilder.append(super.validate()); + + if (bootstrapServers == null || bootstrapServers.trim().length() == 0) { + errorMessageBuilder + .append(" bootstrapServers not specified, must be specified as a string of form host:port\n"); + } + + if (acks == null || acks.trim().length() == 0) { + errorMessageBuilder.append(" acks not specified, must be specified as a string with values [0|1|all]\n"); + } + + if (retries < 0) { + errorMessageBuilder.append(" retries [" + retries + "] invalid, must be specified as retries >= 0\n"); + } + + if (batchSize < 0) { + errorMessageBuilder + .append(" batchSize [" + batchSize + "] invalid, must be specified as batchSize >= 0\n"); + } + + if (lingerTime < 0) { + errorMessageBuilder + .append(" lingerTime [" + lingerTime + "] invalid, must be specified as lingerTime >= 0\n"); + } + + if (bufferMemory < 0) { + errorMessageBuilder + .append(" bufferMemory [" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0\n"); + } + + if (groupId == null || groupId.trim().length() == 0) { + errorMessageBuilder.append(" groupId not specified, must be specified as a string\n"); + } + + if (autoCommitTime < 0) { + errorMessageBuilder.append( + " autoCommitTime [" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0\n"); + } + + if (sessionTimeout < 0) { + errorMessageBuilder.append( + " sessionTimeout [" + sessionTimeout + "] invalid, must be specified as sessionTimeout >= 0\n"); + } + + if (producerTopic == null || producerTopic.trim().length() == 0) { + errorMessageBuilder.append(" producerTopic not specified, must be specified as a string\n"); + } + + if (consumerPollTime < 0) { + errorMessageBuilder.append(" consumerPollTime [" + consumerPollTime + + "] invalid, must be specified as consumerPollTime >= 0\n"); + } + + if (consumerTopicList == null || consumerTopicList.length == 0) { + errorMessageBuilder.append(" consumerTopicList not specified, must be specified as a list of strings\n"); + } + + for (final String consumerTopic : consumerTopicList) { + if (consumerTopic == null || consumerTopic.trim().length() == 0) { + errorMessageBuilder.append(" invalid consumer topic \"" + consumerTopic + + "\" specified on consumerTopicList, consumer topics must be specified as strings\n"); + } + } + + if (keySerializer == null || keySerializer.trim().length() == 0) { + errorMessageBuilder.append(" keySerializer not specified, must be specified as a string\n"); + } + + if (valueSerializer == null || valueSerializer.trim().length() == 0) { + errorMessageBuilder.append(" valueSerializer not specified, must be specified as a string\n"); + } + + if (keyDeserializer == null || keyDeserializer.trim().length() == 0) { + errorMessageBuilder.append(" keyDeserializer not specified, must be specified as a string\n"); + } + + if (valueDeserializer == null || valueDeserializer.trim().length() == 0) { + errorMessageBuilder.append(" valueDeserializer not specified, must be specified as a string\n"); + } + + return errorMessageBuilder.toString(); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/package-info.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/package-info.java new file mode 100644 index 000000000..f04aaceef --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============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========================================================= + */ + +/** + * Implements the APEX event carrier technology plugin for Kafka. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ + +package org.onap.policy.apex.plugins.event.carrier.kafka; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/pom.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/pom.xml new file mode 100644 index 000000000..8be1131e6 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/pom.xml @@ -0,0 +1,49 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId> + <artifactId>plugins-event-carrier</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>plugins-event-carrier-restclient</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] Plugin for handling events being transported over REST where Apex acts as a REST client</description> + + <properties> + <apex-plugins-event-carrier-restclient-dir>${project.basedir}/src</apex-plugins-event-carrier-restclient-dir> + </properties> + + <dependencies> + <dependency> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-client</artifactId> + <version>${version.jersey.core}</version> + </dependency> + <dependency> + <groupId>org.onap.policy.apex-pdp.services</groupId> + <artifactId>services-engine</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java new file mode 100644 index 000000000..b9348d494 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java @@ -0,0 +1,233 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restclient; + +import java.util.EnumMap; +import java.util.Map; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; + +import org.onap.policy.apex.core.infrastructure.threading.ApplicationThreadFactory; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.service.engine.event.ApexEventConsumer; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class implements an Apex event consumer that receives events from a REST server. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexRestClientConsumer implements ApexEventConsumer, Runnable { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexRestClientConsumer.class); + + // The amount of time to wait in milliseconds between checks that the consumer thread has stopped + private static final long REST_CLIENT_WAIT_SLEEP_TIME = 50; + + // The REST parameters read from the parameter service + private RESTClientCarrierTechnologyParameters restConsumerProperties; + + // The event receiver that will receive events from this consumer + private ApexEventReceiver eventReceiver; + + // The HTTP client that makes a REST call to get an input event for Apex + private Client client; + + // The name for this consumer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + // The consumer thread and stopping flag + private Thread consumerThread; + private boolean stopOrderedFlag = false; + + @Override + public void init(final String consumerName, final EventHandlerParameters consumerParameters, + final ApexEventReceiver incomingEventReceiver) throws ApexEventException { + this.eventReceiver = incomingEventReceiver; + this.name = consumerName; + + // Check and get the REST Properties + if (!(consumerParameters.getCarrierTechnologyParameters() instanceof RESTClientCarrierTechnologyParameters)) { + final String errorMessage = + "specified consumer properties are not applicable to REST client consumer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + restConsumerProperties = + (RESTClientCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); + + // Check if the HTTP method has been set + if (restConsumerProperties.getHttpMethod() == null) { + restConsumerProperties.setHttpMethod(RESTClientCarrierTechnologyParameters.CONSUMER_HTTP_METHOD); + } + + if (!restConsumerProperties.getHttpMethod() + .equalsIgnoreCase(RESTClientCarrierTechnologyParameters.CONSUMER_HTTP_METHOD)) { + final String errorMessage = "specified HTTP method of \"" + restConsumerProperties.getHttpMethod() + + "\" is invalid, only HTTP method \"GET\" is supported for event reception on REST client consumer (" + + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Initialize the HTTP client + client = ClientBuilder.newClient(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#start() + */ + @Override + public void start() { + // Configure and start the event reception thread + final String threadName = this.getClass().getName() + ":" + this.name; + consumerThread = new ApplicationThreadFactory(threadName).newThread(this); + consumerThread.setDaemon(true); + consumerThread.start(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#setPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + // The RequestRunner thread runs the get request for the event + Thread requestRunnerThread = null; + + // The endless loop that receives events using REST calls + while (consumerThread.isAlive() && !stopOrderedFlag) { + // Create a new request if one is not in progress + if (requestRunnerThread == null || !requestRunnerThread.isAlive()) { + requestRunnerThread = new Thread(new RequestRunner()); + requestRunnerThread.start(); + } + + ThreadUtilities.sleep(REST_CLIENT_WAIT_SLEEP_TIME); + } + + client.close(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.producer.ApexEventConsumer#stop() + */ + @Override + public void stop() { + stopOrderedFlag = true; + + while (consumerThread.isAlive()) { + ThreadUtilities.sleep(REST_CLIENT_WAIT_SLEEP_TIME); + } + } + + /** + * This class is used to start a thread for each request issued. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ + private class RequestRunner implements Runnable { + /* + * (non-Javadoc) + * + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + try { + final Response response = + client.target(restConsumerProperties.getURL()).request("application/json").get(); + + // Check that the event request worked + if (response.getStatus() != Response.Status.OK.getStatusCode()) { + final String errorMessage = "reception of event from URL \"" + restConsumerProperties.getURL() + + "\" failed with status code " + response.getStatus() + " and message \"" + + response.readEntity(String.class) + "\""; + throw new ApexEventRuntimeException(errorMessage); + } + + // Get the event we received + final String eventJSONString = response.readEntity(String.class); + + // Check there is content + if (eventJSONString == null || eventJSONString.trim().length() == 0) { + final String errorMessage = + "received an empty event from URL \"" + restConsumerProperties.getURL() + "\""; + throw new ApexEventRuntimeException(errorMessage); + } + + // Send the event into Apex + eventReceiver.receiveEvent(eventJSONString); + } catch (final Exception e) { + LOGGER.warn("error receiving events on thread {}", consumerThread.getName(), e); + } + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java new file mode 100644 index 000000000..9d838f55e --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java @@ -0,0 +1,191 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restclient; + +import java.util.EnumMap; +import java.util.Map; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; + +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Concrete implementation of an Apex event producer that sends events using REST. + * + * @author Joss Armstrong (joss.armstrong@ericsson.com) + * + */ +public class ApexRestClientProducer implements ApexEventProducer { + private static final Logger LOGGER = LoggerFactory.getLogger(ApexRestClientProducer.class); + + // The HTTP client that makes a REST call with an event from Apex + private Client client; + + // The REST carrier properties + private RESTClientCarrierTechnologyParameters restProducerProperties; + + // The name for this producer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#init(java.lang.String, + * org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters) + */ + @Override + public void init(final String producerName, final EventHandlerParameters producerParameters) + throws ApexEventException { + this.name = producerName; + + // Check and get the REST Properties + if (!(producerParameters.getCarrierTechnologyParameters() instanceof RESTClientCarrierTechnologyParameters)) { + final String errorMessage = + "specified consumer properties are not applicable to REST client producer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + restProducerProperties = + (RESTClientCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + + // Check if the HTTP method has been set + if (restProducerProperties.getHttpMethod() == null) { + restProducerProperties.setHttpMethod(RESTClientCarrierTechnologyParameters.DEFAULT_PRODUCER_HTTP_METHOD); + } + + if (!restProducerProperties.getHttpMethod().equalsIgnoreCase("POST") + && !restProducerProperties.getHttpMethod().equalsIgnoreCase("PUT")) { + final String errorMessage = "specified HTTP method of \"" + restProducerProperties.getHttpMethod() + + "\" is invalid, only HTTP methods \"POST\" and \"PUT\" are supproted for event sending on REST client producer (" + + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Initialize the HTTP client + client = ClientBuilder.newClient(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#setPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#sendEvent(long, java.lang. String, + * java.lang.Object) + */ + @Override + public void sendEvent(final long executionId, final String eventName, final Object event) { + // Check if this is a synchronized event, if so we have received a reply + final SynchronousEventCache synchronousEventCache = + (SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS); + if (synchronousEventCache != null) { + synchronousEventCache.removeCachedEventToApexIfExists(executionId); + } + + // Send the event as a REST request + final Response response = sendEventAsRESTRequest((String) event); + + // Check that the request worked + if (response.getStatus() != Response.Status.OK.getStatusCode()) { + final String errorMessage = "send of event to URL \"" + restProducerProperties.getURL() + "\" using HTTP \"" + + restProducerProperties.getHttpMethod() + "\" failed with status code " + response.getStatus() + + " and message \"" + response.readEntity(String.class) + "\", event:\n" + event; + LOGGER.warn(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("event sent from engine using {} to URL {} with HTTP {} : {} and response {} ", this.name, + restProducerProperties.getURL(), restProducerProperties.getHttpMethod(), event, response); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#stop() + */ + @Override + public void stop() { + // Close the HTTP session + client.close(); + } + + /** + * Send the event as a JSON string as a REST request. + * + * @param event the event to send + * @return the response tot he JSON request + */ + public Response sendEventAsRESTRequest(final String event) { + // We have already checked that it is a PUT or POST request + if (restProducerProperties.getHttpMethod().equalsIgnoreCase("POST")) { + return client.target(restProducerProperties.getURL()).request("application/json").post(Entity.json(event)); + } else { + return client.target(restProducerProperties.getURL()).request("application/json").put(Entity.json(event)); + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RESTClientCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RESTClientCarrierTechnologyParameters.java new file mode 100644 index 000000000..e07593c55 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RESTClientCarrierTechnologyParameters.java @@ -0,0 +1,134 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restclient; + +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; + +/** + * Apex parameters for REST as an event carrier technology with Apex as a REST client. + * + * The parameters for this plugin are: + * <ol> + * <li>url: The URL that the Apex Rest client will connect to over REST for event reception or event sending. This + * parameter is mandatory. + * <li>httpMethod: The HTTP method to use when sending events over REST, legal values are POST (default) and PUT. When + * receiving events, the REST client plugin always uses the HTTP GET method. + * </ol> + * + * @author Joss Armstrong (joss.armstrong@ericsson.com) + */ +public class RESTClientCarrierTechnologyParameters extends CarrierTechnologyParameters { + + /** The label of this carrier technology. */ + public static final String RESTCLIENT_CARRIER_TECHNOLOGY_LABEL = "RESTCLIENT"; + + /** The producer plugin class for the REST carrier technology. */ + public static final String RESTCLIENT_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestClientProducer.class.getCanonicalName(); + + /** The consumer plugin class for the REST carrier technology. */ + public static final String RESTCLIENT_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestClientConsumer.class.getCanonicalName(); + + /** The default HTTP method for output of events. */ + public static final String DEFAULT_PRODUCER_HTTP_METHOD = "POST"; + + /** The HTTP method for input of events. */ + public static final String CONSUMER_HTTP_METHOD = "GET"; + + private String url = null; + private String httpMethod = null; + + /** + * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter + * service. + */ + public RESTClientCarrierTechnologyParameters() { + super(RESTClientCarrierTechnologyParameters.class.getCanonicalName()); + + // Set the carrier technology properties for the web socket carrier technology + this.setLabel(RESTCLIENT_CARRIER_TECHNOLOGY_LABEL); + this.setEventProducerPluginClass(RESTCLIENT_EVENT_PRODUCER_PLUGIN_CLASS); + this.setEventConsumerPluginClass(RESTCLIENT_EVENT_CONSUMER_PLUGIN_CLASS); + + } + + /** + * Gets the URL for the REST request. + * + * @return the URL + */ + public String getURL() { + return url; + } + + /** + * Sets the URL for the REST request. + * + * @param incomingURL the URL + */ + public void setURL(final String incomingURL) { + this.url = incomingURL; + } + + /** + * Gets the HTTP method to use for the REST request. + * + * @return the HTTP method + */ + public String getHttpMethod() { + return httpMethod; + } + + /** + * Sets the HTTP method to use for the REST request. + * + * @param httpMethod the HTTP method + */ + public void setHttpMethod(final String httpMethod) { + this.httpMethod = httpMethod; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "RESTClientCarrierTechnologyParameters [url=" + url + ", httpMethod=" + httpMethod + "]"; + } + + + /* + * + * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate() + */ + @Override + public String validate() { + final StringBuilder errorMessageBuilder = new StringBuilder(); + + // Check if the URL has been set for event output + if (getURL() == null) { + errorMessageBuilder.append(" no URL has been set for event sending on REST client"); + } + + return errorMessageBuilder.toString(); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/package-info.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/package-info.java new file mode 100644 index 000000000..e674beef6 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/package-info.java @@ -0,0 +1,28 @@ +/*- + * ============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========================================================= + */ + +/** + * APEX REST consumer and producer plugins when APEX is acting as a REST client. + * + * @author Joss Armstrong (joss.armstrong@ericsson.com) + * + */ + +package org.onap.policy.apex.plugins.event.carrier.restclient; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml new file mode 100644 index 000000000..8a5419334 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml @@ -0,0 +1,67 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId> + <artifactId>plugins-event-carrier</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>plugins-event-carrier-restrequestor</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] Plugin for handling REST requests and responses</description> + + <properties> + <apex-plugins-event-carrier-restrequestor-dir>${project.basedir}/src</apex-plugins-event-carrier-restrequestor-dir> + </properties> + + <dependencies> + <dependency> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-client</artifactId> + <version>${version.jersey.core}</version> + </dependency> + <dependency> + <groupId>org.onap.policy.apex-pdp.services</groupId> + <artifactId>services-engine</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.containers</groupId> + <artifactId>jersey-container-grizzly2-http</artifactId> + <version>${version.grizzly2-http}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId> + <artifactId>plugins-executor-mvel</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.apex-pdp.context</groupId> + <artifactId>context-test</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequest.java new file mode 100644 index 000000000..46e68acda --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequest.java @@ -0,0 +1,65 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restrequestor; + +/** + * This class holds a record of a REST request for the REST requestor plugin + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexRestRequest { + private long executionId; + private String eventName; + private Object event; + private long timestamp; + + public ApexRestRequest(final long executionId, final String eventName, final Object event) { + this.executionId = executionId; + this.eventName = eventName; + this.event = event; + } + + public long getExecutionId() { + return executionId; + } + + public String getEventName() { + return eventName; + } + + public Object getEvent() { + return event; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(final long timestamp) { + this.timestamp = timestamp; + } + + @Override + public String toString() { + return "ApexRestRequest [executionId=" + executionId + ", eventName=" + eventName + ", event=" + event + + ", timestamp=" + timestamp + "]"; + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java new file mode 100644 index 000000000..a2069a794 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java @@ -0,0 +1,410 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restrequestor; + +import java.net.URL; +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Response; + +import org.onap.policy.apex.core.infrastructure.threading.ApplicationThreadFactory; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.service.engine.event.ApexEventConsumer; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class implements an Apex event consumer that issues a REST request and returns the REST + * response to APEX as an event. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexRestRequestorConsumer.class); + + // The amount of time to wait in milliseconds between checks that the consumer thread has + // stopped + private static final long REST_REQUESTOR_WAIT_SLEEP_TIME = 50; + + // The REST parameters read from the parameter service + private RESTRequestorCarrierTechnologyParameters restConsumerProperties; + + // The timeout for REST requests + private long restRequestTimeout = RESTRequestorCarrierTechnologyParameters.DEFAULT_REST_REQUEST_TIMEOUT; + + // The event receiver that will receive events from this consumer + private ApexEventReceiver eventReceiver; + + // The HTTP client that makes a REST call to get an input event for Apex + private Client client; + + // The name for this consumer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + // The consumer thread and stopping flag + private Thread consumerThread; + private boolean stopOrderedFlag = false; + + // Temporary request holder for incoming REST requests + private final BlockingQueue<ApexRestRequest> incomingRestRequestQueue = new LinkedBlockingQueue<>(); + + // Map of ongoing REST request threads indexed by the time they started at + private final Map<ApexRestRequest, RestRequestRunner> ongoingRestRequestMap = new ConcurrentHashMap<>(); + + // The number of events received to date + private Object eventsReceivedLock = new Object(); + private Integer eventsReceived = 0; + + // The number of the next request runner thread + private static long nextRequestRunnerThreadNo = 0; + + @Override + public void init(final String consumerName, final EventHandlerParameters consumerParameters, + final ApexEventReceiver incomingEventReceiver) throws ApexEventException { + this.eventReceiver = incomingEventReceiver; + this.name = consumerName; + + // Check and get the REST Properties + if (!(consumerParameters + .getCarrierTechnologyParameters() instanceof RESTRequestorCarrierTechnologyParameters)) { + final String errorMessage = + "specified consumer properties are not applicable to REST Requestor consumer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + restConsumerProperties = + (RESTRequestorCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); + + // Check if we are in peered mode + if (!consumerParameters.isPeeredMode(EventHandlerPeeredMode.REQUESTOR)) { + final String errorMessage = "REST Requestor consumer (" + this.name + + ") must run in peered requestor mode with a REST Requestor producer"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Check if the HTTP method has been set + if (restConsumerProperties.getHttpMethod() == null) { + restConsumerProperties + .setHttpMethod(RESTRequestorCarrierTechnologyParameters.DEFAULT_REQUESTOR_HTTP_METHOD); + } + + // Check if the HTTP URL has been set + if (restConsumerProperties.getURL() == null) { + final String errorMessage = "no URL has been specified on REST Requestor consumer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Check if the HTTP URL is valid + try { + new URL(restConsumerProperties.getURL()); + } catch (final Exception e) { + final String errorMessage = "invalid URL has been specified on REST Requestor consumer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage, e); + } + + // Set the peer timeout to the default value if its not set + if (consumerParameters.getPeerTimeout(EventHandlerPeeredMode.REQUESTOR) != 0) { + restRequestTimeout = consumerParameters.getPeerTimeout(EventHandlerPeeredMode.REQUESTOR); + } + + // Initialize the HTTP client + client = ClientBuilder.newClient(); + } + + /** + * Receive an incoming REST request from the peered REST Requestor producer and queue it + * + * @param restRequest the incoming rest request to queue + * @throws ApexEventRuntimeException on queueing errors + */ + public void processRestRequest(final ApexRestRequest restRequest) { + // Push the event onto the queue for handling + try { + incomingRestRequestQueue.add(restRequest); + } catch (final Exception e) { + final String errorMessage = + "could not queue request \"" + restRequest + "\" on REST Requestor consumer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#start() + */ + @Override + public void start() { + // Configure and start the event reception thread + final String threadName = this.getClass().getName() + ":" + this.name; + consumerThread = new ApplicationThreadFactory(threadName).newThread(this); + consumerThread.setDaemon(true); + consumerThread.start(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getName() + */ + @Override + public String getName() { + return name; + } + + /** + * Get the number of events received to date + * + * @return the number of events received + */ + public int getEventsReceived() { + return eventsReceived; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getPeeredReference(org.onap. + * policy.apex.service. parameters.eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#setPeeredReference(org.onap. + * policy.apex.service. parameters.eventhandler.EventHandlerPeeredMode, + * org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + // The endless loop that receives events using REST calls + while (consumerThread.isAlive() && !stopOrderedFlag) { + try { + // Take the next event from the queue + final ApexRestRequest restRequest = + incomingRestRequestQueue.poll(REST_REQUESTOR_WAIT_SLEEP_TIME, TimeUnit.MILLISECONDS); + if (restRequest == null) { + // Poll timed out, check for request timeouts + timeoutExpiredRequests(); + continue; + } + + // Set the time stamp of the REST request + restRequest.setTimestamp(System.currentTimeMillis()); + + // Create a thread to process the REST request and place it on the map of ongoing + // requests + final RestRequestRunner restRequestRunner = new RestRequestRunner(restRequest); + ongoingRestRequestMap.put(restRequest, restRequestRunner); + + // Start execution of the request + final Thread restRequestRunnerThread = new Thread(restRequestRunner); + restRequestRunnerThread.setName("RestRequestRunner_" + nextRequestRunnerThreadNo); + restRequestRunnerThread.start(); + } catch (final InterruptedException e) { + LOGGER.debug("Thread interrupted, Reason {}", e.getMessage()); + Thread.currentThread().interrupt(); + } + } + + client.close(); + } + + /** + * This method times out REST requests that have expired + */ + private void timeoutExpiredRequests() { + // Hold a list of timed out requests + final List<ApexRestRequest> timedoutRequestList = new ArrayList<>(); + + // Check for timeouts + for (final Entry<ApexRestRequest, RestRequestRunner> requestEntry : ongoingRestRequestMap.entrySet()) { + if (System.currentTimeMillis() - requestEntry.getKey().getTimestamp() > restRequestTimeout) { + requestEntry.getValue().stop(); + timedoutRequestList.add(requestEntry.getKey()); + } + } + + // Interrupt timed out requests and remove them from the ongoing map + for (final ApexRestRequest timedoutRequest : timedoutRequestList) { + final String errorMessage = + "REST Requestor consumer (" + this.name + "), REST request timed out: " + timedoutRequest; + LOGGER.warn(errorMessage); + + ongoingRestRequestMap.remove(timedoutRequest); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.producer.ApexEventConsumer#stop() + */ + @Override + public void stop() { + stopOrderedFlag = true; + + while (consumerThread.isAlive()) { + ThreadUtilities.sleep(REST_REQUESTOR_WAIT_SLEEP_TIME); + } + } + + /** + * This class is used to start a thread for each request issued. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ + private class RestRequestRunner implements Runnable { + private static final String APPLICATION_JSON = "application/json"; + + // The REST request being processed by this thread + private final ApexRestRequest request; + + // The thread executing the REST request + private Thread restRequestThread; + + /** + * Constructor, initialise the request runner with the request + * + * @param request the request this runner will issue + */ + private RestRequestRunner(final ApexRestRequest request) { + this.request = request; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + // Get the thread for the request + restRequestThread = Thread.currentThread(); + + try { + // Execute the REST request + final Response response = sendEventAsRESTRequest(); + + // Check that the event request worked + if (response.getStatus() != Response.Status.OK.getStatusCode()) { + final String errorMessage = "reception of response to \"" + request + "\" from URL \"" + + restConsumerProperties.getURL() + "\" failed with status code " + response.getStatus() + + " and message \"" + response.readEntity(String.class) + "\""; + throw new ApexEventRuntimeException(errorMessage); + } + + // Get the event we received + final String eventJSONString = response.readEntity(String.class); + + // Check there is content + if (eventJSONString == null || eventJSONString.trim().length() == 0) { + final String errorMessage = "received an enpty response to \"" + request + "\" from URL \"" + + restConsumerProperties.getURL() + "\""; + throw new ApexEventRuntimeException(errorMessage); + } + + // Send the event into Apex + eventReceiver.receiveEvent(request.getExecutionId(), eventJSONString); + + synchronized (eventsReceivedLock) { + eventsReceived++; + } + } catch (final Exception e) { + LOGGER.warn("error receiving events on thread {}", consumerThread.getName(), e); + } finally { + // Remove the request from the map of ongoing requests + ongoingRestRequestMap.remove(request); + } + } + + /** + * Stop the REST request + */ + private void stop() { + restRequestThread.interrupt(); + } + + /** + * Execute the REST request. + * + * @return the response to the REST request + */ + public Response sendEventAsRESTRequest() { + switch (restConsumerProperties.getHttpMethod()) { + case GET: + return client.target(restConsumerProperties.getURL()).request(APPLICATION_JSON).get(); + + case PUT: + return client.target(restConsumerProperties.getURL()).request(APPLICATION_JSON) + .put(Entity.json(request.getEvent())); + + case POST: + return client.target(restConsumerProperties.getURL()).request(APPLICATION_JSON) + .post(Entity.json(request.getEvent())); + + case DELETE: + return client.target(restConsumerProperties.getURL()).request(APPLICATION_JSON).delete(); + } + + return null; + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java new file mode 100644 index 000000000..12f194510 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java @@ -0,0 +1,195 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restrequestor; + +import java.util.EnumMap; +import java.util.Map; + +import org.onap.policy.apex.service.engine.event.ApexEventConsumer; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Concrete implementation of an Apex event requestor that manages the producer side of a REST request. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + * + */ +public class ApexRestRequestorProducer implements ApexEventProducer { + private static final Logger LOGGER = LoggerFactory.getLogger(ApexRestRequestorProducer.class); + + // The REST carrier properties + private RESTRequestorCarrierTechnologyParameters restProducerProperties; + + // The name for this producer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + // The number of events sent + private int eventsSent = 0; + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#init(java.lang.String, + * org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters) + */ + @Override + public void init(final String producerName, final EventHandlerParameters producerParameters) + throws ApexEventException { + this.name = producerName; + + // Check and get the REST Properties + if (!(producerParameters + .getCarrierTechnologyParameters() instanceof RESTRequestorCarrierTechnologyParameters)) { + final String errorMessage = + "specified consumer properties are not applicable to REST requestor producer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + restProducerProperties = + (RESTRequestorCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + + // Check if we are in peered mode + if (!producerParameters.isPeeredMode(EventHandlerPeeredMode.REQUESTOR)) { + final String errorMessage = "REST Requestor producer (" + this.name + + ") must run in peered requestor mode with a REST Requestor consumer"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Check if the HTTP URL has been set + if (restProducerProperties.getURL() != null) { + final String errorMessage = "URL may not be specified on REST Requestor producer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Check if the HTTP method has been set + if (restProducerProperties.getHttpMethod() != null) { + final String errorMessage = + "HTTP method may not be specified on REST Requestor producer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getName() + */ + @Override + public String getName() { + return name; + } + + /** + * Get the number of events sent to date + * + * @return the number of events received + */ + public int getEventsSent() { + return eventsSent; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getPeeredReference(org.onap.policy.apex.service. + * parameters.eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#setPeeredReference(org.onap.policy.apex.service. + * parameters.eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#sendEvent(long, java.lang. String, + * java.lang.Object) + */ + @Override + public void sendEvent(final long executionId, final String eventName, final Object event) { + // Check if this is a synchronized event, if so we have received a reply + final SynchronousEventCache synchronousEventCache = + (SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS); + if (synchronousEventCache != null) { + synchronousEventCache.removeCachedEventToApexIfExists(executionId); + } + + // Find the peered consumer for this producer + final PeeredReference peeredRequestorReference = peerReferenceMap.get(EventHandlerPeeredMode.REQUESTOR); + if (peeredRequestorReference != null) { + // Find the REST Response Consumer that will handle this request + final ApexEventConsumer consumer = peeredRequestorReference.getPeeredConsumer(); + if (!(consumer instanceof ApexRestRequestorConsumer)) { + final String errorMessage = "send of event to URL \"" + restProducerProperties.getURL() + "\" failed," + + " REST response consumer is not an instance of ApexRestRequestorConsumer\n" + event; + LOGGER.warn(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + + // Use the consumer to handle this event + final ApexRestRequestorConsumer restRequstConsumer = (ApexRestRequestorConsumer) consumer; + restRequstConsumer.processRestRequest(new ApexRestRequest(executionId, eventName, event)); + + eventsSent++; + } else { + // No peered consumer defined + final String errorMessage = "send of event to URL \"" + restProducerProperties.getURL() + "\" failed," + + " REST response consumer is not defined\n" + event; + LOGGER.warn(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#stop() + */ + @Override + public void stop() { + // For REST requestor, all the implementation is in the consumer + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RESTRequestorCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RESTRequestorCarrierTechnologyParameters.java new file mode 100644 index 000000000..eb5870058 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RESTRequestorCarrierTechnologyParameters.java @@ -0,0 +1,135 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restrequestor; + +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; + +/** + * Apex parameters for REST as an event carrier technology with Apex issuing a REST request and receiving a REST + * response. + * + * The parameters for this plugin are: + * <ol> + * <li>url: The URL that the Apex Rest Requestor will connect to over REST for REST request sending. This parameter is + * mandatory. + * <li>httpMethod: The HTTP method to use when making requests over REST, legal values are GET (default), POST, PUT, and + * DELETE. + * <li>restRequestTimeout: The time in milliseconds to wait for a REST request to complete. + * </ol> + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class RESTRequestorCarrierTechnologyParameters extends CarrierTechnologyParameters { + /** The supported HTTP methods. */ + public enum HTTP_METHOD { + GET, PUT, POST, DELETE + } + + /** The label of this carrier technology. */ + public static final String RESTREQUESTOR_CARRIER_TECHNOLOGY_LABEL = "RESTREQUESTOR"; + + /** The producer plugin class for the REST carrier technology. */ + public static final String RESTREQUSTOR_EVENT_PRODUCER_PLUGIN_CLASS = + ApexRestRequestorProducer.class.getCanonicalName(); + + /** The consumer plugin class for the REST carrier technology. */ + public static final String RESTREQUSTOR_EVENT_CONSUMER_PLUGIN_CLASS = + ApexRestRequestorConsumer.class.getCanonicalName(); + + /** The default HTTP method for request events. */ + public static final HTTP_METHOD DEFAULT_REQUESTOR_HTTP_METHOD = HTTP_METHOD.GET; + + /** The default timeout for REST requests. */ + public static final long DEFAULT_REST_REQUEST_TIMEOUT = 500; + + private String url = null; + private HTTP_METHOD httpMethod = null; + + /** + * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter + * service. + */ + public RESTRequestorCarrierTechnologyParameters() { + super(RESTRequestorCarrierTechnologyParameters.class.getCanonicalName()); + + // Set the carrier technology properties for the web socket carrier technology + this.setLabel(RESTREQUESTOR_CARRIER_TECHNOLOGY_LABEL); + this.setEventProducerPluginClass(RESTREQUSTOR_EVENT_PRODUCER_PLUGIN_CLASS); + this.setEventConsumerPluginClass(RESTREQUSTOR_EVENT_CONSUMER_PLUGIN_CLASS); + } + + /** + * Gets the URL for the REST request. + * + * @return the URL + */ + public String getURL() { + return url; + } + + /** + * Sets the URL for the REST request. + * + * @param incomingURL the URL + */ + public void setURL(final String incomingURL) { + this.url = incomingURL; + } + + /** + * Gets the HTTP method to use for the REST request. + * + * @return the HTTP method + */ + public HTTP_METHOD getHttpMethod() { + return httpMethod; + } + + /** + * Sets the HTTP method to use for the REST request. + * + * @param httpMethod the HTTP method + */ + public void setHttpMethod(final HTTP_METHOD httpMethod) { + this.httpMethod = httpMethod; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + + @Override + public String toString() { + return "RESTRequestorCarrierTechnologyParameters [url=" + url + ", httpMethod=" + httpMethod + "]"; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate() + */ + @Override + public String validate() { + return ""; + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/package-info.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/package-info.java new file mode 100644 index 000000000..904de13c9 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/package-info.java @@ -0,0 +1,28 @@ +/*- + * ============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========================================================= + */ + +/** + * APEX REST consumer and producer plugins when APEX sends a REST request and receives a REST response to a REST server. + * + * @author Joss Armstrong (joss.armstrong@ericsson.com) + * + */ + +package org.onap.policy.apex.plugins.event.carrier.restrequestor; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRESTREequestorEndpoint.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRESTREequestorEndpoint.java new file mode 100644 index 000000000..d9569b1ed --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRESTREequestorEndpoint.java @@ -0,0 +1,153 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.apps.uservice.test.adapt.restrequestor; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.google.gson.Gson; + +import java.util.Map; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +@Path("/apex") +public class TestRESTREequestorEndpoint { + + private static Object counterLock = new Object(); + private static int postMessagesReceived = 0; + private static int putMessagesReceived = 0; + private static int statMessagesReceived = 0; + private static int getMessagesReceived = 0; + private static int deleteMessagesReceived = 0; + + private static String EVENT_STRING = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.sample.events\",\n" + + "\"name\": \"Event0100\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" + getMessagesReceived + + "\",\n" + "\"target\": \"apex\",\n" + "\"TestSlogan\": \"Test slogan for External Event0\",\n" + + "\"TestMatchCase\": 2,\n" + "\"TestTimestamp\": " + System.currentTimeMillis() + ",\n" + + "\"TestTemperature\": 9080.866\n" + "}"; + + public static void resetCounters() { + postMessagesReceived = 0; + putMessagesReceived = 0; + statMessagesReceived = 0; + getMessagesReceived = 0; + deleteMessagesReceived = 0; + } + + @Path("/event/Stats") + @GET + public Response serviceGetStats() { + synchronized (counterLock) { + statMessagesReceived++; + } + return Response.status(200) + .entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": " + + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + ",\"DELETE\": " + + deleteMessagesReceived + "}") + .build(); + } + + @Path("/event/GetEvent") + @GET + public Response serviceGetEvent() { + synchronized (counterLock) { + getMessagesReceived++; + } + + return Response.status(200).entity(EVENT_STRING).build(); + } + + @Path("/event/GetEmptyEvent") + @GET + public Response serviceGetEmptyEvent() { + return Response.status(200).build(); + } + + @Path("/event/GetEventBadResponse") + @GET + public Response serviceGetEventBadResponse() { + return Response.status(400).build(); + } + + @Path("/event/PostEvent") + @POST + public Response servicePostRequest(final String jsonString) { + synchronized (counterLock) { + postMessagesReceived++; + } + + @SuppressWarnings("unchecked") + final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class); + assertTrue(jsonMap.containsKey("name")); + assertEquals("0.0.1", jsonMap.get("version")); + assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace")); + assertEquals("Act", jsonMap.get("source")); + assertEquals("Outside", jsonMap.get("target")); + + return Response.status(200).entity(EVENT_STRING).build(); + } + + @Path("/event/PostEventBadResponse") + @POST + public Response servicePostRequestBadResponse(final String jsonString) { + return Response.status(400).build(); + } + + @Path("/event/PutEvent") + @PUT + public Response servicePutRequest(final String jsonString) { + synchronized (counterLock) { + putMessagesReceived++; + } + + @SuppressWarnings("unchecked") + final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class); + assertTrue(jsonMap.containsKey("name")); + assertEquals("0.0.1", jsonMap.get("version")); + assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace")); + assertEquals("Act", jsonMap.get("source")); + assertEquals("Outside", jsonMap.get("target")); + + return Response.status(200).entity(EVENT_STRING).build(); + } + + @Path("/event/DeleteEvent") + @DELETE + public Response serviceDeleteRequest(final String jsonString) { + synchronized (counterLock) { + deleteMessagesReceived++; + } + + return Response.status(200).entity(EVENT_STRING).build(); + } + + @Path("/event/DeleteEventBadResponse") + @DELETE + public Response serviceDeleteRequestBadResponse(final String jsonString) { + return Response.status(400).build(); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRESTRequestor.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRESTRequestor.java new file mode 100644 index 000000000..d4eb434c7 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRESTRequestor.java @@ -0,0 +1,291 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.apps.uservice.test.adapt.restrequestor; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.google.gson.Gson; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.net.URI; +import java.util.Map; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; + +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.server.ResourceConfig; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.service.engine.main.ApexMain; + +public class TestRESTRequestor { + private static final String BASE_URI = "http://localhost:32801/TestRESTRequestor"; + private static HttpServer server; + + private ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + + private final PrintStream stdout = System.out; + private final PrintStream stderr = System.err; + + @BeforeClass + public static void setUp() throws Exception { + final ResourceConfig rc = new ResourceConfig(TestRESTREequestorEndpoint.class); + server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); + + while (!server.isStarted()) { + ThreadUtilities.sleep(50); + } + } + + @AfterClass + public static void tearDown() throws Exception { + server.shutdownNow(); + + new File("src/test/resources/events/EventsOut.json").delete(); + new File("src/test/resources/events/EventsOutMulti0.json").delete(); + new File("src/test/resources/events/EventsOutMulti1.json").delete(); + } + + @Before + public void resetCounters() { + TestRESTREequestorEndpoint.resetCounters(); + } + + @Test + public void testRESTRequestorGet() throws MessagingException, ApexException, IOException { + final Client client = ClientBuilder.newClient(); + + final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileGet.json" }; + final ApexMain apexMain = new ApexMain(args); + + // Wait for the required amount of events to be received or for 10 seconds + Double getsSoFar = 0.0; + for (int i = 0; i < 40; i++) { + ThreadUtilities.sleep(100); + + final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") + .request("application/json").get(); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + final String responseString = response.readEntity(String.class); + + @SuppressWarnings("unchecked") + final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class); + getsSoFar = Double.valueOf(jsonMap.get("GET").toString()); + + if (getsSoFar >= 50.0) { + break; + } + } + + apexMain.shutdown(); + client.close(); + + assertEquals(Double.valueOf(50.0), getsSoFar); + } + + @Test + public void testRESTRequestorPut() throws MessagingException, ApexException, IOException { + final Client client = ClientBuilder.newClient(); + + final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FilePut.json" }; + final ApexMain apexMain = new ApexMain(args); + + // Wait for the required amount of events to be received or for 10 seconds + Double putsSoFar = 0.0; + for (int i = 0; i < 40; i++) { + ThreadUtilities.sleep(100); + + final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") + .request("application/json").get(); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + final String responseString = response.readEntity(String.class); + + @SuppressWarnings("unchecked") + final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class); + putsSoFar = Double.valueOf(jsonMap.get("PUT").toString()); + + if (putsSoFar >= 50.0) { + break; + } + } + + apexMain.shutdown(); + client.close(); + + assertEquals(Double.valueOf(50.0), putsSoFar); + } + + @Test + public void testRESTRequestorPost() throws MessagingException, ApexException, IOException { + final Client client = ClientBuilder.newClient(); + + final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FilePost.json" }; + final ApexMain apexMain = new ApexMain(args); + + // Wait for the required amount of events to be received or for 10 seconds + Double postsSoFar = 0.0; + for (int i = 0; i < 40; i++) { + ThreadUtilities.sleep(100); + + final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") + .request("application/json").get(); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + final String responseString = response.readEntity(String.class); + + @SuppressWarnings("unchecked") + final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class); + postsSoFar = Double.valueOf(jsonMap.get("POST").toString()); + + if (postsSoFar >= 50.0) { + break; + } + } + + apexMain.shutdown(); + client.close(); + + assertEquals(Double.valueOf(50.0), postsSoFar); + } + + @Test + public void testRESTRequestorDelete() throws MessagingException, ApexException, IOException { + final Client client = ClientBuilder.newClient(); + + final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileDelete.json" }; + final ApexMain apexMain = new ApexMain(args); + + // Wait for the required amount of events to be received or for 10 seconds + Double deletesSoFar = 0.0; + for (int i = 0; i < 40; i++) { + ThreadUtilities.sleep(100); + + final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") + .request("application/json").get(); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + final String responseString = response.readEntity(String.class); + + @SuppressWarnings("unchecked") + final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class); + deletesSoFar = Double.valueOf(jsonMap.get("DELETE").toString()); + + if (deletesSoFar >= 50.0) { + break; + } + } + + apexMain.shutdown(); + client.close(); + + assertEquals(Double.valueOf(50.0), deletesSoFar); + } + + @Test + public void testRESTRequestorMultiInputs() throws MessagingException, ApexException, IOException { + final Client client = ClientBuilder.newClient(); + + final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json" }; + final ApexMain apexMain = new ApexMain(args); + + // Wait for the required amount of events to be received or for 10 seconds + Double getsSoFar = 0.0; + for (int i = 0; i < 40; i++) { + ThreadUtilities.sleep(100); + + final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") + .request("application/json").get(); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + final String responseString = response.readEntity(String.class); + + @SuppressWarnings("unchecked") + final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class); + getsSoFar = Double.valueOf(jsonMap.get("GET").toString()); + + if (getsSoFar >= 8.0) { + break; + } + } + + apexMain.shutdown(); + client.close(); + + assertEquals(Double.valueOf(8.0), getsSoFar); + + ThreadUtilities.sleep(1000); + } + + @Test + public void testRESTRequestorProducerAlone() throws MessagingException, ApexException, IOException { + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + + final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json" }; + + final ApexMain apexMain = new ApexMain(args); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + System.setErr(stderr); + + assertTrue(outString.contains( + "REST Requestor producer (RestRequestorProducer) must run in peered requestor mode with a REST Requestor consumer")); + } + + @Test + public void testRESTRequestorConsumerAlone() throws MessagingException, ApexException, IOException { + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + + final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json" }; + + final ApexMain apexMain = new ApexMain(args); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + System.setErr(stderr); + + assertTrue(outString.contains( + "event input for peered mode \"REQUESTOR\": peer \"RestRequestorProducer\" for event handler \"RestRequestorConsumer\" does not exist or is not defined as being synchronous")); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/events/EventsIn.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/events/EventsIn.json new file mode 100644 index 000000000..037c5ca43 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/events/EventsIn.json @@ -0,0 +1,550 @@ +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/events/EventsInMulti.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/events/EventsInMulti.json new file mode 100644 index 000000000..49325ddea --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/events/EventsInMulti.json @@ -0,0 +1,22 @@ +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +} +{ + "nameSpace": "org.onap.policy.apex.sample.events", + "name": "Event0000", + "version": "0.0.1", + "source": "test", + "target": "apex", + "TestSlogan": "Test slogan for External Event0", + "TestMatchCase": 3, + "TestTimestamp": 1469781869271, + "TestTemperature": 8723.999 +}
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/policymodels/SamplePolicyModelMVEL.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/policymodels/SamplePolicyModelMVEL.json new file mode 100644 index 000000000..c87b265d9 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/policymodels/SamplePolicyModelMVEL.json @@ -0,0 +1,6348 @@ +{ + "apexPolicyModel" : { + "key" : { + "name" : "SamplePolicyModelMVEL", + "version" : "0.0.1" + }, + "keyInformation" : { + "key" : { + "name" : "KeyInformation", + "version" : "0.0.1" + }, + "keyInfoMap" : { + "entry" : [ { + "key" : { + "name" : "Context", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Context", + "version" : "0.0.1" + }, + "UUID" : "2708db15-3117-4ef5-ae06-44ad4bc72756", + "description" : "Generated description for concept referred to by key \"Context:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0000", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0000", + "version" : "0.0.1" + }, + "UUID" : "20f7f2d0-36e1-4134-93d9-8978e0ebb916", + "description" : "Generated description for concept referred to by key \"Event0000:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0001", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0001", + "version" : "0.0.1" + }, + "UUID" : "bfa262fc-f59d-4b05-af44-a5b5c218b314", + "description" : "Generated description for concept referred to by key \"Event0001:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0002", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0002", + "version" : "0.0.1" + }, + "UUID" : "84eeac88-5031-4487-b67a-5a3ae13c1a89", + "description" : "Generated description for concept referred to by key \"Event0002:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0003", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0003", + "version" : "0.0.1" + }, + "UUID" : "7a46a411-1715-48d8-9e70-9b5d14bbbed4", + "description" : "Generated description for concept referred to by key \"Event0003:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0004", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0004", + "version" : "0.0.1" + }, + "UUID" : "da0ba1b4-f654-4e99-97b5-595de84cb3dc", + "description" : "Generated description for concept referred to by key \"Event0004:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0100", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0100", + "version" : "0.0.1" + }, + "UUID" : "1267b311-60e2-48a7-8d0e-23c4ea21d863", + "description" : "Generated description for concept referred to by key \"Event0100:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0101", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0101", + "version" : "0.0.1" + }, + "UUID" : "84013070-ff2e-4295-acbd-4128f0509040", + "description" : "Generated description for concept referred to by key \"Event0101:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0102", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0102", + "version" : "0.0.1" + }, + "UUID" : "6fb7761e-b86f-47fc-8e19-6a116600764e", + "description" : "Generated description for concept referred to by key \"Event0102:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0103", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0103", + "version" : "0.0.1" + }, + "UUID" : "141cc707-009c-4e3b-a0f8-c346f074f590", + "description" : "Generated description for concept referred to by key \"Event0103:0.0.1\"" + } + }, { + "key" : { + "name" : "Event0104", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0104", + "version" : "0.0.1" + }, + "UUID" : "98f4d09f-ff73-4385-8876-df6d04b552cc", + "description" : "Generated description for concept referred to by key \"Event0104:0.0.1\"" + } + }, { + "key" : { + "name" : "Events", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Events", + "version" : "0.0.1" + }, + "UUID" : "889f6414-bc4d-4f29-b7af-175e63d23ac5", + "description" : "Generated description for concept referred to by key \"Events:0.0.1\"" + } + }, { + "key" : { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, + "UUID" : "64e4911c-5aed-467f-be19-277fb6170857", + "description" : "Generated description for concept referred to by key \"ExternalContextAlbum:0.0.1\"" + } + }, { + "key" : { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, + "UUID" : "cb6a1892-8c3c-44df-b8a7-0e5a333ff9eb", + "description" : "Generated description for concept referred to by key \"GlobalContextAlbum:0.0.1\"" + } + }, { + "key" : { + "name" : "KeyInformation", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "KeyInformation", + "version" : "0.0.1" + }, + "UUID" : "f3126983-e26c-491f-8738-c57784ca4026", + "description" : "Generated description for concept referred to by key \"KeyInformation:0.0.1\"" + } + }, { + "key" : { + "name" : "Policies", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Policies", + "version" : "0.0.1" + }, + "UUID" : "b20a18d5-c419-4e90-8519-9c8f8b3ce2ab", + "description" : "Generated description for concept referred to by key \"Policies:0.0.1\"" + } + }, { + "key" : { + "name" : "Policy0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Policy0", + "version" : "0.0.1" + }, + "UUID" : "28943e99-871b-482b-953f-cfa7138da02c", + "description" : "Generated description for concept referred to by key \"Policy0:0.0.1\"" + } + }, { + "key" : { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + }, + "UUID" : "2b1b738b-70f6-4b45-9d3c-a7e889b49993", + "description" : "Generated description for concept referred to by key \"Policy0ContextAlbum:0.0.1\"" + } + }, { + "key" : { + "name" : "Policy1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Policy1", + "version" : "0.0.1" + }, + "UUID" : "798ee6ea-f349-41bb-a281-7e4c22184e8c", + "description" : "Generated description for concept referred to by key \"Policy1:0.0.1\"" + } + }, { + "key" : { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + }, + "UUID" : "eb9568d5-d95f-4713-9622-d95ef4cf81c3", + "description" : "Generated description for concept referred to by key \"Policy1ContextAlbum:0.0.1\"" + } + }, { + "key" : { + "name" : "SamplePolicyModelMVEL", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "SamplePolicyModelMVEL", + "version" : "0.0.1" + }, + "UUID" : "10979d21-947f-4920-83ae-63b827e8e80f", + "description" : "Generated description for concept referred to by key \"SamplePolicyModelMVEL:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Act0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Act0", + "version" : "0.0.1" + }, + "UUID" : "cb65d7fe-8d86-463c-aa16-0f4e6138d705", + "description" : "Generated description for concept referred to by key \"Task_Act0:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Act1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Act1", + "version" : "0.0.1" + }, + "UUID" : "ea2b4e7a-1a79-440c-9cf0-6fddaad64c0c", + "description" : "Generated description for concept referred to by key \"Task_Act1:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Act2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Act2", + "version" : "0.0.1" + }, + "UUID" : "269e1d08-9ab4-48b8-8854-b65deb9d41b1", + "description" : "Generated description for concept referred to by key \"Task_Act2:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Act3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Act3", + "version" : "0.0.1" + }, + "UUID" : "f9c4a91d-92aa-49ce-9b65-ab2378f6b048", + "description" : "Generated description for concept referred to by key \"Task_Act3:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Decide0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Decide0", + "version" : "0.0.1" + }, + "UUID" : "7fde2446-ce2a-4bc2-a675-96496c387c88", + "description" : "Generated description for concept referred to by key \"Task_Decide0:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Decide1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Decide1", + "version" : "0.0.1" + }, + "UUID" : "bc185db6-f18f-4fdd-b5b4-37d14b57f463", + "description" : "Generated description for concept referred to by key \"Task_Decide1:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Decide2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Decide2", + "version" : "0.0.1" + }, + "UUID" : "2c1e2ede-d67c-4845-90ac-a4d53311bfbb", + "description" : "Generated description for concept referred to by key \"Task_Decide2:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Decide3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Decide3", + "version" : "0.0.1" + }, + "UUID" : "1d1645a2-2852-4296-9f22-8f31ebe5386a", + "description" : "Generated description for concept referred to by key \"Task_Decide3:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Establish0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Establish0", + "version" : "0.0.1" + }, + "UUID" : "f3739d83-a029-4ad8-a0b9-e5a028b369b2", + "description" : "Generated description for concept referred to by key \"Task_Establish0:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Establish1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Establish1", + "version" : "0.0.1" + }, + "UUID" : "5351a5a5-4134-44fd-9a6f-fd37dbfc8aa7", + "description" : "Generated description for concept referred to by key \"Task_Establish1:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Establish2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Establish2", + "version" : "0.0.1" + }, + "UUID" : "4206bb68-e710-4a01-aade-3e34771da63b", + "description" : "Generated description for concept referred to by key \"Task_Establish2:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Establish3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Establish3", + "version" : "0.0.1" + }, + "UUID" : "cbaab234-b586-4f63-986e-ed0b317b6c66", + "description" : "Generated description for concept referred to by key \"Task_Establish3:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Match0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Match0", + "version" : "0.0.1" + }, + "UUID" : "24dbc71b-8773-4393-9c36-a5f4991e0f55", + "description" : "Generated description for concept referred to by key \"Task_Match0:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Match1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Match1", + "version" : "0.0.1" + }, + "UUID" : "42ecd25d-e8cb-48e4-890a-b0616528cf10", + "description" : "Generated description for concept referred to by key \"Task_Match1:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Match2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Match2", + "version" : "0.0.1" + }, + "UUID" : "7e691294-a816-42f8-b124-9b5eac70b116", + "description" : "Generated description for concept referred to by key \"Task_Match2:0.0.1\"" + } + }, { + "key" : { + "name" : "Task_Match3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Match3", + "version" : "0.0.1" + }, + "UUID" : "bc7cad3c-85a5-40b4-9eda-51ac2387af05", + "description" : "Generated description for concept referred to by key \"Task_Match3:0.0.1\"" + } + }, { + "key" : { + "name" : "Tasks", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Tasks", + "version" : "0.0.1" + }, + "UUID" : "4386403d-b23c-4c3e-bc14-5d581f9de2f5", + "description" : "Generated description for concept referred to by key \"Tasks:0.0.1\"" + } + }, { + "key" : { + "name" : "TestCase", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestCase", + "version" : "0.0.1" + }, + "UUID" : "901a80ab-dd46-4697-b818-f669b9f9bce9", + "description" : "Generated description for concept referred to by key \"TestCase:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem000", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem000", + "version" : "0.0.1" + }, + "UUID" : "cfd19e5d-ab54-4e54-b4e5-1c5eaa832622", + "description" : "Generated description for concept referred to by key \"TestContextItem000:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem001", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem001", + "version" : "0.0.1" + }, + "UUID" : "42c27d27-878d-4e9d-a139-e60c98f1c747", + "description" : "Generated description for concept referred to by key \"TestContextItem001:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem002", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem002", + "version" : "0.0.1" + }, + "UUID" : "83919fa0-ed4d-4981-908f-79913734a0f5", + "description" : "Generated description for concept referred to by key \"TestContextItem002:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem003", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem003", + "version" : "0.0.1" + }, + "UUID" : "194882b0-d987-4200-b82a-2c015605279b", + "description" : "Generated description for concept referred to by key \"TestContextItem003:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem004", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem004", + "version" : "0.0.1" + }, + "UUID" : "948d345b-39c3-4436-8036-ac9e5c561977", + "description" : "Generated description for concept referred to by key \"TestContextItem004:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem005", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem005", + "version" : "0.0.1" + }, + "UUID" : "fdad8cb5-4375-4bbf-9ffc-1e5ed8f4bae6", + "description" : "Generated description for concept referred to by key \"TestContextItem005:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem006", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem006", + "version" : "0.0.1" + }, + "UUID" : "5243c0ba-5c50-4835-a885-6cd988252bb7", + "description" : "Generated description for concept referred to by key \"TestContextItem006:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem007", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem007", + "version" : "0.0.1" + }, + "UUID" : "29f0b15f-f7c3-46e5-98d7-59a34a677968", + "description" : "Generated description for concept referred to by key \"TestContextItem007:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem008", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem008", + "version" : "0.0.1" + }, + "UUID" : "aac96de5-9f3c-452c-855f-e556cc807351", + "description" : "Generated description for concept referred to by key \"TestContextItem008:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem009", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem009", + "version" : "0.0.1" + }, + "UUID" : "7fdc1cc3-08c7-42a4-92a9-39e172fe2f1f", + "description" : "Generated description for concept referred to by key \"TestContextItem009:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem00A", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem00A", + "version" : "0.0.1" + }, + "UUID" : "cf60cca6-a2e8-4371-b0e5-85ecaae44acc", + "description" : "Generated description for concept referred to by key \"TestContextItem00A:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem00B", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem00B", + "version" : "0.0.1" + }, + "UUID" : "1671f996-e14e-407d-a503-f4de09f0785b", + "description" : "Generated description for concept referred to by key \"TestContextItem00B:0.0.1\"" + } + }, { + "key" : { + "name" : "TestContextItem00C", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem00C", + "version" : "0.0.1" + }, + "UUID" : "814c4c28-9027-4516-9598-adc75fafa92a", + "description" : "Generated description for concept referred to by key \"TestContextItem00C:0.0.1\"" + } + }, { + "key" : { + "name" : "TestDatatypes", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestDatatypes", + "version" : "0.0.1" + }, + "UUID" : "33e81d08-a62b-40ce-b7ff-50734427ebf9", + "description" : "Generated description for concept referred to by key \"TestDatatypes:0.0.1\"" + } + }, { + "key" : { + "name" : "TestExternalContextItem", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestExternalContextItem", + "version" : "0.0.1" + }, + "UUID" : "5cd74351-8e27-4dee-a379-86124db50383", + "description" : "Generated description for concept referred to by key \"TestExternalContextItem:0.0.1\"" + } + }, { + "key" : { + "name" : "TestGlobalContextItem", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestGlobalContextItem", + "version" : "0.0.1" + }, + "UUID" : "e8c9a056-5e95-4e14-bc96-0c0d13a34b18", + "description" : "Generated description for concept referred to by key \"TestGlobalContextItem:0.0.1\"" + } + }, { + "key" : { + "name" : "TestPolicyContextItem", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestPolicyContextItem", + "version" : "0.0.1" + }, + "UUID" : "92489659-02f3-4cb2-b25f-a6234ad71d36", + "description" : "Generated description for concept referred to by key \"TestPolicyContextItem:0.0.1\"" + } + }, { + "key" : { + "name" : "TestSlogan", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestSlogan", + "version" : "0.0.1" + }, + "UUID" : "1c3b9345-32c2-4f7e-94ce-be36d0775e9e", + "description" : "Generated description for concept referred to by key \"TestSlogan:0.0.1\"" + } + }, { + "key" : { + "name" : "TestTemperature", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestTemperature", + "version" : "0.0.1" + }, + "UUID" : "9e719a99-1d73-4d40-b097-c9622b9ea2b4", + "description" : "Generated description for concept referred to by key \"TestTemperature:0.0.1\"" + } + }, { + "key" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + }, + "UUID" : "3bcc8ef1-4cc5-4b7f-9dc4-83046d4a2a5d", + "description" : "Generated description for concept referred to by key \"TestTimestamp:0.0.1\"" + } + } ] + } + }, + "policies" : { + "key" : { + "name" : "Policies", + "version" : "0.0.1" + }, + "policyMap" : { + "entry" : [ { + "key" : { + "name" : "Policy0", + "version" : "0.0.1" + }, + "value" : { + "policyKey" : { + "name" : "Policy0", + "version" : "0.0.1" + }, + "template" : "MEDA", + "state" : { + "entry" : [ { + "key" : "Act", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Act" + }, + "trigger" : { + "name" : "Event0003", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "Act_NULL", + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + }, + "outgoingEvent" : { + "name" : "Event0004", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "NULL", + "parentKeyVersion" : "0.0.0", + "parentLocalName" : "NULL", + "localName" : "NULL" + } + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + } ], + "taskSelectionLogic" : { + "key" : "TaskSelectionLigic", + "logicFlavour" : "MVEL", + "logic" : "logger.debug(subject.id + \":\" + subject.stateName);\nsubject.defaultTaskKey.copyTo(selectedTask);\nreturn true;" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "Task_Act1", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "Task_Act0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Task_Act0_DIRECT_Act_NULL" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + } + } + }, { + "key" : { + "name" : "Task_Act1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Task_Act1_DIRECT_Act_NULL" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + } + } + }, { + "key" : { + "name" : "Task_Act2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Task_Act2_DIRECT_Act_NULL" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + } + } + }, { + "key" : { + "name" : "Task_Act3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Task_Act3_DIRECT_Act_NULL" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + } + } + } ] + } + } + }, { + "key" : "Decide", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Decide" + }, + "trigger" : { + "name" : "Event0002", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "Decide_Act", + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + }, + "outgoingEvent" : { + "name" : "Event0003", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Act" + } + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + } ], + "taskSelectionLogic" : { + "key" : "TaskSelectionLigic", + "logicFlavour" : "MVEL", + "logic" : "logger.debug(subject.id + \":\" + subject.stateName);\nsubject.defaultTaskKey.copyTo(selectedTask);\nreturn true;" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "Task_Decide3", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "Task_Decide0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Task_Decide0_DIRECT_Decide_Act" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + } + } + }, { + "key" : { + "name" : "Task_Decide1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Task_Decide1_DIRECT_Decide_Act" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + } + } + }, { + "key" : { + "name" : "Task_Decide2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Task_Decide2_DIRECT_Decide_Act" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + } + } + }, { + "key" : { + "name" : "Task_Decide3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Task_Decide3_DIRECT_Decide_Act" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + } + } + } ] + } + } + }, { + "key" : "Establish", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Establish" + }, + "trigger" : { + "name" : "Event0001", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "Establish_Decide", + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + }, + "outgoingEvent" : { + "name" : "Event0002", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Decide" + } + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskSelectionLogic" : { + "key" : "TaskSelectionLigic", + "logicFlavour" : "MVEL", + "logic" : "logger.debug(subject.id + \":\" + subject.stateName);\nsubject.defaultTaskKey.copyTo(selectedTask);\nreturn true;" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "Task_Establish2", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "Task_Establish0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Task_Establish0_DIRECT_Establish_Decide" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + } + } + }, { + "key" : { + "name" : "Task_Establish1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Task_Establish1_DIRECT_Establish_Decide" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + } + } + }, { + "key" : { + "name" : "Task_Establish2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Task_Establish2_DIRECT_Establish_Decide" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + } + } + }, { + "key" : { + "name" : "Task_Establish3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Task_Establish3_DIRECT_Establish_Decide" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + } + } + } ] + } + } + }, { + "key" : "Match", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Match" + }, + "trigger" : { + "name" : "Event0000", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "Match_Establish", + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + }, + "outgoingEvent" : { + "name" : "Event0001", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Establish" + } + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + } ], + "taskSelectionLogic" : { + "key" : "TaskSelectionLigic", + "logicFlavour" : "MVEL", + "logic" : "logger.debug(subject.id + \":\" + subject.stateName);\nsubject.defaultTaskKey.copyTo(selectedTask);\nreturn true;" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "Task_Match0", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "Task_Match0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Task_Match0_DIRECT_Match_Establish" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + } + } + }, { + "key" : { + "name" : "Task_Match1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Task_Match1_DIRECT_Match_Establish" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + } + } + }, { + "key" : { + "name" : "Task_Match2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Task_Match2_DIRECT_Match_Establish" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + } + } + }, { + "key" : { + "name" : "Task_Match3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Task_Match3_DIRECT_Match_Establish" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + } + } + } ] + } + } + } ] + }, + "firstState" : "Match" + } + }, { + "key" : { + "name" : "Policy1", + "version" : "0.0.1" + }, + "value" : { + "policyKey" : { + "name" : "Policy1", + "version" : "0.0.1" + }, + "template" : "MEDA", + "state" : { + "entry" : [ { + "key" : "Act", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Act" + }, + "trigger" : { + "name" : "Event0103", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "Act_NULL", + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + }, + "outgoingEvent" : { + "name" : "Event0104", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "NULL", + "parentKeyVersion" : "0.0.0", + "parentLocalName" : "NULL", + "localName" : "NULL" + } + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + } ], + "taskSelectionLogic" : { + "key" : "TaskSelectionLigic", + "logicFlavour" : "MVEL", + "logic" : "logger.debug(subject.id + \":\" + subject.stateName);\nsubject.defaultTaskKey.copyTo(selectedTask);\nreturn true;" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "Task_Act0", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "Task_Act0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Task_Act0_DIRECT_Act_NULL" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + } + } + }, { + "key" : { + "name" : "Task_Act1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Task_Act1_DIRECT_Act_NULL" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + } + } + }, { + "key" : { + "name" : "Task_Act2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Task_Act2_DIRECT_Act_NULL" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + } + } + }, { + "key" : { + "name" : "Task_Act3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Task_Act3_DIRECT_Act_NULL" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Act", + "localName" : "Act_NULL" + } + } + } ] + } + } + }, { + "key" : "Decide", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Decide" + }, + "trigger" : { + "name" : "Event0102", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "Decide_Act", + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + }, + "outgoingEvent" : { + "name" : "Event0103", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Act" + } + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskSelectionLogic" : { + "key" : "TaskSelectionLigic", + "logicFlavour" : "MVEL", + "logic" : "logger.debug(subject.id + \":\" + subject.stateName);\nsubject.defaultTaskKey.copyTo(selectedTask);\nreturn true;" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "Task_Decide3", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "Task_Decide0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Task_Decide0_DIRECT_Decide_Act" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + } + } + }, { + "key" : { + "name" : "Task_Decide1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Task_Decide1_DIRECT_Decide_Act" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + } + } + }, { + "key" : { + "name" : "Task_Decide2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Task_Decide2_DIRECT_Decide_Act" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + } + } + }, { + "key" : { + "name" : "Task_Decide3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Task_Decide3_DIRECT_Decide_Act" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Decide", + "localName" : "Decide_Act" + } + } + } ] + } + } + }, { + "key" : "Establish", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Establish" + }, + "trigger" : { + "name" : "Event0101", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "Establish_Decide", + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + }, + "outgoingEvent" : { + "name" : "Event0102", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Decide" + } + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskSelectionLogic" : { + "key" : "TaskSelectionLigic", + "logicFlavour" : "MVEL", + "logic" : "logger.debug(subject.id + \":\" + subject.stateName);\nsubject.defaultTaskKey.copyTo(selectedTask);\nreturn true;" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "Task_Establish1", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "Task_Establish0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Task_Establish0_DIRECT_Establish_Decide" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + } + } + }, { + "key" : { + "name" : "Task_Establish1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Task_Establish1_DIRECT_Establish_Decide" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + } + } + }, { + "key" : { + "name" : "Task_Establish2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Task_Establish2_DIRECT_Establish_Decide" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + } + } + }, { + "key" : { + "name" : "Task_Establish3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Task_Establish3_DIRECT_Establish_Decide" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Establish", + "localName" : "Establish_Decide" + } + } + } ] + } + } + }, { + "key" : "Match", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Match" + }, + "trigger" : { + "name" : "Event0100", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "Match_Establish", + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + }, + "outgoingEvent" : { + "name" : "Event0101", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Establish" + } + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskSelectionLogic" : { + "key" : "TaskSelectionLigic", + "logicFlavour" : "MVEL", + "logic" : "logger.debug(subject.id + \":\" + subject.stateName);\nsubject.defaultTaskKey.copyTo(selectedTask);\nreturn true;" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "Task_Match3", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "Task_Match0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Task_Match0_DIRECT_Match_Establish" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + } + } + }, { + "key" : { + "name" : "Task_Match1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Task_Match1_DIRECT_Match_Establish" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + } + } + }, { + "key" : { + "name" : "Task_Match2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Task_Match2_DIRECT_Match_Establish" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + } + } + }, { + "key" : { + "name" : "Task_Match3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Task_Match3_DIRECT_Match_Establish" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "Match", + "localName" : "Match_Establish" + } + } + } ] + } + } + } ] + }, + "firstState" : "Match" + } + } ] + } + }, + "tasks" : { + "key" : { + "name" : "Tasks", + "version" : "0.0.1" + }, + "taskMap" : { + "entry" : [ { + "key" : { + "name" : "Task_Act0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Act0", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestActCaseSelected", + "value" : { + "key" : "TestActCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestActStateTime", + "value" : { + "key" : "TestActStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Act0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + }, { + "key" : "Parameter1", + "value" : { + "key" : { + "parentKeyName" : "Task_Act0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter1" + }, + "defaultValue" : "DefaultValue1" + } + }, { + "key" : "Parameter2", + "value" : { + "key" : { + "parentKeyName" : "Task_Act0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter2" + }, + "defaultValue" : "DefaultValue2" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestActCaseSelected\"] = (byte)2;\ntimeNow = new Date();\noutFields[\"TestActStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Act1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Act1", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestActCaseSelected", + "value" : { + "key" : "TestActCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestActStateTime", + "value" : { + "key" : "TestActStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Act1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + }, { + "key" : "Parameter1", + "value" : { + "key" : { + "parentKeyName" : "Task_Act1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter1" + }, + "defaultValue" : "DefaultValue1" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestActCaseSelected\"] = (byte)3;\ntimeNow = new Date();\noutFields[\"TestActStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Act2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Act2", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestActCaseSelected", + "value" : { + "key" : "TestActCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestActStateTime", + "value" : { + "key" : "TestActStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Act2", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestActCaseSelected\"] = (byte)0;\ntimeNow = new Date();\noutFields[\"TestActStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Act3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Act3", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestActCaseSelected", + "value" : { + "key" : "TestActCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestActStateTime", + "value" : { + "key" : "TestActStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Act3", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestActCaseSelected\"] = (byte)1;\ntimeNow = new Date();\noutFields[\"TestActStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Decide0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Decide0", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Decide0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + }, { + "key" : "Parameter1", + "value" : { + "key" : { + "parentKeyName" : "Task_Decide0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter1" + }, + "defaultValue" : "DefaultValue1" + } + }, { + "key" : "Parameter2", + "value" : { + "key" : { + "parentKeyName" : "Task_Decide0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter2" + }, + "defaultValue" : "DefaultValue2" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestDecideCaseSelected\"] = (byte)2;\ntimeNow = new Date();\noutFields[\"TestDecideStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Decide1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Decide1", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Decide1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + }, { + "key" : "Parameter1", + "value" : { + "key" : { + "parentKeyName" : "Task_Decide1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter1" + }, + "defaultValue" : "DefaultValue1" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestDecideCaseSelected\"] = (byte)3;\ntimeNow = new Date();\noutFields[\"TestDecideStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Decide2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Decide2", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Decide2", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestDecideCaseSelected\"] = (byte)0;\ntimeNow = new Date();\noutFields[\"TestDecideStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Decide3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Decide3", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Decide3", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestDecideCaseSelected\"] = (byte)1;\ntimeNow = new Date();\noutFields[\"TestDecideStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Establish0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Establish0", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Establish0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + }, { + "key" : "Parameter1", + "value" : { + "key" : { + "parentKeyName" : "Task_Establish0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter1" + }, + "defaultValue" : "DefaultValue1" + } + }, { + "key" : "Parameter2", + "value" : { + "key" : { + "parentKeyName" : "Task_Establish0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter2" + }, + "defaultValue" : "DefaultValue2" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestEstablishCaseSelected\"] = (byte)2;\ntimeNow = new Date();\noutFields[\"TestEstablishStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Establish1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Establish1", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Establish1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + }, { + "key" : "Parameter1", + "value" : { + "key" : { + "parentKeyName" : "Task_Establish1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter1" + }, + "defaultValue" : "DefaultValue1" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestEstablishCaseSelected\"] = (byte)3;\ntimeNow = new Date();\noutFields[\"TestEstablishStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Establish2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Establish2", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Establish2", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestEstablishCaseSelected\"] = (byte)0;\ntimeNow = new Date();\noutFields[\"TestEstablishStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Establish3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Establish3", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Establish3", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestEstablishCaseSelected\"] = (byte)1;\ntimeNow = new Date();\noutFields[\"TestEstablishStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Match0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Match0", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Match0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + }, { + "key" : "Parameter1", + "value" : { + "key" : { + "parentKeyName" : "Task_Match0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter1" + }, + "defaultValue" : "DefaultValue1" + } + }, { + "key" : "Parameter2", + "value" : { + "key" : { + "parentKeyName" : "Task_Match0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter2" + }, + "defaultValue" : "DefaultValue2" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestMatchCaseSelected\"] = (byte)2;\ntimeNow = new Date();\noutFields[\"TestMatchStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Match1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Match1", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Match1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + }, { + "key" : "Parameter1", + "value" : { + "key" : { + "parentKeyName" : "Task_Match1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter1" + }, + "defaultValue" : "DefaultValue1" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestMatchCaseSelected\"] = (byte)3;\ntimeNow = new Date();\noutFields[\"TestMatchStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Match2", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Match2", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Match2", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestMatchCaseSelected\"] = (byte)0;\ntimeNow = new Date();\noutFields[\"TestMatchStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + }, { + "key" : { + "name" : "Task_Match3", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Task_Match3", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + }, + "taskParameters" : { + "entry" : [ { + "key" : "Parameter0", + "value" : { + "key" : { + "parentKeyName" : "Task_Match3", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "Parameter0" + }, + "defaultValue" : "DefaultValue0" + } + } ] + }, + "contextAlbumReference" : [ { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "_TaskLogic", + "logicFlavour" : "MVEL", + "logic" : "import java.util.Date;\nlogger.debug(subject.id);\ngc = getContextAlbum(\"GlobalContextAlbum\");\nlogger.debug(gc);\nlogger.debug(inFields);\noutFields[\"TestMatchCaseSelected\"] = (byte)1;\ntimeNow = new Date();\noutFields[\"TestMatchStateTime\"] = timeNow.getTime();\nlogger.debug(outFields);\nreturn true;" + } + } + } ] + } + }, + "events" : { + "key" : { + "name" : "Events", + "version" : "0.0.1" + }, + "eventMap" : { + "entry" : [ { + "key" : { + "name" : "Event0000", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0000", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Outside", + "target" : "Match", + "parameter" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + }, { + "key" : { + "name" : "Event0001", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0001", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Match", + "target" : "Establish", + "parameter" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + }, { + "key" : { + "name" : "Event0002", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0002", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Establish", + "target" : "Decide", + "parameter" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + }, { + "key" : { + "name" : "Event0003", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0003", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Decide", + "target" : "Act", + "parameter" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + }, { + "key" : { + "name" : "Event0004", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0004", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Act", + "target" : "Outside", + "parameter" : { + "entry" : [ { + "key" : "TestActCaseSelected", + "value" : { + "key" : "TestActCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestActStateTime", + "value" : { + "key" : "TestActStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + }, { + "key" : { + "name" : "Event0100", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0100", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Outside", + "target" : "Match", + "parameter" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + }, { + "key" : { + "name" : "Event0101", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0101", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Match", + "target" : "Establish", + "parameter" : { + "entry" : [ { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + }, { + "key" : { + "name" : "Event0102", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0102", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Establish", + "target" : "Decide", + "parameter" : { + "entry" : [ { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + }, { + "key" : { + "name" : "Event0103", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0103", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Decide", + "target" : "Act", + "parameter" : { + "entry" : [ { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + }, { + "key" : { + "name" : "Event0104", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Event0104", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.sample.events", + "source" : "Act", + "target" : "Outside", + "parameter" : { + "entry" : [ { + "key" : "TestActCaseSelected", + "value" : { + "key" : "TestActCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestActStateTime", + "value" : { + "key" : "TestActStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideCaseSelected", + "value" : { + "key" : "TestDecideCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestDecideStateTime", + "value" : { + "key" : "TestDecideStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishCaseSelected", + "value" : { + "key" : "TestEstablishCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestEstablishStateTime", + "value" : { + "key" : "TestEstablishStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCase", + "value" : { + "key" : "TestMatchCase", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchCaseSelected", + "value" : { + "key" : "TestMatchCaseSelected", + "fieldSchemaKey" : { + "name" : "TestCase", + "version" : "0.0.1" + } + } + }, { + "key" : "TestMatchStateTime", + "value" : { + "key" : "TestMatchStateTime", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + }, { + "key" : "TestSlogan", + "value" : { + "key" : "TestSlogan", + "fieldSchemaKey" : { + "name" : "TestSlogan", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTemperature", + "value" : { + "key" : "TestTemperature", + "fieldSchemaKey" : { + "name" : "TestTemperature", + "version" : "0.0.1" + } + } + }, { + "key" : "TestTimestamp", + "value" : { + "key" : "TestTimestamp", + "fieldSchemaKey" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + } + } + } ] + } + } + } ] + } + }, + "albums" : { + "key" : { + "name" : "Context", + "version" : "0.0.1" + }, + "albums" : { + "entry" : [ { + "key" : { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "ExternalContextAlbum", + "version" : "0.0.1" + }, + "scope" : "EXTERNAL", + "isWritable" : false, + "itemSchema" : { + "name" : "TestExternalContextItem", + "version" : "0.0.1" + } + } + }, { + "key" : { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "GlobalContextAlbum", + "version" : "0.0.1" + }, + "scope" : "GLOBAL", + "isWritable" : true, + "itemSchema" : { + "name" : "TestGlobalContextItem", + "version" : "0.0.1" + } + } + }, { + "key" : { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Policy0ContextAlbum", + "version" : "0.0.1" + }, + "scope" : "APPLICATION", + "isWritable" : true, + "itemSchema" : { + "name" : "TestPolicyContextItem", + "version" : "0.0.1" + } + } + }, { + "key" : { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Policy1ContextAlbum", + "version" : "0.0.1" + }, + "scope" : "APPLICATION", + "isWritable" : true, + "itemSchema" : { + "name" : "TestPolicyContextItem", + "version" : "0.0.1" + } + } + } ] + } + }, + "schemas" : { + "key" : { + "name" : "TestDatatypes", + "version" : "0.0.1" + }, + "schemas" : { + "entry" : [ { + "key" : { + "name" : "TestCase", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestCase", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "java.lang.Byte" + } + }, { + "key" : { + "name" : "TestContextItem000", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem000", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem000" + } + }, { + "key" : { + "name" : "TestContextItem001", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem001", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem001" + } + }, { + "key" : { + "name" : "TestContextItem002", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem002", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem002" + } + }, { + "key" : { + "name" : "TestContextItem003", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem003", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem003" + } + }, { + "key" : { + "name" : "TestContextItem004", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem004", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem004" + } + }, { + "key" : { + "name" : "TestContextItem005", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem005", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem005" + } + }, { + "key" : { + "name" : "TestContextItem006", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem006", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem006" + } + }, { + "key" : { + "name" : "TestContextItem007", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem007", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem007" + } + }, { + "key" : { + "name" : "TestContextItem008", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem008", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem008" + } + }, { + "key" : { + "name" : "TestContextItem009", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem009", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem009" + } + }, { + "key" : { + "name" : "TestContextItem00A", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem00A", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem00A" + } + }, { + "key" : { + "name" : "TestContextItem00B", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem00B", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem00B" + } + }, { + "key" : { + "name" : "TestContextItem00C", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestContextItem00C", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestContextItem00C" + } + }, { + "key" : { + "name" : "TestExternalContextItem", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestExternalContextItem", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestExternalContextItem" + } + }, { + "key" : { + "name" : "TestGlobalContextItem", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestGlobalContextItem", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestGlobalContextItem" + } + }, { + "key" : { + "name" : "TestPolicyContextItem", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestPolicyContextItem", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "org.onap.policy.apex.context.test.concepts.TestPolicyContextItem" + } + }, { + "key" : { + "name" : "TestSlogan", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestSlogan", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "java.lang.String" + } + }, { + "key" : { + "name" : "TestTemperature", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestTemperature", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "java.lang.Double" + } + }, { + "key" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "TestTimestamp", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "java.lang.Long" + } + } ] + } + } + } +}
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json new file mode 100644 index 000000000..6e12c0b1f --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json @@ -0,0 +1,75 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "src/test/resources/policymodels/SamplePolicyModelMVEL.json", + "engineParameters": { + "executorParameters": { + "MVEL": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FileConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsIn.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "RestRequestorConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/TestRESTRequestor/apex/event/DeleteEvent", + "httpMethod": "DELETE", + "restRequestTimeout": 2000 + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0100", + "requestorMode": true, + "requestorPeer": "RestRequestorProducer", + "requestorTimeout": 500 + } + }, + "eventOutputParameters": { + "RestRequestorProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0004", + "requestorMode": true, + "requestorPeer": "RestRequestorConsumer", + "requestorTimeout": 500 + }, + "FileProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOut.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0104" + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json new file mode 100644 index 000000000..d0879eb73 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json @@ -0,0 +1,75 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "src/test/resources/policymodels/SamplePolicyModelMVEL.json", + "engineParameters": { + "executorParameters": { + "MVEL": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FileConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsIn.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "RestRequestorConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent", + "httpMethod": "GET", + "restRequestTimeout": 2000 + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0100", + "requestorMode": true, + "requestorPeer": "RestRequestorProducer", + "requestorTimeout": 500 + } + }, + "eventOutputParameters": { + "RestRequestorProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0004", + "requestorMode": true, + "requestorPeer": "RestRequestorConsumer", + "requestorTimeout": 500 + }, + "FileProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOut.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0104" + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json new file mode 100644 index 000000000..b957b61de --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json @@ -0,0 +1,71 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "src/test/resources/policymodels/SamplePolicyModelMVEL.json", + "engineParameters": { + "executorParameters": { + "MVEL": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FileConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsIn.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "RestRequestorConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent", + "httpMethod": "GET", + "restRequestTimeout": 2000 + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0100", + "requestorMode": true, + "requestorPeer": "RestRequestorProducer", + "requestorTimeout": 500 + } + }, + "eventOutputParameters": { + "RestRequestorProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "FileProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOut.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0104" + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json new file mode 100644 index 000000000..ba1c997f5 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json @@ -0,0 +1,129 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "src/test/resources/policymodels/SamplePolicyModelMVEL.json", + "engineParameters": { + "executorParameters": { + "MVEL": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FileConsumer0": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsInMulti.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "RestRequestorConsumer0": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent", + "httpMethod": "GET", + "restRequestTimeout": 2000 + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0100", + "requestorMode": true, + "requestorPeer": "RestRequestorProducer0", + "requestorTimeout": 500 + }, + "FileConsumer1": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsInMulti.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "RestRequestorConsumer1": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent", + "httpMethod": "GET", + "restRequestTimeout": 2000 + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0100", + "requestorMode": true, + "requestorPeer": "RestRequestorProducer1", + "requestorTimeout": 500 + } + }, + "eventOutputParameters": { + "RestRequestorProducer0": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0004", + "requestorMode": true, + "requestorPeer": "RestRequestorConsumer0", + "requestorTimeout": 500 + }, + "FileProducer0": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOutMulti0.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0104" + }, + "RestRequestorProducer1": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0004", + "requestorMode": true, + "requestorPeer": "RestRequestorConsumer1", + "requestorTimeout": 500 + }, + "FileProducer1": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOutMulti1.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0104" + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json new file mode 100644 index 000000000..a635e6c72 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json @@ -0,0 +1,54 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "src/test/resources/policymodels/SamplePolicyModelMVEL.json", + "engineParameters": { + "executorParameters": { + "MVEL": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FileConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsIn.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventOutputParameters": { + "RestRequestorProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0004" + }, + "FileProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOut.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0104" + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json new file mode 100644 index 000000000..9db89ce89 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json @@ -0,0 +1,75 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "src/test/resources/policymodels/SamplePolicyModelMVEL.json", + "engineParameters": { + "executorParameters": { + "MVEL": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FileConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsIn.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "RestRequestorConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/TestRESTRequestor/apex/event/PostEvent", + "httpMethod": "POST", + "restRequestTimeout": 2000 + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0100", + "requestorMode": true, + "requestorPeer": "RestRequestorProducer", + "requestorTimeout": 500 + } + }, + "eventOutputParameters": { + "RestRequestorProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0004", + "requestorMode": true, + "requestorPeer": "RestRequestorConsumer", + "requestorTimeout": 500 + }, + "FileProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOut.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0104" + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json new file mode 100644 index 000000000..3eebe3d8a --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json @@ -0,0 +1,75 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "src/test/resources/policymodels/SamplePolicyModelMVEL.json", + "engineParameters": { + "executorParameters": { + "MVEL": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "FileConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsIn.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "RestRequestorConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameters": { + "url": "http://localhost:32801/TestRESTRequestor/apex/event/PutEvent", + "httpMethod": "PUT", + "restRequestTimeout": 2000 + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0100", + "requestorMode": true, + "requestorPeer": "RestRequestorProducer", + "requestorTimeout": 500 + } + }, + "eventOutputParameters": { + "RestRequestorProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0004", + "requestorMode": true, + "requestorPeer": "RestRequestorConsumer", + "requestorTimeout": 500 + }, + "FileProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOut.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "Event0104" + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/pom.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/pom.xml new file mode 100644 index 000000000..643908932 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/pom.xml @@ -0,0 +1,59 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId> + <artifactId>plugins-event-carrier</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>plugins-event-carrier-restserver</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] Plugin for handling events being transported over REST where Apex acts as a REST server</description> + + <properties> + <apex-plugins-event-carrier-restserver-dir>${project.basedir}/src</apex-plugins-event-carrier-restserver-dir> + </properties> + + <dependencies> + <dependency> + <groupId>org.onap.policy.apex-pdp.services</groupId> + <artifactId>services-engine</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-client</artifactId> + <version>${version.jersey.core}</version> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.containers</groupId> + <artifactId>jersey-container-grizzly2-http</artifactId> + <version>${version.grizzly2-http}</version> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.containers</groupId> + <artifactId>jersey-container-servlet-core</artifactId> + <version>2.25.1</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java new file mode 100644 index 000000000..71bf80f66 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java @@ -0,0 +1,281 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restserver; + +import java.net.URI; +import java.util.EnumMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + +import javax.ws.rs.core.Response; + +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.server.ResourceConfig; +import org.onap.policy.apex.core.infrastructure.threading.ApplicationThreadFactory; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.service.engine.event.ApexEventConsumer; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class implements an Apex event consumer that receives events from a REST server. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexRestServerConsumer implements ApexEventConsumer, Runnable { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexRestServerConsumer.class); + + private static final String BASE_URI_TEMPLATE = "http://%s:%d/apex"; + + // The amount of time to wait in milliseconds between checks that the consumer thread has stopped + private static final long REST_SERVER_CONSUMER_WAIT_SLEEP_TIME = 50; + + // The REST parameters read from the parameter service + private RESTServerCarrierTechnologyParameters restConsumerProperties; + + // The event receiver that will receive events from this consumer + private ApexEventReceiver eventReceiver; + + // The name for this consumer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + // The consumer thread and stopping flag + private Thread consumerThread; + private boolean stopOrderedFlag = false; + + // The local HTTP server to use for REST call reception if we are running a local Grizzly server + private HttpServer server; + + // Holds the next identifier for event execution. + private static AtomicLong nextExecutionID = new AtomicLong(0L); + + /** + * Private utility to get the next candidate value for a Execution ID. This value will always be unique in a single + * JVM + * + * @return the next candidate value for a Execution ID + */ + private static synchronized long getNextExecutionID() { + return nextExecutionID.getAndIncrement(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#init(java.lang.String, + * org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters, + * org.onap.policy.apex.service.engine.event.ApexEventReceiver) + */ + @Override + public void init(final String consumerName, final EventHandlerParameters consumerParameters, + final ApexEventReceiver incomingEventReceiver) throws ApexEventException { + this.eventReceiver = incomingEventReceiver; + this.name = consumerName; + + // Check and get the REST Properties + if (!(consumerParameters.getCarrierTechnologyParameters() instanceof RESTServerCarrierTechnologyParameters)) { + final String errorMessage = + "specified consumer properties are not applicable to REST Server consumer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + restConsumerProperties = + (RESTServerCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); + + // Check if we are in synchronous mode + if (!consumerParameters.isPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS)) { + final String errorMessage = + "REST Server consumer (" + this.name + ") must run in synchronous mode with a REST Server producer"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Check if we're in standalone mode + if (restConsumerProperties.isStandalone()) { + // Check if host and port are defined + if (restConsumerProperties.getHost() == null || restConsumerProperties.getPort() == -1) { + final String errorMessage = + "the parameters \"host\" and \"port\" must be defined for REST Server consumer (" + this.name + + ") in standalone mode"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Compose the URI for the standalone server + final String baseURI = String.format(BASE_URI_TEMPLATE, restConsumerProperties.getHost(), + restConsumerProperties.getPort()); + + // Instantiate the standalone server + final ResourceConfig rc = new ResourceConfig(RestServerEndpoint.class); + server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseURI), rc); + + while (!server.isStarted()) { + ThreadUtilities.sleep(REST_SERVER_CONSUMER_WAIT_SLEEP_TIME); + } + } + + // Register this consumer with the REST server end point + RestServerEndpoint.registerApexRestServerConsumer(this.name, this); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#start() + */ + @Override + public void start() { + // Configure and start the event reception thread + final String threadName = this.getClass().getName() + ":" + this.name; + consumerThread = new ApplicationThreadFactory(threadName).newThread(this); + consumerThread.setDaemon(true); + consumerThread.start(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#setPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /** + * Receive an event for processing in Apex. + * + * @param event the event to receive + * @return the response from Apex + */ + public Response receiveEvent(final String event) { + // Get an execution ID for the event + final long executionId = getNextExecutionID(); + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(name + ": sending event " + name + '_' + executionId + " to Apex, event=" + event); + } + + try { + // Send the event into Apex + eventReceiver.receiveEvent(executionId, event); + } catch (final Exception e) { + final String errorMessage = "error receiving events on event consumer " + name + ", " + e.getMessage(); + LOGGER.warn(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) + .entity("{'errorMessage', '" + errorMessage + "'}").build(); + } + + final SynchronousEventCache synchronousEventCache = + (SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS); + // Wait until the event is in the cache of events sent to apex + do { + ThreadUtilities.sleep(REST_SERVER_CONSUMER_WAIT_SLEEP_TIME); + } while (!synchronousEventCache.existsEventToApex(executionId)); + + // Now wait for the reply or for the event to time put + do { + ThreadUtilities.sleep(REST_SERVER_CONSUMER_WAIT_SLEEP_TIME); + + // Check if we have received an answer from Apex + if (synchronousEventCache.existsEventFromApex(executionId)) { + // We have received a response event, read and remove the response event and remove the sent event from + // the cache + final Object responseEvent = synchronousEventCache.removeCachedEventFromApexIfExists(executionId); + synchronousEventCache.removeCachedEventToApexIfExists(executionId); + + // Return the event as a response to the call + return Response.status(Response.Status.OK.getStatusCode()).entity(responseEvent.toString()).build(); + } + } while (synchronousEventCache.existsEventToApex(executionId)); + + // The event timed out + final String errorMessage = "processing of event on event consumer " + name + " timed out, event=" + event; + LOGGER.warn(errorMessage); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) + .entity("{'errorMessage', '" + errorMessage + "'}").build(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + // Keep the consumer thread alive until it is shut down. We do not currently do anything in the thread but may + // do supervision in the future + while (consumerThread.isAlive() && !stopOrderedFlag) { + ThreadUtilities.sleep(REST_SERVER_CONSUMER_WAIT_SLEEP_TIME); + } + + if (server != null) { + server.shutdown(); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.consumer.ApexEventConsumer#stop() + */ + @Override + public void stop() { + stopOrderedFlag = true; + + while (consumerThread.isAlive()) { + ThreadUtilities.sleep(REST_SERVER_CONSUMER_WAIT_SLEEP_TIME); + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducer.java new file mode 100644 index 000000000..e51482ce4 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducer.java @@ -0,0 +1,167 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restserver; + +import java.util.EnumMap; +import java.util.Map; + +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Concrete implementation of an Apex event producer that sends events using REST. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + * + */ +public class ApexRestServerProducer implements ApexEventProducer { + private static final Logger LOGGER = LoggerFactory.getLogger(ApexRestServerProducer.class); + + // The REST carrier properties + private RESTServerCarrierTechnologyParameters restProducerProperties; + + // The name for this producer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#init(java.lang.String, + * org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters) + */ + @Override + public void init(final String producerName, final EventHandlerParameters producerParameters) + throws ApexEventException { + this.name = producerName; + + // Check and get the REST Properties + if (!(producerParameters.getCarrierTechnologyParameters() instanceof RESTServerCarrierTechnologyParameters)) { + final String errorMessage = + "specified producer properties are not applicable to REST Server producer (" + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + restProducerProperties = + (RESTServerCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + + // Check if host and port are defined + if (restProducerProperties.getHost() != null || restProducerProperties.getPort() != -1 + || restProducerProperties.isStandalone()) { + final String errorMessage = + "the parameters \"host\", \"port\", and \"standalone\" are illegal on REST Server producer (" + + this.name + ")"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Check if we are in synchronous mode + if (!producerParameters.isPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS)) { + final String errorMessage = + "REST Server producer (" + this.name + ") must run in synchronous mode with a REST Server consumer"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#setPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#sendEvent(long, java.lang. String, + * java.lang.Object) + */ + @Override + public void sendEvent(final long executionId, final String eventName, final Object event) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(name + ": event " + executionId + ':' + eventName + " recevied from Apex, event=" + event); + } + + // If we are not synchronized, then exit + final SynchronousEventCache synchronousEventCache = + (SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS); + if (synchronousEventCache == null) { + return; + } + + // We see all events on the receiver, even those that are not replies to events sent by the synchronized + // consumer of this producer, ignore those + // events + if (!synchronousEventCache.existsEventToApex(executionId)) { + return; + } + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(name + ": event " + executionId + ':' + eventName + " is a reply to a REST server call from " + + name); + } + + // Add the event to the received event cache + synchronousEventCache.cacheSynchronizedEventFromApex(executionId, event); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#stop() + */ + @Override + public void stop() {} +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RESTServerCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RESTServerCarrierTechnologyParameters.java new file mode 100644 index 000000000..47e31fffa --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RESTServerCarrierTechnologyParameters.java @@ -0,0 +1,136 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restserver; + +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; + +/** + * Apex parameters for REST as an event carrier technology with Apex as a REST client. + * + * The parameters for this plugin are: + * <ol> + * <li>standalone: A flag indicating if APEX should start a standalone HTTP server to process REST requests (true) or + * whether it should use an underlying servlet infrastructure such as Apache Tomcat (False). This parameter is legal + * only on REST server event inputs. + * <li>host: The host name to use when setting up a standalone HTTP server. This parameter is legal only on REST server + * event inputs in standalone mode. + * <li>port: The port to use when setting up a standalone HTTP server. This parameter is legal only on REST server event + * inputs in standalone mode. + * </ol> + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class RESTServerCarrierTechnologyParameters extends CarrierTechnologyParameters { + // @formatter:off + private static final int MIN_USER_PORT = 1024; + private static final int MAX_USER_PORT = 65535; + + /** The label of this carrier technology. */ + public static final String RESTSERVER_CARRIER_TECHNOLOGY_LABEL = "RESTSERVER"; + + /** The producer plugin class for the REST carrier technology. */ + public static final String RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestServerProducer.class.getCanonicalName(); + + /** The consumer plugin class for the REST carrier technology. */ + public static final String RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestServerConsumer.class.getCanonicalName(); + + // REST server parameters + private boolean standalone = false; + private String host = null; + private int port = -1; + // @formatter:on + + /** + * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter + * service. + */ + public RESTServerCarrierTechnologyParameters() { + super(RESTServerCarrierTechnologyParameters.class.getCanonicalName()); + + // Set the carrier technology properties for the web socket carrier technology + this.setLabel(RESTSERVER_CARRIER_TECHNOLOGY_LABEL); + this.setEventProducerPluginClass(RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS); + this.setEventConsumerPluginClass(RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS); + } + + /** + * Check if the REST server is running in standalone mode or is using an underlying servlet infrastructure to manage + * requests. + * + * @return true if in standalone mode + */ + public boolean isStandalone() { + return standalone; + } + + /** + * Gets the host. + * + * @return the host + */ + public String getHost() { + return host; + } + + /** + * Gets the port. + * + * @return the port + */ + public int getPort() { + return port; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate() + */ + @Override + public String validate() { + final StringBuilder errorMessageBuilder = new StringBuilder(); + + errorMessageBuilder.append(super.validate()); + + // Check if host is defined, it is only defined on REST server consumers + if (standalone) { + if (host != null) { + if (host.trim().length() == 0) { + errorMessageBuilder.append(" host not specified, must be host as a string\n"); + } + } + + // Check if port is defined, it is only defined on REST server consumers + if (port != -1) { + if (port < MIN_USER_PORT || port > MAX_USER_PORT) { + errorMessageBuilder + .append(" port [" + port + "] invalid, must be specified as 1024 <= port <= 6535\n"); + } + } + } else { + if (host != null || port != -1) { + errorMessageBuilder.append(" host and port are specified only in standalone mode\n"); + } + } + + return errorMessageBuilder.toString(); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java new file mode 100644 index 000000000..beee10fd0 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java @@ -0,0 +1,150 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restserver; + +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.ws.rs.Consumes; +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.core.MediaType; +import javax.ws.rs.core.Response; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class RestServerEndpoint is the end point servlet class for handling REST requests and responses to and from + * Apex. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +@Path("/{eventInput}") +@Produces({ MediaType.APPLICATION_JSON }) +@Consumes({ MediaType.APPLICATION_JSON }) +public class RestServerEndpoint { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(RestServerEndpoint.class); + + // Statistics on the amount of HTTP messages handled + private static int getMessagesReceived = 0; + private static int postEventMessagesReceived = 0; + private static int putEventMessagesReceived = 0; + + // This map is used to hold all the REST server event inputs. This is used to determine which consumer to send input + // events to + private static Map<String, ApexRestServerConsumer> consumerMap = + new LinkedHashMap<String, ApexRestServerConsumer>(); + + // The ID of this event input. This gets injected from the URL. + @PathParam("eventInput") + private String eventInputID = null; + + /** + * Register an Apex consumer with the REST server end point. + * + * @param consumerEventInputID The event input ID that indicates this consumer shoud be used + * @param consumer The consumer to register + */ + public static void registerApexRestServerConsumer(final String consumerEventInputID, + final ApexRestServerConsumer consumer) { + consumerMap.put(consumerEventInputID, consumer); + } + + /** + * Get statistics on apex REST event handling. + * + * @return the response + */ + @Path("/Status") + @GET + public Response serviceGetStats() { + getMessagesReceived++; + return Response.status(Response.Status.OK.getStatusCode()) + .entity("{\n" + "\"INPUTS\": \"" + consumerMap.keySet() + "\",\n" + "\"STAT\": " + getMessagesReceived + + ",\n" + "\"POST\": " + postEventMessagesReceived + ",\n" + "\"PUT\": " + + putEventMessagesReceived + "\n}") + .build(); + } + + /** + * Service post request, an incoming event over RETS to Apex. + * + * @param jsonString the JSON string containing the data coming in on the REST call + * @return the response event to the request + */ + @Path("/EventIn") + @POST + public Response servicePostRequest(final String jsonString) { + postEventMessagesReceived++; + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("event input " + eventInputID + ", received POST of event \"" + jsonString + "\""); + } + + // Common handler method for POST and PUT requests + return handleEvent(jsonString); + } + + /** + * Service put request, an incoming event over RETS to Apex. + * + * @param jsonString the JSON string containing the data coming in on the REST call + * @return the response event to the request + */ + @Path("/EventIn") + @PUT + public Response servicePutRequest(final String jsonString) { + putEventMessagesReceived++; + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("event input \"" + eventInputID + "\", received PUT of event \"" + jsonString + "\""); + } + + // Common handler method for POST and PUT requests + return handleEvent(jsonString); + } + + /** + * Common event handler for events received on POST and PUT messages. + * + * @param jsonString the JSON string containing the data coming in on the REST call + * @return the response event to the request + */ + private Response handleEvent(final String jsonString) { + // Find the correct consumer for this REST message + final ApexRestServerConsumer eventConsumer = consumerMap.get(eventInputID); + if (eventConsumer == null) { + final String errorMessage = + "event input " + eventInputID + " is not defined in the Apex configuration file"; + LOGGER.warn(errorMessage); + return Response.status(Response.Status.BAD_REQUEST.getStatusCode()) + .entity("{'errorMessage', '" + errorMessage + "'}").build(); + } + + return eventConsumer.receiveEvent(jsonString); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/package-info.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/package-info.java new file mode 100644 index 000000000..98a1c4bd6 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/package-info.java @@ -0,0 +1,28 @@ +/*- + * ============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========================================================= + */ + +/** + * APEX REST consumer and producer plugins when APEX is acting as a REST client. + * + * @author Joss Armstrong (joss.armstrong@ericsson.com) + * + */ + +package org.onap.policy.apex.plugins.event.carrier.restserver; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/resources/logback-test.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/resources/logback-test.xml new file mode 100644 index 000000000..dc591b1f1 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/resources/logback-test.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============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========================================================= +--> + +<configuration> + + <contextName>Apex</contextName> + <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> + <property name="LOG_DIR" value="${java.io.tmpdir}/apex_logging/" /> + + <!-- USE FOR STD OUT ONLY --> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern> + </encoder> + </appender> + + <root level="info"> + <appender-ref ref="STDOUT" /> + </root> + + <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_DIR}/apex.log</file> + <encoder> + <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level + %logger{26} - %msg %n %ex{full}</pattern> + </encoder> + </appender> + + <logger name="org.onap.policy.apex.plugins.event.carrier.restserver" level="trace" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> +</configuration> diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/pom.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/pom.xml new file mode 100644 index 000000000..f6068aa28 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/pom.xml @@ -0,0 +1,36 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId> + <artifactId>plugins-event-carrier</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>plugins-event-carrier-websocket</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] Plugin for handling events being transported over web sockets</description> + + <properties> + <apex-plugins-event-carrier-websocket-dir>${project.basedir}/src</apex-plugins-event-carrier-websocket-dir> + </properties> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java new file mode 100644 index 000000000..f2c59453c --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java @@ -0,0 +1,195 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.websocket; + +import java.util.EnumMap; +import java.util.Map; + +import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageClient; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageListener; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageServer; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessager; +import org.onap.policy.apex.core.infrastructure.threading.ApplicationThreadFactory; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.service.engine.event.ApexEventConsumer; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventReceiver; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Concrete implementation an Apex event consumer that receives events using Kafka. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexWebSocketConsumer implements ApexEventConsumer, WSStringMessageListener, Runnable { + private static final int WEB_SOCKET_WAIT_SLEEP_TIME = 100; + + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexWebSocketConsumer.class); + + // The Web Socket properties + private WEBSOCKETCarrierTechnologyParameters webSocketConsumerProperties; + + // The web socket messager, may be WS a server or a client + private WSStringMessager wsStringMessager; + + // The event receiver that will receive events from this consumer + private ApexEventReceiver eventReceiver; + + // The name for this consumer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + // The consumer thread and stopping flag + private Thread consumerThread; + private boolean stopOrderedFlag = false; + + // The number of events read to date + private int eventsRead = 0; + + @Override + public void init(final String consumerName, final EventHandlerParameters consumerParameters, + final ApexEventReceiver incomingEventReceiver) throws ApexEventException { + this.eventReceiver = incomingEventReceiver; + this.name = consumerName; + + // Check and get the Kafka Properties + if (!(consumerParameters.getCarrierTechnologyParameters() instanceof WEBSOCKETCarrierTechnologyParameters)) { + LOGGER.warn("specified consumer properties are not applicable to a web socket consumer"); + throw new ApexEventException("specified consumer properties are not applicable to a web socket consumer"); + } + webSocketConsumerProperties = + (WEBSOCKETCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); + + // Check if this is a server or a client Web Socket + if (webSocketConsumerProperties.isWsClient()) { + // Create a WS client + wsStringMessager = new WSStringMessageClient(webSocketConsumerProperties.getHost(), + webSocketConsumerProperties.getPort()); + } else { + wsStringMessager = new WSStringMessageServer(webSocketConsumerProperties.getPort()); + } + + // Start reception of event strings on the web socket + try { + wsStringMessager.start(this); + } catch (final MessagingException e) { + LOGGER.warn("could not start web socket consumer"); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#start() + */ + @Override + public void start() { + // Configure and start the event reception thread + final String threadName = this.getClass().getName() + ":" + this.name; + consumerThread = new ApplicationThreadFactory(threadName).newThread(this); + consumerThread.setDaemon(true); + consumerThread.start(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#getPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConsumer#setPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + while (consumerThread.isAlive() && !stopOrderedFlag) { + ThreadUtilities.sleep(WEB_SOCKET_WAIT_SLEEP_TIME); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.producer.ApexEventProducer#stop() + */ + @Override + public void stop() { + if (wsStringMessager != null) { + wsStringMessager.stop(); + } + stopOrderedFlag = true; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageListener#receiveString(java. + * lang. String) + */ + @Override + public void receiveString(final String eventString) { + try { + eventReceiver.receiveEvent(eventString); + eventsRead++; + } catch (final Exception e) { + final String errorMessage = "Error sending event " + name + '_' + eventsRead + ", " + e.getMessage() + + ", event:\n" + eventString; + LOGGER.warn(errorMessage); + } + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java new file mode 100644 index 000000000..1fd146824 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java @@ -0,0 +1,166 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.websocket; + +import java.util.EnumMap; +import java.util.Map; + +import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageClient; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageListener; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageServer; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessager; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProducer; +import org.onap.policy.apex.service.engine.event.PeeredReference; +import org.onap.policy.apex.service.engine.event.SynchronousEventCache; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; +import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Concrete implementation of an Apex event producer that sends events using a web socket. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexWebSocketProducer implements ApexEventProducer, WSStringMessageListener { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexWebSocketProducer.class); + + // The Web Socket properties + private WEBSOCKETCarrierTechnologyParameters webSocketProducerProperties; + + // The web socket messager, may be WS a server or a client + private WSStringMessager wsStringMessager; + + // The name for this producer + private String name = null; + + // The peer references for this event handler + private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + + @Override + public void init(final String producerName, final EventHandlerParameters producerParameters) + throws ApexEventException { + this.name = producerName; + + // Check and get the web socket Properties + if (!(producerParameters.getCarrierTechnologyParameters() instanceof WEBSOCKETCarrierTechnologyParameters)) { + LOGGER.warn( + "specified producer properties for " + this.name + "are not applicable to a web socket producer"); + throw new ApexEventException("specified producer properties are not applicable to a web socket producer"); + } + webSocketProducerProperties = + (WEBSOCKETCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + + // Check if this is a server or a client Web Socket + if (webSocketProducerProperties.isWsClient()) { + // Create a WS client + wsStringMessager = new WSStringMessageClient(webSocketProducerProperties.getHost(), + webSocketProducerProperties.getPort()); + } else { + wsStringMessager = new WSStringMessageServer(webSocketProducerProperties.getPort()); + } + + // Start reception of event strings on the web socket + try { + wsStringMessager.start(this); + } catch (final MessagingException e) { + LOGGER.warn("could not start web socket producer (" + this.name + ")"); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#getPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode) + */ + @Override + public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) { + return peerReferenceMap.get(peeredMode); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#setPeeredReference(org.onap.policy.apex.service. + * parameters. eventhandler.EventHandlerPeeredMode, org.onap.policy.apex.service.engine.event.PeeredReference) + */ + @Override + public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) { + peerReferenceMap.put(peeredMode, peeredReference); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.producer.ApexEventProducer#sendEvent(long, java.lang.String, + * java.lang.Object) + */ + @Override + public void sendEvent(final long executionId, final String eventName, final Object event) { + // Check if this is a synchronized event, if so we have received a reply + final SynchronousEventCache synchronousEventCache = + (SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS); + if (synchronousEventCache != null) { + synchronousEventCache.removeCachedEventToApexIfExists(executionId); + } + + wsStringMessager.sendString((String) event); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.producer.ApexEventProducer#stop() + */ + @Override + public void stop() { + if (wsStringMessager != null) { + wsStringMessager.stop(); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageListener#receiveString(java. + * lang. String) + */ + @Override + public void receiveString(final String messageString) { + LOGGER.warn("received message \"" + messageString + "\" on web socket producer (" + this.name + + ") , no messages should be received on a web socket producer"); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/WEBSOCKETCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/WEBSOCKETCarrierTechnologyParameters.java new file mode 100644 index 000000000..e8009a5d8 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/WEBSOCKETCarrierTechnologyParameters.java @@ -0,0 +1,115 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.websocket; + +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; + +/** + * Apex parameters for Kafka as an event carrier technology. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class WEBSOCKETCarrierTechnologyParameters extends CarrierTechnologyParameters { + // @formatter:off + private static final int MIN_USER_PORT = 1024; + private static final int MAX_USER_PORT = 65535; + + /** The label of this carrier technology. */ + public static final String WEB_SCOKET_CARRIER_TECHNOLOGY_LABEL = "WEBSOCKET"; + + /** The producer plugin class for the web socket carrier technology. */ + public static final String WEB_SCOKET_EVENT_PRODUCER_PLUGIN_CLASS = ApexWebSocketProducer.class.getCanonicalName(); + + /** The consumer plugin class for the web socket carrier technology. */ + public static final String KWEB_SCOKET_EVENT_CONSUMER_PLUGIN_CLASS = ApexWebSocketConsumer.class.getCanonicalName(); + + // Default parameter values + private static final String DEFAULT_HOST = "localhost"; + private static final int DEFAULT_PORT = -1; + + // Web socket parameters + private boolean wsClient = true; + private String host = DEFAULT_HOST; + private int port = DEFAULT_PORT; + // @formatter:on + + /** + * Constructor to create a web socket carrier technology parameters instance and register the instance with the + * parameter service. + */ + public WEBSOCKETCarrierTechnologyParameters() { + super(WEBSOCKETCarrierTechnologyParameters.class.getCanonicalName()); + + // Set the carrier technology properties for the web socket carrier technology + this.setLabel(WEB_SCOKET_CARRIER_TECHNOLOGY_LABEL); + this.setEventProducerPluginClass(WEB_SCOKET_EVENT_PRODUCER_PLUGIN_CLASS); + this.setEventConsumerPluginClass(KWEB_SCOKET_EVENT_CONSUMER_PLUGIN_CLASS); + } + + /** + * Gets the host. + * + * @return the host + */ + public String getHost() { + return host; + } + + /** + * Gets the port. + * + * @return the port + */ + public int getPort() { + return port; + } + + /** + * Checks if is ws client. + * + * @return true, if checks if is ws client + */ + public boolean isWsClient() { + return wsClient; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate() + */ + @Override + public String validate() { + final StringBuilder errorMessageBuilder = new StringBuilder(); + + errorMessageBuilder.append(super.validate()); + + if (wsClient && (host == null || host.trim().length() == 0)) { + errorMessageBuilder.append(" host not specified, must be host as a string\n"); + } + + if (port < MIN_USER_PORT || port > MAX_USER_PORT) { + errorMessageBuilder.append(" port [" + port + "] invalid, must be specified as 1024 <= port <= 6535\n"); + } + + return errorMessageBuilder.toString(); + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/package-info.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/package-info.java new file mode 100644 index 000000000..9555ea447 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============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========================================================= + */ + +/** + * Implements the APEX event carrier technology plugin for web sockets. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ + +package org.onap.policy.apex.plugins.event.carrier.websocket; diff --git a/plugins/plugins-event/plugins-event-carrier/pom.xml b/plugins/plugins-event/plugins-event-carrier/pom.xml new file mode 100644 index 000000000..c8ce3a720 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/pom.xml @@ -0,0 +1,48 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event</groupId> + <artifactId>plugins-event</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId> + <artifactId>plugins-event-carrier</artifactId> + <packaging>pom</packaging> + + <name>${project.artifactId}</name> + <description>Plugins for 3pps that carry events</description> + + <properties> + <apex-plugins-event-carrier-dir>${project.basedir}/src</apex-plugins-event-carrier-dir> + </properties> + + <modules> + <module>plugins-event-carrier-kafka</module> + <module>plugins-event-carrier-websocket</module> + <module>plugins-event-carrier-jms</module> + <module>plugins-event-carrier-restclient</module> + <module>plugins-event-carrier-restserver</module> + <module>plugins-event-carrier-restrequestor</module> + </modules> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml new file mode 100644 index 000000000..98328951e --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml @@ -0,0 +1,44 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId> + <artifactId>plugins-event-protocol</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>plugins-event-protocol-jms</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] Plugins for handling events that are being transported as JMS messages</description> + + <properties> + <apex-plugins-event-protocol-jms-dir>${project.basedir}/src</apex-plugins-event-protocol-jms-dir> + </properties> + + <dependencies> + <dependency> + <groupId>javax.jms</groupId> + <artifactId>javax.jms-api</artifactId> + <version>2.0.1</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java new file mode 100644 index 000000000..52c678407 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java @@ -0,0 +1,148 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.jms; + +import java.util.ArrayList; +import java.util.List; + +import javax.jms.ObjectMessage; + +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class Apex2JMSObjectEventConverter converts {@link ApexEvent} instances into string instances of + * {@link javax.jms.ObjectMessage} message events for JMS. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConverter { + private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2JMSObjectEventConverter.class); + + // JMS event protocol parameters on the consumer (JMS->Apex) sides + private JMSObjectEventProtocolParameters eventProtocolParameters = null; + + /** + * Constructor to create the Apex to JMS Object converter. + * + * @throws ApexEventException the apex event exception + */ + public Apex2JMSObjectEventConverter() throws ApexEventException {} + + @Override + public void init(final EventProtocolParameters parameters) { + // Check if properties have been set for JMS object event conversion as a consumer. They may not be set because + // JMS may not be in use + // on both sides of Apex + if (!(parameters instanceof JMSObjectEventProtocolParameters)) { + final String errormessage = "specified Event Protocol Parameters properties of type \"" + + parameters.getClass().getCanonicalName() + "\" are not applicable to a " + + Apex2JMSObjectEventConverter.class.getName() + " converter"; + LOGGER.error(errormessage); + } else { + this.eventProtocolParameters = (JMSObjectEventProtocolParameters) parameters; + } + + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#toApexEvent(java.lang.String, java.lang.Object) + */ + @Override + public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException { + // Check if this is an ObjectMessage from JMS + if (!(eventObject instanceof ObjectMessage)) { + final String errorMessage = "message \"" + eventObject + "\" received from JMS is not an instance of \"" + + ObjectMessage.class.getCanonicalName() + "\""; + LOGGER.warn(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + + // Get the object from the object message + final ObjectMessage objectMessage = (ObjectMessage) eventObject; + Object jmsIncomingObject; + try { + jmsIncomingObject = objectMessage.getObject(); + } catch (final Exception e) { + final String errorMessage = "object contained in message \"" + eventObject + + "\" received from JMS could not be retrieved as a Java object"; + LOGGER.debug(errorMessage, e); + throw new ApexEventRuntimeException(errorMessage, e); + } + + // Check that the consumer parameters for JMS->Apex messaging have been set + if (eventProtocolParameters == null) { + final String errorMessage = + "consumer parameters for JMS events consumed by Apex are not set in the Apex configuration for this engine"; + LOGGER.debug(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + + // Create the Apex event + // @formatter:off + final ApexEvent apexEvent = new ApexEvent( + jmsIncomingObject.getClass().getSimpleName() + eventProtocolParameters.getIncomingEventSuffix(), + eventProtocolParameters.getIncomingEventVersion(), + jmsIncomingObject.toString().getClass().getPackage().getName(), + eventProtocolParameters.getIncomingEventSource(), + eventProtocolParameters.getIncomingEventTarget()); + // @formattter:on + + // Set the data on the apex event as the incoming object + apexEvent.put(jmsIncomingObject.getClass().getSimpleName(), jmsIncomingObject); + + // Return the event in a single element + final ArrayList<ApexEvent> eventList = new ArrayList<ApexEvent>(); + eventList.add(apexEvent); + return eventList; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#fromApexEvent(org.onap.policy.apex.service.engine.event.ApexEvent) + */ + @Override + public Object fromApexEvent(final ApexEvent apexEvent) throws ApexEventException { + // Check the Apex event + if (apexEvent == null) { + LOGGER.warn("event processing failed, Apex event is null"); + throw new ApexEventException("event processing failed, Apex event is null"); + } + + // Check that the Apex event has a single parameter + if (apexEvent.size() != 1) { + final String errorMessage = "event processing failed, Apex event must have one and only one parameter for JMS Object handling"; + LOGGER.warn(errorMessage); + throw new ApexEventException(errorMessage); + } + + // Return the single object from the Apex event message + return apexEvent.values().iterator().next(); + } +} diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java new file mode 100644 index 000000000..f48843125 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java @@ -0,0 +1,100 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.jms; + +import java.util.List; + +import javax.jms.TextMessage; + +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JSONEventConverter; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class Apex2JMSTextEventConverter converts {@link ApexEvent} instances into string instances of + * {@link javax.jms.TextMessage} message events for JMS. It is a proxy for the built in + * {@link org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JSONEventConverter} plugin. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public final class Apex2JMSTextEventConverter extends Apex2JSONEventConverter { + private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2JMSTextEventConverter.class); + + /** + * Constructor to create the Apex to JMS Object converter. + * + * @throws ApexEventException the apex event exception + */ + public Apex2JMSTextEventConverter() throws ApexEventException {} + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#toApexEvent(java.lang.String, java.lang.Object) + */ + @Override + public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException { + // Check if this is an TextMessage from JMS + if (!(eventObject instanceof TextMessage)) { + final String errorMessage = "message \"" + eventObject + "\" received from JMS is not an instance of \"" + + TextMessage.class.getCanonicalName() + "\""; + LOGGER.debug(errorMessage); + throw new ApexEventRuntimeException(errorMessage); + } + + // Get the string from the object message + final TextMessage textMessage = (TextMessage) eventObject; + String jmsString; + try { + jmsString = textMessage.getText(); + } catch (final Exception e) { + final String errorMessage = "object contained in message \"" + eventObject + + "\" received from JMS could not be retrieved as a Java String"; + LOGGER.debug(errorMessage, e); + throw new ApexEventRuntimeException(errorMessage, e); + } + + // Use the generic JSON plugin from here + return super.toApexEvent(eventName, jmsString); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.service.engine.event.ApexEventConverter#fromApexEvent(org.onap.policy.apex.service.engine. + * event. ApexEvent) + */ + @Override + public Object fromApexEvent(final ApexEvent apexEvent) throws ApexEventException { + // Check the Apex event + if (apexEvent == null) { + LOGGER.warn("event processing failed, Apex event is null"); + throw new ApexEventException("event processing failed, Apex event is null"); + } + + // Return the Apex event as a string object + return super.fromApexEvent(apexEvent); + } +} diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSObjectEventProtocolParameters.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSObjectEventProtocolParameters.java new file mode 100644 index 000000000..c2baff8e6 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSObjectEventProtocolParameters.java @@ -0,0 +1,127 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.jms; + +import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters; + +/** + * Event protocol parameters for JMS Object messages as an event protocol. + * + * <p> + * On reception of an a JMS {@link javax.jms.ObjectMessage}, the JMS Object plugin unmarshals the message as follows: + * <ol> + * <li>It extracts the Java object from the {@link javax.jms.ObjectMessage} instance. + * <li>It creates an {@link org.onap.policy.apex.service.engine.event.ApexEvent} instance to hold the java object. + * <li>It sets the name of the Apex event to be the simple class name of the incoming Java object and appends the value + * of the {@code incomingEventSuffix} parameter to it. + * <li>It sets the version of the incoming event to the value of the {@code incomingEventVersion} parameter. + * <li>It sets the name space of the incoming event to be the value of the package of the class of the incoming Java + * object. + * <li>It sets the source of the incoming event to the value of the {@code incomingEventSource} parameter. + * <li>It sets the target of the incoming event to the value of the {@code incomingEventTarget} parameter. + * <li>It puts a single entry into the Apex event map with the the simple class name of the incoming Java object being + * the key of the entry and the actual incoming object as the value of the entry. + * </ol> + * <p> + * When sending an object to JMS, the plugin expects to receive an Apex event with a single entry. The plugin marshals + * the value of that entry to an object that can be sent by JMS as a {@link javax.jms.ObjectMessage} instance. + * <p> + * The parameters for this plugin are: + * <ol> + * <li>incomingEventSuffix: The suffix to append to the simple name of incoming Java class instances when they are + * encapsulated in Apex events. The parameter defaults to the string value {@code IncomingEvent}. + * <li>incomingEventVersion: The event version to use for incoming Java class instances when they are encapsulated in + * Apex events. The parameter defaults to the string value {@code 1.0.0}. + * <li>incomingEventSource: The event source to use for incoming Java class instances when they are encapsulated in Apex + * events. The parameter defaults to the string value {@code JMS}. + * <li>incomingEventTarget: The event target to use for incoming Java class instances when they are encapsulated in Apex + * events. The parameter defaults to the string value {@code Apex}. + * </ol> + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class JMSObjectEventProtocolParameters extends EventProtocolParameters { + /** The label of this event protocol. */ + public static final String JMS_OBJECT_EVENT_PROTOCOL_LABEL = "JMSOBJECT"; + + //@formatter:off + // Default parameter values + private static final String DEFAULT_INCOMING_EVENT_SUFFIX = "IncomingEvent"; + private static final String DEFAULT_INCOMING_EVENT_VERSION = "1.0.0"; + private static final String DEFAULT_INCOMING_EVENT_SOURCE = "JMS"; + private static final String DEFAULT_INCOMING_EVENT_TARGET = "Apex"; + + // JMS carrier parameters + private String incomingEventSuffix = DEFAULT_INCOMING_EVENT_SUFFIX; + private String incomingEventVersion = DEFAULT_INCOMING_EVENT_VERSION; + private String incomingEventSource = DEFAULT_INCOMING_EVENT_SOURCE; + private String incomingEventTarget = DEFAULT_INCOMING_EVENT_TARGET; + //@formatter:off + + /** + * Constructor to create a JSON event protocol parameter instance and register the instance with the parameter service. + */ + public JMSObjectEventProtocolParameters() { + super(JMSObjectEventProtocolParameters.class.getCanonicalName()); + + // Set the event protocol properties for the JMS Text event protocol + this.setLabel(JMS_OBJECT_EVENT_PROTOCOL_LABEL); + + // Set the event protocol plugin class + this.setEventProtocolPluginClass(Apex2JMSObjectEventConverter.class.getCanonicalName()); + } + + /** + * Gets the incoming event version. + * + * @return the incoming event version + */ + public String getIncomingEventVersion() { + return incomingEventVersion; + } + + /** + * Gets the incoming event source. + * + * @return the incoming event source + */ + public String getIncomingEventSource() { + return incomingEventSource; + } + + /** + * Gets the incoming event target. + * + * @return the incoming event target + */ + public String getIncomingEventTarget() { + return incomingEventTarget; + } + + /** + * Gets the incoming event suffix. + * + * @return the incoming event suffix + */ + public String getIncomingEventSuffix() { + return incomingEventSuffix; + } +} diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSTextEventProtocolParameters.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSTextEventProtocolParameters.java new file mode 100644 index 000000000..8ddc64862 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSTextEventProtocolParameters.java @@ -0,0 +1,56 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.jms; + +import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JSONEventProtocolParameters; + +/** + * Event protocol parameters for JMS Text messages as an event protocol. + * <p> + * Text messages received and sent over JMS in ~Text format are assumed to be in a JSON format that Apex can understand. + * Therefore this plugin is a subclass of the built in JSON event protocol plugin. + * <p> + * On reception of a JMS {@link javax.jms.TextMessage} message, the JMS Text plugin unmarshals the message the JMS text + * message and passes it to its JSON superclass unmarshaling for processing. + * <p> + * When sending an Apex event, the plugin uses its underlying JSON superclass to marshal the event to a JSON string and + * passes that string to the JSON carrier plugin for sending. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class JMSTextEventProtocolParameters extends JSONEventProtocolParameters { + /** The label of this event protocol. */ + public static final String JMS_TEXT_EVENT_PROTOCOL_LABEL = "JMSTEXT"; + + /** + * Constructor to create a JSON event protocol parameter instance and register the instance with the parameter + * service. + */ + public JMSTextEventProtocolParameters() { + super(JMSTextEventProtocolParameters.class.getCanonicalName(), JMS_TEXT_EVENT_PROTOCOL_LABEL); + + // Set the event protocol properties for the JMS Text event protocol + this.setLabel(JMS_TEXT_EVENT_PROTOCOL_LABEL); + + // Set the event protocol plugin class + this.setEventProtocolPluginClass(Apex2JMSTextEventConverter.class.getCanonicalName()); + } +} diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/package-info.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/package-info.java new file mode 100644 index 000000000..92d6d07d4 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/package-info.java @@ -0,0 +1,28 @@ +/*- + * ============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========================================================= + */ + +/** + * Contains implementations of Apex event protocol converter plugins for JMS event protocols that are implementations of + * {@link javax.jms.Message}. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ + +package org.onap.policy.apex.plugins.event.protocol.jms; diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/pom.xml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/pom.xml new file mode 100644 index 000000000..fd2be45c1 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/pom.xml @@ -0,0 +1,104 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId> + <artifactId>plugins-event-protocol</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>plugins-event-protocol-xml</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] Plugin for handling events that are being transported in XML format</description> + + <properties> + <apex-plugins-event-protocol-xml-dir>${project.basedir}/src</apex-plugins-event-protocol-xml-dir> + </properties> + + <dependencies> + <dependency> + <groupId>org.jvnet.jaxb2.maven2</groupId> + <artifactId>maven-jaxb2-plugin</artifactId> + <version>0.13.2</version> + </dependency> + <dependency> + <groupId>org.jvnet.jaxb2_commons</groupId> + <artifactId>jaxb2-basics-runtime</artifactId> + <version>1.11.1</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.jvnet.jaxb2.maven2</groupId> + <artifactId>maven-jaxb2-plugin</artifactId> + <version>0.13.2</version> + <configuration> + <schemaDirectory>src/main/resources/xml</schemaDirectory> + <schemaFiles>apex-event.xsd</schemaFiles> + <bindingDirectory>src/main/resources/xml</bindingDirectory> + <bindingFiles>apex-event.xjb</bindingFiles> + <generatePackage>org.onap.policy.apex.plugins.event.protocol.xml.jaxb</generatePackage> + <extension>true</extension> + <addGeneratedAnnotation>true</addGeneratedAnnotation> + <readOnly>true</readOnly> + <verbose>true</verbose> + <plugins> + <plugin> + <groupId>org.jvnet.jaxb2_commons</groupId> + <artifactId>jaxb2-basics</artifactId> + <version>1.11.1</version> + </plugin> + <plugin> + <groupId>org.jvnet.jaxb2_commons</groupId> + <artifactId>jaxb2-basics-annotate</artifactId> + <version>1.0.2</version> + </plugin> + <plugin> + <groupId>org.jvnet.jaxb2_commons</groupId> + <artifactId>jaxb2-value-constructor</artifactId> + <version>3.0</version> + </plugin> + </plugins> + <args> + <arg>-Xannotate</arg> + <arg>-XtoString</arg> + <arg>-Xmergeable</arg> + <arg>-Xcopyable</arg> + <arg>-Xequals</arg> + <arg>-XhashCode</arg> + <arg>-Xvalue-constructor</arg> + </args> + </configuration> + <executions> + <execution> + <id>generate</id> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XMLEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XMLEventConverter.java new file mode 100644 index 000000000..01a57caf6 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XMLEventConverter.java @@ -0,0 +1,206 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.xml; + +import java.io.ByteArrayInputStream; +import java.io.StringWriter; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +import javax.xml.XMLConstants; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.onap.policy.apex.model.utilities.ResourceUtils; +import org.onap.policy.apex.plugins.event.protocol.xml.jaxb.ObjectFactory; +import org.onap.policy.apex.plugins.event.protocol.xml.jaxb.XMLApexEvent; +import org.onap.policy.apex.plugins.event.protocol.xml.jaxb.XMLApexEventData; +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; +import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; +import org.xml.sax.SAXException; + +/** + * The Class Apex2XMLEventConverter converts {@link ApexEvent} instances into string instances of {@link XMLApexEvent} + * that are XML representations of Apex events defined in JAXB. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public final class Apex2XMLEventConverter implements ApexEventProtocolConverter { + private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2XMLEventConverter.class); + + private static final String MODEL_SCHEMA_NAME = "xml/apex-event.xsd"; + + // XML Unmarshaller and marshaller and object factory for events + private Unmarshaller unmarshaller; + private Marshaller marshaller; + private ObjectFactory objectFactory = new ObjectFactory(); + + /** + * Constructor to create the Apex to XML converter. + * + * @throws ApexEventException the apex event exception + */ + public Apex2XMLEventConverter() throws ApexEventException { + try { + final URL schemaURL = ResourceUtils.getURLResource(MODEL_SCHEMA_NAME); + final Schema apexEventSchema = + SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaURL); + + final JAXBContext jaxbContext = JAXBContext.newInstance(XMLApexEvent.class); + + // Set up the unmarshaller to carry out validation + unmarshaller = jaxbContext.createUnmarshaller(); + unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler()); + unmarshaller.setSchema(apexEventSchema); + + // Set up the marshaller + marshaller = jaxbContext.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + marshaller.setSchema(apexEventSchema); + } catch (JAXBException | SAXException e) { + LOGGER.error("Unable to set up marshalling and unmarshalling for XML events", e); + throw new ApexEventException("Unable to set up marshalling and unmarshalling for XML events", e); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter#init(org.onap.policy.apex.service. + * parameters. eventprotocol.EventProtocolParameters) + */ + @Override + public void init(final EventProtocolParameters parameters) {} + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#toApexEvent(java.lang.String, java.lang.Object) + */ + @Override + public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException { + // Check the XML event + if (eventObject == null) { + LOGGER.warn("event processing failed, XML event is null"); + throw new ApexEventException("event processing failed, XML event is null"); + } + + // Cast the event to a string, if our conversion is correctly configured, this cast should always work + String xmlEventString = null; + try { + xmlEventString = (String) eventObject; + } catch (final Exception e) { + final String errorMessage = "error converting event \"" + eventObject + "\" to a string"; + LOGGER.debug(errorMessage, e); + throw new ApexEventRuntimeException(errorMessage, e); + } + + // The XML event + XMLApexEvent xmlApexEvent = null; + + // Use JAXB to read and verify the event from the XML string + try { + final StreamSource source = new StreamSource(new ByteArrayInputStream(xmlEventString.getBytes())); + final JAXBElement<XMLApexEvent> rootElement = unmarshaller.unmarshal(source, XMLApexEvent.class); + xmlApexEvent = rootElement.getValue(); + } catch (final JAXBException e) { + LOGGER.warn("Unable to unmarshal Apex XML event\n" + xmlEventString, e); + throw new ApexEventException("Unable to unmarshal Apex XML event\n" + xmlEventString, e); + } + + // Create the Apex event + final ApexEvent apexEvent = new ApexEvent(xmlApexEvent.getName(), xmlApexEvent.getVersion(), + xmlApexEvent.getNameSpace(), xmlApexEvent.getSource(), xmlApexEvent.getTarget()); + + // Set the data on the apex event + for (final XMLApexEventData xmlData : xmlApexEvent.getData()) { + apexEvent.put(xmlData.getKey(), xmlData.getValue()); + } + + // Return the event in a single element + final ArrayList<ApexEvent> eventList = new ArrayList<ApexEvent>(); + eventList.add(apexEvent); + return eventList; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.service.engine.event.ApexEventConverter#fromApexEvent(org.onap.policy.apex.service.engine. + * event. ApexEvent) + */ + @Override + public String fromApexEvent(final ApexEvent apexEvent) throws ApexEventException { + // Check the Apex event + if (apexEvent == null) { + LOGGER.warn("event processing failed, Apex event is null"); + throw new ApexEventException("event processing failed, Apex event is null"); + } + + // Get the Apex event data + final List<XMLApexEventData> xmlDataList = new ArrayList<XMLApexEventData>(); + + try { + for (final Entry<String, Object> apexDataEntry : apexEvent.entrySet()) { + // Add an XML event data item + if (apexDataEntry.getValue() != null) { + xmlDataList.add(new XMLApexEventData(apexDataEntry.getKey(), apexDataEntry.getValue().toString())); + } else { + xmlDataList.add(new XMLApexEventData(apexDataEntry.getKey(), "")); + } + } + } catch (final Exception e) { + LOGGER.warn("Unable to transfer Apex event data to XML\n" + apexEvent, e); + throw new ApexEventException("Unable to transfer Apex event data to XML\n" + apexEvent, e); + } + + // Create the XML event + final XMLApexEvent xmlApexEvent = new XMLApexEvent(apexEvent.getName(), apexEvent.getVersion(), + apexEvent.getNameSpace(), apexEvent.getSource(), apexEvent.getTarget(), xmlDataList); + + // Write the event into a DOM document + try { + // Marshal the event into XML + final StringWriter writer = new StringWriter(); + marshaller.marshal(objectFactory.createXmlApexEvent(xmlApexEvent), writer); + + // Return the event as XML in a string + return writer.toString(); + } catch (final JAXBException e) { + LOGGER.warn("Unable to unmarshal Apex event to XML\n" + apexEvent, e); + throw new ApexEventException("Unable to unmarshal Apex event to XML\n" + apexEvent, e); + } + } +} diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventProtocolParameters.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventProtocolParameters.java new file mode 100644 index 000000000..e96a3f5d5 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventProtocolParameters.java @@ -0,0 +1,53 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.xml; + +import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextTokenDelimitedParameters; + +/** + * Event protocol parameters for XML as an event protocol. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class XMLEventProtocolParameters extends EventProtocolTextTokenDelimitedParameters { + /** The label of this carrier technology. */ + public static final String XML_EVENT_PROTOCOL_LABEL = "XML"; + + // Constants for the text delimiter token + private static final String XML_TEXT_DELIMITER_TOKEN = "<?xml"; + + /** + * Constructor to create a JSON event protocol parameter instance and register the instance with the parameter + * service. + */ + public XMLEventProtocolParameters() { + super(XMLEventProtocolParameters.class.getCanonicalName()); + + // Set the event protocol properties for the XML event protocol + this.setLabel(XML_EVENT_PROTOCOL_LABEL); + + // Set the starting and ending delimiters for text blocks of XML events + this.setDelimiterToken(XML_TEXT_DELIMITER_TOKEN); + + // Set the event protocol plugin class + this.setEventProtocolPluginClass(Apex2XMLEventConverter.class.getCanonicalName()); + } +} diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/package-info.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/package-info.java new file mode 100644 index 000000000..4f972657f --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/package-info.java @@ -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========================================================= + */ + +/** + * Contains the implementation of the APEX event protocol converter plugin for events in XML format. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +package org.onap.policy.apex.plugins.event.protocol.xml; diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/resources/xml/apex-event.xjb b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/resources/xml/apex-event.xjb new file mode 100644 index 000000000..fa334c413 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/resources/xml/apex-event.xjb @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============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========================================================= +--> + +<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" + xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:annox="http://annox.dev.java.net" + xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" + version="2.1"> + + <!--jaxb:globalBindings generateIsSetMethod="true"> + <xjc:serializable uid="1" /> + <xjc:javaType name="java.lang.String" xmlType="xs:string" + adapter="org.onap.policy.apex.core.model.xml.StringTrimAdapter" /> + </jaxb:globalBindings--> + + <jaxb:bindings schemaLocation="apex-event.xsd" node="/xs:schema"> + <jaxb:bindings node="xs:complexType[@name='XMLApexEvent']"> <annox:annotate> + <annox:annotate annox:class="java.lang.SuppressWarnings" value="all" /> </annox:annotate> + </jaxb:bindings> + </jaxb:bindings> +</jaxb:bindings> diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/resources/xml/apex-event.xsd b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/resources/xml/apex-event.xsd new file mode 100644 index 000000000..c8314550a --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/resources/xml/apex-event.xsd @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============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========================================================= +--> + +<schema targetNamespace="http://www.onap.org/policy/apex-pdp/apexevent" elementFormDefault="qualified" + xmlns="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" + xmlns:basic="http://jaxb2-commons.dev.java.net/basic" + xmlns:copyable="http://jaxb2-commons.dev.java.net/basic/copyable" + xmlns:equals="http://jaxb2-commons.dev.java.net/basic/equals" + xmlns:hashCode="http://jaxb2-commons.dev.java.net/basic/hashCode" + xmlns:mergeable="http://jaxb2-commons.dev.java.net/basic/mergeable" + xmlns:toString="http://jaxb2-commons.dev.java.net/basic/toString" + jaxb:extensionBindingPrefixes="xjc basic copyable equals hashCode mergeable toString" + xmlns:apexev="http://www.onap.org/policy/apex-pdp/apexevent" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" + jaxb:version="2.0"> + + <annotation> + <documentation>An event that comes into or is emitted out of an Apex system. + </documentation> + </annotation> + + <annotation> + <appinfo> + <jaxb:globalBindings generateIsSetMethod="true"> + <xjc:serializable uid="1" /> + </jaxb:globalBindings> + </appinfo> + </annotation> + + <complexType name="XMLApexEvent"> + <annotation> + <documentation>An event that comes into or goes out of an Apex system</documentation> + </annotation> + <sequence> + <element name="name" maxOccurs="1" minOccurs="1"> + <simpleType> + <restriction base="string"> + <pattern value="[A-Za-z0-9\-_:]+"></pattern> + </restriction> + </simpleType> + </element> + <element name="version" maxOccurs="1" minOccurs="1"> + <simpleType> + <restriction base="string"> + <pattern value="[0-9.]+"></pattern> + </restriction> + </simpleType> + </element> + <element name="nameSpace" maxOccurs="1" minOccurs="1"> + <simpleType> + <restriction base="string"> + <minLength value="1"></minLength> + </restriction> + </simpleType> + </element> + <element name="source" maxOccurs="1" minOccurs="0"> + <simpleType> + <restriction base="string"> + <minLength value="0"></minLength> + </restriction> + </simpleType> + </element> + <element name="target" maxOccurs="1" minOccurs="0"> + <simpleType> + <restriction base="string"> + <minLength value="0"></minLength> + </restriction> + </simpleType> + </element> + <element name="data" type="apexev:XMLApexEventData" maxOccurs="unbounded" minOccurs="0"> + </element> + </sequence> + </complexType> + + <element name="xmlApexEvent" type="apexev:XMLApexEvent"></element> + + <complexType name="XMLApexEventData"> + <annotation> + <documentation> + A single data item of an Apex event. + </documentation> + </annotation> + <sequence> + <element name="key" maxOccurs="1" minOccurs="1"> + <simpleType> + <restriction base="string"> + <pattern value="[A-Za-z0-9\-_:]+"></pattern> + </restriction> + </simpleType> + </element> + <element name="value" maxOccurs="1" minOccurs="1"> + <simpleType> + <restriction base="string"> + <minLength value="0"></minLength> + </restriction> + </simpleType> + </element> + </sequence> + </complexType> + + +</schema> diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLEventHandler.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLEventHandler.java new file mode 100644 index 000000000..a62cc24cf --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLEventHandler.java @@ -0,0 +1,147 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.xml; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class TestApexXMLEventHandlerURL. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestXMLEventHandler { + private static final XLogger logger = XLoggerFactory.getXLogger(TestXMLEventHandler.class); + + /** + * Test XML to apex event. + * + * @throws ApexException on Apex event handling errors + */ + @Test + public void testXMLtoApexEvent() throws ApexException { + try { + final Apex2XMLEventConverter xmlEventConverter = new Apex2XMLEventConverter(); + assertNotNull(xmlEventConverter); + + final String apexEventXMLStringIn = XMLEventGenerator.xmlEvent(); + + logger.debug("input event\n" + apexEventXMLStringIn); + + for (final ApexEvent apexEvent : xmlEventConverter.toApexEvent("XMLEventName", apexEventXMLStringIn)) { + assertNotNull(apexEvent); + + logger.debug(apexEvent.toString()); + + assertTrue(apexEvent.getName().equals("Event0000") || apexEvent.getName().equals("Event0100")); + assertTrue(apexEvent.getVersion().equals("0.0.1")); + assertTrue(apexEvent.getNameSpace().equals("org.onap.policy.apex.sample.events")); + assertTrue(apexEvent.getSource().equals("test")); + assertTrue(apexEvent.getTarget().equals("apex")); + assertTrue(apexEvent.get("TestSlogan").toString().startsWith("Test slogan for External Event")); + + final Object testMatchCaseSelected = apexEvent.get("TestMatchCaseSelected"); + assertTrue(testMatchCaseSelected == null); + } + } catch (final Exception e) { + e.printStackTrace(); + throw new ApexException("Exception reading Apex event xml file", e); + } + } + + /** + * Test apex event to xml. + * + * @throws ApexException on Apex event handling errors + */ + @Test + public void testApexEventToXML() throws ApexException { + try { + final Apex2XMLEventConverter xmlEventConverter = new Apex2XMLEventConverter(); + assertNotNull(xmlEventConverter); + + final Date event0000StartTime = new Date(); + final Map<String, Object> event0000DataMap = new HashMap<String, Object>(); + event0000DataMap.put("TestSlogan", "This is a test slogan"); + event0000DataMap.put("TestMatchCase", 12345); + event0000DataMap.put("TestTimestamp", event0000StartTime.getTime()); + event0000DataMap.put("TestTemperature", 34.5445667); + + final ApexEvent apexEvent0000 = + new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.sample.events", "test", "apex"); + apexEvent0000.putAll(event0000DataMap); + + final String apexEvent0000XMLString = xmlEventConverter.fromApexEvent(apexEvent0000); + + logger.debug(apexEvent0000XMLString); + + assertTrue(apexEvent0000XMLString.contains("<name>Event0000</name>")); + assertTrue(apexEvent0000XMLString.contains("<version>0.0.1</version>")); + assertTrue(apexEvent0000XMLString.contains("<value>This is a test slogan</value>")); + assertTrue(apexEvent0000XMLString.contains("<value>12345</value>")); + assertTrue(apexEvent0000XMLString.contains("<value>" + event0000StartTime.getTime() + "</value>")); + assertTrue(apexEvent0000XMLString.contains("<value>34.5445667</value>")); + + final Date event0004StartTime = new Date(1434363272000L); + final Map<String, Object> event0004DataMap = new HashMap<String, Object>(); + event0004DataMap.put("TestSlogan", "Test slogan for External Event"); + event0004DataMap.put("TestMatchCase", new Integer(2)); + event0004DataMap.put("TestTimestamp", new Long(event0004StartTime.getTime())); + event0004DataMap.put("TestTemperature", new Double(1064.43)); + event0004DataMap.put("TestMatchCaseSelected", new Integer(2)); + event0004DataMap.put("TestMatchStateTime", new Long(1434370506078L)); + event0004DataMap.put("TestEstablishCaseSelected", new Integer(0)); + event0004DataMap.put("TestEstablishStateTime", new Long(1434370506085L)); + event0004DataMap.put("TestDecideCaseSelected", new Integer(3)); + event0004DataMap.put("TestDecideStateTime", new Long(1434370506092L)); + event0004DataMap.put("TestActCaseSelected", new Integer(2)); + event0004DataMap.put("TestActStateTime", new Long(1434370506095L)); + + final ApexEvent apexEvent0004 = + new ApexEvent("Event0004", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + apexEvent0004.putAll(event0004DataMap); + + final String apexEvent0004XMLString = xmlEventConverter.fromApexEvent(apexEvent0004); + + logger.debug(apexEvent0004XMLString); + + assertTrue(apexEvent0004XMLString.contains("<name>Event0004</name>")); + assertTrue(apexEvent0004XMLString.contains("<version>0.0.1</version>")); + assertTrue(apexEvent0004XMLString.contains("<value>Test slogan for External Event</value>")); + assertTrue(apexEvent0004XMLString.contains("<value>1434370506078</value>")); + assertTrue(apexEvent0004XMLString.contains("<value>" + event0004StartTime.getTime() + "</value>")); + assertTrue(apexEvent0004XMLString.contains("<value>1064.43</value>")); + } catch (final Exception e) { + e.printStackTrace(); + throw new ApexException("Exception reading Apex event xml file", e); + } + } +} diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLTaggedEventConsumer.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLTaggedEventConsumer.java new file mode 100644 index 000000000..761357a1d --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLTaggedEventConsumer.java @@ -0,0 +1,336 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Test; +import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.HeaderDelimitedTextBlockReader; +import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlock; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestXMLTaggedEventConsumer { + @Test + public void testGarbageTextLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream("hello there".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertNull(textBlock.getText()); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testPartialEventLine() throws IOException { + final InputStream xmlInputStream = + new ByteArrayInputStream("1469781869268</TestTimestamp></MainTag>".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertNull(textBlock.getText()); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventGarbageBeforeLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventGarbageBeforeAfterLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventGarbageAfterLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testGarbageTextMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream("hello\nthere".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testPartialEventMultiLine() throws IOException { + final InputStream xmlInputStream = + new ByteArrayInputStream("1469781869268\n</TestTimestamp>\n</MainTag>".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventGarbageBeforeMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventGarbageBeforeAfterMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish\n\n" + .getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventGarbageAfterMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testPartialEventsLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "1469781869268</TestTimestamp></MainTag><?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp>" + .getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventsGarbageBeforeLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag><?xml><MainTag><TestTimestamp>" + .getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventsGarbageBeforeAfterLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish<?xml><MainTag><TestTimestamp>\nRefuse" + .getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventsGarbageAfterLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish<?xml><MainTag><TestTimestamp>Refuse" + .getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish<?xml><MainTag><TestTimestamp>Refuse"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testPartialEventsMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "1469781869268\n</TestTimestamp>\n</MainTag>\n<?xml>\n<MainTag>\n<TestTimestamp>".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), "<?xml>\n<MainTag>\n<TestTimestamp>"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventsMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n" + .getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>"); + assertFalse(textBlock.isEndOfText()); + + textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventsGarbageBeforeMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n" + .getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>"); + assertFalse(textBlock.isEndOfText()); + + textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventsGarbageBeforeAfterMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRefuse\n" + .getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish"); + assertFalse(textBlock.isEndOfText()); + + textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRefuse"); + assertTrue(textBlock.isEndOfText()); + } + + @Test + public void testFullEventsGarbageAfterMultiLine() throws IOException { + final InputStream xmlInputStream = new ByteArrayInputStream( + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish".getBytes()); + + final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml"); + xmlTaggedReader.init(xmlInputStream); + + final TextBlock textBlock = xmlTaggedReader.readTextBlock(); + assertEquals(textBlock.getText(), + "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish"); + assertTrue(textBlock.isEndOfText()); + } +} diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventGenerator.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventGenerator.java new file mode 100644 index 000000000..765f098de --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventGenerator.java @@ -0,0 +1,104 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.xml; + +import java.util.Random; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class XMLEventGenerator { + private static int nextEventNo = 0; + + public static String xmlEvents(final int eventCount) { + final StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < eventCount; i++) { + if (i > 0) { + builder.append("\n"); + } + builder.append(xmlEvent()); + } + + return builder.toString(); + } + + public static String xmlEvent() { + final Random rand = new Random(); + + final StringBuilder builder = new StringBuilder(); + + int nextEventNo = rand.nextInt(2); + final String eventName = (nextEventNo == 0 ? "Event0000" : "Event0100"); + final int nextMatchCase = rand.nextInt(4); + final float nextTestTemperature = rand.nextFloat() * 10000; + + builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); + builder.append("<xmlApexEvent xmlns=\"http://www.onap.org/policy/apex-pdp/apexevent\">\n"); + + builder.append(" <name>" + eventName + "</name>\n"); + builder.append(" <version>0.0.1</version>\n"); + builder.append(" <nameSpace>org.onap.policy.apex.sample.events</nameSpace>\n"); + builder.append(" <source>test</source>\n"); + builder.append(" <target>apex</target>\n"); + builder.append(" <data>\n"); + builder.append(" <key>TestSlogan</key>\n"); + builder.append(" <value>Test slogan for External Event" + (nextEventNo++) + "</value>\n"); + builder.append(" </data>\n"); + builder.append(" <data>\n"); + builder.append(" <key>TestMatchCase</key>\n"); + builder.append(" <value>" + nextMatchCase + "</value>\n"); + builder.append(" </data>\n"); + builder.append(" <data>\n"); + builder.append(" <key>TestTimestamp</key>\n"); + builder.append(" <value>" + System.currentTimeMillis() + "</value>\n"); + builder.append(" </data>\n"); + builder.append(" <data>\n"); + builder.append(" <key>TestTemperature</key>\n"); + builder.append(" <value>" + nextTestTemperature + "</value>\n"); + builder.append(" </data>\n"); + builder.append("</xmlApexEvent>"); + + return builder.toString(); + } + + public static void main(final String[] args) { + if (args.length != 1) { + System.err.println("usage EventGenerator #events"); + return; + } + + int eventCount = 0; + try { + eventCount = Integer.parseInt(args[0]); + } catch (final Exception e) { + System.err.println("usage EventGenerator #events"); + e.printStackTrace(); + return; + } + + System.out.println(xmlEvents(eventCount)); + } + + public static int getNextEventNo() { + return nextEventNo; + } +} diff --git a/plugins/plugins-event/plugins-event-protocol/pom.xml b/plugins/plugins-event/plugins-event-protocol/pom.xml new file mode 100644 index 000000000..563a4f625 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/pom.xml @@ -0,0 +1,44 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event</groupId> + <artifactId>plugins-event</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId> + <artifactId>plugins-event-protocol</artifactId> + <packaging>pom</packaging> + + <name>${project.artifactId}</name> + <description>Plugins for protocols that events are carried in</description> + + <properties> + <apex-plugins-event-protocol-dir>${project.basedir}/src</apex-plugins-event-protocol-dir> + </properties> + + <modules> + <module>plugins-event-protocol-jms</module> + <module>plugins-event-protocol-xml</module> + </modules> +</project>
\ No newline at end of file diff --git a/plugins/plugins-event/pom.xml b/plugins/plugins-event/pom.xml new file mode 100644 index 000000000..c48b8aefa --- /dev/null +++ b/plugins/plugins-event/pom.xml @@ -0,0 +1,48 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins</groupId> + <artifactId>plugins</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.onap.policy.apex-pdp.plugins.plugins-event</groupId> + <artifactId>plugins-event</artifactId> + <packaging>pom</packaging> + + <name>${project.artifactId}</name> + <description>Plugins for 3pps that carry events and protocol formats of events</description> + + <dependencies> + <dependency> + <groupId>org.onap.policy.apex-pdp.services</groupId> + <artifactId>services-engine</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + + <modules> + <module>plugins-event-carrier</module> + <module>plugins-event-protocol</module> + </modules> +</project>
\ No newline at end of file diff --git a/plugins/plugins-executor/plugins-executor-mvel/pom.xml b/plugins/plugins-executor/plugins-executor-mvel/pom.xml new file mode 100644 index 000000000..a8b2c7db9 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-mvel/pom.xml @@ -0,0 +1,44 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId> + <artifactId>plugins-executor</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>plugins-executor-mvel</artifactId> + <name>${project.artifactId}</name> + <description>[${project.parent.artifactId}] Plugin for execution of Mvel logic in Apex</description> + + <properties> + <apex-plugins-executor-mvel-dir>${project.basedir}/src</apex-plugins-executor-mvel-dir> + </properties> + + <dependencies> + <dependency> + <groupId>org.mvel</groupId> + <artifactId>mvel2</artifactId> + <version>2.3.1.Final</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MVELExecutorParameters.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MVELExecutorParameters.java new file mode 100644 index 000000000..21d124212 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MVELExecutorParameters.java @@ -0,0 +1,42 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.executor.mvel; + +import org.onap.policy.apex.core.engine.ExecutorParameters; + +/** + * This class provides executor parameters for the MVEL Executor plugin. It specifies the classes that provide the MVEL + * implementations of the abstract classes {@link org.onap.policy.apex.core.engine.executor.TaskExecutor}, + * {@link org.onap.policy.apex.core.engine.executor.TaskSelectExecutor}, and + * {@link org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor}. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class MVELExecutorParameters extends ExecutorParameters { + /** + * Constructor that sets the abstract implementation classes. + */ + public MVELExecutorParameters() { + this.setTaskExecutorPluginClass(MvelTaskExecutor.class.getCanonicalName()); + this.setTaskSelectionExecutorPluginClass(MvelTaskSelectExecutor.class.getCanonicalName()); + this.setStateFinalizerExecutorPluginClass(MvelStateFinalizerExecutor.class.getCanonicalName()); + } +} diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutor.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutor.java new file mode 100644 index 000000000..8cd76a94d --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutor.java @@ -0,0 +1,118 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.executor.mvel; + +import static org.onap.policy.apex.model.utilities.Assertions.argumentNotNull; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.mvel2.MVEL; +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class MvelStateFinalizerExecutor is the state finalizer executor for state finalizer logic written in MVEL. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class MvelStateFinalizerExecutor extends StateFinalizerExecutor { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(MvelStateFinalizerExecutor.class); + + // The MVEL code + private Serializable compiled = null; + + /** + * Prepares the state finalizer for processing. + * + * @throws StateMachineException thrown when a state machine execution error occurs + */ + @Override + public void prepare() throws StateMachineException { + // Call generic prepare logic + super.prepare(); + + // Compile the MVEL code + try { + compiled = MVEL.compileExpression(getSubject().getLogic()); + } catch (final Exception e) { + LOGGER.warn("failed to compile MVEL code for state " + getSubject().getKey().getID(), e); + throw new StateMachineException("failed to compile MVEL code for state " + getSubject().getKey().getID(), + e); + } + } + + /** + * Executes the executor for the state finalizer logic in a sequential manner. + * + * @param executionID the execution ID for the current APEX policy execution + * @param incomingFields the incoming fields for finalisation + * @return The state output for the state + * @throws StateMachineException on an execution error + * @throws ContextException on context errors + */ + @Override + public String execute(final long executionID, final Map<String, Object> incomingFields) + throws StateMachineException, ContextException { + // Do execution pre work + executePre(executionID, incomingFields); + + // Check and execute the MVEL logic + argumentNotNull(compiled, "MVEL state finalizer logic not compiled."); + + boolean returnValue = false; + try { + // Execute the MVEL code + returnValue = + (boolean) MVEL.executeExpression(compiled, getExecutionContext(), new HashMap<String, Object>()); + } catch (final Exception e) { + LOGGER.warn("failed to execute MVEL code for state " + getSubject().getKey().getID(), e); + throw new StateMachineException("failed to execute MVEL code for state " + getSubject().getKey().getID(), + e); + } + + // Do the execution post work + executePost(returnValue); + + // Send back the return event + if (returnValue) { + return getOutgoing(); + } else { + return null; + } + } + + /** + * Cleans up the state finalizer after processing. + * + * @throws StateMachineException thrown when a state machine execution error occurs + */ + @Override + public void cleanUp() throws StateMachineException { + LOGGER.debug("cleanUp:" + getSubject().getKey().getID() + "," + getSubject().getLogicFlavour() + "," + + getSubject().getLogic()); + } +} diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutor.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutor.java new file mode 100644 index 000000000..8599eabac --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutor.java @@ -0,0 +1,117 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.executor.mvel; + +import static org.onap.policy.apex.model.utilities.Assertions.argumentNotNull; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.mvel2.MVEL; +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.core.engine.executor.TaskExecutor; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class MvelTaskExecutor is the task executor for task logic written in MVEL. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class MvelTaskExecutor extends TaskExecutor { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(MvelTaskExecutor.class); + + // The MVEL code + private Serializable compiled = null; + + /** + * Prepares the task for processing. + * + * @throws StateMachineException thrown when a state machine execution error occurs + */ + @Override + public void prepare() throws StateMachineException { + // Call generic prepare logic + super.prepare(); + + // Compile the MVEL code + try { + compiled = MVEL.compileExpression(getSubject().getTaskLogic().getLogic()); + } catch (final Exception e) { + LOGGER.warn("failed to compile MVEL code for task " + getSubject().getKey().getID(), e); + throw new StateMachineException("failed to compile MVEL code for task " + getSubject().getKey().getID(), e); + } + argumentNotNull(compiled, "MVEL task not compiled."); + } + + /** + * Executes the executor for the task in a sequential manner. + * + * @param executionID the execution ID for the current APEX policy execution + * @param incomingFields the incoming fields + * @return The outgoing fields + * @throws StateMachineException on an execution error + * @throws ContextException on context errors + */ + @Override + public Map<String, Object> execute(final long executionID, final Map<String, Object> incomingFields) + throws StateMachineException, ContextException { + // Do execution pre work + executePre(executionID, incomingFields); + + // Check and execute the MVEL logic + argumentNotNull(compiled, "MVEL task not compiled."); + boolean returnValue = false; + + try { + // Execute the MVEL code + returnValue = + (boolean) MVEL.executeExpression(compiled, getExecutionContext(), new HashMap<String, Object>()); + } catch (final Exception e) { + LOGGER.warn("failed to execute MVEL code for task " + getSubject().getKey().getID(), e); + throw new StateMachineException("failed to execute MVEL code for task " + getSubject().getKey().getID(), e); + } + + // Do the execution post work + executePost(returnValue); + + // Send back the return event + if (returnValue) { + return getOutgoing(); + } else { + return null; + } + } + + /** + * Cleans up the task after processing. + * + * @throws StateMachineException thrown when a state machine execution error occurs + */ + @Override + public void cleanUp() throws StateMachineException { + LOGGER.debug("cleanUp:" + getSubject().getKey().getID() + "," + getSubject().getTaskLogic().getLogicFlavour() + + "," + getSubject().getTaskLogic().getLogic()); + } +} diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutor.java new file mode 100644 index 000000000..3cb5d9bf6 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutor.java @@ -0,0 +1,120 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.apex.plugins.executor.mvel; + +import static org.onap.policy.apex.model.utilities.Assertions.argumentNotNull; + +import java.io.Serializable; +import java.util.HashMap; + +import org.mvel2.MVEL; +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class MvelTaskSelectExecutor is the task selection executor for task selection logic written in MVEL. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class MvelTaskSelectExecutor extends TaskSelectExecutor { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(MvelTaskSelectExecutor.class); + + // The MVEL code + private Serializable compiled = null; + + /** + * Prepares the task for processing. + * + * @throws StateMachineException thrown when a state machine execution error occurs + */ + @Override + public void prepare() throws StateMachineException { + // Call generic prepare logic + super.prepare(); + + // Compile the MVEL code + try { + compiled = MVEL.compileExpression(getSubject().getTaskSelectionLogic().getLogic()); + } catch (final Exception e) { + LOGGER.warn("failed to compile MVEL code for state " + getSubject().getKey().getID(), e); + throw new StateMachineException("failed to compile MVEL code for state " + getSubject().getKey().getID(), + e); + } + } + + /** + * Executes the executor for the task in a sequential manner. + * + * @param executionID the execution ID for the current APEX policy execution + * @param incomingEvent the incoming event + * @return The outgoing event + * @throws StateMachineException on an execution error + * @throws ContextException on context errors + */ + @Override + public AxArtifactKey execute(final long executionID, final EnEvent incomingEvent) + throws StateMachineException, ContextException { + // Do execution pre work + executePre(executionID, incomingEvent); + + // Check and execute the MVEL logic + argumentNotNull(compiled, "MVEL task not compiled."); + + boolean returnValue = false; + try { + // Execute the MVEL code + returnValue = + (boolean) MVEL.executeExpression(compiled, getExecutionContext(), new HashMap<String, Object>()); + } catch (final Exception e) { + LOGGER.warn("failed to execute MVEL code for state " + getSubject().getKey().getID(), e); + throw new StateMachineException("failed to execute MVEL code for state " + getSubject().getKey().getID(), + e); + } + + // Do the execution post work + executePost(returnValue); + + // Send back the return event + if (returnValue) { + return getOutgoing(); + } else { + return null; + } + } + + /** + * Cleans up the task after processing. + * + * @throws StateMachineException thrown when a state machine execution error occurs + */ + @Override + public void cleanUp() throws StateMachineException { + LOGGER.debug("cleanUp:" + getSubject().getKey().getID() + "," + + getSubject().getTaskSelectionLogic().getLogicFlavour() + "," + + getSubject().getTaskSelectionLogic().getLogic()); + } +} diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/package-info.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/package-info.java new file mode 100644 index 000000000..8e8ab889b --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/package-info.java @@ -0,0 +1,30 @@ +/*- + * ============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========================================================= + */ + +/** + * Implements the MVEL executor plugin for APEX, providing extensions of the abstract classes + * {@link com.ericsson.apex.core.engine.executor.TaskExecutor}, + * {@link com.ericsson.apex.core.engine.executor.TaskSelectExecutor}, and + * {@link com.ericsson.apex.core.engine.executor.StateFinalizerExecutor}. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ + +package org.onap.policy.apex.plugins.executor.mvel; diff --git a/plugins/plugins-executor/pom.xml b/plugins/plugins-executor/pom.xml new file mode 100644 index 000000000..e18fd17e8 --- /dev/null +++ b/plugins/plugins-executor/pom.xml @@ -0,0 +1,81 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 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========================================================= +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.apex-pdp.plugins</groupId> + <artifactId>plugins</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId> + <artifactId>plugins-executor</artifactId> + <packaging>pom</packaging> + + <name>${project.artifactId}</name> + <description>Plugins for logic execution in Apex</description> + + <properties> + <apex-plugins-executor-dir>${project.basedir}/src</apex-plugins-executor-dir> + </properties> + + <dependencies> + <dependency> + <groupId>org.onap.policy.apex-pdp.core</groupId> + <artifactId>core-engine</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>apexDefault</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <modules> + <module>plugins-executor-mvel</module> + </modules> + </profile> + <profile> + <id>apexTests</id> + <activation> + <property> + <name>apexTests</name> + </property> + </activation> + <modules> + <module>plugins-executor-mvel</module> + </modules> + </profile> + <profile> + <id>apexAll</id> + <activation> + <property> + <name>apexAll</name> + </property> + </activation> + <modules> + <module>plugins-executor-mvel</module> + </modules> + </profile> + </profiles> +</project>
\ No newline at end of file diff --git a/plugins/pom.xml b/plugins/pom.xml index f9afef8de..73bcdfa09 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -36,9 +36,13 @@ <properties> <version.hazelcast>3.8.3</version.hazelcast> + <version.jersey.core>2.25.1</version.jersey.core> + <version.grizzly2-http>2.25.1</version.grizzly2-http> </properties> <modules> <module>plugins-context</module> + <module>plugins-event</module> + <module>plugins-executor</module> </modules> </project>
\ No newline at end of file diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListener.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListener.java index 311e3b660..5c757c6d9 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListener.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListener.java @@ -164,6 +164,8 @@ public class EngDepMessageListener implements MessageListener<Message>, Runnable } } } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.debug("message listener execution has been interrupted"); break; } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java index b4ba2ac3e..9904847aa 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventMarshaller.java @@ -163,6 +163,8 @@ public class ApexEventMarshaller implements ApexEventListener, Runnable { try { queue.put(apexEvent); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.warn("Failed to queue the event: " + apexEvent, e); } } @@ -191,6 +193,8 @@ public class ApexEventMarshaller implements ApexEventListener, Runnable { LOGGER.trace("event sent : " + apexEvent.toString()); } } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.debug("Thread interrupted, Reason {}", e.getMessage()); break; } catch (final Exception e) { diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java index a9385751e..7b4188ea1 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java @@ -276,6 +276,8 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { // Pass the event to the activator for forwarding to Apex engineServiceHandler.forwardEvent(apexEvent); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.warn("BatchProcessor thread interrupted, Reason {}", e.getMessage()); break; } catch (final Exception e) { diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java index 20f8aaf75..f74c0f47b 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java @@ -649,6 +649,8 @@ final class EngineWorker implements EngineService { try { event = eventProcessingQueue.take(); } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); LOGGER.debug("Engine {} processing interrupted ", engineWorkerKey); break; } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJSONAdapter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJSONAdapter.java index 5aa7d6455..e72a283cd 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJSONAdapter.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJSONAdapter.java @@ -124,9 +124,10 @@ public class CarrierTechnologyParametersJSONAdapter // Check the carrier technology parameter class if (carrierTechnologyParameterClassName == null || carrierTechnologyParameterClassName.length() == 0) { - final String errorMessage = - "carrier technology \"" + carrierTechnologyLabel + "\" parameter \"" + PARAMETER_CLASS_NAME - + "\" value \"" + classNameJsonPrimitive.getAsString() + "\" invalid in JSON file"; + final String errorMessage = "carrier technology \"" + carrierTechnologyLabel + "\" parameter \"" + + PARAMETER_CLASS_NAME + "\" value \"" + + (classNameJsonPrimitive != null ? classNameJsonPrimitive.getAsString() : "null") + + "\" invalid in JSON file"; LOGGER.warn(errorMessage); throw new ApexParameterRuntimeException(errorMessage); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJSONAdapter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJSONAdapter.java index c880756b3..1f33db6b8 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJSONAdapter.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJSONAdapter.java @@ -123,7 +123,8 @@ public class EventProtocolParametersJSONAdapter if (eventProtocolParameterClassName == null || eventProtocolParameterClassName.length() == 0) { final String errorMessage = "event protocol \"" + eventProtocolLabel + "\" parameter \"" + PARAMETER_CLASS_NAME + "\" value \"" - + classNameJsonPrimitive.getAsString() + "\" invalid in JSON file"; + + (classNameJsonPrimitive != null ? classNameJsonPrimitive.getAsString() : "null") + + "\" invalid in JSON file"; LOGGER.warn(errorMessage); throw new ApexParameterRuntimeException(errorMessage); } |