Search in sources :

Example 1 with IntegrationDeployment

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();
}
Also used : StateUpdate(io.syndesis.server.controller.StateUpdate) Properties(java.util.Properties) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) StringWriter(java.io.StringWriter) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) ControllersConfigurationProperties(io.syndesis.server.controller.ControllersConfigurationProperties) DeploymentData(io.syndesis.server.openshift.DeploymentData) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Map(java.util.Map) DataManager(io.syndesis.server.dao.manager.DataManager) OpenShiftService(io.syndesis.server.openshift.OpenShiftService) Integration(io.syndesis.common.model.integration.Integration) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) Collections(java.util.Collections) StateChangeHandler(io.syndesis.server.controller.StateChangeHandler) InputStream(java.io.InputStream) Labels(io.syndesis.common.util.Labels) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Integration(io.syndesis.common.model.integration.Integration) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment)

Example 2 with IntegrationDeployment

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());
}
Also used : StateUpdate(io.syndesis.server.controller.StateUpdate) Properties(java.util.Properties) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) StringWriter(java.io.StringWriter) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) ControllersConfigurationProperties(io.syndesis.server.controller.ControllersConfigurationProperties) DeploymentData(io.syndesis.server.openshift.DeploymentData) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Map(java.util.Map) DataManager(io.syndesis.server.dao.manager.DataManager) OpenShiftService(io.syndesis.server.openshift.OpenShiftService) Integration(io.syndesis.common.model.integration.Integration) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) Collections(java.util.Collections) StateChangeHandler(io.syndesis.server.controller.StateChangeHandler) InputStream(java.io.InputStream) Labels(io.syndesis.common.util.Labels) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Integration(io.syndesis.common.model.integration.Integration)

Example 3 with IntegrationDeployment

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();
}
Also used : StateUpdate(io.syndesis.server.controller.StateUpdate) Properties(java.util.Properties) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) StringWriter(java.io.StringWriter) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) ControllersConfigurationProperties(io.syndesis.server.controller.ControllersConfigurationProperties) DeploymentData(io.syndesis.server.openshift.DeploymentData) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Map(java.util.Map) DataManager(io.syndesis.server.dao.manager.DataManager) OpenShiftService(io.syndesis.server.openshift.OpenShiftService) Integration(io.syndesis.common.model.integration.Integration) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) Collections(java.util.Collections) StateChangeHandler(io.syndesis.server.controller.StateChangeHandler) InputStream(java.io.InputStream) Labels(io.syndesis.common.util.Labels) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Integration(io.syndesis.common.model.integration.Integration) HashMap(java.util.HashMap)

Example 4 with IntegrationDeployment

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));
}
Also used : IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment)

Example 5 with IntegrationDeployment

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);
        }
    });
}
Also used : IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment)

Aggregations

IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)11 DataManager (io.syndesis.server.dao.manager.DataManager)6 Integration (io.syndesis.common.model.integration.Integration)5 IntegrationDeploymentState (io.syndesis.common.model.integration.IntegrationDeploymentState)5 OpenShiftService (io.syndesis.server.openshift.OpenShiftService)5 IOException (java.io.IOException)5 Set (java.util.Set)5 Labels (io.syndesis.common.util.Labels)4 SyndesisServerException (io.syndesis.common.util.SyndesisServerException)4 IntegrationProjectGenerator (io.syndesis.integration.api.IntegrationProjectGenerator)4 ControllersConfigurationProperties (io.syndesis.server.controller.ControllersConfigurationProperties)4 StateChangeHandler (io.syndesis.server.controller.StateChangeHandler)4 StateUpdate (io.syndesis.server.controller.StateUpdate)4 DeploymentData (io.syndesis.server.openshift.DeploymentData)4 InputStream (java.io.InputStream)4 StringWriter (java.io.StringWriter)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Properties (java.util.Properties)4