Search in sources :

Example 1 with ApplicationDetail

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

the class UpgradeTool method upgrade.

private boolean upgrade(final ApplicationId appId) throws Exception {
    ApplicationDetail appDetail = appClient.get(appId);
    if (!upgrader.shouldUpgrade(appDetail.getArtifact())) {
        LOG.debug("Skipping app {} since it is not an upgradeable pipeline.", appId);
        return false;
    }
    LOG.info("Upgrading pipeline: {}", appId);
    return upgrader.upgrade(appDetail.getArtifact(), appDetail.getConfiguration(), new Upgrader.UpgradeAction() {

        @Override
        public boolean upgrade(AppRequest<? extends ETLConfig> appRequest) {
            try {
                appClient.update(appId, appRequest);
                return true;
            } catch (Exception e) {
                LOG.error("Error upgrading pipeline {}.", appId, e);
                if (errorDir != null) {
                    File errorFile = new File(errorDir, String.format("%s-%s.json", appId.getParent(), appId.getEntityName()));
                    LOG.error("Writing config for pipeline {} to {} for further manual investigation.", appId, errorFile.getAbsolutePath());
                    try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(errorFile))) {
                        outputStreamWriter.write(GSON.toJson(appRequest));
                    } catch (IOException e1) {
                        LOG.error("Error writing config out for manual investigation.", e1);
                    }
                }
                return false;
            }
        }
    });
}
Also used : ApplicationDetail(co.cask.cdap.proto.ApplicationDetail) Upgrader(co.cask.cdap.etl.tool.config.Upgrader) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 2 with ApplicationDetail

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

the class ApplicationClientTestRun method testAll.

@Test
public void testAll() throws Exception {
    ApplicationId app = NamespaceId.DEFAULT.app(FakeApp.NAME);
    Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
    // deploy app
    LOG.info("Deploying app");
    appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class, FakeApp.NAME, "1.0.0-SNAPSHOT"));
    appClient.waitForDeployed(app, 30, TimeUnit.SECONDS);
    Assert.assertEquals(1, appClient.list(NamespaceId.DEFAULT).size());
    try {
        // check program list
        LOG.info("Checking program list for app");
        Map<ProgramType, List<ProgramRecord>> programs = appClient.listProgramsByType(app);
        verifyProgramNames(FakeApp.FLOWS, programs.get(ProgramType.FLOW));
        verifyProgramNames(FakeApp.MAPREDUCES, programs.get(ProgramType.MAPREDUCE));
        verifyProgramNames(FakeApp.WORKFLOWS, programs.get(ProgramType.WORKFLOW));
        verifyProgramNames(FakeApp.SERVICES, programs.get(ProgramType.SERVICE));
        verifyProgramNames(FakeApp.FLOWS, appClient.listPrograms(app, ProgramType.FLOW));
        verifyProgramNames(FakeApp.MAPREDUCES, appClient.listPrograms(app, ProgramType.MAPREDUCE));
        verifyProgramNames(FakeApp.WORKFLOWS, appClient.listPrograms(app, ProgramType.WORKFLOW));
        verifyProgramNames(FakeApp.SERVICES, appClient.listPrograms(app, ProgramType.SERVICE));
        verifyProgramNames(FakeApp.FLOWS, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.FLOW));
        verifyProgramNames(FakeApp.MAPREDUCES, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.MAPREDUCE));
        verifyProgramNames(FakeApp.WORKFLOWS, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.WORKFLOW));
        verifyProgramNames(FakeApp.SERVICES, appClient.listAllPrograms(NamespaceId.DEFAULT, ProgramType.SERVICE));
        verifyProgramRecords(FakeApp.ALL_PROGRAMS, appClient.listAllPrograms(NamespaceId.DEFAULT));
        ApplicationDetail appDetail = appClient.get(app);
        ArtifactSummary expected = new ArtifactSummary(FakeApp.NAME, "1.0.0-SNAPSHOT");
        Assert.assertEquals(expected, appDetail.getArtifact());
    } finally {
        // delete app
        LOG.info("Deleting app");
        appClient.delete(app);
        appClient.waitForDeleted(app, 30, TimeUnit.SECONDS);
        Assert.assertEquals(0, appClient.list(NamespaceId.DEFAULT).size());
    }
}
Also used : FakeApp(co.cask.cdap.client.app.FakeApp) ApplicationDetail(co.cask.cdap.proto.ApplicationDetail) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) List(java.util.List) ProgramType(co.cask.cdap.proto.ProgramType) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 3 with ApplicationDetail

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

the class ProgramLifecycleHttpHandlerTest method verifyProgramList.

private void verifyProgramList(String namespace, String appName, final ProgramType programType, int expected) throws Exception {
    HttpResponse response = requestAppDetail(namespace, appName);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    String json = EntityUtils.toString(response.getEntity());
    ApplicationDetail appDetail = GSON.fromJson(json, ApplicationDetail.class);
    Collection<ProgramRecord> programs = Collections2.filter(appDetail.getPrograms(), new Predicate<ProgramRecord>() {

        @Override
        public boolean apply(@Nullable ProgramRecord record) {
            return programType.getCategoryName().equals(record.getType().getCategoryName());
        }
    });
    Assert.assertEquals(expected, programs.size());
}
Also used : ApplicationDetail(co.cask.cdap.proto.ApplicationDetail) ProgramRecord(co.cask.cdap.proto.ProgramRecord) HttpResponse(org.apache.http.HttpResponse)

Example 4 with ApplicationDetail

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

the class ApplicationClient method get.

/**
   * Get details about the specified application.
   *
   * @param appId the id of the application to get
   * @return details about the specified application
   * @throws ApplicationNotFoundException if the application with the given ID was not found
   * @throws IOException if a network error occurred
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public ApplicationDetail get(ApplicationId appId) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
    String path = String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion());
    HttpResponse response = restClient.execute(HttpMethod.GET, config.resolveNamespacedURLV3(appId.getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ApplicationNotFoundException(appId);
    }
    return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject();
}
Also used : ApplicationDetail(co.cask.cdap.proto.ApplicationDetail) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) HttpResponse(co.cask.common.http.HttpResponse)

Aggregations

ApplicationDetail (co.cask.cdap.proto.ApplicationDetail)4 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1 FakeApp (co.cask.cdap.client.app.FakeApp)1 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)1 Upgrader (co.cask.cdap.etl.tool.config.Upgrader)1 ProgramRecord (co.cask.cdap.proto.ProgramRecord)1 ProgramType (co.cask.cdap.proto.ProgramType)1 ApplicationId (co.cask.cdap.proto.id.ApplicationId)1 HttpResponse (co.cask.common.http.HttpResponse)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 List (java.util.List)1 HttpResponse (org.apache.http.HttpResponse)1 Test (org.junit.Test)1