2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright (C) 2019 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.dmaap.dbcapi.util;
25 import org.onap.dmaap.dbcapi.database.DatabaseClass;
26 import org.onap.dmaap.dbcapi.model.DcaeLocation;
27 import org.onap.dmaap.dbcapi.model.MR_Client;
28 import org.onap.dmaap.dbcapi.model.MR_Cluster;
29 import org.onap.dmaap.dbcapi.service.MR_ClusterService;
31 import java.util.Collection;
32 import java.util.HashMap;
33 import java.util.List;
38 private HashMap<String, String> graph;
39 private boolean hasCentral;
41 private Map<String, DcaeLocation> locations = DatabaseClass.getDcaeLocations();
43 //TODO add to properties file
44 private static String centralDcaeLayerName = "central";
47 public Graph(HashMap<String, String> graph) {
52 public Graph( List<MR_Client> clients, boolean strict ) {
53 if ( clients == null )
55 initGraph( clients, strict, "" );
59 public Graph( List<MR_Client> clients, boolean strict, String group ) {
60 if ( clients == null )
62 initGraph( clients, strict, group );
66 private void initGraph(List<MR_Client> clients, boolean strict, String group ) {
67 MR_ClusterService clusters = new MR_ClusterService();
68 this.graph = new HashMap<String, String>();
69 this.hasCentral = false;
70 for( MR_Client client: clients ) {
71 if ( ! strict || client.isStatusValid()) {
72 String loc = client.getDcaeLocationName();
73 DcaeLocation dcaeLoc = locations.get(loc);
74 if ( dcaeLoc == null ) continue;
75 MR_Cluster c = clusters.getMr_ClusterByLoc(loc);
76 if ( group != null && ! group.isEmpty() && ! group.equals(c.getReplicationGroup())) continue;
78 for( String action : client.getAction() ){
79 if ( ! action.equals("view") && dcaeLoc != null ) {
80 String layer = dcaeLoc.getDcaeLayer();
81 if ( layer != null && layer.contains(centralDcaeLayerName) ) {
82 this.hasCentral = true;
84 graph.put(loc, layer);
92 public HashMap<String, String> getGraph() {
96 public void setGraph(HashMap<String, String> graph) {
100 public String put( String key, String val ) {
101 return graph.put(key, val);
104 public String get( String key ) {
105 return graph.get(key);
108 public Collection<String> getKeys() {
109 return graph.keySet();
111 public boolean hasCentral() {
114 public void setHasCentral(boolean hasCentral) {
115 this.hasCentral = hasCentral;
118 public String getCentralLoc() {
119 if ( ! hasCentral ) {
122 for( String loc : graph.keySet()) {
123 if ( graph.get(loc).contains(centralDcaeLayerName)) {
129 public boolean isEmpty() {
130 return graph.isEmpty();