@VisibleForTesting public Set<String> getMatchedContainerLogFiles(ContainerLogsRequest request, boolean useRegex, boolean ignoreSizeLimit) throws IOException { // fetch all the log files for the container // filter the log files based on the given -log_files pattern List<Pair<ContainerLogFileInfo, String>> allLogFileInfos= getContainerLogFiles(getConf(), request.getContainerId(), request.getNodeHttpAddress()); List<ContainerLogFileInfo> fileNames = new ArrayList< ContainerLogFileInfo>(); for (Pair<ContainerLogFileInfo, String> fileInfo : allLogFileInfos) { fileNames.add(fileInfo.getKey()); } return getMatchedLogFiles(request, fileNames, useRegex, ignoreSizeLimit); }
@Private @VisibleForTesting public ContainerLogsRequest getMatchedOptionForRunningApp( ContainerLogsRequest container, boolean useRegex, boolean ignoreSizeLimit) throws IOException { String containerIdStr = container.getContainerId().toString(); String nodeHttpAddress = container.getNodeHttpAddress(); if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()) { System.err.println("Can not get the logs for the container: " + containerIdStr); System.err.println("The node http address is required to get container " + "logs for the Running application."); return null; } Set<String> matchedFiles = getMatchedContainerLogFiles(container, useRegex, ignoreSizeLimit); if (matchedFiles.isEmpty()) { System.err.println("Can not find any log file matching the pattern: " + container.getLogTypes() + " for the container: " + containerIdStr + " within the application: " + container.getAppId()); return null; } container.setLogTypes(matchedFiles); return container; }
private void outputAMContainerLogs(ContainerLogsRequest request, Configuration conf, LogCLIHelpers logCliHelper, boolean useRegex, boolean ignoreSizeLimit) throws Exception { String nodeHttpAddress = request.getNodeHttpAddress(); String containerId = request.getContainerId(); String nodeId = request.getNodeId(); if (request.isAppFinished()) { if (containerId != null && !containerId.isEmpty()) { if (nodeId != null && !nodeId.isEmpty()) { logCliHelper.dumpAContainerLogsForLogType(request); } else { logCliHelper.dumpAContainerLogsForLogTypeWithoutNodeId( request); } } } else { if (nodeHttpAddress != null && containerId != null && !nodeHttpAddress.isEmpty() && !containerId.isEmpty()) { ContainerState containerState = getContainerReport(containerId) .getContainerState(); request.setContainerState(containerState); printContainerLogsFromRunningApplication(conf, request, logCliHelper, useRegex, ignoreSizeLimit); } } }
@VisibleForTesting public ClientResponse getResponeFromNMWebService(Configuration conf, Client webServiceClient, ContainerLogsRequest request, String logFile) { WebResource webResource = webServiceClient.resource(WebAppUtils.getHttpSchemePrefix(conf) + request.getNodeHttpAddress()); return webResource.path("ws").path("v1").path("node") .path("containers").path(request.getContainerId()).path("logs") .path(logFile) .queryParam("size", Long.toString(request.getBytes())) .accept(MediaType.TEXT_PLAIN).get(ClientResponse.class); }
public ContainerLogsRequest(ContainerLogsRequest request) { this.setAppId(request.getAppId()); this.setAppFinished(request.isAppFinished()); this.setAppOwner(request.getAppOwner()); this.setNodeId(request.getNodeId()); this.setNodeHttpAddress(request.getNodeHttpAddress()); this.setContainerId(request.getContainerId()); this.setOutputLocalDir(request.getOutputLocalDir()); this.setLogTypes(request.getLogTypes()); this.setBytes(request.getBytes()); this.setContainerState(request.getContainerState()); }