Ejemplo n.º 1
0
            /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
            public virtual StartContainersResponse StartContainers(StartContainersRequest requests
                                                                   )
            {
                StartContainersResponse response = TestRPC.recordFactory.NewRecordInstance <StartContainersResponse
                                                                                            >();

                foreach (StartContainerRequest request in requests.GetStartContainerRequests())
                {
                    Token containerToken             = request.GetContainerToken();
                    ContainerTokenIdentifier tokenId = null;
                    try
                    {
                        tokenId = TestRPC.NewContainerTokenIdentifier(containerToken);
                    }
                    catch (IOException e)
                    {
                        throw RPCUtil.GetRemoteException(e);
                    }
                    ContainerStatus status = TestRPC.recordFactory.NewRecordInstance <ContainerStatus>
                                                 ();
                    status.SetState(ContainerState.Running);
                    status.SetContainerId(tokenId.GetContainerID());
                    status.SetExitStatus(0);
                    this.statuses.AddItem(status);
                }
                return(response);
            }
            /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
            public StartContainersResponse StartContainers(StartContainersRequest requests)
            {
                StartContainerRequest request = requests.GetStartContainerRequests()[0];

                Log.Info("Container started by MyContainerManager: " + request);
                launched = true;
                IDictionary <string, string> env = request.GetContainerLaunchContext().GetEnvironment
                                                       ();
                Token containerToken             = request.GetContainerToken();
                ContainerTokenIdentifier tokenId = null;

                try
                {
                    tokenId = BuilderUtils.NewContainerTokenIdentifier(containerToken);
                }
                catch (IOException e)
                {
                    throw RPCUtil.GetRemoteException(e);
                }
                ContainerId containerId = tokenId.GetContainerID();

                containerIdAtContainerManager = containerId.ToString();
                attemptIdAtContainerManager   = containerId.GetApplicationAttemptId().ToString();
                nmHostAtContainerManager      = tokenId.GetNmHostAddress();
                submitTimeAtContainerManager  = long.Parse(env[ApplicationConstants.AppSubmitTimeEnv
                                                           ]);
                maxAppAttempts = System.Convert.ToInt32(env[ApplicationConstants.MaxAppAttemptsEnv
                                                        ]);
                return(StartContainersResponse.NewInstance(new Dictionary <string, ByteBuffer>(),
                                                           new AList <ContainerId>(), new Dictionary <ContainerId, SerializedException>()));
            }
Ejemplo n.º 3
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual UseSharedCacheResourceResponse Use(UseSharedCacheResourceRequest request
                                                          )
        {
            UseSharedCacheResourceResponse response = recordFactory.NewRecordInstance <UseSharedCacheResourceResponse
                                                                                       >();
            UserGroupInformation callerUGI;

            try
            {
                callerUGI = UserGroupInformation.GetCurrentUser();
            }
            catch (IOException ie)
            {
                Log.Info("Error getting UGI ", ie);
                throw RPCUtil.GetRemoteException(ie);
            }
            string fileName = this.store.AddResourceReference(request.GetResourceKey(), new SharedCacheResourceReference
                                                                  (request.GetAppId(), callerUGI.GetShortUserName()));

            if (fileName != null)
            {
                response.SetPath(GetCacheEntryFilePath(request.GetResourceKey(), fileName));
                this.metrics.IncCacheHitCount();
            }
            else
            {
                this.metrics.IncCacheMissCount();
            }
            return(response);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Quick validation on the input to check some obvious fail conditions (fail
        /// fast) the input and returns the appropriate
        /// <see cref="Plan"/>
        /// associated with
        /// the specified
        /// <see cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Scheduler.Queue"/>
        /// or throws an exception message illustrating the
        /// details of any validation check failures
        /// </summary>
        /// <param name="reservationSystem">
        /// the
        /// <see cref="ReservationSystem"/>
        /// to validate against
        /// </param>
        /// <param name="request">
        /// the
        /// <see cref="Org.Apache.Hadoop.Yarn.Api.Protocolrecords.ReservationSubmissionRequest
        ///     "/>
        /// defining the
        /// resources required over time for the request
        /// </param>
        /// <param name="reservationId">
        /// the
        /// <see cref="Org.Apache.Hadoop.Yarn.Api.Records.ReservationId"/>
        /// associated with the current
        /// request
        /// </param>
        /// <returns>
        /// the
        /// <see cref="Plan"/>
        /// to submit the request to
        /// </returns>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        public virtual Plan ValidateReservationSubmissionRequest(ReservationSystem reservationSystem
                                                                 , ReservationSubmissionRequest request, ReservationId reservationId)
        {
            // Check if it is a managed queue
            string queueName = request.GetQueue();

            if (queueName == null || queueName.IsEmpty())
            {
                string errMsg = "The queue to submit is not specified." + " Please try again with a valid reservable queue.";
                RMAuditLogger.LogFailure("UNKNOWN", RMAuditLogger.AuditConstants.SubmitReservationRequest
                                         , "validate reservation input", "ClientRMService", errMsg);
                throw RPCUtil.GetRemoteException(errMsg);
            }
            Plan plan = reservationSystem.GetPlan(queueName);

            if (plan == null)
            {
                string errMsg = "The specified queue: " + queueName + " is not managed by reservation system."
                                + " Please try again with a valid reservable queue.";
                RMAuditLogger.LogFailure("UNKNOWN", RMAuditLogger.AuditConstants.SubmitReservationRequest
                                         , "validate reservation input", "ClientRMService", errMsg);
                throw RPCUtil.GetRemoteException(errMsg);
            }
            ValidateReservationDefinition(reservationId, request.GetReservationDefinition(),
                                          plan, RMAuditLogger.AuditConstants.SubmitReservationRequest);
            return(plan);
        }
Ejemplo n.º 5
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private Plan ValidateReservation(ReservationSystem reservationSystem, ReservationId
                                         reservationId, string auditConstant)
        {
            string message = string.Empty;

            // check if the reservation id is valid
            if (reservationId == null)
            {
                message = "Missing reservation id." + " Please try again by specifying a reservation id.";
                RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input",
                                         "ClientRMService", message);
                throw RPCUtil.GetRemoteException(message);
            }
            string queueName = reservationSystem.GetQueueForReservation(reservationId);

            if (queueName == null)
            {
                message = "The specified reservation with ID: " + reservationId + " is unknown. Please try again with a valid reservation.";
                RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input",
                                         "ClientRMService", message);
                throw RPCUtil.GetRemoteException(message);
            }
            // check if the associated plan is valid
            Plan plan = reservationSystem.GetPlan(queueName);

            if (plan == null)
            {
                message = "The specified reservation: " + reservationId + " is not associated with any valid plan."
                          + " Please try again with a valid reservation.";
                RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input",
                                         "ClientRMService", message);
                throw RPCUtil.GetRemoteException(message);
            }
            return(plan);
        }
