Search in sources :

Example 6 with ProgramClient

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

the class GenerateClientUsageExample method programClient.

public void programClient() throws Exception {
    // Construct the client used to interact with CDAP
    ProgramClient programClient = new ProgramClient(clientConfig);
    // Start a service in the WordCount example
    programClient.start(NamespaceId.DEFAULT.app("WordCount").service("RetrieveCounts"));
    // Fetch live information from the HelloWorld example
    // Live info includes the address of an component’s container host and the container’s debug port,
    // formatted in JSON
    programClient.getLiveInfo(NamespaceId.DEFAULT.app("HelloWorld").service("greet"));
    // Fetch program logs in the WordCount example
    programClient.getProgramLogs(NamespaceId.DEFAULT.app("WordCount").service("RetrieveCounts"), 0, Long.MAX_VALUE);
    // Scale a service in the HelloWorld example
    programClient.setServiceInstances(NamespaceId.DEFAULT.app("HelloWorld").service("greet"), 3);
    // Stop a service in the HelloWorld example
    programClient.stop(NamespaceId.DEFAULT.app("HelloWorld").service("greet"));
}
Also used : ProgramClient(io.cdap.cdap.client.ProgramClient)

Example 7 with ProgramClient

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

the class PostUpgradeJobMain method restartPipelinesAndSchedules.

private static void restartPipelinesAndSchedules(ClientConfig clientConfig, long startTimeMillis, boolean restartSystemApps) throws Exception {
    long endTimeMillis = System.currentTimeMillis();
    ApplicationClient applicationClient = new ApplicationClient(clientConfig);
    ScheduleClient scheduleClient = new ScheduleClient(clientConfig);
    ProgramClient programClient = new ProgramClient(clientConfig);
    NamespaceClient namespaceClient = new NamespaceClient(clientConfig);
    List<NamespaceId> namespaceIdList = namespaceClient.list().stream().map(NamespaceMeta::getNamespaceId).collect(Collectors.toList());
    if (restartSystemApps) {
        namespaceIdList.add(NamespaceId.SYSTEM);
    }
    for (NamespaceId namespaceId : namespaceIdList) {
        for (ApplicationRecord record : applicationClient.list(namespaceId)) {
            ApplicationId applicationId = new ApplicationId(namespaceId.getNamespace(), record.getName(), record.getAppVersion());
            programClient.restart(applicationId, TimeUnit.MILLISECONDS.toSeconds(startTimeMillis), TimeUnit.MILLISECONDS.toSeconds(endTimeMillis));
        }
        // Re-enable schedules in a namespace AFTER programs have been restarted.
        scheduleClient.reEnableSuspendedSchedules(namespaceId, startTimeMillis, endTimeMillis);
    }
}
Also used : ApplicationClient(io.cdap.cdap.client.ApplicationClient) ProgramClient(io.cdap.cdap.client.ProgramClient) NamespaceClient(io.cdap.cdap.client.NamespaceClient) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ScheduleClient(io.cdap.cdap.client.ScheduleClient) ApplicationRecord(io.cdap.cdap.proto.ApplicationRecord)

Example 8 with ProgramClient

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

the class PostUpgradeJobMain method restartPipelinesAndSchedules.

private static void restartPipelinesAndSchedules(ClientConfig clientConfig, long startTimeMillis, boolean restartSystemApps) throws Exception {
    long endTimeMillis = System.currentTimeMillis();
    ApplicationClient applicationClient = new ApplicationClient(clientConfig);
    ScheduleClient scheduleClient = new ScheduleClient(clientConfig);
    ProgramClient programClient = new ProgramClient(clientConfig);
    NamespaceClient namespaceClient = new NamespaceClient(clientConfig);
    List<NamespaceId> namespaceIdList = namespaceClient.list().stream().map(NamespaceMeta::getNamespaceId).collect(Collectors.toList());
    if (restartSystemApps) {
        namespaceIdList.add(NamespaceId.SYSTEM);
    }
    for (NamespaceId namespaceId : namespaceIdList) {
        for (ApplicationRecord record : applicationClient.list(namespaceId)) {
            ApplicationId applicationId = new ApplicationId(namespaceId.getNamespace(), record.getName(), record.getAppVersion());
            programClient.restart(applicationId, TimeUnit.MILLISECONDS.toSeconds(startTimeMillis), TimeUnit.MILLISECONDS.toSeconds(endTimeMillis));
        }
        // Re-enable schedules in a namespace AFTER programs have been restarted.
        scheduleClient.reEnableSuspendedSchedules(namespaceId, startTimeMillis, endTimeMillis);
    }
}
Also used : ApplicationClient(io.cdap.cdap.client.ApplicationClient) ProgramClient(io.cdap.cdap.client.ProgramClient) NamespaceClient(io.cdap.cdap.client.NamespaceClient) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ScheduleClient(io.cdap.cdap.client.ScheduleClient) ApplicationRecord(io.cdap.cdap.proto.ApplicationRecord)

Example 9 with ProgramClient

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

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 10 with ProgramClient

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

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)

Aggregations

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