use of io.syndesis.common.model.integration.IntegrationDeployment in project syndesis by syndesisio.
the class PublishHandler method countActiveIntegrationsOfSameUserAs.
/**
* Counts active integrations (in DB) of the owner of the specified integration.
*
* @param deployment The specified IntegrationDeployment.
* @return The number of integrations (excluding the current).
*/
private int countActiveIntegrationsOfSameUserAs(IntegrationDeployment deployment) {
Integration integration = deployment.getSpec();
String integrationId = 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"));
return (int) dataManager.fetchAll(IntegrationDeployment.class).getItems().stream().filter(// The "current" integration will already be in the database.
i -> !i.getIntegrationId().get().equals(integrationId)).filter(i -> IntegrationDeploymentState.Published == i.getCurrentState()).filter(i -> i.getUserId().map(username::equals).orElse(Boolean.FALSE)).count();
}
use of io.syndesis.common.model.integration.IntegrationDeployment in project syndesis by syndesisio.
the class PublishHandler method setVersion.
private void setVersion(IntegrationDeployment integrationDeployment) {
Integration integration = integrationDeployment.getIntegrationId().map(i -> dataManager.fetch(Integration.class, i)).orElseThrow(() -> new IllegalStateException("Integration not found!"));
dataManager.update(new Integration.Builder().createFrom(integration).version(integrationDeployment.getVersion()).build());
}
use of io.syndesis.common.model.integration.IntegrationDeployment 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.model.integration.IntegrationDeployment in project syndesis by syndesisio.
the class PublishHandler method updateDeploymentState.
private void updateDeploymentState(IntegrationDeployment integrationDeployment, IntegrationDeploymentState state) {
IntegrationDeployment d = dataManager.fetch(IntegrationDeployment.class, integrationDeployment.getId().get());
dataManager.update(d.withCurrentState(state));
}
use of io.syndesis.common.model.integration.IntegrationDeployment in project syndesis by syndesisio.
the class IntegrationController method checkIntegrationStatusIfNotAlreadyInProgress.
private void checkIntegrationStatusIfNotAlreadyInProgress(String id) {
executor.execute(() -> {
IntegrationDeployment integrationDeployment = dataManager.fetch(IntegrationDeployment.class, id);
if (integrationDeployment != null) {
String scheduledKey = getIntegrationMarkerKey(integrationDeployment);
LOG.debug("Check if IntegrationStatus {} is already in progress for key: {} (keys: {})", id, scheduledKey, scheduledChecks);
// Don't start check is already a check is running
if (!scheduledChecks.contains(scheduledKey)) {
checkIntegrationStatus(integrationDeployment);
} else {
LOG.debug("A check for IntegrationDeployment {} is already configured with key {}", id, scheduledKey);
}
} else {
LOG.debug("No IntegrationDeployment with id: {}", id);
}
});
}
Aggregations