Search in sources :

Example 91 with ApplicationId

use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class AppLifecycleHttpHandler method getApplicationDetails.

/**
 * Gets {@link ApplicationDetail} for a set of applications. It expects a post body as a array of object, with each
 * object specifying the applciation id and an optional version. E.g.
 *
 * <pre>
 * {@code
 * [
 *   {"appId":"XYZ", "version":"1.2.3"},
 *   {"appId":"ABC"},
 *   {"appId":"FOO", "version":"2.3.4"},
 * ]
 * }
 * </pre>
 * The response will be an array of {@link BatchApplicationDetail} object, which either indicates a success (200) or
 * failure for each of the requested application in the same order as the request.
 */
@POST
@Path("/appdetail")
public void getApplicationDetails(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception {
    List<ApplicationId> appIds = decodeAndValidateBatchApplication(validateNamespace(namespace), request);
    Map<ApplicationId, ApplicationDetail> details = applicationLifecycleService.getAppDetails(appIds);
    List<BatchApplicationDetail> result = new ArrayList<>();
    for (ApplicationId appId : appIds) {
        ApplicationDetail detail = details.get(appId);
        if (detail == null) {
            result.add(new BatchApplicationDetail(new NotFoundException(appId)));
        } else {
            result.add(new BatchApplicationDetail(detail));
        }
    }
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result));
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) BatchApplicationDetail(io.cdap.cdap.proto.BatchApplicationDetail) ArrayList(java.util.ArrayList) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) BatchApplicationDetail(io.cdap.cdap.proto.BatchApplicationDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 92 with ApplicationId

use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class AppLifecycleHttpHandler method deleteApp.

/**
 * Delete an application specified by appId.
 */
@DELETE
@Path("/apps/{app-id}")
public void deleteApp(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") final String appId) throws Exception {
    ApplicationId id = validateApplicationId(namespaceId, appId);
    applicationLifecycleService.removeApplication(id);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 93 with ApplicationId

use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class PreferencesTable method ensureSequence.

/**
 * Verify that the preferences for the entity id were written with a greater or equal sequence id.
 *
 * @param entityId the entity id to verify
 * @param afterId  the sequence id to check
 * @throws ConflictException if the latest version of the preferences is older than the given sequence id
 */
public void ensureSequence(EntityId entityId, long afterId) throws IOException, ConflictException {
    switch(entityId.getEntityType()) {
        case INSTANCE:
            checkSeqId(EMPTY_NAMESPACE, INSTANCE_PREFERENCE, entityId.getEntityName(), afterId);
            return;
        case NAMESPACE:
            NamespaceId namespaceId = (NamespaceId) entityId;
            checkSeqId(namespaceId.getNamespace(), NAMESPACE_PREFERENCE, namespaceId.getNamespace(), afterId);
            return;
        case APPLICATION:
            ApplicationId appId = (ApplicationId) entityId;
            checkSeqId(appId.getNamespace(), APPLICATION_PREFERENCE, appId.getApplication(), afterId);
            return;
        case PROGRAM:
            ProgramId programId = (ProgramId) entityId;
            checkSeqId(programId.getNamespace(), PROGRAM_PREFERENCE, getProgramName(programId), afterId);
            return;
        default:
            throw new UnsupportedOperationException(String.format("Preferences cannot be used on this entity type: %s", entityId.getEntityType()));
    }
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 94 with ApplicationId

use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class AppCreator method execute.

@Override
public void execute(Arguments arguments) throws Exception {
    ApplicationId appId = arguments.getId();
    ArtifactSummary artifactSummary = arguments.getArtifact();
    if (appExists(appId) && !arguments.overwrite) {
        return;
    }
    KerberosPrincipalId ownerPrincipalId = arguments.getOwnerPrincipal() == null ? null : new KerberosPrincipalId(arguments.getOwnerPrincipal());
    // if we don't null check, it gets serialized to "null"
    String configString = arguments.getConfig() == null ? null : GSON.toJson(arguments.getConfig());
    try {
        appLifecycleService.deployApp(appId.getParent(), appId.getApplication(), appId.getVersion(), artifactSummary, configString, x -> {
        }, ownerPrincipalId, arguments.canUpdateSchedules(), false, Collections.emptyMap());
    } catch (NotFoundException | UnauthorizedException | InvalidArtifactException e) {
        // up to the default time limit
        throw e;
    } catch (DatasetManagementException e) {
        if (e.getCause() instanceof UnauthorizedException) {
            throw (UnauthorizedException) e.getCause();
        } else {
            throw new RetryableException(e);
        }
    } catch (Exception e) {
        throw new RetryableException(e);
    }
}
Also used : DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) RetryableException(io.cdap.cdap.api.retry.RetryableException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) RetryableException(io.cdap.cdap.api.retry.RetryableException) DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 95 with ApplicationId

use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class CapabilityManagementServiceTest method testCapabilityRefresh.

@Test
public void testCapabilityRefresh() throws Exception {
    String externalConfigPath = tmpFolder.newFolder("capability-config-refresh").getAbsolutePath();
    cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
    String appName = AllProgramsApp.NAME;
    String programName = AllProgramsApp.NoOpService.NAME;
    Class<AllProgramsApp> appClass = AllProgramsApp.class;
    String version = "1.0.0";
    String namespace = NamespaceId.SYSTEM.getNamespace();
    // deploy the artifact
    deployTestArtifact(namespace, appName, version, appClass);
    ApplicationId applicationId = new ApplicationId(namespace, appName, version);
    ProgramId programId = new ProgramId(applicationId, ProgramType.SERVICE, programName);
    // check that app is not available
    List<JsonObject> appList = getAppList(namespace);
    Assert.assertTrue(appList.isEmpty());
    // enable the capability
    CapabilityConfig config = getTestConfig("1.0.0");
    writeConfigAsFile(externalConfigPath, config.getCapability(), config);
    capabilityManagementService.runTask();
    // app should show up and program should have run
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // Capability management service might not yet have deployed application.
    // So wait till program exists and is in running state.
    waitState(programId, "RUNNING");
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 1);
    String capability = config.getCapability();
    capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
    // disable capability. Program should stop, status should be disabled and app should still be present.
    CapabilityConfig disabledConfig = changeConfigStatus(config, CapabilityStatus.DISABLED);
    writeConfigAsFile(externalConfigPath, disabledConfig.getCapability(), disabledConfig);
    capabilityManagementService.runTask();
    assertProgramRuns(programId, ProgramRunStatus.KILLED, 1);
    assertProgramRuns(programId, ProgramRunStatus.RUNNING, 0);
    try {
        capabilityStatusStore.checkAllEnabled(Collections.singleton(capability));
        Assert.fail("expecting exception");
    } catch (CapabilityNotAvailableException ex) {
    }
    appList = getAppList(namespace);
    Assert.assertFalse(appList.isEmpty());
    // delete capability. Program should stop, status should be disabled and app should still be present.
    new File(externalConfigPath, disabledConfig.getCapability()).delete();
    capabilityManagementService.runTask();
    Assert.assertTrue(capabilityStatusStore.getConfigs(Collections.singleton(capability)).isEmpty());
    appList = getAppList(namespace);
    Assert.assertTrue(appList.isEmpty());
}
Also used : JsonObject(com.google.gson.JsonObject) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) File(java.io.File) Test(org.junit.Test)

Aggregations

ApplicationId (io.cdap.cdap.proto.id.ApplicationId)789 Test (org.junit.Test)410 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)279 ProgramId (io.cdap.cdap.proto.id.ProgramId)263 ApplicationManager (io.cdap.cdap.test.ApplicationManager)225 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)223 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)196 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)180 Table (io.cdap.cdap.api.dataset.table.Table)178 WorkflowManager (io.cdap.cdap.test.WorkflowManager)169 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)154 Schema (io.cdap.cdap.api.data.schema.Schema)147 ArrayList (java.util.ArrayList)129 HashSet (java.util.HashSet)126 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)124 HashMap (java.util.HashMap)109 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)107 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)88 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)88 Path (javax.ws.rs.Path)75