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"));
}
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);
}
}
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);
}
}
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);
}
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());
}
Aggregations