Search in sources :

Example 51 with Private

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

the class NMContainerTokenSecretManager method setMasterKey.

/**
   * Used by NodeManagers to create a token-secret-manager with the key obtained
   * from the RM. This can happen during registration or when the RM rolls the
   * master-key and signals the NM.
   * 
   * @param masterKeyRecord
   */
@Private
public synchronized void setMasterKey(MasterKey masterKeyRecord) {
    // Update keys only if the key has changed.
    if (super.currentMasterKey == null || super.currentMasterKey.getMasterKey().getKeyId() != masterKeyRecord.getKeyId()) {
        LOG.info("Rolling master-key for container-tokens, got key with id " + masterKeyRecord.getKeyId());
        if (super.currentMasterKey != null) {
            updatePreviousMasterKey(super.currentMasterKey);
        }
        updateCurrentMasterKey(new MasterKeyData(masterKeyRecord, createSecretKey(masterKeyRecord.getBytes().array())));
    }
}
Also used : MasterKeyData(org.apache.hadoop.yarn.server.security.MasterKeyData) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 52 with Private

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

the class ClientRMService method getApplications.

/**
   * Get applications matching the {@link GetApplicationsRequest}. If
   * caseSensitive is set to false, applicationTypes in
   * GetApplicationRequest are expected to be in all-lowercase
   */
@Private
public GetApplicationsResponse getApplications(GetApplicationsRequest request, boolean caseSensitive) throws YarnException {
    UserGroupInformation callerUGI;
    try {
        callerUGI = UserGroupInformation.getCurrentUser();
    } catch (IOException ie) {
        LOG.info("Error getting UGI ", ie);
        throw RPCUtil.getRemoteException(ie);
    }
    Set<String> applicationTypes = request.getApplicationTypes();
    EnumSet<YarnApplicationState> applicationStates = request.getApplicationStates();
    Set<String> users = request.getUsers();
    Set<String> queues = request.getQueues();
    Set<String> tags = request.getApplicationTags();
    long limit = request.getLimit();
    LongRange start = request.getStartRange();
    LongRange finish = request.getFinishRange();
    ApplicationsRequestScope scope = request.getScope();
    final Map<ApplicationId, RMApp> apps = rmContext.getRMApps();
    Iterator<RMApp> appsIter;
    // of those queues by asking the scheduler for the apps in those queues.
    if (queues != null && !queues.isEmpty()) {
        // Construct an iterator over apps in given queues
        // Collect list of lists to avoid copying all apps
        final List<List<ApplicationAttemptId>> queueAppLists = new ArrayList<List<ApplicationAttemptId>>();
        for (String queue : queues) {
            List<ApplicationAttemptId> appsInQueue = scheduler.getAppsInQueue(queue);
            if (appsInQueue != null && !appsInQueue.isEmpty()) {
                queueAppLists.add(appsInQueue);
            }
        }
        appsIter = new Iterator<RMApp>() {

            Iterator<List<ApplicationAttemptId>> appListIter = queueAppLists.iterator();

            Iterator<ApplicationAttemptId> schedAppsIter;

            @Override
            public boolean hasNext() {
                // current list hasNext or whether there are any remaining lists
                return (schedAppsIter != null && schedAppsIter.hasNext()) || appListIter.hasNext();
            }

            @Override
            public RMApp next() {
                if (schedAppsIter == null || !schedAppsIter.hasNext()) {
                    schedAppsIter = appListIter.next().iterator();
                }
                return apps.get(schedAppsIter.next().getApplicationId());
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("Remove not supported");
            }
        };
    } else {
        appsIter = apps.values().iterator();
    }
    List<ApplicationReport> reports = new ArrayList<ApplicationReport>();
    while (appsIter.hasNext() && reports.size() < limit) {
        RMApp application = appsIter.next();
        // Check if current application falls under the specified scope
        if (scope == ApplicationsRequestScope.OWN && !callerUGI.getUserName().equals(application.getUser())) {
            continue;
        }
        if (applicationTypes != null && !applicationTypes.isEmpty()) {
            String appTypeToMatch = caseSensitive ? application.getApplicationType() : StringUtils.toLowerCase(application.getApplicationType());
            if (!applicationTypes.contains(appTypeToMatch)) {
                continue;
            }
        }
        if (applicationStates != null && !applicationStates.isEmpty()) {
            if (!applicationStates.contains(application.createApplicationState())) {
                continue;
            }
        }
        if (users != null && !users.isEmpty() && !users.contains(application.getUser())) {
            continue;
        }
        if (start != null && !start.containsLong(application.getStartTime())) {
            continue;
        }
        if (finish != null && !finish.containsLong(application.getFinishTime())) {
            continue;
        }
        if (tags != null && !tags.isEmpty()) {
            Set<String> appTags = application.getApplicationTags();
            if (appTags == null || appTags.isEmpty()) {
                continue;
            }
            boolean match = false;
            for (String tag : tags) {
                if (appTags.contains(tag)) {
                    match = true;
                    break;
                }
            }
            if (!match) {
                continue;
            }
        }
        // checkAccess can grab the scheduler lock so call it last
        boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application);
        if (scope == ApplicationsRequestScope.VIEWABLE && !allowAccess) {
            continue;
        }
        reports.add(application.createAndGetApplicationReport(callerUGI.getUserName(), allowAccess));
    }
    GetApplicationsResponse response = recordFactory.newRecordInstance(GetApplicationsResponse.class);
    response.setApplicationList(reports);
    return response;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) ArrayList(java.util.ArrayList) LongRange(org.apache.commons.lang.math.LongRange) ArrayList(java.util.ArrayList) List(java.util.List) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) ApplicationsRequestScope(org.apache.hadoop.yarn.api.protocolrecords.ApplicationsRequestScope) IOException(java.io.IOException) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) 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