2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2024 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.drools.apps.controlloop.feature.management;
24 import java.util.stream.Stream;
25 import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
26 import org.onap.policy.drools.features.PolicyEngineFeatureApi;
27 import org.onap.policy.drools.system.PolicyController;
28 import org.onap.policy.drools.system.PolicyControllerConstants;
31 * Control Loop Management Feature.
33 public class ControlLoopManagementFeature implements PolicyEngineFeatureApi {
35 private static final String FEATURE_NAME = "controlloop-management";
36 private static final int SEQNO = 1000;
39 * Factory for various objects. May be overridden by junit tests.
41 private static Factory factory = new Factory();
45 * retrieves control loops.
47 * @param controllerName controller name.
48 * @param sessionName session name.
49 * @return control loops.
51 public static Stream<ControlLoopParams> controlLoops(String controllerName, String sessionName) {
52 PolicyController controller = factory.getController(controllerName);
53 if (controller == null) {
54 throw new IllegalArgumentException("Invalid Controller Name");
57 if (controller.getDrools().getSessionNames().stream().noneMatch(sessionName::equals)) {
58 throw new IllegalArgumentException("Invalid Session Name");
61 return controller.getDrools()
62 .facts(sessionName, ControlLoopParams.class.getName(), false)
64 .filter(ControlLoopParams.class::isInstance)
65 .map(ControlLoopParams.class::cast);
69 * retrieves a control loop.
71 * @param controllerName controller name.
72 * @param sessionName session name.
73 * @param controlLoopName control loop name
75 * @return control loops.
77 public static ControlLoopParams controlLoop(String controllerName, String sessionName, String controlLoopName) {
78 return controlLoops(controllerName, sessionName)
79 .filter(c -> c.getClosedLoopControlName().equals(controlLoopName))
88 public int getSequenceNumber() {
96 public String getName() {
101 * Factory that can be overridden by junit tests.
103 public static class Factory {
104 public PolicyController getController(String controllerName) {
105 return PolicyControllerConstants.getFactory().get(controllerName);