protected void validateLinks(final Map<String, ServiceLink> newServiceLinks) {
   for (ServiceLink link : newServiceLinks.values()) {
     Service targetService = objMgr.loadResource(Service.class, link.getServiceId());
     if (targetService == null
         || targetService.getRemoved() != null
         || targetService.getState().equalsIgnoreCase(CommonStatesConstants.REMOVING)) {
       Object obfuscatedId = idFormatter.formatId("service", link.getServiceId());
       String obfuscatedIdStr = obfuscatedId != null ? obfuscatedId.toString() : null;
       String svcName = targetService != null ? targetService.getName() : obfuscatedIdStr;
       ValidationErrorCodes.throwValidationError(
           ValidationErrorCodes.INVALID_REFERENCE, "Service " + svcName + " is removed");
     }
   }
 }
示例#2
0
 @Override
 public void upgrade(
     Service service, io.cattle.platform.core.addon.ServiceUpgradeStrategy strategy) {
   /*
    * TODO: move this and all downstream methods to a UpgradeManager with pluggable
    * strategies
    */
   if (strategy instanceof ToServiceUpgradeStrategy) {
     ToServiceUpgradeStrategy toServiceStrategy = (ToServiceUpgradeStrategy) strategy;
     Service toService =
         objectManager.loadResource(Service.class, toServiceStrategy.getToServiceId());
     if (toService == null || toService.getRemoved() != null) {
       return;
     }
     updateLinks(service, toServiceStrategy);
   }
   while (!doUpgrade(service, strategy)) {
     sleep(service, strategy);
   }
 }
示例#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;
    }
  }