2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
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.oransc.policyagent.repository;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Vector;
26 import org.oransc.policyagent.configuration.RicConfig;
27 import org.oransc.policyagent.repository.Ric.RicState;
30 * Represents the dynamic information about a NearRealtime-RIC.
33 private final RicConfig ricConfig;
34 private RicState state = RicState.NOT_INITIATED;
35 private Vector<PolicyType> supportedPolicyTypes = new Vector<>();
38 * Creates the Ric. Initial state is {@link RicState.NOT_INITIATED}.
40 * @param ricConfig The {@link RicConfig} for this Ric.
42 public Ric(RicConfig ricConfig) {
43 this.ricConfig = ricConfig;
46 public String name() {
47 return ricConfig.name();
50 public RicState state() {
54 public void setState(RicState newState) {
59 * Gets the nodes managed by this Ric.
61 * @return a vector containing the nodes managed by this Ric.
63 public Vector<String> getManagedNodes() {
64 return ricConfig.managedElementIds();
68 * Determines if the given node is managed by this Ric.
70 * @param nodeName the node name to check.
71 * @return true if the given node is managed by this Ric.
73 public boolean isManaging(String nodeName) {
74 return ricConfig.managedElementIds().contains(nodeName);
78 * Adds the given node as managed by this Ric.
80 * @param nodeName the node to add.
82 public void addManagedNode(String nodeName) {
83 if (!ricConfig.managedElementIds().contains(nodeName)) {
84 ricConfig.managedElementIds().add(nodeName);
89 * Removes the given node as managed by this Ric.
91 * @param nodeName the node to remove.
93 public void removeManagedNode(String nodeName) {
94 ricConfig.managedElementIds().remove(nodeName);
98 * Gets the policy types supported by this Ric.
100 * @return the policy types supported by this Ric in an unmodifiable list.
102 public List<PolicyType> getSupportedPolicyTypes() {
103 return Collections.unmodifiableList(supportedPolicyTypes);
107 * Adds a policy type as supported by this Ric.
109 * @param type the policy type to support.
111 public void addSupportedPolicyType(PolicyType type) {
112 if (!supportedPolicyTypes.contains(type)) {
113 supportedPolicyTypes.add(type);
118 * Adds policy types as supported by this Ric.
120 * @param types the policy types to support.
122 public void addSupportedPolicyTypes(Vector<PolicyType> types) {
123 for (PolicyType type : types) {
124 addSupportedPolicyType(type);
129 * Removes a policy type as supported by this Ric.
131 * @param type the policy type to remove as supported by this Ric.
133 public void removeSupportedPolicyType(PolicyType type) {
134 supportedPolicyTypes.remove(type);
138 * Checks if a type is supported by this Ric.
140 * @param type the type to check if it is supported.
142 * @return true if the given type issupported by this Ric, false otherwise.
144 public boolean isSupportingType(PolicyType type) {
145 return supportedPolicyTypes.contains(type);
149 * Represents the states possible for a Ric.
151 public static enum RicState {
153 * The Ric has not been initiated yet.
157 * The Ric is working fine.
161 * Something is wrong with the Ric.
165 * The node is unreachable at the moment.