Search in sources :

Example 36 with Private

use of org.apache.hadoop.classification.InterfaceAudience.Private in project hadoop by apache.

the class LogsCLI method printContainerLogsFromRunningApplication.

@Private
@VisibleForTesting
public int printContainerLogsFromRunningApplication(Configuration conf, ContainerLogsRequest request, LogCLIHelpers logCliHelper, boolean useRegex) throws IOException {
    String containerIdStr = request.getContainerId().toString();
    String localDir = request.getOutputLocalDir();
    String nodeHttpAddress = request.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 -1;
    }
    String nodeId = request.getNodeId();
    PrintStream out = logCliHelper.createPrintStream(localDir, nodeId, containerIdStr);
    try {
        Set<String> matchedFiles = getMatchedContainerLogFiles(request, useRegex);
        if (matchedFiles.isEmpty()) {
            System.err.println("Can not find any log file matching the pattern: " + request.getLogTypes() + " for the container: " + containerIdStr + " within the application: " + request.getAppId());
            return -1;
        }
        ContainerLogsRequest newOptions = new ContainerLogsRequest(request);
        newOptions.setLogTypes(matchedFiles);
        Client webServiceClient = Client.create();
        boolean foundAnyLogs = false;
        byte[] buffer = new byte[65536];
        for (String logFile : newOptions.getLogTypes()) {
            InputStream is = null;
            try {
                ClientResponse response = getResponeFromNMWebService(conf, webServiceClient, request, logFile);
                if (response != null && response.getStatusInfo().getStatusCode() == ClientResponse.Status.OK.getStatusCode()) {
                    is = response.getEntityInputStream();
                    int len = 0;
                    while ((len = is.read(buffer)) != -1) {
                        out.write(buffer, 0, len);
                    }
                    out.println();
                } else {
                    out.println("Can not get any logs for the log file: " + logFile);
                    String msg = "Response from the NodeManager:" + nodeId + " WebService is " + ((response == null) ? "null" : "not successful," + " HTTP error code: " + response.getStatus() + ", Server response:\n" + response.getEntity(String.class));
                    out.println(msg);
                }
                out.flush();
                foundAnyLogs = true;
            } catch (ClientHandlerException | UniformInterfaceException ex) {
                System.err.println("Can not find the log file:" + logFile + " for the container:" + containerIdStr + " in NodeManager:" + nodeId);
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
        if (foundAnyLogs) {
            return 0;
        } else {
            return -1;
        }
    } finally {
        logCliHelper.closePrintStream(out);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) PrintStream(java.io.PrintStream) InputStream(java.io.InputStream) ContainerLogsRequest(org.apache.hadoop.yarn.logaggregation.ContainerLogsRequest) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) Client(com.sun.jersey.api.client.Client) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 37 with Private

use of org.apache.hadoop.classification.InterfaceAudience.Private in project hadoop by apache.

the class AMRMClientImpl method populateNMTokens.

@Private
@VisibleForTesting
protected void populateNMTokens(List<NMToken> nmTokens) {
    for (NMToken token : nmTokens) {
        String nodeId = token.getNodeId().toString();
        if (LOG.isDebugEnabled()) {
            if (getNMTokenCache().containsToken(nodeId)) {
                LOG.debug("Replacing token for : " + nodeId);
            } else {
                LOG.debug("Received new token for : " + nodeId);
            }
        }
        getNMTokenCache().setToken(nodeId, token.getToken());
    }
}
Also used : NMToken(org.apache.hadoop.yarn.api.records.NMToken) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 38 with Private

use of org.apache.hadoop.classification.InterfaceAudience.Private in project hadoop by apache.

the class LogCLIHelpers method getOwnerForAppIdOrNull.

@Private
@VisibleForTesting
public static /**
   * Return the owner for a given AppId
   * @param remoteRootLogDir
   * @param appId
   * @param bestGuess
   * @param conf
   * @return the owner or null
   * @throws IOException
   */
String getOwnerForAppIdOrNull(ApplicationId appId, String bestGuess, Configuration conf) throws IOException {
    Path remoteRootLogDir = new Path(conf.get(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR));
    String suffix = LogAggregationUtils.getRemoteNodeLogDirSuffix(conf);
    Path fullPath = LogAggregationUtils.getRemoteAppLogDir(remoteRootLogDir, appId, bestGuess, suffix);
    FileContext fc = FileContext.getFileContext(remoteRootLogDir.toUri(), conf);
    String pathAccess = fullPath.toString();
    try {
        if (fc.util().exists(fullPath)) {
            return bestGuess;
        }
        Path toMatch = LogAggregationUtils.getRemoteAppLogDir(remoteRootLogDir, appId, "*", suffix);
        pathAccess = toMatch.toString();
        FileStatus[] matching = fc.util().globStatus(toMatch);
        if (matching == null || matching.length != 1) {
            return null;
        }
        //fetch the user from the full path /app-logs/user[/suffix]/app_id
        Path parent = matching[0].getPath().getParent();
        //skip the suffix too
        if (suffix != null && !StringUtils.isEmpty(suffix)) {
            parent = parent.getParent();
        }
        return parent.getName();
    } catch (AccessControlException | AccessDeniedException ex) {
        logDirNoAccessPermission(pathAccess, bestGuess, ex.getMessage());
        return null;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AccessDeniedException(java.nio.file.AccessDeniedException) FileStatus(org.apache.hadoop.fs.FileStatus) AccessControlException(org.apache.hadoop.security.AccessControlException) FileContext(org.apache.hadoop.fs.FileContext) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 39 with Private

use of org.apache.hadoop.classification.InterfaceAudience.Private in project hadoop by apache.

the class LogCLIHelpers method dumpAContainerLogs.

@Private
public int dumpAContainerLogs(String containerIdStr, AggregatedLogFormat.LogReader reader, PrintStream out, long logUploadedTime, long bytes) throws IOException {
    DataInputStream valueStream = getContainerLogsStream(containerIdStr, reader);
    if (valueStream == null) {
        return -1;
    }
    boolean foundContainerLogs = false;
    while (true) {
        try {
            LogReader.readAContainerLogsForALogType(valueStream, out, logUploadedTime, bytes);
            foundContainerLogs = true;
        } catch (EOFException eof) {
            break;
        }
    }
    if (foundContainerLogs) {
        return 0;
    }
    return -1;
}
Also used : EOFException(java.io.EOFException) DataInputStream(java.io.DataInputStream) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 40 with Private

use of org.apache.hadoop.classification.InterfaceAudience.Private in project hadoop by apache.

the class LogCLIHelpers method dumpAContainerLogsForALogType.

@Private
public int dumpAContainerLogsForALogType(String containerIdStr, AggregatedLogFormat.LogReader reader, PrintStream out, long logUploadedTime, List<String> logType, long bytes) throws IOException {
    DataInputStream valueStream = getContainerLogsStream(containerIdStr, reader);
    if (valueStream == null) {
        return -1;
    }
    boolean foundContainerLogs = false;
    while (true) {
        try {
            int result = LogReader.readContainerLogsForALogType(valueStream, out, logUploadedTime, logType, bytes);
            if (result == 0) {
                foundContainerLogs = true;
            }
        } catch (EOFException eof) {
            break;
        }
    }
    if (foundContainerLogs) {
        return 0;
    }
    return -1;
}
Also used : EOFException(java.io.EOFException) DataInputStream(java.io.DataInputStream) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Aggregations

Private (org.apache.hadoop.classification.InterfaceAudience.Private)52 VisibleForTesting (com.google.common.annotations.VisibleForTesting)15 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)12 IOException (java.io.IOException)9 FileStatus (org.apache.hadoop.fs.FileStatus)8 ArrayList (java.util.ArrayList)6 Path (org.apache.hadoop.fs.Path)6 DataInputStream (java.io.DataInputStream)5 EOFException (java.io.EOFException)5 PrintStream (java.io.PrintStream)5 LogReader (org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogReader)5 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 Resource (org.apache.hadoop.yarn.api.records.Resource)4 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)4 ByteString (com.google.protobuf.ByteString)2 FileNotFoundException (java.io.FileNotFoundException)2 AccessDeniedException (java.nio.file.AccessDeniedException)2 HashSet (java.util.HashSet)2 FileSystem (org.apache.hadoop.fs.FileSystem)2