Ejemplo n.º 1
0
 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");
     }
   }
 }
Ejemplo n.º 2
0
 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");
     }
   }
 }
 private boolean initTest(TestPlanEntity testPlan) {
   List<EngineRole> engineRoles = testPlan.getTestTenant().getEngineList();
   Host tester = testPlan.getHost();
   List<Engine> idleEngines = engineService.getIdleEngines().stream().collect(Collectors.toList());
   List<Engine> engineOnTester =
       tester.getEngineList().stream().map(EngineRole::getEngine).collect(Collectors.toList());
   if (idleEngines.size() + tester.getEngineList().size() < engineRoles.size()) {
     _logger.error(
         String.format("Testplan: %d can't init. Not enough available engines", testPlan.getId()));
     return false;
   }
   tester
       .getEngineList()
       .stream()
       .filter(e -> e.getEngine() != null)
       .forEach(e -> e.getEngine().setStatus(EngineStatus.IDLE));
   if (roleSettingOperation(testPlan, tester, idleEngines, engineOnTester)) return false;
   tester
       .getEngineList()
       .stream()
       .filter(e -> e.getEngine() != null)
       .forEach(e -> e.getEngine().setStatus(EngineStatus.TESTING));
   return true;
 }
 private void startTest(TestPlanEntity testPlan) {
   Host tester = testPlan.getHost();
   List<EngineRole> engines = tester.getEngineList();
   Timer exe = new Timer();
   exe.schedule(
       new TimerTask() {
         @Override
         public void run() {
           double avgSpeed = 0;
           for (EngineRole e : engines) {
             avgSpeed += e.getCurrentSpeed();
           }
           avgSpeed = avgSpeed / engines.size();
           double speed = avgSpeed * 0.8 + tester.getCapability(engines.size()) * 0.2;
           tester.setCapability(engines.size(), speed);
           _pm.exec(tester, HibernateEngine.DB_UPDATE, true);
           _logger.info("current speed: " + speed);
         }
       },
       1000,
       5000);
   Timer shut = new Timer();
   shut.schedule(
       new TimerTask() {
         @Override
         public void run() {
           exe.cancel();
           _logger.info(
               String.format(
                   "test %s stop, tested capability: %f",
                   testPlan, tester.getCapability(engines.size())));
           for (EngineRole e : engines) {
             e.getEngine().setStatus(EngineStatus.SERVING);
           }
           _pm.exec(tester, HibernateEngine.DB_UPDATE, true);
           testPlan.setFinished(true);
         }
       },
       testPlan.getEndTime().getTime() - (new Date()).getTime());
   testPlan.setStartTime(new Date());
   _executor.put(testPlan.getId(), exe);
   _shutdownNotifier.put(testPlan.getId(), shut);
   _logger.info(String.format("test %s started", testPlan));
 }
Ejemplo n.º 5
0
 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;
 }