/// <exception cref="System.IO.IOException"/> protected internal virtual void LocalizeFiles(LocalizationProtocol nodemanager, CompletionService <Path> cs, UserGroupInformation ugi) { while (true) { try { LocalizerStatus status = CreateStatus(); LocalizerHeartbeatResponse response = nodemanager.Heartbeat(status); switch (response.GetLocalizerAction()) { case LocalizerAction.Live: { IList <ResourceLocalizationSpec> newRsrcs = response.GetResourceSpecs(); foreach (ResourceLocalizationSpec newRsrc in newRsrcs) { if (!pendingResources.Contains(newRsrc.GetResource())) { pendingResources[newRsrc.GetResource()] = cs.Submit(Download(new Path(newRsrc.GetDestinationDirectory ().GetFile()), newRsrc.GetResource(), ugi)); } } break; } case LocalizerAction.Die: { // killall running localizations foreach (Future <Path> pending in pendingResources.Values) { pending.Cancel(true); } status = CreateStatus(); // ignore response try { nodemanager.Heartbeat(status); } catch (YarnException) { } return; } } cs.Poll(1000, TimeUnit.Milliseconds); } catch (Exception) { return; } catch (YarnException) { // TODO cleanup return; } } }
/// <exception cref="System.Exception"/> public virtual void TestLocalizerHeartbeatResponseSerDe() { LocalizerHeartbeatResponse rsrcS = CreateLocalizerHeartbeatResponse(); NUnit.Framework.Assert.IsTrue(rsrcS is LocalizerHeartbeatResponsePBImpl); LocalizerHeartbeatResponsePBImpl rsrcPb = (LocalizerHeartbeatResponsePBImpl)rsrcS; DataOutputBuffer @out = new DataOutputBuffer(); rsrcPb.GetProto().WriteDelimitedTo(@out); DataInputBuffer @in = new DataInputBuffer(); @in.Reset(@out.GetData(), 0, @out.GetLength()); YarnServerNodemanagerServiceProtos.LocalizerHeartbeatResponseProto rsrcPbD = YarnServerNodemanagerServiceProtos.LocalizerHeartbeatResponseProto .ParseDelimitedFrom(@in); NUnit.Framework.Assert.IsNotNull(rsrcPbD); LocalizerHeartbeatResponse rsrcD = new LocalizerHeartbeatResponsePBImpl(rsrcPbD); NUnit.Framework.Assert.AreEqual(rsrcS, rsrcD); NUnit.Framework.Assert.AreEqual(CreateResource(), rsrcS.GetResourceSpecs()[0].GetResource ()); NUnit.Framework.Assert.AreEqual(CreateResource(), rsrcD.GetResourceSpecs()[0].GetResource ()); }