Integration of fcaps applications
[vpnservice.git] / fcapsapplication / fcapsapplication-impl / src / main / java / org / opendaylight / vpnservice / fcapsapp / performancecounter / NodeUpdateCounter.java
1 /*
2  * Copyright (c) 2016 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.vpnservice.fcapsapp.performancecounter;
9
10
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 import java.lang.Integer;
14 import java.lang.String;
15 import java.net.InetAddress;
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.Map;
20
21 public class NodeUpdateCounter {
22
23     private static final Logger LOG = LoggerFactory.getLogger(NodeUpdateCounter.class);
24     private String nodeListEFSCountStr;
25     private static HashSet<String> dpnList = new HashSet<String>();
26     public static final PMAgent pmagent = new PMAgent();
27     Map<String, String> counter_map = new HashMap<String, String>();
28
29     public NodeUpdateCounter() {
30     }
31
32     public void nodeAddedNotification(String sNode,String hostName) {
33         dpnList.add(sNode);
34         sendNodeUpdation(dpnList.size(),hostName);
35     }
36
37     public void nodeRemovedNotification(String sNode,String hostName) {
38         dpnList.remove(sNode);
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:" + nodeListEFSCountStr + " dpnList.size " + count);
47
48             counter_map.put("NumberOfEFS:" + nodeListEFSCountStr, "" + count);
49             pmagent.connectToPMAgent(counter_map);
50         } else
51             LOG.error("Hostname is null upon NumberOfEFS counter");
52     }
53
54     public boolean isDpnConnectedLocal(String sNode) {
55         if (dpnList.contains(sNode))
56             return true;
57         return false;
58     }
59 }