Search in sources :

Example 51 with Connection

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

the class RestTestHooks method afterTest.

@After
public void afterTest() {
    stepStorage.flushStepDefinitions();
    log.debug("Flushed steps from steps storage");
    SampleDbConnectionManager.closeConnections();
    if (TestConfiguration.isDeloreanEnvironment()) {
        // delete all integrations and connections after the test. Only for Delorean since it doesn't support TEST_SUPPORT env
        List<Integration> integrations = integrationsEndpoint.list();
        for (Integration integration : integrations) {
            integrationsEndpoint.delete(integration.getId().get());
        }
        List<Connection> connections = connectionsEndpoint.list();
        for (Connection connection : connections) {
            if (SyndesisDB.DEFAULT_PSQL_CONNECTION_ORIGINAL.equals(connection.getName()) || SyndesisDB.DEFAULT_PSQL_CONNECTION_BACKUP.equals(connection.getName()) || // for default connections (Webhook, Log, Flow, Timer, Api Provider etc.) We don't want to delete them
            connection.getTags().isEmpty()) {
                continue;
            }
            connectionsEndpoint.delete(connection.getId().get());
        }
    }
}
Also used : Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) After(io.cucumber.java.After)

Example 52 with Connection

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

the class Connections method createConnection.

@Given("create connection")
public void createConnection(DataTable connectionProperties) {
    List<List<String>> cells = connectionProperties.cells();
    Map<String, String> connectionPropertiesMap = new HashMap<>();
    for (List<String> cell : cells) {
        connectionPropertiesMap.put(cell.get(0), cell.get(1));
    }
    final String connectorName = connectionPropertiesMap.get("connector").toUpperCase();
    final String connectorId = RestTestsUtils.Connector.valueOf(connectorName).getId();
    final String connectionId = connectionPropertiesMap.get("connectionId");
    final String connectionName = connectionPropertiesMap.get("name");
    final Connector connector = connectorsEndpoint.get(connectorId);
    connectionPropertiesMap.remove("connector");
    connectionPropertiesMap.remove("connectionId");
    connectionPropertiesMap.remove("account");
    connectionPropertiesMap.remove("name");
    for (Map.Entry<String, String> keyValue : connectionPropertiesMap.entrySet()) {
        if ("$ACCOUNT$".equals(keyValue.getValue())) {
            keyValue.setValue(accountsDirectory.get(connectionPropertiesMap.get("account")).getProperty(keyValue.getKey()));
        }
    }
    final Connection connection = new Connection.Builder().connector(connector).connectorId(getConnectorId(connector)).id(connectionId != null ? connectionId : RestTestsUtils.Connection.valueOf(connectorName).getId()).name(connectionName != null ? connectionName : "Fuse QE " + connectorName).configuredProperties(connectionPropertiesMap).icon(connector.getIcon()).tags(Collections.singletonList(connectorId)).build();
    log.info("Creating {} connection with properties {}", connectorId, connectionPropertiesMap);
    connectionsEndpoint.create(connection);
}
Also used : Connector(io.syndesis.common.model.connection.Connector) HashMap(java.util.HashMap) S3BucketNameBuilder(io.syndesis.qe.utils.aws.S3BucketNameBuilder) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Given(io.cucumber.java.en.Given)

Example 53 with Connection

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

the class SyndesisDB method deploy.

