Search in sources :

Example 21 with ApiClient

use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.

the class NodeRosterTask method findFacts.

/**
 * Find facts for a given host name or host id
 */
public void findFacts(Context ctx, Map<String, Object> paramsCfg) throws Exception {
    ApiClient clientConfig = clientConfig(ctx, paramsCfg);
    NodeRosterFactsApi api = new NodeRosterFactsApi(clientConfig);
    Object facts = NodeRosterTaskUtils.findFacts(api, paramsCfg);
    ctx.setVariable("result", createResponse(facts));
}
Also used : ApiClient(com.walmartlabs.concord.ApiClient)

Example 22 with ApiClient

use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.

the class SleepTask method execute.

@Override
public void execute(Context ctx) throws Exception {
    Supplier<Suspender> suspender = () -> {
        ApiClient apiClient = apiClientFactory.create(ApiClientConfiguration.builder().context(ctx).build());
        return new Suspender(apiClient, ContextUtils.getTxId(ctx));
    };
    Map<String, Object> cfg = createCfg(ctx);
    TaskResult taskResult = new SleepTaskCommon(suspender).execute(new TaskParams(cfg));
    if (taskResult instanceof TaskResult.SuspendResult) {
        ctx.suspend(((TaskResult.SuspendResult) taskResult).eventName());
    }
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) ApiClient(com.walmartlabs.concord.ApiClient)

Example 23 with ApiClient

use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.

the class SecretServiceImpl method encryptString.

@Override
public String encryptString(Context ctx, String instanceId, String orgName, String projectName, String value) throws Exception {
    ApiClientConfiguration cfg = ApiClientConfiguration.builder().sessionToken(ContextUtils.getSessionToken(ctx)).txId(UUID.fromString(instanceId)).build();
    ApiClient c = clientFactory.create(cfg);
    String path = "/api/v1/org/" + orgName + "/project/" + projectName + "/encrypt";
    Map<String, String> headerParams = new HashMap<>();
    headerParams.put("Content-Type", "text/plain;charset=UTF-8");
    ApiResponse<EncryptValueResponse> r = ClientUtils.postData(c, path, value, headerParams, EncryptValueResponse.class);
    if (r.getStatusCode() == 200 && r.getData().isOk()) {
        return r.getData().getData();
    }
    throw new ApiException("Error encrypting string. Status code:" + r.getStatusCode() + " Data: " + r.getData());
}
Also used : HashMap(java.util.HashMap) ApiClient(com.walmartlabs.concord.ApiClient) ApiException(com.walmartlabs.concord.ApiException)

Example 24 with ApiClient

use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.

the class AbstractOneOpsTriggerIT method sendOneOpsEvent.

protected void sendOneOpsEvent(String payloadPath) throws Exception {
    ApiClient apiClient = getApiClient();
    OkHttpClient httpClient = apiClient.getHttpClient();
    String payload = resourceToString(payloadPath);
    HttpUrl.Builder b = HttpUrl.parse(apiClient.getBasePath() + "/api/v1/events/oneops").newBuilder();
    Request req = new Request.Builder().url(b.build()).post(RequestBody.create(MediaType.parse("application/json"), payload)).header("Authorization", ServerClient.DEFAULT_API_KEY).build();
    Response resp = httpClient.newCall(req).execute();
    if (!resp.isSuccessful()) {
        throw new RuntimeException("Request failed: " + resp);
    }
}
Also used : ApiClient(com.walmartlabs.concord.ApiClient)

Example 25 with ApiClient

use of com.walmartlabs.concord.ApiClient in project concord by walmartlabs.

the class JsonStoreIT method test.

/**
 * Tests various methods of the 'jsonStore' plugin.
 */
@Test
@SuppressWarnings("unchecked")
public void test() throws Exception {
    ApiClient apiClient = concord.apiClient();
    String orgName = "org_" + randomString();
    OrganizationsApi orgApi = new OrganizationsApi(apiClient);
    orgApi.createOrUpdate(new OrganizationEntry().setName(orgName));
    String projectName = "project_" + randomString();
    ProjectsApi projectsApi = new ProjectsApi(apiClient);
    projectsApi.createOrUpdate(orgName, new ProjectEntry().setName(projectName).setRawPayloadMode(ProjectEntry.RawPayloadModeEnum.OWNERS));
    String storeName = "store_" + randomString();
    // ---
    Payload payload = new Payload().org(orgName).project(projectName).archive(resource("jsonStore")).arg("storeName", storeName);
    ConcordProcess proc = concord.processes().start(payload);
    expectStatus(proc, ProcessEntry.StatusEnum.FINISHED);
    proc.assertLog(".*the store doesn't exist.*");
    proc.assertLog(".*the item doesn't exist.*");
    proc.assertLog(".*the store exists now.*");
    proc.assertLog(".*the item exists now.*");
    proc.assertLog(".*empty: ==.*");
    proc.assertLog(".*get: \\{x=1}.*");
    proc.assertLog(".*Updating item 'test2'.*" + orgName + ".*" + storeName + ".*");
    // ---
    JsonStoreDataApi jsonStoreDataApi = new JsonStoreDataApi(apiClient);
    Object test = jsonStoreDataApi.get(orgName, storeName, "test2");
    assertNotNull(test);
    assertTrue(test instanceof Map);
    Map<String, Object> m = (Map<String, Object>) test;
    assertEquals(m.get("x"), "1");
}
Also used : ConcordProcess(ca.ibodrov.concord.testcontainers.ConcordProcess) Payload(ca.ibodrov.concord.testcontainers.Payload) ITUtils.randomString(com.walmartlabs.concord.it.common.ITUtils.randomString) ApiClient(com.walmartlabs.concord.ApiClient) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

ApiClient (com.walmartlabs.concord.ApiClient)27 Test (org.junit.jupiter.api.Test)7 ITUtils.randomString (com.walmartlabs.concord.it.common.ITUtils.randomString)4 ConcordProcess (ca.ibodrov.concord.testcontainers.ConcordProcess)3 Payload (ca.ibodrov.concord.testcontainers.Payload)3 TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 OkHttpClient (com.squareup.okhttp.OkHttpClient)2 ApiException (com.walmartlabs.concord.ApiException)2 ConcordApiClient (com.walmartlabs.concord.client.ConcordApiClient)2 ProcessHeartbeat (com.walmartlabs.concord.runtime.common.ProcessHeartbeat)2 Path (java.nio.file.Path)2 UUID (java.util.UUID)2 WebElement (org.openqa.selenium.WebElement)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMockTest (com.github.tomakehurst.wiremock.junit5.WireMockTest)1 Injector (com.google.inject.Injector)1 HttpUrl (com.squareup.okhttp.HttpUrl)1 Request (com.squareup.okhttp.Request)1