Search in sources :

Example 56 with ApplicationAccessType

use of org.apache.hadoop.yarn.api.records.ApplicationAccessType in project hadoop by apache.

the class RegisterApplicationMasterResponsePBImpl method initApplicationACLs.

private void initApplicationACLs() {
    if (this.applicationACLS != null) {
        return;
    }
    RegisterApplicationMasterResponseProtoOrBuilder p = viaProto ? proto : builder;
    List<ApplicationACLMapProto> list = p.getApplicationACLsList();
    this.applicationACLS = new HashMap<ApplicationAccessType, String>(list.size());
    for (ApplicationACLMapProto aclProto : list) {
        this.applicationACLS.put(ProtoUtils.convertFromProtoFormat(aclProto.getAccessType()), aclProto.getAcl());
    }
}
Also used : RegisterApplicationMasterResponseProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnServiceProtos.RegisterApplicationMasterResponseProtoOrBuilder) ApplicationAccessType(org.apache.hadoop.yarn.api.records.ApplicationAccessType) ApplicationACLMapProto(org.apache.hadoop.yarn.proto.YarnProtos.ApplicationACLMapProto) ByteString(com.google.protobuf.ByteString)

Example 57 with ApplicationAccessType

use of org.apache.hadoop.yarn.api.records.ApplicationAccessType in project hadoop by apache.

the class RegisterApplicationMasterResponsePBImpl method addApplicationACLs.

