* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
/**
* This class is the implementation of the {@link org.onap.policy.apex.context.SchemaHelper} interface for Avro schemas.
*/
public class AvroSchemaHelper extends AbstractSchemaHelper {
// Get a reference to the logger
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroSchemaHelper.class);
// Recurring string constants
private static final String OBJECT_TAG = ": object \"";
avroSchema = new Schema.Parser().parse(schema.getSchema());
} catch (final Exception e) {
final String resultSting = userKey.getId() + ": avro context schema \"" + schema.getId()
- + "\" schema is invalid: " + e.getMessage() + ", schema: " + schema.getSchema();
- LOGGER.warn(resultSting, e);
- throw new ContextRuntimeException(resultSting);
+ + "\" schema is invalid, schema: " + schema.getSchema();
+ throw new ContextRuntimeException(resultSting, e);
}
// Get the object mapper for the schema type to a Java class
} else {
final String returnString =
getUserKey().getId() + ": the object \"" + incomingObject + "\" is not an instance of JsonObject";
- LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
}
} else {
final String returnString = getUserKey().getId() + ": the schema \"" + avroSchema.getName()
+ "\" does not have a subtype of type \"" + subInstanceType + "\"";
- LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
}
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_TAG + objectString
- + "\" Avro unmarshalling failed: " + e.getMessage();
- LOGGER.warn(returnString, e);
+ final String returnString =
+ getUserKey().getId() + OBJECT_TAG + objectString + "\" Avro unmarshalling failed.";
throw new ContextRuntimeException(returnString, e);
}
final String returnString = getUserKey().getId() + OBJECT_TAG + object + "\" of type \""
+ (object != null ? object.getClass().getName() : "null") + "\" must be assignable to \""
+ getSchemaClass().getName() + "\" or be a Json string representation of it for Avro unmarshalling";
- LOGGER.warn(returnString, e);
- throw new ContextRuntimeException(returnString);
+ throw new ContextRuntimeException(returnString, e);
}
}
jsonEncoder.flush();
return new String(output.toByteArray());
} catch (final Exception e) {
- final String returnString =
- getUserKey().getId() + OBJECT_TAG + object + "\" Avro marshalling failed: " + e.getMessage();
- LOGGER.warn(returnString);
+ final String returnString = getUserKey().getId() + OBJECT_TAG + object + "\" Avro marshalling failed.";
throw new ContextRuntimeException(returnString, e);
}
}
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleHearts.json");
assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json"))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. "
- + "Got VALUE_NULL");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json"))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. "
- + "Got VALUE_NULL");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad0.json"))
- .hasMessage("AvroTest:0.0.1: object \"\"TWEED\"\" Avro unmarshalling failed: Unknown symbol "
- + "in enum TWEED");
+ .hasMessage("AvroTest:0.0.1: object \"\"TWEED\"\" Avro unmarshalling failed.");
assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad1.json"))
- .hasMessage("AvroTest:0.0.1: object \"\"Hearts\"\" Avro unmarshalling failed: Unknown symbol "
- + "in enum Hearts");
+ .hasMessage("AvroTest:0.0.1: object \"\"Hearts\"\" Avro unmarshalling failed.");
}
/**
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleGood.json");
assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json"))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. "
- + "Got VALUE_NULL");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json"))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. "
- + "Got VALUE_NULL");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad0.json"))
- .hasMessage("AvroTest:0.0.1: object \"\"BADBAD\"\" "
- + "Avro unmarshalling failed: Expected fixed length 64, but got6");
+ .hasMessage("AvroTest:0.0.1: object \"\"BADBAD\"\" " + "Avro unmarshalling failed.");
assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad1.json"))
- .hasMessage("AvroTest:0.0.1: object "
- + "\"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" "
- + "Avro unmarshalling failed: Expected fixed length 64, but got65");
+ .hasMessage(
+ "AvroTest:0.0.1: object " + "\"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" "
+ + "Avro unmarshalling failed.");
}
/**
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
assertEquals("true", schemaHelper1.marshal2String(true));
assertEquals("false", schemaHelper1.marshal2String(false));
assertThatThrownBy(() -> schemaHelper1.marshal2String(0))
- .hasMessage("AvroTest:0.0.1: object \"0\" Avro marshalling failed: "
- + "class java.lang.Integer cannot be cast to class java.lang.Boolean (java.lang.Integer and "
- + "java.lang.Boolean are in module java.base of loader 'bootstrap')");
+ .hasMessage("AvroTest:0.0.1: object \"0\" Avro marshalling failed.");
assertThatThrownBy(() -> schemaHelper1.marshal2String("0"))
- .hasMessage("AvroTest:0.0.1: object \"0\" Avro marshalling failed: class java.lang.String "
- + "cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module"
- + " java.base of loader 'bootstrap')");
+ .hasMessage("AvroTest:0.0.1: object \"0\" Avro marshalling failed.");
}
/**
assertEquals("2147483647", schemaHelper2.marshal2String(2147483647));
assertEquals("-2147483648", schemaHelper2.marshal2String(-2147483648));
assertThatThrownBy(() -> schemaHelper2.marshal2String("Hello"))
- .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
- + "class java.lang.String cannot be cast to class java.lang.Number");
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed.");
assertThatThrownBy(() -> schemaHelper2.marshal2String(null))
.hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\"");
}
assertEquals("9223372036854775807", schemaHelper3.marshal2String(9223372036854775807L));
assertEquals("-9223372036854775808", schemaHelper3.marshal2String(-9223372036854775808L));
assertThatThrownBy(() -> schemaHelper3.marshal2String("Hello"))
- .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
- + "class java.lang.String cannot be cast to class java.lang.Long");
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed.");
assertThatThrownBy(() -> schemaHelper3.marshal2String(null))
.hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\"");
}
assertEquals("9.223372E18", schemaHelper4.marshal2String(9.223372E18F));
assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F));
assertThatThrownBy(() -> schemaHelper4.marshal2String("Hello"))
- .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
- + "class java.lang.String cannot be cast to class java.lang.Float");
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed.");
assertThatThrownBy(() -> schemaHelper4.marshal2String(null))
.hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\"");
}
assertEquals("9.223372036854776E18", schemaHelper5.marshal2String(9.223372036854776E18));
assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18));
assertThatThrownBy(() -> schemaHelper5.marshal2String("Hello"))
- .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
- + "class java.lang.String cannot be cast to class java.lang.Double");
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed.");
assertThatThrownBy(() -> schemaHelper5.marshal2String(null))
.hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\"");
}
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
assertEquals(null, schemaHelper0.unmarshal("null"));
assertThatThrownBy(() -> schemaHelper0.unmarshal("123"))
- .hasMessage("AvroTest:0.0.1: object \"123\" Avro unmarshalling failed: "
- + "Expected null. Got VALUE_NUMBER_INT");
+ .hasMessage("AvroTest:0.0.1: object \"123\" Avro unmarshalling failed.");
}
/**
assertEquals(2147483647, schemaHelper2.unmarshal("2147483647"));
assertEquals(-2147483648, schemaHelper2.unmarshal("-2147483648"));
assertThatThrownBy(() -> schemaHelper2.unmarshal("2147483648"))
- .hasMessageStartingWith("AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed: "
- + "Numeric value (2147483648) out of range of int");
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed.");
assertThatThrownBy(() -> schemaHelper2.unmarshal("-2147483649"))
- .hasMessageStartingWith("AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed: "
- + "Numeric value (-2147483649) out of range of int");
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed.");
assertThatThrownBy(() -> schemaHelper2.unmarshal(null))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
}
/**
assertEquals(9223372036854775807L, schemaHelper3.unmarshal("9223372036854775807"));
assertEquals(-9223372036854775808L, schemaHelper3.unmarshal("-9223372036854775808"));
assertThatThrownBy(() -> schemaHelper3.unmarshal("9223372036854775808"))
- .hasMessageStartingWith("AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed: "
- + "Numeric value (9223372036854775808) out of range of long");
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed.");
assertThatThrownBy(() -> schemaHelper3.unmarshal("-9223372036854775809"))
- .hasMessageStartingWith("AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed: "
- + "Numeric value (-9223372036854775809) out of range of long");
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed.");
assertThatThrownBy(() -> schemaHelper3.unmarshal("\"Hello\""))
- .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
- + "Expected long. Got VALUE_STRING");
+ .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed.");
assertThatThrownBy(() -> schemaHelper3.unmarshal(null))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
}
/**
assertEquals(9.223372E18F, schemaHelper4.unmarshal("9223372036854775808"));
assertEquals(-9.223372E18F, schemaHelper4.unmarshal("-9223372036854775809"));
assertThatThrownBy(() -> schemaHelper4.unmarshal("\"Hello\""))
- .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
- + "Expected float. Got VALUE_STRING");
+ .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed.");
assertThatThrownBy(() -> schemaHelper4.unmarshal(null))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
}
/**
assertEquals(9.223372036854776E18, schemaHelper5.unmarshal("9223372036854775808"));
assertEquals(-9.223372036854776E18, schemaHelper5.unmarshal("-9223372036854775809"));
assertThatThrownBy(() -> schemaHelper5.unmarshal("\"Hello\""))
- .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
- + "Expected double. Got VALUE_STRING");
+ .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed.");
assertThatThrownBy(() -> schemaHelper5.unmarshal(null))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
}
/**
assertEquals("Hello", schemaHelper7.unmarshal("Hello"));
assertEquals("Hello", schemaHelper7.unmarshal(new Utf8("Hello")));
assertThatThrownBy(() -> schemaHelper7.unmarshal(null))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
}
/**
assertEquals(111, newBytes[4]);
assertThatThrownBy(() -> schemaHelper.unmarshal(null))
- .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!");
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed.");
}
}
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
} catch (Exception e) {
final String errorMessage = "message \"" + eventObject
+ "\" received from JMS does not have a \"getObject()\" method";
- LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage);
}
} 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);
}
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);
}
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");
}
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);
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 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.
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
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public final class Apex2JmsTextEventConverter extends Apex2JsonEventConverter {
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2JmsTextEventConverter.class);
/**
* {@inheritDoc}.
} catch (Exception e) {
final String errorMessage = "message \"" + eventObject
+ "\" received from JMS does not have a \"getText()\" method";
- LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage);
}
} 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);
}
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");
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 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.
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
import org.xml.sax.SAXException;
/**
* @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";
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);
}
}
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");
}
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);
}
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");
}
}
}
} 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);
}
// 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);
}
}
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
// Check and get the YAML parameters
if (!(parameters instanceof YamlEventProtocolParameters)) {
final String errorMessage = "specified consumer properties are not applicable to the YAML event protocol";
- LOGGER.warn(errorMessage);
throw new ApexEventRuntimeException(errorMessage);
}
public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException {
// Check the event eventObject
if (eventObject == null) {
- LOGGER.warn("event processing failed, event is null");
throw new ApexEventException("event processing failed, event is null");
}
// always work
if (!(eventObject instanceof String)) {
final String errorMessage = "error converting event \"" + eventObject + "\" to a string";
- LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
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");
}
if (!eventField.getOptional()) {
final String errorMessage = "error parsing " + eventDefinition.getId() + " event to Json. "
+ "Field \"" + fieldName + "\" is missing, but is mandatory. Fields: " + apexEvent;
- LOGGER.debug(errorMessage);
throw new ApexEventRuntimeException(errorMessage);
}
continue;
if (!eventField.getOptional()) {
final String errorMessage = "error parsing " + eventDefinition.getId() + " event from Json. "
+ "Field \"" + fieldName + "\" is missing, but is mandatory.";
- LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
continue;
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException {
// Check the event eventObject
if (eventObject == null) {
- LOGGER.warn("event processing failed, event is null");
throw new ApexEventException("event processing failed, event is null");
}
eventList.add(event);
}
} catch (final Exception e) {
- final String errorString = "Failed to unmarshal APEX event: " + e.getMessage() + ", event=" + eventObject;
- LOGGER.warn(errorString, e);
+ final String errorString = "Failed to unmarshal APEX event, event=" + eventObject;
throw new ApexEventException(errorString, e);
}
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");
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 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.
import org.onap.policy.apex.service.engine.event.ApexEventConverter;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
/**
* The Class ApexEvent2EnEventConverter converts externally facing {@link ApexEvent} instances to
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public final class ApexEvent2EnEventConverter implements ApexEventConverter {
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEvent2EnEventConverter.class);
// The Apex engine with its event definitions
private final ApexEngine apexEngine;
public List<ApexEvent> toApexEvent(final String eventName, final Object event) throws ApexException {
// Check the Engine event
if (event == null) {
- LOGGER.warn("event processing failed, engine event is null");
throw new ApexEventException("event processing failed, engine event is null");
}
enEvent = (EnEvent) event;
} catch (final Exception e) {
final String errorMessage = "error transferring event \"" + event + "\" to the Apex engine";
- LOGGER.debug(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage, e);
}
public EnEvent fromApexEvent(final ApexEvent apexEvent) throws ApexException {
// Check the Apex model
if (apexEngine == null) {
- LOGGER.warn("event processing failed, apex engine is null");
throw new ApexEventException("event processing failed, apex engine is null");
}
// Get the event definition
final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(apexEvent.getName());
if (eventDefinition == null) {
- LOGGER.warn("event processing failed, event \"" + apexEvent.getName() + "\" not found in apex model");
throw new ApexEventException(
"event processing failed, event \"" + apexEvent.getName() + "\" not found in apex model");
}
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 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.
// Check and get the JSON parameters
if (!(parameters instanceof JsonEventProtocolParameters)) {
final String errorMessage = "specified consumer properties are not applicable to the JSON event protocol";
- LOGGER.warn(errorMessage);
throw new ApexEventRuntimeException(errorMessage);
}
public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException {
// Check the event eventObject
if (eventObject == null) {
- LOGGER.warn("event processing failed, event is null");
throw new ApexEventException("event processing failed, event is null");
}
jsonEventString = (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);
}
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");
}
if (!eventField.getOptional()) {
final String errorMessage = ERROR_CODING + eventDefinition.getId() + " event to Json. " + "Field \""
+ fieldName + "\" is missing, but is mandatory. Fields: " + apexEvent;
- LOGGER.debug(errorMessage);
throw new ApexEventRuntimeException(errorMessage);
}
continue;
if (eventDefinition.getFields().isEmpty()) {
final String errorMessage = ERROR_CODING + eventDefinition.getId() + " event to Json, Field "
+ jsonPars.getPojoField() + " not found, no fields defined on event.";
- LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
final String errorMessage = ERROR_CODING + eventDefinition.getId() + " event to Json, Field "
+ jsonPars.getPojoField() + ", "
+ " one and only one field may be defined on a POJO event definition.";
- LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
if (!jsonPars.getPojoField().equals(pojoFieldDefinition.getKey().getLocalName())) {
final String errorMessage = ERROR_CODING + eventDefinition.getId() + " event to Json. Field "
+ jsonPars.getPojoField() + " not found on POJO event definition.";
- LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
if (!eventField.getOptional()) {
final String errorMessage = ERROR_PARSING + eventDefinition.getId() + " event from Json. "
+ "Field \"" + fieldName + "\" is missing, but is mandatory.";
- LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
continue;
if (eventDefinition.getFields().isEmpty()) {
final String errorMessage = ERROR_PARSING + eventDefinition.getId() + " event from Json, Field "
+ jsonPars.getPojoField() + " not found, no fields defined on event.";
- LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
final String errorMessage = ERROR_PARSING + eventDefinition.getId() + " event from Json, Field "
+ jsonPars.getPojoField()
+ ", one and only one field may be defined on a POJO event definition.";
- LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
if (!jsonPars.getPojoField().equals(pojoFieldDefinition.getKey().getLocalName())) {
final String errorMessage = ERROR_PARSING + eventDefinition.getId() + " event from Json. Field "
+ jsonPars.getPojoField() + " not found on POJO event definition.";
- LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}