Merge "Add password recovery procedure for default admin user"
[controller.git] / opendaylight / clustering / stub / src / main / java / org / opendaylight / controller / clustering / stub / internal / ClusterManagerCommon.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.clustering.stub.internal;
11
12 import java.util.ArrayList;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.net.UnknownHostException;
15 import java.net.InetAddress;
16 import java.util.List;
17 import java.util.Properties;
18 import java.util.Set;
19 import java.util.concurrent.ConcurrentMap;
20
21 import javax.transaction.HeuristicMixedException;
22 import javax.transaction.HeuristicRollbackException;
23 import javax.transaction.NotSupportedException;
24 import javax.transaction.RollbackException;
25 import javax.transaction.SystemException;
26 import javax.transaction.Transaction;
27 import javax.transaction.TransactionManager;
28
29 import org.opendaylight.controller.clustering.services.CacheConfigException;
30 import org.opendaylight.controller.clustering.services.CacheExistException;
31 import org.opendaylight.controller.clustering.services.CacheListenerAddException;
32 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
33 import org.opendaylight.controller.clustering.services.IClusterServices;
34 import org.opendaylight.controller.clustering.services.IClusterServicesCommon;
35 import org.opendaylight.controller.clustering.services.ICoordinatorChangeAware;
36 import org.opendaylight.controller.clustering.services.IListenRoleChange;
37 import org.opendaylight.controller.clustering.services.ListenRoleChangeAddException;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 import java.util.Dictionary;
42 import java.util.Collections;
43 import java.util.HashSet;
44 import org.apache.felix.dm.Component;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 public abstract class ClusterManagerCommon implements IClusterServicesCommon {
49     protected String containerName = "";
50     protected static final Logger logger = LoggerFactory
51             .getLogger(ClusterManagerCommon.class);
52     private InetAddress loopbackAddress;
53     private ConcurrentMap<String, ConcurrentMap<?, ?>> caches = new ConcurrentHashMap<String, ConcurrentMap<?, ?>>();
54
55     protected ClusterManagerCommon() throws UnknownHostException {
56         loopbackAddress = InetAddress.getByName("127.0.0.1");
57     }
58
59     /**
60      * Function called by the dependency manager when all the required
61      * dependencies are satisfied
62      *
63      */
64     void init(Component c) {
65         Dictionary props = c.getServiceProperties();
66         if (props != null) {
67             this.containerName = (String) props.get("containerName");
68             logger.debug("Running containerName: {}", this.containerName);
69         } else {
70             // In the Global instance case the containerName is empty
71             this.containerName = "";
72         }
73     }
74
75     /**
76      * Function called by the dependency manager when any of the required
77      * dependencies are going away
78      *
79      */
80     void destroy() {
81         // Clear the caches, will restart on the new life
82         this.caches.clear();
83     }
84
85     @Override
86     public ConcurrentMap<?, ?> createCache(String cacheName,
87             Set<IClusterServices.cacheMode> cMode) throws CacheExistException,
88             CacheConfigException {
89         ConcurrentMap<?, ?> res = this.caches.get(cacheName);
90         if (res == null) {
91             res = new ConcurrentHashMap<Object, Object>();
92             this.caches.put(cacheName, res);
93             return res;
94         }
95         throw new CacheExistException();
96     }
97
98     @Override
99     public ConcurrentMap<?, ?> getCache(String cacheName) {
100         return this.caches.get(cacheName);
101     }
102
103     @Override
104     public void destroyCache(String cacheName) {
105         this.caches.remove(cacheName);
106     }
107
108     @Override
109     public boolean existCache(String cacheName) {
110         return (this.caches.get(cacheName) != null);
111     }
112
113     @Override
114     public Set<String> getCacheList() {
115         return this.caches.keySet();
116     }
117
118     @Override
119     public Properties getCacheProperties(String cacheName) {
120         return null;
121     }
122
123     @Override
124     public void tbegin() throws NotSupportedException, SystemException {
125     }
126
127     @Override
128     public void tcommit() throws RollbackException, HeuristicMixedException,
129             HeuristicRollbackException, java.lang.SecurityException,
130             java.lang.IllegalStateException, SystemException {
131     }
132
133     @Override
134     public void trollback() throws java.lang.IllegalStateException,
135             java.lang.SecurityException, SystemException {
136     }
137
138     @Override
139     public Transaction tgetTransaction() throws SystemException {
140         return null;
141     }
142
143     @Override
144     public List<InetAddress> getClusteredControllers() {
145         List<InetAddress> res = new ArrayList<InetAddress>();
146         res.add(loopbackAddress);
147         return res;
148     }
149
150     @Override
151     public InetAddress getMyAddress() {
152         return loopbackAddress;
153     }
154
155     @Override
156     public InetAddress getCoordinatorAddress() {
157         return loopbackAddress;
158     }
159
160     @Override
161     public boolean amICoordinator() {
162         return true;
163     }
164 }