private void addApplicationACLs() {
    maybeInitBuilder();
    builder.clearApplicationACLs();
    if (applicationACLS == null) {
        return;
    }
    Iterable<? extends ApplicationACLMapProto> values = new Iterable<ApplicationACLMapProto>() {

        @Override
        public Iterator<ApplicationACLMapProto> iterator() {
            return new Iterator<ApplicationACLMapProto>() {

                Iterator<ApplicationAccessType> aclsIterator = applicationACLS.keySet().iterator();

                @Override
                public boolean hasNext() {
                    return aclsIterator.hasNext();
                }

                @Override
                public ApplicationACLMapProto next() {
                    ApplicationAccessType key = aclsIterator.next();
                    return ApplicationACLMapProto.newBuilder().setAcl(applicationACLS.get(key)).setAccessType(ProtoUtils.convertToProtoFormat(key)).build();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
    this.builder.addAllApplicationACLs(values);
}
Also used : ApplicationAccessType(org.apache.hadoop.yarn.api.records.ApplicationAccessType) ApplicationACLMapProto(org.apache.hadoop.yarn.proto.YarnProtos.ApplicationACLMapProto)

Example 58 with ApplicationAccessType

use of org.apache.hadoop.yarn.api.records.ApplicationAccessType in project hadoop by apache.

the class ContainerLaunchContextPBImpl method initApplicationACLs.

private void initApplicationACLs() {
    if (this.applicationACLS != null) {
        return;
    }
    ContainerLaunchContextProtoOrBuilder p = viaProto ? proto : builder;
    List<ApplicationACLMapProto> list = p.getApplicationACLsList();
    this.applicationACLS = new HashMap<ApplicationAccessType, String>(list.size());
    for (ApplicationACLMapProto aclProto : list) {
        this.applicationACLS.put(ProtoUtils.convertFromProtoFormat(aclProto.getAccessType()), aclProto.getAcl());
    }
}
Also used : ApplicationAccessType(org.apache.hadoop.yarn.api.records.ApplicationAccessType) ApplicationACLMapProto(org.apache.hadoop.yarn.proto.YarnProtos.ApplicationACLMapProto) ByteString(com.google.protobuf.ByteString) ContainerLaunchContextProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnProtos.ContainerLaunchContextProtoOrBuilder)

Example 59 with ApplicationAccessType

use of org.apache.hadoop.yarn.api.records.ApplicationAccessType in project hadoop by apache.

the class ContainerLaunchContextPBImpl method addApplicationACLs.

private void addApplicationACLs() {
    maybeInitBuilder();
    builder.clearApplicationACLs();
    if (applicationACLS == null) {
        return;
    }
    Iterable<? extends ApplicationACLMapProto> values = new Iterable<ApplicationACLMapProto>() {

        @Override
        public Iterator<ApplicationACLMapProto> iterator() {
            return new Iterator<ApplicationACLMapProto>() {

                Iterator<ApplicationAccessType> aclsIterator = applicationACLS.keySet().iterator();

                @Override
                public boolean hasNext() {
                    return aclsIterator.hasNext();
                }

                @Override
                public ApplicationACLMapProto next() {
                    ApplicationAccessType key = aclsIterator.next();
                    return ApplicationACLMapProto.newBuilder().setAcl(applicationACLS.get(key)).setAccessType(ProtoUtils.convertToProtoFormat(key)).build();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
    this.builder.addAllApplicationACLs(values);
}
Also used : ApplicationAccessType(org.apache.hadoop.yarn.api.records.ApplicationAccessType) ApplicationACLMapProto(org.apache.hadoop.yarn.proto.YarnProtos.ApplicationACLMapProto) Iterator(java.util.Iterator)

Example 60 with ApplicationAccessType

use of org.apache.hadoop.yarn.api.records.ApplicationAccessType in project hadoop by apache.

the class AggregatedLogsBlock method render.

@Override
protected void render(Block html) {
    ContainerId containerId = verifyAndGetContainerId(html);
    NodeId nodeId = verifyAndGetNodeId(html);
    String appOwner = verifyAndGetAppOwner(html);
    LogLimits logLimits = verifyAndGetLogLimits(html);
    if (containerId == null || nodeId == null || appOwner == null || appOwner.isEmpty() || logLimits == null) {
        return;
    }
    ApplicationId applicationId = containerId.getApplicationAttemptId().getApplicationId();
    String logEntity = $(ENTITY_STRING);
    if (logEntity == null || logEntity.isEmpty()) {
        logEntity = containerId.toString();
    }
    String nmApplicationLogUrl = getApplicationLogURL(applicationId);
    if (!conf.getBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED, YarnConfiguration.DEFAULT_LOG_AGGREGATION_ENABLED)) {
        html.h1()._("Aggregation is not enabled. Try the nodemanager at " + nodeId)._();
        if (nmApplicationLogUrl != null) {
            html.h1()._("Or see application log at " + nmApplicationLogUrl)._();
        }
        return;
    }
    Path remoteRootLogDir = new Path(conf.get(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR));
    Path remoteAppDir = LogAggregationUtils.getRemoteAppLogDir(remoteRootLogDir, applicationId, appOwner, LogAggregationUtils.getRemoteNodeLogDirSuffix(conf));
    RemoteIterator<FileStatus> nodeFiles;
    try {
        Path qualifiedLogDir = FileContext.getFileContext(conf).makeQualified(remoteAppDir);
        nodeFiles = FileContext.getFileContext(qualifiedLogDir.toUri(), conf).listStatus(remoteAppDir);
    } catch (FileNotFoundException fnf) {
        html.h1()._("Logs not available for " + logEntity + ". Aggregation may not be complete, " + "Check back later or try the nodemanager at " + nodeId)._();
        if (nmApplicationLogUrl != null) {
            html.h1()._("Or see application log at " + nmApplicationLogUrl)._();
        }
        return;
    } catch (Exception ex) {
        html.h1()._("Error getting logs at " + nodeId)._();
        return;
    }
    boolean foundLog = false;
    String desiredLogType = $(CONTAINER_LOG_TYPE);
    try {
        while (nodeFiles.hasNext()) {
            AggregatedLogFormat.LogReader reader = null;
            try {
                FileStatus thisNodeFile = nodeFiles.next();
                if (thisNodeFile.getPath().getName().equals(applicationId + ".har")) {
                    Path p = new Path("har:///" + thisNodeFile.getPath().toUri().getRawPath());
                    nodeFiles = HarFs.get(p.toUri(), conf).listStatusIterator(p);
                    continue;
                }
                if (!thisNodeFile.getPath().getName().contains(LogAggregationUtils.getNodeString(nodeId)) || thisNodeFile.getPath().getName().endsWith(LogAggregationUtils.TMP_FILE_SUFFIX)) {
                    continue;
                }
                long logUploadedTime = thisNodeFile.getModificationTime();
                reader = new AggregatedLogFormat.LogReader(conf, thisNodeFile.getPath());
                String owner = null;
                Map<ApplicationAccessType, String> appAcls = null;
                try {
                    owner = reader.getApplicationOwner();
                    appAcls = reader.getApplicationAcls();
                } catch (IOException e) {
                    LOG.error("Error getting logs for " + logEntity, e);
                    continue;
                }
                ApplicationACLsManager aclsManager = new ApplicationACLsManager(conf);
                aclsManager.addApplication(applicationId, appAcls);
                String remoteUser = request().getRemoteUser();
                UserGroupInformation callerUGI = null;
                if (remoteUser != null) {
                    callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
                }
                if (callerUGI != null && !aclsManager.checkAccess(callerUGI, ApplicationAccessType.VIEW_APP, owner, applicationId)) {
                    html.h1()._("User [" + remoteUser + "] is not authorized to view the logs for " + logEntity + " in log file [" + thisNodeFile.getPath().getName() + "]")._();
                    LOG.error("User [" + remoteUser + "] is not authorized to view the logs for " + logEntity);
                    continue;
                }
                AggregatedLogFormat.ContainerLogsReader logReader = reader.getContainerLogsReader(containerId);
                if (logReader == null) {
                    continue;
                }
                foundLog = readContainerLogs(html, logReader, logLimits, desiredLogType, logUploadedTime);
            } catch (IOException ex) {
                LOG.error("Error getting logs for " + logEntity, ex);
                continue;
            } finally {
                if (reader != null)
                    reader.close();
            }
        }
        if (!foundLog) {
            if (desiredLogType.isEmpty()) {
                html.h1("No logs available for container " + containerId.toString());
            } else {
                html.h1("Unable to locate '" + desiredLogType + "' log for container " + containerId.toString());
            }
        }
    } catch (IOException e) {
        html.h1()._("Error getting logs for " + logEntity)._();
        LOG.error("Error getting logs for " + logEntity, e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AggregatedLogFormat(org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ApplicationAccessType(org.apache.hadoop.yarn.api.records.ApplicationAccessType) NodeId(org.apache.hadoop.yarn.api.records.NodeId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

ApplicationAccessType (org.apache.hadoop.yarn.api.records.ApplicationAccessType)64 Test (org.junit.Test)32 HashMap (java.util.HashMap)27 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)24 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)23 Credentials (org.apache.hadoop.security.Credentials)19 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)19 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)18 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)17 ByteBuffer (java.nio.ByteBuffer)14 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)14 ArrayList (java.util.ArrayList)13 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)12 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)11 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)10 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)10 Path (org.apache.hadoop.fs.Path)9 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)9 ApplicationSubmissionContext (org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext)9 MemoryRMStateStore (org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore)9