use of co.cask.cdap.proto.DistributedProgramLiveInfo in project cdap by caskdata.
the class ProgramClient method getLiveInfo.
/**
* Gets the live information of a program. In distributed CDAP,
* this will contain IDs of the YARN applications that are running the program.
*
* @param program the program
* @return {@link ProgramLiveInfo} of the program
* @throws IOException if a network error occurred
* @throws ProgramNotFoundException if the program with the specified name could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public DistributedProgramLiveInfo getLiveInfo(ProgramId program) throws IOException, ProgramNotFoundException, UnauthenticatedException, UnauthorizedException {
String path = String.format("apps/%s/%s/%s/live-info", program.getApplication(), program.getType().getCategoryName(), program.getProgram());
URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ProgramNotFoundException(program);
}
return ObjectResponse.fromJsonBody(response, DistributedProgramLiveInfo.class).getResponseObject();
}
use of co.cask.cdap.proto.DistributedProgramLiveInfo 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);
}
use of co.cask.cdap.proto.DistributedProgramLiveInfo 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);
}
}
Aggregations