Search in sources :

Example 76 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class KnativeCustomizerTest method testKnativeCustomizerChannels.

@Test
public void testKnativeCustomizerChannels() throws IOException {
    Connector connector;
    ConnectorAction sinkAction;
    ConnectorAction sourceAction;
    try (InputStream is = KnativeCustomizerTest.class.getResourceAsStream("/META-INF/syndesis/connector/knative.json")) {
        connector = JsonUtils.readFromStream(is, Connector.class);
        sinkAction = connector.getActions(ConnectorAction.class).stream().filter(a -> a.getId().get().equals("io.syndesis:knative-channel-send-connector")).findFirst().orElseThrow(() -> new IllegalArgumentException());
        sourceAction = connector.getActions(ConnectorAction.class).stream().filter(a -> a.getId().get().equals("io.syndesis:knative-channel-receive-connector")).findFirst().orElseThrow(() -> new IllegalArgumentException());
    }
    TestResourceManager manager = new TestResourceManager();
    Integration integration = manager.newIntegration(new Step.Builder().stepKind(StepKind.endpoint).putConfiguredProperty("name", "my-channel-sink").action(sinkAction).connection(new Connection.Builder().connector(connector).build()).build(), new Step.Builder().stepKind(StepKind.endpoint).putConfiguredProperty("name", "my-channel-source").action(sourceAction).connection(new Connection.Builder().connector(connector).build()).build());
    IntegrationDeployment deployment = new IntegrationDeployment.Builder().userId("user").id("idId").spec(integration).build();
    CamelKIntegrationCustomizer customizer = new KnativeCustomizer();
    io.syndesis.server.controller.integration.camelk.crd.Integration i = customizer.customize(deployment, new io.syndesis.server.controller.integration.camelk.crd.Integration(), EnumSet.of(Exposure.SERVICE));
    assertThat(i.getSpec().getTraits()).containsKey("knative");
    assertThat(i.getSpec().getTraits().get("knative").getConfiguration()).containsOnly(entry("enabled", "true"), entry("channel-sources", "my-channel-source"), entry("channel-sinks", "my-channel-sink"), entry("endpoint-sources", "default"), entry("endpoint-sinks", ""));
}
Also used : ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step) TestResourceManager(io.syndesis.server.controller.integration.camelk.TestResourceManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Connector(io.syndesis.common.model.connection.Connector) IOException(java.io.IOException) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) JsonUtils(io.syndesis.common.util.json.JsonUtils) Connection(io.syndesis.common.model.connection.Connection) Exposure(io.syndesis.server.openshift.Exposure) StepKind(io.syndesis.common.model.integration.StepKind) Integration(io.syndesis.common.model.integration.Integration) EnumSet(java.util.EnumSet) InputStream(java.io.InputStream) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) InputStream(java.io.InputStream) Connection(io.syndesis.common.model.connection.Connection) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) TestResourceManager(io.syndesis.server.controller.integration.camelk.TestResourceManager) Test(org.junit.Test)

Example 77 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class OAuth1Applicator method applyTo.

@Override
public Connection applyTo(final Connection connection, final OAuthToken token) {
    final Connection.Builder mutableConnection = new Connection.Builder().createFrom(connection).lastUpdated(new Date());
    Applicator.applyProperty(mutableConnection, accessTokenValueProperty, token.getValue());
    Applicator.applyProperty(mutableConnection, accessTokenSecretProperty, token.getSecret());
    Applicator.applyProperty(mutableConnection, consumerKeyProperty, consumerKey);
    Applicator.applyProperty(mutableConnection, consumerSecretProperty, consumerSecret);
    return mutableConnection.build();
}
Also used : Connection(io.syndesis.common.model.connection.Connection) Date(java.util.Date)

Example 78 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class PublicApiHandlerTest method importResources.

