Esempio n. 1
0
  public boolean doRestart(
      Service service, RollingRestartStrategy strategy, Map<String, List<Instance>> toRestart) {
    try {
      long batchSize = strategy.getBatchSize();
      final Map<String, List<Instance>> restartBatch = new HashMap<>();
      long i = 0;
      Iterator<Map.Entry<String, List<Instance>>> it = toRestart.entrySet().iterator();
      while (it.hasNext() && i < batchSize) {
        Map.Entry<String, List<Instance>> instances = it.next();
        String deploymentUnitUUID = instances.getKey();
        restartBatch.put(deploymentUnitUUID, instances.getValue());
        it.remove();
        i++;
      }

      restartDeploymentUnits(service, restartBatch);

      if (toRestart.isEmpty()) {
        return true;
      }
      return false;

    } catch (TimeoutException e) {
      return false;
    }
  }
Esempio n. 2
0
 protected List<? extends Instance> getServiceInstancesToRestart(Service service) {
   // get all instances of the service
   List<? extends Instance> instances = exposeMapDao.listServiceManagedInstances(service.getId());
   List<Instance> toRestart = new ArrayList<>();
   ServiceRestart svcRestart =
       DataAccessor.field(
           service, ServiceDiscoveryConstants.FIELD_RESTART, jsonMapper, ServiceRestart.class);
   RollingRestartStrategy strategy = svcRestart.getRollingRestartStrategy();
   Map<Long, Long> instanceToStartCount = strategy.getInstanceToStartCount();
   // compare its start_count with one set on the service restart field
   for (Instance instance : instances) {
     if (instanceToStartCount.containsKey(instance.getId())) {
       Long previousStartCount = instanceToStartCount.get(instance.getId());
       if (previousStartCount == instance.getStartCount()) {
         toRestart.add(instance);
       }
     }
   }
   return toRestart;
 }