ResourceInitializerService implements IResourceInitializerService { @Override public void initResource() { final String serverMobId = Configuration.getString(Constants.SERENGETI_SERVER_VM_MOBID); logger.info("server mob id:" + serverMobId); final VcVirtualMachine serverVm = VcResourceUtils.findServerVM(serverMobId); final VcResourcePool vcRP = VcResourceUtils.getVmRp(serverVm); String clusterName = VcResourceUtils.getRpCluster(vcRP).getName(); String vcRPName = vcRP.getName(); logger.info("vc rp: " + vcRPName + ", cluster: " + clusterName); String networkName = VcResourceUtils.getVMNetwork(serverVm); Map<DatastoreType, List<String>> dsNames = VcResourceUtils.getVmDatastore(serverVm); if (rpSvc.isDeployedUnderCluster(clusterName, vcRPName)) { vcRPName = ""; } addResourceIntoDB(clusterName, vcRPName, networkName, dsNames); }  IServerInfoDAO getServerInfoDao(); @Autowired void setServerInfoDao(IServerInfoDAO serverInfoDao); IResourcePoolService getRpSvc(); @Autowired void setRpSvc(IResourcePoolService rpSvc); IDatastoreService getDsSvc(); @Autowired void setDsSvc(IDatastoreService dsSvc); INetworkService getNetworkSvc(); @Autowired void setNetworkSvc(INetworkService networkSvc); @Override void initResource(); @Override @Transactional @RetryTransaction(2) void addResourceIntoDB(String clusterName, String vcRPName,
         String networkName, Map<DatastoreType, List<String>> dsNames); @Override @Transactional(readOnly = true) boolean isResourceInitialized(); @Override @Transactional @RetryTransaction(2) void updateOrInsertServerInfo(); static final String DEFAULT_NETWORK; static final String DEFAULT_DS_SHARED; static final String DEFAULT_DS_LOCAL; static final String DEFAULT_RP; }
@Test(groups={"res-mgmt","dependsOnVC","dependsOnDB"}) public void initResource(){ super.init(); IResourceInitializerService svc = ctx.getBean(IResourceInitializerService.class); IResourcePoolDAO rpDao = ctx.getBean(IResourcePoolDAO.class); IDatastoreDAO dsDao = ctx.getBean(IDatastoreDAO.class); INetworkDAO networkDao = ctx.getBean(INetworkDAO.class); VcResourcePoolEntity rpEntity = rpDao.findByName(ResourceInitializerService.DEFAULT_RP); if(rpEntity != null){ rpDao.delete(rpEntity); } List<VcDatastoreEntity> dss = dsDao.findByName(ResourceInitializerService.DEFAULT_DS_SHARED); if(dss != null && dss.size() > 0){ for(VcDatastoreEntity ds : dss){ dsDao.delete(ds); } } dss = dsDao.findByName(ResourceInitializerService.DEFAULT_DS_LOCAL); if(dss != null && dss.size() > 0){ for(VcDatastoreEntity ds : dss){ dsDao.delete(ds); } } NetworkEntity network = networkDao.findNetworkByName(ResourceInitializerService.DEFAULT_NETWORK); if(network != null){ networkDao.delete(network); } svc.initResource(); }