/// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> private void StopContainerInternal(ContainerId containerId, NodeId nodeId) { ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null; IList <ContainerId> containerIds = new AList <ContainerId>(); containerIds.AddItem(containerId); try { proxy = cmProxy.GetProxy(nodeId.ToString(), containerId); StopContainersResponse response = proxy.GetContainerManagementProtocol().StopContainers (StopContainersRequest.NewInstance(containerIds)); if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains (containerId)) { Exception t = response.GetFailedRequests()[containerId].DeSerialize(); ParseAndThrowException(t); } } finally { if (proxy != null) { cmProxy.MayBeCloseProxy(proxy); } } }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> public override ContainerStatus GetContainerStatus(ContainerId containerId, NodeId nodeId) { ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null; IList <ContainerId> containerIds = new AList <ContainerId>(); containerIds.AddItem(containerId); try { proxy = cmProxy.GetProxy(nodeId.ToString(), containerId); GetContainerStatusesResponse response = proxy.GetContainerManagementProtocol().GetContainerStatuses (GetContainerStatusesRequest.NewInstance(containerIds)); if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains (containerId)) { Exception t = response.GetFailedRequests()[containerId].DeSerialize(); ParseAndThrowException(t); } ContainerStatus containerStatus = response.GetContainerStatuses()[0]; return(containerStatus); } finally { if (proxy != null) { cmProxy.MayBeCloseProxy(proxy); } } }
public virtual void MayBeCloseProxy(ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy) { lock (this) { TryCloseProxy(proxy); } }
private bool RemoveProxy(ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy) { lock (this) { if (!proxy.scheduledForClose) { proxy.scheduledForClose = true; return(TryCloseProxy(proxy)); } return(false); } }
GetProxy(string containerManagerBindAddr, ContainerId containerId) { lock (this) { // This get call will update the map which is working as LRU cache. ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = cmProxy [containerManagerBindAddr]; while (proxy != null && !proxy.token.GetIdentifier().Equals(nmTokenCache.GetToken (containerManagerBindAddr).GetIdentifier())) { Log.Info("Refreshing proxy as NMToken got updated for node : " + containerManagerBindAddr ); // Token is updated. check if anyone has already tried closing it. if (!proxy.scheduledForClose) { // try closing the proxy. Here if someone is already using it // then we might not close it. In which case we will wait. RemoveProxy(proxy); } else { try { Sharpen.Runtime.Wait(this); } catch (Exception e) { Sharpen.Runtime.PrintStackTrace(e); } } if (proxy.activeCallers < 0) { proxy = cmProxy[containerManagerBindAddr]; } } if (proxy == null) { proxy = new ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData (this, rpc, containerManagerBindAddr, containerId, nmTokenCache.GetToken(containerManagerBindAddr )); if (maxConnectedNMs > 0) { AddProxyToCache(containerManagerBindAddr, proxy); } } // This is to track active users of this proxy. proxy.activeCallers++; UpdateLRUCache(containerManagerBindAddr); return(proxy); } }
private bool TryCloseProxy(ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy) { proxy.activeCallers--; if (proxy.scheduledForClose && proxy.activeCallers < 0) { Log.Info("Closing proxy : " + proxy.containerManagerBindAddr); Sharpen.Collections.Remove(cmProxy, proxy.containerManagerBindAddr); try { rpc.StopProxy(proxy.GetContainerManagementProtocol(), conf); } finally { Sharpen.Runtime.NotifyAll(this); } return(true); } return(false); }
private void AddProxyToCache(string containerManagerBindAddr, ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy) { while (cmProxy.Count >= maxConnectedNMs) { if (Log.IsDebugEnabled()) { Log.Debug("Cleaning up the proxy cache, size=" + cmProxy.Count + " max=" + maxConnectedNMs ); } bool removedProxy = false; foreach (ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData otherProxy in cmProxy.Values) { removedProxy = RemoveProxy(otherProxy); if (removedProxy) { break; } } if (!removedProxy) { // all of the proxies are currently in use and already scheduled // for removal, so we need to wait until at least one of them closes try { Sharpen.Runtime.Wait(this); } catch (Exception e) { Sharpen.Runtime.PrintStackTrace(e); } } } if (maxConnectedNMs > 0) { cmProxy[containerManagerBindAddr] = proxy; } }
/// <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); } }
public virtual void StopAllProxies() { lock (this) { IList <string> nodeIds = new AList <string>(); Sharpen.Collections.AddAll(nodeIds, this.cmProxy.Keys); foreach (string nodeId in nodeIds) { ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = cmProxy [nodeId]; // Explicitly reducing the proxy count to allow stopping proxy. proxy.activeCallers = 0; try { RemoveProxy(proxy); } catch (Exception t) { Log.Error("Error closing connection", t); } } cmProxy.Clear(); } }
private void UpdateLRUCache(string containerManagerBindAddr) { if (maxConnectedNMs > 0) { ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = Sharpen.Collections.Remove (cmProxy, containerManagerBindAddr); cmProxy[containerManagerBindAddr] = proxy; } }