Ejemplo n.º 6
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 public virtual StopContainersResponse StopContainers(StopContainersRequest request
                                                      )
 {
     lock (this)
     {
         foreach (ContainerId containerID in request.GetContainerIds())
         {
             string applicationId = containerID.GetApplicationAttemptId().GetApplicationId().GetId
                                        ().ToString();
             // Mark the container as COMPLETE
             IList <Container> applicationContainers = containers[containerID.GetApplicationAttemptId
                                                                      ().GetApplicationId()];
             foreach (Container c in applicationContainers)
             {
                 if (c.GetId().CompareTo(containerID) == 0)
                 {
                     ContainerStatus containerStatus = containerStatusMap[c];
                     containerStatus.SetState(ContainerState.Complete);
                     containerStatusMap[c] = containerStatus;
                 }
             }
             // Send a heartbeat
             try
             {
                 Heartbeat();
             }
             catch (IOException ioe)
             {
                 throw RPCUtil.GetRemoteException(ioe);
             }
             // Remove container and update status
             int       ctr       = 0;
             Container container = null;
             for (IEnumerator <Container> i = applicationContainers.GetEnumerator(); i.HasNext(
                      );)
             {
                 container = i.Next();
                 if (container.GetId().CompareTo(containerID) == 0)
                 {
                     i.Remove();
                     ++ctr;
                 }
             }
             if (ctr != 1)
             {
                 throw new InvalidOperationException("Container " + containerID + " stopped " + ctr
                                                     + " times!");
             }
             Resources.AddTo(available, container.GetResource());
             Resources.SubtractFrom(used, container.GetResource());
             if (Log.IsDebugEnabled())
             {
                 Log.Debug("stopContainer:" + " node=" + containerManagerAddress + " application="
                           + applicationId + " container=" + containerID + " available=" + available + " used="
                           + used);
             }
         }
         return(StopContainersResponse.NewInstance(null, null));
     }
 }
Ejemplo n.º 7
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual ReleaseSharedCacheResourceResponse Release(ReleaseSharedCacheResourceRequest
                                                                  request)
        {
            ReleaseSharedCacheResourceResponse response = recordFactory.NewRecordInstance <ReleaseSharedCacheResourceResponse
                                                                                           >();
            UserGroupInformation callerUGI;

            try
            {
                callerUGI = UserGroupInformation.GetCurrentUser();
            }
            catch (IOException ie)
            {
                Log.Info("Error getting UGI ", ie);
                throw RPCUtil.GetRemoteException(ie);
            }
            bool removed = this.store.RemoveResourceReference(request.GetResourceKey(), new SharedCacheResourceReference
                                                                  (request.GetAppId(), callerUGI.GetShortUserName()), true);

            if (removed)
            {
                this.metrics.IncCacheRelease();
            }
            return(response);
        }
Ejemplo n.º 8
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 private YarnException LogAndWrapException(IOException ioe, string user, string argName
                                           , string msg)
 {
     Log.Info("Exception " + msg, ioe);
     RMAuditLogger.LogFailure(user, argName, string.Empty, "AdminService", "Exception "
                              + msg);
     return(RPCUtil.GetRemoteException(ioe));
 }
