Search in sources :

Example 1 with ApplicationRecord

use of co.cask.cdap.proto.ApplicationRecord 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"));
}
Also used : ApplicationClient(co.cask.cdap.client.ApplicationClient) File(java.io.File) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 2 with ApplicationRecord

use of co.cask.cdap.proto.ApplicationRecord 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());
}
Also used : ApplicationClient(co.cask.cdap.client.ApplicationClient) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 3 with ApplicationRecord

use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.

the class IntegrationTestBase method doClear.

private void doClear(NamespaceId namespace, boolean deleteNamespace) throws Exception {
    // stop all programs in the namespace
    getProgramClient().stopAll(namespace);
    if (deleteNamespace) {
        getNamespaceClient().delete(namespace);
        return;
    }
    // delete all apps in the namespace
    for (ApplicationRecord app : getApplicationClient().list(namespace)) {
        getApplicationClient().delete(namespace.app(app.getName(), app.getAppVersion()));
    }
    // delete all streams
    for (StreamDetail streamDetail : getStreamClient().list(namespace)) {
        getStreamClient().delete(namespace.stream(streamDetail.getName()));
    }
    // delete all dataset instances
    for (DatasetSpecificationSummary datasetSpecSummary : getDatasetClient().list(namespace)) {
        getDatasetClient().delete(namespace.dataset(datasetSpecSummary.getName()));
    }
    ArtifactClient artifactClient = new ArtifactClient(getClientConfig(), getRestClient());
    for (ArtifactSummary artifactSummary : artifactClient.list(namespace, ArtifactScope.USER)) {
        artifactClient.delete(namespace.artifact(artifactSummary.getName(), artifactSummary.getVersion()));
    }
    assertIsClear(namespace);
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) StreamDetail(co.cask.cdap.proto.StreamDetail) ArtifactClient(co.cask.cdap.client.ArtifactClient) DatasetSpecificationSummary(co.cask.cdap.proto.DatasetSpecificationSummary) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 4 with ApplicationRecord

use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.

the class ProgramClient method stopAll.

/**
 * Stops all currently running programs.
 */
public void stopAll(NamespaceId namespace) throws IOException, UnauthenticatedException, InterruptedException, TimeoutException, UnauthorizedException, ApplicationNotFoundException {
    List<ApplicationRecord> allApps = applicationClient.list(namespace);
    for (ApplicationRecord applicationRecord : allApps) {
        ApplicationId appId = new ApplicationId(namespace.getNamespace(), applicationRecord.getName(), applicationRecord.getAppVersion());
        List<ProgramRecord> programRecords = applicationClient.listPrograms(appId);
        for (ProgramRecord programRecord : programRecords) {
            try {
                ProgramId program = appId.program(programRecord.getType(), programRecord.getName());
                String status = this.getStatus(program);
                if (!status.equals("STOPPED")) {
                    try {
                        this.stop(program);
                    } catch (IOException ioe) {
                        // ProgramClient#stop calls RestClient, which throws an IOException if the HTTP response code is 400,
                        // which can be due to the program already being stopped when calling stop on it.
                        // Most likely, there was a race condition that the program stopped between the time we checked its
                        // status and calling the stop method.
                        LOG.warn("Program {} is already stopped, proceeding even though the following exception is raised.", program, ioe);
                    }
                    this.waitForStatus(program, ProgramStatus.STOPPED, 60, TimeUnit.SECONDS);
                }
            } catch (ProgramNotFoundException e) {
            // IGNORE
            }
        }
    }
}
Also used : ProgramRecord(co.cask.cdap.proto.ProgramRecord) IOException(java.io.IOException) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Example 5 with ApplicationRecord

use of co.cask.cdap.proto.ApplicationRecord in project cdap by caskdata.

the class ApplicationClientTestRun method testArtifactFilter.