@Test
public void importResources() {
    final DataManager dataManager = mock(DataManager.class);
    final SecurityContext securityContext = newMockSecurityContext();
    final InputStream givenDataStream = new ByteArrayInputStream(new byte[0]);
    // too convoluted to use the implementation directly
    final IntegrationSupportHandler supportHandler = mock(IntegrationSupportHandler.class);
    final Connection testConnection = new Connection.Builder().id("connection-id").connectorId("connector-id").name("test-connection").build();
    final Integration integration = new Integration.Builder().id("integration-id").addConnection(testConnection).build();
    Map<String, List<WithResourceId>> resultMap = new HashMap<>();
    resultMap.put("integration-id", Collections.singletonList(integration));
    resultMap.put("connection-id", Collections.singletonList(testConnection));
    when(supportHandler.importIntegration(securityContext, givenDataStream)).thenReturn(resultMap);
    final Environment env = newEnvironment("env");
    when(dataManager.fetchByPropertyValue(Environment.class, "name", "env")).thenReturn(Optional.of(env));
    when(dataManager.fetch(Connector.class, "connector-id")).thenReturn(new Connector.Builder().putProperty("prop", new ConfigurationProperty.Builder().build()).build());
    when(dataManager.fetchAll(eq(Integration.class), any())).then((Answer<ListResult<Integration>>) invocation -> {
        final Object[] arguments = invocation.getArguments();
        ListResult<Integration> result = new ListResult.Builder<Integration>().addItem(integration).build();
        for (int i = 1; i < arguments.length; i++) {
            @SuppressWarnings("unchecked") Function<ListResult<Integration>, ListResult<Integration>> operator = (Function<ListResult<Integration>, ListResult<Integration>>) arguments[i];
            result = operator.apply(result);
        }
        return result;
    });
    final EnvironmentHandler environmentHandler = new EnvironmentHandler(dataManager);
    final IntegrationDeploymentHandler deploymentHandler = mock(IntegrationDeploymentHandler.class);
    final EncryptionComponent encryptionComponent = mock(EncryptionComponent.class);
    when(encryptionComponent.encryptPropertyValues(any(), any())).thenReturn(Collections.singletonMap("prop", "value"));
    IntegrationHandler integrationHandler = mock(IntegrationHandler.class);
    when(integrationHandler.getOverview(any())).thenReturn(new IntegrationOverview.Builder().createFrom(integration).connections(Collections.singletonList(testConnection.builder().putConfiguredProperty("prop", "value").build())).build());
    // null's are not used
    final PublicApiHandler handler = new PublicApiHandler(dataManager, encryptionComponent, deploymentHandler, null, null, environmentHandler, supportHandler, integrationHandler);
    final PublicApiHandler.ImportFormDataInput formInput = new PublicApiHandler.ImportFormDataInput();
    formInput.setData(givenDataStream);
    formInput.setProperties(new ByteArrayInputStream("test-connection.prop=value".getBytes(StandardCharsets.UTF_8)));
    formInput.setRefreshIntegrations(Boolean.TRUE);
    formInput.setEnvironment("env");
    formInput.setDeploy(Boolean.TRUE);
    final ContinuousDeliveryImportResults importResults = handler.importResources(securityContext, formInput);
    verify(deploymentHandler).update(securityContext, "integration-id");
    assertThat(importResults.getLastImportedAt()).isNotNull();
    assertThat(importResults.getResults().size()).isEqualTo(2);
    // verify the integration connection was refreshed
    final Integration importedIntegration = (Integration) importResults.getResults().get(0);
    assertThat(importedIntegration.getConnections().get(0).getConfiguredProperties().get("prop")).isEqualTo("value");
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityContext(javax.ws.rs.core.SecurityContext) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) WithResourceId(io.syndesis.common.model.WithResourceId) ClientErrorException(javax.ws.rs.ClientErrorException) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) Environment(io.syndesis.common.model.environment.Environment) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) ByteArrayInputStream(java.io.ByteArrayInputStream) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) IntegrationDeploymentHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler) IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) Integration(io.syndesis.common.model.integration.Integration) Connector(io.syndesis.common.model.connection.Connector) StreamingOutput(javax.ws.rs.core.StreamingOutput) ListResult(io.syndesis.common.model.ListResult) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) IntegrationSupportHandler(io.syndesis.server.endpoint.v1.handler.integration.support.IntegrationSupportHandler) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ContinuousDeliveryImportResults(io.syndesis.common.model.integration.ContinuousDeliveryImportResults) HashMap(java.util.HashMap) Function(java.util.function.Function) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) DataManager(io.syndesis.server.dao.manager.DataManager) Status(javax.ws.rs.core.Response.Status) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Assertions.entry(org.assertj.core.api.Assertions.entry) Mockito.verify(org.mockito.Mockito.verify) WithName(io.syndesis.common.model.WithName) TargetStateRequest(io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler.TargetStateRequest) MonitoringProvider(io.syndesis.server.endpoint.monitoring.MonitoringProvider) IntegrationDeploymentStateDetails(io.syndesis.common.model.monitoring.IntegrationDeploymentStateDetails) Condition(org.assertj.core.api.Condition) IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) Collections(java.util.Collections) InputStream(java.io.InputStream) Connector(io.syndesis.common.model.connection.Connector) HashMap(java.util.HashMap) Function(java.util.function.Function) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) ContinuousDeliveryImportResults(io.syndesis.common.model.integration.ContinuousDeliveryImportResults) List(java.util.List) IntegrationSupportHandler(io.syndesis.server.endpoint.v1.handler.integration.support.IntegrationSupportHandler) IntegrationDeploymentHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler) IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) Integration(io.syndesis.common.model.integration.Integration) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Connection(io.syndesis.common.model.connection.Connection) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) DataManager(io.syndesis.server.dao.manager.DataManager) ListResult(io.syndesis.common.model.ListResult) ByteArrayInputStream(java.io.ByteArrayInputStream) SecurityContext(javax.ws.rs.core.SecurityContext) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) Environment(io.syndesis.common.model.environment.Environment) Test(org.junit.Test)

