public static boolean isDeploymentConfigReady(DeploymentConfig d) { Utils.checkNotNull(d, "Deployment can't be null."); DeploymentConfigSpec spec = d.getSpec(); DeploymentConfigStatus status = d.getStatus(); if (status == null || status.getReplicas() == null || status.getAvailableReplicas() == null) { return false; } //Can be true in testing, so handle it to make test writing easier. if (spec == null || spec.getReplicas() == null) { return false; } return spec.getReplicas().intValue() == status.getReplicas() && spec.getReplicas().intValue() <= status.getAvailableReplicas(); }
public void run() { try { DeploymentConfig deploymentConfig = get(); //If the rs is gone, we shouldn't wait. if (deploymentConfig == null) { if (count == 0) { queue.put(true); return; } else { queue.put(new IllegalStateException("Can't wait for DeploymentConfig: " + checkName(getItem()) + " in namespace: " + checkName(getItem()) + " to scale. Resource is no longer available.")); return; } } replicasRef.set(deploymentConfig.getStatus().getReplicas()); int currentReplicas = deploymentConfig.getStatus().getReplicas() != null ? deploymentConfig.getStatus().getReplicas() : 0; if (deploymentConfig.getStatus().getObservedGeneration() >= deploymentConfig.getMetadata().getGeneration() && Objects.equals(deploymentConfig.getSpec().getReplicas(), currentReplicas)) { queue.put(true); } else { LOG.debug("Only {}/{} pods scheduled for DeploymentConfig: {} in namespace: {} seconds so waiting...", deploymentConfig.getStatus().getReplicas(), deploymentConfig.getSpec().getReplicas(), deploymentConfig.getMetadata().getName(), namespace); } } catch (Throwable t) { LOG.error("Error while waiting for Deployment to be scaled.", t); } } };
oldReplicas = spec.getReplicas(); spec.setReplicas(replicas); DeploymentConfig updated = resource.patch(deploymentConfig);
@Override public DeploymentConfig deployLatest(boolean wait) { Long currentVersion = getMandatory().getStatus().getLatestVersion(); if(currentVersion == null){ currentVersion = 1L; } DeploymentConfig deployment = cascading(false).edit().editStatus().withLatestVersion(++currentVersion).endStatus().done(); if (wait) { waitUntilDeploymentConfigIsScaled(deployment.getSpec().getReplicas()); deployment = getMandatory(); } return deployment; }
@Override protected Integer currentScale(String namespace, String name) { DeploymentConfig deploymentConfig = get(namespace, name); if (deploymentConfig != null) { return deploymentConfig.getSpec().getReplicas(); } else { return null; } }
public static boolean isDeploymentConfigReady(DeploymentConfig d) { Utils.checkNotNull(d, "Deployment can't be null."); DeploymentConfigSpec spec = d.getSpec(); DeploymentConfigStatus status = d.getStatus(); if (status == null || status.getReplicas() == null || status.getAvailableReplicas() == null) { return false; } //Can be true in testing, so handle it to make test writing easier. if (spec == null || spec.getReplicas() == null) { return false; } return spec.getReplicas().intValue() == status.getReplicas() && spec.getReplicas().intValue() <= status.getAvailableReplicas(); }
/** * Count the deployments of the owner of the specified integration. * * @param deployment The specified IntegrationDeployment. * @return The number of deployed integrations (excluding the current). */ private int countDeployments(IntegrationDeployment deployment) { Integration integration = deployment.getSpec(); String id = Labels.sanitize(integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration"))); String username = deployment.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)); return (int) openShiftService().getDeploymentsByLabel(labels) .stream() .filter(d -> !id.equals(d.getMetadata().getLabels().get(OpenShiftService.INTEGRATION_ID_LABEL))) .filter(d -> d.getSpec().getReplicas() > 0) .count(); }
/** * Count the deployments of the owner of the specified integration. * * @param integration The specified integration. * @return The number of deployed integrations (excluding the current). */ private int countDeployments(Integration integration) { String id = Labels.sanitize(integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration"))); String username = integration.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)); return (int) openShiftService().getDeploymentsByLabel(labels) .stream() .filter(d -> !id.equals(d.getMetadata().getLabels().get(OpenShiftService.INTEGRATION_ID_LABEL))) .filter(d -> d.getSpec().getReplicas() > 0) .count(); }
/** * Check if Integration has active deployments. * @param deployment The specified {@link IntegrationDeployment}. * @return The true if there are, false otherwise. */ private boolean hasPublishedDeployments(IntegrationDeployment deployment) { Integration integration = deployment.getSpec(); String id = Labels.validate(integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration"))); String version = String.valueOf(integration.getVersion()); Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.INTEGRATION_ID_LABEL, id); return (int) openShiftService().getDeploymentsByLabel(labels) .stream() .filter(d -> !version.equals(d.getMetadata().getLabels().get(OpenShiftService.DEPLOYMENT_VERSION_LABEL))) .filter(d -> d.getSpec().getReplicas() > 0) .count() > 0; }
/** * Count the deployments of the owner of the specified integration. * * @param deployment The specified IntegrationDeployment. * @return The number of deployed integrations (excluding the current). */ private int countDeployments(IntegrationDeployment deployment) { Integration integration = deployment.getSpec(); String id = Labels.validate(integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration"))); String username = deployment.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)); return (int) openShiftService().getDeploymentsByLabel(labels) .stream() .filter(d -> !id.equals(d.getMetadata().getLabels().get(OpenShiftService.INTEGRATION_ID_LABEL))) .filter(d -> d.getSpec().getReplicas() > 0) .count(); }
private Integer getReplicas(Service service) { DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig> dcr = getDeploymentConfigResource(service); return dcr != null ? dcr.get().getSpec().getReplicas() : null; }
public void run() { try { DeploymentConfig deploymentConfig = get(); //If the rs is gone, we shouldn't wait. if (deploymentConfig == null) { if (count == 0) { queue.put(true); return; } else { queue.put(new IllegalStateException("Can't wait for DeploymentConfig: " + checkName(getItem()) + " in namespace: " + checkName(getItem()) + " to scale. Resource is no longer available.")); return; } } replicasRef.set(deploymentConfig.getStatus().getReplicas()); int currentReplicas = deploymentConfig.getStatus().getReplicas() != null ? deploymentConfig.getStatus().getReplicas() : 0; if (deploymentConfig.getStatus().getObservedGeneration() >= deploymentConfig.getMetadata().getGeneration() && Objects.equals(deploymentConfig.getSpec().getReplicas(), currentReplicas)) { queue.put(true); } else { LOG.debug("Only {}/{} pods scheduled for DeploymentConfig: {} in namespace: {} seconds so waiting...", deploymentConfig.getStatus().getReplicas(), deploymentConfig.getSpec().getReplicas(), deploymentConfig.getMetadata().getName(), namespace); } } catch (Throwable t) { LOG.error("Error while waiting for Deployment to be scaled.", t); } } };
public DeploymentConfigSpecBuilder( DeploymentConfigSpecFluent<?> fluent , DeploymentConfigSpec instance ){ this.fluent = fluent; fluent.withReplicas(instance.getReplicas()); fluent.withSelector(instance.getSelector()); fluent.withStrategy(instance.getStrategy()); fluent.withTemplate(instance.getTemplate()); fluent.withTemplateRef(instance.getTemplateRef()); fluent.withTriggers(instance.getTriggers()); } public DeploymentConfigSpecBuilder( DeploymentConfigSpec instance ){
@Override public DeploymentConfig deployLatest(boolean wait) { Long currentVersion = getMandatory().getStatus().getLatestVersion(); if(currentVersion == null){ currentVersion = 1L; } DeploymentConfig deployment = cascading(false).edit().editStatus().withLatestVersion(++currentVersion).endStatus().done(); if (wait) { waitUntilDeploymentConfigIsScaled(deployment.getSpec().getReplicas()); deployment = getMandatory(); } return deployment; }
public DeploymentConfigSpecBuilder( DeploymentConfigSpecFluent<?> fluent , DeploymentConfigSpec instance ){ this.fluent = fluent; fluent.withReplicas(instance.getReplicas()); fluent.withSelector(instance.getSelector()); fluent.withStrategy(instance.getStrategy()); fluent.withTemplate(instance.getTemplate()); fluent.withTemplateRef(instance.getTemplateRef()); fluent.withTriggers(instance.getTriggers()); } public DeploymentConfigSpecBuilder( DeploymentConfigSpec instance ){
public DeploymentConfigSpecBuilder( DeploymentConfigSpec instance ){ this.fluent = this; this.withReplicas(instance.getReplicas()); this.withSelector(instance.getSelector()); this.withStrategy(instance.getStrategy()); this.withTemplate(instance.getTemplate()); this.withTemplateRef(instance.getTemplateRef()); this.withTriggers(instance.getTriggers()); }
public DeploymentConfigSpecBuilder( DeploymentConfigSpec instance ){ this.fluent = this; this.withReplicas(instance.getReplicas()); this.withSelector(instance.getSelector()); this.withStrategy(instance.getStrategy()); this.withTemplate(instance.getTemplate()); this.withTemplateRef(instance.getTemplateRef()); this.withTriggers(instance.getTriggers()); }
public DeploymentConfigSpecFluentImpl(DeploymentConfigSpec instance){ this.withMinReadySeconds(instance.getMinReadySeconds()); this.withPaused(instance.getPaused()); this.withReplicas(instance.getReplicas()); this.withRevisionHistoryLimit(instance.getRevisionHistoryLimit()); this.withSelector(instance.getSelector()); this.withStrategy(instance.getStrategy()); this.withTemplate(instance.getTemplate()); this.withTest(instance.getTest()); this.withTriggers(instance.getTriggers()); }
public DeploymentConfigSpecBuilder(DeploymentConfigSpec instance,Boolean validationEnabled){ this.fluent = this; this.withMinReadySeconds(instance.getMinReadySeconds()); this.withPaused(instance.getPaused()); this.withReplicas(instance.getReplicas()); this.withRevisionHistoryLimit(instance.getRevisionHistoryLimit()); this.withSelector(instance.getSelector()); this.withStrategy(instance.getStrategy()); this.withTemplate(instance.getTemplate()); this.withTest(instance.getTest()); this.withTriggers(instance.getTriggers()); this.validationEnabled = validationEnabled; }
public DeploymentConfigSpecBuilder(DeploymentConfigSpecFluent<?> fluent,DeploymentConfigSpec instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withMinReadySeconds(instance.getMinReadySeconds()); fluent.withPaused(instance.getPaused()); fluent.withReplicas(instance.getReplicas()); fluent.withRevisionHistoryLimit(instance.getRevisionHistoryLimit()); fluent.withSelector(instance.getSelector()); fluent.withStrategy(instance.getStrategy()); fluent.withTemplate(instance.getTemplate()); fluent.withTest(instance.getTest()); fluent.withTriggers(instance.getTriggers()); this.validationEnabled = validationEnabled; } public DeploymentConfigSpecBuilder(DeploymentConfigSpec instance){