Search in sources :

Example 31 with Account

use of io.syndesis.qe.account.Account 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 32 with Account

use of io.syndesis.qe.account.Account in project syndesis-qe by syndesisio.

the class OAuthJiraAuthenticationHandler method createAccessToken.

private AbstractOAuthGetToken createAccessToken() throws NoSuchAlgorithmException, InvalidKeySpecException {
    Account jiraAccount = AccountsDirectory.getInstance().get("Jira");
    String privateKey = jiraAccount.getProperty("privatekey");
    String tempToken = jiraAccount.getProperty("accesstoken");
    String verifier = jiraAccount.getProperty("verificationcode");
    String consumerKey = jiraAccount.getProperty("consumerkey");
    String jiraUrl = jiraAccount.getProperty("jiraurl");
    byte[] privateBytes = Base64.decodeBase64(privateKey);
    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateBytes);
    KeyFactory kf = KeyFactory.getInstance("RSA");
    OAuthRsaSigner oAuthRsaSigner = new OAuthRsaSigner();
    oAuthRsaSigner.privateKey = kf.generatePrivate(keySpec);
    JiraOAuthGetAccessToken accessToken = new JiraOAuthGetAccessToken(jiraUrl + "/plugins/servlet/oauth/access-token");
    accessToken.temporaryToken = tempToken;
    accessToken.signer = oAuthRsaSigner;
    accessToken.transport = new ApacheHttpTransport();
    accessToken.verifier = verifier;
    accessToken.consumerKey = consumerKey;
    return accessToken;
}
Also used : Account(io.syndesis.qe.account.Account) OAuthRsaSigner(com.google.api.client.auth.oauth.OAuthRsaSigner) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) ApacheHttpTransport(com.google.api.client.http.apache.ApacheHttpTransport) KeyFactory(java.security.KeyFactory)

Example 33 with Account

use of io.syndesis.qe.account.Account in project syndesis-qe by syndesisio.

the class TestUtils method transhipExternalProperties.

/**
 * This is method for transhipping externally dynamicaly generated connection data(Database, etc.) into
 * io.syndesis.qe.Account properties.
 *
 * @param connectionName name of the connection
 * @param sourceMap source map
 */
private static void transhipExternalProperties(String connectionName, Map<String, String> sourceMap) {
    Optional<Account> optional = AccountsDirectory.getInstance().getAccount(connectionName);
    Account account;
    if (!optional.isPresent()) {
        account = new Account();
        account.setService(connectionName);
        AccountsDirectory.getInstance().setAccount(connectionName, account);
    } else {
        account = optional.get();
    }
    Map<String, String> properties = account.getProperties();
    if (properties == null) {
        account.setProperties(new HashMap<>());
        properties = account.getProperties();
    }
    switch(account.getService()) {
        case "oracle12":
        case "mysql":
            properties.put("url", sourceMap.get("db.jdbc_url"));
            properties.put("user", sourceMap.get("db.username"));
            properties.put("password", sourceMap.get("db.password"));
            properties.put("schema", sourceMap.get("db.schema"));
            log.debug("UPDATED ACCOUNT {} PROPERTIES:", account.getService());
            properties.forEach((key, value) -> log.debug("Key: *{}*, value: *{}*", key, value));
            break;
    }
}
Also used : Account(io.syndesis.qe.account.Account)

Example 34 with Account

use of io.syndesis.qe.account.Account in project syndesis-qe by syndesisio.

the class IssueHooksUtils method getZenHubPipeline.

private static String getZenHubPipeline(Scenario scenario, String issueNumber) {
    // TODO: this whole thing should probably be refactored eventually
    String oauthToken = "";
    Optional<Account> optional = AccountsDirectory.getInstance().getAccount(Account.Name.ZENHUB);
    if (optional.isPresent()) {
        if (!optional.get().getProperties().containsKey("APIToken")) {
            logError(scenario, "Account with name \"ZenHub\" and property \"APIToken\" is required in credentials.json file.");
            return null;
        } else {
            oauthToken = optional.get().getProperty("APIToken");
        }
    }
    // hardcoded syndesis repo id for now
    JsonNode jsonNode = EndpointClient.getClient().target("https://api.zenhub.io/p1/repositories/105563335/issues/" + issueNumber).request(MediaType.APPLICATION_JSON).header("X-Authentication-Token", oauthToken).get(JsonNode.class);
    if (jsonNode != null && jsonNode.has("pipeline") && jsonNode.get("pipeline").has("name")) {
        return jsonNode.get("pipeline").get("name").asText();
    } else {
        logError(scenario, "No ZenHub pipeline info found for issue " + issueNumber);
        return null;
    }
}
Also used : Account(io.syndesis.qe.account.Account) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 35 with Account

use of io.syndesis.qe.account.Account in project syndesis-qe by syndesisio.

the class IssueHooksUtils method getJiraClient.

private static JiraRestClient getJiraClient(Scenario scenario) {
    String userName = "";
    String password = "";
    String instanceUrl = "";
    URI uri = null;
    Optional<Account> account = AccountsDirectory.getInstance().getAccount(Account.Name.JIRA_HOOK);
    if (account.isPresent()) {
        if (!account.get().getProperties().keySet().containsAll(Arrays.asList("username", "password", "instanceUrl"))) {
            logError(scenario, "Account with name \"Jira\" and properties \"username\", \"password\", \"instanceUrl\" is required in credentials.json file.");
            logError(scenario, "If you want to get known issues from Jira in logs in case of scenario fails, update your credentials.");
            return null;
        } else {
            userName = account.get().getProperty("username");
            password = account.get().getProperty("password");
            instanceUrl = account.get().getProperty("instanceUrl");
        }
    }
    JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
    try {
        uri = new URI(instanceUrl);
    } catch (URISyntaxException e) {
        log.error("URL {} is a malformed URL", instanceUrl);
        e.printStackTrace();
    }
    return factory.createWithBasicHttpAuthentication(uri, userName, password);
}
Also used : Account(io.syndesis.qe.account.Account) AsynchronousJiraRestClientFactory(com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory) JiraRestClientFactory(com.atlassian.jira.rest.client.api.JiraRestClientFactory) AsynchronousJiraRestClientFactory(com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

Account (io.syndesis.qe.account.Account)51 HashMap (java.util.HashMap)21 GoogleAccount (io.syndesis.qe.utils.google.GoogleAccount)10 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)9 Then (io.cucumber.java.en.Then)6 When (io.cucumber.java.en.When)6 Given (io.cucumber.java.en.Given)5 ArrayList (java.util.ArrayList)5 TimeoutException (java.util.concurrent.TimeoutException)5 List (java.util.List)4 ElementsCollection (com.codeborne.selenide.ElementsCollection)3 Form (io.syndesis.qe.fragments.common.form.Form)3 AsynchronousJiraRestClientFactory (com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory)2 SelenideElement (com.codeborne.selenide.SelenideElement)2 ElementNotFound (com.codeborne.selenide.ex.ElementNotFound)2 DataTable (io.cucumber.datatable.DataTable)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)2