// requires synchronization between host platform and db.
 public List<Host> loadFromPlatform() {
   List<Host> hosts = adapter.getHosts();
   List<Engine> engines = adapter.bindEngineAndHost(engineService.getAllEngines(), hosts);
   _pm.beginTransaction();
   engines.stream().forEach(e -> _pm.exec(e, HibernateEngine.DB_UPDATE));
   hosts.stream().forEach(h -> _pm.exec(h, HibernateEngine.DB_UPDATE));
   _pm.commit();
   return hosts;
 }
 public Host createHost(String name, String ip) {
   Host host = new Host();
   host.setName(name);
   host.setIp(ip);
   _pm.exec(host, HibernateEngine.DB_INSERT, true);
   return null;
 }
 public Host updateSpeed(Host host) {
   if (host == null) return null;
   double speed =
       host.getEngineList()
           .stream()
           .map(EngineRole::getCurrentSpeed)
           .reduce((double) 0, (a, b) -> a + b);
   HostSpeedRcd speedRcd = new HostSpeedRcd();
   Date time = new Date();
   speedRcd.setHost(host);
   speedRcd.setTime(time);
   speedRcd.setSpeed(speed);
   host.getSpeedRcds().add(speedRcd);
   host.setCurrentSpeed(speed);
   host.setRecordTime(time);
   _pm.exec(speedRcd, HibernateEngine.DB_INSERT, true);
   _pm.exec(host, HibernateEngine.DB_UPDATE, true);
   return host;
 }
 public void removeEngine(Host host, EngineRole e) throws GeneralException {
   if (e != null) {
     if (host.getEngineList().contains(e)) {
       host.getEngineList().remove(e);
       _pm.exec(host, HibernateEngine.DB_UPDATE, true);
     } else {
       throw new GeneralException("invalid engine");
     }
   }
 }
 public void addEngine(Host host, EngineRole e) throws GeneralException {
   if (e != null) {
     if (!host.getEngineList().contains(e)) {
       host.getEngineList().add(e);
       _pm.exec(host, HibernateEngine.DB_UPDATE, true);
     } else {
       throw new GeneralException("duplicated engine");
     }
   }
 }
 public TestPlanEntity createTestPlan(Host host, int eNum, Date endTime) {
   TestPlanEntity testPlan = new TestPlanEntity();
   testPlan.setHost(host);
   testPlan.setEngineNumber(eNum);
   testPlan.setEndTime(endTime);
   testPlan.setStartTime(new Date());
   testPlan.setTestTenant(
       tenantService.getTesterTenant(UUID.randomUUID().toString(), testPlan.getEngineNumber()));
   _pm.exec(testPlan, HibernateEngine.DB_INSERT, true);
   return testPlan;
 }
 public void setHostCapability(long hid, int engineNum, double capability) {
   Host host = (Host) _pm.get(Host.class, hid);
   host.setCapability(engineNum, capability);
   _pm.exec(host, HibernateEngine.DB_UPDATE);
 }
 public Host getHostById(long id) {
   return (Host) _pm.get(Host.class, id);
 }
 @SuppressWarnings("unchecked")
 public List<Host> getAllHosts() {
   return (List<Host>) _pm.getObjectsForClass("Host");
 }
 @SuppressWarnings("unchecked")
 public List<TestPlanEntity> getAllTestPlan() {
   return (List<TestPlanEntity>) _pm.getObjectsForClass("TestPlanEntity");
 }
 public TestPlanEntity getTestPlanByID(long id) {
   return (TestPlanEntity) _pm.get(TestPlanEntity.class, id);
 }