Search in sources :

Example 1 with ResourceReport

use of org.apache.twill.api.ResourceReport in project cdap by caskdata.

the class DistributedProgramRuntimeService method createController.

@Nullable
private ProgramController createController(ProgramDescriptor programDescriptor, TwillController controller, RunId runId) {
    ProgramId programId = programDescriptor.getProgramId();
    ProgramRunner programRunner;
    try {
        programRunner = programRunnerFactory.create(programId.getType());
    } catch (IllegalArgumentException e) {
        // This shouldn't happen. If it happen, it means CDAP was incorrectly install such that some of the program
        // type is not support (maybe due to version mismatch in upgrade).
        LOG.error("Unsupported program type {} for program {}. " + "It is likely caused by incorrect CDAP installation or upgrade to incompatible CDAP version", programId.getType(), programId);
        return null;
    }
    if (!(programRunner instanceof DistributedProgramRunner)) {
        // This is also unexpected. If it happen, it means the CDAP core or the runtime provider extension was wrongly
        // implemented
        ResourceReport resourceReport = controller.getResourceReport();
        LOG.error("Unable to create ProgramController for program {} for twill application {}. It is likely caused by " + "invalid CDAP program runtime extension.", programId, resourceReport == null ? "'unknown twill application'" : resourceReport.getApplicationId());
        return null;
    }
    return ((DistributedProgramRunner) programRunner).createProgramController(controller, programDescriptor, runId);
}
Also used : ResourceReport(org.apache.twill.api.ResourceReport) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramRunner(co.cask.cdap.app.runtime.ProgramRunner) Nullable(javax.annotation.Nullable)

Example 2 with ResourceReport

use of org.apache.twill.api.ResourceReport in project cdap by caskdata.

the class AbstractDistributedMasterServiceManager method getLiveInfo.

@Override
public SystemServiceLiveInfo getLiveInfo() {
    SystemServiceLiveInfo.Builder builder = SystemServiceLiveInfo.builder();
    Iterable<TwillController> twillControllerList = twillRunnerService.lookup(Constants.Service.MASTER_SERVICES);
    if (twillControllerList == null) {
        return builder.build();
    }
    for (TwillController twillController : twillControllerList) {
        if (twillController.getResourceReport() == null) {
            continue;
        }
        ResourceReport resourceReport = twillController.getResourceReport();
        Collection<TwillRunResources> runResources = resourceReport.getResources().get(serviceName);
        for (TwillRunResources resources : runResources) {
            Containers.ContainerInfo containerInfo = new Containers.ContainerInfo(Containers.ContainerType.SYSTEM_SERVICE, serviceName, resources.getInstanceId(), resources.getContainerId(), resources.getHost(), resources.getMemoryMB(), resources.getVirtualCores(), resources.getDebugPort());
            builder.addContainer(containerInfo);
        }
    }
    return builder.build();
}
Also used : TwillController(org.apache.twill.api.TwillController) SystemServiceLiveInfo(co.cask.cdap.proto.SystemServiceLiveInfo) Containers(co.cask.cdap.proto.Containers) ResourceReport(org.apache.twill.api.ResourceReport) TwillRunResources(org.apache.twill.api.TwillRunResources)

Example 3 with ResourceReport

use of org.apache.twill.api.ResourceReport in project cdap by caskdata.

the class DistributedProgramRuntimeService method getLiveInfo.

@Override
public ProgramLiveInfo getLiveInfo(ProgramId program) {
    String twillAppName = TwillAppNames.toTwillAppName(program);
    Iterator<TwillController> controllers = twillRunner.lookup(twillAppName).iterator();
    // this will return an empty Json if there is no live instance
    if (controllers.hasNext()) {
        TwillController controller = controllers.next();
        if (controllers.hasNext()) {
            LOG.warn("Expected at most one live instance of Twill app {} but found at least two.", twillAppName);
        }
        ResourceReport report = controller.getResourceReport();
        if (report != null) {
            DistributedProgramLiveInfo liveInfo = new DistributedProgramLiveInfo(program, report.getApplicationId());
            // if program type is flow then the container type is flowlet.
            Containers.ContainerType containerType = ProgramType.FLOW.equals(program.getType()) ? FLOWLET : Containers.ContainerType.valueOf(program.getType().name());
            for (Map.Entry<String, Collection<TwillRunResources>> entry : report.getResources().entrySet()) {
                for (TwillRunResources resources : entry.getValue()) {
                    liveInfo.addContainer(new ContainerInfo(containerType, entry.getKey(), resources.getInstanceId(), resources.getContainerId(), resources.getHost(), resources.getMemoryMB(), resources.getVirtualCores(), resources.getDebugPort()));
                }
            }
            // Add a list of announced services and their discoverables to the liveInfo.
            liveInfo.addServices(report.getServices());
            return liveInfo;
        }
    }
    return new NotRunningProgramLiveInfo(program);
}
Also used : Containers(co.cask.cdap.proto.Containers) TwillController(org.apache.twill.api.TwillController) NotRunningProgramLiveInfo(co.cask.cdap.proto.NotRunningProgramLiveInfo) DistributedProgramLiveInfo(co.cask.cdap.proto.DistributedProgramLiveInfo) ContainerInfo(co.cask.cdap.proto.Containers.ContainerInfo) Collection(java.util.Collection) ResourceReport(org.apache.twill.api.ResourceReport) TwillRunResources(org.apache.twill.api.TwillRunResources) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ResourceReport (org.apache.twill.api.ResourceReport)3 Containers (co.cask.cdap.proto.Containers)2 TwillController (org.apache.twill.api.TwillController)2 TwillRunResources (org.apache.twill.api.TwillRunResources)2 ProgramRunner (co.cask.cdap.app.runtime.ProgramRunner)1 ContainerInfo (co.cask.cdap.proto.Containers.ContainerInfo)1 DistributedProgramLiveInfo (co.cask.cdap.proto.DistributedProgramLiveInfo)1 NotRunningProgramLiveInfo (co.cask.cdap.proto.NotRunningProgramLiveInfo)1 SystemServiceLiveInfo (co.cask.cdap.proto.SystemServiceLiveInfo)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1