Ejemplo n.º 9
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual UpdateNodeResourceResponse UpdateNodeResource(UpdateNodeResourceRequest
                                                                     request)
        {
            string argName            = "updateNodeResource";
            UserGroupInformation user = CheckAcls(argName);

            CheckRMStatus(user.GetShortUserName(), argName, "update node resource.");
            IDictionary <NodeId, ResourceOption> nodeResourceMap = request.GetNodeResourceMap(
                );
            ICollection <NodeId> nodeIds = nodeResourceMap.Keys;

            // verify nodes are all valid first.
            // if any invalid nodes, throw exception instead of partially updating
            // valid nodes.
            foreach (NodeId nodeId in nodeIds)
            {
                RMNode node = this.rmContext.GetRMNodes()[nodeId];
                if (node == null)
                {
                    Log.Error("Resource update get failed on all nodes due to change " + "resource on an unrecognized node: "
                              + nodeId);
                    throw RPCUtil.GetRemoteException("Resource update get failed on all nodes due to change resource "
                                                     + "on an unrecognized node: " + nodeId);
                }
            }
            // do resource update on each node.
            // Notice: it is still possible to have invalid NodeIDs as nodes decommission
            // may happen just at the same time. This time, only log and skip absent
            // nodes without throwing any exceptions.
            bool allSuccess = true;

            foreach (KeyValuePair <NodeId, ResourceOption> entry in nodeResourceMap)
            {
                ResourceOption newResourceOption = entry.Value;
                NodeId         nodeId_1          = entry.Key;
                RMNode         node = this.rmContext.GetRMNodes()[nodeId_1];
                if (node == null)
                {
                    Log.Warn("Resource update get failed on an unrecognized node: " + nodeId_1);
                    allSuccess = false;
                }
                else
                {
                    // update resource to RMNode
                    this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMNodeResourceUpdateEvent
                                                                                (nodeId_1, newResourceOption));
                    Log.Info("Update resource on node(" + node.GetNodeID() + ") with resource(" + newResourceOption
                             .ToString() + ")");
                }
            }
            if (allSuccess)
            {
                RMAuditLogger.LogSuccess(user.GetShortUserName(), argName, "AdminService");
            }
            UpdateNodeResourceResponse response = UpdateNodeResourceResponse.NewInstance();

            return(response);
        }
Ejemplo n.º 10
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 public virtual StartContainersResponse StartContainers(StartContainersRequest requests
                                                        )
 {
     lock (this)
     {
         foreach (StartContainerRequest request in requests.GetStartContainerRequests())
         {
             Token containerToken             = request.GetContainerToken();
             ContainerTokenIdentifier tokenId = null;
             try
             {
                 tokenId = BuilderUtils.NewContainerTokenIdentifier(containerToken);
             }
             catch (IOException e)
             {
                 throw RPCUtil.GetRemoteException(e);
             }
             ContainerId   containerID   = tokenId.GetContainerID();
             ApplicationId applicationId = containerID.GetApplicationAttemptId().GetApplicationId
                                               ();
             IList <Container> applicationContainers = containers[applicationId];
             if (applicationContainers == null)
             {
                 applicationContainers     = new AList <Container>();
                 containers[applicationId] = applicationContainers;
             }
             // Sanity check
             foreach (Container container in applicationContainers)
             {
                 if (container.GetId().CompareTo(containerID) == 0)
                 {
                     throw new InvalidOperationException("Container " + containerID + " already setup on node "
                                                         + containerManagerAddress);
                 }
             }
             Container container_1 = BuilderUtils.NewContainer(containerID, this.nodeId, nodeHttpAddress
                                                               , tokenId.GetResource(), null, null);
             // DKDC - Doesn't matter
             ContainerStatus containerStatus = BuilderUtils.NewContainerStatus(container_1.GetId
                                                                                   (), ContainerState.New, string.Empty, -1000);
             applicationContainers.AddItem(container_1);
             containerStatusMap[container_1] = containerStatus;
             Resources.SubtractFrom(available, tokenId.GetResource());
             Resources.AddTo(used, tokenId.GetResource());
             if (Log.IsDebugEnabled())
             {
                 Log.Debug("startContainer:" + " node=" + containerManagerAddress + " application="
                           + applicationId + " container=" + container_1 + " available=" + available + " used="
                           + used);
             }
         }
         StartContainersResponse response = StartContainersResponse.NewInstance(null, null
                                                                                , null);
         return(response);
     }
 }
Ejemplo n.º 11
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 private void AddStartingContainer(NMClientImpl.StartedContainer startedContainer)
 {
     if (startedContainers.PutIfAbsent(startedContainer.containerId, startedContainer)
         != null)
     {
         throw RPCUtil.GetRemoteException("Container " + startedContainer.containerId.ToString
                                              () + " is already started");
     }
     startedContainers[startedContainer.GetContainerId()] = startedContainer;
 }
Ejemplo n.º 12
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 private UserGroupInformation CheckAcls(string method)
 {
     try
     {
         return(CheckAccess(method));
     }
     catch (IOException ioe)
     {
         throw RPCUtil.GetRemoteException(ioe);
     }
 }
