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 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 DeploymentConfigStatusBuilder(Boolean validationEnabled){ this(new DeploymentConfigStatus(), validationEnabled); } public DeploymentConfigStatusBuilder(DeploymentConfigStatusFluent<?> fluent){
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 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 DeploymentConfigStatusBuilder( DeploymentConfigStatusFluent<?> fluent , DeploymentConfigStatus instance ){ this.fluent = fluent; fluent.withDetails(instance.getDetails()); fluent.withLatestVersion(instance.getLatestVersion()); } public DeploymentConfigStatusBuilder( DeploymentConfigStatus instance ){
@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; }
public void run() { DeploymentConfig deployment = operation.getMandatory(); if (observedGeneration <= deployment.getStatus().getObservedGeneration()) { countDownLatch.countDown(); } } };
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( DeploymentConfigStatus instance ){ this.fluent = this; this.withDetails(instance.getDetails()); this.withLatestVersion(instance.getLatestVersion()); }
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); } } };
@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 reap() { DeploymentConfig deployment = operation.cascading(false).edit().editSpec().withReplicas(0).endSpec().done(); //TODO: These checks shouldn't be used as they are not realistic. We just use them to support mock/crud tests. Need to find a cleaner way to do so. if (deployment.getStatus() != null) { waitForObservedGeneration(deployment.getStatus().getObservedGeneration()); } //We are deleting the DC before reaping the replication controller, because the RC's won't go otherwise. Boolean reaped = operation.cascading(false).delete(); // Waiting for the DC to be completely deleted before removing the replication controller (error in Openshift 3.9) waitForDeletion(); Map<String, String> selector = new HashMap<>(); selector.put(DEPLOYMENT_CONFIG_REF, deployment.getMetadata().getName()); if (selector != null && !selector.isEmpty()) { Boolean deleted = new ReplicationControllerOperationsImpl(client, operation.getConfig(), operation.getNamespace()) .withLabels(selector) .delete(); } return reaped; }
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){
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 DeploymentConfigStatusBuilder( DeploymentConfigStatusFluent<?> fluent , DeploymentConfigStatus instance ){ this.fluent = fluent; fluent.withDetails(instance.getDetails()); fluent.withLatestVersion(instance.getLatestVersion()); } public DeploymentConfigStatusBuilder( DeploymentConfigStatus instance ){
public DeploymentConfigStatusBuilder( DeploymentConfigStatusFluent<?> fluent ){ this(fluent, new DeploymentConfigStatus()); } public DeploymentConfigStatusBuilder( DeploymentConfigStatusFluent<?> fluent , DeploymentConfigStatus instance ){
@Override public String deploy(String name, DeploymentData deploymentData) { final String sanitizedName = openshiftName(name); LOGGER.debug("Deploy {}", sanitizedName); ensureDeploymentConfig(sanitizedName, deploymentData); ensureSecret(sanitizedName, deploymentData); ensureExposure(sanitizedName, deploymentData); DeploymentConfig deployment = openShiftClient.deploymentConfigs().withName(sanitizedName).deployLatest(); return String.valueOf(deployment.getStatus().getLatestVersion()); }
public void run() { DeploymentConfig deployment = operation.getMandatory(); if (observedGeneration <= deployment.getStatus().getObservedGeneration()) { countDownLatch.countDown(); } } };
@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; }