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