2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
23 import java.util.ArrayList;
24 import java.util.List;
26 import java.util.UUID;
27 import java.util.stream.Collectors;
29 import lombok.EqualsAndHashCode;
30 import lombok.NoArgsConstructor;
31 import lombok.NonNull;
32 import org.apache.commons.collections4.MapUtils;
33 import org.onap.policy.models.base.PfConceptKey;
34 import org.onap.policy.models.base.PfUtils;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
39 * Class to represent a control loop instance.
43 @EqualsAndHashCode(callSuper = true)
44 public class ControlLoop extends ToscaEntity implements Comparable<ControlLoop> {
46 private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
49 private ControlLoopState state = ControlLoopState.UNINITIALISED;
52 private ControlLoopOrderedState orderedState = ControlLoopOrderedState.UNINITIALISED;
54 private Map<UUID, ControlLoopElement> elements;
57 public String getType() {
58 return definition.getName();
62 public String getTypeVersion() {
63 return definition.getVersion();
67 * Copy contructor, does a deep copy.
69 * @param otherControlLoop the other element to copy from
71 public ControlLoop(final ControlLoop otherControlLoop) {
72 super(otherControlLoop);
73 this.definition = new ToscaConceptIdentifier(otherControlLoop.definition);
74 this.state = otherControlLoop.state;
75 this.orderedState = otherControlLoop.orderedState;
76 this.elements = PfUtils.mapMap(otherControlLoop.elements, ControlLoopElement::new);
80 public int compareTo(final ControlLoop other) {
81 return compareNameVersion(this, other);
85 * Set the ordered state on the control loop and on all its control loop elements.
87 * @param orderedState the state we want the control loop to transition to
89 public void setCascadedOrderedState(final ControlLoopOrderedState orderedState) {
90 this.orderedState = orderedState;
92 if (MapUtils.isEmpty(elements)) {
96 elements.values().forEach(element -> element.setOrderedState(orderedState));
100 * Get a list of control loop element statistics.
102 * @param controlLoop the control loop
103 * @return List of ClElementStatistics
105 public List<ClElementStatistics> getControlLoopElementStatisticsList(final ControlLoop controlLoop) {
106 if (MapUtils.isEmpty(controlLoop.elements)) {
110 return controlLoop.elements.values().stream().map(ControlLoopElement::getClElementStatistics)
111 .collect(Collectors.toList());