diff options
Diffstat (limited to 'plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml')
3 files changed, 37 insertions, 12 deletions
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java index 9359e4ef9..731d3519a 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2021 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -257,7 +257,9 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter { String target = getHeaderTarget(yamlMap, eventDefinition); - return new ApexEvent(name, version, namespace, source, target); + String toscaPolicyState = getHeaderToscaPolicyState(yamlMap, eventDefinition); + + return new ApexEvent(name, version, namespace, source, target, toscaPolicyState); } /** @@ -318,6 +320,23 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter { } /** + * Get the event header toscaPolicyState field. + * + * @param yamlMap the YAML map to read from + * @param eventDefinition the event definition + * @return the event header toscaPolicyState field + */ + private String getHeaderToscaPolicyState(final Map<?, ?> yamlMap, final AxEvent eventDefinition) { + // For toscaPolicyState, use the defined value only if not found on the incoming event + var toscaPolicyState = getYamlStringField(yamlMap, ApexEvent.TOSCA_POLICY_STATE_HEADER_FIELD, + yamlPars.getToscaPolicyStateAlias(), null, false); + if (toscaPolicyState == null) { + toscaPolicyState = eventDefinition.getTarget(); + } + return toscaPolicyState; + } + + /** * This method gets an event string field from a JSON object. * * @param yamlMap the YAML containing the YAML representation of the incoming event @@ -391,4 +410,4 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter { return eventElement; } -} +}
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java index e5539cd04..120104460 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,12 +62,13 @@ public class YamlEventProtocolParameters extends EventProtocolTextTokenDelimited // Aliases for Apex event header fields // @formatter:off - private String nameAlias = null; - private String versionAlias = null; - private String nameSpaceAlias = null; - private String sourceAlias = null; - private String targetAlias = null; - private String yamlFieldName = DEFAULT_YAML_FIELD_NAME; + private String nameAlias = null; + private String versionAlias = null; + private String nameSpaceAlias = null; + private String sourceAlias = null; + private String targetAlias = null; + private String toscaPolicyStateAlias = null; + private String yamlFieldName = DEFAULT_YAML_FIELD_NAME; // @formatter:on /** @@ -96,4 +98,4 @@ public class YamlEventProtocolParameters extends EventProtocolTextTokenDelimited // Set the event protocol plugin class this.setEventProtocolPluginClass(Apex2YamlEventConverter.class.getName()); } -} +}
\ No newline at end of file diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java index ab911499a..0d3d62382 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java @@ -3,6 +3,7 @@ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +36,7 @@ import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus; import org.onap.policy.apex.model.basicmodel.service.ModelService; import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; @@ -80,6 +82,7 @@ public class YamlPluginStabilityTest { testEvent = new AxEvent(new AxArtifactKey("TestEvent", "0.0.1")); testEvent.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml"); + testEvent.setToscaPolicyState(AxToscaPolicyProcessingStatus.ENTRY.name()); AxField teField0 = new AxField(new AxReferenceKey(testEvent.getKey(), "intValue"), simpleIntSchema.getKey()); testEvent.getParameterMap().put("intValue", teField0); AxField teField1 = new AxField(new AxReferenceKey(testEvent.getKey(), "doubleValue"), @@ -130,7 +133,8 @@ public class YamlPluginStabilityTest { assertThatThrownBy(() -> converter.fromApexEvent(null)) .hasMessage("event processing failed, Apex event is null"); ApexEvent apexEvent = new ApexEvent(testEvent.getKey().getName(), testEvent.getKey().getVersion(), - testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget()); + testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget(), + testEvent.getToscaPolicyState()); apexEvent.put("doubleValue", 123.45); apexEvent.put("intValue", 123); apexEvent.put("stringValue", "123.45"); @@ -216,4 +220,4 @@ public class YamlPluginStabilityTest { assertThatThrownBy(() -> converter.toApexEvent("TestEvent", "doubleValue: 123.45\n" + "intValue: ~\n" + "stringValue: MyString")).getCause().hasMessageStartingWith("mandatory field \"intValue\" is missing"); } -} +}
\ No newline at end of file |