aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
blob: 75e7c74ae17ca1fc32eb2f117f40e296f6af98b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/*
 * ============LICENSE_START=======================================================
 * ONAP
 * ================================================================================
 * Copyright (C) 2017-2022 AT&T Intellectual Property. 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.
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.drools.system;

import java.util.List;
import java.util.Properties;
import java.util.concurrent.ScheduledExecutorService;
import org.onap.policy.common.capabilities.Lockable;
import org.onap.policy.common.capabilities.Startable;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicListener;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.drools.core.lock.Lock;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.features.PolicyEngineFeatureApi;
import org.onap.policy.drools.metrics.Metric;
import org.onap.policy.drools.policies.DomainMaker;
import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
import org.onap.policy.drools.stats.PolicyStatsManager;

/**
 * Policy Engine, the top abstraction for the Drools PDP Policy Engine. It abstracts away a Drools
 * PDP Engine from management purposes. This is the best place to looking at the code from a top
 * down approach. Other managed entities can be obtained from the PolicyEngine, hierarchically. <br>
 * PolicyEngine 1 --- * PolicyController 1 --- 1 DroolsController 1 --- 1 PolicyContainer 1 --- *
 * PolicySession <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicReader 1 --- 1
 * UebTopicReader <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicReader 1 --- 1
 * DmaapTopicReader <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicWriter 1 --- 1
 * DmaapTopicWriter <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicReader 1 --- 1
 * RestTopicReader <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicWriter 1 --- 1
 * RestTopicWriter <br> PolicyEngine 1 --- 1 ManagementServer
 */
public interface PolicyEngine extends Startable, Lockable, TopicListener {

    /**
     * Boot the engine.
     *
     * @param cliArgs command line arguments
     */
    void boot(String[] cliArgs);

    /**
     * configure the policy engine according to the given properties.
     *
     * @param properties Policy Engine properties
     * @throws IllegalArgumentException when invalid or insufficient properties are provided
     */
    void configure(Properties properties);

    /**
     * updates the Policy Engine with the given configuration.
     *
     * @param configuration the configuration
     * @return success or failure
     * @throws IllegalArgumentException if invalid argument provided
     * @throws IllegalStateException    if the system is in an invalid state
     */
    boolean configure(PdpdConfiguration configuration);

    /**
     * open the Policy Engine to external configuration systems.
     *
     * @return success or failure
     */
    boolean open();


    /**
     * configure the engine's environment. General lab installation configuration is made available
     * to the Engine. Typically, custom lab installation that may be needed by arbitrary drools
     * applications are made available, for example network component and database host addresses.
     * Multiple environments can be passed in and tracked by the engine.
     *
     * @param properties an environment properties
     */
    void setEnvironment(Properties properties);

    /**
     * gets the engine's environment.
     *
     * @return properties object
     */
    Properties getEnvironment();

    /**
     * gets an environment's value, by 1) first from the engine's environment, and 2) from the OS
     * environment.
     *
     * @param key environment key
     * @return environment value or null if absent
     */
    String getEnvironmentProperty(String key);

    /**
     * sets an engine's environment property.
     *
     * @param key key
     * @param value value
     * @return property string
     */
    String setEnvironmentProperty(String key, String value);

    /**
     * Gets the hostname used by this PDP-D.
     */
    String getHostName();

    /**
     * Gets the cluster name as configured in $CLUSTER_NAME,
     * otherwise it will assume an UUID as the cluster name.
     */
    String getClusterName();

    /**
     * Gets the PDP Name from hostname and $CLUSTER_NAME,
     * otherwise if CLUSTER_NAME is not set, the PdpName
     * will be the concatenation of the hostname and a
     * UUID.
     */
    String getPdpName();

    /**
     * registers a new Policy Controller with the Policy Engine initialized per properties.
     *
     * @param properties properties to initialize the Policy Controller
     * @return the newly instantiated Policy Controller
     * @throws IllegalArgumentException when invalid or insufficient properties are provided
     * @throws IllegalStateException    when the engine is in a state where this operation is not
     *                                  permitted.
     */
    PolicyController createPolicyController(String name, Properties properties);

