2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.rest;
26 import org.onap.appc.Constants;
27 import org.onap.appc.adapter.rest.impl.RestAdapterImpl;
28 import org.onap.appc.configuration.Configuration;
29 import org.onap.appc.configuration.ConfigurationFactory;
30 import org.onap.appc.i18n.Msg;
31 import org.osgi.framework.BundleActivator;
32 import org.osgi.framework.BundleContext;
33 import org.osgi.framework.ServiceRegistration;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
40 * This activator is used to initialize and terminate the connection pool to one or more providers.
42 * The CDP abstraction layer supports multiple types of providers, with each provider supporting multiple tenants. The
43 * "connection" to a specific tenant on a specific provider is represented by a "context" object. These context objects
44 * are authenticated to a specific tenant on the provider, but can be reused from one request to another. Contexts are
45 * slow to set up and are resource intensive, so they are cached. However, the contexts for a specific tenant on a
46 * specific provider must be cached separately.
49 * Activation of the bundle creates an empty cache which is organized first by provider type, then by tenant name, with
50 * the contents being an empty pool of contexts for that provider/tenant combination. The pool is created on first use,
51 * and retained for as long as the bundle is active.
54 * When the bundle is deactivated, the cache is torn down with all contexts being closed.
57 public class RestActivator implements BundleActivator {
60 * The bundle registration
62 private ServiceRegistration registration = null;
65 * The reference to the actual implementation object that implements the services
67 private RestAdapter adapter;
70 * The logger to be used
72 private final EELFLogger logger = EELFManager.getInstance().getLogger(RestActivator.class);
75 * The configuration object used to configure this bundle
77 private Configuration configuration;
80 * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
81 * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
83 * This method must complete and return to its caller in a timely manner.
87 * The execution context of the bundle being started.
88 * @throws java.lang.Exception
89 * If this method throws an exception, this bundle is marked as stopped and the Framework will remove
90 * this bundle's listeners, unregister all services registered by this bundle, and release all services
91 * used by this bundle.
92 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
95 public void start(BundleContext context) throws Exception {
96 logger.info("Starting bundle " + getName());
98 configuration = ConfigurationFactory.getConfiguration();
99 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
100 logger.info(Msg.COMPONENT_INITIALIZING, appName, "rest adapter");
101 adapter = new RestAdapterImpl();
102 if (registration == null) {
103 logger.info(Msg.REGISTERING_SERVICE, appName, adapter.getAdapterName(),RestAdapter.class.getSimpleName());
105 registration = context.registerService(RestAdapter.class, adapter, null);
108 logger.info(Msg.COMPONENT_INITIALIZED, appName, "REST adapter");
112 * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
113 * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
114 * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
115 * call any Framework objects.
117 * This method must complete and return to its caller in a timely manner.
121 * The execution context of the bundle being stopped.
122 * @throws java.lang.Exception
123 * If this method throws an exception, the bundle is still marked as stopped, and the Framework will
124 * remove the bundle's listeners, unregister all services registered by the bundle, and release all
125 * services used by the bundle. *
126 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
129 public void stop(BundleContext context) throws Exception {
130 logger.info("Stopping bundle " + getName());
132 if (registration != null) {
133 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
134 logger.info(Msg.COMPONENT_TERMINATING, appName, "REST adapter");
135 logger.info(Msg.UNREGISTERING_SERVICE, appName, adapter.getAdapterName());
136 registration.unregister();
138 logger.info(Msg.COMPONENT_TERMINATED, appName, "REST adapter");
142 public String getName() {
143 return "APPC IaaS adapter";