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, "" );
58 public Graph( List<MR_Client> clients, boolean strict, String group ) {
59 if ( clients == null )
61 initGraph( clients, strict, group );
64 private void initGraph(List<MR_Client> clients, boolean strict, String group ) {
65 MR_ClusterService clusters = new MR_ClusterService();
66 this.graph = new HashMap<>();
67 this.hasCentral = false;
68 for( MR_Client client: clients ) {
69 if ( ! strict || client.isStatusValid()) {
70 String loc = client.getDcaeLocationName();
71 DcaeLocation dcaeLoc = locations.get(loc);
72 if ( dcaeLoc == null ) continue;
73 MR_Cluster c = clusters.getMr_ClusterByLoc(loc);
74 if ( group != null && ! group.isEmpty() && ! group.equals(c.getReplicationGroup())) continue;
76 for( String action : client.getAction() ){
77 if ( ! action.equals("view") && dcaeLoc != null ) {
78 String layer = dcaeLoc.getDcaeLayer();
79 if ( layer != null && layer.contains(centralDcaeLayerName) ) {
80 this.hasCentral = true;
82 graph.put(loc, layer);
90 public HashMap<String, String> getGraph() {
94 public void setGraph(HashMap<String, String> graph) {
98 public String put( String key, String val ) {
99 return graph.put(key, val);
102 public String get( String key ) {
103 return graph.get(key);
106 public Collection<String> getKeys() {
107 return graph.keySet();
109 public boolean hasCentral() {
112 public void setHasCentral(boolean hasCentral) {
113 this.hasCentral = hasCentral;
116 public String getCentralLoc() {
117 if ( ! hasCentral ) {
120 for( String loc : graph.keySet()) {
121 if ( graph.get(loc).contains(centralDcaeLayerName)) {
127 public boolean isEmpty() {
128 return graph.isEmpty();