f43737f5b58da53b8d056d1e215e6777e083a6b1
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
4  * ======================================================================
5  * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
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.onap.ccsdk.oran.a1policymanagementservice.repository;
22
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Vector;
27
28 import lombok.Getter;
29 import lombok.Setter;
30
31 import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1ProtocolType;
32 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
33
34 /**
35  * Holds information about a Near-RT RIC.
36  */
37 public class Ric {
38
39     @Setter
40     private RicConfig ricConfig;
41     private RicState state = RicState.UNAVAILABLE;
42     private Map<String, PolicyType> supportedPolicyTypes = new HashMap<>();
43     @Getter
44     @Setter
45     private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN;
46
47     @Getter
48     private final Lock lock;
49
50     /**
51      * Creates the Ric. Initial state is {@link RicState.UNDEFINED}.
52      *
53      * @param ricConfig The {@link RicConfig} for this Ric.
54      */
55     public Ric(RicConfig ricConfig) {
56         this.ricConfig = ricConfig;
57         this.lock = new Lock(ricConfig.ricId());
58     }
59
60     public String id() {
61         return ricConfig.ricId();
62     }
63
64     public RicConfig getConfig() {
65         return this.ricConfig;
66     }
67
68     public synchronized RicState getState() {
69         return this.state;
70     }
71
72     public synchronized void setState(RicState state) {
73         this.state = state;
74     }
75
76     /**
77      * Gets the nodes managed by this Ric.
78      *
79      * @return a vector containing the nodes managed by this Ric.
80      */
81     public synchronized Collection<String> getManagedElementIds() {
82         return new Vector<>(ricConfig.managedElementIds());
83     }
84
85     /**
86      * Determines if the given node is managed by this Ric.
87      *
88      * @param managedElementId the node name to check.
89      * @return true if the given node is managed by this Ric.
90      */
91     public synchronized boolean isManaging(String managedElementId) {
92         return ricConfig.managedElementIds().contains(managedElementId);
93     }
94
95     /**
96      * Gets the policy types supported by this Ric.
97      *
98      * @return the policy types supported by this Ric in an unmodifiable list.
99      */
100     public synchronized Collection<PolicyType> getSupportedPolicyTypes() {
101         return new Vector<>(supportedPolicyTypes.values());
102     }
103
104     public synchronized Collection<String> getSupportedPolicyTypeNames() {
105         return new Vector<>(supportedPolicyTypes.keySet());
106     }
107
108     /**
109      * Adds a policy type as supported by this Ric.
110      *
111      * @param type the policy type to support.
112      */
113     public synchronized void addSupportedPolicyType(PolicyType type) {
114         supportedPolicyTypes.put(type.getId(), type);
115     }
116
117     /**
118      * Removes all policy type as supported by this Ric.
119      */
120     public synchronized void clearSupportedPolicyTypes() {
121         supportedPolicyTypes.clear();
122     }
123
124     /**
125      * Checks if a type is supported by this Ric.
126      *
127      * @param typeId the identity of the type to check if it is supported.
128      *
129      * @return true if the given type is supported by this Ric, false otherwise.
130      */
131     public synchronized boolean isSupportingType(String typeId) {
132         return supportedPolicyTypes.containsKey(typeId);
133     }
134
135     @Override
136     public synchronized String toString() {
137         return Ric.class.getSimpleName() + ": " + "name: " + id() + ", state: " + state + ", baseUrl: "
138                 + ricConfig.baseUrl() + ", managedNodes: " + ricConfig.managedElementIds();
139     }
140
141     /**
142      * Represents the states possible for a Ric.
143      */
144     public enum RicState {
145         /**
146          * The Policy Management Service's view of the Near-RT RIC may be inconsistent.
147          */
148         UNAVAILABLE,
149         /**
150          * The normal state. Policies can be configured.
151          */
152         AVAILABLE,
153         /**
154          * The Policy Management Service is synchronizing the view of the Near-RT RIC.
155          */
156         SYNCHRONIZING,
157
158         /**
159          * A consistency check between the Policy Management Service and the Near-RT RIC
160          * is done
161          */
162         CONSISTENCY_CHECK
163     }
164 }