    /**
     * updates a set of Policy Controllers with configuration information.
     *
     * @param configuration list of configurations
     * @return list of controllers
     * @throws IllegalArgumentException exception
     * @throws IllegalStateException exception
     */
    List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configuration);

    /**
     * updates an already existing Policy Controller with configuration information.
     *
     * @param configuration configuration
     * @return the updated Policy Controller
     * @throws IllegalArgumentException in the configuration is invalid
     * @throws IllegalStateException    if the controller is in a bad state
     */
    PolicyController updatePolicyController(ControllerConfiguration configuration);

    /**
     * removes the Policy Controller identified by its name from the Policy Engine.
     *
     * @param name name of the Policy Controller
     */
    void removePolicyController(String name);

    /**
     * removes a Policy Controller from the Policy Engine.
     *
     * @param controller the Policy Controller to remove from the Policy Engine
     */
    void removePolicyController(PolicyController controller);

    /**
     * returns a list of the available Policy Controllers.
     *
     * @return list of Policy Controllers
     */
    List<PolicyController> getPolicyControllers();


    /**
     * get policy controller names.
     *
     * @return list of controller names
     */
    List<String> getPolicyControllerIds();

    /**
     * get unmanaged sources.
     *
     * @return unmanaged sources
     */
    List<TopicSource> getSources();

    /**
     * get unmanaged sinks.
     *
     * @return unmanaged sinks
     */
    List<TopicSink> getSinks();

    /**
     * get unmmanaged http servers list.
     *
     * @return http servers
     */
    List<HttpServletServer> getHttpServers();

    /**
     * Gets a thread pool that can be used to execute background tasks.
     */
    ScheduledExecutorService getExecutorService();

    /**
     * get properties configuration.
     *
     * @return properties objects
     */
    Properties getProperties();

    /**
     * get features attached to the Policy Engine.
     *
     * @return list of features
     */
    List<PolicyEngineFeatureApi> getFeatureProviders();

    /**
     * get named feature attached to the Policy Engine.
     *
     * @return the feature
     */
    PolicyEngineFeatureApi getFeatureProvider(String featureName);

    /**
     * get features attached to the Policy Engine.
     *
     * @return list of features
     */
    List<String> getFeatures();

    /**
     * get domain maker.
     *
     * @return the domain maker
     */
    DomainMaker getDomainMaker();

    /**
     * get statistics for this PDP.
     *
     * @return statistics
     */
    PolicyStatsManager getStats();

    /**
     * Attempts the dispatching of an "event" object.
     *
     * @param topic topic
     * @param event the event object to send
     * @return true if successful, false if a failure has occurred.
     * @throws IllegalArgumentException when invalid or insufficient properties are provided
     * @throws IllegalStateException    when the engine is in a state where this operation is not
     *                                  permitted (ie. locked or stopped).
     */
    boolean deliver(String topic, Object event);

    /**
     * Attempts the dispatching of an "event" object over communication infrastructure "busType".
     *
     * @param topic topic
     * @param event the event object to send
     * @return true if successful, false if a failure has occurred.
     * @throws IllegalArgumentException      when invalid or insufficient properties are provided
     * @throws IllegalStateException         when the engine is in a state where this operation is not
     *                                       permitted (ie. locked or stopped).
     * @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
     *                                       missing (ie. communication infrastructure not supported.
     */
    boolean deliver(String busType, String topic, Object event);

    /**
     * Attempts the dispatching of an "event" object over communication infrastructure "busType".
     *
     * @param topic topic
     * @param event the event object to send
     * @return true if successful, false if a failure has occurred.
     * @throws IllegalArgumentException      when invalid or insufficient properties are provided
     * @throws IllegalStateException         when the engine is in a state where this operation is not
     *                                       permitted (ie. locked or stopped).
     * @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
     *                                       missing (ie. communication infrastructure not supported.
     */
    boolean deliver(CommInfrastructure busType, String topic, Object event);

    /**
     * Attempts delivering of an String over communication infrastructure "busType".
     *
     * @param topic topic
     * @param event the event object to send
     * @return true if successful, false if a failure has occurred.
     * @throws IllegalArgumentException      when invalid or insufficient properties are provided
     * @throws IllegalStateException         when the engine is in a state where this operation is not
     *                                       permitted (ie. locked or stopped).
     * @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
     *                                       missing (ie. communication infrastructure not supported.
     */
    boolean deliver(CommInfrastructure busType, String topic, String event);

    /**
     * Requests a lock on a resource. Typically, the lock is not immediately granted,
     * though a "lock" object is always returned. Once the lock has been granted (or
     * denied), the callback will be invoked to indicate the result.
     *
     * <p/>
     * Notes:
     * <dl>
     * <li>The callback may be invoked <i>before</i> this method returns</li>
     * <li>The implementation need not honor waitForLock={@code true}</li>
     * </dl>
     *
     * @param resourceId identifier of the resource to be locked
     * @param ownerKey information identifying the owner requesting the lock
     * @param holdSec amount of time, in seconds, for which the lock should be held once
     *        it has been granted, after which it will automatically be released
     * @param callback callback to be invoked once the lock is granted, or subsequently
     *        lost; must not be {@code null}
     * @param waitForLock {@code true} to wait for the lock, if it is currently locked,
     *        {@code false} otherwise
     * @return a new lock
     */
    Lock createLock(String resourceId, String ownerKey, int holdSec, LockCallback callback,
        boolean waitForLock);

    /**
     * Invoked when the host goes into the active state.
     */
    void activate();

    /**
     * Invoked when the host goes into the standby state.
     */
    void deactivate();

    /**
     * produces a default telemetry configuration.
     *
     * @return policy engine configuration
     */
    Properties defaultTelemetryConfig();

    /**
     * Track a policy execution metric.
     *
     * @param controllerName controller name
     * @param policyName policy name
     * @param metric metric
     */
    void metric(String controllerName, String policyName, Metric metric);

    /**
     * Track a policy execution transaction.
     *
     * @param controllerName controller name
     * @param policyName policy name
     * @param transaction transaction
     */
    void transaction(String controllerName, String policyName, Metric transaction);
}