Ejemplo n.º 13
0
        public virtual void TestRMConnectionRetry()
        {
            // verify the connection exception is thrown
            // if we haven't exhausted the retry interval
            ApplicationMasterProtocol mockScheduler = Org.Mockito.Mockito.Mock <ApplicationMasterProtocol
                                                                                >();

            Org.Mockito.Mockito.When(mockScheduler.Allocate(Matchers.IsA <AllocateRequest>()))
            .ThenThrow(RPCUtil.GetRemoteException(new IOException("forcefail")));
            Configuration           conf = new Configuration();
            LocalContainerAllocator lca  = new TestLocalContainerAllocator.StubbedLocalContainerAllocator
                                               (mockScheduler);

            lca.Init(conf);
            lca.Start();
            try
            {
                lca.Heartbeat();
                NUnit.Framework.Assert.Fail("heartbeat was supposed to throw");
            }
            catch (YarnException)
            {
            }
            finally
            {
                // YarnException is expected
                lca.Stop();
            }
            // verify YarnRuntimeException is thrown when the retry interval has expired
            conf.SetLong(MRJobConfig.MrAmToRmWaitIntervalMs, 0);
            lca = new TestLocalContainerAllocator.StubbedLocalContainerAllocator(mockScheduler
                                                                                 );
            lca.Init(conf);
            lca.Start();
            try
            {
                lca.Heartbeat();
                NUnit.Framework.Assert.Fail("heartbeat was supposed to throw");
            }
            catch (YarnRuntimeException)
            {
            }
            finally
            {
                // YarnRuntimeException is expected
                lca.Stop();
            }
        }
Ejemplo n.º 14
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private AMRMTokenIdentifier AuthorizeRequest()
        {
            UserGroupInformation remoteUgi;

            try
            {
                remoteUgi = UserGroupInformation.GetCurrentUser();
            }
            catch (IOException e)
            {
                string msg = "Cannot obtain the user-name for authorizing ApplicationMaster. " +
                             "Got exception: " + StringUtils.StringifyException(e);
                Log.Warn(msg);
                throw RPCUtil.GetRemoteException(msg);
            }
            bool   tokenFound = false;
            string message    = string.Empty;
            AMRMTokenIdentifier appTokenIdentifier = null;

            try
            {
                appTokenIdentifier = SelectAMRMTokenIdentifier(remoteUgi);
                if (appTokenIdentifier == null)
                {
                    tokenFound = false;
                    message    = "No AMRMToken found for user " + remoteUgi.GetUserName();
                }
                else
                {
                    tokenFound = true;
                }
            }
            catch (IOException)
            {
                tokenFound = false;
                message    = "Got exception while looking for AMRMToken for user " + remoteUgi.GetUserName
                                 ();
            }
            if (!tokenFound)
            {
                Log.Warn(message);
                throw RPCUtil.GetRemoteException(message);
            }
            return(appTokenIdentifier);
        }
Ejemplo n.º 15
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        private NMClient MockNMClient(int mode)
        {
            NMClient client = Org.Mockito.Mockito.Mock <NMClient>();

            switch (mode)
            {
            case 0:
            {
                Org.Mockito.Mockito.When(client.StartContainer(Matchers.Any <Container>(), Matchers.Any
                                                               <ContainerLaunchContext>())).ThenReturn(Sharpen.Collections.EmptyMap <string, ByteBuffer
                                                                                                                                     >());
                Org.Mockito.Mockito.When(client.GetContainerStatus(Matchers.Any <ContainerId>(), Matchers.Any
                                                                   <NodeId>())).ThenReturn(recordFactory.NewRecordInstance <ContainerStatus>());
                Org.Mockito.Mockito.DoNothing().When(client).StopContainer(Matchers.Any <ContainerId
                                                                                         >(), Matchers.Any <NodeId>());
                break;
            }

            case 1:
            {
                Org.Mockito.Mockito.DoThrow(RPCUtil.GetRemoteException("Start Exception")).When(client
                                                                                                ).StartContainer(Matchers.Any <Container>(), Matchers.Any <ContainerLaunchContext>
                                                                                                                     ());
                Org.Mockito.Mockito.DoThrow(RPCUtil.GetRemoteException("Query Exception")).When(client
                                                                                                ).GetContainerStatus(Matchers.Any <ContainerId>(), Matchers.Any <NodeId>());
                Org.Mockito.Mockito.DoThrow(RPCUtil.GetRemoteException("Stop Exception")).When(client
                                                                                               ).StopContainer(Matchers.Any <ContainerId>(), Matchers.Any <NodeId>());
                break;
            }

            case 2:
            {
                Org.Mockito.Mockito.When(client.StartContainer(Matchers.Any <Container>(), Matchers.Any
                                                               <ContainerLaunchContext>())).ThenReturn(Sharpen.Collections.EmptyMap <string, ByteBuffer
                                                                                                                                     >());
                Org.Mockito.Mockito.When(client.GetContainerStatus(Matchers.Any <ContainerId>(), Matchers.Any
                                                                   <NodeId>())).ThenReturn(recordFactory.NewRecordInstance <ContainerStatus>());
                Org.Mockito.Mockito.DoThrow(RPCUtil.GetRemoteException("Stop Exception")).When(client
                                                                                               ).StopContainer(Matchers.Any <ContainerId>(), Matchers.Any <NodeId>());
                break;
            }
            }
            return(client);
        }
