Search in sources :

Example 11 with ApiClient

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

the class NodeRosterTask method findDeployedArtifacts.

/**
 * Find artifacts deployed on a given host
 */
public void findDeployedArtifacts(Context ctx, Map<String, Object> paramsCfg) throws Exception {
    ApiClient clientConfig = clientConfig(ctx, paramsCfg);
    NodeRosterArtifactsApi api = new NodeRosterArtifactsApi(clientConfig);
    List<ArtifactEntry> deployedArtifacts = NodeRosterTaskUtils.findDeployedArtifacts(api, paramsCfg);
    ctx.setVariable("result", createResponse(deployedArtifacts));
}
Also used : ApiClient(com.walmartlabs.concord.ApiClient)

Example 12 with ApiClient

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

the class NodeRosterTask method findHostsWithArtifacts.

/**
 * Find hosts with a deployed artifact
 */
public void findHostsWithArtifacts(Context ctx, Map<String, Object> paramsCfg) throws Exception {
    ApiClient clientConfig = clientConfig(ctx, paramsCfg);
    NodeRosterHostsApi api = new NodeRosterHostsApi(clientConfig);
    List<HostEntry> hosts = NodeRosterTaskUtils.findHostsWithArtifacts(api, paramsCfg);
    ctx.setVariable("result", createResponse(hosts));
}
Also used : ApiClient(com.walmartlabs.concord.ApiClient)

Example 13 with ApiClient

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

the class LockTask method unlock.

public void unlock(@InjectVariable("txId") String instanceId, String lockName, String scope) throws Exception {
    ApiClient apiClient = apiClientFactory.create(context);
    new LockTaskCommon(apiClient, UUID.fromString(instanceId)).unlock(lockName, scope);
}
Also used : ApiClient(com.walmartlabs.concord.ApiClient)

Example 14 with ApiClient

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

the class LockTask method lock.

public void lock(@InjectVariable("txId") String instanceId, String lockName, String scope) throws Exception {
    ApiClient apiClient = apiClientFactory.create(context);
    TaskResult taskResult = new LockTaskCommon(apiClient, UUID.fromString(instanceId)).lock(lockName, scope);
    if (taskResult instanceof TaskResult.SuspendResult) {
        context.suspend(((TaskResult.SuspendResult) taskResult).eventName());
    }
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) ApiClient(com.walmartlabs.concord.ApiClient)

Example 15 with ApiClient

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

the class Main method run.

public void run(RunnerConfiguration runnerCfg, Path baseDir) throws Exception {
    log.debug("run -> working directory: {}", baseDir.toAbsolutePath());
    long t1 = System.currentTimeMillis();
    Path idPath = baseDir.resolve(Constants.Files.INSTANCE_ID_FILE_NAME);
    UUID instanceId = readInstanceId(idPath);
    long t2 = System.currentTimeMillis();
    if (runnerCfg.debug()) {
        log.info("Spent {}ms waiting for the payload", (t2 - t1));
    }
    Map<String, Object> policy = readPolicyRules(baseDir);
    if (policy.isEmpty()) {
        PolicyEngineHolder.INSTANCE.setEngine(null);
    } else {
        PolicyEngineHolder.INSTANCE.setEngine(new PolicyEngine(objectMapper.convertValue(policy, PolicyEngineRules.class)));
    }
    // read the process configuration
    Map<String, Object> processCfg = readRequest(baseDir);
    processCfg = variablesConverter.convert(baseDir, processCfg);
    String sessionToken = getSessionToken(processCfg);
    ApiClient apiClient = apiClientFactory.create(ApiClientConfiguration.builder().sessionToken(sessionToken).txId(instanceId).build());
    ProcessHeartbeat heartbeat = new ProcessHeartbeat(apiClient, instanceId, runnerCfg.api().maxNoHeartbeatInterval());
    heartbeat.start();
    ProcessApiClient processApiClient = new ProcessApiClient(runnerCfg, apiClient);
    processApiClient.updateStatus(instanceId, runnerCfg.agentId(), ProcessEntry.StatusEnum.RUNNING);
    CheckpointManager checkpointManager = new CheckpointManager(instanceId, processApiClient);
    long t3 = System.currentTimeMillis();
    if (runnerCfg.debug()) {
        log.info("Ready to start in {}ms", (t3 - t2));
    }
    executeProcess(instanceId.toString(), checkpointManager, baseDir, processCfg);
}
Also used : Path(java.nio.file.Path) ProcessHeartbeat(com.walmartlabs.concord.runtime.common.ProcessHeartbeat) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) ApiClient(com.walmartlabs.concord.ApiClient)

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