Search in sources :

Example 26 with ProgramType

use of io.cdap.cdap.proto.ProgramType in project cdap by caskdata.

the class ProgramLifecycleHttpHandler method liveInfo.

@GET
@Path("/apps/{app-id}/{program-category}/{program-id}/live-info")
@SuppressWarnings("unused")
public void liveInfo(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-category") String programCategory, @PathParam("program-id") String programId) throws BadRequestException {
    ProgramType type = getProgramType(programCategory);
    ProgramId program = new ProgramId(namespaceId, appId, type, programId);
    getLiveInfo(responder, program, runtimeService);
}
Also used : ProgramType(io.cdap.cdap.proto.ProgramType) ProgramId(io.cdap.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 27 with ProgramType

use of io.cdap.cdap.proto.ProgramType in project cdap by caskdata.

the class ProgramLifecycleHttpHandler method getServiceAvailability.

/**
 * Return the availability (i.e. discoverable registration) status of a service.
 */
@GET
@Path("/apps/{app-name}/versions/{app-version}/{service-type}/{program-name}/available")
public void getServiceAvailability(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-name") String appName, @PathParam("app-version") String appVersion, @PathParam("service-type") String serviceType, @PathParam("program-name") String programName) throws Exception {
    // Currently we only support services and sparks as the service-type
    ProgramType programType = getProgramType(serviceType);
    if (!ServiceDiscoverable.getUserServiceTypes().contains(programType)) {
        throw new BadRequestException("Only service or spark is support for service availability check");
    }
    ProgramId programId = new ProgramId(new ApplicationId(namespaceId, appName, appVersion), programType, programName);
    ProgramStatus status = lifecycleService.getProgramStatus(programId);
    if (status == ProgramStatus.STOPPED) {
        throw new ServiceUnavailableException(programId.toString(), "Service is stopped. Please start it.");
    }
    // Construct discoverable name and return 200 OK if discoverable is present. If not return 503.
    String discoverableName = ServiceDiscoverable.getName(programId);
    // TODO: CDAP-12959 - Should use the UserServiceEndpointStrategy and discover based on the version
    // and have appVersion nullable for the non versioned endpoint
    EndpointStrategy strategy = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(discoverableName));
    if (strategy.pick(300L, TimeUnit.MILLISECONDS) == null) {
        LOG.trace("Discoverable endpoint {} not found", discoverableName);
        throw new ServiceUnavailableException(programId.toString(), "Service is running but not accepting requests at this time.");
    }
    responder.sendString(HttpResponseStatus.OK, "Service is available to accept requests.");
}
Also used : RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(io.cdap.cdap.common.discovery.EndpointStrategy) BadRequestException(io.cdap.cdap.common.BadRequestException) ProgramType(io.cdap.cdap.proto.ProgramType) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) ProgramId(io.cdap.cdap.proto.id.ProgramId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramStatus(io.cdap.cdap.proto.ProgramStatus) BatchProgramStatus(io.cdap.cdap.proto.BatchProgramStatus) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 28 with ProgramType

use of io.cdap.cdap.proto.ProgramType in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerInternal method getProgramRunRecordMeta.

/**
 * Return {@link RunRecordDetail} for the given program run id
 *
 * @param request {@link HttpRequest}
 * @param responder {@link HttpResponse}
 * @param namespaceId namespace of the program
 * @param appName name of the application
 * @param appVersion version of the application
 * @param type type of the program
 * @param programName name of the program
 * @param runid for which {@link RunRecordDetail} will be returned
 * @throws Exception if failed to to get {@link RunRecordDetail}
 */
@GET
@Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}/runs/{run-id}")
public void getProgramRunRecordMeta(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-name") String appName, @PathParam("app-version") String appVersion, @PathParam("program-type") String type, @PathParam("program-name") String programName, @PathParam("run-id") String runid) throws Exception {
    ProgramType programType = ProgramType.valueOfCategoryName(type, BadRequestException::new);
    ProgramId programId = new ApplicationId(namespaceId, appName, appVersion).program(programType, programName);
    RunRecordDetail runRecordMeta = programLifecycleService.getRunRecordMeta(programId.run(runid));
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runRecordMeta));
}
Also used : RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) BadRequestException(io.cdap.cdap.common.BadRequestException) ProgramType(io.cdap.cdap.proto.ProgramType) ProgramId(io.cdap.cdap.proto.id.ProgramId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 29 with ProgramType

use of io.cdap.cdap.proto.ProgramType in project cdap by caskdata.

the class UsageHandler method getProgramDatasetUsage.

@GET
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/datasets")
public void getProgramDatasetUsage(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId) {
    ProgramType type = ProgramType.valueOfCategoryName(programType);
    final ProgramId id = new ProgramId(namespaceId, appId, type, programId);
    Set<DatasetId> ids = registry.getDatasets(id);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids));
}
Also used : ProgramType(io.cdap.cdap.proto.ProgramType) ProgramId(io.cdap.cdap.proto.id.ProgramId) DatasetId(io.cdap.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 30 with ProgramType

use of io.cdap.cdap.proto.ProgramType in project cdap by caskdata.

the class WorkflowStatsSLAHttpHandler method getDetailedRecord.

/**
 * Returns the detailed Record for the Workflow
 *
 * @param workflowId Workflow that needs to get its detailed record
 * @param runId Run Id of the workflow
 * @return Return the Workflow Run Metrics
 */
@Nullable
private WorkflowRunMetrics getDetailedRecord(WorkflowId workflowId, String runId) throws Exception {
    WorkflowTable.WorkflowRunRecord workflowRunRecord = store.getWorkflowRun(workflowId, runId);
    if (workflowRunRecord == null) {
        return null;
    }
    List<WorkflowTable.ProgramRun> programRuns = workflowRunRecord.getProgramRuns();
    List<ProgramMetrics> programMetricsList = new ArrayList<>();
    for (WorkflowTable.ProgramRun programRun : programRuns) {
        Map<String, Long> programMap = new HashMap<>();
        String programName = programRun.getName();
        ProgramType programType = programRun.getProgramType();
        ProgramId program = new ProgramId(workflowId.getNamespace(), workflowId.getApplication(), programType, programName);
        String programRunId = programRun.getRunId();
        if (programType == ProgramType.MAPREDUCE) {
            programMap = getMapreduceDetails(program, programRunId);
        } else if (programType == ProgramType.SPARK) {
            programMap = getSparkDetails(program, programRunId);
        }
        programMap.put("timeTaken", programRun.getTimeTaken());
        long programStartTime = RunIds.getTime(RunIds.fromString(programRunId), TimeUnit.SECONDS);
        programMetricsList.add(new ProgramMetrics(programName, programType, programRunId, programStartTime, programMap));
    }
    return new WorkflowRunMetrics(runId, programMetricsList);
}
Also used : WorkflowTable(io.cdap.cdap.internal.app.store.WorkflowTable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProgramId(io.cdap.cdap.proto.id.ProgramId) ProgramType(io.cdap.cdap.proto.ProgramType) Nullable(javax.annotation.Nullable)

Aggregations

ProgramType (io.cdap.cdap.proto.ProgramType)150 ProgramId (io.cdap.cdap.proto.id.ProgramId)82 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)53 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)50 Path (javax.ws.rs.Path)44 GET (javax.ws.rs.GET)40 ArrayList (java.util.ArrayList)34 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)30 BadRequestException (io.cdap.cdap.common.BadRequestException)28 List (java.util.List)26 Map (java.util.Map)26 HashMap (java.util.HashMap)24 Nullable (javax.annotation.Nullable)24 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)22 NotFoundException (io.cdap.cdap.common.NotFoundException)22 RunRecordDetail (io.cdap.cdap.internal.app.store.RunRecordDetail)22 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)22 Set (java.util.Set)22 RunId (org.apache.twill.api.RunId)22 Constants (io.cdap.cdap.common.conf.Constants)20