@Test
public void testArtifactFilter() throws Exception {
    ApplicationId appId1 = NamespaceId.DEFAULT.app(FakeApp.NAME);
    ApplicationId appId2 = NamespaceId.DEFAULT.app("fake2");
    ApplicationId appId3 = NamespaceId.DEFAULT.app("fake3");
    try {
        // app1 should use fake-1.0.0-SNAPSHOT
        appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "otherfake", "1.0.0-SNAPSHOT"));
        appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "fake", "0.1.0-SNAPSHOT"));
        // app1 should end up with fake-1.0.0-SNAPSHOT
        appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, "fake", "1.0.0-SNAPSHOT"));
        // app2 should use fake-0.1.0-SNAPSHOT
        appClient.deploy(appId2, new AppRequest<Config>(new ArtifactSummary("fake", "0.1.0-SNAPSHOT")));
        // app3 should use otherfake-1.0.0-SNAPSHOT
        appClient.deploy(appId3, new AppRequest<Config>(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT")));
        appClient.waitForDeployed(appId1, 30, TimeUnit.SECONDS);
        appClient.waitForDeployed(appId2, 30, TimeUnit.SECONDS);
        appClient.waitForDeployed(appId3, 30, TimeUnit.SECONDS);
        // check calls that should return nothing
        // these don't match anything
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "ghost", null).isEmpty());
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, (String) null, "1.0.0").isEmpty());
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "ghost", "1.0.0").isEmpty());
        // these match one but not the other
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "otherfake", "0.1.0-SNAPSHOT").isEmpty());
        Assert.assertTrue(appClient.list(NamespaceId.DEFAULT, "fake", "1.0.0").isEmpty());
        // check filter by name only
        Set<ApplicationRecord> apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "fake", null));
        Set<ApplicationRecord> expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
        Assert.assertEquals(expected, apps);
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "otherfake", null));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""));
        Assert.assertEquals(expected, apps);
        // check filter by multiple names
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, ImmutableSet.of("fake", "otherfake"), null));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""), new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
        Assert.assertEquals(expected, apps);
        // check filter by version only
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, (String) null, "0.1.0-SNAPSHOT"));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
        Assert.assertEquals(expected, apps);
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, (String) null, "1.0.0-SNAPSHOT"));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "1.0.0-SNAPSHOT"), appId1, ""), new ApplicationRecord(new ArtifactSummary("otherfake", "1.0.0-SNAPSHOT"), appId3, ""));
        Assert.assertEquals(expected, apps);
        // check filter by both
        apps = Sets.newHashSet(appClient.list(NamespaceId.DEFAULT, "fake", "0.1.0-SNAPSHOT"));
        expected = ImmutableSet.of(new ApplicationRecord(new ArtifactSummary("fake", "0.1.0-SNAPSHOT"), appId2, ""));
        Assert.assertEquals(expected, apps);
    } finally {
        appClient.deleteAll(NamespaceId.DEFAULT);
        appClient.waitForDeleted(appId1, 30, TimeUnit.SECONDS);
        appClient.waitForDeleted(appId2, 30, TimeUnit.SECONDS);
        appClient.waitForDeleted(appId3, 30, TimeUnit.SECONDS);
        Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
    }
}
Also used : FakeApp(co.cask.cdap.client.app.FakeApp) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) Config(co.cask.cdap.api.Config) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord) Test(org.junit.Test)

Aggregations

ApplicationRecord (co.cask.cdap.proto.ApplicationRecord)9 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3 ApplicationClient (co.cask.cdap.client.ApplicationClient)2 Config (co.cask.cdap.api.Config)1 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)1 StreamSpecification (co.cask.cdap.api.data.stream.StreamSpecification)1 RowMaker (co.cask.cdap.cli.util.RowMaker)1 Table (co.cask.cdap.cli.util.table.Table)1 ArtifactClient (co.cask.cdap.client.ArtifactClient)1 FakeApp (co.cask.cdap.client.app.FakeApp)1 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)1 DatasetSpecificationSummary (co.cask.cdap.proto.DatasetSpecificationSummary)1 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)1 ProgramRecord (co.cask.cdap.proto.ProgramRecord)1 ProgramType (co.cask.cdap.proto.ProgramType)1 StreamDetail (co.cask.cdap.proto.StreamDetail)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 StreamId (co.cask.cdap.proto.id.StreamId)1