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.onap.appc.adapter.ansible;
27 import org.osgi.framework.BundleActivator;
28 import org.osgi.framework.BundleContext;
29 import org.osgi.framework.ServiceRegistration;
31 import org.onap.appc.Constants;
32 import org.onap.appc.adapter.ansible.impl.AnsibleAdapterImpl;
33 import org.onap.appc.configuration.Configuration;
34 import org.onap.appc.configuration.ConfigurationFactory;
35 import org.onap.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 public class AnsibleActivator implements BundleActivator {
45 * The bundle registration
47 private ServiceRegistration registration = null;
50 * The reference to the actual implementation object that implements the services
52 private AnsibleAdapter adapter;
55 * The logger to be used
57 private final EELFLogger logger = EELFManager.getInstance().getLogger(AnsibleActivator.class);
60 * The configuration object used to configure this bundle
62 private final Configuration configuration = ConfigurationFactory.getConfiguration();
65 * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
66 * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
68 * This method must complete and return to its caller in a timely manner.
71 * @param context The execution context of the bundle being started.
72 * @throws java.lang.Exception If this method throws an exception, this bundle is marked as stopped and the
73 * Framework will remove this bundle's listeners, unregister all services registered
74 * by this bundle, and release all services used by this bundle.
75 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
78 public void start(BundleContext context) throws Exception {
80 logger.info("Starting bundle " + getName());
81 String appName = "APPC: ";
82 logger.info(Msg.COMPONENT_INITIALIZING, appName, "Ansible Adapter");
83 adapter = new AnsibleAdapterImpl();
85 if (registration == null) {
86 logger.info(Msg.REGISTERING_SERVICE, appName, adapter.getAdapterName(),
87 AnsibleAdapter.class.getSimpleName());
88 registration = context.registerService(AnsibleAdapter.class, adapter, null);
91 logger.info(Msg.COMPONENT_INITIALIZED, appName, "Ansible adapter");
95 * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
96 * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
97 * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
98 * call any Framework objects.
100 * This method must complete and return to its caller in a timely manner.
103 * @param context The execution context of the bundle being stopped.
104 * @throws java.lang.Exception If this method throws an exception, the bundle is still marked as stopped, and the
105 * Framework will remove the bundle's listeners, unregister all services registered
106 * by the bundle, and release all services used by the bundle.
107 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
110 public void stop(BundleContext context) throws Exception {
111 logger.info("Stopping bundle " + getName());
113 if (registration != null) {
114 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
115 logger.info(Msg.COMPONENT_TERMINATING, appName, "Ansible adapter");
116 logger.info(Msg.UNREGISTERING_SERVICE, appName, adapter.getAdapterName());
117 registration.unregister();
119 logger.info(Msg.COMPONENT_TERMINATED, appName, "Ansible adapter");
123 public String getName() {
124 return "APPC Ansible Adapter";