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;
31 import org.oransc.policyagent.clients.A1Client.A1ProtocolType;
32 import org.oransc.policyagent.configuration.RicConfig;
35 * Represents the dynamic information about a NearRealtime-RIC.
38 private final RicConfig ricConfig;
41 private RicState state = RicState.UNDEFINED;
42 private Map<String, PolicyType> supportedPolicyTypes = new HashMap<>();
45 private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN;
48 * Creates the Ric. Initial state is {@link RicState.NOT_INITIATED}.
50 * @param ricConfig The {@link RicConfig} for this Ric.
52 public Ric(RicConfig ricConfig) {
53 this.ricConfig = ricConfig;
56 public String name() {
57 return ricConfig.name();
60 public RicConfig getConfig() {
61 return this.ricConfig;
65 * Gets the nodes managed by this Ric.
67 * @return a vector containing the nodes managed by this Ric.
69 public Vector<String> getManagedElementIds() {
70 return ricConfig.managedElementIds();
74 * Determines if the given node is managed by this Ric.
76 * @param managedElementId the node name to check.
77 * @return true if the given node is managed by this Ric.
79 public boolean isManaging(String managedElementId) {
80 return ricConfig.managedElementIds().contains(managedElementId);
84 * Adds the given node as managed by this Ric.
86 * @param managedElementId the node to add.
88 public void addManagedElement(String managedElementId) {
89 if (!ricConfig.managedElementIds().contains(managedElementId)) {
90 ricConfig.managedElementIds().add(managedElementId);
95 * Removes the given node as managed by this Ric.
97 * @param managedElementId the node to remove.
99 public void removeManagedElement(String managedElementId) {
100 ricConfig.managedElementIds().remove(managedElementId);
104 * Gets the policy types supported by this Ric.
106 * @return the policy types supported by this Ric in an unmodifiable list.
108 public Collection<PolicyType> getSupportedPolicyTypes() {
109 return supportedPolicyTypes.values();
112 public Collection<String> getSupportedPolicyTypeNames() {
113 return supportedPolicyTypes.keySet();
117 * Adds a policy type as supported by this Ric.
119 * @param type the policy type to support.
121 public void addSupportedPolicyType(PolicyType type) {
122 supportedPolicyTypes.put(type.name(), type);
126 * Removes all policy type as supported by this Ric.
128 public void clearSupportedPolicyTypes() {
129 supportedPolicyTypes.clear();
133 * Checks if a type is supported by this Ric.
135 * @param typeName the name of the type to check if it is supported.
137 * @return true if the given type is supported by this Ric, false otherwise.
139 public boolean isSupportingType(String typeName) {
140 return supportedPolicyTypes.containsKey(typeName);
144 public String toString() {
145 return Ric.class.getSimpleName() + ": " + "name: " + name() + ", state: " + state + ", baseUrl: "
146 + ricConfig.baseUrl() + ", managedNodes: " + ricConfig.managedElementIds();
150 * Represents the states possible for a Ric.
152 public static enum RicState {
154 * The agent view of the agent may be inconsistent.
158 * The normal state. Policies can be configured.
162 * The Ric states are recovered.