Search in sources :

Example 16 with ApplicationSpecification

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));
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) AllProgramsApp(io.cdap.cdap.AllProgramsApp) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 17 with ApplicationSpecification

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)));
    }
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ArrayList(java.util.ArrayList) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 18 with ApplicationSpecification

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());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 19 with ApplicationSpecification

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());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 20 with ApplicationSpecification

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);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) ProgramType(io.cdap.cdap.proto.ProgramType) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException)

Aggregations

ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)228 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)114 ProgramId (io.cdap.cdap.proto.id.ProgramId)90 Test (org.junit.Test)90 AllProgramsApp (io.cdap.cdap.AllProgramsApp)54 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)52 ProgramType (io.cdap.cdap.proto.ProgramType)50 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)40 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)38 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)32 NotFoundException (io.cdap.cdap.common.NotFoundException)30 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)28 Map (java.util.Map)28 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)24 IOException (java.io.IOException)24 HashSet (java.util.HashSet)22 RunId (org.apache.twill.api.RunId)22 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)20 DefaultApplicationSpecification (io.cdap.cdap.internal.app.DefaultApplicationSpecification)20