BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / connectionmanager / implementation / src / main / java / org / opendaylight / controller / connectionmanager / scheme / AnyControllerScheme.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.connectionmanager.scheme;
9
10 import java.net.InetAddress;
11 import java.util.Set;
12
13 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
14 import org.opendaylight.controller.connectionmanager.ConnectionMgmtScheme;
15 import org.opendaylight.controller.sal.core.Node;
16
17 class AnyControllerScheme extends AbstractScheme {
18     private static AbstractScheme myScheme= null;
19
20     protected AnyControllerScheme(IClusterGlobalServices clusterServices) {
21         super(clusterServices, ConnectionMgmtScheme.ANY_CONTROLLER_ONE_MASTER);
22     }
23
24     public static AbstractScheme getScheme(IClusterGlobalServices clusterServices) {
25         if (myScheme == null) {
26             myScheme = new AnyControllerScheme(clusterServices);
27         }
28         return myScheme;
29     }
30
31     @Override
32     public boolean isConnectionAllowedInternal(Node node) {
33         Set <InetAddress> controllers = nodeConnections.get(node);
34         if (controllers == null || controllers.size() == 0) return true;
35         return (controllers.size() == 1 && controllers.contains(clusterServices.getMyAddress()));
36     }
37 }