2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.adapter.ansible;
27 import org.osgi.framework.BundleActivator;
28 import org.osgi.framework.BundleContext;
29 import org.osgi.framework.ServiceRegistration;
31 import org.openecomp.appc.Constants;
32 import org.openecomp.appc.adapter.ansible.impl.AnsibleAdapterImpl;
33 import org.openecomp.appc.configuration.Configuration;
34 import org.openecomp.appc.configuration.ConfigurationFactory;
35 import org.openecomp.appc.i18n.Msg;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
40 * This activator is used to initialize and terminate an instance of AnsibleAdapter class
42 * Author : Ashwin Sridharan
45 public class AnsibleActivator implements BundleActivator {
48 * The bundle registration
50 private ServiceRegistration registration = null;
53 * The reference to the actual implementation object that implements the services
55 private AnsibleAdapter adapter;
58 * The logger to be used
60 private static final EELFLogger logger = EELFManager.getInstance().getLogger(AnsibleActivator.class);
63 * The configuration object used to configure this bundle
65 private Configuration configuration;
68 * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
69 * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
71 * This method must complete and return to its caller in a timely manner.
75 * The execution context of the bundle being started.
76 * @throws java.lang.Exception
77 * If this method throws an exception, this bundle is marked as stopped and the Framework will remove
78 * this bundle's listeners, unregister all services registered by this bundle, and release all services
79 * used by this bundle.
80 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
83 public void start(BundleContext context) throws Exception {
85 logger.info("Starting bundle " + getName());
86 String appName = "APPC: ";
87 logger.info(Msg.COMPONENT_INITIALIZING, appName, "Ansible Adapter");
88 adapter = new AnsibleAdapterImpl();
90 if (registration == null) {
91 logger.info(Msg.REGISTERING_SERVICE, appName, adapter.getAdapterName(),
92 AnsibleAdapter.class.getSimpleName());
93 registration = context.registerService(AnsibleAdapter.class, adapter, null);
96 logger.info(Msg.COMPONENT_INITIALIZED, appName, "Ansible adapter");
100 * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
101 * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
102 * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
103 * call any Framework objects.
105 * This method must complete and return to its caller in a timely manner.
109 * The execution context of the bundle being stopped.
110 * @throws java.lang.Exception
111 * If this method throws an exception, the bundle is still marked as stopped, and the Framework will
112 * remove the bundle's listeners, unregister all services registered by the bundle, and release all
113 * services used by the bundle. *
114 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
117 public void stop(BundleContext context) throws Exception {
118 logger.info("Stopping bundle " + getName());
120 if (registration != null) {
121 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
122 logger.info(Msg.COMPONENT_TERMINATING, appName, "Ansible adapter");
123 logger.info(Msg.UNREGISTERING_SERVICE, appName, adapter.getAdapterName());
124 registration.unregister();
126 logger.info(Msg.COMPONENT_TERMINATED, appName, "Ansible adapter");
130 public String getName() {
131 return "APPC Ansible Adapter";