Search in sources :

Example 11 with Integration

use of io.syndesis.common.model.integration.Integration 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 12 with Integration

use of io.syndesis.common.model.integration.Integration 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 13 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class IntegrationHandler method create.

@Override
public Integration create(@Context SecurityContext sec, @ConvertGroup(from = Default.class, to = AllValidations.class) final Integration integration) {
    Integration encryptedIntegration = encryptionSupport.encrypt(integration);
    Integration updatedIntegration = new Integration.Builder().createFrom(encryptedIntegration).createdAt(System.currentTimeMillis()).build();
    // Create the the integration.
    return getDataManager().create(updatedIntegration);
}
Also used : Integration(io.syndesis.common.model.integration.Integration)

Example 14 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class IntegrationHandler method getIntegration.

// **************************
// Helpers
// **************************
public Integration getIntegration(String id) {
    final DataManager dataManager = getDataManager();
    final Integration integration = dataManager.fetch(Integration.class, id);
    if (integration == null) {
        throw new EntityNotFoundException();
    }
    return integration;
}
Also used : Integration(io.syndesis.common.model.integration.Integration) DataManager(io.syndesis.server.dao.manager.DataManager) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 15 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class IntegrationHandler method putDeployment.

@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/deployments")
public IntegrationDeployment putDeployment(@Context SecurityContext sec, @NotNull @PathParam("id") @ApiParam(required = true) String id) {
    Integration integration = getIntegration(id);
    int nextDeploymentVersion = 1;
    // Update previous deployments targetState=Undeployed and make sure nextDeploymentVersion is larger than all previous ones.
    Set<String> deploymentIds = getDataManager().fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", id);
    if (deploymentIds != null && !deploymentIds.isEmpty()) {
        Stream<IntegrationDeployment> deployments = deploymentIds.stream().map(i -> getDataManager().fetch(IntegrationDeployment.class, i)).filter(r -> r != null);
        for (IntegrationDeployment d : deployments.toArray(IntegrationDeployment[]::new)) {
            nextDeploymentVersion = Math.max(nextDeploymentVersion, d.getVersion() + 1);
            getDataManager().update(d.withTargetState(IntegrationDeploymentState.Unpublished));
        }
    }
    IntegrationDeployment deployment = new IntegrationDeployment.Builder().id(IntegrationDeployment.compositeId(id, nextDeploymentVersion)).spec(integration).version(nextDeploymentVersion).userId(sec.getUserPrincipal().getName()).build();
    deployment = getDataManager().create(deployment);
    return deployment;
}
Also used : Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) SortOptionsFromQueryParams(io.syndesis.server.endpoint.v1.operations.SortOptionsFromQueryParams) PaginationFilter(io.syndesis.server.endpoint.util.PaginationFilter) MediaType(javax.ws.rs.core.MediaType) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) Connection(io.syndesis.common.model.connection.Connection) IdPrefixFilter(io.syndesis.server.dao.manager.operators.IdPrefixFilter) IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) Integration(io.syndesis.common.model.integration.Integration) AllValidations(io.syndesis.common.model.validation.AllValidations) Context(javax.ws.rs.core.Context) Set(java.util.Set) Validator(javax.validation.Validator) Connector(io.syndesis.common.model.connection.Connector) ListResult(io.syndesis.common.model.ListResult) Extension(io.syndesis.common.model.extension.Extension) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Updater(io.syndesis.server.endpoint.v1.operations.Updater) List(java.util.List) Stream(java.util.stream.Stream) PaginationOptionsFromQueryParams(io.syndesis.server.endpoint.v1.operations.PaginationOptionsFromQueryParams) DataManagerSupport(io.syndesis.server.endpoint.v1.util.DataManagerSupport) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) ReflectiveSorter(io.syndesis.server.endpoint.util.ReflectiveSorter) ReverseFilter(io.syndesis.server.dao.manager.operators.ReverseFilter) Op(io.syndesis.common.model.filter.Op) PathParam(javax.ws.rs.PathParam) Creator(io.syndesis.server.endpoint.v1.operations.Creator) Action(io.syndesis.common.model.action.Action) GET(javax.ws.rs.GET) Step(io.syndesis.common.model.integration.Step) Kind(io.syndesis.common.model.Kind) IntegrationBulletinBoard(io.syndesis.common.model.bulletin.IntegrationBulletinBoard) Validating(io.syndesis.server.endpoint.v1.operations.Validating) ConvertGroup(javax.validation.groups.ConvertGroup) EntityNotFoundException(javax.persistence.EntityNotFoundException) FilterOptions(io.syndesis.common.model.filter.FilterOptions) DataManager(io.syndesis.server.dao.manager.DataManager) Api(io.swagger.annotations.Api) SuppressFBWarnings(io.syndesis.common.util.SuppressFBWarnings) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Default(javax.validation.groups.Default) POST(javax.ws.rs.POST) IntegrationDeploymentOverview(io.syndesis.common.model.integration.IntegrationDeploymentOverview) Deleter(io.syndesis.server.endpoint.v1.operations.Deleter) DataShape(io.syndesis.common.model.DataShape) Getter(io.syndesis.server.endpoint.v1.operations.Getter) Lister(io.syndesis.server.endpoint.v1.operations.Lister) Component(org.springframework.stereotype.Component) Inspectors(io.syndesis.server.inspector.Inspectors) OpenShiftService(io.syndesis.server.openshift.OpenShiftService) PUT(javax.ws.rs.PUT) BaseHandler(io.syndesis.server.endpoint.v1.handler.BaseHandler) Integration(io.syndesis.common.model.integration.Integration) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

Integration (io.syndesis.common.model.integration.Integration)57 Test (org.junit.Test)19 Step (io.syndesis.common.model.integration.Step)17 List (java.util.List)16 Connection (io.syndesis.common.model.connection.Connection)15 Connector (io.syndesis.common.model.connection.Connector)11 DataManager (io.syndesis.server.dao.manager.DataManager)11 IOException (java.io.IOException)11 Set (java.util.Set)10 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)9 Collectors (java.util.stream.Collectors)9 IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)8 IntegrationDeploymentState (io.syndesis.common.model.integration.IntegrationDeploymentState)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 IntegrationProjectGenerator (io.syndesis.integration.api.IntegrationProjectGenerator)7 Map (java.util.Map)7 Action (io.syndesis.common.model.action.Action)6 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)6 StepKind (io.syndesis.common.model.integration.StepKind)6