Remove commented out logger in APPC
[appc.git] / appc-adapters / appc-chef-adapter / appc-chef-adapter-bundle / src / main / java / org / openecomp / appc / adapter / chef / ChefActivator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.adapter.chef;
23
24 import org.openecomp.appc.Constants;
25 import org.openecomp.appc.adapter.chef.impl.ChefAdapterImpl;
26 import org.openecomp.appc.configuration.Configuration;
27 import org.openecomp.appc.configuration.ConfigurationFactory;
28 import org.openecomp.appc.i18n.Msg;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
31 import org.osgi.framework.BundleActivator;
32 import org.osgi.framework.BundleContext;
33 import org.osgi.framework.ServiceRegistration;
34
35 /**
36  * This activator is used to initialize and terminate the connection pool to one or more providers.
37  * <p>
38  * The CDP abstraction layer supports multiple types of providers, with each provider supporting multiple tenants. The
39  * "connection" to a specific tenant on a specific provider is represented by a "context" object. These context objects
40  * are authenticated to a specific tenant on the provider, but can be reused from one request to another. Contexts are
41  * slow to set up and are resource intensive, so they are cached. However, the contexts for a specific tenant on a
42  * specific provider must be cached separately.
43  * </p>
44  * <p>
45  * Activation of the bundle creates an empty cache which is organized first by provider type, then by tenant name, with
46  * the contents being an empty pool of contexts for that provider/tenant combination. The pool is created on first use,
47  * and retained for as long as the bundle is active.
48  * </p>
49  * <p>
50  * When the bundle is deactivated, the cache is torn down with all contexts being closed.
51  * </p>
52  */
53 public class ChefActivator implements BundleActivator {
54
55     /**
56      * The bundle registration
57      */
58     private ServiceRegistration registration = null;
59
60     /**
61      * The reference to the actual implementation object that implements the services
62      */
63     private ChefAdapter adapter;
64
65     /**
66      * The logger to be used
67      */
68     private static final EELFLogger logger = EELFManager.getInstance().getLogger(ChefActivator.class);
69
70     /**
71      * The configuration object used to configure this bundle
72      */
73     private Configuration configuration;
74
75     /**
76      * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
77      * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
78      * <p>
79      * This method must complete and return to its caller in a timely manner.
80      * </p>
81      * 
82      * @param context
83      *            The execution context of the bundle being started.
84      * @throws java.lang.Exception
85      *             If this method throws an exception, this bundle is marked as stopped and the Framework will remove
86      *             this bundle's listeners, unregister all services registered by this bundle, and release all services
87      *             used by this bundle.
88      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
89      */
90     @Override
91     public void start(BundleContext context) throws Exception {
92         logger.info("Starting bundle " + getName());
93
94         configuration = ConfigurationFactory.getConfiguration();
95         String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
96         logger.info(Msg.COMPONENT_INITIALIZING, appName, "chef adapter");
97         adapter = new ChefAdapterImpl(configuration.getProperties());
98         if (registration == null) {
99             logger.info(Msg.REGISTERING_SERVICE, appName, adapter.getAdapterName(),
100                 ChefAdapter.class.getSimpleName());
101             registration = context.registerService(ChefAdapter.class, adapter, null);
102         }
103
104         logger.info(Msg.COMPONENT_INITIALIZED, appName, "CHEF adapter");
105     }
106
107     /**
108      * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
109      * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
110      * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
111      * call any Framework objects.
112      * <p>
113      * This method must complete and return to its caller in a timely manner.
114      * </p>
115      * 
116      * @param context
117      *            The execution context of the bundle being stopped.
118      * @throws java.lang.Exception
119      *             If this method throws an exception, the bundle is still marked as stopped, and the Framework will
120      *             remove the bundle's listeners, unregister all services registered by the bundle, and release all
121      *             services used by the bundle. *
122      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
123      */
124     @Override
125     public void stop(BundleContext context) throws Exception {
126         logger.info("Stopping bundle " + getName());
127
128         if (registration != null) {
129             String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
130             logger.info(Msg.COMPONENT_TERMINATING, appName, "CHEF adapter");
131             logger.info(Msg.UNREGISTERING_SERVICE, appName, adapter.getAdapterName());
132             registration.unregister();
133             registration = null;
134             logger.info(Msg.COMPONENT_TERMINATED, appName, "CHEF adapter");
135         }
136     }
137
138     public String getName() {
139         return "APPC IaaS adapter";
140     }
141
142 }