Exemplo n.º 1
0
 /// <exception cref="System.IO.IOException"/>
 private void Recover()
 {
     if (stateStore.CanRecover())
     {
         NMStateStoreService.RecoveredLogDeleterState state = stateStore.LoadLogDeleterState
                                                                  ();
         long now = Runtime.CurrentTimeMillis();
         foreach (KeyValuePair <ApplicationId, YarnServerNodemanagerRecoveryProtos.LogDeleterProto
                                > entry in state.GetLogDeleterMap())
         {
             ApplicationId appId = entry.Key;
             YarnServerNodemanagerRecoveryProtos.LogDeleterProto proto = entry.Value;
             long deleteDelayMsec = proto.GetDeletionTime() - now;
             if (Log.IsDebugEnabled())
             {
                 Log.Debug("Scheduling deletion of " + appId + " logs in " + deleteDelayMsec + " msec"
                           );
             }
             NonAggregatingLogHandler.LogDeleterRunnable logDeleter = new NonAggregatingLogHandler.LogDeleterRunnable
                                                                          (this, proto.GetUser(), appId);
             try
             {
                 sched.Schedule(logDeleter, deleteDelayMsec, TimeUnit.Milliseconds);
             }
             catch (RejectedExecutionException)
             {
                 // Handling this event in local thread before starting threads
                 // or after calling sched.shutdownNow().
                 logDeleter.Run();
             }
         }
     }
 }
Exemplo n.º 2
0
        public virtual void Handle(LogHandlerEvent @event)
        {
            switch (@event.GetType())
            {
            case LogHandlerEventType.ApplicationStarted:
            {
                LogHandlerAppStartedEvent appStartedEvent = (LogHandlerAppStartedEvent)@event;
                this.appOwners[appStartedEvent.GetApplicationId()] = appStartedEvent.GetUser();
                this.dispatcher.GetEventHandler().Handle(new ApplicationEvent(appStartedEvent.GetApplicationId
                                                                                  (), ApplicationEventType.ApplicationLogHandlingInited));
                break;
            }

            case LogHandlerEventType.ContainerFinished:
            {
                // Ignore
                break;
            }

            case LogHandlerEventType.ApplicationFinished:
            {
                LogHandlerAppFinishedEvent appFinishedEvent = (LogHandlerAppFinishedEvent)@event;
                ApplicationId appId = appFinishedEvent.GetApplicationId();
                // Schedule - so that logs are available on the UI till they're deleted.
                Log.Info("Scheduling Log Deletion for application: " + appId + ", with delay of "
                         + this.deleteDelaySeconds + " seconds");
                string user = Sharpen.Collections.Remove(appOwners, appId);
                if (user == null)
                {
                    Log.Error("Unable to locate user for " + appId);
                    break;
                }
                NonAggregatingLogHandler.LogDeleterRunnable logDeleter = new NonAggregatingLogHandler.LogDeleterRunnable
                                                                             (this, user, appId);
                long deletionTimestamp = Runtime.CurrentTimeMillis() + this.deleteDelaySeconds *
                                         1000;
                YarnServerNodemanagerRecoveryProtos.LogDeleterProto deleterProto = ((YarnServerNodemanagerRecoveryProtos.LogDeleterProto
                                                                                     )YarnServerNodemanagerRecoveryProtos.LogDeleterProto.NewBuilder().SetUser(user).
                                                                                    SetDeletionTime(deletionTimestamp).Build());
                try
                {
                    stateStore.StoreLogDeleter(appId, deleterProto);
                }
                catch (IOException e)
                {
                    Log.Error("Unable to record log deleter state", e);
                }
                try
                {
                    sched.Schedule(logDeleter, this.deleteDelaySeconds, TimeUnit.Seconds);
                }
                catch (RejectedExecutionException)
                {
                    // Handling this event in local thread before starting threads
                    // or after calling sched.shutdownNow().
                    logDeleter.Run();
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }