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.ArrayList;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.Vector;
33 import org.oransc.policyagent.clients.A1Client.A1ProtocolType;
34 import org.oransc.policyagent.configuration.RicConfig;
37 * Represents the dynamic information about a NearRealtime-RIC.
41 private final RicConfig ricConfig;
42 private final List<String> managedElementIds;
44 private RicState state = RicState.UNDEFINED;
45 private Map<String, PolicyType> supportedPolicyTypes = new HashMap<>();
48 private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN;
51 private final Lock lock = new Lock();
54 * Creates the Ric. Initial state is {@link RicState.NOT_INITIATED}.
56 * @param ricConfig The {@link RicConfig} for this Ric.
58 public Ric(RicConfig ricConfig) {
59 this.ricConfig = ricConfig;
60 this.managedElementIds = new ArrayList<>(ricConfig.managedElementIds()); // TODO, this is config why is it
64 public String name() {
65 return ricConfig.name();
68 public RicConfig getConfig() {
69 return this.ricConfig;
72 public synchronized RicState getState() {
76 public synchronized void setState(RicState state) {
81 * Gets the nodes managed by this Ric.
83 * @return a vector containing the nodes managed by this Ric.
85 public synchronized Collection<String> getManagedElementIds() {
86 return managedElementIds;
90 * Determines if the given node is managed by this Ric.
92 * @param managedElementId the node name to check.
93 * @return true if the given node is managed by this Ric.
95 public synchronized boolean isManaging(String managedElementId) {
96 return managedElementIds.contains(managedElementId);
100 * Adds the given node as managed by this Ric.
102 * @param managedElementId the node to add.
104 public synchronized void addManagedElement(String managedElementId) {
105 if (!managedElementIds.contains(managedElementId)) {
106 managedElementIds.add(managedElementId);
111 * Removes the given node as managed by this Ric.
113 * @param managedElementId the node to remove.
115 public synchronized void removeManagedElement(String managedElementId) {
116 managedElementIds.remove(managedElementId);
120 * Gets the policy types supported by this Ric.
122 * @return the policy types supported by this Ric in an unmodifiable list.
124 public synchronized Collection<PolicyType> getSupportedPolicyTypes() {
125 return new Vector<>(supportedPolicyTypes.values());
128 public synchronized Collection<String> getSupportedPolicyTypeNames() {
129 return new Vector<>(supportedPolicyTypes.keySet());
133 * Adds a policy type as supported by this Ric.
135 * @param type the policy type to support.
137 public synchronized void addSupportedPolicyType(PolicyType type) {
138 supportedPolicyTypes.put(type.name(), type);
142 * Removes all policy type as supported by this Ric.
144 public synchronized void clearSupportedPolicyTypes() {
145 supportedPolicyTypes.clear();
149 * Checks if a type is supported by this Ric.
151 * @param typeName the name of the type to check if it is supported.
153 * @return true if the given type is supported by this Ric, false otherwise.
155 public synchronized boolean isSupportingType(String typeName) {
156 return supportedPolicyTypes.containsKey(typeName);
160 public synchronized String toString() {
161 return Ric.class.getSimpleName() + ": " + "name: " + name() + ", state: " + state + ", baseUrl: "
162 + ricConfig.baseUrl() + ", managedNodes: " + managedElementIds;
166 * Represents the states possible for a Ric.
168 public enum RicState {
170 * The agent view of the Ric may be inconsistent.
174 * The normal state. Policies can be configured.
178 * The agent is synchronizing the view of the Ric.