Search in sources :

Example 6 with IntegrationDeployment

use of io.syndesis.common.model.integration.IntegrationDeployment 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)

Example 7 with IntegrationDeployment

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

the class IntegrationHandler method toCurrentIntegrationOverview.

public IntegrationOverview toCurrentIntegrationOverview(Integration integration) {
    final DataManager dataManager = getDataManager();
    final String id = integration.getId().get();
    final IntegrationOverview.Builder builder = new IntegrationOverview.Builder().createFrom(integration);
    // add board
    DataManagerSupport.fetchBoard(dataManager, IntegrationBulletinBoard.class, id).ifPresent(builder::board);
    // Defaults
    builder.isDraft(true);
    builder.currentState(IntegrationDeploymentState.Unpublished);
    builder.targetState(IntegrationDeploymentState.Unpublished);
    // Get the latest connection.
    builder.connections(integration.getConnections().stream().map(this::toCurrentConnection).collect(Collectors.toList()));
    // Get the latest steps.
    builder.steps(integration.getSteps().stream().map(this::toCurrentSteps).collect(Collectors.toList()));
    for (IntegrationDeployment deployment : dataManager.fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id + ":"), ReverseFilter.getInstance())) {
        builder.addDeployment(IntegrationDeploymentOverview.of(deployment));
        if (deployment.getVersion() == integration.getVersion()) {
            builder.isDraft(deployment.getVersion() != integration.getVersion());
            builder.targetState(deployment.getTargetState());
            builder.currentState(deployment.getCurrentState());
            builder.deploymentVersion(deployment.getVersion());
        }
    }
    return builder.build();
}
Also used : IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) IntegrationBulletinBoard(io.syndesis.common.model.bulletin.IntegrationBulletinBoard) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) DataManager(io.syndesis.server.dao.manager.DataManager)

Example 8 with IntegrationDeployment

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

the class IntegrationHandler method setTargetStatus.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/deployments/{version}/targetState")
@SuppressFBWarnings("UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD")
public void setTargetStatus(@NotNull @PathParam("id") @ApiParam(required = true) String id, @NotNull @PathParam("version") @ApiParam(required = true) Integer version, TargetStateRequest request) {
    String compositeId = IntegrationDeployment.compositeId(id, version);
    IntegrationDeployment deployment = getDataManager().fetch(IntegrationDeployment.class, compositeId);
    deployment = new IntegrationDeployment.Builder().createFrom(deployment).targetState(request.targetState).build();
    getDataManager().update(deployment);
}
Also used : IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) SuppressFBWarnings(io.syndesis.common.util.SuppressFBWarnings)

Example 9 with IntegrationDeployment

use of io.syndesis.common.model.integration.IntegrationDeployment 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)

Example 10 with IntegrationDeployment

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

the class IntegrationController method reschedule.

@SuppressWarnings("FutureReturnValueIgnored")
private void reschedule(String integrationId) {
    LOG.debug("Reschedule IntegrationDeployment check, id:{}, keys: {}", integrationId, scheduledChecks);
    scheduler.schedule(() -> {
        IntegrationDeployment i = dataManager.fetch(IntegrationDeployment.class, integrationId);
        LOG.debug("Trigger checkIntegrationStatus, id:{}", integrationId);
        checkIntegrationStatus(i);
    }, SCHEDULE_INTERVAL_IN_SECONDS, TimeUnit.SECONDS);
}
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