use of io.cdap.cdap.client.ApplicationClient in project cdap by caskdata.
the class IntegrationTestBase method assertNoApps.
private void assertNoApps(NamespaceId namespace) throws Exception {
ApplicationClient applicationClient = getApplicationClient();
List<ApplicationRecord> applicationRecords = applicationClient.list(namespace);
List<String> applicationIds = Lists.newArrayList();
for (ApplicationRecord applicationRecord : applicationRecords) {
applicationIds.add(applicationRecord.getName());
}
Assert.assertTrue("Must have no deployed apps, but found the following apps: " + Joiner.on(", ").join(applicationIds), applicationRecords.isEmpty());
}
use of io.cdap.cdap.client.ApplicationClient in project cdap by caskdata.
the class IntegrationTestBaseTest method testDeployApplicationInNamespace.
@Test
public void testDeployApplicationInNamespace() throws Exception {
NamespaceId namespace = new NamespaceId("Test1");
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespace).build();
getNamespaceClient().create(namespaceMeta);
ClientConfig clientConfig = new ClientConfig.Builder(getClientConfig()).build();
deployApplication(namespace, AllProgramsApp.class);
// Check the default namespaces applications to see whether the application wasn't made in the default namespace
ClientConfig defaultClientConfig = new ClientConfig.Builder(getClientConfig()).build();
Assert.assertTrue(new ApplicationClient(defaultClientConfig).list(NamespaceId.DEFAULT).isEmpty());
ApplicationClient applicationClient = new ApplicationClient(clientConfig);
Assert.assertEquals(AllProgramsApp.NAME, applicationClient.list(namespace).get(0).getName());
applicationClient.delete(namespace.app(AllProgramsApp.NAME));
Assert.assertTrue(new ApplicationClient(clientConfig).list(namespace).isEmpty());
}
use of io.cdap.cdap.client.ApplicationClient 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.ApplicationClient in project cdap by caskdata.
the class UpgradeJobMain method suspendSchedulesAndStopPipelines.
private static void suspendSchedulesAndStopPipelines(ClientConfig clientConfig) throws Exception {
ApplicationClient applicationClient = new ApplicationClient(clientConfig);
ScheduleClient scheduleClient = new ScheduleClient(clientConfig);
ProgramClient programClient = new ProgramClient(clientConfig);
NamespaceClient namespaceClient = new NamespaceClient(clientConfig);
boolean shouldRetry = false;
List<NamespaceId> namespaceIdList = namespaceClient.list().stream().map(NamespaceMeta::getNamespaceId).collect(Collectors.toList());
namespaceIdList.add(NamespaceId.SYSTEM);
for (NamespaceId namespaceId : namespaceIdList) {
for (ApplicationRecord record : applicationClient.list(namespaceId)) {
ApplicationId applicationId = new ApplicationId(namespaceId.getNamespace(), record.getName(), record.getAppVersion());
LOG.debug("Trying to stop schedule and workflows for application " + applicationId);
List<WorkflowId> workflowIds = applicationClient.get(applicationId).getPrograms().stream().filter(programRecord -> programRecord.getType().equals(ProgramType.WORKFLOW)).map(programRecord -> new WorkflowId(applicationId, programRecord.getName())).collect(Collectors.toList());
for (WorkflowId workflowId : workflowIds) {
List<ScheduleId> scheduleIds = scheduleClient.listSchedules(workflowId).stream().map(scheduleDetail -> new ScheduleId(namespaceId.getNamespace(), record.getName(), record.getAppVersion(), scheduleDetail.getName())).collect(Collectors.toList());
for (ScheduleId scheduleId : scheduleIds) {
if (scheduleClient.getStatus(scheduleId).equals(SCHEDULED)) {
scheduleClient.suspend(scheduleId);
}
}
// Need to stop workflows first or else the program will fail to stop below
if (!programClient.getStatus(workflowId).equals(ProgramStatus.STOPPED.toString())) {
try {
programClient.stop(workflowId);
} catch (BadRequestException e) {
// transitioned to stop state since it was checked earlier or not.
if (!programClient.getStatus(workflowId).equals(ProgramStatus.STOPPED.toString())) {
// Pipeline still in running state. Continue with stopping rest of the pipelines in this namespace and
// next retry should try to stop/verify status for this pipeline.
shouldRetry = true;
}
}
}
}
}
// At least one pipeline is still in running state so retry to verify pipeline status .
if (shouldRetry) {
throw new RetryableException("At least one pipeline in namespace " + namespaceId + " is still running.");
}
// All schedules are stopped, now stop all programs
programClient.stopAll(namespaceId);
}
}
use of io.cdap.cdap.client.ApplicationClient in project cdap by caskdata.
the class GenerateClientUsageExample method applicationClient.
public void applicationClient() throws Exception {
// Construct the client used to interact with CDAP
ApplicationClient appClient = new ApplicationClient(clientConfig);
// Fetch the list of applications
List<ApplicationRecord> apps = appClient.list(NamespaceId.DEFAULT);
// Deploy an application
File appJarFile = new File("your-app.jar");
appClient.deploy(NamespaceId.DEFAULT, appJarFile);
// Delete an application
appClient.delete(NamespaceId.DEFAULT.app("Purchase"));
// List programs belonging to an application
appClient.listPrograms(NamespaceId.DEFAULT.app("Purchase"));
}
Aggregations