Search in sources :

Example 46 with Integration

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

the class IntegrationHandler method delete.

@Override
public void delete(String id) {
    Integration existing = getIntegration(id);
    // Set all integration status to Undeployed.
    Set<String> deploymentIds = getDataManager().fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", existing.getId().get());
    if (deploymentIds != null && !deploymentIds.isEmpty()) {
        deploymentIds.stream().map(i -> getDataManager().fetch(IntegrationDeployment.class, i)).filter(r -> r != null).map(r -> r.unpublishing()).forEach(r -> getDataManager().update(r));
    }
    Integration updatedIntegration = new Integration.Builder().createFrom(existing).updatedAt(System.currentTimeMillis()).isDeleted(true).build();
    openShiftService.delete(existing.getName());
    Updater.super.update(id, updatedIntegration);
}
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)

Example 47 with Integration

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

the class IntegrationSupportHandler method importIntegrations.

private void importIntegrations(SecurityContext sec, JsonDbDao<Integration> export, List<ChangeEvent> result) {
    for (Integration integration : export.fetchAll().getItems()) {
        Integration.Builder builder = new Integration.Builder().createFrom(integration).isDeleted(false).updatedAt(System.currentTimeMillis());
        // Do we need to create it?
        String id = integration.getId().get();
        Integration previous = dataManager.fetch(Integration.class, id);
        if (previous == null) {
            LOG.info("Creating integration: {}", integration.getName());
            integrationHandler.create(sec, builder.build());
            result.add(ChangeEvent.of("created", integration.getKind().getModelName(), id));
        } else {
            LOG.info("Updating integration: {}", integration.getName());
            integrationHandler.update(id, builder.version(previous.getVersion() + 1).build());
            result.add(ChangeEvent.of("updated", integration.getKind().getModelName(), id));
        }
    }
}
Also used : Integration(io.syndesis.common.model.integration.Integration)

Example 48 with Integration

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

the class IntegrationSupportHandler method export.