Ejemplo n.º 16
0
 public override void StopContainerAsync(ContainerId containerId, NodeId nodeId)
 {
     if (containers[containerId] == null)
     {
         callbackHandler.OnStopContainerError(containerId, RPCUtil.GetRemoteException("Container "
                                                                                      + containerId + " is neither started nor scheduled to start"));
     }
     try
     {
         events.Put(new NMClientAsyncImpl.ContainerEvent(containerId, nodeId, null, NMClientAsyncImpl.ContainerEventType
                                                         .StopContainer));
     }
     catch (Exception e)
     {
         Log.Warn("Exception when scheduling the event of stopping Container " + containerId
                  );
         callbackHandler.OnStopContainerError(containerId, e);
     }
 }
Ejemplo n.º 17
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private void CheckAcls(string method)
        {
            UserGroupInformation user;

            try
            {
                user = UserGroupInformation.GetCurrentUser();
            }
            catch (IOException ioe)
            {
                Log.Warn("Couldn't get current user", ioe);
                throw RPCUtil.GetRemoteException(ioe);
            }
            if (!authorizer.IsAdmin(user))
            {
                Log.Warn("User " + user.GetShortUserName() + " doesn't have permission" + " to call '"
                         + method + "'");
                throw RPCUtil.GetRemoteException(new AccessControlException("User " + user.GetShortUserName
                                                                                () + " doesn't have permission" + " to call '" + method + "'"));
            }
            Log.Info("SCM Admin: " + method + " invoked by user " + user.GetShortUserName());
        }
Ejemplo n.º 18
0
 public override void StartContainerAsync(Container container, ContainerLaunchContext
                                          containerLaunchContext)
 {
     if (containers.PutIfAbsent(container.GetId(), new NMClientAsyncImpl.StatefulContainer
                                    (this, container.GetId())) != null)
     {
         callbackHandler.OnStartContainerError(container.GetId(), RPCUtil.GetRemoteException
                                                   ("Container " + container.GetId() + " is already started or scheduled to start")
                                               );
     }
     try
     {
         events.Put(new NMClientAsyncImpl.StartContainerEvent(container, containerLaunchContext
                                                              ));
     }
     catch (Exception e)
     {
         Log.Warn("Exception when scheduling the event of starting Container " + container
                  .GetId());
         callbackHandler.OnStartContainerError(container.GetId(), e);
     }
 }
Ejemplo n.º 19
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        protected internal virtual void SubmitApplication(ApplicationSubmissionContext submissionContext
                                                          , long submitTime, string user)
        {
            ApplicationId applicationId = submissionContext.GetApplicationId();
            RMAppImpl     application   = CreateAndPopulateNewRMApp(submissionContext, submitTime,
                                                                    user, false);
            ApplicationId appId = submissionContext.GetApplicationId();

            if (UserGroupInformation.IsSecurityEnabled())
            {
                try
                {
                    this.rmContext.GetDelegationTokenRenewer().AddApplicationAsync(appId, ParseCredentials
                                                                                       (submissionContext), submissionContext.GetCancelTokensWhenComplete(), application
                                                                                   .GetUser());
                }
                catch (Exception e)
                {
                    Log.Warn("Unable to parse credentials.", e);
                    // Sending APP_REJECTED is fine, since we assume that the
                    // RMApp is in NEW state and thus we haven't yet informed the
                    // scheduler about the existence of the application
                    System.Diagnostics.Debug.Assert(application.GetState() == RMAppState.New);
                    this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMAppEvent(applicationId
                                                                                           , RMAppEventType.AppRejected, e.Message));
                    throw RPCUtil.GetRemoteException(e);
                }
            }
            else
            {
                // Dispatcher is not yet started at this time, so these START events
                // enqueued should be guaranteed to be first processed when dispatcher
                // gets started.
                this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMAppEvent(applicationId
                                                                                       , RMAppEventType.Start));
            }
        }
Ejemplo n.º 20
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual RefreshServiceAclsResponse RefreshServiceAcls(RefreshServiceAclsRequest
                                                                     request)
        {
            if (!GetConfig().GetBoolean(CommonConfigurationKeysPublic.HadoopSecurityAuthorization
                                        , false))
            {
                throw RPCUtil.GetRemoteException(new IOException("Service Authorization (" + CommonConfigurationKeysPublic
                                                                 .HadoopSecurityAuthorization + ") not enabled."));
            }
            string argName            = "refreshServiceAcls";
            UserGroupInformation user = CheckAcls(argName);

            CheckRMStatus(user.GetShortUserName(), argName, "refresh Service ACLs.");
            PolicyProvider policyProvider = RMPolicyProvider.GetInstance();
            Configuration  conf           = GetConfiguration(new Configuration(false), YarnConfiguration
                                                             .HadoopPolicyConfigurationFile);

            RefreshServiceAcls(conf, policyProvider);
            rmContext.GetClientRMService().RefreshServiceAcls(conf, policyProvider);
            rmContext.GetApplicationMasterService().RefreshServiceAcls(conf, policyProvider);
            rmContext.GetResourceTrackerService().RefreshServiceAcls(conf, policyProvider);
            RMAuditLogger.LogSuccess(user.GetShortUserName(), argName, "AdminService");
            return(recordFactory.NewRecordInstance <RefreshServiceAclsResponse>());
        }
