2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.drools.system;
23 import java.util.List;
24 import java.util.Properties;
25 import org.onap.policy.common.capabilities.Lockable;
26 import org.onap.policy.common.capabilities.Startable;
27 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
28 import org.onap.policy.common.endpoints.event.comm.TopicListener;
29 import org.onap.policy.common.endpoints.event.comm.TopicSink;
30 import org.onap.policy.common.endpoints.event.comm.TopicSource;
31 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
32 import org.onap.policy.drools.features.PolicyEngineFeatureApi;
33 import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
34 import org.onap.policy.drools.protocol.configuration.PdpdConfiguration;
37 * Policy Engine, the top abstraction for the Drools PDP Policy Engine. It abstracts away a Drools
38 * PDP Engine from management purposes. This is the best place to looking at the code from a top
39 * down approach. Other managed entities can be obtained from the PolicyEngine, hierarchically. <br>
40 * PolicyEngine 1 --- * PolicyController 1 --- 1 DroolsController 1 --- 1 PolicyContainer 1 --- *
41 * PolicySession <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicReader 1 --- 1
42 * UebTopicReader <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicReader 1 --- 1
43 * DmaapTopicReader <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicWriter 1 --- 1
44 * DmaapTopicWriter <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicReader 1 --- 1
45 * RestTopicReader <br> PolicyEngine 1 --- 1 TopicEndpointManager 1 -- * TopicWriter 1 --- 1
46 * RestTopicWriter <br> PolicyEngine 1 --- 1 ManagementServer
48 public interface PolicyEngine extends Startable, Lockable, TopicListener {
50 * Policy Engine Manager.
52 PolicyEngine manager = new PolicyEngineManager();
55 * Default Telemetry Server Port.
57 int TELEMETRY_SERVER_DEFAULT_PORT = 9696;
60 * Default Telemetry Server Hostname.
62 String TELEMETRY_SERVER_DEFAULT_HOST = "localhost";
65 * Default Telemetry Server Name.
67 String TELEMETRY_SERVER_DEFAULT_NAME = "TELEMETRY";
72 * @param cliArgs command line arguments
74 void boot(String[] cliArgs);
77 * configure the policy engine according to the given properties.
79 * @param properties Policy Engine properties
80 * @throws IllegalArgumentException when invalid or insufficient properties are provided
82 void configure(Properties properties);
85 * updates the Policy Engine with the given configuration.
87 * @param configuration the configuration
88 * @return success or failure
89 * @throws IllegalArgumentException if invalid argument provided
90 * @throws IllegalStateException if the system is in an invalid state
92 boolean configure(PdpdConfiguration configuration);
95 * configure the engine's environment. General lab installation configuration is made available
96 * to the Engine. Typically, custom lab installation that may be needed by arbitrary drools
97 * applications are made available, for example network component and database host addresses.
98 * Multiple environments can be passed in and tracked by the engine.
100 * @param properties an environment properties
102 void setEnvironment(Properties properties);
105 * gets the engine's environment.
107 * @return properties object
109 Properties getEnvironment();
112 * gets an environment's value, by 1) first from the engine's environment, and 2) from the OS
115 * @param key environment key
116 * @return environment value or null if absent
118 String getEnvironmentProperty(String key);
121 * sets an engine's environment property.
125 * @return property string
127 String setEnvironmentProperty(String key, String value);
130 * registers a new Policy Controller with the Policy Engine initialized per properties.
132 * @param properties properties to initialize the Policy Controller
133 * @return the newly instantiated Policy Controller
134 * @throws IllegalArgumentException when invalid or insufficient properties are provided
135 * @throws IllegalStateException when the engine is in a state where this operation is not
138 PolicyController createPolicyController(String name, Properties properties);
141 * updates a set of Policy Controllers with configuration information.
143 * @param configuration list of configurations
144 * @return list of controllers
145 * @throws IllegalArgumentException exception
146 * @throws IllegalStateException exception
148 List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configuration);
151 * updates an already existing Policy Controller with configuration information.
153 * @param configuration configuration
154 * @return the updated Policy Controller
155 * @throws IllegalArgumentException in the configuration is invalid
156 * @throws IllegalStateException if the controller is in a bad state
157 * @throws Exception any other reason
159 PolicyController updatePolicyController(ControllerConfiguration configuration);
162 * removes the Policy Controller identified by its name from the Policy Engine.
164 * @param name name of the Policy Controller
166 void removePolicyController(String name);
169 * removes a Policy Controller from the Policy Engine.
171 * @param controller the Policy Controller to remove from the Policy Engine
173 void removePolicyController(PolicyController controller);
176 * returns a list of the available Policy Controllers.
178 * @return list of Policy Controllers
180 List<PolicyController> getPolicyControllers();
184 * get policy controller names.
186 * @return list of controller names
188 List<String> getPolicyControllerIds();
191 * get unmanaged sources.
193 * @return unmanaged sources
195 List<TopicSource> getSources();
198 * get unmanaged sinks.
200 * @return unmanaged sinks
202 List<TopicSink> getSinks();
205 * get unmmanaged http servers list.
207 * @return http servers
209 List<HttpServletServer> getHttpServers();
212 * get properties configuration.
214 * @return properties objects
216 Properties getProperties();
219 * get features attached to the Policy Engine.
221 * @return list of features
223 List<PolicyEngineFeatureApi> getFeatureProviders();
226 * get named feature attached to the Policy Engine.
228 * @return the feature
230 PolicyEngineFeatureApi getFeatureProvider(String featureName);
233 * get features attached to the Policy Engine.
235 * @return list of features
237 List<String> getFeatures();
240 * Attempts the dispatching of an "event" object.
243 * @param event the event object to send
244 * @return true if successful, false if a failure has occurred.
245 * @throws IllegalArgumentException when invalid or insufficient properties are provided
246 * @throws IllegalStateException when the engine is in a state where this operation is not
247 * permitted (ie. locked or stopped).
249 boolean deliver(String topic, Object event);
252 * Attempts the dispatching of an "event" object over communication infrastructure "busType".
255 * @param event the event object to send
256 * @return true if successful, false if a failure has occurred.
257 * @throws IllegalArgumentException when invalid or insufficient properties are provided
258 * @throws IllegalStateException when the engine is in a state where this operation is not
259 * permitted (ie. locked or stopped).
260 * @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
261 * missing (ie. communication infrastructure not supported.
263 boolean deliver(String busType, String topic, Object event);
266 * Attempts the dispatching of an "event" object over communication infrastructure "busType".
269 * @param event the event object to send
270 * @return true if successful, false if a failure has occurred.
271 * @throws IllegalArgumentException when invalid or insufficient properties are provided
272 * @throws IllegalStateException when the engine is in a state where this operation is not
273 * permitted (ie. locked or stopped).
274 * @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
275 * missing (ie. communication infrastructure not supported.
277 boolean deliver(CommInfrastructure busType, String topic, Object event);
280 * Attempts delivering of an String over communication infrastructure "busType".
283 * @param event the event object to send
284 * @return true if successful, false if a failure has occurred.
285 * @throws IllegalArgumentException when invalid or insufficient properties are provided
286 * @throws IllegalStateException when the engine is in a state where this operation is not
287 * permitted (ie. locked or stopped).
288 * @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
289 * missing (ie. communication infrastructure not supported.
291 boolean deliver(CommInfrastructure busType, String topic, String event);
294 * Invoked when the host goes into the active state.
299 * Invoked when the host goes into the standby state.
304 * produces a default telemetry configuration.
306 * @return policy engine configuration
308 Properties defaultTelemetryConfig();