Search in sources :

Example 16 with MapBackedVariables

use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord by walmartlabs.

the class ConcordTaskParams method of.

public static ConcordTaskParams of(Variables input, Map<String, Object> defaults) {
    Map<String, Object> variablesMap = new HashMap<>(defaults != null ? defaults : Collections.emptyMap());
    variablesMap.putAll(input.toMap());
    Variables variables = new MapBackedVariables(variablesMap);
    ConcordTaskParams p = new ConcordTaskParams(variables);
    switch(p.action()) {
        case START:
            {
                return new StartParams(variables);
            }
        case STARTEXTERNAL:
            {
                return new StartExternalParams(variables);
            }
        case FORK:
            {
                return new ForkParams(variables);
            }
        case KILL:
            {
                return new KillParams(variables);
            }
        default:
            {
                throw new IllegalArgumentException("Unsupported action type: " + p.action());
            }
    }
}
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)

Example 17 with MapBackedVariables

use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord by walmartlabs.

the class ConcordTaskParamsTest method testForks.

@Test
public void testForks() {
    List<String> tags = Arrays.asList("x", "y", "z");
    Map<String, Object> input = new HashMap<>();
    input.put("action", "fork");
    input.put("tags", tags);
    input.put("forks", Arrays.asList(Collections.singletonMap("entryPoint", "aaa"), Collections.singletonMap("entryPoint", "bbb")));
    ForkParams params = (ForkParams) ConcordTaskParams.of(new MapBackedVariables(input), Collections.emptyMap());
    List<ForkStartParams> forks = params.forks();
    assertEquals(2, forks.size());
    ForkStartParams f1 = forks.get(0);
    assertEquals("aaa", f1.entryPoint());
    assertTrue(f1.tags().containsAll(tags));
    ForkStartParams f2 = forks.get(1);
    assertEquals("bbb", f2.entryPoint());
    assertTrue(f2.tags().containsAll(tags));
    System.out.println(params);
}
Also used : ForkStartParams(com.walmartlabs.concord.client.ConcordTaskParams.ForkStartParams) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) ForkParams(com.walmartlabs.concord.client.ConcordTaskParams.ForkParams) Test(org.junit.jupiter.api.Test)

Example 18 with MapBackedVariables

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

the class HashiVaultTaskV2Test method testReadTokenFromSecretV2.

@Test
public void testReadTokenFromSecretV2() throws Exception {
    Map<String, Object> varMap = new HashMap<>();
    Map<String, Object> secretInfo = new HashMap<>(3);
    secretInfo.put("org", "my-org");
    secretInfo.put("name", "my-secret");
    varMap.put("apiTokenSecret", secretInfo);
    varMap.put("baseUrl", getBaseUrl());
    varMap.put("path", "cubbyhole/hello");
    Variables vars = new MapBackedVariables(varMap);
    SimpleResult result = getTask(false).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 19 with MapBackedVariables

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

the class HashiVaultTaskV2Test method testReadKvSingleV2.

@Test
public void testReadKvSingleV2() throws Exception {
    Map<String, Object> varMap = new HashMap<>();
    varMap.put("path", "secret/testing");
    varMap.put("key", "db_password");
    Variables vars = new MapBackedVariables(varMap);
    SimpleResult result = getTask(true).execute(vars);
    Assert.assertTrue(result.ok());
    final String data = MapUtils.getString(result.values(), "data");
    assertEquals("dbpassword1", data);
}
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 20 with MapBackedVariables

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

the class UnitTest method stringDataTest.

@Test
public void stringDataTest() {
    Variables vars = new MapBackedVariables(getMap("path", "secret/mysecret", "key", "top_secret"));
    TaskParams params = TaskParams.of(vars, null, exporter);
    HashiVaultTaskResult result = HashiVaultTaskResult.of(true, getMap("top_secret", "value"), null, params);
    try {
        Map<String, Object> m = result.data();
        fail("data should be String when key param is given");
    } catch (ClassCastException e) {
    // that's expected
    }
    // this should work
    String s = result.data();
    assertEquals("value", s);
}
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) Test(org.junit.Test)

Aggregations

MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)21 HashMap (java.util.HashMap)14 Test (org.junit.Test)10 Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)9 Test (org.junit.jupiter.api.Test)6 SimpleResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult)5 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)3 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)3 MimeMessage (javax.mail.internet.MimeMessage)3 ForkParams (com.walmartlabs.concord.client.ConcordTaskParams.ForkParams)1 ForkStartParams (com.walmartlabs.concord.client.ConcordTaskParams.ForkStartParams)1 HashiVaultTask (com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask)1 TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)1 TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)1 TaskContext (com.walmartlabs.concord.runtime.v2.runner.context.TaskContext)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)1 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)1 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)1 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)1