Ejemplo n.º 1
0
  @Override
  public void finishUpgrade(Service service, boolean reconcile) {
    // cleanup instances set for upgrade
    cleanupUpgradedInstances(service);

    // reconcile
    if (reconcile) {
      deploymentMgr.activate(service);
    }
  }
Ejemplo n.º 2
0
  protected Service changeScale(Service service, long delta) {
    if (delta == 0) {
      return service;
    }

    long newScale = Math.max(0, getScale(service) + delta);

    service = objectManager.setFields(service, ServiceDiscoveryConstants.FIELD_SCALE, newScale);
    deploymentMgr.activate(service);
    return objectManager.reload(service);
  }
Ejemplo n.º 3
0
  /**
   * @param fromService
   * @param strategy
   * @return true if the upgrade is done
   */
  protected boolean doToServiceUpgrade(Service fromService, ToServiceUpgradeStrategy strategy) {
    Service toService = objectManager.loadResource(Service.class, strategy.getToServiceId());
    if (toService == null || toService.getRemoved() != null) {
      return true;
    }

    try {
      deploymentMgr.activate(toService);
      if (!deploymentMgr.isHealthy(toService)) {
        return false;
      }

      deploymentMgr.activate(fromService);

      fromService = objectManager.reload(fromService);
      toService = objectManager.reload(toService);

      long batchSize = strategy.getBatchSize();
      long finalScale = strategy.getFinalScale();

      long toScale = getScale(toService);
      long totalScale = getScale(fromService) + toScale;

      if (totalScale > finalScale) {
        fromService = changeScale(fromService, 0 - Math.min(batchSize, totalScale - finalScale));
      } else if (toScale < finalScale) {
        long max = Math.min(batchSize, finalScale - toScale);
        toService = changeScale(toService, Math.min(max, finalScale + batchSize - totalScale));
      }

      if (getScale(fromService) == 0 && getScale(toService) != finalScale) {
        changeScale(toService, finalScale - getScale(toService));
      }

      return getScale(fromService) == 0 && getScale(toService) == finalScale;
    } catch (TimeoutException e) {

      return false;
    }
  }