/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
// Send the periodic event
try {
- final ApexEvent periodicEvent = new ApexEvent(PERIODIC_EVENT_NAME, PERIODIC_EVENT_VERSION,
+ final var periodicEvent = new ApexEvent(PERIODIC_EVENT_NAME, PERIODIC_EVENT_VERSION,
PERIODIC_EVENT_NAMESPACE, PERIODIC_EVENT_SOURCE, PERIODIC_EVENT_TARGET);
periodicEvent.putAll(periodicEventMap);
engineServiceEventInterface.sendEvent(periodicEvent);
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
public void sendEvent(final long executionId, final Properties executionProperties, final String eventName,
final Object event) {
// Check if this is a synchronized event, if so we have received a reply
- final SynchronousEventCache synchronousEventCache =
+ final var synchronousEventCache =
(SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS);
if (synchronousEventCache != null) {
synchronousEventCache.removeCachedEventToApexIfExists(executionId);
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
public void init(final EventProtocolParameters parameters) {
// Check and get the APEX parameters
if (!(parameters instanceof ApexEventProtocolParameters)) {
- final String errorMessage = "specified consumer properties are not applicable to the APEX event protocol";
+ final var errorMessage = "specified consumer properties are not applicable to the APEX event protocol";
LOGGER.warn(errorMessage);
throw new ApexEventRuntimeException(errorMessage);
}
// Check whether we have any ApexEventList fields, if so this is an event of events and
// all fields should be of type ApexEventList
- boolean foundEventListFields = false;
- boolean foundOtherFields = false;
+ var foundEventListFields = false;
+ var foundOtherFields = false;
for (final Object fieldObject : event.values()) {
if (fieldObject instanceof ApexEventList) {
foundEventListFields = true;
eventList.add(event);
}
} catch (final Exception e) {
- final String errorString = "Failed to unmarshal APEX event, event=" + eventObject;
+ final var errorString = "Failed to unmarshal APEX event, event=" + eventObject;
throw new ApexEventException(errorString, e);
}
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
// Create the Apex event
- final AxEvent axEvent = enEvent.getAxEvent();
- final ApexEvent apexEvent = new ApexEvent(axEvent.getKey().getName(), axEvent.getKey().getVersion(),
+ final var axEvent = enEvent.getAxEvent();
+ final var apexEvent = new ApexEvent(axEvent.getKey().getName(), axEvent.getKey().getVersion(),
axEvent.getNameSpace(), axEvent.getSource(), axEvent.getTarget());
apexEvent.setExecutionId(enEvent.getExecutionId());
}
// Create the internal engine event
- final EnEvent enEvent = apexEngine.createEvent(eventDefinition.getKey());
+ final var enEvent = apexEngine.createEvent(eventDefinition.getKey());
// Set the data on the engine event
enEvent.putAll(apexEvent);
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
LOGGER.warn(errorMessage);
throw new ApexEventException(errorMessage);
}
- final FileCarrierTechnologyParameters fileCarrierTechnologyParameters =
+ final var fileCarrierTechnologyParameters =
(FileCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters();
// Now we create a writer for events
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.onap.policy.apex.context.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.model.basicmodel.service.ModelService;
import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
public void init(final EventProtocolParameters parameters) {
// Check and get the JSON parameters
if (!(parameters instanceof JsonEventProtocolParameters)) {
- final String errorMessage = "specified consumer properties are not applicable to the JSON event protocol";
+ final var errorMessage = "specified consumer properties are not applicable to the JSON event protocol";
throw new ApexEventRuntimeException(errorMessage);
}
try {
// We may have a single JSON object with a single event or an array of JSON objects
- final Object decodedJsonObject = new GsonBuilder().serializeNulls().create().fromJson(jsonEventString,
+ final var decodedJsonObject = new GsonBuilder().serializeNulls().create().fromJson(jsonEventString,
Object.class);
// Check if we have a list of objects
apexEvent.getVersion());
// Use a GSON Json object to marshal the Apex event to JSON
- final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
- final JsonObject jsonObject = new JsonObject();
+ final var gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
+ final var jsonObject = new JsonObject();
jsonObject.addProperty(ApexEvent.NAME_HEADER_FIELD, apexEvent.getName());
jsonObject.addProperty(ApexEvent.VERSION_HEADER_FIELD, apexEvent.getVersion());
final Object fieldValue = apexEvent.get(fieldName);
// Get the schema helper
- final SchemaHelper fieldSchemaHelper = new SchemaHelperFactory().createSchemaHelper(eventField.getKey(),
+ final var fieldSchemaHelper = new SchemaHelperFactory().createSchemaHelper(eventField.getKey(),
eventField.getSchema());
jsonObject.add(fieldName, (JsonElement) fieldSchemaHelper.marshal2Object(fieldValue));
}
final Object fieldValue = apexEvent.get(jsonPars.getPojoField());
// Get the schema helper
- final SchemaHelper fieldSchemaHelper = new SchemaHelperFactory()
+ final var fieldSchemaHelper = new SchemaHelperFactory()
.createSchemaHelper(pojoFieldDefinition.getKey(), pojoFieldDefinition.getSchema());
return fieldSchemaHelper.marshal2String(fieldValue);
private ApexEvent jsonStringApexEvent(final String eventName, final String jsonEventString)
throws ApexEventException {
// Use GSON to read the event string
- final JsonObject jsonObject = new GsonBuilder().serializeNulls().create().fromJson(jsonEventString,
+ final var jsonObject = new GsonBuilder().serializeNulls().create().fromJson(jsonEventString,
JsonObject.class);
if (jsonObject == null || !jsonObject.isJsonObject()) {
private ApexEvent jsonObject2ApexEvent(final String eventName, final JsonObject jsonObject)
throws ApexEventException {
// Process the mandatory Apex header
- final ApexEvent apexEvent = processApexEventHeader(eventName, jsonObject);
+ final var apexEvent = processApexEventHeader(eventName, jsonObject);
// Get the event definition for the event from the model service
final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(apexEvent.getName(),
if (fieldValue != null && !fieldValue.isJsonNull()) {
// Get the schema helper
- final SchemaHelper fieldSchemaHelper = new SchemaHelperFactory().createSchemaHelper(eventField.getKey(),
+ final var fieldSchemaHelper = new SchemaHelperFactory().createSchemaHelper(eventField.getKey(),
eventField.getSchema());
apexEvent.put(fieldName, fieldSchemaHelper.createNewInstance(fieldValue));
} else {
}
// Get the schema helper
- final SchemaHelper fieldSchemaHelper = new SchemaHelperFactory()
+ final var fieldSchemaHelper = new SchemaHelperFactory()
.createSchemaHelper(pojoFieldDefinition.getKey(), pojoFieldDefinition.getSchema());
apexEvent.put(jsonPars.getPojoField(), fieldSchemaHelper.createNewInstance(jsonObject));
}
* @return the event name to use on the event header
*/
private String getHeaderName(final JsonObject jsonObject, final String parameterEventName) {
- final String jsonEventName = getJsonStringField(jsonObject, ApexEvent.NAME_HEADER_FIELD,
+ final var jsonEventName = getJsonStringField(jsonObject, ApexEvent.NAME_HEADER_FIELD,
jsonPars.getNameAlias(), ApexEvent.NAME_REGEXP, false);
// Check that an event name has been specified
*/
private String getHeaderNamespace(final JsonObject jsonObject, final String name, final AxEvent eventDefinition) {
// Check the name space is OK if it is defined, if not, use the name space from the model
- String namespace = getJsonStringField(jsonObject, ApexEvent.NAMESPACE_HEADER_FIELD,
+ var namespace = getJsonStringField(jsonObject, ApexEvent.NAMESPACE_HEADER_FIELD,
jsonPars.getNameSpaceAlias(), ApexEvent.NAMESPACE_REGEXP, false);
if (namespace != null) {
if (!namespace.equals(eventDefinition.getNameSpace())) {
*/
private String getHeaderSource(final JsonObject jsonObject, final AxEvent eventDefinition) {
// For source, use the defined source only if the source is not found on the incoming event
- String source = getJsonStringField(jsonObject, ApexEvent.SOURCE_HEADER_FIELD, jsonPars.getSourceAlias(),
+ var source = getJsonStringField(jsonObject, ApexEvent.SOURCE_HEADER_FIELD, jsonPars.getSourceAlias(),
ApexEvent.SOURCE_REGEXP, false);
if (source == null) {
source = eventDefinition.getSource();
*/
private String getHeaderTarget(final JsonObject jsonObject, final AxEvent eventDefinition) {
// For target, use the defined source only if the source is not found on the incoming event
- String target = getJsonStringField(jsonObject, ApexEvent.TARGET_HEADER_FIELD, jsonPars.getTargetAlias(),
+ var target = getJsonStringField(jsonObject, ApexEvent.TARGET_HEADER_FIELD, jsonPars.getTargetAlias(),
ApexEvent.TARGET_REGEXP, false);
if (target == null) {
target = eventDefinition.getTarget();
private void setUpModelMarshallerAndUnmarshaller(ApexParameters apexParameters) throws ApexException {
AxPolicyModel model;
try {
- final String policyModelString = apexParameters.getEngineServiceParameters().getPolicyModel();
+ final var policyModelString = apexParameters.getEngineServiceParameters().getPolicyModel();
model = EngineServiceImpl.createModel(apexParameters.getEngineServiceParameters().getEngineKey(),
policyModelString);
} catch (ApexException e) {
AxContextAlbums existingAlbums, AxTasks existingTasks,
AxPolicies existingPolicies) throws ApexModelException {
- AxContextSchemas axContextSchemas = ModelService.getModel(AxContextSchemas.class);
- AxEvents axEvents = ModelService.getModel(AxEvents.class);
- AxContextAlbums axContextAlbums = ModelService.getModel(AxContextAlbums.class);
- AxTasks axTasks = ModelService.getModel(AxTasks.class);
- AxPolicies axPolicies = ModelService.getModel(AxPolicies.class);
+ var axContextSchemas = ModelService.getModel(AxContextSchemas.class);
+ var axEvents = ModelService.getModel(AxEvents.class);
+ var axContextAlbums = ModelService.getModel(AxContextAlbums.class);
+ var axTasks = ModelService.getModel(AxTasks.class);
+ var axPolicies = ModelService.getModel(AxPolicies.class);
Map<AxArtifactKey, AxContextSchema> newSchemasMap = axContextSchemas.getSchemasMap();
Map<AxArtifactKey, AxEvent> newEventsMap = axEvents.getEventMap();
Map<AxArtifactKey, AxTask> newTasksMap = axTasks.getTaskMap();
Map<AxArtifactKey, AxPolicy> newPoliciesMap = axPolicies.getPolicyMap();
- StringBuilder errorMessage = new StringBuilder();
+ var errorMessage = new StringBuilder();
PolicyModelMerger.checkForDuplicateItem(existingSchemas.getSchemasMap(), newSchemasMap, errorMessage, "schema");
PolicyModelMerger.checkForDuplicateItem(existingEvents.getEventMap(), newEventsMap, errorMessage, "event");
PolicyModelMerger.checkForDuplicateItem(existingAlbums.getAlbumsMap(), newAlbumsMap, errorMessage, "album");
throw new ApexModelException(errorMessage.toString());
}
- AxKeyInformation axKeyInformation = ModelService.getModel(AxKeyInformation.class);
+ var axKeyInformation = ModelService.getModel(AxKeyInformation.class);
Map<AxArtifactKey, AxKeyInfo> newKeyInfoMap = axKeyInformation.getKeyInfoMap();
// Now add all the concepts that must be copied over
newKeyInfoMap.putAll(existingKeyInformation.getKeyInfoMap());
// Apex are
// set up and how they are set up
for (Entry<String, EventHandlerParameters> outputParameters : outputParametersMap.entrySet()) {
- final ApexEventMarshaller marshaller = new ApexEventMarshaller(outputParameters.getKey(),
+ final var marshaller = new ApexEventMarshaller(outputParameters.getKey(),
engineServiceParameters, outputParameters.getValue());
marshaller.init();
apexEngineService.registerActionListener(outputParameters.getKey(), marshaller);
// into Apex
// are set up and how they are set up
for (final Entry<String, EventHandlerParameters> inputParameters : inputParametersMap.entrySet()) {
- final ApexEventUnmarshaller unmarshaller = new ApexEventUnmarshaller(inputParameters.getKey(),
+ final var unmarshaller = new ApexEventUnmarshaller(inputParameters.getKey(),
engineServiceParameters, inputParameters.getValue());
unmarshallerMap.put(inputParameters.getKey(), unmarshaller);
unmarshaller.init(engineServiceHandler);
*/
private static Options apexCustomOptions() {
//@formatter:off
- Options options = new Options();
+ var options = new Options();
options.addOption(Option.builder("h")
.longOpt("help")
.desc("outputs the usage of this command")
* Validate the relative file root.
*/
private void validateRelativeFileRoot() throws ApexException {
- File relativeFileRootPath = new File(relativeFileRoot);
+ var relativeFileRootPath = new File(relativeFileRoot);
if (!relativeFileRootPath.isDirectory()) {
throw new ApexException(RELATIVE_FILE_ROOT + relativeFileRoot + "\" does not exist or is not a directory");
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
while (marshallerThread.isAlive() && !stopOrderedFlag) {
try {
// Take the next event from the queue
- final ApexEvent apexEvent = queue.poll(EVENT_QUEUE_POLL_INTERVAL, TimeUnit.MILLISECONDS);
+ final var apexEvent = queue.poll(EVENT_QUEUE_POLL_INTERVAL, TimeUnit.MILLISECONDS);
if (apexEvent == null) {
continue;
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
final boolean generateExecutionId) throws ApexEventException {
// Push the event onto the queue
if (LOGGER.isTraceEnabled()) {
- String eventString = "onMessage(): event received: " + event.toString();
+ var eventString = "onMessage(): event received: " + event.toString();
LOGGER.trace(eventString);
}
}
// Cache synchronized events that are sent
if (consumerParameters.isPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS)) {
- final SynchronousEventCache synchronousEventCache =
+ final var synchronousEventCache =
(SynchronousEventCache) consumer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS);
synchronousEventCache.cacheSynchronizedEventToApex(apexEvent.getExecutionId(), apexEvent);
}
while (unmarshallerThread.isAlive() && !stopOrderedFlag) {
try {
// Take the next event from the queue
- final ApexEvent apexEvent = queue.poll(EVENT_QUEUE_POLL_INTERVAL, TimeUnit.MILLISECONDS);
+ final var apexEvent = queue.poll(EVENT_QUEUE_POLL_INTERVAL, TimeUnit.MILLISECONDS);
if (apexEvent == null) {
continue;
}
if (LOGGER.isTraceEnabled()) {
- String message = apexEvent.toString();
+ var message = apexEvent.toString();
LOGGER.trace("event received {}", message);
}
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
-import org.onap.policy.apex.core.engine.EngineParameters;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
import org.onap.policy.apex.service.parameters.ApexParameterConstants;
private ApexParameters populateApexParameters(String[] args) throws ApexException {
// Check the arguments
- final ApexCommandLineArguments arguments = new ApexCommandLineArguments();
+ final var arguments = new ApexCommandLineArguments();
try {
// The arguments return a string if there is a message to print and we should exit
final String argumentMessage = arguments.parse(args);
}
aggregatedParameters.getEventInputParameters().putAll(apexParameters.getEventInputParameters());
aggregatedParameters.getEventOutputParameters().putAll(apexParameters.getEventOutputParameters());
- EngineParameters aggregatedEngineParameters =
+ var aggregatedEngineParameters =
aggregatedParameters.getEngineServiceParameters().getEngineParameters();
- EngineParameters engineParameters = apexParameters.getEngineServiceParameters().getEngineParameters();
+ var engineParameters = apexParameters.getEngineServiceParameters().getEngineParameters();
aggregatedEngineParameters.getTaskParameters().addAll(engineParameters.getTaskParameters());
aggregatedEngineParameters.getExecutorParameterMap().putAll(engineParameters.getExecutorParameterMap());
aggregatedEngineParameters.getContextParameters().getSchemaParameters().getSchemaHelperParameterMap()
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
this.periodicEventPeriod = periodicEventPeriod;
// Start engine workers
- for (int engineCounter = 0; engineCounter < threadCount; engineCounter++) {
- final AxArtifactKey engineWorkerKey = new AxArtifactKey(engineServiceKey.getName() + '-' + engineCounter,
+ for (var engineCounter = 0; engineCounter < threadCount; engineCounter++) {
+ final var engineWorkerKey = new AxArtifactKey(engineServiceKey.getName() + '-' + engineCounter,
engineServiceKey.getVersion());
engineWorkerMap.put(engineWorkerKey, new EngineWorker(engineWorkerKey, queue, atFactory));
LOGGER.info("Created apex engine {} .", engineWorkerKey.getId());
LOGGER.entry(apexEventListener);
if (listenerName == null) {
- String message = "listener name must be specified and may not be null";
+ var message = "listener name must be specified and may not be null";
LOGGER.warn(message);
return;
}
if (apexEventListener == null) {
- String message = "apex event listener must be specified and may not be null";
+ var message = "apex event listener must be specified and may not be null";
LOGGER.warn(message);
return;
}
}
// Update the engines
- boolean isSubsequentInstance = false;
+ var isSubsequentInstance = false;
for (final Entry<AxArtifactKey, EngineWorker> engineWorkerEntry : engineWorkerMap.entrySet()) {
LOGGER.info("Registering apex model on engine {}", engineWorkerEntry.getKey().getId());
- EngineWorker engineWorker = engineWorkerEntry.getValue();
+ var engineWorker = engineWorkerEntry.getValue();
if (isSubsequentInstance) {
// set subsequentInstance flag as true if the current engine worker instance is not the first one
// first engine instance will have this flag as false
ThreadUtilities.sleep(ENGINE_SERVICE_STOP_START_WAIT_INTERVAL);
}
// Check if all engines are running
- final StringBuilder notRunningEngineIdBuilder = new StringBuilder();
+ final var notRunningEngineIdBuilder = new StringBuilder();
for (final Entry<AxArtifactKey, EngineWorker> engineWorkerEntry : engineWorkerMap.entrySet()) {
if (engineWorkerEntry.getValue().getState() != AxEngineState.READY
&& engineWorkerEntry.getValue().getState() != AxEngineState.EXECUTING) {
}
}
if (notRunningEngineIdBuilder.length() > 0) {
- final String errorString = "engine start error on model update on engine service with key "
+ final var errorString = "engine start error on model update on engine service with key "
+ incomingEngineServiceKey.getId() + ", engines not running are: "
+ notRunningEngineIdBuilder.toString().trim();
LOGGER.warn(errorString);
ThreadUtilities.sleep(ENGINE_SERVICE_STOP_START_WAIT_INTERVAL);
}
// Check if all engines are stopped
- final StringBuilder notStoppedEngineIdBuilder = new StringBuilder();
+ final var notStoppedEngineIdBuilder = new StringBuilder();
for (final Entry<AxArtifactKey, EngineWorker> engineWorkerEntry : engineWorkerMap.entrySet()) {
if (engineWorkerEntry.getValue().getState() != AxEngineState.STOPPED) {
notStoppedEngineIdBuilder.append(engineWorkerEntry.getKey().getId());
}
}
if (notStoppedEngineIdBuilder.length() > 0) {
- final String errorString = "cannot update model on engine service with key "
+ final var errorString = "cannot update model on engine service with key "
+ incomingEngineServiceKey.getId() + ", engines not stopped after " + MAX_STOP_WAIT_TIME
+ "ms are: " + notStoppedEngineIdBuilder.toString().trim();
LOGGER.warn(errorString);
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
package org.onap.policy.apex.service.parameters;
-import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
parseConfigAndModel(toscaPolicyFilePath);
// Register the adapters for our carrier technologies and event protocols with GSON
// @formatter:off
- final Gson gson = new GsonBuilder()
+ final var gson = new GsonBuilder()
.registerTypeAdapter(EngineParameters.class,
new EngineServiceParametersJsonAdapter())
.registerTypeAdapter(CarrierTechnologyParameters.class,
private void parseConfigAndModel(final String toscaPolicyFilePath) throws ApexException {
policyModel = null;
apexConfig = null;
- final StandardCoder standardCoder = new StandardCoder();
- JsonObject apexConfigJsonObject = new JsonObject();
+ final var standardCoder = new StandardCoder();
+ var apexConfigJsonObject = new JsonObject();
try {
- ToscaServiceTemplate toscaServiceTemplate = standardCoder
+ var toscaServiceTemplate = standardCoder
.decode(Files.readString(Paths.get(toscaPolicyFilePath)), ToscaServiceTemplate.class);
for (Entry<String, Object> property : toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0)
.entrySet().iterator().next().getValue().getProperties().entrySet()) {
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return null;
}
- BeanValidationResult result = new BeanValidationResult(JAVA_PROPERTIES, javaProperties);
- int item = 0;
+ var result = new BeanValidationResult(JAVA_PROPERTIES, javaProperties);
+ var item = 0;
for (String[] javaProperty : javaProperties) {
final String label = "entry " + (item++);
final List<String> value = (javaProperty == null ? null : Arrays.asList(javaProperty));
- BeanValidationResult result2 = new BeanValidationResult(label, value);
+ var result2 = new BeanValidationResult(label, value);
if (javaProperty == null) {
// note: add to result, not result2
@Test
public void getStartDelay() {
- assertThat(parameters.getStartDelay()).isEqualTo(0L);
+ assertThat(parameters.getStartDelay()).isZero();
}
@Test
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
ModelService.clear();
}
- @Test
- public void testEngineServiceImplSanity() throws ApexException {
- assertThatThrownBy(() -> EngineServiceImpl.create(null)).isInstanceOf(ApexException.class)
- .hasMessage("engine service configuration parameters are null");
+ private EngineServiceParameters makeConfig() {
EngineServiceParameters config = new EngineServiceParameters();
config.setInstanceCount(0);
- assertThatThrownBy(() -> EngineServiceImpl.create(config)).isInstanceOf(ApexException.class)
- .hasMessageContaining("Invalid engine service configuration parameters");
-
config.setId(123);
config.setEngineKey(new AxArtifactKey("Engine", "0.0.1"));
config.setInstanceCount(1);
config.setPolicyModel("policyModelContent");
+ return config;
+ }
+
+ @Test
+ public void testEngineServiceImplSanity() throws ApexException {
+ assertThatThrownBy(() -> EngineServiceImpl.create(null)).isInstanceOf(ApexException.class)
+ .hasMessage("engine service configuration parameters are null");
+
+ EngineServiceParameters invalidConfig = new EngineServiceParameters();
+ invalidConfig.setInstanceCount(0);
+ assertThatThrownBy(() -> EngineServiceImpl.create(invalidConfig)).isInstanceOf(ApexException.class)
+ .hasMessageContaining("Invalid engine service configuration parameters");
+ EngineServiceParameters config = makeConfig();
EngineServiceImpl esImpl = EngineServiceImpl.create(config);
assertEquals("Engine:0.0.1", esImpl.getKey().getId());
assertTrue(esImpl.isStopped(null));
assertTrue(esImpl.isStopped(new AxArtifactKey("DummyKey", "0.0.1")));
assertTrue(esImpl.isStopped(esImpl.getEngineKeys().iterator().next()));
+ }
+ @Test
+ public void testEngineServiceExceptions() throws ApexException {
+ EngineServiceParameters config = makeConfig();
+ EngineServiceImpl esImpl = EngineServiceImpl.create(config);
assertThatThrownBy(() -> esImpl.start(null)).isInstanceOf(ApexException.class)
.hasMessage("engine key must be specified and may not be null");
@Test
public void testApexImplModelWIthModel() throws ApexException {
- EngineServiceParameters config = new EngineServiceParameters();
- config.setId(123);
- config.setEngineKey(new AxArtifactKey("Engine", "0.0.1"));
- config.setInstanceCount(1);
- config.setPolicyModel("policyModelContent");
+ EngineServiceParameters config = makeConfig();
EngineServiceImpl esImpl = EngineServiceImpl.create(config);
assertEquals("Engine:0.0.1", esImpl.getKey().getId());