Search in sources :

Example 1 with ProgramClient

use of io.cdap.cdap.client.ProgramClient in project cdap by caskdata.

the class CLITestBase method testWorkflows.

@Test
public void testWorkflows() throws Exception {
    ProgramClient programClient = getProgramClient();
    String workflow = String.format("%s.%s", FakeApp.NAME, FakeWorkflow.NAME);
    File doneFile = TMP_FOLDER.newFile("fake.done");
    Map<String, String> runtimeArgs = ImmutableMap.of("done.file", doneFile.getAbsolutePath());
    String runtimeArgsKV = SPACE_EQUALS_JOINER.join(runtimeArgs);
    testCommandOutputContains("start workflow " + workflow + " '" + runtimeArgsKV + "'", "Successfully started workflow");
    Tasks.waitFor(1, new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            return programClient.getProgramRuns(FAKE_WORKFLOW_ID, ProgramRunStatus.COMPLETED.name(), 0, Long.MAX_VALUE, Integer.MAX_VALUE).size();
        }
    }, 180, TimeUnit.SECONDS);
    testCommandOutputContains("cli render as csv", "Now rendering as CSV");
    String commandOutput = getCommandOutput("get workflow runs " + workflow);
    String[] lines = commandOutput.split("\\r?\\n");
    Assert.assertEquals(2, lines.length);
    String[] split = lines[1].split(",");
    String runId = split[0];
    // Test entire workflow token
    List<WorkflowTokenDetail.NodeValueDetail> tokenValues = new ArrayList<>();
    tokenValues.add(new WorkflowTokenDetail.NodeValueDetail(FakeWorkflow.FakeAction.class.getSimpleName(), FakeWorkflow.FakeAction.TOKEN_VALUE));
    tokenValues.add(new WorkflowTokenDetail.NodeValueDetail(FakeWorkflow.FakeAction.ANOTHER_FAKE_NAME, FakeWorkflow.FakeAction.TOKEN_VALUE));
    testCommandOutputContains(String.format("get workflow token %s %s", workflow, runId), Joiner.on(",").join(FakeWorkflow.FakeAction.TOKEN_KEY, GSON.toJson(tokenValues)));
    testCommandOutputNotContains(String.format("get workflow token %s %s scope system", workflow, runId), Joiner.on(",").join(FakeWorkflow.FakeAction.TOKEN_KEY, GSON.toJson(tokenValues)));
    testCommandOutputContains(String.format("get workflow token %s %s scope user key %s", workflow, runId, FakeWorkflow.FakeAction.TOKEN_KEY), Joiner.on(",").join(FakeWorkflow.FakeAction.TOKEN_KEY, GSON.toJson(tokenValues)));
    // Test with node name
    String fakeNodeValue = Joiner.on(",").join(FakeWorkflow.FakeAction.TOKEN_KEY, FakeWorkflow.FakeAction.TOKEN_VALUE);
    testCommandOutputContains(String.format("get workflow token %s %s at node %s", workflow, runId, FakeWorkflow.FakeAction.class.getSimpleName()), fakeNodeValue);
    testCommandOutputNotContains(String.format("get workflow token %s %s at node %s scope system", workflow, runId, FakeWorkflow.FakeAction.ANOTHER_FAKE_NAME), fakeNodeValue);
    testCommandOutputContains(String.format("get workflow token %s %s at node %s scope user key %s", workflow, runId, FakeWorkflow.FakeAction.ANOTHER_FAKE_NAME, FakeWorkflow.FakeAction.TOKEN_KEY), fakeNodeValue);
    testCommandOutputContains("get workflow logs " + workflow, FakeWorkflow.FAKE_LOG);
    // Test schedule
    testCommandOutputContains(String.format("add time schedule %s for workflow %s at \"0 4 * * *\"", FakeWorkflow.SCHEDULE, workflow), String.format("Successfully added schedule '%s' in app '%s'", FakeWorkflow.SCHEDULE, FakeApp.NAME));
    testCommandOutputContains(String.format("get workflow schedules %s", workflow), "0 4 * * *");
    testCommandOutputContains(String.format("update time schedule %s for workflow %s description \"testdesc\" at \"* * * * *\" " + "concurrency 4 properties \"key=value\"", FakeWorkflow.SCHEDULE, workflow), String.format("Successfully updated schedule '%s' in app '%s'", FakeWorkflow.SCHEDULE, FakeApp.NAME));
    testCommandOutputContains(String.format("get workflow schedules %s", workflow), "* * * * *");
    testCommandOutputContains(String.format("get workflow schedules %s", workflow), "testdesc");
    testCommandOutputContains(String.format("get workflow schedules %s", workflow), "{\"key\":\"value\"}");
    testCommandOutputContains(String.format("delete schedule %s.%s", FakeApp.NAME, FakeWorkflow.SCHEDULE), String.format("Successfully deleted schedule '%s' in app '%s'", FakeWorkflow.SCHEDULE, FakeApp.NAME));
    testCommandOutputNotContains(String.format("get workflow schedules %s", workflow), "* * * * *");
    testCommandOutputNotContains(String.format("get workflow schedules %s", workflow), "testdesc");
    testCommandOutputNotContains(String.format("get workflow schedules %s", workflow), "{\"key\":\"value\"}");
    // stop workflow
    testCommandOutputContains("stop workflow " + workflow, String.format("400: Program '%s' is not running", FAKE_WORKFLOW_ID));
}
Also used : ProgramClient(io.cdap.cdap.client.ProgramClient) ArrayList(java.util.ArrayList) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) IOException(java.io.IOException) FakeWorkflow(io.cdap.cdap.client.app.FakeWorkflow) File(java.io.File) WorkflowTokenDetail(io.cdap.cdap.proto.WorkflowTokenDetail) Test(org.junit.Test)

