Search in sources :

Example 1 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.

the class ConfluenceTaskV2 method execute.

@Override
public TaskResult execute(Variables input) {
    Result result = new ConfluenceTaskCommon(context.workingDirectory(), context.variables().toMap()).execute(TaskParams.of(input, context.defaultVariables().toMap()));
    TaskResult.SimpleResult taskResult = TaskResult.of(result.ok, result.error);
    if (result.pageId != null) {
        taskResult.value("pageId", result.pageId);
    }
    if (result.childId != null) {
        taskResult.value("childId", result.childId);
    }
    if (result.data != null) {
        taskResult.value("data", result.data);
    }
    return taskResult;
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) ConfluenceTaskCommon(com.walmartlabs.concord.plugins.confluence.ConfluenceTaskCommon) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) Result(com.walmartlabs.concord.plugins.confluence.Result)

Example 2 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.

the class TaskParams method of.

public static TaskParams of(Variables input, Map<String, Object> defaults) {
    Variables variables = merge(input, defaults);
    Action action = new TaskParams(variables).action();
    switch(action) {
        case CPU:
            {
                return new CpuParams(variables);
            }
        case MEMORY:
            {
                return new MemoryParams(variables);
            }
        case DISK:
            {
                return new DiskParams(variables);
            }
        case IO:
            {
                return new IOParams(variables);
            }
        case SHUTDOWN:
            {
                return new ShutdownParams(variables);
            }
        case TIMETRAVEL:
            {
                return new TimeTravelParams(variables);
            }
        case PROCESSKILLER:
            {
                return new ProcessKiller(variables);
            }
        case BLACKHOLE:
            {
                return new BlackHoleParams(variables);
            }
        case DNS:
            {
                return new DnsParams(variables);
            }
        case LATENCY:
            {
                return new LatencyParams(variables);
            }
        case PACKETLOSS:
            {
                return new PacketLossParams(variables);
            }
        case HALT:
            {
                return new HaltParams(variables);
            }
        default:
            throw new IllegalArgumentException("Unsupported action type: " + action);
    }
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables)

Example 3 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.

the class HashiVaultTaskV2Test method testCubbyV2.

@Test
public void testCubbyV2() throws Exception {
    Map<String, Object> varMap = new HashMap<>();
    varMap.put("path", "cubbyhole/hello");
    Variables vars = new MapBackedVariables(varMap);
    SimpleResult result = getTask(true).execute(vars);
    Assert.assertTrue(result.ok());
    final Map<String, Object> data = MapUtils.assertMap(result.values(), "data");
    assertEquals("cubbyVal", data.get("cubbyKey"));
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashMap(java.util.HashMap) SimpleResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult) Test(org.junit.Test)

Example 4 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.

the class HashiVaultTaskV2Test method testKvV2.

@Test
public void testKvV2() throws Exception {
    Map<String, Object> varMap = new HashMap<>();
    varMap.put("path", "secret/testing");
    Variables vars = new MapBackedVariables(varMap);
    SimpleResult result = getTask(true).execute(vars);
    Assert.assertTrue(result.ok());
    final Map<String, Object> data = MapUtils.assertMap(result.values(), "data");
    assertEquals("password1", data.get("top_secret"));
    assertEquals("dbpassword1", data.get("db_password"));
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashMap(java.util.HashMap) SimpleResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult) Test(org.junit.Test)

Example 5 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.

the class HashiVaultTaskV2Test method writeAndRead.

private void writeAndRead(String path, String prefix) throws Exception {
    HashiVaultTask task = getTask(true);
    Map<String, Object> vars1 = new HashMap<>();
    vars1.put("action", "writeKV");
    vars1.put("path", path);
    Map<String, Object> kvPairs = new HashMap<>(2);
    kvPairs.put("key1", prefix + "Value1");
    kvPairs.put("key2", prefix + "Value2");
    vars1.put("kvPairs", kvPairs);
    Variables input1 = new MapBackedVariables(vars1);
    SimpleResult writeResult = task.execute(input1);
    assertTrue(writeResult.ok());
    // -- now get the values back
    // resets context
    task = getTask(true);
    Map<String, Object> vars2 = new HashMap<>();
    vars2.put("action", "readKV");
    vars2.put("path", path);
    Variables input2 = new MapBackedVariables(vars2);
    SimpleResult readResult = task.execute(input2);
    assertTrue(readResult.ok());
    Map<String, Object> data = MapUtils.getMap(readResult.values(), "data", Collections.emptyMap());
    assertEquals(prefix + "Value1", MapUtils.getString(data, "key1"));
    assertEquals(prefix + "Value2", MapUtils.getString(data, "key2"));
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashiVaultTask(com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask) HashMap(java.util.HashMap) SimpleResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult)

Aggregations

Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)24 MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)16 HashMap (java.util.HashMap)7 Test (org.junit.Test)6 SimpleResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult)5 Path (java.nio.file.Path)4 Map (java.util.Map)4 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)3 UpdateLocalsCommand (com.walmartlabs.concord.runtime.v2.runner.vm.UpdateLocalsCommand)3 TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)2 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)2 com.walmartlabs.concord.runtime.v2.sdk (com.walmartlabs.concord.runtime.v2.sdk)2 ProcessConfiguration (com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 Injector (com.google.inject.Injector)1 ApiClient (com.walmartlabs.concord.ApiClient)1 DependencyManager (com.walmartlabs.concord.dependencymanager.DependencyManager)1