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;
24 import java.util.Collection;
25 import java.util.HashMap;
27 import java.util.Vector;
32 import org.oransc.policyagent.clients.A1Client.A1ProtocolType;
33 import org.oransc.policyagent.configuration.RicConfig;
36 * Represents the dynamic information about a NearRealtime-RIC.
40 private final RicConfig ricConfig;
41 private final ImmutableList<String> managedElementIds;
43 private RicState state = RicState.UNDEFINED;
44 private Map<String, PolicyType> supportedPolicyTypes = new HashMap<>();
47 private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN;
50 private final Lock lock = new Lock();
53 * Creates the Ric. Initial state is {@link RicState.UNDEFINED}.
55 * @param ricConfig The {@link RicConfig} for this Ric.
57 public Ric(RicConfig ricConfig) {
58 this.ricConfig = ricConfig;
59 this.managedElementIds = ricConfig.managedElementIds();
62 public String name() {
63 return ricConfig.name();
66 public RicConfig getConfig() {
67 return this.ricConfig;
70 public synchronized RicState getState() {
74 public synchronized void setState(RicState state) {
79 * Gets the nodes managed by this Ric.
81 * @return a vector containing the nodes managed by this Ric.
83 public synchronized Collection<String> getManagedElementIds() {
84 return managedElementIds;
88 * Determines if the given node is managed by this Ric.
90 * @param managedElementId the node name to check.
91 * @return true if the given node is managed by this Ric.
93 public synchronized boolean isManaging(String managedElementId) {
94 return managedElementIds.contains(managedElementId);
98 * Gets the policy types supported by this Ric.
100 * @return the policy types supported by this Ric in an unmodifiable list.
102 public synchronized Collection<PolicyType> getSupportedPolicyTypes() {
103 return new Vector<>(supportedPolicyTypes.values());
106 public synchronized Collection<String> getSupportedPolicyTypeNames() {
107 return new Vector<>(supportedPolicyTypes.keySet());
111 * Adds a policy type as supported by this Ric.
113 * @param type the policy type to support.
115 public synchronized void addSupportedPolicyType(PolicyType type) {
116 supportedPolicyTypes.put(type.name(), type);
120 * Removes all policy type as supported by this Ric.
122 public synchronized void clearSupportedPolicyTypes() {
123 supportedPolicyTypes.clear();
127 * Checks if a type is supported by this Ric.
129 * @param typeName the name of the type to check if it is supported.
131 * @return true if the given type is supported by this Ric, false otherwise.
133 public synchronized boolean isSupportingType(String typeName) {
134 return supportedPolicyTypes.containsKey(typeName);
138 public synchronized String toString() {
139 return Ric.class.getSimpleName() + ": " + "name: " + name() + ", state: " + state + ", baseUrl: "
140 + ricConfig.baseUrl() + ", managedNodes: " + managedElementIds;
144 * Represents the states possible for a Ric.
146 public enum RicState {
148 * The agent view of the Ric may be inconsistent.
152 * The normal state. Policies can be configured.
156 * The agent is synchronizing the view of the Ric.