Example 2 with ProgramClient

use of io.cdap.cdap.client.ProgramClient in project cdap by caskdata.

the class CLITestBase method testProgram.

@Test
public void testProgram() throws Exception {
    ProgramClient programClient = getProgramClient();
    final ProgramId serviceId = FAKE_APP_ID.service(FakeApp.SERVICES.get(0));
    String qualifiedServiceId = FakeApp.NAME + "." + serviceId.getProgram();
    testCommandOutputContains("start service " + qualifiedServiceId, "Successfully started service");
    assertProgramStatus(programClient, serviceId, "RUNNING");
    testCommandOutputContains("stop service " + qualifiedServiceId, "Successfully stopped service");
    assertProgramStatus(programClient, serviceId, "STOPPED");
    testCommandOutputContains("get service status " + qualifiedServiceId, "STOPPED");
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            List<RunRecord> output = programClient.getProgramRuns(serviceId, "KILLED", 0L, Long.MAX_VALUE, Integer.MAX_VALUE);
            return output != null && output.size() != 0;
        }
    }, 5, TimeUnit.SECONDS);
    testCommandOutputContains("get service runs " + qualifiedServiceId, "KILLED");
    testCommandOutputContains("get service live " + qualifiedServiceId, serviceId.getProgram());
}
Also used : ProgramClient(io.cdap.cdap.client.ProgramClient) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ProgramId(io.cdap.cdap.proto.id.ProgramId) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with ProgramClient

use of io.cdap.cdap.client.ProgramClient in project cdap by caskdata.

the class CLITestBase method testService.