Example 79 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class IntegrationSupportHandler method importModels.

public Map<String, List<WithResourceId>> importModels(SecurityContext sec, ModelExport export, JsonDB given) throws IOException {
    // Apply per version migrations to get the schema upgraded on the import.
    int from = export.schemaVersion();
    int to = Schema.VERSION;
    if (from > to) {
        throw new IOException("Cannot import an export at schema version level: " + export.schemaVersion());
    }
    for (int i = from; i < to; i++) {
        int version = i + 1;
        migrator.migrate(given, version);
    }
    Map<String, List<WithResourceId>> result = new HashMap<>();
    // id->new-name map
    Map<String, String> renamedIds = new HashMap<>();
    // Import the extensions..
    final JsonDbDao<Extension> extensionDao = new JsonDbDao<Extension>(given) {

        @Override
        public Class<Extension> getType() {
            return Extension.class;
        }
    };
    final Map<String, String> replacedIds = new HashMap<>();
    importExtensions(extensionDao, replacedIds, renamedIds, result);
    // NOTE: connectors are imported without renaming and ignoring renamed ids
    // as a matter of fact, the lambda should never be called
    importModels(new JsonDbDao<Connector>(given) {

        @Override
        public Class<Connector> getType() {
            return Connector.class;
        }
    }, (c, n) -> new Connector.Builder().createFrom(c).name(c.getName()).build(), new HashMap<>(), result);
    importModels(new JsonDbDao<Connection>(given) {

        @Override
        public Class<Connection> getType() {
            return Connection.class;
        }
    }, IntegrationSupportHandler::renameConnection, renamedIds, result);
    // remove hidden external secrets from imported connections
    final List<WithResourceId> connections = result.get("connections");
    if (connections != null && !connections.isEmpty()) {
        for (WithResourceId connection : connections) {
            removeHiddenExternalSecrets((Connection) connection);
        }
    }
    // import missing environments
    importEnvironments(new JsonDbDao<Environment>(given) {

        @Override
        public Class<Environment> getType() {
            return Environment.class;
        }
    }, replacedIds, renamedIds, result);
    importIntegrations(sec, new JsonDbDao<Integration>(given) {

        @Override
        public Class<Integration> getType() {
            return Integration.class;
        }
    }, renamedIds, replacedIds, result);
    importModels(new JsonDbDao<OpenApi>(given) {

        @Override
        public Class<OpenApi> getType() {
            return OpenApi.class;
        }
    }, (a, n) -> new OpenApi.Builder().createFrom(a).name(n).build(), new HashMap<>(), result);
    importModels(new JsonDbDao<Icon>(given) {

        @Override
        public Class<Icon> getType() {
            return Icon.class;
        }
    }, result);
    return result;
}
Also used : Connector(io.syndesis.common.model.connection.Connector) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) IOException(java.io.IOException) WithResourceId(io.syndesis.common.model.WithResourceId) JsonDbDao(io.syndesis.server.jsondb.dao.JsonDbDao) Extension(io.syndesis.common.model.extension.Extension) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) Environment(io.syndesis.common.model.environment.Environment) Icon(io.syndesis.common.model.icon.Icon) OpenApi(io.syndesis.common.model.openapi.OpenApi)