@GET
@Path("/export.zip")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public StreamingOutput export(@NotNull @QueryParam("id") @ApiParam(required = true) List<String> requestedIds) throws IOException {
    List<String> ids = requestedIds;
    if (ids == null || ids.isEmpty()) {
        throw new ClientErrorException("No 'integration' query parameter specified.", Response.Status.BAD_REQUEST);
    }
    LinkedHashSet<String> extensions = new LinkedHashSet<>();
    CloseableJsonDB memJsonDB = MemorySqlJsonDB.create(jsonDB.getIndexes());
    if (ids.contains("all")) {
        ids = new ArrayList<>();
        for (Integration integration : dataManager.fetchAll(Integration.class)) {
            ids.add(integration.getId().get());
        }
    }
    for (String id : ids) {
        Integration integration = integrationHandler.getIntegration(id);
        addToExport(memJsonDB, integration);
        resourceManager.collectDependencies(integration.getSteps(), true).stream().filter(Dependency::isExtension).map(Dependency::getId).forEach(extensions::add);
    }
    LOG.debug("Extensions: {}", extensions);
    return out -> {
        try (ZipOutputStream tos = new ZipOutputStream(out)) {
            ModelExport exportObject = ModelExport.of(Schema.VERSION);
            addEntry(tos, EXPORT_MODEL_INFO_FILE_NAME, Json.writer().writeValueAsBytes(exportObject));
            addEntry(tos, EXPORT_MODEL_FILE_NAME, memJsonDB.getAsByteArray("/"));
            memJsonDB.close();
            for (String extensionId : extensions) {
                addEntry(tos, "extensions/" + Names.sanitize(extensionId) + ".jar", IOUtils.toByteArray(extensionDataManager.getExtensionBinaryFile(extensionId)));
            }
        }
    };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) ClientErrorException(javax.ws.rs.ClientErrorException) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Connection(io.syndesis.common.model.connection.Connection) IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) Integration(io.syndesis.common.model.integration.Integration) ZipEntry(java.util.zip.ZipEntry) JsonDbDao(io.syndesis.server.jsondb.dao.JsonDbDao) Context(javax.ws.rs.core.Context) Connector(io.syndesis.common.model.connection.Connector) StreamingOutput(javax.ws.rs.core.StreamingOutput) ListResult(io.syndesis.common.model.ListResult) Extension(io.syndesis.common.model.extension.Extension) NotNull(javax.validation.constraints.NotNull) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) ZipOutputStream(java.util.zip.ZipOutputStream) Migrator(io.syndesis.server.jsondb.dao.Migrator) ZipInputStream(java.util.zip.ZipInputStream) GET(javax.ws.rs.GET) Step(io.syndesis.common.model.integration.Step) Kind(io.syndesis.common.model.Kind) Names(io.syndesis.common.util.Names) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StreamUtils.nonClosing(org.springframework.util.StreamUtils.nonClosing) DataManager(io.syndesis.server.dao.manager.DataManager) FileDataManager(io.syndesis.server.dao.file.FileDataManager) Api(io.swagger.annotations.Api) MemorySqlJsonDB(io.syndesis.server.jsondb.impl.MemorySqlJsonDB) LinkedHashSet(java.util.LinkedHashSet) SqlJsonDB(io.syndesis.server.jsondb.impl.SqlJsonDB) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) CloseableJsonDB(io.syndesis.server.jsondb.CloseableJsonDB) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) WithId(io.syndesis.common.model.WithId) IOException(java.io.IOException) JsonDB(io.syndesis.server.jsondb.JsonDB) ModelExport(io.syndesis.common.model.ModelExport) Dependency(io.syndesis.common.model.Dependency) Component(org.springframework.stereotype.Component) Schema(io.syndesis.common.model.Schema) IntegrationResourceManager(io.syndesis.integration.api.IntegrationResourceManager) IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) ChangeEvent(io.syndesis.common.model.ChangeEvent) Json(io.syndesis.common.util.Json) InputStream(java.io.InputStream) Integration(io.syndesis.common.model.integration.Integration) CloseableJsonDB(io.syndesis.server.jsondb.CloseableJsonDB) Dependency(io.syndesis.common.model.Dependency) ZipOutputStream(java.util.zip.ZipOutputStream) ClientErrorException(javax.ws.rs.ClientErrorException) ModelExport(io.syndesis.common.model.ModelExport) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 49 with Integration

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

the class TestSupportHandler method deleteDeployments.

@GET
@Path("/delete-deployments")
public void deleteDeployments() {
    LOG.warn("user {} is deleting all integration deploymets", context.getRemoteUser());
    List<Integration> integrations = dataMgr.fetchAll(Integration.class).getItems();
    for (Integration i : integrations) {
        if (openShiftService.exists(i.getName())) {
            openShiftService.delete(i.getName());
            LOG.debug("Deleting integration \"{}\"", i.getName());
        } else {
            LOG.debug("Skipping integration named \"{}\". No such deployment found.", i.getName());
        }
    }
}
Also used : Integration(io.syndesis.common.model.integration.Integration) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 50 with Integration

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

the class UniquePropertyValidatorTest method parameters.

@Parameters
public static Iterable<Object[]> parameters() {
    final Connection existingNameNoId = new Connection.Builder().name("Existing").build();
    final Connection existingNameWithSameId = new Connection.Builder().name("Existing").id("same").build();
    final Connection existingNameWithDifferentId = new Connection.Builder().name("Existing").id("different").build();
    final Connection uniqueNameNoId = new Connection.Builder().name("Unique").build();
    final Integration existingButDeleted = new Integration.Builder().name("Existing").id("different").build();
    return // 
    Arrays.asList(// 
    new Object[] { existingNameNoId, false }, // 
    new Object[] { existingNameWithSameId, true }, // 
    new Object[] { existingNameWithDifferentId, false }, // 
    new Object[] { uniqueNameNoId, true }, // 
    new Object[] { existingButDeleted, true });
}
Also used : Integration(io.syndesis.common.model.integration.Integration) ConstraintViolationBuilder(javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder) Connection(io.syndesis.common.model.connection.Connection) Parameters(org.junit.runners.Parameterized.Parameters)

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