2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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.dmaap.dbcapi.util;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
29 import org.onap.dmaap.dbcapi.database.DatabaseClass;
30 import org.onap.dmaap.dbcapi.model.DcaeLocation;
31 import org.onap.dmaap.dbcapi.model.MR_Client;
32 import org.onap.dmaap.dbcapi.model.MR_Cluster;
33 import org.onap.dmaap.dbcapi.service.MR_ClusterService;
37 private HashMap<String, String> graph;
38 private boolean hasCentral;
40 private Map<String, DcaeLocation> locations = DatabaseClass.getDcaeLocations();
42 //TODO add to properties file
43 private static String centralDcaeLayerName = "central";
46 public Graph(HashMap<String, String> graph) {
51 public Graph( List<MR_Client> clients, boolean strict ) {
52 if ( clients == null )
54 initGraph( clients, strict, "" );
58 public Graph( List<MR_Client> clients, boolean strict, String group ) {
59 if ( clients == null )
61 initGraph( clients, strict, group );
65 private void initGraph(List<MR_Client> clients, boolean strict, String group ) {
66 MR_ClusterService clusters = new MR_ClusterService();
67 this.graph = new HashMap<String, String>();
68 this.hasCentral = false;
69 for( MR_Client client: clients ) {
70 if ( ! strict || client.isStatusValid()) {
71 String loc = client.getDcaeLocationName();
72 DcaeLocation dcaeLoc = locations.get(loc);
73 if ( dcaeLoc == null ) continue;
74 MR_Cluster c = clusters.getMr_ClusterByLoc(loc);
75 if ( group != null && ! group.isEmpty() && ! group.equals(c.getReplicationGroup())) continue;
77 for( String action : client.getAction() ){
78 if ( ! action.equals("view") && dcaeLoc != null ) {
79 String layer = dcaeLoc.getDcaeLayer();
80 if ( layer != null && layer.contains(centralDcaeLayerName) ) {
81 this.hasCentral = true;
83 graph.put(loc, layer);
91 public HashMap<String, String> getGraph() {
95 public void setGraph(HashMap<String, String> graph) {
99 public String put( String key, String val ) {
100 return graph.put(key, val);
103 public String get( String key ) {
104 return graph.get(key);
107 public Collection<String> getKeys() {
108 return graph.keySet();
110 public boolean hasCentral() {
113 public void setHasCentral(boolean hasCentral) {
114 this.hasCentral = hasCentral;
117 public String getCentralLoc() {
118 if ( ! hasCentral ) {
121 for( String loc : graph.keySet()) {
122 if ( graph.get(loc).contains(centralDcaeLayerName)) {
128 public boolean isEmpty() {
129 return graph.isEmpty();