Ejemplo n.º 1
0
 public Container(ContainerLauncherImpl _enclosing, TaskAttemptId taId, ContainerId
                  containerID, string containerMgrAddress)
 {
     this._enclosing = _enclosing;
     // store enough information to be able to cleanup the container
     this.state               = ContainerLauncherImpl.ContainerState.Prep;
     this.taskAttemptID       = taId;
     this.containerMgrAddress = containerMgrAddress;
     this.containerID         = containerID;
 }
Ejemplo n.º 2
0
 public virtual void Kill()
 {
     lock (this)
     {
         if (this.state == ContainerLauncherImpl.ContainerState.Prep)
         {
             this.state = ContainerLauncherImpl.ContainerState.KilledBeforeLaunch;
         }
         else
         {
             if (!this.IsCompletelyDone())
             {
                 ContainerLauncherImpl.Log.Info("KILLING " + this.taskAttemptID);
                 ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null;
                 try
                 {
                     proxy = this._enclosing.GetCMProxy(this.containerMgrAddress, this.containerID);
                     // kill the remote container if already launched
                     IList <ContainerId> ids = new AList <ContainerId>();
                     ids.AddItem(this.containerID);
                     StopContainersRequest  request  = StopContainersRequest.NewInstance(ids);
                     StopContainersResponse response = proxy.GetContainerManagementProtocol().StopContainers
                                                           (request);
                     if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains
                             (this.containerID))
                     {
                         throw response.GetFailedRequests()[this.containerID].DeSerialize();
                     }
                 }
                 catch (Exception t)
                 {
                     // ignore the cleanup failure
                     string message = "cleanup failed for container " + this.containerID + " : " + StringUtils
                                      .StringifyException(t);
                     this._enclosing.context.GetEventHandler().Handle(new TaskAttemptDiagnosticsUpdateEvent
                                                                          (this.taskAttemptID, message));
                     ContainerLauncherImpl.Log.Warn(message);
                 }
                 finally
                 {
                     if (proxy != null)
                     {
                         this._enclosing.cmProxy.MayBeCloseProxy(proxy);
                     }
                 }
                 this.state = ContainerLauncherImpl.ContainerState.Done;
             }
         }
         // after killing, send killed event to task attempt
         this._enclosing.context.GetEventHandler().Handle(new TaskAttemptEvent(this.taskAttemptID
                                                                               , TaskAttemptEventType.TaContainerCleaned));
     }
 }
Ejemplo n.º 3
0
 public virtual void Launch(ContainerRemoteLaunchEvent @event)
 {
     lock (this)
     {
         ContainerLauncherImpl.Log.Info("Launching " + this.taskAttemptID);
         if (this.state == ContainerLauncherImpl.ContainerState.KilledBeforeLaunch)
         {
             this.state = ContainerLauncherImpl.ContainerState.Done;
             this._enclosing.SendContainerLaunchFailedMsg(this.taskAttemptID, "Container was killed before it was launched"
                                                          );
             return;
         }
         ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null;
         try
         {
             proxy = this._enclosing.GetCMProxy(this.containerMgrAddress, this.containerID);
             // Construct the actual Container
             ContainerLaunchContext containerLaunchContext = @event.GetContainerLaunchContext(
                 );
             // Now launch the actual container
             StartContainerRequest startRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                    , @event.GetContainerToken());
             IList <StartContainerRequest> list = new AList <StartContainerRequest>();
             list.AddItem(startRequest);
             StartContainersRequest  requestList = StartContainersRequest.NewInstance(list);
             StartContainersResponse response    = proxy.GetContainerManagementProtocol().StartContainers
                                                       (requestList);
             if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains
                     (this.containerID))
             {
                 throw response.GetFailedRequests()[this.containerID].DeSerialize();
             }
             ByteBuffer portInfo = response.GetAllServicesMetaData()[ShuffleHandler.MapreduceShuffleServiceid
                                   ];
             int port = -1;
             if (portInfo != null)
             {
                 port = ShuffleHandler.DeserializeMetaData(portInfo);
             }
             ContainerLauncherImpl.Log.Info("Shuffle port returned by ContainerManager for " +
                                            this.taskAttemptID + " : " + port);
             if (port < 0)
             {
                 this.state = ContainerLauncherImpl.ContainerState.Failed;
                 throw new InvalidOperationException("Invalid shuffle port number " + port + " returned for "
                                                     + this.taskAttemptID);
             }
             // after launching, send launched event to task attempt to move
             // it from ASSIGNED to RUNNING state
             this._enclosing.context.GetEventHandler().Handle(new TaskAttemptContainerLaunchedEvent
                                                                  (this.taskAttemptID, port));
             this.state = ContainerLauncherImpl.ContainerState.Running;
         }
         catch (Exception t)
         {
             string message = "Container launch failed for " + this.containerID + " : " + StringUtils
                              .StringifyException(t);
             this.state = ContainerLauncherImpl.ContainerState.Failed;
             this._enclosing.SendContainerLaunchFailedMsg(this.taskAttemptID, message);
         }
         finally
         {
             if (proxy != null)
             {
                 this._enclosing.cmProxy.MayBeCloseProxy(proxy);
             }
         }
     }
 }