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> getManagedElementIds() {
69 return ricConfig.managedElementIds();
73 * Determines if the given node is managed by this Ric.
75 * @param managedElementId the node name to check.
76 * @return true if the given node is managed by this Ric.
78 public boolean isManaging(String managedElementId) {
79 return ricConfig.managedElementIds().contains(managedElementId);
83 * Adds the given node as managed by this Ric.
85 * @param managedElementId the node to add.
87 public void addManagedElement(String managedElementId) {
88 if (!ricConfig.managedElementIds().contains(managedElementId)) {
89 ricConfig.managedElementIds().add(managedElementId);
94 * Removes the given node as managed by this Ric.
96 * @param managedElementId the node to remove.
98 public void removeManagedElement(String managedElementId) {
99 ricConfig.managedElementIds().remove(managedElementId);
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 * Removes all policy type as supported by this Ric.
127 public void clearSupportedPolicyTypes() {
128 supportedPolicyTypes.clear();
132 * Checks if a type is supported by this Ric.
134 * @param typeName the name of the type to check if it is supported.
136 * @return true if the given type is supported by this Ric, false otherwise.
138 public boolean isSupportingType(String typeName) {
139 return supportedPolicyTypes.containsKey(typeName);
143 public String toString() {
144 return Ric.class.getSimpleName() + ": " + "name: " + name() + ", state: " + state + ", baseUrl: "
145 + ricConfig.baseUrl() + ", managedNodes: " + ricConfig.managedElementIds();
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 * The Ric cannot be contacted.
163 NOT_REACHABLE, RECOVERING