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 com.google.common.collect.ImmutableList;
25 import java.util.Collection;
26 import java.util.HashMap;
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 ImmutableList<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.UNDEFINED}.
56 * @param ricConfig The {@link RicConfig} for this Ric.
58 public Ric(RicConfig ricConfig) {
59 this.ricConfig = ricConfig;
60 this.managedElementIds = ricConfig.managedElementIds();
63 public String name() {
64 return ricConfig.name();
67 public RicConfig getConfig() {
68 return this.ricConfig;
71 public synchronized RicState getState() {
75 public synchronized void setState(RicState state) {
80 * Gets the nodes managed by this Ric.
82 * @return a vector containing the nodes managed by this Ric.
84 public synchronized Collection<String> getManagedElementIds() {
85 return managedElementIds;
89 * Determines if the given node is managed by this Ric.
91 * @param managedElementId the node name to check.
92 * @return true if the given node is managed by this Ric.
94 public synchronized boolean isManaging(String managedElementId) {
95 return managedElementIds.contains(managedElementId);
99 * Gets the policy types supported by this Ric.
101 * @return the policy types supported by this Ric in an unmodifiable list.
103 public synchronized Collection<PolicyType> getSupportedPolicyTypes() {
104 return new Vector<>(supportedPolicyTypes.values());
107 public synchronized Collection<String> getSupportedPolicyTypeNames() {
108 return new Vector<>(supportedPolicyTypes.keySet());
112 * Adds a policy type as supported by this Ric.
114 * @param type the policy type to support.
116 public synchronized void addSupportedPolicyType(PolicyType type) {
117 supportedPolicyTypes.put(type.name(), type);
121 * Removes all policy type as supported by this Ric.
123 public synchronized void clearSupportedPolicyTypes() {
124 supportedPolicyTypes.clear();
128 * Checks if a type is supported by this Ric.
130 * @param typeName the name of the type to check if it is supported.
132 * @return true if the given type is supported by this Ric, false otherwise.
134 public synchronized boolean isSupportingType(String typeName) {
135 return supportedPolicyTypes.containsKey(typeName);
139 public synchronized String toString() {
140 return Ric.class.getSimpleName() + ": " + "name: " + name() + ", state: " + state + ", baseUrl: "
141 + ricConfig.baseUrl() + ", managedNodes: " + managedElementIds;
145 * Represents the states possible for a Ric.
147 public enum RicState {
149 * The agent view of the Ric may be inconsistent.
153 * The normal state. Policies can be configured.
157 * The agent is synchronizing the view of the Ric.