@Override
public void deploy() {
    List<ContainerPort> ports = new LinkedList<>();
    ports.add(new ContainerPortBuilder().withName("psql-cmd").withContainerPort(5432).withProtocol("TCP").build());
    List<EnvVar> templateParams = new ArrayList<>();
    templateParams.add(new EnvVar("POSTGRESQL_USER", DB_ROOT_USER, null));
    templateParams.add(new EnvVar("POSTGRESQL_PASSWORD", DB_PASSWORD, null));
    // sample DB schema is created by post start script, this DB is not important
    templateParams.add(new EnvVar("POSTGRESQL_DATABASE", "whatever", null));
    templateParams.add(new EnvVar("POSTGRESQL_SAMPLEDB_PASSWORD", DB_PASSWORD, null));
    // config map with the post start script
    if (OpenShiftUtils.getInstance().getConfigMap("syndesis-sampledb-config") == null) {
        try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-sampledb-config.yml")) {
            ConfigMap cm = OpenShiftUtils.getInstance().configMaps().load(is).get();
            OpenShiftUtils.getInstance().createConfigMap(cm);
        } catch (IOException ex) {
            throw new IllegalArgumentException("Unable to read config map ", ex);
        }
    }
    OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage("quay.io/syndesis_qe/postgresql-10-centos7:latest").addAllToPorts(ports).addAllToEnv(templateParams).editOrNewLifecycle().editOrNewPostStart().editOrNewExec().addNewCommand("/bin/sh").addNewCommand("-c").addNewCommand("/var/lib/pgsql/sampledb/postStart.sh").endExec().endPostStart().endLifecycle().addNewVolumeMount().withNewMountPath("/var/lib/pgsql/sampledb").withName("syndesis-sampledb-config").endVolumeMount().endContainer().addNewVolume().editOrNewConfigMap().withName("syndesis-sampledb-config").withDefaultMode(511).endConfigMap().withName("syndesis-sampledb-config").endVolume().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
    ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
    serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("psql-cmd").withPort(5432).withTargetPort(new IntOrString(5432)).build());
    OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
    try {
        OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.areExactlyNPodsReady(LABEL_NAME, APP_NAME, 1));
        Thread.sleep(20 * 1000);
    } catch (InterruptedException | TimeoutException e) {
        log.error("Wait for {} deployment failed ", APP_NAME, e);
    }
    Account syndesisDbAccount = new Account();
    syndesisDbAccount.setService("SyndesisDB");
    Map<String, String> accountParameters = new HashMap<>();
    accountParameters.put("url", DB_URL);
    accountParameters.put("user", DB_SAMPLE_DB_USER);
    accountParameters.put("password", DB_PASSWORD);
    accountParameters.put("schema", DB_SCHEMA);
    syndesisDbAccount.setProperties(accountParameters);
    AccountsDirectory.getInstance().addAccount(Account.Name.SYNDESIS_DB.getId(), syndesisDbAccount);
    Connection defaultPostgresDBConnection = connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_ORIGINAL);
    // (When the test suite was killed before, the backup can exist and original connection was already changed, ignore in that case
    if (connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_BACKUP) == null) {
        connectionsEndpoint.create(defaultPostgresDBConnection.builder().name(DEFAULT_PSQL_CONNECTION_BACKUP).id("1000").build());
    }
    // config prop for new instance
    Map<String, String> configuredProperties = new HashMap<>(defaultPostgresDBConnection.getConfiguredProperties());
    configuredProperties.put("schema", DB_SCHEMA);
    configuredProperties.put("password", DB_PASSWORD);
    configuredProperties.put("user", DB_SAMPLE_DB_USER);
    configuredProperties.put("url", DB_URL);
    Connection build = defaultPostgresDBConnection.builder().configuredProperties(configuredProperties).build();
    connectionsEndpoint.update(defaultPostgresDBConnection.getId().get(), build);
}
Also used : Account(io.syndesis.qe.account.Account) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) IOException(java.io.IOException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) LinkedList(java.util.LinkedList) ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) TimeoutException(java.util.concurrent.TimeoutException)

Example 54 with Connection

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

the class SyndesisDB method undeploy.

@Override
public void undeploy() {
    try {
        OpenShiftUtils.getInstance().getDeploymentConfigs().stream().filter(dc -> dc.getMetadata().getName().equals(APP_NAME)).findFirst().ifPresent(dc -> OpenShiftUtils.getInstance().deleteDeploymentConfig(dc, true));
        OpenShiftUtils.getInstance().getServices().stream().filter(service -> APP_NAME.equals(service.getMetadata().getName())).findFirst().ifPresent(service -> OpenShiftUtils.getInstance().deleteService(service));
        TestUtils.sleepIgnoreInterrupt(5000);
    } catch (Exception e) {
        log.error("Error thrown while trying to delete Syndesis DB PostgreSQL database. It is just deletion, it should not affect following tests.", e);
    }
    // revert changes if the default connection was changes
    if (connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_BACKUP) != null) {
        Connection backupConnection = connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_BACKUP);
        Connection defaultConnection = connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_ORIGINAL);
        Map<String, String> originalConfiguredProperties = new HashMap<>(backupConnection.getConfiguredProperties());
        Connection build = defaultConnection.builder().configuredProperties(originalConfiguredProperties).build();
        connectionsEndpoint.update(defaultConnection.getId().get(), build);
        connectionsEndpoint.delete(backupConnection.getId().get());
    }
}
Also used : HashMap(java.util.HashMap) Connection(io.syndesis.common.model.connection.Connection) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException)

Example 55 with Connection

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

the class DbSteps method createFinishDbInvokeSqlStep.

@Then("^create finish DB invoke sql action step with query \"([^\"]*)\"")
public void createFinishDbInvokeSqlStep(String sqlQuery) {
    final Connection dbConnection = connectionsEndpoint.get(getDbConnectionId());
    final Connector dbConnector = connectorsEndpoint.get("sql");
    final Action dbAction = TestUtils.findConnectorAction(dbConnector, "sql-connector");
    final Map<String, String> properties = TestUtils.map("query", sqlQuery);
    final ConnectorDescriptor connectorDescriptor = getConnectorDescriptor(dbAction, properties, dbConnection.getId().get());
    final Step dbStep = new Step.Builder().stepKind(StepKind.endpoint).id(UUID.randomUUID().toString()).connection(dbConnection).action(generateStepAction(dbAction, connectorDescriptor)).configuredProperties(properties).build();
    steps.getStepDefinitions().add(new StepDefinition(dbStep, connectorDescriptor));
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Action(io.syndesis.common.model.action.Action) Connection(io.syndesis.common.model.connection.Connection) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) Step(io.syndesis.common.model.integration.Step) AbstractStep(io.syndesis.qe.bdd.AbstractStep) Then(cucumber.api.java.en.Then)

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