3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
11 * @file ContainerManager.java
13 * @brief Manage one or many Containers
17 package org.opendaylight.controller.containermanager.internal;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.HashSet;
22 import java.util.List;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
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;
34 public class ContainerManager implements IContainerManager {
35 private static final Logger logger = LoggerFactory
36 .getLogger(ContainerManager.class);
37 private IClusterGlobalServices clusterServices;
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
43 private Set<IContainerAware> iContainerAware = (Set<IContainerAware>) Collections
44 .synchronizedSet(new HashSet<IContainerAware>());
45 private Set<IContainerListener> iContainerListener = Collections
46 .synchronizedSet(new HashSet<IContainerListener>());
48 void setIContainerListener(IContainerListener s) {
49 if (this.iContainerListener != null) {
50 this.iContainerListener.add(s);
54 void unsetIContainerListener(IContainerListener s) {
55 if (this.iContainerListener != null) {
56 this.iContainerListener.remove(s);
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
65 List<String> containerDB = getContainerNames();
66 if (containerDB != null) {
67 for (int i = 0; i < containerDB.size(); i++) {
68 iContainerAware.containerCreate(containerDB.get(i));
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
81 public void setClusterServices(IClusterGlobalServices i) {
82 this.clusterServices = i;
83 logger.debug("IClusterServices set");
86 public void unsetClusterServices(IClusterGlobalServices i) {
87 if (this.clusterServices == i) {
88 this.clusterServices = null;
89 logger.debug("IClusterServices Unset");
94 logger.info("ContainerManager startup....");
97 public void destroy() {
99 this.iContainerAware.clear();
100 this.iContainerListener.clear();
102 logger.info("ContainerManager Shutdown....");
106 public List<String> getContainerNames() {
108 * Return container names as they were configured by user (case sensitive)
109 * along with the default container
111 List<String> containerNameList = new ArrayList<String>();
112 containerNameList.add(GlobalConstants.DEFAULT.toString());
113 return containerNameList;
117 public boolean hasNonDefaultContainer() {
122 public Status saveContainerConfig() {