Ejemplo n.º 21
0
        public virtual int Call()
        {
            // dispatcher not typed
            ContainerLaunchContext launchContext = container.GetLaunchContext();
            IDictionary <Path, IList <string> > localResources = null;
            ContainerId    containerID    = container.GetContainerId();
            string         containerIdStr = ConverterUtils.ToString(containerID);
            IList <string> command        = launchContext.GetCommands();
            int            ret            = -1;

            // CONTAINER_KILLED_ON_REQUEST should not be missed if the container
            // is already at KILLING
            if (container.GetContainerState() == ContainerState.Killing)
            {
                dispatcher.GetEventHandler().Handle(new ContainerExitEvent(containerID, ContainerEventType
                                                                           .ContainerKilledOnRequest, Shell.Windows ? ContainerExecutor.ExitCode.ForceKilled
                                                                           .GetExitCode() : ContainerExecutor.ExitCode.Terminated.GetExitCode(), "Container terminated before launch."
                                                                           ));
                return(0);
            }
            try
            {
                localResources = container.GetLocalizedResources();
                if (localResources == null)
                {
                    throw RPCUtil.GetRemoteException("Unable to get local resources when Container "
                                                     + containerID + " is at " + container.GetContainerState());
                }
                string user = container.GetUser();
                // /////////////////////////// Variable expansion
                // Before the container script gets written out.
                IList <string> newCmds  = new AList <string>(command.Count);
                string         appIdStr = app.GetAppId().ToString();
                string         relativeContainerLogDir = Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Launcher.ContainerLaunch
                                                         .GetRelativeContainerLogDir(appIdStr, containerIdStr);
                Path containerLogDir = dirsHandler.GetLogPathForWrite(relativeContainerLogDir, false
                                                                      );
                foreach (string str in command)
                {
                    // TODO: Should we instead work via symlinks without this grammar?
                    newCmds.AddItem(ExpandEnvironment(str, containerLogDir));
                }
                launchContext.SetCommands(newCmds);
                IDictionary <string, string> environment = launchContext.GetEnvironment();
                // Make a copy of env to iterate & do variable expansion
                foreach (KeyValuePair <string, string> entry in environment)
                {
                    string value = entry.Value;
                    value = ExpandEnvironment(value, containerLogDir);
                    entry.SetValue(value);
                }
                // /////////////////////////// End of variable expansion
                FileContext lfs = FileContext.GetLocalFSFileContext();
                Path        nmPrivateContainerScriptPath = dirsHandler.GetLocalPathForWrite(GetContainerPrivateDir
                                                                                                (appIdStr, containerIdStr) + Path.Separator + ContainerScript);
                Path nmPrivateTokensPath = dirsHandler.GetLocalPathForWrite(GetContainerPrivateDir
                                                                                (appIdStr, containerIdStr) + Path.Separator + string.Format(ContainerLocalizer.TokenFileNameFmt
                                                                                                                                            , containerIdStr));
                Path nmPrivateClasspathJarDir = dirsHandler.GetLocalPathForWrite(GetContainerPrivateDir
                                                                                     (appIdStr, containerIdStr));
                DataOutputStream containerScriptOutStream = null;
                DataOutputStream tokensOutStream          = null;
                // Select the working directory for the container
                Path containerWorkDir = dirsHandler.GetLocalPathForWrite(ContainerLocalizer.Usercache
                                                                         + Path.Separator + user + Path.Separator + ContainerLocalizer.Appcache + Path.Separator
                                                                         + appIdStr + Path.Separator + containerIdStr, LocalDirAllocator.SizeUnknown, false
                                                                         );
                string pidFileSubpath = GetPidFileSubpath(appIdStr, containerIdStr);
                // pid file should be in nm private dir so that it is not
                // accessible by users
                pidFilePath = dirsHandler.GetLocalPathForWrite(pidFileSubpath);
                IList <string> localDirs        = dirsHandler.GetLocalDirs();
                IList <string> logDirs          = dirsHandler.GetLogDirs();
                IList <string> containerLogDirs = new AList <string>();
                foreach (string logDir in logDirs)
                {
                    containerLogDirs.AddItem(logDir + Path.Separator + relativeContainerLogDir);
                }
                if (!dirsHandler.AreDisksHealthy())
                {
                    ret = ContainerExitStatus.DisksFailed;
                    throw new IOException("Most of the disks failed. " + dirsHandler.GetDisksHealthReport
                                              (false));
                }
                try
                {
                    // /////////// Write out the container-script in the nmPrivate space.
                    IList <Path> appDirs = new AList <Path>(localDirs.Count);
                    foreach (string localDir in localDirs)
                    {
                        Path usersdir = new Path(localDir, ContainerLocalizer.Usercache);
                        Path userdir  = new Path(usersdir, user);
                        Path appsdir  = new Path(userdir, ContainerLocalizer.Appcache);
                        appDirs.AddItem(new Path(appsdir, appIdStr));
                    }
                    containerScriptOutStream = lfs.Create(nmPrivateContainerScriptPath, EnumSet.Of(CreateFlag
                                                                                                   .Create, CreateFlag.Overwrite));
                    // Set the token location too.
                    environment[ApplicationConstants.ContainerTokenFileEnvName] = new Path(containerWorkDir
                                                                                           , FinalContainerTokensFile).ToUri().GetPath();
                    // Sanitize the container's environment
                    SanitizeEnv(environment, containerWorkDir, appDirs, containerLogDirs, localResources
                                , nmPrivateClasspathJarDir);
                    // Write out the environment
                    exec.WriteLaunchEnv(containerScriptOutStream, environment, localResources, launchContext
                                        .GetCommands());
                    // /////////// End of writing out container-script
                    // /////////// Write out the container-tokens in the nmPrivate space.
                    tokensOutStream = lfs.Create(nmPrivateTokensPath, EnumSet.Of(CreateFlag.Create, CreateFlag
                                                                                 .Overwrite));
                    Credentials creds = container.GetCredentials();
                    creds.WriteTokenStorageToStream(tokensOutStream);
                }
                finally
                {
                    // /////////// End of writing out container-tokens
                    IOUtils.Cleanup(Log, containerScriptOutStream, tokensOutStream);
                }
                // LaunchContainer is a blocking call. We are here almost means the
                // container is launched, so send out the event.
                dispatcher.GetEventHandler().Handle(new ContainerEvent(containerID, ContainerEventType
                                                                       .ContainerLaunched));
                context.GetNMStateStore().StoreContainerLaunched(containerID);
                // Check if the container is signalled to be killed.
                if (!shouldLaunchContainer.CompareAndSet(false, true))
                {
                    Log.Info("Container " + containerIdStr + " not launched as " + "cleanup already called"
                             );
                    ret = ContainerExecutor.ExitCode.Terminated.GetExitCode();
                }
                else
                {
                    exec.ActivateContainer(containerID, pidFilePath);
                    ret = exec.LaunchContainer(container, nmPrivateContainerScriptPath, nmPrivateTokensPath
                                               , user, appIdStr, containerWorkDir, localDirs, logDirs);
                }
            }
            catch (Exception e)
            {
                Log.Warn("Failed to launch container.", e);
                dispatcher.GetEventHandler().Handle(new ContainerExitEvent(containerID, ContainerEventType
                                                                           .ContainerExitedWithFailure, ret, e.Message));
                return(ret);
            }
            finally
            {
                completed.Set(true);
                exec.DeactivateContainer(containerID);
                try
                {
                    context.GetNMStateStore().StoreContainerCompleted(containerID, ret);
                }
                catch (IOException)
                {
                    Log.Error("Unable to set exit code for container " + containerID);
                }
            }
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Container " + containerIdStr + " completed with exit code " + ret);
            }
            if (ret == ContainerExecutor.ExitCode.ForceKilled.GetExitCode() || ret == ContainerExecutor.ExitCode
                .Terminated.GetExitCode())
            {
                // If the process was killed, Send container_cleanedup_after_kill and
                // just break out of this method.
                dispatcher.GetEventHandler().Handle(new ContainerExitEvent(containerID, ContainerEventType
                                                                           .ContainerKilledOnRequest, ret, "Container exited with a non-zero exit code " +
                                                                           ret));
                return(ret);
            }
            if (ret != 0)
            {
                Log.Warn("Container exited with a non-zero exit code " + ret);
                this.dispatcher.GetEventHandler().Handle(new ContainerExitEvent(containerID, ContainerEventType
                                                                                .ContainerExitedWithFailure, ret, "Container exited with a non-zero exit code "
                                                                                + ret));
                return(ret);
            }
            Log.Info("Container " + containerIdStr + " succeeded ");
            dispatcher.GetEventHandler().Handle(new ContainerEvent(containerID, ContainerEventType
                                                                   .ContainerExitedWithSuccess));
            return(0);
        }
