Search in sources :

Example 1 with Containers

use of io.cdap.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(io.cdap.cdap.proto.NotRunningProgramLiveInfo) Containers(io.cdap.cdap.proto.Containers) ProgramLiveInfo(io.cdap.cdap.proto.ProgramLiveInfo) NotRunningProgramLiveInfo(io.cdap.cdap.proto.NotRunningProgramLiveInfo) Constraint(io.cdap.cdap.internal.schedule.constraint.Constraint)

Example 2 with Containers

use of io.cdap.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(io.cdap.cdap.cli.exception.CommandInputError) Table(io.cdap.cdap.cli.util.table.Table) DistributedProgramLiveInfo(io.cdap.cdap.proto.DistributedProgramLiveInfo) RowMaker(io.cdap.cdap.cli.util.RowMaker) Containers(io.cdap.cdap.proto.Containers) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Aggregations

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