Logging related enhancements.
[controller.git] / opendaylight / configuration / implementation / src / main / java / org / opendaylight / controller / configuration / internal / ConfigurationImpl.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.configuration.internal;
11
12 import java.util.Collections;
13 import java.util.HashSet;
14 import java.util.Set;
15
16 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
17 import org.opendaylight.controller.configuration.IConfigurationAware;
18 import org.opendaylight.controller.configuration.IConfigurationService;
19 import org.opendaylight.controller.sal.utils.StatusCode;
20 import org.opendaylight.controller.sal.utils.Status;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * @file   ConfigurationImpl.java
26  *
27  * @brief  Backend functionality for all Configuration related tasks.
28  *
29  *
30  */
31
32 public class ConfigurationImpl implements IConfigurationService {
33     private static final Logger logger = LoggerFactory
34             .getLogger(ConfigurationImpl.class);
35     private IClusterGlobalServices clusterServices;
36     /*
37      * Collection containing the configuration objects.
38      * This is configuration world: container names (also the map key)
39      * are maintained as they were configured by user, same case
40      */
41     private Set<IConfigurationAware> configurationAwareList = (Set<IConfigurationAware>) Collections
42             .synchronizedSet(new HashSet<IConfigurationAware>());
43
44     
45     public int getConfigurationAwareListSize() {
46         return this.configurationAwareList.size();
47     }
48     
49     public void addConfigurationAware(IConfigurationAware configurationAware) {
50         if (!this.configurationAwareList.contains(configurationAware)) {
51             this.configurationAwareList.add(configurationAware);
52         }
53     }
54
55     public void removeConfigurationAware(IConfigurationAware configurationAware) {
56         this.configurationAwareList.remove(configurationAware);
57     }
58
59     public void setClusterServices(IClusterGlobalServices i) {
60         this.clusterServices = i;
61         logger.debug("IClusterServices set");
62     }
63
64     public void unsetClusterServices(IClusterGlobalServices i) {
65         if (this.clusterServices == i) {
66             this.clusterServices = null;
67             logger.debug("IClusterServices Unset");
68         }
69     }
70
71     public void init() {
72         logger.info("ContainerManager startup....");
73     }
74
75     public void destroy() {
76         // Clear local states
77         this.configurationAwareList.clear();
78     }
79
80     @Override
81     public Status saveConfigurations() {
82         boolean success = true;
83         for (IConfigurationAware configurationAware : configurationAwareList) {
84                 Status status = configurationAware.saveConfiguration();
85             if (!status.isSuccess()) {
86                 success = false;
87                 logger.info("Failed to save config for {}",
88                                 configurationAware.getClass().getName());
89             }
90         }
91         if (success) {
92             return new Status(StatusCode.SUCCESS, null);
93         } else {
94             return new Status(StatusCode.INTERNALERROR,
95                         "Failed to Save All Configurations");
96         }
97     }
98
99 }