2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2021 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.drl.legacy.ControlLoopParams;
25 import org.onap.policy.drools.features.PolicyEngineFeatureApi;
26 import org.onap.policy.drools.system.PolicyController;
27 import org.onap.policy.drools.system.PolicyControllerConstants;
30 * Control Loop Management Feature.
32 public class ControlLoopManagementFeature implements PolicyEngineFeatureApi {
34 private static final String FEATURE_NAME = "controlloop-management";
35 private static final int SEQNO = 1000;
38 * Factory for various objects. May be overridden by junit tests.
40 private static Factory factory = new Factory();
44 * retrieves control loops.
46 * @param controllerName controller name.
47 * @param sessionName session name.
48 * @return control loops.
50 public static Stream<ControlLoopParams> controlLoops(String controllerName, String sessionName) {
51 PolicyController controller = factory.getController(controllerName);
52 if (controller == null) {
53 throw new IllegalArgumentException("Invalid Controller Name");
56 if (controller.getDrools().getSessionNames().stream().filter(sessionName::equals).count() <= 0) {
57 throw new IllegalArgumentException("Invalid Session Name");
60 return controller.getDrools()
61 .facts(sessionName, ControlLoopParams.class.getName(), false)
63 .filter(ControlLoopParams.class::isInstance)
64 .map(ControlLoopParams.class::cast);
68 * retrieves a control loop.
70 * @param controllerName controller name.
71 * @param sessionName session name.
72 * @param controlLoopName control loop name
74 * @return control loops.
76 public static ControlLoopParams controlLoop(String controllerName, String sessionName, String controlLoopName) {
77 return controlLoops(controllerName, sessionName)
78 .filter(c -> c.getClosedLoopControlName().equals(controlLoopName))
87 public int getSequenceNumber() {
95 public String getName() {
100 * Factory that can be overridden by junit tests.
102 public static class Factory {
103 public PolicyController getController(String controllerName) {
104 return PolicyControllerConstants.getFactory().get(controllerName);