Ejemplo n.º 22
0
 public virtual void Transition(NMClientAsyncImpl.StatefulContainer container, NMClientAsyncImpl.ContainerEvent
                                @event)
 {
     try
     {
         container.nmClientAsync.GetCallbackHandler().OnStartContainerError(@event.GetContainerId
                                                                                (), RPCUtil.GetRemoteException(StopBeforeStartErrorMsg));
     }
     catch (Exception thr)
     {
         // Don't process user created unchecked exception
         Log.Info("Unchecked exception is thrown from onStartContainerError for " + "Container "
                  + @event.GetContainerId(), thr);
     }
 }
Ejemplo n.º 23
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 /// <exception cref="System.IO.IOException"/>
 public override IDictionary <string, ByteBuffer> StartContainer(Container container
                                                                 , ContainerLaunchContext containerLaunchContext)
 {
     // Do synchronization on StartedContainer to prevent race condition
     // between startContainer and stopContainer only when startContainer is
     // in progress for a given container.
     NMClientImpl.StartedContainer startingContainer = CreateStartedContainer(container
                                                                              );
     lock (startingContainer)
     {
         AddStartingContainer(startingContainer);
         IDictionary <string, ByteBuffer> allServiceResponse;
         ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null;
         try
         {
             proxy = cmProxy.GetProxy(container.GetNodeId().ToString(), container.GetId());
             StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                 , container.GetContainerToken());
             IList <StartContainerRequest> list = new AList <StartContainerRequest>();
             list.AddItem(scRequest);
             StartContainersRequest  allRequests = StartContainersRequest.NewInstance(list);
             StartContainersResponse response    = proxy.GetContainerManagementProtocol().StartContainers
                                                       (allRequests);
             if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains
                     (container.GetId()))
             {
                 Exception t = response.GetFailedRequests()[container.GetId()].DeSerialize();
                 ParseAndThrowException(t);
             }
             allServiceResponse      = response.GetAllServicesMetaData();
             startingContainer.state = ContainerState.Running;
         }
         catch (YarnException e)
         {
             startingContainer.state = ContainerState.Complete;
             // Remove the started container if it failed to start
             RemoveStartedContainer(startingContainer);
             throw;
         }
         catch (IOException e)
         {
             startingContainer.state = ContainerState.Complete;
             RemoveStartedContainer(startingContainer);
             throw;
         }
         catch (Exception t)
         {
             startingContainer.state = ContainerState.Complete;
             RemoveStartedContainer(startingContainer);
             throw RPCUtil.GetRemoteException(t);
         }
         finally
         {
             if (proxy != null)
             {
                 cmProxy.MayBeCloseProxy(proxy);
             }
         }
         return(allServiceResponse);
     }
 }
