2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.service.engine.runtime.impl;
23 import java.io.ByteArrayInputStream;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.LinkedHashMap;
28 import java.util.Map.Entry;
29 import java.util.concurrent.BlockingQueue;
30 import java.util.concurrent.LinkedBlockingQueue;
32 import org.onap.policy.apex.context.ContextException;
33 import org.onap.policy.apex.core.infrastructure.threading.ApplicationThreadFactory;
34 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
35 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
37 import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
38 import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
39 import org.onap.policy.apex.model.basicmodel.service.ModelService;
40 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
41 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
42 import org.onap.policy.apex.service.engine.event.ApexEvent;
43 import org.onap.policy.apex.service.engine.event.ApexPeriodicEventGenerator;
44 import org.onap.policy.apex.service.engine.runtime.ApexEventListener;
45 import org.onap.policy.apex.service.engine.runtime.EngineService;
46 import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface;
47 import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters;
48 import org.onap.policy.common.parameters.GroupValidationResult;
49 import org.slf4j.ext.XLogger;
50 import org.slf4j.ext.XLoggerFactory;
53 * The Class EngineServiceImpl controls a thread pool that runs a set of Apex engine workers, each of which is running
54 * on an identical Apex model. This class handles the management of the engine worker instances, their threads, and
55 * event forwarding to and from the engine workers.
57 * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com)
58 * @author Liam Fallon (liam.fallon@ericsson.com)
59 * @author John Keeney (john.keeney@ericsson.com)
61 public final class EngineServiceImpl implements EngineService, EngineServiceEventInterface {
62 // Logging static variables
63 private static final XLogger LOGGER = XLoggerFactory.getXLogger(EngineServiceImpl.class);
64 private static final boolean DEBUG_ENABLED = LOGGER.isDebugEnabled();
66 // Recurring string constants
67 private static final String ENGINE_KEY_PREAMBLE = "engine with key ";
68 private static final String NOT_FOUND_SUFFIX = " not found in engine service";
69 private static final String ENGINE_KEY_NOT_SPECIFIED = "engine key must be specified and may not be null";
71 // Constants for timing
72 private static final long MAX_START_WAIT_TIME = 5000; // 5 seconds
73 private static final long MAX_STOP_WAIT_TIME = 5000; // 5 seconds
74 private static final int ENGINE_SERVICE_STOP_START_WAIT_INTERVAL = 200;
76 // The ID of this engine
77 private AxArtifactKey engineServiceKey = null;
79 // The Apex engine workers this engine service is handling
80 private final Map<AxArtifactKey, EngineService> engineWorkerMap = Collections
81 .synchronizedMap(new LinkedHashMap<AxArtifactKey, EngineService>());
83 // Event queue for events being sent into the Apex engines, it used by all engines within a
85 private final BlockingQueue<ApexEvent> queue = new LinkedBlockingQueue<>();
87 // Thread factory for thread management
88 private final ApplicationThreadFactory atFactory = new ApplicationThreadFactory("apex-engine-service", 512);
90 // Periodic event generator and its period in milliseconds
91 private ApexPeriodicEventGenerator periodicEventGenerator = null;
92 private long periodicEventPeriod;
95 * This constructor instantiates engine workers and adds them to the set of engine workers to be managed. The
96 * constructor is private to prevent subclassing.
98 * @param engineServiceKey the engine service key
99 * @param threadCount the thread count, the number of engine workers to start
100 * @param periodicEventPeriod the period in milliseconds at which periodic events are generated
101 * @throws ApexException on worker instantiation errors
103 private EngineServiceImpl(final AxArtifactKey engineServiceKey, final int threadCount,
104 final long periodicEventPeriod) {
105 LOGGER.entry(engineServiceKey, threadCount);
107 this.engineServiceKey = engineServiceKey;
108 this.periodicEventPeriod = periodicEventPeriod;
110 // Start engine workers
111 for (int engineCounter = 0; engineCounter < threadCount; engineCounter++) {
112 final AxArtifactKey engineWorkerKey = new AxArtifactKey(engineServiceKey.getName() + '-' + engineCounter,
113 engineServiceKey.getVersion());
114 engineWorkerMap.put(engineWorkerKey, new EngineWorker(engineWorkerKey, queue, atFactory));
115 LOGGER.info("Created apex engine {} .", engineWorkerKey.getId());
118 LOGGER.info("APEX service created.");
123 * Create an Apex Engine Service instance. This method does not load the policy so
124 * {@link #updateModel(AxArtifactKey, AxPolicyModel, boolean)} or
125 * {@link #updateModel(AxArtifactKey, AxPolicyModel, boolean)} must be used to load a model. This method does not
126 * start the Engine Service so {@link #start(AxArtifactKey)} or {@link #startAll()} must be used.
128 * @param config the configuration for this Apex Engine Service.
129 * @return the Engine Service instance
130 * @throws ApexException on worker instantiation errors
132 public static EngineServiceImpl create(final EngineServiceParameters config) throws ApexException {
133 if (config == null) {
134 LOGGER.warn("Engine service configuration parameters is null");
135 throw new ApexException("engine service configuration parameters are null");
138 final GroupValidationResult validation = config.validate();
139 if (!validation.isValid()) {
140 LOGGER.warn("Invalid engine service configuration parameters: {}" + validation.getResult());
141 throw new ApexException("Invalid engine service configuration parameters: " + validation);
144 final AxArtifactKey engineServiceKey = config.getEngineKey();
145 final int threadCount = config.getInstanceCount();
147 return new EngineServiceImpl(engineServiceKey, threadCount, config.getPeriodicEventPeriod());
153 * @see org.onap.policy.apex.service.engine.runtime.EngineService#registerActionListener(java.lang. String,
154 * org.onap.policy.apex.service.engine.runtime.ApexEventListener)
157 public void registerActionListener(final String listenerName, final ApexEventListener apexEventListener) {
158 LOGGER.entry(apexEventListener);
160 if (listenerName == null) {
161 String message = "listener name must be specified and may not be null";
162 LOGGER.warn(message);
166 if (apexEventListener == null) {
167 String message = "apex event listener must be specified and may not be null";
168 LOGGER.warn(message);
172 // Register the Apex event listener on all engine workers, each worker will return Apex
173 // events to the listening application
174 for (final EngineService engineWorker : engineWorkerMap.values()) {
175 engineWorker.registerActionListener(listenerName, apexEventListener);
178 LOGGER.info("Added the action listener to the engine");
185 * @see org.onap.policy.apex.service.engine.runtime.EngineService#deregisterActionListener(java.lang. String)
188 public void deregisterActionListener(final String listenerName) {
189 LOGGER.entry(listenerName);
191 // Register the Apex event listener on all engine workers, each worker will return Apex
192 // events to the listening application
193 for (final EngineService engineWorker : engineWorkerMap.values()) {
194 engineWorker.deregisterActionListener(listenerName);
197 LOGGER.info("Removed the action listener from the engine");
204 * @see org.onap.policy.apex.service.engine.runtime.EngineService#getEngineServiceEventInterface()
207 public EngineServiceEventInterface getEngineServiceEventInterface() {
214 * @see org.onap.policy.apex.service.engine.runtime.EngineService#getKey()
217 public AxArtifactKey getKey() {
218 return engineServiceKey;
224 * @see org.onap.policy.apex.service.engine.runtime.EngineService#getInfo()
227 public Collection<AxArtifactKey> getEngineKeys() {
228 return engineWorkerMap.keySet();
234 * @see org.onap.policy.apex.service.engine.runtime.EngineService#getApexModelKey()
237 public AxArtifactKey getApexModelKey() {
238 if (engineWorkerMap.size() == 0) {
242 return engineWorkerMap.entrySet().iterator().next().getValue().getApexModelKey();
248 * @see org.onap.policy.apex.service.engine.runtime.EngineService#updateModel(org.onap.policy.apex.model.
249 * basicmodel.concepts.AxArtifactKey, java.lang.String, boolean)
252 public void updateModel(final AxArtifactKey incomingEngineServiceKey, final String apexModelString,
253 final boolean forceFlag) throws ApexException {
254 // Check if the engine service key specified is sane
255 if (incomingEngineServiceKey == null) {
256 String message = ENGINE_KEY_NOT_SPECIFIED;
257 LOGGER.warn(message);
258 throw new ApexException(message);
261 // Check if the Apex model specified is sane
262 if (apexModelString == null || apexModelString.trim().length() == 0) {
263 String emptyModelMessage = "model for updating engine service with key "
264 + incomingEngineServiceKey.getId() + " is empty";
265 LOGGER.warn(emptyModelMessage);
266 throw new ApexException(emptyModelMessage);
269 // Read the Apex model into memory using the Apex Model Reader
270 AxPolicyModel apexPolicyModel = null;
272 final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
273 apexPolicyModel = modelReader.read(new ByteArrayInputStream(apexModelString.getBytes()));
274 } catch (final ApexModelException e) {
275 String message = "failed to unmarshal the apex model on engine service " + incomingEngineServiceKey.getId();
276 LOGGER.error(message, e);
277 throw new ApexException(message, e);
281 updateModel(incomingEngineServiceKey, apexPolicyModel, forceFlag);
289 * @see org.onap.policy.apex.service.engine.runtime.EngineService#updateModel(org.onap.policy.apex.model.
290 * basicmodel.concepts.AxArtifactKey, org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel, boolean)
293 public void updateModel(final AxArtifactKey incomingEngineServiceKey, final AxPolicyModel apexModel,
294 final boolean forceFlag) throws ApexException {
295 LOGGER.entry(incomingEngineServiceKey);
297 // Check if the engine service key specified is sane
298 if (incomingEngineServiceKey == null) {
299 String message = ENGINE_KEY_NOT_SPECIFIED;
300 LOGGER.warn(message);
301 throw new ApexException(message);
304 // Check if the Apex model specified is sane
305 if (apexModel == null) {
306 LOGGER.warn("model for updating on engine service with key " + incomingEngineServiceKey.getId()
308 throw new ApexException("model for updating on engine service with key " + incomingEngineServiceKey.getId()
312 // Check if the key on the update request is correct
313 if (!this.engineServiceKey.equals(incomingEngineServiceKey)) {
314 LOGGER.warn("engine service key " + incomingEngineServiceKey.getId() + " does not match the key"
315 + engineServiceKey.getId() + " of this engine service");
316 throw new ApexException("engine service key " + incomingEngineServiceKey.getId() + " does not match the key"
317 + engineServiceKey.getId() + " of this engine service");
320 // Check model compatibility
321 if (ModelService.existsModel(AxPolicyModel.class)) {
322 // The current policy model may or may not be defined
323 final AxPolicyModel currentModel = ModelService.getModel(AxPolicyModel.class);
324 if (!currentModel.getKey().isCompatible(apexModel.getKey())) {
325 handleIncompatibility(apexModel, forceFlag, currentModel);
329 executeModelUpdate(incomingEngineServiceKey, apexModel, forceFlag);
335 * Execute the model update on the engine instances.
337 * @param incomingEngineServiceKey the engine service key to update
338 * @param apexModel the model to update the engines with
339 * @param forceFlag if true, ignore compatibility problems
340 * @throws ApexException on model update errors
342 private void executeModelUpdate(final AxArtifactKey incomingEngineServiceKey, final AxPolicyModel apexModel,
343 final boolean forceFlag) throws ApexException {
346 stopEngines(incomingEngineServiceKey);
349 // Update the engines
350 for (final Entry<AxArtifactKey, EngineService> engineWorkerEntry : engineWorkerMap.entrySet()) {
351 LOGGER.info("Registering apex model on engine {}", engineWorkerEntry.getKey().getId());
352 engineWorkerEntry.getValue().updateModel(engineWorkerEntry.getKey(), apexModel, forceFlag);
355 // start all engines on this engine service if it was not stopped before the update
357 final long starttime = System.currentTimeMillis();
358 while (!isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT_TIME) {
359 ThreadUtilities.sleep(ENGINE_SERVICE_STOP_START_WAIT_INTERVAL);
361 // Check if all engines are running
362 final StringBuilder notRunningEngineIdBuilder = new StringBuilder();
363 for (final Entry<AxArtifactKey, EngineService> engineWorkerEntry : engineWorkerMap.entrySet()) {
364 if (engineWorkerEntry.getValue().getState() != AxEngineState.READY
365 && engineWorkerEntry.getValue().getState() != AxEngineState.EXECUTING) {
366 notRunningEngineIdBuilder.append(engineWorkerEntry.getKey().getId());
367 notRunningEngineIdBuilder.append('(');
368 notRunningEngineIdBuilder.append(engineWorkerEntry.getValue().getState());
369 notRunningEngineIdBuilder.append(") ");
372 if (notRunningEngineIdBuilder.length() > 0) {
373 final String errorString = "engine start error on model update on engine service with key "
374 + incomingEngineServiceKey.getId() + ", engines not running are: "
375 + notRunningEngineIdBuilder.toString().trim();
376 LOGGER.warn(errorString);
377 throw new ApexException(errorString);
382 * Stop engines for a model update.
383 * @param incomingEngineServiceKey the engine service key for the engines that are to be stopped
384 * @throws ApexException on errors stopping engines
386 private void stopEngines(final AxArtifactKey incomingEngineServiceKey) throws ApexException {
387 // Stop all engines on this engine service
389 final long stoptime = System.currentTimeMillis();
390 while (!isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT_TIME) {
391 ThreadUtilities.sleep(ENGINE_SERVICE_STOP_START_WAIT_INTERVAL);
393 // Check if all engines are stopped
394 final StringBuilder notStoppedEngineIdBuilder = new StringBuilder();
395 for (final Entry<AxArtifactKey, EngineService> engineWorkerEntry : engineWorkerMap.entrySet()) {
396 if (engineWorkerEntry.getValue().getState() != AxEngineState.STOPPED) {
397 notStoppedEngineIdBuilder.append(engineWorkerEntry.getKey().getId());
398 notStoppedEngineIdBuilder.append('(');
399 notStoppedEngineIdBuilder.append(engineWorkerEntry.getValue().getState());
400 notStoppedEngineIdBuilder.append(") ");
403 if (notStoppedEngineIdBuilder.length() > 0) {
404 final String errorString = "cannot update model on engine service with key "
405 + incomingEngineServiceKey.getId() + ", engines not stopped after " + MAX_STOP_WAIT_TIME
406 + "ms are: " + notStoppedEngineIdBuilder.toString().trim();
407 LOGGER.warn(errorString);
408 throw new ApexException(errorString);
413 * Issue compatibility warning or error message.
414 * @param apexModel The model name
415 * @param forceFlag true if we are forcing the update
416 * @param currentModel the existing model that is loaded
417 * @throws ContextException on compatibility errors
419 private void handleIncompatibility(final AxPolicyModel apexModel, final boolean forceFlag,
420 final AxPolicyModel currentModel) throws ContextException {
422 LOGGER.warn("apex model update forced, supplied model with key \"" + apexModel.getKey().getId()
423 + "\" is not a compatible model update from the existing engine model with key \""
424 + currentModel.getKey().getId() + "\"");
426 throw new ContextException("apex model update failed, supplied model with key \""
427 + apexModel.getKey().getId()
428 + "\" is not a compatible model update from the existing engine model with key \""
429 + currentModel.getKey().getId() + "\"");
436 * @see org.onap.policy.apex.service.engine.runtime.EngineService#getState()
439 public AxEngineState getState() {
440 // If one worker is running then we are running, otherwise we are stopped
441 for (final EngineService engine : engineWorkerMap.values()) {
442 if (engine.getState() != AxEngineState.STOPPED) {
443 return AxEngineState.EXECUTING;
447 return AxEngineState.STOPPED;
453 * @see org.onap.policy.apex.service.engine.runtime.EngineService#startAll()
456 public void startAll() throws ApexException {
457 for (final EngineService engine : engineWorkerMap.values()) {
458 start(engine.getKey());
465 * @see org.onap.policy.apex.service.engine.runtime.EngineService#start(org.onap.policy.apex.core.model.
466 * concepts.AxArtifactKey)
469 public void start(final AxArtifactKey engineKey) throws ApexException {
470 LOGGER.entry(engineKey);
472 if (engineKey == null) {
473 String message = ENGINE_KEY_NOT_SPECIFIED;
474 LOGGER.warn(message);
475 throw new ApexException(message);
478 // Check if we have this key on our map
479 if (!engineWorkerMap.containsKey(engineKey)) {
480 String message = ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX;
481 LOGGER.warn(message);
482 throw new ApexException(message);
486 engineWorkerMap.get(engineKey).start(engineKey);
488 // Check if periodic events should be turned on
489 if (periodicEventPeriod > 0) {
490 startPeriodicEvents(periodicEventPeriod);
493 LOGGER.exit(engineKey);
499 * @see org.onap.policy.apex.service.engine.runtime.EngineService#stop()
502 public void stop() throws ApexException {
505 if (periodicEventGenerator != null) {
506 periodicEventGenerator.cancel();
507 periodicEventGenerator = null;
511 for (final EngineService engine : engineWorkerMap.values()) {
512 if (engine.getState() != AxEngineState.STOPPED) {
523 * @see org.onap.policy.apex.service.engine.runtime.EngineService#stop(org.onap.policy.apex.core.model.
524 * concepts.AxArtifactKey)
527 public void stop(final AxArtifactKey engineKey) throws ApexException {
528 LOGGER.entry(engineKey);
530 if (engineKey == null) {
531 String message = ENGINE_KEY_NOT_SPECIFIED;
532 LOGGER.warn(message);
533 throw new ApexException(message);
536 // Check if we have this key on our map
537 if (!engineWorkerMap.containsKey(engineKey)) {
538 LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
539 throw new ApexException(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
543 engineWorkerMap.get(engineKey).stop(engineKey);
545 LOGGER.exit(engineKey);
551 * @see org.onap.policy.apex.service.engine.runtime.EngineService#clear()
554 public void clear() throws ApexException {
558 for (final EngineService engine : engineWorkerMap.values()) {
559 if (engine.getState() == AxEngineState.STOPPED) {
570 * @see org.onap.policy.apex.service.engine.runtime.EngineService#clear(org.onap.policy.apex.core.model.
571 * concepts.AxArtifactKey)
574 public void clear(final AxArtifactKey engineKey) throws ApexException {
575 LOGGER.entry(engineKey);
577 if (engineKey == null) {
578 String message = ENGINE_KEY_NOT_SPECIFIED;
579 LOGGER.warn(message);
580 throw new ApexException(message);
583 // Check if we have this key on our map
584 if (!engineWorkerMap.containsKey(engineKey)) {
585 LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
586 throw new ApexException(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
590 if (engineWorkerMap.get(engineKey).getState() == AxEngineState.STOPPED) {
591 engineWorkerMap.get(engineKey).stop(engineKey);
594 LOGGER.exit(engineKey);
598 * Check all engines are started.
600 * @return true if <i>all</i> engines are started
601 * @see org.onap.policy.apex.service.engine.runtime.EngineService#isStarted()
604 public boolean isStarted() {
605 for (final EngineService engine : engineWorkerMap.values()) {
606 if (!engine.isStarted()) {
616 * @see org.onap.policy.apex.service.engine.runtime.EngineService#isStarted(org.onap.policy.apex.model.
617 * basicmodel.concepts.AxArtifactKey)
620 public boolean isStarted(final AxArtifactKey engineKey) {
621 if (engineKey == null) {
622 String message = ENGINE_KEY_NOT_SPECIFIED;
623 LOGGER.warn(message);
627 // Check if we have this key on our map
628 if (!engineWorkerMap.containsKey(engineKey)) {
629 LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
632 return engineWorkerMap.get(engineKey).isStarted();
636 * Check all engines are stopped.
638 * @return true if <i>all</i> engines are stopped
639 * @see org.onap.policy.apex.service.engine.runtime.EngineService#isStopped()
642 public boolean isStopped() {
643 for (final EngineService engine : engineWorkerMap.values()) {
644 if (!engine.isStopped()) {
654 * @see org.onap.policy.apex.service.engine.runtime.EngineService#isStopped(org.onap.policy.apex.model.
655 * basicmodel.concepts.AxArtifactKey)
658 public boolean isStopped(final AxArtifactKey engineKey) {
659 if (engineKey == null) {
660 String message = ENGINE_KEY_NOT_SPECIFIED;
661 LOGGER.warn(message);
665 // Check if we have this key on our map
666 if (!engineWorkerMap.containsKey(engineKey)) {
667 LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
670 return engineWorkerMap.get(engineKey).isStopped();
676 * @see org.onap.policy.apex.service.engine.runtime.EngineService#startPeriodicEvents(long)
679 public void startPeriodicEvents(final long period) throws ApexException {
680 // Check if periodic events are already started
681 if (periodicEventGenerator != null) {
682 String message = "Peiodic event geneation already running on engine " + engineServiceKey.getId() + ", "
683 + periodicEventGenerator.toString();
684 LOGGER.warn(message);
685 throw new ApexException(message);
688 // Set up periodic event execution, its a Java Timer/TimerTask
689 periodicEventGenerator = new ApexPeriodicEventGenerator(this.getEngineServiceEventInterface(), period);
691 // Record the periodic event period because it may have been set over the Web Socket admin
693 this.periodicEventPeriod = period;
699 * @see org.onap.policy.apex.service.engine.runtime.EngineService#stopPeriodicEvents()
702 public void stopPeriodicEvents() throws ApexException {
703 // Check if periodic events are already started
704 if (periodicEventGenerator == null) {
705 LOGGER.warn("Peiodic event geneation not running on engine " + engineServiceKey.getId());
706 throw new ApexException("Peiodic event geneation not running on engine " + engineServiceKey.getId());
709 // Stop periodic events
710 periodicEventGenerator.cancel();
711 periodicEventGenerator = null;
712 periodicEventPeriod = 0;
718 * @see org.onap.policy.apex.service.engine.runtime.EngineService#getStatus(org.onap.policy.apex.core.model
719 * .concepts.AxArtifactKey)
722 public String getStatus(final AxArtifactKey engineKey) throws ApexException {
723 if (engineKey == null) {
724 String message = ENGINE_KEY_NOT_SPECIFIED;
725 LOGGER.warn(message);
726 throw new ApexException(message);
729 // Check if we have this key on our map
730 if (!engineWorkerMap.containsKey(engineKey)) {
731 LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
732 throw new ApexException(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
735 // Return the information for this worker
736 return engineWorkerMap.get(engineKey).getStatus(engineKey);
742 * @see org.onap.policy.apex.service.engine.runtime.EngineService#getRuntimeInfo(org.onap.policy.apex.core.
743 * model.concepts.AxArtifactKey)
746 public String getRuntimeInfo(final AxArtifactKey engineKey) throws ApexException {
747 if (engineKey == null) {
748 String message = ENGINE_KEY_NOT_SPECIFIED;
749 LOGGER.warn(message);
750 throw new ApexException(message);
753 // Check if we have this key on our map
754 if (!engineWorkerMap.containsKey(engineKey)) {
755 LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
756 throw new ApexException(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
759 // Return the information for this worker
760 return engineWorkerMap.get(engineKey).getRuntimeInfo(engineKey);
766 * @see org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface#sendEvent(org.onap.policy.
767 * apex.service.engine.event.ApexEvent)
770 public void sendEvent(final ApexEvent event) {
772 LOGGER.warn("Null events cannot be processed, in engine service " + engineServiceKey.getId());
776 // Check if we have this key on our map
777 if (getState() == AxEngineState.STOPPED) {
778 LOGGER.warn("event " + event.getName() + " not processed, no engines on engine service "
779 + engineServiceKey.getId() + " are running");
784 LOGGER.debug("Forwarding Apex Event {} to the processing engine", event);
787 // Add the incoming event to the queue, the next available worker will process it