Search in sources :

Example 6 with TwillController

use of org.apache.twill.api.TwillController 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

TwillController (org.apache.twill.api.TwillController)6 Map (java.util.Map)3 SimpleRuntimeInfo (co.cask.cdap.internal.app.runtime.service.SimpleRuntimeInfo)2 RunRecordMeta (co.cask.cdap.internal.app.store.RunRecordMeta)2 Containers (co.cask.cdap.proto.Containers)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ResourceReport (org.apache.twill.api.ResourceReport)2 RunId (org.apache.twill.api.RunId)2 TwillRunResources (org.apache.twill.api.TwillRunResources)2 TwillRunner (org.apache.twill.api.TwillRunner)2 ProgramDescriptor (co.cask.cdap.app.program.ProgramDescriptor)1 ProgramController (co.cask.cdap.app.runtime.ProgramController)1 ProgramOptions (co.cask.cdap.app.runtime.ProgramOptions)1 MainClassLoader (co.cask.cdap.common.app.MainClassLoader)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 CombineClassLoader (co.cask.cdap.common.lang.CombineClassLoader)1 LoggerLogHandler (co.cask.cdap.common.logging.LoggerLogHandler)1 HBaseDDLExecutorFactory (co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory)1 SimpleProgramOptions (co.cask.cdap.internal.app.runtime.SimpleProgramOptions)1