use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStoreTest method testRemoveApplication.
@Test
public void testRemoveApplication() {
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
NamespaceId namespaceId = new NamespaceId("account1");
ApplicationId appId = namespaceId.app(spec.getName());
store.addApplication(appId, spec);
Assert.assertNotNull(store.getApplication(appId));
// removing application
store.removeApplication(appId);
Assert.assertNull(store.getApplication(appId));
}
use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class AppMetadataStoreTest method testBatchApplications.
@Test
public void testBatchApplications() {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
// Writes 20 application specs
for (int i = 0; i < 20; i++) {
String appName = "test" + i;
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.writeApplication(NamespaceId.DEFAULT.getNamespace(), appName, ApplicationId.DEFAULT_VERSION, appSpec);
store.writeApplication(NamespaceId.SYSTEM.getNamespace(), appName, ApplicationId.DEFAULT_VERSION, appSpec);
});
}
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
long count = store.getApplicationCount();
// System apps are not included in the count
Assert.assertEquals(20, count);
});
// Batch read 30, expect to get back 20
List<ApplicationId> appIds = new ArrayList<>();
for (int i = 0; i < 30; i++) {
appIds.add(NamespaceId.DEFAULT.app("test" + i));
}
Map<ApplicationId, ApplicationMeta> result = TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
return store.getApplicationsForAppIds(appIds);
});
Assert.assertEquals(20, result.size());
for (int i = 0; i < 20; i++) {
Assert.assertTrue("Missing application test" + i, result.containsKey(NamespaceId.DEFAULT.app("test" + i)));
}
}
use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class AppMetadataStoreTest method testScanApplicationsWithNamespace.
@Test
public void testScanApplicationsWithNamespace() {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
// Writes 100 application specs
int count = 100;
for (int i = 0; i < count / 2; i++) {
String defaultAppName = "test" + (2 * i);
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.writeApplication(NamespaceId.DEFAULT.getNamespace(), defaultAppName, ApplicationId.DEFAULT_VERSION, appSpec);
});
String cdapAppName = "test" + (2 * i + 1);
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.writeApplication(NamespaceId.CDAP.getNamespace(), cdapAppName, ApplicationId.DEFAULT_VERSION, appSpec);
});
}
// Scan all apps
Map<ApplicationId, ApplicationMeta> apps = new LinkedHashMap<>();
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.scanApplications(ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.DEFAULT).build(), entry -> {
apps.put(entry.getKey(), entry.getValue());
return true;
});
});
Assert.assertEquals(count / 2, apps.size());
}
use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class AppMetadataStoreTest method testScanApplications.
@Test
public void testScanApplications() {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
// Writes 100 application specs
int count = 100;
for (int i = 0; i < count; i++) {
String appName = "test" + i;
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.writeApplication(NamespaceId.DEFAULT.getNamespace(), appName, ApplicationId.DEFAULT_VERSION, appSpec);
});
}
// Scan all apps
Map<ApplicationId, ApplicationMeta> apps = new LinkedHashMap<>();
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.scanApplications(ScanApplicationsRequest.builder().build(), entry -> {
apps.put(entry.getKey(), entry.getValue());
return true;
});
});
Assert.assertEquals(count, apps.size());
}
use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ProgramExistenceVerifier method ensureExists.
@Override
public void ensureExists(ProgramId programId) throws ApplicationNotFoundException, ProgramNotFoundException {
ApplicationId appId = programId.getParent();
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
ProgramType programType = programId.getType();
Set<String> programNames = null;
if (programType == ProgramType.MAPREDUCE && appSpec.getMapReduce() != null) {
programNames = appSpec.getMapReduce().keySet();
} else if (programType == ProgramType.WORKFLOW && appSpec.getWorkflows() != null) {
programNames = appSpec.getWorkflows().keySet();
} else if (programType == ProgramType.SERVICE && appSpec.getServices() != null) {
programNames = appSpec.getServices().keySet();
} else if (programType == ProgramType.SPARK && appSpec.getSpark() != null) {
programNames = appSpec.getSpark().keySet();
} else if (programType == ProgramType.WORKER && appSpec.getWorkers() != null) {
programNames = appSpec.getWorkers().keySet();
}
if (programNames != null) {
if (programNames.contains(programId.getProgram())) {
// is valid.
return;
}
}
throw new ProgramNotFoundException(programId);
}
Aggregations