Search in sources :

Example 1 with ProcessHeartbeat

use of com.walmartlabs.concord.runtime.common.ProcessHeartbeat 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)

Example 2 with ProcessHeartbeat

use of com.walmartlabs.concord.runtime.common.ProcessHeartbeat in project concord by walmartlabs.

the class Main method main.

public static void main(String[] args) throws Exception {
    RunnerConfiguration runnerCfg = readRunnerConfiguration(args);
    // create the inject with all dependencies and services available before
    // the actual process' working directory is ready. It allows us to load
    // all dependencies and have them available in "pre-fork" situations
    Injector injector = InjectorFactory.createDefault(runnerCfg);
    try {
        ProcessConfiguration processCfg = injector.getInstance(ProcessConfiguration.class);
        ApiClient apiClient = injector.getInstance(ApiClient.class);
        ProcessHeartbeat heartbeat = new ProcessHeartbeat(apiClient, processCfg.instanceId(), runnerCfg.api().maxNoHeartbeatInterval());
        heartbeat.start();
        Main main = injector.getInstance(Main.class);
        main.execute();
        System.exit(0);
    } catch (MultiException e) {
        log.error(e.getMessage());
        System.exit(1);
    } catch (Throwable t) {
        log.error("", t);
        System.exit(1);
    }
}
Also used : ProcessHeartbeat(com.walmartlabs.concord.runtime.common.ProcessHeartbeat) ProcessConfiguration(com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration) Injector(com.google.inject.Injector) RunnerConfiguration(com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration) ApiClient(com.walmartlabs.concord.ApiClient) MultiException(com.walmartlabs.concord.svm.MultiException)

Aggregations

ApiClient (com.walmartlabs.concord.ApiClient)2 ProcessHeartbeat (com.walmartlabs.concord.runtime.common.ProcessHeartbeat)2 Injector (com.google.inject.Injector)1 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)1 RunnerConfiguration (com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration)1 ProcessConfiguration (com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration)1 MultiException (com.walmartlabs.concord.svm.MultiException)1 Path (java.nio.file.Path)1