Search in sources :

Example 11 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp 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 12 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp 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 13 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp 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 14 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.

the class DefaultStoreTest method testScanApplicationsWithNamespace.

public void testScanApplicationsWithNamespace(Store store) {
    ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
    int count = 100;
    for (int i = 0; i < count / 2; i++) {
        String appName = "test" + (2 * i);
        store.addApplication(new ApplicationId(NamespaceId.DEFAULT.getNamespace(), appName), appSpec);
        appName = "test" + (2 * i + 1);
        store.addApplication(new ApplicationId(NamespaceId.CDAP.getNamespace(), appName), appSpec);
    }
    List<ApplicationId> apps = new ArrayList<ApplicationId>();
    ScanApplicationsRequest request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).build();
    store.scanApplications(request, 20, (appId, spec) -> {
        apps.add(appId);
    });
    Assert.assertEquals(count / 2, apps.size());
    // Reverse
    List<ApplicationId> reverseApps = new ArrayList<>();
    request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).setSortOrder(SortOrder.DESC).build();
    store.scanApplications(request, 20, (appId, spec) -> reverseApps.add(appId));
    Assert.assertEquals(Lists.reverse(apps), reverseApps);
    // Second page
    int firstPageSize = 10;
    List<ApplicationId> restartApps = new ArrayList<>();
    request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).setScanFrom(apps.get(firstPageSize - 1)).build();
    store.scanApplications(request, 20, (appId, spec) -> restartApps.add(appId));
    Assert.assertEquals(apps.subList(firstPageSize, apps.size()), restartApps);
}
Also used : ScanApplicationsRequest(io.cdap.cdap.app.store.ScanApplicationsRequest) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ArrayList(java.util.ArrayList) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Example 15 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp 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)

Aggregations

AllProgramsApp (io.cdap.cdap.AllProgramsApp)70 Test (org.junit.Test)66 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)54 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)48 ProgramId (io.cdap.cdap.proto.id.ProgramId)28 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)18 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)14 ArrayList (java.util.ArrayList)12 HashSet (java.util.HashSet)12 File (java.io.File)10 Set (java.util.Set)10 Assert (org.junit.Assert)10 JsonObject (com.google.gson.JsonObject)9 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)9 ProgramType (io.cdap.cdap.api.app.ProgramType)8 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)8 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)8 Specifications (io.cdap.cdap.internal.app.deploy.Specifications)8 AppDeploymentInfo (io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo)8 ProgramType (io.cdap.cdap.proto.ProgramType)8