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());
}
}
}
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);
}
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);
}
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());
}
}
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));
}
Aggregations