Fix startup
[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.Vector;
24 import org.oransc.policyagent.configuration.RicConfig;
25
26 /**
27  * Represents the dynamic information about a NearRealtime-RIC.
28  */
29 public class Ric {
30     private final RicConfig ricConfig;
31     private RicState state = RicState.NOT_INITIATED;
32
33     /**
34      * Creates the Ric. Initial state is {@link RicState.NOT_INITIATED}.
35      *
36      * @param ricConfig The {@link RicConfig} for this Ric.
37      */
38     public Ric(RicConfig ricConfig) {
39         this.ricConfig = ricConfig;
40     }
41
42     public String name() {
43         return ricConfig.name();
44     }
45
46     public RicState state() {
47         return state;
48     }
49
50     public void setState(RicState newState) {
51         state = newState;
52     }
53
54     /**
55      * Gets the nodes managed by this Ric.
56      *
57      * @return a vector containing the nodes managed by this Ric.
58      */
59     public Vector<String> getManagedNodes() {
60         return ricConfig.managedElementIds();
61     }
62
63     /**
64      * Determines if the given node is managed by this Ric.
65      *
66      * @param nodeName the node name to check.
67      * @return true if the given node is managed by this Ric.
68      */
69     public boolean isManaging(String nodeName) {
70         return ricConfig.managedElementIds().contains(nodeName);
71     }
72
73     /**
74      * Adds the given node as managed by this Ric.
75      *
76      * @param nodeName the node to add.
77      */
78     public void addManagedNode(String nodeName) {
79         if (!ricConfig.managedElementIds().contains(nodeName)) {
80             ricConfig.managedElementIds().add(nodeName);
81         }
82     }
83
84     /**
85      * Removes the given node as managed by this Ric.
86      *
87      * @param nodeName the node to remove.
88      */
89     public void removeManagedNode(String nodeName) {
90         ricConfig.managedElementIds().remove(nodeName);
91     }
92
93     /**
94      * Represents the states possible for a Ric.
95      */
96     public static enum RicState {
97         /**
98          * The Ric has not been initiated yet.
99          */
100         NOT_INITIATED,
101         /**
102          * The Ric is working fine.
103          */
104         ACTIVE,
105         /**
106          * Something is wrong with the Ric.
107          */
108         FAULTY,
109         /**
110          * The node is unreachable at the moment.
111          */
112         UNREACHABLE
113     }
114 }