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