df612dc5476981d539854d98d0c8a7549459c8d5
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / repository / Ric.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 Nordix Foundation
6  * %%
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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===================================
19  */
20
21 package org.oransc.policyagent.repository;
22
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Vector;
26
27 import org.oransc.policyagent.configuration.RicConfig;
28
29 /**
30  * Represents the dynamic information about a NearRealtime-RIC.
31  */
32 public class Ric {
33     private final RicConfig ricConfig;
34     private RicState state = RicState.NOT_INITIATED;
35     private Vector<PolicyType> supportedPolicyTypes = new Vector<>();
36
37     /**
38      * Creates the Ric. Initial state is {@link RicState.NOT_INITIATED}.
39      *
40      * @param ricConfig The {@link RicConfig} for this Ric.
41      */
42     public Ric(RicConfig ricConfig) {
43         this.ricConfig = ricConfig;
44     }
45
46     public String name() {
47         return ricConfig.name();
48     }
49
50     public RicState state() {
51         return state;
52     }
53
54     public void setState(RicState newState) {
55         state = newState;
56     }
57
58     public RicConfig getConfig() {
59         return this.ricConfig;
60     }
61
62     /**
63      * Gets the nodes managed by this Ric.
64      *
65      * @return a vector containing the nodes managed by this Ric.
66      */
67     public Vector<String> getManagedNodes() {
68         return ricConfig.managedElementIds();
69     }
70
71     /**
72      * Determines if the given node is managed by this Ric.
73      *
74      * @param nodeName the node name to check.
75      * @return true if the given node is managed by this Ric.
76      */
77     public boolean isManaging(String nodeName) {
78         return ricConfig.managedElementIds().contains(nodeName);
79     }
80
81     /**
82      * Adds the given node as managed by this Ric.
83      *
84      * @param nodeName the node to add.
85      */
86     public void addManagedNode(String nodeName) {
87         if (!ricConfig.managedElementIds().contains(nodeName)) {
88             ricConfig.managedElementIds().add(nodeName);
89         }
90     }
91
92     /**
93      * Removes the given node as managed by this Ric.
94      *
95      * @param nodeName the node to remove.
96      */
97     public void removeManagedNode(String nodeName) {
98         ricConfig.managedElementIds().remove(nodeName);
99     }
100
101     /**
102      * Gets the policy types supported by this Ric.
103      *
104      * @return the policy types supported by this Ric in an unmodifiable list.
105      */
106     public List<PolicyType> getSupportedPolicyTypes() {
107         return Collections.unmodifiableList(supportedPolicyTypes);
108     }
109
110     /**
111      * Adds a policy type as supported by this Ric.
112      *
113      * @param type the policy type to support.
114      */
115     public void addSupportedPolicyType(PolicyType type) {
116         if (!supportedPolicyTypes.contains(type)) {
117             supportedPolicyTypes.add(type);
118         }
119     }
120
121     /**
122      * Adds policy types as supported by this Ric.
123      *
124      * @param types the policy types to support.
125      */
126     public void addSupportedPolicyTypes(Vector<PolicyType> types) {
127         for (PolicyType type : types) {
128             addSupportedPolicyType(type);
129         }
130     }
131
132     /**
133      * Removes a policy type as supported by this Ric.
134      *
135      * @param type the policy type to remove as supported by this Ric.
136      */
137     public void removeSupportedPolicyType(PolicyType type) {
138         supportedPolicyTypes.remove(type);
139     }
140
141     /**
142      * Checks if a type is supported by this Ric.
143      *
144      * @param type the type to check if it is supported.
145      *
146      * @return true if the given type issupported by this Ric, false otherwise.
147      */
148     public boolean isSupportingType(PolicyType type) {
149         return supportedPolicyTypes.contains(type);
150     }
151
152     /**
153      * Represents the states possible for a Ric.
154      */
155     public static enum RicState {
156         /**
157          * The Ric has not been initiated yet.
158          */
159         NOT_INITIATED,
160         /**
161          * The Ric is working fine.
162          */
163         ACTIVE,
164         /**
165          * Something is wrong with the Ric.
166          */
167         FAULTY,
168         /**
169          * The node is unreachable at the moment.
170          */
171         UNREACHABLE
172     }
173 }