Search in sources :

Example 1 with Containers

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

the class GetProgramLiveInfoCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    String appId = programIdParts[0];
    String programName = programIdParts[1];
    ProgramId program = cliConfig.getCurrentNamespace().app(appId).program(elementType.getProgramType(), programName);
    DistributedProgramLiveInfo liveInfo = programClient.getLiveInfo(program);
    if (liveInfo == null) {
        output.println("No live info found");
        return;
    }
    Table table = Table.builder().setHeader("app", "type", "id", "runtime", "yarn app id").setRows(ImmutableList.of(liveInfo), new RowMaker<DistributedProgramLiveInfo>() {

        @Override
        public List<?> makeRow(DistributedProgramLiveInfo object) {
            return Lists.newArrayList(object.getApp(), object.getType(), object.getName(), object.getRuntime(), object.getYarnAppId());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
    if (liveInfo.getContainers() != null) {
        Table containersTable = Table.builder().setHeader("containers", "instance", "host", "container", "memory", "virtual cores", "debug port").setRows(liveInfo.getContainers(), new RowMaker<Containers.ContainerInfo>() {

            @Override
            public List<?> makeRow(Containers.ContainerInfo object) {
                return Lists.newArrayList("", object.getInstance(), object.getHost(), object.getContainer(), object.getMemory(), object.getVirtualCores(), object.getDebugPort());
            }
        }).build();
        cliConfig.getTableRenderer().render(cliConfig, output, containersTable);
    }
}
Also used : CommandInputError(co.cask.cdap.cli.exception.CommandInputError) Table(co.cask.cdap.cli.util.table.Table) DistributedProgramLiveInfo(co.cask.cdap.proto.DistributedProgramLiveInfo) RowMaker(co.cask.cdap.cli.util.RowMaker) Containers(co.cask.cdap.proto.Containers) ProgramId(co.cask.cdap.proto.id.ProgramId)

Example 2 with Containers

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

Aggregations

Containers (co.cask.cdap.proto.Containers)2 CommandInputError (co.cask.cdap.cli.exception.CommandInputError)1 RowMaker (co.cask.cdap.cli.util.RowMaker)1 Table (co.cask.cdap.cli.util.table.Table)1 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)1 DistributedProgramLiveInfo (co.cask.cdap.proto.DistributedProgramLiveInfo)1 NotRunningProgramLiveInfo (co.cask.cdap.proto.NotRunningProgramLiveInfo)1 ProgramLiveInfo (co.cask.cdap.proto.ProgramLiveInfo)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1