2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-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.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 * Factory for various objects. May be overridden by junit tests.
39 private static Factory factory = new Factory();
43 * retrieves control loops.
45 * @param controllerName controller name.
46 * @param sessionName session name.
47 * @return control loops.
49 public static Stream<ControlLoopParams> controlLoops(String controllerName, String sessionName) {
50 PolicyController controller = factory.getController(controllerName);
51 if (controller == null) {
52 throw new IllegalArgumentException("Invalid Controller Name");
55 if (controller.getDrools().getSessionNames().stream().filter(sessionName::equals).count() <= 0) {
56 throw new IllegalArgumentException("Invalid Session Name");
59 return controller.getDrools()
60 .facts(sessionName, ControlLoopParams.class.getName(), false)
62 .filter(c -> c instanceof ControlLoopParams)
63 .map(c -> (ControlLoopParams) c);
67 * retrieves a control loop.
69 * @param controllerName controller name.
70 * @param sessionName session name.
71 * @param controlLoopName control loop name
73 * @return control loops.
75 public static ControlLoopParams controlLoop(String controllerName, String sessionName, String controlLoopName) {
76 return controlLoops(controllerName, sessionName)
77 .filter(c -> c.getClosedLoopControlName().equals(controlLoopName))
86 public int getSequenceNumber() {
94 public String getName() {
99 * Factory that can be overridden by junit tests.
101 public static class Factory {
102 public PolicyController getController(String controllerName) {
103 return PolicyController.factory.get(controllerName);