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);
}
}
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;
}
Aggregations