2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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.apps.controlloop.feature.management;
23 import java.util.stream.Stream;
24 import org.onap.policy.controlloop.params.ControlLoopParams;
25 import org.onap.policy.drools.features.PolicyEngineFeatureAPI;
26 import org.onap.policy.drools.system.PolicyController;
29 * Control Loop Management Feature.
31 public class ControlLoopManagementFeature implements PolicyEngineFeatureAPI {
33 private static final String FEATURE_NAME = "controlloop-management";
34 private static final int SEQNO = 1000;
37 * retrieves control loops.
39 * @param controllerName controller name.
40 * @param sessionName session name.
41 * @return control loops.
43 public static Stream<ControlLoopParams> controlLoops(String controllerName, String sessionName) {
44 PolicyController controller = PolicyController.factory.get(controllerName);
45 if (controller == null) {
46 throw new IllegalArgumentException("Invalid Controller Name");
49 if (controller.getDrools().getSessionNames().stream().filter(sessionName::equals).count() <= 0) {
50 throw new IllegalArgumentException("Invalid Session Name");
53 return controller.getDrools()
54 .facts(sessionName, ControlLoopParams.class.getCanonicalName(), false)
56 .filter(c -> c instanceof ControlLoopParams)
57 .map(c -> (ControlLoopParams) c);
61 * retrieves a control loop.
63 * @param controllerName controller name.
64 * @param sessionName session name.
65 * @param controlLoopName control loop name
67 * @return control loops.
69 public static ControlLoopParams controlLoop(String controllerName, String sessionName, String controlLoopName) {
70 return controlLoops(controllerName, sessionName)
71 .filter(c -> c.getClosedLoopControlName().equals(controlLoopName))
80 public int getSequenceNumber() {
88 public String getName() {