Exemplo n.º 1
0
 // Create container token and NMToken altogether, if either of them fails for
 // some reason like DNS unavailable, do not return this container and keep it
 // in the newlyAllocatedContainers waiting to be refetched.
 public virtual SchedulerApplicationAttempt.ContainersAndNMTokensAllocation PullNewlyAllocatedContainersAndNMTokens
     ()
 {
     lock (this)
     {
         IList <Container> returnContainerList = new AList <Container>(newlyAllocatedContainers
                                                                       .Count);
         IList <NMToken> nmTokens = new AList <NMToken>();
         for (IEnumerator <RMContainer> i = newlyAllocatedContainers.GetEnumerator(); i.HasNext
                  ();)
         {
             RMContainer rmContainer = i.Next();
             Container   container   = rmContainer.GetContainer();
             try
             {
                 // create container token and NMToken altogether.
                 container.SetContainerToken(rmContext.GetContainerTokenSecretManager().CreateContainerToken
                                                 (container.GetId(), container.GetNodeId(), GetUser(), container.GetResource(), container
                                                 .GetPriority(), rmContainer.GetCreationTime(), this.logAggregationContext));
                 NMToken nmToken = rmContext.GetNMTokenSecretManager().CreateAndGetNMToken(GetUser
                                                                                               (), GetApplicationAttemptId(), container);
                 if (nmToken != null)
                 {
                     nmTokens.AddItem(nmToken);
                 }
             }
             catch (ArgumentException e)
             {
                 // DNS might be down, skip returning this container.
                 Log.Error("Error trying to assign container token and NM token to" + " an allocated container "
                           + container.GetId(), e);
                 continue;
             }
             returnContainerList.AddItem(container);
             i.Remove();
             rmContainer.Handle(new RMContainerEvent(rmContainer.GetContainerId(), RMContainerEventType
                                                     .Acquired));
         }
         return(new SchedulerApplicationAttempt.ContainersAndNMTokensAllocation(returnContainerList
                                                                                , nmTokens));
     }
 }