Search in sources :

Example 1 with ContainerInfo

use of io.cdap.cdap.proto.Containers.ContainerInfo 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());
            Containers.ContainerType containerType = 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 super.getLiveInfo(program);
}
Also used : TwillController(org.apache.twill.api.TwillController) DistributedProgramLiveInfo(io.cdap.cdap.proto.DistributedProgramLiveInfo) Containers(io.cdap.cdap.proto.Containers) ContainerInfo(io.cdap.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) HashMap(java.util.HashMap)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Containers (io.cdap.cdap.proto.Containers)1 ContainerInfo (io.cdap.cdap.proto.Containers.ContainerInfo)1 DistributedProgramLiveInfo (io.cdap.cdap.proto.DistributedProgramLiveInfo)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ResourceReport (org.apache.twill.api.ResourceReport)1 TwillController (org.apache.twill.api.TwillController)1 TwillRunResources (org.apache.twill.api.TwillRunResources)1