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 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(); }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { Map<String, String> stepsDone = new HashMap<>(integrationDeployment.getStepsDone()); stepsDone.remove("deploy"); //we are literally undoing this step. IntegrationDeploymentState currentState = IntegrationDeploymentState.Pending; Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.INTEGRATION_ID_LABEL, Labels.validate(integrationDeployment.getIntegrationId().get())); labels.put(OpenShiftService.DEPLOYMENT_VERSION_LABEL, String.valueOf(integrationDeployment.getVersion())); List<DeploymentConfig> deployments = openShiftService().getDeploymentsByLabel(labels); Boolean isDeployed = !deployments.stream().filter(d -> d.getSpec().getReplicas() != 0).collect(Collectors.toList()).isEmpty(); if (isDeployed) { try { LOG.info("Undeploying integration deployment:{} version:{}", integrationDeployment.getSpec().getName(), integrationDeployment.getVersion()); openShiftService().scale(integrationDeployment.getSpec().getName(), labels, 0, 1, TimeUnit.MINUTES); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return new StateUpdate(currentState, stepsDone); } } Boolean isUndeployed = !deployments.stream().filter(d -> d.getStatus().getAvailableReplicas() == 0).collect(Collectors.toList()).isEmpty(); if(isUndeployed){ currentState = IntegrationDeploymentState.Unpublished; } return new StateUpdate(currentState, stepsDone); }
@Override public Boolean call() { DeploymentConfig dc = client.deploymentConfigs().inNamespace(namespace).withName(deploymentName).get(); DeploymentConfigStatus status = (dc == null) ? null : dc.getStatus(); Integer replicas = (status == null) ? null : status.getAvailableReplicas(); return replicas != null && replicas.intValue() == replicas; }
@Override public boolean isScaled(String name, int desiredReplicas, Map<String, String> labels) { List<DeploymentConfig> deploymentConfigs = getDeploymentsByLabel(labels); if (deploymentConfigs.isEmpty()) { return false; } DeploymentConfig dc = deploymentConfigs.get(0); int allReplicas = 0; int availableReplicas = 0; if (dc != null && dc.getStatus() != null) { DeploymentConfigStatus status = dc.getStatus(); allReplicas = nullSafe(status.getReplicas()); availableReplicas = nullSafe(status.getAvailableReplicas()); } return desiredReplicas == allReplicas && desiredReplicas == availableReplicas; }
@Override public boolean isScaled(String name, int desiredReplicas) { String sName = Names.sanitize(name); DeploymentConfig dc = openShiftClient.deploymentConfigs().withName(sName).get(); int allReplicas = 0; int availableReplicas = 0; if (dc != null && dc.getStatus() != null) { DeploymentConfigStatus status = dc.getStatus(); allReplicas = nullSafe(status.getReplicas()); availableReplicas = nullSafe(status.getAvailableReplicas()); } return desiredReplicas == allReplicas && desiredReplicas == availableReplicas; }
public DeploymentConfigStatusBuilder(DeploymentConfigStatus instance,Boolean validationEnabled){ this.fluent = this; this.withAvailableReplicas(instance.getAvailableReplicas()); this.withDetails(instance.getDetails()); this.withLatestVersion(instance.getLatestVersion()); this.withObservedGeneration(instance.getObservedGeneration()); this.withReplicas(instance.getReplicas()); this.withUnavailableReplicas(instance.getUnavailableReplicas()); this.withUpdatedReplicas(instance.getUpdatedReplicas()); this.validationEnabled = validationEnabled; }
public DeploymentConfigStatusFluentImpl(DeploymentConfigStatus instance){ this.withAvailableReplicas(instance.getAvailableReplicas()); this.withDetails(instance.getDetails()); this.withLatestVersion(instance.getLatestVersion()); this.withObservedGeneration(instance.getObservedGeneration()); this.withReplicas(instance.getReplicas()); this.withUnavailableReplicas(instance.getUnavailableReplicas()); this.withUpdatedReplicas(instance.getUpdatedReplicas()); }
public DeploymentConfigStatusBuilder(DeploymentConfigStatusFluent<?> fluent,DeploymentConfigStatus instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withAvailableReplicas(instance.getAvailableReplicas()); fluent.withDetails(instance.getDetails()); fluent.withLatestVersion(instance.getLatestVersion()); fluent.withObservedGeneration(instance.getObservedGeneration()); fluent.withReplicas(instance.getReplicas()); fluent.withUnavailableReplicas(instance.getUnavailableReplicas()); fluent.withUpdatedReplicas(instance.getUpdatedReplicas()); this.validationEnabled = validationEnabled; } public DeploymentConfigStatusBuilder(DeploymentConfigStatus instance){