ef17a8eab9a5a8f733261a3f09d62b095f2e2c7b
[policy/apex-pdp.git] /
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.service.engine.runtime;
22
23 import java.util.Collection;
24
25 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
26 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
27 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
28 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
29
30 /**
31  * The administration interface for Apex engine users. Apex engine implementations expose this
32  * interface and external users use it to manage Apex engines.
33  *
34  * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com)
35  */
36 public interface EngineService {
37     /**
38      * A method to attach a listener to the engine.
39      *
40      * @param listenerName a unique name for the listener
41      * @param listener is a callback interface to the engine.
42      */
43     void registerActionListener(String listenerName, ApexEventListener listener);
44
45     /**
46      * A method to detach a listener from the engine.
47      *
48      * @param listenerName the unique name of the listener to deregister
49      */
50     void deregisterActionListener(String listenerName);
51
52     /**
53      * This method gets the current runtime information for the running Apex engines.
54      *
55      * @return the engine service event interface
56      */
57     EngineServiceEventInterface getEngineServiceEventInterface();
58
59     /**
60      * Gets the key of the engine service or worker.
61      *
62      * @return the key
63      */
64     AxArtifactKey getKey();
65
66     /**
67      * This method gets the keys of the engines on the engine service.
68      *
69      * @return the engine keys
70      */
71     Collection<AxArtifactKey> getEngineKeys();
72
73     /**
74      * The the key of the Apex model the engine service is running on.
75      *
76      * @return the Apex model key
77      */
78     AxArtifactKey getApexModelKey();
79
80     /**
81      * This method updates the Apex model on Apex execution engines using a string representation of
82      * the model.
83      *
84      * @param engineServiceKey The key of the engine service on which to update the model
85      * @param apexModelString the apex model string
86      * @param forceFlag if true, model updates will be executed even on incompatible models
87      *        (different model names) and versions (different model version)
88      * @throws ApexException on model update errors
89      */
90     void updateModel(AxArtifactKey engineServiceKey, String apexModelString, boolean forceFlag) throws ApexException;
91
92     /**
93      * This method updates the Apex model on Apex execution engines using a policy model as input.
94      *
95      * @param engineServiceKey The key of the engine service on which to update the model
96      * @param apexModel is a policy definition model
97      * @param forceFlag if true, model updates will be executed even on incompatible models
98      *        (different model names) and versions (different model version)
99      * @throws ApexException on model update errors
100      */
101     void updateModel(AxArtifactKey engineServiceKey, AxPolicyModel apexModel, boolean forceFlag) throws ApexException;
102
103     /**
104      * Return the state of an engine service or engine.
105      *
106      * @return The engine service or engine state
107      */
108     AxEngineState getState();
109
110     /**
111      * This method starts all Apex engines in the engine service.
112      *
113      * @throws ApexException on start errors
114      */
115     void startAll() throws ApexException;
116
117     /**
118      * This method starts an Apex engine in the engine service.
119      *
120      * @param engineKey The key of the Apex engine to start
121      * @throws ApexException on start errors
122      */
123     void start(AxArtifactKey engineKey) throws ApexException;
124
125     /**
126      * This method stops all Apex engines in the engine service.
127      *
128      * @throws ApexException on stop errors
129      */
130     void stop() throws ApexException;
131
132     /**
133      * This method stops an Apex engine in the engine service.
134      *
135      * @param engineKey The key of the Apex engine to stop
136      * @throws ApexException on stop errors
137      */
138     void stop(AxArtifactKey engineKey) throws ApexException;
139
140     /**
141      * This method clears and uninitializes all Apex engines in the engine service.
142      *
143      * @throws ApexException on clear errors
144      */
145     void clear() throws ApexException;
146
147     /**
148      * This method clears and uninitializes an Apex engine in the engine service.
149      *
150      * @param engineKey The key of the Apex engine to clear
151      * @throws ApexException on clear errors
152      */
153     void clear(AxArtifactKey engineKey) throws ApexException;
154
155     /**
156      * This method checks if all Apex engines in the engine service are started.
157      * 
158      * <p>Note: an engine can be both not stopped and not started, for example, when it is starting or
159      * stopping
160      *
161      * @return true if all Apex engines in the engine service are started.
162      */
163     boolean isStarted();
164
165     /**
166      * This method checks if an Apex engine in the engine service is started.
167      * 
168      * <p>Note: an engine can be both not stopped and not started, for example, when it is starting or
169      * stopping
170      *
171      * @param engineKey The key of the Apex engine to check
172      * @return true if all Apex engines in the engine service are started.
173      */
174     boolean isStarted(AxArtifactKey engineKey);
175
176     /**
177      * This method checks if all Apex engines in the engine service are stopped.
178      * 
179      * <p>Note: an engine can be both not stopped and not started, for example, when it is starting or
180      * stopping
181      *
182      * @return true if all Apex engines in the engine service are stopped.
183      */
184     boolean isStopped();
185
186     /**
187      * This method checks if an Apex engine in the engine service is stopped.
188      * 
189      * <p>Note: an engine can be both not stopped and not started, for example, when it is starting or
190      * stopping
191      *
192      * @param engineKey The key of the Apex engine to check
193      * @return true if all Apex engines in the engine service are stopped.
194      */
195     boolean isStopped(AxArtifactKey engineKey);
196
197     /**
198      * This method starts periodic event generation.
199      *
200      * @param period The period in milliseconds between periodic events
201      * @throws ApexException On periodic event start errors
202      */
203     void startPeriodicEvents(long period) throws ApexException;
204
205     /**
206      * This method stops periodic event generation.
207      *
208      * @throws ApexException On periodic event stop errors
209      */
210     void stopPeriodicEvents() throws ApexException;
211
212     /**
213      * This method gets the status of an Apex engine in the engine service.
214      *
215      * @param engineKey the engine key
216      * @return the engine runtime information
217      * @throws ApexException on status read errors
218      */
219     String getStatus(AxArtifactKey engineKey) throws ApexException;
220
221     /**
222      * This method gets the runtime information of all Apex engines in the engine service.
223      *
224      * @param engineKey the engine key
225      * @return the engine runtime information
226      * @throws ApexException on runtime information read errors
227      */
228     String getRuntimeInfo(AxArtifactKey engineKey) throws ApexException;
229 }