Example 80 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class IntegrationSupportHandler method addToExport.

private void addToExport(JsonDB export, Integration integration) {
    addModelToExport(export, integration);
    integration.getFlows().stream().flatMap(flow -> flow.getSteps().stream()).forEach(step -> {
        Optional<Connection> c = step.getConnection();
        if (c.isPresent()) {
            Connection connection = c.get();
            addModelToExport(export, connection);
            Connector connector = integrationHandler.getDataManager().fetch(Connector.class, connection.getConnectorId());
            if (connector != null) {
                addModelToExport(export, connector);
                if (connector.getIcon() != null && connector.getIcon().startsWith("db:")) {
                    Icon icon = integrationHandler.getDataManager().fetch(Icon.class, connector.getIcon().substring(3));
                    addModelToExport(export, icon);
                }
            }
        }
        Optional<Extension> e = step.getExtension();
        if (e.isPresent()) {
            Extension extension = e.get();
            addModelToExport(export, extension);
        }
    });
    // add environments
    integration.getContinuousDeliveryState().keySet().forEach(id -> addModelToExport(export, dataManager.fetch(Environment.class, id)));
    addResourcesToExport(export, integration);
}
Also used : OpenApi(io.syndesis.common.model.openapi.OpenApi) Produces(javax.ws.rs.Produces) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) BiFunction(java.util.function.BiFunction) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) WithResourceId(io.syndesis.common.model.WithResourceId) ClientErrorException(javax.ws.rs.ClientErrorException) ExtensionActivator(io.syndesis.server.endpoint.v1.handler.extension.ExtensionActivator) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) Environment(io.syndesis.common.model.environment.Environment) MediaType(javax.ws.rs.core.MediaType) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) JsonUtils(io.syndesis.common.util.json.JsonUtils) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) Integration(io.syndesis.common.model.integration.Integration) Icon(io.syndesis.common.model.icon.Icon) ZipEntry(java.util.zip.ZipEntry) JsonDbDao(io.syndesis.server.jsondb.dao.JsonDbDao) Context(javax.ws.rs.core.Context) Collection(java.util.Collection) Set(java.util.Set) 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) Collectors(java.util.stream.Collectors) Parameter(io.swagger.v3.oas.annotations.Parameter) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) Tag(io.swagger.v3.oas.annotations.tags.Tag) Optional(java.util.Optional) 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) ResourceIdentifier(io.syndesis.common.model.ResourceIdentifier) Kind(io.syndesis.common.model.Kind) HashMap(java.util.HashMap) Names(io.syndesis.common.util.Names) Function(java.util.function.Function) ArrayList(java.util.ArrayList) StreamUtils.nonClosing(org.springframework.util.StreamUtils.nonClosing) DataManager(io.syndesis.server.dao.manager.DataManager) FileDataManager(io.syndesis.server.dao.file.FileDataManager) MemorySqlJsonDB(io.syndesis.server.jsondb.impl.MemorySqlJsonDB) SuppressFBWarnings(io.syndesis.common.util.SuppressFBWarnings) LinkedHashSet(java.util.LinkedHashSet) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) 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) WithName(io.syndesis.common.model.WithName) 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) IconDao(io.syndesis.server.dao.file.IconDao) Collections(java.util.Collections) InputStream(java.io.InputStream) Extension(io.syndesis.common.model.extension.Extension) Connector(io.syndesis.common.model.connection.Connector) Connection(io.syndesis.common.model.connection.Connection) Icon(io.syndesis.common.model.icon.Icon)

Aggregations

Connection (io.syndesis.common.model.connection.Connection)111 Connector (io.syndesis.common.model.connection.Connector)65 Test (org.junit.Test)48 Step (io.syndesis.common.model.integration.Step)40 Integration (io.syndesis.common.model.integration.Integration)38 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)26 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)26 List (java.util.List)24 HashMap (java.util.HashMap)21 Action (io.syndesis.common.model.action.Action)18 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)18 ArrayList (java.util.ArrayList)17 Map (java.util.Map)16 IOException (java.io.IOException)14 InputStream (java.io.InputStream)14 IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)13 StepDefinition (io.syndesis.qe.bdd.entities.StepDefinition)12 DataManager (io.syndesis.server.dao.manager.DataManager)11 Given (cucumber.api.java.en.Given)10 Flow (io.syndesis.common.model.integration.Flow)10