Search in sources :

Example 1 with NotRunningProgramLiveInfo

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

the class ProgramLifecycleHttpHandler method getInstanceCount.

/**
   * Returns the number of instances currently running for different runnables for different programs
   */
private int getInstanceCount(ProgramId programId, String runnableId) {
    ProgramLiveInfo info = runtimeService.getLiveInfo(programId);
    int count = 0;
    if (info instanceof NotRunningProgramLiveInfo) {
        return count;
    }
    if (info instanceof Containers) {
        Containers containers = (Containers) info;
        for (Containers.ContainerInfo container : containers.getContainers()) {
            if (container.getName().equals(runnableId)) {
                count++;
            }
        }
        return count;
    }
    // The get instances contract for both flowlets and services should be re-thought and fixed as part of CDAP-1091
    if (programId.getType() == ProgramType.SERVICE) {
        return getRequestedServiceInstances(programId);
    }
    // Not running on YARN default 1
    return 1;
}
Also used : NotRunningProgramLiveInfo(co.cask.cdap.proto.NotRunningProgramLiveInfo) Containers(co.cask.cdap.proto.Containers) NotRunningProgramLiveInfo(co.cask.cdap.proto.NotRunningProgramLiveInfo) ProgramLiveInfo(co.cask.cdap.proto.ProgramLiveInfo) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) ProtoConstraint(co.cask.cdap.proto.ProtoConstraint)

Example 2 with NotRunningProgramLiveInfo

use of co.cask.cdap.proto.NotRunningProgramLiveInfo 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

Containers (co.cask.cdap.proto.Containers)2 NotRunningProgramLiveInfo (co.cask.cdap.proto.NotRunningProgramLiveInfo)2 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)1 ContainerInfo (co.cask.cdap.proto.Containers.ContainerInfo)1 DistributedProgramLiveInfo (co.cask.cdap.proto.DistributedProgramLiveInfo)1 ProgramLiveInfo (co.cask.cdap.proto.ProgramLiveInfo)1 ProtoConstraint (co.cask.cdap.proto.ProtoConstraint)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)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