@GET @Path("/delete-deployments") public void deleteDeployments() { LOG.warn("user {} is deleting all integration deploymets", context.getRemoteUser()); List<Integration> integrations = dataMgr.fetchAll(Integration.class).getItems(); for (Integration i : integrations) { if (openShiftService.exists(i.getName())) { openShiftService.delete(i.getName()); LOG.debug("Deleting integration \"{}\"", i.getName()); } else { LOG.debug("Skipping integration named \"{}\". No such deployment found.", i.getName()); } } }
/** * 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(); }
private boolean isBuildStarted(IntegrationDeployment integrationDeployment) { return openShiftService().isBuildStarted(integrationDeployment.getName()); }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { try { openShiftService().scale(integrationDeployment.getName(), 0); logInfo(integrationDeployment,"Deactivated"); } catch (KubernetesClientException e) { // Ignore 404 errors, means the deployment does not exist for us // to scale down if( e.getCode() != 404 ) { throw e; } } IntegrationDeploymentState currentState = openShiftService().isScaled(integrationDeployment.getName(), 0) ? IntegrationDeploymentState.Inactive : IntegrationDeploymentState.Pending; return new StateUpdate(currentState); }
private void build(IntegrationDeployment integrationDeployment, DeploymentData data) throws IOException { InputStream tarInputStream = createProjectFiles(integrationDeployment); logInfo(integrationDeployment, "Created project files and starting build"); openShiftService().build(integrationDeployment.getName(), data, tarInputStream); }
private void deploy(IntegrationDeployment integration, DeploymentData data) throws IOException { logInfo(integration, "Starting deployment"); openShiftService().deploy(integration.getName(), data); logInfo(integration, "Deployment done"); }
public boolean isRunning(IntegrationDeployment integrationDeployment) { return openShiftService().isScaled(integrationDeployment.getName(), 1); }
private boolean isReady(IntegrationDeployment integrationDeployment) { return openShiftService().isDeploymentReady(integrationDeployment.getName()); }
private boolean isBuildFailed(IntegrationDeployment integrationDeployment) { return openShiftService().isBuildFailed(integrationDeployment.getSpec().getName()); }
private void build(IntegrationDeployment integration, DeploymentData data) throws IOException { InputStream tarInputStream = createProjectFiles(integration.getSpec()); logInfo(integration, "Created project files and starting build"); openShiftService().build(integration.getSpec().getName(), data, tarInputStream); }
private void deploy(IntegrationDeployment integration, DeploymentData data) throws IOException { logInfo(integration, "Starting deployment"); openShiftService().deploy(integration.getSpec().getName(), data); logInfo(integration, "Deployment done"); }
public boolean isRunning(IntegrationDeployment integrationDeployment) { return openShiftService().isScaled(integrationDeployment.getSpec().getName(), 1); }
private boolean isReady(IntegrationDeployment integrationDeployment) { return openShiftService().isDeploymentReady(integrationDeployment.getSpec().getName()); }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { IntegrationDeploymentState currentState = !openShiftService().exists(integrationDeployment.getName()) || openShiftService().delete(integrationDeployment.getName()) ? IntegrationDeploymentState.Undeployed : IntegrationDeploymentState.Pending; logInfo(integrationDeployment,"Deleted"); return new StateUpdate(currentState); }
private boolean isBuildStarted(IntegrationDeployment integrationDeployment) { return openShiftService().isBuildStarted(integrationDeployment.getSpec().getName()); }
/** * 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(); }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { IntegrationDeploymentState currentState = !openShiftService().exists(integrationDeployment.getSpec().getName()) || openShiftService().delete(integrationDeployment.getSpec().getName()) ? IntegrationDeploymentState.Unpublished : IntegrationDeploymentState.Pending; if (currentState == IntegrationDeploymentState.Unpublished) { logInfo(integrationDeployment,"Deleted"); IntegrationDeployment updated = new IntegrationDeployment.Builder().createFrom(integrationDeployment).addAllStepsDone(Collections.emptyList()).build(); dataManager.update(updated); } return new StateUpdate(currentState); }