31172a3e331d9b9cc6af74a1a7226c6cd2ea7a59
[genius.git] / fcapsapplication / fcapsapplication-impl / src / main / java / org / opendaylight / genius / fcapsapp / performancecounter / NodeUpdateCounter.java
1 /*
2  * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.genius.fcapsapp.performancecounter;
9
10 import java.util.HashMap;
11 import java.util.HashSet;
12 import java.util.Map;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 @Singleton
19 public class NodeUpdateCounter {
20
21     private static final Logger LOG = LoggerFactory.getLogger(NodeUpdateCounter.class);
22     private String nodeListEFSCountStr;
23     private static HashSet<String> dpnList = new HashSet<>();
24     public final PMAgent agent;
25     private final Map<String, String> countersMap = new HashMap<>();
26
27     @Inject
28     public NodeUpdateCounter(final PMAgent agent) {
29         this.agent = agent;
30     }
31
32     public void nodeAddedNotification(String node, String hostName) {
33         dpnList.add(node);
34         sendNodeUpdation(dpnList.size(), hostName);
35     }
36
37     public void nodeRemovedNotification(String node, String hostName) {
38         dpnList.remove(node);
39         sendNodeUpdation(dpnList.size(), hostName);
40     }
41
42     private void sendNodeUpdation(Integer count, String hostName) {
43
44         if (hostName != null) {
45             nodeListEFSCountStr = "Node_" + hostName + "_NumberOfEFS";
46             LOG.debug("NumberOfEFS: {} dpnList.size {}", nodeListEFSCountStr, count);
47
48             countersMap.put("NumberOfEFS:" + nodeListEFSCountStr, "" + count);
49             agent.connectToPMAgent(countersMap);
50         } else {
51             LOG.error("Hostname is null upon NumberOfEFS counter");
52         }
53     }
54
55     public boolean isDpnConnectedLocal(String node) {
56         return dpnList.contains(node);
57     }
58 }