2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.adapter.ansible;
25 import org.osgi.framework.BundleActivator;
26 import org.osgi.framework.BundleContext;
27 import org.osgi.framework.ServiceRegistration;
29 import org.openecomp.appc.Constants;
30 import org.openecomp.appc.adapter.ansible.impl.AnsibleAdapterImpl;
31 import org.openecomp.appc.configuration.Configuration;
32 import org.openecomp.appc.configuration.ConfigurationFactory;
33 import org.openecomp.appc.i18n.Msg;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
38 * This activator is used to initialize and terminate an instance of AnsibleAdapter class
40 * Author : Ashwin Sridharan
43 public class AnsibleActivator implements BundleActivator {
46 * The bundle registration
48 private ServiceRegistration registration = null;
51 * The reference to the actual implementation object that implements the services
53 private AnsibleAdapter adapter;
56 * The logger to be used
58 private static final EELFLogger logger = EELFManager.getInstance().getLogger(AnsibleActivator.class);
61 * The configuration object used to configure this bundle
63 private Configuration configuration;
66 * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
67 * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
69 * This method must complete and return to its caller in a timely manner.
73 * The execution context of the bundle being started.
74 * @throws java.lang.Exception
75 * If this method throws an exception, this bundle is marked as stopped and the Framework will remove
76 * this bundle's listeners, unregister all services registered by this bundle, and release all services
77 * used by this bundle.
78 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
81 public void start(BundleContext context) throws Exception {
83 logger.info("Starting bundle " + getName());
84 String appName = "APPC: ";
85 logger.info(Msg.COMPONENT_INITIALIZING, appName, "Ansible Adapter");
86 adapter = new AnsibleAdapterImpl();
88 if (registration == null) {
89 logger.info(Msg.REGISTERING_SERVICE, appName, adapter.getAdapterName(),
90 AnsibleAdapter.class.getSimpleName());
91 registration = context.registerService(AnsibleAdapter.class, adapter, null);
94 logger.info(Msg.COMPONENT_INITIALIZED, appName, "Ansible adapter");
98 * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
99 * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
100 * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
101 * call any Framework objects.
103 * This method must complete and return to its caller in a timely manner.
107 * The execution context of the bundle being stopped.
108 * @throws java.lang.Exception
109 * If this method throws an exception, the bundle is still marked as stopped, and the Framework will
110 * remove the bundle's listeners, unregister all services registered by the bundle, and release all
111 * services used by the bundle. *
112 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
115 public void stop(BundleContext context) throws Exception {
116 logger.info("Stopping bundle " + getName());
118 if (registration != null) {
119 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
120 logger.info(Msg.COMPONENT_TERMINATING, appName, "Ansible adapter");
121 logger.info(Msg.UNREGISTERING_SERVICE, appName, adapter.getAdapterName());
122 registration.unregister();
124 logger.info(Msg.COMPONENT_TERMINATED, appName, "Ansible adapter");
128 public String getName() {
129 return "APPC Ansible Adapter";