use of io.syndesis.common.util.Labels in project syndesis by syndesisio.
the class PublishHandler method countDeployments.
/**
* 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();
}
use of io.syndesis.common.util.Labels in project syndesis by syndesisio.
the class PublishHandler method hasPublishedDeployments.
/**
* 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;
}
Aggregations