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.Collection;
24 import java.util.HashMap;
26 import java.util.Vector;
28 import org.oransc.policyagent.configuration.RicConfig;
31 * Represents the dynamic information about a NearRealtime-RIC.
34 private final RicConfig ricConfig;
35 private RicState state = RicState.NOT_INITIATED;
36 private Map<String, PolicyType> supportedPolicyTypes = new HashMap<>();
39 * Creates the Ric. Initial state is {@link RicState.NOT_INITIATED}.
41 * @param ricConfig The {@link RicConfig} for this Ric.
43 public Ric(RicConfig ricConfig) {
44 this.ricConfig = ricConfig;
47 public String name() {
48 return ricConfig.name();
51 public RicState state() {
55 public void setState(RicState newState) {
59 public RicConfig getConfig() {
60 return this.ricConfig;
64 * Gets the nodes managed by this Ric.
66 * @return a vector containing the nodes managed by this Ric.
68 public Vector<String> getManagedNodes() {
69 return ricConfig.managedElementIds();
73 * Determines if the given node is managed by this Ric.
75 * @param nodeName the node name to check.
76 * @return true if the given node is managed by this Ric.
78 public boolean isManaging(String nodeName) {
79 return ricConfig.managedElementIds().contains(nodeName);
83 * Adds the given node as managed by this Ric.
85 * @param nodeName the node to add.
87 public void addManagedNode(String nodeName) {
88 if (!ricConfig.managedElementIds().contains(nodeName)) {
89 ricConfig.managedElementIds().add(nodeName);
94 * Removes the given node as managed by this Ric.
96 * @param nodeName the node to remove.
98 public void removeManagedNode(String nodeName) {
99 ricConfig.managedElementIds().remove(nodeName);
103 * Gets the policy types supported by this Ric.
105 * @return the policy types supported by this Ric in an unmodifiable list.
107 public Collection<PolicyType> getSupportedPolicyTypes() {
108 return supportedPolicyTypes.values();
111 public Collection<String> getSupportedPolicyTypeNames() {
112 return supportedPolicyTypes.keySet();
116 * Adds a policy type as supported by this Ric.
118 * @param type the policy type to support.
120 public void addSupportedPolicyType(PolicyType type) {
121 supportedPolicyTypes.put(type.name(), type);
125 * Adds policy types as supported by this Ric.
127 * @param types the policy types to support.
129 public void addSupportedPolicyTypes(Collection<PolicyType> types) {
130 for (PolicyType type : types) {
131 addSupportedPolicyType(type);
136 * Removes a policy type as supported by this Ric.
138 * @param type the policy type to remove as supported by this Ric.
140 public void removeSupportedPolicyType(PolicyType type) {
141 supportedPolicyTypes.remove(type.name());
145 * Checks if a type is supported by this Ric.
147 * @param typeName the name of the type to check if it is supported.
149 * @return true if the given type is supported by this Ric, false otherwise.
151 public boolean isSupportingType(String typeName) {
152 return supportedPolicyTypes.containsKey(typeName);
156 public String toString() {
157 return Ric.class.getSimpleName() + ": " + "name: " + name() + ", state: " + state + ", baseUrl: "
158 + ricConfig.baseUrl() + ", managedNodes: " + ricConfig.managedElementIds();
162 * Represents the states possible for a Ric.
164 public static enum RicState {
166 * The Ric has not been initiated yet.
170 * The Ric is working fine.
174 * The Ric cannot be contacted.