d47aca8135e69a0037d82080e94ffa69771b33a5
[controller.git] / opendaylight / containermanager / implementation / src / main / java / org / opendaylight / controller / containermanager / internal / ContainerManager.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 /**
11  * @file   ContainerManager.java
12  *
13  * @brief  Manage one or many Containers
14  *
15  *
16  */
17 package org.opendaylight.controller.containermanager.internal;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
28 import org.opendaylight.controller.containermanager.IContainerManager;
29 import org.opendaylight.controller.sal.core.IContainerAware;
30 import org.opendaylight.controller.sal.core.IContainerListener;
31 import org.opendaylight.controller.sal.utils.GlobalConstants;
32 import org.opendaylight.controller.sal.utils.Status;
33
34 public class ContainerManager implements IContainerManager {
35     private static final Logger logger = LoggerFactory
36             .getLogger(ContainerManager.class);
37     private IClusterGlobalServices clusterServices;
38     /*
39      * Collection containing the configuration objects.
40      * This is configuration world: container names (also the map key)
41      * are maintained as they were configured by user, same case
42      */
43     private Set<IContainerAware> iContainerAware = (Set<IContainerAware>) Collections
44             .synchronizedSet(new HashSet<IContainerAware>());
45     private Set<IContainerListener> iContainerListener = Collections
46             .synchronizedSet(new HashSet<IContainerListener>());
47
48     void setIContainerListener(IContainerListener s) {
49         if (this.iContainerListener != null) {
50             this.iContainerListener.add(s);
51         }
52     }
53
54     void unsetIContainerListener(IContainerListener s) {
55         if (this.iContainerListener != null) {
56             this.iContainerListener.remove(s);
57         }
58     }
59
60     public void setIContainerAware(IContainerAware iContainerAware) {
61         if (!this.iContainerAware.contains(iContainerAware)) {
62             this.iContainerAware.add(iContainerAware);
63             // Now call the container creation for all the known containers so
64             // far
65             List<String> containerDB = getContainerNames();
66             if (containerDB != null) {
67                 for (int i = 0; i < containerDB.size(); i++) {
68                     iContainerAware.containerCreate(containerDB.get(i));
69                 }
70             }
71         }
72     }
73
74     public void unsetIContainerAware(IContainerAware iContainerAware) {
75         this.iContainerAware.remove(iContainerAware);
76         // There is no need to do cleanup of the component when
77         // unregister because it will be taken care by the Containerd
78         // component itself
79     }
80
81     public void setClusterServices(IClusterGlobalServices i) {
82         this.clusterServices = i;
83         logger.debug("IClusterServices set");
84     }
85
86     public void unsetClusterServices(IClusterGlobalServices i) {
87         if (this.clusterServices == i) {
88             this.clusterServices = null;
89             logger.debug("IClusterServices Unset");
90         }
91     }
92
93     public void init() {
94         logger.info("ContainerManager startup....");
95     }
96
97     public void destroy() {
98         // Clear local states
99         this.iContainerAware.clear();
100         this.iContainerListener.clear();
101
102         logger.info("ContainerManager Shutdown....");
103     }
104
105     @Override
106     public List<String> getContainerNames() {
107         /*
108          * Return container names as they were configured by user (case sensitive)
109          * along with the default container
110          */
111         List<String> containerNameList = new ArrayList<String>();
112         containerNameList.add(GlobalConstants.DEFAULT.toString());
113         return containerNameList;
114     }
115
116     @Override
117     public boolean hasNonDefaultContainer() {
118         return false;
119     }
120
121     @Override
122     public Status saveContainerConfig() {
123         return null;
124     }
125
126 }