Ejemplo n.º 24
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private void ValidateReservationDefinition(ReservationId reservationId, ReservationDefinition
                                                   contract, Plan plan, string auditConstant)
        {
            string message = string.Empty;

            // check if deadline is in the past
            if (contract == null)
            {
                message = "Missing reservation definition." + " Please try again by specifying a reservation definition.";
                RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input definition"
                                         , "ClientRMService", message);
                throw RPCUtil.GetRemoteException(message);
            }
            if (contract.GetDeadline() <= clock.GetTime())
            {
                message = "The specified deadline: " + contract.GetDeadline() + " is the past. Please try again with deadline in the future.";
                RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input definition"
                                         , "ClientRMService", message);
                throw RPCUtil.GetRemoteException(message);
            }
            // Check if at least one RR has been specified
            ReservationRequests resReqs = contract.GetReservationRequests();

            if (resReqs == null)
            {
                message = "No resources have been specified to reserve." + "Please try again by specifying the resources to reserve.";
                RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input definition"
                                         , "ClientRMService", message);
                throw RPCUtil.GetRemoteException(message);
            }
            IList <ReservationRequest> resReq = resReqs.GetReservationResources();

            if (resReq == null || resReq.IsEmpty())
            {
                message = "No resources have been specified to reserve." + " Please try again by specifying the resources to reserve.";
                RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input definition"
                                         , "ClientRMService", message);
                throw RPCUtil.GetRemoteException(message);
            }
            // compute minimum duration and max gang size
            long     minDuration = 0;
            Resource maxGangSize = Resource.NewInstance(0, 0);
            ReservationRequestInterpreter type = contract.GetReservationRequests().GetInterpreter
                                                     ();

            foreach (ReservationRequest rr in resReq)
            {
                if (type == ReservationRequestInterpreter.RAll || type == ReservationRequestInterpreter
                    .RAny)
                {
                    minDuration = Math.Max(minDuration, rr.GetDuration());
                }
                else
                {
                    minDuration += rr.GetDuration();
                }
                maxGangSize = Resources.Max(plan.GetResourceCalculator(), plan.GetTotalCapacity()
                                            , maxGangSize, Resources.Multiply(rr.GetCapability(), rr.GetConcurrency()));
            }
            // verify the allocation is possible (skip for ANY)
            if (contract.GetDeadline() - contract.GetArrival() < minDuration && type != ReservationRequestInterpreter
                .RAny)
            {
                message = "The time difference (" + (contract.GetDeadline() - contract.GetArrival
                                                         ()) + ") between arrival (" + contract.GetArrival() + ") " + "and deadline (" +
                          contract.GetDeadline() + ") must " + " be greater or equal to the minimum resource duration ("
                          + minDuration + ")";
                RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input definition"
                                         , "ClientRMService", message);
                throw RPCUtil.GetRemoteException(message);
            }
            // check that the largest gang does not exceed the inventory available
            // capacity (skip for ANY)
            if (Resources.GreaterThan(plan.GetResourceCalculator(), plan.GetTotalCapacity(),
                                      maxGangSize, plan.GetTotalCapacity()) && type != ReservationRequestInterpreter.RAny)
            {
                message = "The size of the largest gang in the reservation refinition (" + maxGangSize
                          + ") exceed the capacity available (" + plan.GetTotalCapacity() + " )";
                RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input definition"
                                         , "ClientRMService", message);
                throw RPCUtil.GetRemoteException(message);
            }
        }