2  * ========================LICENSE_START=================================
 
   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
 
  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.onap.ccsdk.oran.a1policymanagementservice.repository;
 
  23 import java.util.Collection;
 
  24 import java.util.HashMap;
 
  26 import java.util.Vector;
 
  31 import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1ProtocolType;
 
  32 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
 
  35  * Holds information about a NearRT-RIC.
 
  40     private RicConfig ricConfig;
 
  41     private RicState state = RicState.UNAVAILABLE;
 
  42     private Map<String, PolicyType> supportedPolicyTypes = new HashMap<>();
 
  45     private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN;
 
  48     private final Lock lock = new Lock();
 
  51      * Creates the Ric. Initial state is {@link RicState.UNDEFINED}.
 
  53      * @param ricConfig The {@link RicConfig} for this Ric.
 
  55     public Ric(RicConfig ricConfig) {
 
  56         this.ricConfig = ricConfig;
 
  60         return ricConfig.ricId();
 
  63     public RicConfig getConfig() {
 
  64         return this.ricConfig;
 
  67     public synchronized RicState getState() {
 
  71     public synchronized void setState(RicState state) {
 
  76      * Gets the nodes managed by this Ric.
 
  78      * @return a vector containing the nodes managed by this Ric.
 
  80     public synchronized Collection<String> getManagedElementIds() {
 
  81         return ricConfig.managedElementIds();
 
  85      * Determines if the given node is managed by this Ric.
 
  87      * @param managedElementId the node name to check.
 
  88      * @return true if the given node is managed by this Ric.
 
  90     public synchronized boolean isManaging(String managedElementId) {
 
  91         return ricConfig.managedElementIds().contains(managedElementId);
 
  95      * Gets the policy types supported by this Ric.
 
  97      * @return the policy types supported by this Ric in an unmodifiable list.
 
  99     public synchronized Collection<PolicyType> getSupportedPolicyTypes() {
 
 100         return new Vector<>(supportedPolicyTypes.values());
 
 103     public synchronized Collection<String> getSupportedPolicyTypeNames() {
 
 104         return new Vector<>(supportedPolicyTypes.keySet());
 
 108      * Adds a policy type as supported by this Ric.
 
 110      * @param type the policy type to support.
 
 112     public synchronized void addSupportedPolicyType(PolicyType type) {
 
 113         supportedPolicyTypes.put(type.id(), type);
 
 117      * Removes all policy type as supported by this Ric.
 
 119     public synchronized void clearSupportedPolicyTypes() {
 
 120         supportedPolicyTypes.clear();
 
 124      * Checks if a type is supported by this Ric.
 
 126      * @param typeName the name of the type to check if it is supported.
 
 128      * @return true if the given type is supported by this Ric, false otherwise.
 
 130     public synchronized boolean isSupportingType(String typeName) {
 
 131         return supportedPolicyTypes.containsKey(typeName);
 
 135     public synchronized String toString() {
 
 136         return Ric.class.getSimpleName() + ": " + "name: " + id() + ", state: " + state + ", baseUrl: "
 
 137             + ricConfig.baseUrl() + ", managedNodes: " + ricConfig.managedElementIds();
 
 141      * Represents the states possible for a Ric.
 
 143     public enum RicState {
 
 145          * The Policy Management Service's view of the NearRT-RIC may be inconsistent.
 
 149          * The normal state. Policies can be configured.
 
 153          * The Policy Management Service is synchronizing the view of the NearRT-RIC.
 
 158          * A consistency check between the Policy Management Service and the NearRT-RIC