2 * Copyright 2016-2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.aai.esr.hibernate;
19 import io.dropwizard.ConfiguredBundle;
20 import io.dropwizard.setup.Bootstrap;
21 import io.dropwizard.setup.Environment;
23 import org.onap.aai.esr.ExtsysAppConfiguration;
24 import org.onap.aai.esr.dao.DaoManager;
25 import org.onap.aai.esr.entity.db.BaseData;
26 import org.onap.aai.esr.entity.db.EmsData;
27 import org.onap.aai.esr.entity.db.SdncData;
28 import org.onap.aai.esr.entity.db.VimData;
29 import org.onap.aai.esr.entity.db.VnfmData;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class HibernateBundleAgent implements ConfiguredBundle<ExtsysAppConfiguration> {
35 private final HibernateBundleExt bundle = new HibernateBundleExt(EmsData.class, BaseData.class, VimData.class,
36 VnfmData.class, SdncData.class);
37 private static final Logger LOGGER = LoggerFactory.getLogger(HibernateBundleAgent.class);
40 public void run(final ExtsysAppConfiguration configuration, final Environment environment)
42 Thread thread = new Thread(new Runnable() {
46 while (retry < 1000) {
47 LOGGER.info("init hibernateBundle.retry:" + retry);
50 bundle.runExt(configuration, environment);
51 } catch (Exception e1) {
54 "init hibernateBundle failed, sleep 15S and try again.errorMsg:" + e1.getMessage());
58 LOGGER.info("init hibernateBundle success!");
65 thread.setName("init hibernateBundle");
69 private void initDao() {
70 DaoManager.getInstance().setSessionFactory(bundle.getSessionFactory());
73 private void threadSleep(int second) {
74 LOGGER.info("start sleep ....");
77 } catch (InterruptedException error) {
78 LOGGER.error("thread sleep error.errorMsg:" + error.getMessage());
80 LOGGER.info("sleep end .");
84 public void initialize(Bootstrap<?> bootstrap) {
85 bundle.initializeExt(bootstrap);
88 // public SessionFactory getSessionFactory() {
89 // return bundle.getSessionFactory();