Search in sources :

Example 1 with OpenShiftService

use of io.syndesis.server.openshift.OpenShiftService 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 2 with OpenShiftService

use of io.syndesis.server.openshift.OpenShiftService in project syndesis by syndesisio.

the class IntegrationHandlerTest method setUp.

@Before
public void setUp() {
    DataManager manager = mock(DataManager.class);
    Validator validator = mock(Validator.class);
    openShiftService = mock(OpenShiftService.class);
    inspectors = mock(Inspectors.class);
    handler = new IntegrationHandler(manager, openShiftService, validator, inspectors, new EncryptionComponent(null));
}
Also used : IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) Inspectors(io.syndesis.server.inspector.Inspectors) OpenShiftService(io.syndesis.server.openshift.OpenShiftService) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) DataManager(io.syndesis.server.dao.manager.DataManager) Validator(javax.validation.Validator) Before(org.junit.Before)

Example 3 with OpenShiftService

use of io.syndesis.server.openshift.OpenShiftService 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;
}
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)

Aggregations

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