* See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.openo.commontosca.catalog;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.jaxrs.config.BeanConfig;
 import io.swagger.jaxrs.listing.ApiListingResource;
 
-import java.util.EnumSet;
-
-import javax.servlet.DispatcherType;
-
 import org.eclipse.jetty.servlets.CrossOriginFilter;
 import org.glassfish.jersey.media.multipart.MultiPartFeature;
 import org.openo.commontosca.catalog.common.Config;
 import org.openo.commontosca.catalog.db.entity.PackageData;
 import org.openo.commontosca.catalog.db.entity.ServiceTemplateData;
 import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData;
+import org.openo.commontosca.catalog.db.hibernate.HibernateBundleAgent;
 import org.openo.commontosca.catalog.health.ConsoleHealthCheck;
 import org.openo.commontosca.catalog.resources.PackageResource;
 import org.openo.commontosca.catalog.resources.TemplateResource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.EnumSet;
+import javax.servlet.DispatcherType;
+
+
+
 
 public class CatalogApp extends Application<CatalogAppConfiguration> {
 
   public String getName() {
     return "OPENO-Catalog";
   }
-
-  private final HibernateBundle<CatalogAppConfiguration> bundle =
-      new HibernateBundle<CatalogAppConfiguration>(ServiceTemplateData.class, PackageData.class,
-          NodeTemplateData.class, ServiceTemplateMappingData.class) {
-        @Override
-        public DataSourceFactory getDataSourceFactory(CatalogAppConfiguration configuration) {
-          return configuration.getDataSourceFactory();
-        }
-      };
-
+  private final HibernateBundleAgent bundle = new HibernateBundleAgent();
   @Override
   public void initialize(Bootstrap<CatalogAppConfiguration> bootstrap) {
     bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
     initDb(bootstrap);
   }
 
-  private void initDao() {
-    DaoManager.getInstance().setSessionFactory(bundle.getSessionFactory());
-  }
+  //  private void initDao() {
+  //    DaoManager.getInstance().setSessionFactory(bundle.getSessionFactory());
+  //  }
 
   private void initDb(Bootstrap<CatalogAppConfiguration> bootstrap) {
     bootstrap.addBundle(bundle);
     MsbAddrConfig.setMsbAddress(configuration.getMsbServerAddr());
     HttpServerAddrConfig.setHttpServerAddress(configuration.getHttpServerAddr());
     HttpServerPathConfig.setHttpServerPath(configuration.getHttpServerPath());
-    initDao();
+    //initDao();
     final ConsoleHealthCheck healthCheck = new ConsoleHealthCheck(configuration.getTemplate());
     environment.healthChecks().register("template", healthCheck);
 
 
 package org.openo.commontosca.catalog.db.dao;
 
 import org.hibernate.SessionFactory;
+
 import org.openo.commontosca.catalog.db.common.CatalogResuorceType;
+import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
 
 /**
  * DAO manager class.
    * @param type data type
    * @return BaseDao<?>
    */
-  public BaseDao<?> getDao(String type) {
+  public BaseDao<?> getDao(String type) throws CatalogResourceException{
+    if (sessionFactory == null) {
+      throw new CatalogResourceException("errorMsg:database connect init faild!");
+    }
     switch (CatalogResuorceType.getType(type)) {
       case SERVICETEMPLATE:
         return getServiceTemplateDao();
 
--- /dev/null
+/**
+ * Copyright 2016 [ZTE] and others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.commontosca.catalog.db.hibernate;
+
+import io.dropwizard.ConfiguredBundle;
+import io.dropwizard.setup.Bootstrap;
+import io.dropwizard.setup.Environment;
+
+import org.openo.commontosca.catalog.CatalogAppConfiguration;
+import org.openo.commontosca.catalog.db.dao.DaoManager;
+import org.openo.commontosca.catalog.db.entity.NodeTemplateData;
+import org.openo.commontosca.catalog.db.entity.PackageData;
+import org.openo.commontosca.catalog.db.entity.ServiceTemplateData;
+import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HibernateBundleAgent implements ConfiguredBundle<CatalogAppConfiguration> {
+
+  private final HibernateBundleExt bundle = new HibernateBundleExt(ServiceTemplateData.class,
+      PackageData.class, NodeTemplateData.class, ServiceTemplateMappingData.class);
+  private static final Logger LOGGER = LoggerFactory.getLogger(HibernateBundleAgent.class);
+
+  @Override
+  public void run(final CatalogAppConfiguration configuration, final Environment environment)
+      throws Exception {
+    Thread thread = new Thread(new Runnable() {
+      int retry = 0;
+      boolean flag = true;
+
+      public void run() {
+        while (retry < 1000) {
+          LOGGER.info("init hibernateBundle.retry:" + retry);
+          retry++;
+          try {
+            bundle.runExt(configuration, environment);
+          } catch (Exception e1) {
+            flag = false;
+            LOGGER.warn(
+                "init hibernateBundle failed, sleep 15S and try again.errorMsg:" + e1.getMessage());
+            threadSleep(15000);
+          }
+          if (flag) {
+            LOGGER.info("init hibernateBundle success!");
+            initDao();
+            break;
+          }
+        }
+      }
+    });
+    thread.setName("init hibernateBundle");
+    thread.start();
+  }
+
+  private void initDao() {
+    DaoManager.getInstance().setSessionFactory(bundle.getSessionFactory());
+  }
+
+  private void threadSleep(int second) {
+    LOGGER.info("start sleep ....");
+    try {
+      Thread.sleep(second);
+    } catch (InterruptedException error) {
+      LOGGER.error("thread sleep error.errorMsg:" + error.getMessage());
+    }
+    LOGGER.info("sleep end .");
+  }
+
+  @Override
+  public void initialize(Bootstrap<?> bootstrap) {
+    bundle.initializeExt(bootstrap);
+  }
+  //
+  // public SessionFactory getSessionFactory() {
+  // return bundle.getSessionFactory();
+  // }
+}
 
--- /dev/null
+/**
+ * Copyright 2016 [ZTE] and others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.commontosca.catalog.db.hibernate;
+
+import com.google.common.collect.ImmutableList;
+
+import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
+
+import io.dropwizard.db.DataSourceFactory;
+import io.dropwizard.hibernate.HibernateBundle;
+import io.dropwizard.hibernate.SessionFactoryFactory;
+import io.dropwizard.setup.Bootstrap;
+import io.dropwizard.setup.Environment;
+
+import org.hibernate.SessionFactory;
+import org.openo.commontosca.catalog.CatalogAppConfiguration;
+
+
+public class HibernateBundleExt extends HibernateBundle<CatalogAppConfiguration> {
+
+  private static final String DEFAULT_NAME = "hibernate";
+
+  private SessionFactory sessionFactory;
+
+  private final ImmutableList<Class<?>> entities;
+  private final SessionFactoryFactory sessionFactoryFactory;
+
+  protected HibernateBundleExt(Class<?> entity, Class<?>... entities) {
+    this(ImmutableList.<Class<?>>builder().add(entity).add(entities).build(),
+        new SessionFactoryFactory());
+  }
+
+  protected HibernateBundleExt(ImmutableList<Class<?>> entities,
+      SessionFactoryFactory sessionFactoryFactory) {
+    super(entities, sessionFactoryFactory);
+    this.entities = entities;
+    this.sessionFactoryFactory = sessionFactoryFactory;
+  }
+
+  public final void initializeExt(Bootstrap<?> bootstrap) {
+    bootstrap.getObjectMapper().registerModule(createHibernate4Module());
+  }
+
+  /**
+   * Override to configure the {@link Hibernate4Module}.
+   */
+  protected Hibernate4Module createHibernate4Module() {
+    return new Hibernate4Module();
+  }
+
+  protected String name() {
+    return DEFAULT_NAME;
+  }
+
+  public final void runExt(CatalogAppConfiguration configuration, Environment environment)
+      throws Exception {
+    final DataSourceFactory dbConfig = getDataSourceFactory(configuration);
+    this.sessionFactory =
+        sessionFactoryFactory.build(this, environment, dbConfig, entities, name());
+
+  }
+
+  public SessionFactory getSessionFactory() {
+    return sessionFactory;
+  }
+
+
+  @Override
+  public DataSourceFactory getDataSourceFactory(CatalogAppConfiguration configuration) {
+    return configuration.getDataSourceFactory();
+  }
+
+}
 
--- /dev/null
+/**
+ * Copyright 2016 [ZTE] and others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.commontosca.catalog.externalservice.msb;
+
+import java.io.Serializable;
+
+public class ApiRouteInfo implements Serializable {
+  private static final long serialVersionUID = 1L;
+  private String serviceName;
+  private String version = "";
+  private String url;
+  private String apiJson = "";
+  private String apiJsonType = "1";
+  private String metricsUrl = "";
+  private String control = "0";
+  private String status = "1";
+
+  private RouteServer []servers;
+
+
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  public String getVersion() {
+    return version;
+  }
+
+  public void setVersion(String version) {
+    this.version = version;
+  }
+
+  public String getApiJson() {
+    return apiJson;
+  }
+
+  public void setApiJson(String apiJson) {
+    this.apiJson = apiJson;
+  }
+
+  public String getUrl() {
+    return url;
+  }
+
+  public void setUrl(String url) {
+    this.url = url;
+  }
+
+  public RouteServer[] getServers() {
+    return servers;
+  }
+
+  public void setServers(RouteServer[] servers) {
+    this.servers = servers;
+  }
+
+  public String getApiJsonType() {
+    return apiJsonType;
+  }
+
+  public void setApiJsonType(String apiJsonType) {
+    this.apiJsonType = apiJsonType;
+  }
+
+  public String getMetricsUrl() {
+    return metricsUrl;
+  }
+
+  public void setMetricsUrl(String metricsUrl) {
+    this.metricsUrl = metricsUrl;
+  }
+
+  public String getControl() {
+    return control;
+  }
+
+  public void setControl(String control) {
+    this.control = control;
+  }
+
+  public String getStatus() {
+    return status;
+  }
+
+  public void setStatus(String status) {
+    this.status = status;
+  }
+}
 
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.openo.commontosca.catalog.externalservice.msb;
 
 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
 import org.glassfish.jersey.client.ClientConfig;
-import org.openo.commontosca.catalog.db.util.CatalogDbUtil;
+
 import org.openo.commontosca.catalog.common.Config;
+import org.openo.commontosca.catalog.db.util.CatalogDbUtil;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
   /**
    * register service to MSB.
+   * 
    * @param entity ServiceRegisterEntity
    * @return boolean
    */
     ClientConfig config = new ClientConfig();
     LOG.info("microservice register body:" + CatalogDbUtil.objectToString(entity));
     try {
-      MicroserviceBusRest resourceserviceproxy =
-          ConsumerFactory.createConsumer(Config.getConfigration().getMsbServerAddr(), config,
-              MicroserviceBusRest.class);
+      MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer(
+          Config.getConfigration().getMsbServerAddr(), config, MicroserviceBusRest.class);
       resourceserviceproxy.registerServce("false", entity);
     } catch (Exception e1) {
       LOG.error("microservice register failed!" + e1.getMessage());
     }
     return true;
   }
+
+  public static ApiRouteInfo queryApiRouteInfo(String serviceName, String version) {
+    ClientConfig config = new ClientConfig();
+    LOG.info("microservice register body:" + "serviceName:" + serviceName + " version:" + version);
+    ApiRouteInfo apiRouteInfo = null;
+    try {
+      MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer(
+          Config.getConfigration().getMsbServerAddr(), config, MicroserviceBusRest.class);
+      apiRouteInfo = resourceserviceproxy.queryApiRouteInfo(serviceName, version);
+    } catch (Exception e1) {
+      LOG.error("query api route failed!" + e1.getMessage());
+
+    }
+    return apiRouteInfo;
+  }
 }
 
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.openo.commontosca.catalog.externalservice.msb;
 
 import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
   @Produces(MediaType.APPLICATION_JSON)
   public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate,
       ServiceRegisterEntity entity) throws Exception;
+
+  @Path("")
+  @GET
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  public ApiRouteInfo queryApiRouteInfo(@PathParam("serviceName") String serviceName,
+      @PathParam("version") String version ) throws Exception;
 }
 
--- /dev/null
+/**
+ * Copyright 2016 [ZTE] and others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.commontosca.catalog.externalservice.msb;
+
+import java.io.Serializable;
+
+public class RouteServer implements Serializable {
+  private static final long serialVersionUID = 1L;
+  private String ip;
+  private int weight;
+
+  public String getIp() {
+    return ip;
+  }
+
+  public void setIp(String ip) {
+    this.ip = ip;
+  }
+
+
+
+  public int getWeight() {
+    return weight;
+  }
+
+  public void setWeight(int weight) {
+    this.weight = weight;
+  }
+
+  public RouteServer() {
+
+  }
+
+  public RouteServer(String ip) {
+    this.ip = ip;
+    this.weight = 0;
+  }
+
+}
 
         </init-param>
         <init-param>
             <param-name>listings</param-name>
-            <param-value>false</param-value>
+            <param-value>true</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>