@Test
public void testService() throws Exception {
    ProgramClient programClient = getProgramClient();
    ServiceId service = FAKE_APP_ID.service(PrefixedEchoHandler.NAME);
    ServiceId serviceV1 = FAKE_APP_ID_V_1.service(PrefixedEchoHandler.NAME);
    String serviceName = String.format("%s.%s", FakeApp.NAME, PrefixedEchoHandler.NAME);
    String serviceArgument = String.format("%s version %s", serviceName, ApplicationId.DEFAULT_VERSION);
    String serviceV1Argument = String.format("%s version %s", serviceName, V1_SNAPSHOT);
    try {
        // Test service commands with no optional version argument
        testCommandOutputContains("start service " + serviceName, "Successfully started service");
        assertProgramStatus(programClient, service, ProgramStatus.RUNNING.name());
        testCommandOutputContains("get endpoints service " + serviceName, "POST");
        testCommandOutputContains("get endpoints service " + serviceName, "/echo");
        testCommandOutputContains("check service availability " + serviceName, "Service is available");
        testCommandOutputContains("call service " + serviceName + " POST /echo body \"testBody\"", ":testBody");
        testCommandOutputContains("stop service " + serviceName, "Successfully stopped service");
        assertProgramStatus(programClient, service, ProgramStatus.STOPPED.name());
        // Test service commands with version argument when two versions of the service are running
        testCommandOutputContains("start service " + serviceArgument, "Successfully started service");
        testCommandOutputContains("start service " + serviceV1Argument, "Successfully started service");
        assertProgramStatus(programClient, service, ProgramStatus.RUNNING.name());
        assertProgramStatus(programClient, serviceV1, ProgramStatus.RUNNING.name());
        testCommandOutputContains("get endpoints service " + serviceArgument, "POST");
        testCommandOutputContains("get endpoints service " + serviceV1Argument, "POST");
        testCommandOutputContains("get endpoints service " + serviceArgument, "/echo");
        testCommandOutputContains("get endpoints service " + serviceV1Argument, "/echo");
        testCommandOutputContains("check service availability " + serviceArgument, "Service is available");
        testCommandOutputContains("check service availability " + serviceV1Argument, "Service is available");
        testCommandOutputContains("call service " + serviceArgument + " POST /echo body \"testBody\"", ":testBody");
        testCommandOutputContains("call service " + serviceV1Argument + " POST /echo body \"testBody\"", ":testBody");
        testCommandOutputContains("get service logs " + serviceName, "Starting HTTP server for Service " + service);
    } finally {
        // Stop all running services
        programClient.stopAll(NamespaceId.DEFAULT);
    }
}
Also used : ProgramClient(io.cdap.cdap.client.ProgramClient) ServiceId(io.cdap.cdap.proto.id.ServiceId) Test(org.junit.Test)

Example 4 with ProgramClient

use of io.cdap.cdap.client.ProgramClient in project cdap by caskdata.

the class CLIMainLinkTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    cliConfig = createCLIConfigWithURIPrefix(STANDALONE.getBaseURI());
    LaunchOptions launchOptions = new LaunchOptions("", true, true, false, null, LaunchOptions.DEFAULT.getUri());
    cliMain = new CLIMain(launchOptions, cliConfig);
    programClient = new ProgramClient(cliConfig.getClientConfig());
    queryClient = new QueryClient(cliConfig.getClientConfig());
    cli = cliMain.getCLI();
    testSetup(cli, STANDALONE, TMP_FOLDER);
}
Also used : ProgramClient(io.cdap.cdap.client.ProgramClient) QueryClient(io.cdap.cdap.client.QueryClient) BeforeClass(org.junit.BeforeClass)

Example 5 with ProgramClient

use of io.cdap.cdap.client.ProgramClient in project cdap by caskdata.

the class CLIMainTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    cliConfig = createCLIConfig(STANDALONE.getBaseURI());
    LaunchOptions launchOptions = new LaunchOptions(LaunchOptions.DEFAULT.getUri(), true, true, false);
    cliMain = new CLIMain(launchOptions, cliConfig);
    programClient = new ProgramClient(cliConfig.getClientConfig());
    queryClient = new QueryClient(cliConfig.getClientConfig());
    cli = cliMain.getCLI();
    testSetup(cli, STANDALONE, TMP_FOLDER);
}
Also used : ProgramClient(io.cdap.cdap.client.ProgramClient) QueryClient(io.cdap.cdap.client.QueryClient) BeforeClass(org.junit.BeforeClass)

Aggregations

ProgramClient (io.cdap.cdap.client.ProgramClient)10 Test (org.junit.Test)4 IOException (java.io.IOException)3 ApplicationClient (io.cdap.cdap.client.ApplicationClient)2 NamespaceClient (io.cdap.cdap.client.NamespaceClient)2 QueryClient (io.cdap.cdap.client.QueryClient)2 ScheduleClient (io.cdap.cdap.client.ScheduleClient)2 DatasetTypeNotFoundException (io.cdap.cdap.common.DatasetTypeNotFoundException)2 ApplicationRecord (io.cdap.cdap.proto.ApplicationRecord)2 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)2 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)2 ProgramId (io.cdap.cdap.proto.id.ProgramId)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BeforeClass (org.junit.BeforeClass)2 ImmutableList (com.google.common.collect.ImmutableList)1 RetryableException (io.cdap.cdap.api.retry.RetryableException)1 FakeWorkflow (io.cdap.cdap.client.app.FakeWorkflow)1 ClientConfig (io.cdap.cdap.client.config.ClientConfig)1 ConnectionConfig (io.cdap.cdap.client.config.ConnectionConfig)1