Search in sources :

Example 36 with ProgramType

use of co.cask.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(co.cask.cdap.proto.ProgramType) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 37 with ProgramType

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

the class UsageHandler method getProgramStreamUsage.

@GET
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/streams")
public void getProgramStreamUsage(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<StreamId> ids = registry.getStreams(id);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids));
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ProgramType(co.cask.cdap.proto.ProgramType) ProgramId(co.cask.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 38 with ProgramType

use of co.cask.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 {
    WorkflowDataset.WorkflowRunRecord workflowRunRecord = store.getWorkflowRun(workflowId, runId);
    if (workflowRunRecord == null) {
        return null;
    }
    List<WorkflowDataset.ProgramRun> programRuns = workflowRunRecord.getProgramRuns();
    List<ProgramMetrics> programMetricsList = new ArrayList<>();
    for (WorkflowDataset.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 : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramType(co.cask.cdap.proto.ProgramType) WorkflowDataset(co.cask.cdap.internal.app.store.WorkflowDataset) Nullable(javax.annotation.Nullable)

Example 39 with ProgramType

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

the class ProgramLifecycleHttpHandler method getProgramInstances.

/**
 * Get requested and provisioned instances for a program type.
 * The program type passed here should be one that can have instances (flows, services, ...)
 * Requires caller to do this validation.
 */
private BatchRunnableInstances getProgramInstances(BatchRunnable runnable, ApplicationSpecification spec, ProgramId programId) {
    int requested;
    String programName = programId.getProgram();
    String runnableId = programName;
    ProgramType programType = programId.getType();
    if (programType == ProgramType.WORKER) {
        if (!spec.getWorkers().containsKey(programName)) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Worker: " + programName + " not found");
        }
        requested = spec.getWorkers().get(programName).getInstances();
    } else if (programType == ProgramType.SERVICE) {
        if (!spec.getServices().containsKey(programName)) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Service: " + programName + " not found");
        }
        requested = spec.getServices().get(programName).getInstances();
    } else if (programType == ProgramType.FLOW) {
        // flows must have runnable id
        runnableId = runnable.getRunnableId();
        if (runnableId == null) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.BAD_REQUEST.code(), "Must provide the flowlet id as the runnableId for flows");
        }
        FlowSpecification flowSpec = spec.getFlows().get(programName);
        if (flowSpec == null) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Flow: " + programName + " not found");
        }
        FlowletDefinition flowletDefinition = flowSpec.getFlowlets().get(runnableId);
        if (flowletDefinition == null) {
            return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Flowlet: " + runnableId + " not found");
        }
        requested = flowletDefinition.getInstances();
    } else {
        return new BatchRunnableInstances(runnable, HttpResponseStatus.BAD_REQUEST.code(), "Instances not supported for program type + " + programType);
    }
    int provisioned = getInstanceCount(programId, runnableId);
    // use the pretty name of program types to be consistent
    return new BatchRunnableInstances(runnable, HttpResponseStatus.OK.code(), provisioned, requested);
}
Also used : FlowletDefinition(co.cask.cdap.api.flow.FlowletDefinition) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) BatchRunnableInstances(co.cask.cdap.proto.BatchRunnableInstances) ProgramType(co.cask.cdap.proto.ProgramType) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint)

Example 40 with ProgramType

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

the class ProgramLifecycleHttpHandler method resetLogLevels.

private void resetLogLevels(FullHttpRequest request, HttpResponder responder, String namespace, String appName, String appVersion, String type, String programName, @Nullable String component, String runId) throws Exception {
    ProgramType programType = getProgramType(type);
    if (programType == null) {
        throw new BadRequestException("Invalid program type provided");
    }
    try {
        Set<String> loggerNames = parseBody(request, SET_STRING_TYPE);
        lifecycleService.resetProgramLogLevels(new ApplicationId(namespace, appName, appVersion).program(programType, programName), loggerNames == null ? Collections.emptySet() : loggerNames, component, runId);
        responder.sendStatus(HttpResponseStatus.OK);
    } catch (JsonSyntaxException e) {
        throw new BadRequestException("Invalid JSON in body");
    } catch (SecurityException e) {
        throw new UnauthorizedException("Unauthorized to reset the log levels");
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) BadRequestException(co.cask.cdap.common.BadRequestException) ProgramType(co.cask.cdap.proto.ProgramType) ApplicationId(co.cask.cdap.proto.id.ApplicationId)

Aggregations

ProgramType (co.cask.cdap.proto.ProgramType)71 ProgramId (co.cask.cdap.proto.id.ProgramId)33 ApplicationId (co.cask.cdap.proto.id.ApplicationId)22 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)21 Path (javax.ws.rs.Path)16 BadRequestException (co.cask.cdap.common.BadRequestException)13 GET (javax.ws.rs.GET)13 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)12 NotFoundException (co.cask.cdap.common.NotFoundException)12 RunId (org.apache.twill.api.RunId)11 ProgramController (co.cask.cdap.app.runtime.ProgramController)8 ArrayList (java.util.ArrayList)8 ProgramContextAware (co.cask.cdap.data.ProgramContextAware)6 BasicProgramContext (co.cask.cdap.internal.app.runtime.BasicProgramContext)6 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)5 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)5 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)4 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)4 PluginInstantiator (co.cask.cdap.internal.app.runtime.plugin.PluginInstantiator)4