public virtual void DumpTreeRecursively(INodeDirectory snapshotRoot, PrintWriter @out, StringBuilder prefix, int snapshot) { if (snapshot == Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId) { @out.WriteLine(); @out.Write(prefix); @out.Write("Snapshot of "); string name = snapshotRoot.GetLocalName(); @out.Write(name.IsEmpty() ? "/" : name); @out.Write(": quota="); @out.Write(GetSnapshotQuota()); int n = 0; foreach (DirectoryWithSnapshotFeature.DirectoryDiff diff in GetDiffs()) { if (diff.IsSnapshotRoot()) { n++; } } Preconditions.CheckState(n == snapshotsByNames.Count, "#n=" + n + ", snapshotsByNames.size()=" + snapshotsByNames.Count); @out.Write(", #snapshot="); @out.WriteLine(n); INodeDirectory.DumpTreeRecursively(@out, prefix, new _IEnumerable_416(this)); } }
public virtual void TestSimplePlacementPolicyFromConf() { Configuration conf = new Configuration(); conf.Set(FairSchedulerConfiguration.AllocationFile, AllocFile); conf.SetBoolean(FairSchedulerConfiguration.AllowUndeclaredPools, false); conf.SetBoolean(FairSchedulerConfiguration.UserAsDefaultQueue, false); PrintWriter @out = new PrintWriter(new FileWriter(AllocFile)); @out.WriteLine("<?xml version=\"1.0\"?>"); @out.WriteLine("<allocations>"); @out.WriteLine("</allocations>"); @out.Close(); AllocationFileLoaderService allocLoader = new AllocationFileLoaderService(); allocLoader.Init(conf); TestAllocationFileLoaderService.ReloadListener confHolder = new TestAllocationFileLoaderService.ReloadListener (this); allocLoader.SetReloadListener(confHolder); allocLoader.ReloadAllocations(); AllocationConfiguration allocConf = confHolder.allocConf; QueuePlacementPolicy placementPolicy = allocConf.GetPlacementPolicy(); IList <QueuePlacementRule> rules = placementPolicy.GetRules(); NUnit.Framework.Assert.AreEqual(2, rules.Count); NUnit.Framework.Assert.AreEqual(typeof(QueuePlacementRule.Specified), rules[0].GetType ()); NUnit.Framework.Assert.AreEqual(false, rules[0].create); NUnit.Framework.Assert.AreEqual(typeof(QueuePlacementRule.Default), rules[1].GetType ()); }
/// <summary> /// Creates a script to run a container that will run forever unless /// stopped by external means. /// </summary> /// <exception cref="System.IO.IOException"/> private static FilePath CreateUnhaltingScriptFile(ContainerId cId, FilePath scriptFileDir , FilePath processStartFile) { FilePath scriptFile = Shell.AppendScriptExtension(scriptFileDir, "scriptFile"); PrintWriter fileWriter = new PrintWriter(scriptFile); if (Shell.Windows) { fileWriter.WriteLine("@echo \"Running testscript for delayed kill\""); fileWriter.WriteLine("@echo \"Writing pid to start file\""); fileWriter.WriteLine("@echo " + cId + ">> " + processStartFile); fileWriter.WriteLine("@pause"); } else { fileWriter.Write("#!/bin/bash\n\n"); fileWriter.Write("echo \"Running testscript for delayed kill\"\n"); fileWriter.Write("hello=\"Got SIGTERM\"\n"); fileWriter.Write("umask 0\n"); fileWriter.Write("trap \"echo $hello >> " + processStartFile + "\" SIGTERM\n"); fileWriter.Write("echo \"Writing pid to start file\"\n"); fileWriter.Write("echo $$ >> " + processStartFile + "\n"); fileWriter.Write("while true; do\ndate >> /dev/null;\n done\n"); } fileWriter.Close(); return(scriptFile); }
private static void PrintLockInfo(LockInfo[] locks, PrintWriter @out) { @out.WriteLine(Indent + "Locked synchronizers: count = " + locks.Length); foreach (LockInfo li in locks) { @out.WriteLine(Indent + " - " + li); } @out.WriteLine(); }
/// <exception cref="System.Exception"/> public override void TestFailure(Failure failure) { if (failure != null && failure.GetMessage() != null && failure.GetMessage().StartsWith (TestTimedOutPrefix)) { output.WriteLine("====> TEST TIMED OUT. PRINTING THREAD DUMP. <===="); output.WriteLine(); output.Write(BuildThreadDiagnosticString()); } }
/// <exception cref="System.IO.IOException"/> private static void Process(Logger log, string level, PrintWriter @out) { if (level != null) { log.SetLevel(Level.Parse(level)); @out.WriteLine(Marker + "Setting Level to " + level + " ...<br />"); } Level lev; for (; (lev = log.GetLevel()) == null; log = log.GetParent()) { } @out.WriteLine(Marker + "Effective level: <b>" + lev + "</b><br />"); }
/// <summary>Write output to files.</summary> /// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> protected override void Cleanup(Reducer.Context context) { Configuration conf = context.GetConfiguration(); Path dir = new Path(conf.Get(WorkingDirProperty)); FileSystem fs = dir.GetFileSystem(conf); { // write hex output Path hexfile = new Path(conf.Get(HexFileProperty)); OutputStream @out = new BufferedOutputStream(fs.Create(hexfile)); try { foreach (byte b in hex) { @out.Write(b); } } finally { @out.Close(); } } // If the starting digit is 1, // the hex value can be converted to decimal value. if (conf.GetInt(DigitStartProperty, 1) == 1) { Path outfile = new Path(dir, "pi.txt"); Log.Info("Writing text output to " + outfile); OutputStream outputstream = fs.Create(outfile); try { PrintWriter @out = new PrintWriter(new OutputStreamWriter(outputstream, Charsets. Utf8), true); // write hex text Print(@out, hex.GetEnumerator(), "Pi = 0x3.", "%02X", 5, 5); @out.WriteLine("Total number of hexadecimal digits is " + 2 * hex.Count + "."); // write decimal text BaileyBorweinPlouffe.Fraction dec = new BaileyBorweinPlouffe.Fraction(hex); int decDigits = 2 * hex.Count; // TODO: this is conservative. Print(@out, new _IEnumerator_168(decDigits, dec), "Pi = 3.", "%d", 10, 5); @out.WriteLine("Total number of decimal digits is " + decDigits + "."); } finally { outputstream.Close(); } } }
/// <exception cref="System.Exception"/> public virtual void TestShellCommandTimeout() { if (Shell.Windows) { // setExecutable does not work on Windows return; } string rootDir = new FilePath(Runtime.GetProperty("test.build.data", "/tmp")).GetAbsolutePath (); FilePath shellFile = new FilePath(rootDir, "timeout.sh"); string timeoutCommand = "sleep 4; echo \"hello\""; PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile)); writer.WriteLine(timeoutCommand); writer.Close(); FileUtil.SetExecutable(shellFile, true); Shell.ShellCommandExecutor shexc = new Shell.ShellCommandExecutor(new string[] { shellFile.GetAbsolutePath() }, null, null, 100); try { shexc.Execute(); } catch (Exception) { } //When timing out exception is thrown. shellFile.Delete(); Assert.True("Script didnt not timeout", shexc.IsTimedOut()); }
/// <summary>Start a job to compute sigma</summary> /// <exception cref="System.IO.IOException"/> private void Compute(string name, Summation sigma) { if (sigma.GetValue() != null) { throw new IOException("sigma.getValue() != null, sigma=" + sigma); } //setup remote directory FileSystem fs = FileSystem.Get(GetConf()); Path dir = fs.MakeQualified(new Path(parameters.remoteDir, name)); if (!Org.Apache.Hadoop.Examples.PI.Util.CreateNonexistingDirectory(fs, dir)) { return; } //setup a job Job job = CreateJob(name, sigma); Path outdir = new Path(dir, "out"); FileOutputFormat.SetOutputPath(job, outdir); //start a map/reduce job string startmessage = "steps/parts = " + sigma.E.GetSteps() + "/" + parameters.nParts + " = " + Org.Apache.Hadoop.Examples.PI.Util.Long2string(sigma.E.GetSteps() / parameters .nParts); Org.Apache.Hadoop.Examples.PI.Util.RunJob(name, job, parameters.machine, startmessage , timer); IList <TaskResult> results = Org.Apache.Hadoop.Examples.PI.Util.ReadJobOutputs(fs, outdir); Org.Apache.Hadoop.Examples.PI.Util.WriteResults(name, results, fs, parameters.remoteDir ); fs.Delete(dir, true); //combine results IList <TaskResult> combined = Org.Apache.Hadoop.Examples.PI.Util.Combine(results); PrintWriter @out = Org.Apache.Hadoop.Examples.PI.Util.CreateWriter(parameters.localDir , name); try { foreach (TaskResult r in combined) { string s = TaskResult2string(name, r); @out.WriteLine(s); @out.Flush(); [email protected](s); } } finally { @out.Close(); } if (combined.Count == 1) { Summation s = combined[0].GetElement(); if (sigma.Contains(s) && s.Contains(sigma)) { sigma.SetValue(s.GetValue()); } } }
/// <exception cref="System.IO.IOException"/> public virtual void TestSimpleGet() { string rootDir = new FilePath(Runtime.GetProperty("test.build.data", "/tmp")).GetAbsolutePath (); FilePath testFile = null; string expectedProcessId = Shell.Windows ? "container_1353742680940_0002_01_000001" : "56789"; try { testFile = new FilePath(rootDir, "temp.txt"); PrintWriter fileWriter = new PrintWriter(testFile); fileWriter.WriteLine(expectedProcessId); fileWriter.Close(); string processId = null; processId = ProcessIdFileReader.GetProcessId(new Path(rootDir + Path.Separator + "temp.txt")); NUnit.Framework.Assert.AreEqual(expectedProcessId, processId); } finally { if (testFile != null && testFile.Exists()) { testFile.Delete(); } } }
public override void DumpTreeRecursively(PrintWriter @out, StringBuilder prefix, int snapshot) { base.DumpTreeRecursively(@out, prefix, snapshot); @out.Write(", childrenSize=" + GetChildrenList(snapshot).Size()); DirectoryWithQuotaFeature q = GetDirectoryWithQuotaFeature(); if (q != null) { @out.Write(", " + q); } if (this is Snapshot.Root) { @out.Write(", snapshotId=" + snapshot); } @out.WriteLine(); if (prefix.Length >= 2) { prefix.Length = prefix.Length - 2; prefix.Append(" "); } DumpTreeRecursively(@out, prefix, new _IEnumerable_874(this, snapshot)); DirectorySnapshottableFeature s = GetDirectorySnapshottableFeature(); if (s != null) { s.DumpTreeRecursively(this, @out, prefix, snapshot); } }
/// <exception cref="System.IO.IOException"/> private static void Process(Logger log, string level, PrintWriter @out) { if (level != null) { if (!level.Equals(Level.ToLevel(level).ToString())) { @out.WriteLine(Marker + "Bad level : <b>" + level + "</b><br />"); } else { log.SetLevel(Level.ToLevel(level)); @out.WriteLine(Marker + "Setting Level to " + level + " ...<br />"); } } @out.WriteLine(Marker + "Effective level: <b>" + log.GetEffectiveLevel() + "</b><br />" ); }
/// <summary> /// Writes a message the the logging library and the given print writer (if it /// is not null) /// </summary> /// <param name="msg">the message to write</param> /// <param name="os">the print writer if specified to also write to</param> private void WriteMessage(string msg, PrintWriter os) { Log.Info(msg); if (os != null) { os.WriteLine(msg); } }
/// <summary>Iterate through all items and print them.</summary> internal virtual void MetaSave(PrintWriter @out) { lock (pendingReplications) { @out.WriteLine("Metasave: Blocks being replicated: " + pendingReplications.Count); IEnumerator <KeyValuePair <Block, PendingReplicationBlocks.PendingBlockInfo> > iter = pendingReplications.GetEnumerator(); while (iter.HasNext()) { KeyValuePair <Block, PendingReplicationBlocks.PendingBlockInfo> entry = iter.Next( ); PendingReplicationBlocks.PendingBlockInfo pendingBlock = entry.Value; Block block = entry.Key; @out.WriteLine(block + " StartTime: " + Sharpen.Extensions.CreateDate(pendingBlock .timeStamp) + " NumReplicaInProgress: " + pendingBlock.GetNumReplicas()); } } }
/// <summary>Initial HTML header</summary> /// <exception cref="System.IO.IOException"/> public static PrintWriter InitHTML(ServletResponse response, string title) { response.SetContentType("text/html"); PrintWriter @out = response.GetWriter(); @out.WriteLine("<html>\n" + "<link rel='stylesheet' type='text/css' href='/static/hadoop.css'>\n" + "<title>" + title + "</title>\n" + "<body>\n" + "<h1>" + title + "</h1>\n"); return(@out); }
public override void DumpTreeRecursively(PrintWriter @out, StringBuilder prefix, int snapshotId) { base.DumpTreeRecursively(@out, prefix, snapshotId); @out.Write(", fileSize=" + ComputeFileSize(snapshotId)); // only compare the first block @out.Write(", blocks="); @out.Write(blocks == null || blocks.Length == 0 ? null : blocks[0]); @out.WriteLine(); }
/// <exception cref="System.IO.IOException"/> private string WriteScriptFile(params string[] cmd) { FilePath f = FilePath.CreateTempFile("TestLinuxContainerExecutor", ".sh"); f.DeleteOnExit(); PrintWriter p = new PrintWriter(new FileOutputStream(f)); p.WriteLine("#!/bin/sh"); p.Write("exec"); foreach (string part in cmd) { p.Write(" '"); p.Write(part.Replace("\\", "\\\\").Replace("'", "\\'")); p.Write("'"); } p.WriteLine(); p.Close(); return(f.GetAbsolutePath()); }
/// <exception cref="System.Exception"/> public virtual void Test() { conf.Set(FairSchedulerConfiguration.AllocationFile, AllocFile); PrintWriter @out = new PrintWriter(new FileWriter(AllocFile)); @out.WriteLine("<?xml version=\"1.0\"?>"); @out.WriteLine("<allocations>"); @out.WriteLine("<queue name=\"queueA\">"); @out.WriteLine("<minResources>2048mb,0vcores</minResources>"); @out.WriteLine("</queue>"); @out.WriteLine("<queue name=\"queueB\">"); @out.WriteLine("<minResources>2048mb,0vcores</minResources>"); @out.WriteLine("</queue>"); @out.WriteLine("</allocations>"); @out.Close(); resourceManager = new MockRM(conf); resourceManager.Start(); scheduler = (FairScheduler)resourceManager.GetResourceScheduler(); // Add one big node (only care about aggregate capacity) RMNode node1 = MockNodes.NewNodeInfo(1, Resources.CreateResource(4 * 1024, 4), 1, "127.0.0.1"); NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1); scheduler.Handle(nodeEvent1); scheduler.Update(); // Queue A wants 3 * 1024. Node update gives this all to A CreateSchedulingRequest(3 * 1024, "queueA", "user1"); scheduler.Update(); NodeUpdateSchedulerEvent nodeEvent2 = new NodeUpdateSchedulerEvent(node1); scheduler.Handle(nodeEvent2); // Queue B arrives and wants 1 * 1024 CreateSchedulingRequest(1 * 1024, "queueB", "user1"); scheduler.Update(); ICollection <FSLeafQueue> queues = scheduler.GetQueueManager().GetLeafQueues(); NUnit.Framework.Assert.AreEqual(3, queues.Count); // Queue A should be above min share, B below. FSLeafQueue queueA = scheduler.GetQueueManager().GetLeafQueue("queueA", false); FSLeafQueue queueB = scheduler.GetQueueManager().GetLeafQueue("queueB", false); NUnit.Framework.Assert.IsFalse(queueA.IsStarvedForMinShare()); NUnit.Framework.Assert.IsTrue(queueB.IsStarvedForMinShare()); // Node checks in again, should allocate for B scheduler.Handle(nodeEvent2); // Now B should have min share ( = demand here) NUnit.Framework.Assert.IsFalse(queueB.IsStarvedForMinShare()); }
/// <summary>Prints the application attempt report for an application attempt id.</summary> /// <param name="applicationAttemptId"/> /// <returns>exitCode</returns> /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> private int PrintApplicationAttemptReport(string applicationAttemptId) { ApplicationAttemptReport appAttemptReport = null; try { appAttemptReport = client.GetApplicationAttemptReport(ConverterUtils.ToApplicationAttemptId (applicationAttemptId)); } catch (ApplicationNotFoundException) { sysout.WriteLine("Application for AppAttempt with id '" + applicationAttemptId + "' doesn't exist in RM or Timeline Server."); return(-1); } catch (ApplicationAttemptNotFoundException) { sysout.WriteLine("Application Attempt with id '" + applicationAttemptId + "' doesn't exist in RM or Timeline Server." ); return(-1); } // Use PrintWriter.println, which uses correct platform line ending. ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter appAttemptReportStr = new PrintWriter(new OutputStreamWriter(baos, Sharpen.Extensions.GetEncoding ("UTF-8"))); if (appAttemptReport != null) { appAttemptReportStr.WriteLine("Application Attempt Report : "); appAttemptReportStr.Write("\tApplicationAttempt-Id : "); appAttemptReportStr.WriteLine(appAttemptReport.GetApplicationAttemptId()); appAttemptReportStr.Write("\tState : "); appAttemptReportStr.WriteLine(appAttemptReport.GetYarnApplicationAttemptState()); appAttemptReportStr.Write("\tAMContainer : "); appAttemptReportStr.WriteLine(appAttemptReport.GetAMContainerId().ToString()); appAttemptReportStr.Write("\tTracking-URL : "); appAttemptReportStr.WriteLine(appAttemptReport.GetTrackingUrl()); appAttemptReportStr.Write("\tRPC Port : "); appAttemptReportStr.WriteLine(appAttemptReport.GetRpcPort()); appAttemptReportStr.Write("\tAM Host : "); appAttemptReportStr.WriteLine(appAttemptReport.GetHost()); appAttemptReportStr.Write("\tDiagnostics : "); appAttemptReportStr.Write(appAttemptReport.GetDiagnostics()); } else { appAttemptReportStr.Write("Application Attempt with id '" + applicationAttemptId + "' doesn't exist in Timeline Server."); appAttemptReportStr.Close(); sysout.WriteLine(baos.ToString("UTF-8")); return(-1); } appAttemptReportStr.Close(); sysout.WriteLine(baos.ToString("UTF-8")); return(0); }
/// <summary> /// Verify that you can't include periods as the queue name in the allocations /// file. /// </summary> /// <exception cref="System.Exception"/> public virtual void TestQueueNameContainingPeriods() { Configuration conf = new Configuration(); conf.Set(FairSchedulerConfiguration.AllocationFile, AllocFile); PrintWriter @out = new PrintWriter(new FileWriter(AllocFile)); @out.WriteLine("<?xml version=\"1.0\"?>"); @out.WriteLine("<allocations>"); @out.WriteLine("<queue name=\"parent1.child1\">"); @out.WriteLine("</queue>"); @out.WriteLine("</allocations>"); @out.Close(); AllocationFileLoaderService allocLoader = new AllocationFileLoaderService(); allocLoader.Init(conf); TestAllocationFileLoaderService.ReloadListener confHolder = new TestAllocationFileLoaderService.ReloadListener (this); allocLoader.SetReloadListener(confHolder); allocLoader.ReloadAllocations(); }
/// <exception cref="System.IO.IOException"/> private string WriteScriptFile(IDictionary <string, string> launchCtxEnv, params string [] cmd) { FilePath f = FilePath.CreateTempFile("TestDockerContainerExecutor", ".sh"); f.DeleteOnExit(); PrintWriter p = new PrintWriter(new FileOutputStream(f)); foreach (KeyValuePair <string, string> entry in launchCtxEnv) { p.WriteLine("export " + entry.Key + "=\"" + entry.Value + "\""); } foreach (string part in cmd) { p.Write(part.Replace("\\", "\\\\").Replace("'", "\\'")); p.Write(" "); } p.WriteLine(); p.Close(); return(f.GetAbsolutePath()); }
private static void PrintThreadInfo(ThreadInfo ti, PrintWriter @out) { // print thread information PrintThread(ti, @out); // print stack trace with locks StackTraceElement[] stacktrace = ti.GetStackTrace(); MonitorInfo[] monitors = ti.GetLockedMonitors(); for (int i = 0; i < stacktrace.Length; i++) { StackTraceElement ste = stacktrace[i]; @out.WriteLine(Indent + "at " + ste.ToString()); foreach (MonitorInfo mi in monitors) { if (mi.GetLockedStackDepth() == i) { @out.WriteLine(Indent + " - locked " + mi); } } } @out.WriteLine(); }
/// <summary>Lists the Queue Information matching the given queue name</summary> /// <param name="queueName"/> /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> private int ListQueue(string queueName) { int rc; PrintWriter writer = new PrintWriter(new OutputStreamWriter(sysout, Sharpen.Extensions.GetEncoding ("UTF-8"))); QueueInfo queueInfo = client.GetQueueInfo(queueName); if (queueInfo != null) { writer.WriteLine("Queue Information : "); PrintQueueInfo(writer, queueInfo); rc = 0; } else { writer.WriteLine("Cannot get queue from RM by queueName = " + queueName + ", please check." ); rc = -1; } writer.Flush(); return(rc); }
/// <summary>Print the contents to out.</summary> internal virtual void Dump(PrintWriter @out) { lock (this) { int size = node2blocks.Values.Count; @out.WriteLine("Metasave: Blocks " + numBlocks + " waiting deletion from " + size + " datanodes."); if (size == 0) { return; } foreach (KeyValuePair <DatanodeInfo, LightWeightHashSet <Block> > entry in node2blocks) { LightWeightHashSet <Block> blocks = entry.Value; if (blocks.Count > 0) { @out.WriteLine(entry.Key); @out.WriteLine(blocks); } } } }
private static void PrintThread(ThreadInfo ti, PrintWriter @out) { @out.Write("\"" + ti.GetThreadName() + "\"" + " Id=" + ti.GetThreadId() + " in " + ti.GetThreadState()); if (ti.GetLockName() != null) { @out.Write(" on lock=" + ti.GetLockName()); } if (ti.IsSuspended()) { @out.Write(" (suspended)"); } if (ti.IsInNative()) { @out.Write(" (running in native)"); } @out.WriteLine(); if (ti.GetLockOwnerName() != null) { @out.WriteLine(Indent + " owned by " + ti.GetLockOwnerName() + " Id=" + ti.GetLockOwnerId ()); } }
/// <summary>Writes a chunk of data to a file in pretty printed hexidecimal.</summary> /// <remarks>Writes a chunk of data to a file in pretty printed hexidecimal.</remarks> /// <exception cref="System.IO.IOException"></exception> public static void ToHexFile(string fileName, ByteBuffer buffer, int offset, int size) { PrintWriter writer = new PrintWriter(new FileWriter(fileName)); try { writer.WriteLine(ToHexString(buffer, offset, size)); } finally { writer.Close(); } }
/// <summary> /// Creates a new file in the specified directory, with the specified name and /// the specified file contents. /// </summary> /// <remarks> /// Creates a new file in the specified directory, with the specified name and /// the specified file contents. This method will add a newline terminator to /// the end of the contents string in the destination file. /// </remarks> /// <param name="directory">File non-null destination directory.</param> /// <param name="name">String non-null file name.</param> /// <param name="contents">String non-null file contents.</param> /// <exception cref="System.IO.IOException">if an I/O error occurs.</exception> private FilePath CreateFile(FilePath directory, string name, string contents) { FilePath newFile = new FilePath(directory, name); PrintWriter pw = new PrintWriter(newFile); try { pw.WriteLine(contents); } finally { pw.Close(); } return(newFile); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest req, HttpServletResponse resp) { UserGroupInformation ugi; ServletContext context = GetServletContext(); Configuration conf = NameNodeHttpServer.GetConfFromContext(context); try { ugi = GetUGI(req, conf); } catch (IOException ioe) { Log.Info("Request for token received with no authentication from " + req.GetRemoteAddr (), ioe); resp.SendError(HttpServletResponse.ScForbidden, "Unable to identify or authenticate user" ); return; } NameNode nn = NameNodeHttpServer.GetNameNodeFromContext(context); string tokenString = req.GetParameter(Token); if (tokenString == null) { resp.SendError(HttpServletResponse.ScMultipleChoices, "Token to renew not specified" ); } Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = new Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier>(); token.DecodeFromUrlString(tokenString); try { long result = ugi.DoAs(new _PrivilegedExceptionAction_73(nn, token)); PrintWriter os = new PrintWriter(new OutputStreamWriter(resp.GetOutputStream(), Charsets .Utf8)); os.WriteLine(result); os.Close(); } catch (Exception e) { // transfer exception over the http string exceptionClass = e.GetType().FullName; string exceptionMsg = e.GetLocalizedMessage(); string strException = exceptionClass + ";" + exceptionMsg; Log.Info("Exception while renewing token. Re-throwing. s=" + strException, e); resp.SendError(HttpServletResponse.ScInternalServerError, strException); } }
public virtual void TestInstances() { Injector injector = WebAppTests.CreateMockInjector(this); HttpServletRequest req = injector.GetInstance <HttpServletRequest>(); HttpServletResponse res = injector.GetInstance <HttpServletResponse>(); string val = req.GetParameter("foo"); PrintWriter @out = res.GetWriter(); @out.WriteLine("Hello world!"); LogInstances(req, res, @out); NUnit.Framework.Assert.AreSame(req, injector.GetInstance <HttpServletRequest>()); NUnit.Framework.Assert.AreSame(res, injector.GetInstance <HttpServletResponse>()); NUnit.Framework.Assert.AreSame(this, injector.GetInstance <TestWebAppTests>()); Org.Mockito.Mockito.Verify(req).GetParameter("foo"); Org.Mockito.Mockito.Verify(res).GetWriter(); Org.Mockito.Mockito.Verify(@out).WriteLine("Hello world!"); }
/// <summary>Lists the nodes matching the given node states</summary> /// <param name="nodeStates"/> /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> private void ListClusterNodes(ICollection <NodeState> nodeStates) { PrintWriter writer = new PrintWriter(new OutputStreamWriter(sysout, Sharpen.Extensions.GetEncoding ("UTF-8"))); IList <NodeReport> nodesReport = client.GetNodeReports(Sharpen.Collections.ToArray (nodeStates, new NodeState[0])); writer.WriteLine("Total Nodes:" + nodesReport.Count); writer.Printf(NodesPattern, "Node-Id", "Node-State", "Node-Http-Address", "Number-of-Running-Containers" ); foreach (NodeReport nodeReport in nodesReport) { writer.Printf(NodesPattern, nodeReport.GetNodeId(), nodeReport.GetNodeState(), nodeReport .GetHttpAddress(), nodeReport.GetNumContainers()); } writer.Flush(); }