/// <exception cref="System.Exception"/> public virtual void TestTopUsersNoPeriods() { Configuration conf = new Configuration(); conf.SetBoolean(DFSConfigKeys.NntopEnabledKey, true); conf.Set(DFSConfigKeys.NntopWindowsMinutesKey, string.Empty); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).Build(); cluster.WaitActive(); MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanNameFsns = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState" ); FileSystem fs = cluster.GetFileSystem(); Path path = new Path("/"); int NumOps = 10; for (int i = 0; i < NumOps; i++) { fs.ListStatus(path); fs.SetTimes(path, 0, 1); } string topUsers = (string)(mbs.GetAttribute(mxbeanNameFsns, "TopUserOpCounts")); NUnit.Framework.Assert.IsNotNull("Expected TopUserOpCounts bean!", topUsers); } finally { if (cluster != null) { cluster.Shutdown(); } } }
public virtual void startService <S>(string name, PlatformService <S> service) { lock (this) { ObjectName serviceName = getObjectName(name); if (getService(serviceName) != default(S)) { throw new ProcessEngineException("Cannot register service " + serviceName + " with MBeans Container, service with same name already registered."); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final javax.management.MBeanServer beanServer = getmBeanServer(); MBeanServer beanServer = getmBeanServer(); // call the service-provided start behavior service.start(this); try { beanServer.registerMBean(service, serviceName); servicesByName[serviceName] = service; Stack <DeploymentOperation> currentOperationContext = activeDeploymentOperations.get(); if (currentOperationContext != null) { currentOperationContext.Peek().serviceAdded(name); } } catch (Exception e) { throw LOG.cannotRegisterService(serviceName, e); } } }
/// <summary> /// Register the MBean using our standard MBeanName format /// "hadoop:service=<serviceName>,name=<nameName>" /// Where the <serviceName> and <nameName> are the supplied parameters /// </summary> /// <param name="serviceName"/> /// <param name="nameName"/> /// <param name="theMbean">- the MBean to register</param> /// <returns>the named used to register the MBean</returns> public static ObjectName Register(string serviceName, string nameName, object theMbean ) { MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName name = GetMBeanName(serviceName, nameName); try { mbs.RegisterMBean(theMbean, name); Log.Debug("Registered " + name); return(name); } catch (InstanceAlreadyExistsException iaee) { if (Log.IsTraceEnabled()) { Log.Trace("Failed to register MBean \"" + name + "\"", iaee); } else { Log.Warn("Failed to register MBean \"" + name + "\": Instance already exists."); } } catch (Exception e) { Log.Warn("Failed to register MBean \"" + name + "\"", e); } return(null); }
public override void Run() { try { MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); // Metrics that belong to "FSNamesystem", these are metrics that // come from hadoop metrics framework for the class FSNamesystem. ObjectName mxbeanNamefsn = new ObjectName("Hadoop:service=NameNode,name=FSNamesystem" ); // Metrics that belong to "FSNamesystemState". // These are metrics that FSNamesystem registers directly with MBeanServer. ObjectName mxbeanNameFsns = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState" ); // Metrics that belong to "NameNodeInfo". // These are metrics that FSNamesystem registers directly with MBeanServer. ObjectName mxbeanNameNni = new ObjectName("Hadoop:service=NameNode,name=NameNodeInfo" ); ICollection <ObjectName> mbeans = new HashSet <ObjectName>(); mbeans.AddItem(mxbeanNamefsn); mbeans.AddItem(mxbeanNameFsns); mbeans.AddItem(mxbeanNameNni); foreach (ObjectName mbean in mbeans) { MBeanInfo attributes = mbs.GetMBeanInfo(mbean); foreach (MBeanAttributeInfo attributeInfo in attributes.GetAttributes()) { mbs.GetAttribute(mbean, attributeInfo.GetName()); } } succeeded = true; } catch (Exception) { } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @POST @Consumes(javax.ws.rs.core.MediaType.APPLICATION_JSON) @Path(QUERY_PATH) @SuppressWarnings("unchecked") public javax.ws.rs.core.Response queryBeans(String query) public virtual Response QueryBeans(string query) { try { MBeanServer server = ManagementFactory.PlatformMBeanServer; string json = DodgeStartingUnicodeMarker(query); ICollection <object> queries = (ICollection <object>)JsonHelper.readJson(json); List <JmxMBeanRepresentation> beans = new List <JmxMBeanRepresentation>(); foreach (object queryObj in queries) { Debug.Assert(queryObj is string); foreach (object objName in server.queryNames(new ObjectName(( string )queryObj), null)) { beans.Add(new JmxMBeanRepresentation(( ObjectName )objName)); } } return(_output.ok(new ListRepresentation("jmxBean", beans))); } catch (Exception e) when(e is JsonParseException || e is MalformedObjectNameException) { return(_output.badRequest(e)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @PostConstruct public void postConstruct() public virtual void postConstruct() { string str1 = this.properties.getProperty("code"); string str2 = this.properties.getProperty("name"); requireNotNull(str1); requireNotNull(str2); try { MBeanServer mBeanServer = ManagementFactory.PlatformMBeanServer; ObjectName objectName = new ObjectName(str2); mBeanServer.registerMBean(this, objectName); } catch (MalformedObjectNameException malformedObjectNameException) { this.log.error("Malformed MBean name: " + str2); throw new MBeanRegistrationException(malformedObjectNameException); } catch (InstanceAlreadyExistsException instanceAlreadyExistsException) { this.log.error("Instance already exists: " + str2); throw new MBeanRegistrationException(instanceAlreadyExistsException); } catch (NotCompliantMBeanException notCompliantMBeanException) { this.log.error("Class is not a valid MBean: " + str1); throw new MBeanRegistrationException(notCompliantMBeanException); } catch (MBeanRegistrationException mBeanRegistrationException) { this.log.error("Error registering " + str2 + ", " + str1); throw new MBeanRegistrationException(mBeanRegistrationException); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @PreDestroy public void preDestroy() public virtual void preDestroy() { string str = this.properties.getProperty("name"); try { MBeanServer mBeanServer = ManagementFactory.PlatformMBeanServer; ObjectName objectName = new ObjectName(str); mBeanServer.unregisterMBean(objectName); } catch (MalformedObjectNameException malformedObjectNameException) { this.log.error("Malformed MBean name: " + str); throw new MBeanRegistrationException(malformedObjectNameException); } catch (MBeanRegistrationException mBeanRegistrationException) { this.log.error("Error unregistering " + str); throw new MBeanRegistrationException(mBeanRegistrationException); } catch (InstanceNotFoundException instanceNotFoundException) { this.log.error("Error unregistering " + str); throw new MBeanRegistrationException(instanceNotFoundException); } }
public virtual void postDeregister() { this.log.info("postDeregister()"); stop(); this.server = null; this.serviceName = null; }
/// <summary>Verify the following scenario.</summary> /// <remarks> /// Verify the following scenario. /// 1. NN restarts. /// 2. Heartbeat RPC will retry and succeed. NN asks DN to reregister. /// 3. After reregistration completes, DN will send Heartbeat, followed by /// Blockreport. /// 4. NN will mark DatanodeStorageInfo#blockContentsStale to false. /// </remarks> /// <exception cref="System.Exception"/> public virtual void TestStorageBlockContentsStaleAfterNNRestart() { MiniDFSCluster dfsCluster = null; try { Configuration config = new Configuration(); dfsCluster = new MiniDFSCluster.Builder(config).NumDataNodes(1).Build(); dfsCluster.WaitActive(); dfsCluster.RestartNameNode(true); BlockManagerTestUtil.CheckHeartbeat(dfsCluster.GetNamesystem().GetBlockManager()); MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanNameFsns = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState" ); int numStaleStorages = (int)(mbs.GetAttribute(mxbeanNameFsns, "NumStaleStorages") ); NUnit.Framework.Assert.AreEqual(0, numStaleStorages); } finally { if (dfsCluster != null) { dfsCluster.Shutdown(); } } return; }
public virtual void Test() { Configuration conf = new Configuration(); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).Build(); cluster.WaitActive(); FSNamesystem fsn = cluster.GetNameNode().namesystem; MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState" ); string snapshotStats = (string)(mbs.GetAttribute(mxbeanName, "SnapshotStats")); IDictionary <string, object> stat = (IDictionary <string, object>)JSON.Parse(snapshotStats ); NUnit.Framework.Assert.IsTrue(stat.Contains("SnapshottableDirectories") && (long) stat["SnapshottableDirectories"] == fsn.GetNumSnapshottableDirs()); NUnit.Framework.Assert.IsTrue(stat.Contains("Snapshots") && (long)stat["Snapshots" ] == fsn.GetNumSnapshots()); object pendingDeletionBlocks = mbs.GetAttribute(mxbeanName, "PendingDeletionBlocks" ); NUnit.Framework.Assert.IsNotNull(pendingDeletionBlocks); NUnit.Framework.Assert.IsTrue(pendingDeletionBlocks is long); } finally { if (cluster != null) { cluster.Shutdown(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @GET @Path(DOMAINS_PATH) public javax.ws.rs.core.Response listDomains() throws NullPointerException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual Response ListDomains() { MBeanServer server = ManagementFactory.PlatformMBeanServer; ListRepresentation domains = ListRepresentation.strings(server.Domains); return(_output.ok(domains)); }
/// <exception cref="System.Exception"/> public virtual void TestTopUsers() { Configuration conf = new Configuration(); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).Build(); cluster.WaitActive(); MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanNameFsns = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState" ); FileSystem fs = cluster.GetFileSystem(); Path path = new Path("/"); int NumOps = 10; for (int i = 0; i < NumOps; i++) { fs.ListStatus(path); fs.SetTimes(path, 0, 1); } string topUsers = (string)(mbs.GetAttribute(mxbeanNameFsns, "TopUserOpCounts")); ObjectMapper mapper = new ObjectMapper(); IDictionary <string, object> map = mapper.ReadValue <IDictionary>(topUsers); NUnit.Framework.Assert.IsTrue("Could not find map key timestamp", map.Contains("timestamp" )); NUnit.Framework.Assert.IsTrue("Could not find map key windows", map.Contains("windows" )); IList <IDictionary <string, IList <IDictionary <string, object> > > > windows = (IList <IDictionary <string, IList <IDictionary <string, object> > > >)map["windows"]; NUnit.Framework.Assert.AreEqual("Unexpected num windows", 3, windows.Count); foreach (IDictionary <string, IList <IDictionary <string, object> > > window in windows) { IList <IDictionary <string, object> > ops = window["ops"]; NUnit.Framework.Assert.AreEqual("Unexpected num ops", 3, ops.Count); foreach (IDictionary <string, object> op in ops) { long count = long.Parse(op["totalCount"].ToString()); string opType = op["opType"].ToString(); int expected; if (opType.Equals(TopConf.AllCmds)) { expected = 2 * NumOps; } else { expected = NumOps; } NUnit.Framework.Assert.AreEqual("Unexpected total count", expected, count); } } } finally { if (cluster != null) { cluster.Shutdown(); } } }
/// <exception cref="Javax.Management.MalformedObjectNameException"/> /// <exception cref="Javax.Management.MBeanException"/> /// <exception cref="Javax.Management.AttributeNotFoundException"/> /// <exception cref="Javax.Management.InstanceNotFoundException"/> /// <exception cref="Javax.Management.ReflectionException"/> private static CompositeDataSupport GetBean() { MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=NameNode,name=NameNodeInfo" ); return((CompositeDataSupport)mbs.GetAttribute(mxbeanName, "RollingUpgradeStatus")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void Setup() { _jmxServer = mock(typeof(MBeanServer)); _beanName = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference"); _attributeName = "name"; when(_jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(_beanName)); when(_jmxServer.getMBeanInfo(_beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo(_attributeName, "someType", "This is the attribute desc.", true, false, false) }, null, null, null)); }
public virtual void TestHostsExcludeInUI() { Configuration conf = GetConf(); short ReplicationFactor = 2; Path filePath = new Path("/testFile"); // Configure an excludes file FileSystem localFileSys = FileSystem.GetLocal(conf); Path workingDir = localFileSys.GetWorkingDirectory(); Path dir = new Path(workingDir, "build/test/data/temp/decommission"); Path excludeFile = new Path(dir, "exclude"); Path includeFile = new Path(dir, "include"); NUnit.Framework.Assert.IsTrue(localFileSys.Mkdirs(dir)); DFSTestUtil.WriteFile(localFileSys, excludeFile, string.Empty); DFSTestUtil.WriteFile(localFileSys, includeFile, string.Empty); conf.Set(DFSConfigKeys.DfsHostsExclude, excludeFile.ToUri().GetPath()); conf.Set(DFSConfigKeys.DfsHosts, includeFile.ToUri().GetPath()); // Two blocks and four racks string[] racks = new string[] { "/rack1", "/rack1", "/rack2", "/rack2" }; MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(racks.Length ).Racks(racks).Build(); FSNamesystem ns = cluster.GetNameNode().GetNamesystem(); try { // Create a file with one block FileSystem fs = cluster.GetFileSystem(); DFSTestUtil.CreateFile(fs, filePath, 1L, ReplicationFactor, 1L); ExtendedBlock b = DFSTestUtil.GetFirstBlock(fs, filePath); DFSTestUtil.WaitForReplication(cluster, b, 2, ReplicationFactor, 0); // Decommission one of the hosts with the block, this should cause // the block to get replicated to another host on the same rack, // otherwise the rack policy is violated. BlockLocation[] locs = fs.GetFileBlockLocations(fs.GetFileStatus(filePath), 0, long.MaxValue ); string name = locs[0].GetNames()[0]; string names = name + "\n" + "localhost:42\n"; Log.Info("adding '" + names + "' to exclude file " + excludeFile.ToUri().GetPath( )); DFSTestUtil.WriteFile(localFileSys, excludeFile, name); ns.GetBlockManager().GetDatanodeManager().RefreshNodes(conf); DFSTestUtil.WaitForDecommission(fs, name); // Check the block still has sufficient # replicas across racks DFSTestUtil.WaitForReplication(cluster, b, 2, ReplicationFactor, 0); MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=NameNode,name=NameNodeInfo" ); string nodes = (string)mbs.GetAttribute(mxbeanName, "LiveNodes"); NUnit.Framework.Assert.IsTrue("Live nodes should contain the decommissioned node" , nodes.Contains("Decommissioned")); } finally { cluster.Shutdown(); } }
public virtual void TestLastContactTime() { Configuration conf = new Configuration(); conf.SetInt(DFSConfigKeys.DfsHeartbeatIntervalKey, 1); conf.SetInt(DFSConfigKeys.DfsNamenodeHeartbeatRecheckIntervalKey, 1); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(3).Build(); cluster.WaitActive(); FSNamesystem fsn = cluster.GetNameNode().namesystem; MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=NameNode,name=NameNodeInfo" ); // Define include file to generate deadNodes metrics FileSystem localFileSys = FileSystem.GetLocal(conf); Path workingDir = localFileSys.GetWorkingDirectory(); Path dir = new Path(workingDir, "build/test/data/temp/TestNameNodeMXBean"); Path includeFile = new Path(dir, "include"); NUnit.Framework.Assert.IsTrue(localFileSys.Mkdirs(dir)); StringBuilder includeHosts = new StringBuilder(); foreach (DataNode dn in cluster.GetDataNodes()) { includeHosts.Append(dn.GetDisplayName()).Append("\n"); } DFSTestUtil.WriteFile(localFileSys, includeFile, includeHosts.ToString()); conf.Set(DFSConfigKeys.DfsHosts, includeFile.ToUri().GetPath()); fsn.GetBlockManager().GetDatanodeManager().RefreshNodes(conf); cluster.StopDataNode(0); while (fsn.GetBlockManager().GetDatanodeManager().GetNumLiveDataNodes() != 2) { Uninterruptibles.SleepUninterruptibly(1, TimeUnit.Seconds); } // get attribute deadnodeinfo string deadnodeinfo = (string)(mbs.GetAttribute(mxbeanName, "DeadNodes")); NUnit.Framework.Assert.AreEqual(fsn.GetDeadNodes(), deadnodeinfo); IDictionary <string, IDictionary <string, object> > deadNodes = (IDictionary <string, IDictionary <string, object> >)JSON.Parse(deadnodeinfo); NUnit.Framework.Assert.IsTrue(deadNodes.Count > 0); foreach (IDictionary <string, object> deadNode in deadNodes.Values) { NUnit.Framework.Assert.IsTrue(deadNode.Contains("lastContact")); NUnit.Framework.Assert.IsTrue(deadNode.Contains("decommissioned")); NUnit.Framework.Assert.IsTrue(deadNode.Contains("xferaddr")); } } finally { if (cluster != null) { cluster.Shutdown(); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public Object run() throws Exception public virtual object run() { MBeanServer mBeanServer = MBeanServerLocator.locateJBoss(); JaasSecurityDomainMBean jaasSecurityDomainMBean = (JaasSecurityDomainMBean)MBeanServerInvocationHandler.newProxyInstance(mBeanServer, this.serviceName, typeof(JaasSecurityDomainMBean), false); sbyte[] arrayOfByte = jaasSecurityDomainMBean.decode64(this.password); string str = StringHelper.NewString(arrayOfByte, "UTF-8"); return(str.ToCharArray()); }
public void RegisterMBeanPermissionTest() { DoPermissionTest( null, delegate() { IMBeanServer server = new MBeanServer(); server.RegisterMBean(new Dummy(), new ObjectName("dummy:")); }, null, null, MBeanPermissionAction.RegisterMBean, MBeanPermissionAction.UnregisterMBean); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public javax.management.ObjectName preRegister(javax.management.MBeanServer paramMBeanServer, javax.management.ObjectName paramObjectName) throws Exception public virtual ObjectName preRegister(MBeanServer paramMBeanServer, ObjectName paramObjectName) { this.server = paramMBeanServer; this.serviceName = getObjectName(paramMBeanServer, paramObjectName); this.myName = paramObjectName.getKeyProperty("name"); if (string.ReferenceEquals(this.myName, null) || this.myName.Equals("")) { this.myName = Classes.stripPackageName(this.GetType()); } this.log.info("preRegister(), chosen myName=" + this.myName + ", objectName=" + this.serviceName); return(paramObjectName); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @GET @Path(BEAN_TEMPLATE) public javax.ws.rs.core.Response getBean(@PathParam("domain") String domainName, @PathParam("objectName") String objectName) public virtual Response GetBean(string domainName, string objectName) { MBeanServer server = ManagementFactory.PlatformMBeanServer; List <JmxMBeanRepresentation> beans = new List <JmxMBeanRepresentation>(); foreach (object objName in server.queryNames(CreateObjectName(domainName, objectName), null)) { beans.Add(new JmxMBeanRepresentation(( ObjectName )objName)); } return(_output.ok(new ListRepresentation("bean", beans))); }
public override void Start() { try { ServerManagement serverManagement = new ServerManagement(_server); MBeanServer beanServer = ManagementFactory.PlatformMBeanServer; beanServer.registerMBean(serverManagement, CreateObjectName()); } catch (Exception e) { throw new Exception("Unable to initialize jmx management, see nested exception.", e); } }
public virtual MBeanServer getmBeanServer() { if (mBeanServer == null) { lock (this) { if (mBeanServer == null) { mBeanServer = createOrLookupMbeanServer(); } } } return(mBeanServer); }
public virtual void TestSecondaryWebUi() { MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=SecondaryNameNode,name=SecondaryNameNodeInfo" ); string[] checkpointDir = (string[])mbs.GetAttribute(mxbeanName, "CheckpointDirectories" ); Assert.AssertArrayEquals(checkpointDir, snn.GetCheckpointDirectories()); string[] checkpointEditlogDir = (string[])mbs.GetAttribute(mxbeanName, "CheckpointEditlogDirectories" ); Assert.AssertArrayEquals(checkpointEditlogDir, snn.GetCheckpointEditlogDirectories ()); }
public void SetAttributePermissionTest() { IMBeanServer server = null; DoPermissionTest( delegate() { server = new MBeanServer(); server.RegisterMBean(new Dummy(), new ObjectName("dummy:")); }, delegate() { server.SetAttribute(new ObjectName("dummy:"), "IntValue", 5); }, "IntValue", "DoSomething", MBeanPermissionAction.SetAttribute, MBeanPermissionAction.GetAttribute); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @GET @Path(DOMAIN_TEMPLATE) public javax.ws.rs.core.Response getDomain(@PathParam("domain") String domainName) public virtual Response GetDomain(string domainName) { MBeanServer server = ManagementFactory.PlatformMBeanServer; JmxDomainRepresentation domain = new JmxDomainRepresentation(domainName); foreach (object objName in server.queryNames(null, null)) { if (objName.ToString().StartsWith(domainName, StringComparison.Ordinal)) { domain.AddBean(( ObjectName )objName); } } return(_output.ok(domain)); }
public override void Stop() { try { MBeanServer beanServer = ManagementFactory.PlatformMBeanServer; beanServer.unregisterMBean(CreateObjectName()); } catch (InstanceNotFoundException) { // ok } catch (Exception e) { throw new Exception("Unable to shut down jmx management, see nested exception.", e); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldConvertAllStandardBeansWithoutError() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldConvertAllStandardBeansWithoutError() { // given MBeanServer jmxServer = ManagementFactory.PlatformMBeanServer; JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), jmxServer); // when RawIterator <object[], ProcedureException> result = procedure.Apply(null, new object[] { "*:*" }, _resourceTracker); // then we verify that we respond with the expected number of beans without error // .. we don't assert more than this, this is more of a smoke test to ensure // that independent of platform, we never throw exceptions even when converting every // single MBean into Neo4j types, and we always get the correct number of MBeans out. assertThat(asList(result).size(), equalTo(jmxServer.MBeanCount)); }
public virtual void TestDataNodeMXBean() { Configuration conf = new Configuration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).Build(); try { IList <DataNode> datanodes = cluster.GetDataNodes(); NUnit.Framework.Assert.AreEqual(datanodes.Count, 1); DataNode datanode = datanodes[0]; MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=DataNode,name=DataNodeInfo" ); // get attribute "ClusterId" string clusterId = (string)mbs.GetAttribute(mxbeanName, "ClusterId"); NUnit.Framework.Assert.AreEqual(datanode.GetClusterId(), clusterId); // get attribute "Version" string version = (string)mbs.GetAttribute(mxbeanName, "Version"); NUnit.Framework.Assert.AreEqual(datanode.GetVersion(), version); // get attribute "RpcPort" string rpcPort = (string)mbs.GetAttribute(mxbeanName, "RpcPort"); NUnit.Framework.Assert.AreEqual(datanode.GetRpcPort(), rpcPort); // get attribute "HttpPort" string httpPort = (string)mbs.GetAttribute(mxbeanName, "HttpPort"); NUnit.Framework.Assert.AreEqual(datanode.GetHttpPort(), httpPort); // get attribute "NamenodeAddresses" string namenodeAddresses = (string)mbs.GetAttribute(mxbeanName, "NamenodeAddresses" ); NUnit.Framework.Assert.AreEqual(datanode.GetNamenodeAddresses(), namenodeAddresses ); // get attribute "getVolumeInfo" string volumeInfo = (string)mbs.GetAttribute(mxbeanName, "VolumeInfo"); NUnit.Framework.Assert.AreEqual(ReplaceDigits(datanode.GetVolumeInfo()), ReplaceDigits (volumeInfo)); // Ensure mxbean's XceiverCount is same as the DataNode's // live value. int xceiverCount = (int)mbs.GetAttribute(mxbeanName, "XceiverCount"); NUnit.Framework.Assert.AreEqual(datanode.GetXceiverCount(), xceiverCount); } finally { if (cluster != null) { cluster.Shutdown(); } } }
public virtual void TestHostsIncludeForDeadCount() { Configuration conf = GetConf(); // Configure an excludes file FileSystem localFileSys = FileSystem.GetLocal(conf); Path workingDir = localFileSys.GetWorkingDirectory(); Path dir = new Path(workingDir, "build/test/data/temp/decommission"); Path excludeFile = new Path(dir, "exclude"); Path includeFile = new Path(dir, "include"); NUnit.Framework.Assert.IsTrue(localFileSys.Mkdirs(dir)); StringBuilder includeHosts = new StringBuilder(); includeHosts.Append("localhost:52").Append("\n").Append("127.0.0.1:7777").Append( "\n"); DFSTestUtil.WriteFile(localFileSys, excludeFile, string.Empty); DFSTestUtil.WriteFile(localFileSys, includeFile, includeHosts.ToString()); conf.Set(DFSConfigKeys.DfsHostsExclude, excludeFile.ToUri().GetPath()); conf.Set(DFSConfigKeys.DfsHosts, includeFile.ToUri().GetPath()); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).Build(); FSNamesystem ns = cluster.GetNameNode().GetNamesystem(); NUnit.Framework.Assert.IsTrue(ns.GetNumDeadDataNodes() == 2); NUnit.Framework.Assert.IsTrue(ns.GetNumLiveDataNodes() == 0); // Testing using MBeans MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState" ); string nodes = mbs.GetAttribute(mxbeanName, "NumDeadDataNodes") + string.Empty; NUnit.Framework.Assert.IsTrue((int)mbs.GetAttribute(mxbeanName, "NumDeadDataNodes" ) == 2); NUnit.Framework.Assert.IsTrue((int)mbs.GetAttribute(mxbeanName, "NumLiveDataNodes" ) == 0); } finally { if (cluster != null) { cluster.Shutdown(); } } }
/// <exception cref="System.Exception"/> public virtual void TestTimeoutMetric() { Configuration conf = new HdfsConfiguration(); Path path = new Path("/test"); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(2).Build(); IList <FSDataOutputStream> streams = Lists.NewArrayList(); try { FSDataOutputStream @out = cluster.GetFileSystem().Create(path, (short)2); DataNodeFaultInjector injector = Org.Mockito.Mockito.Mock <DataNodeFaultInjector>( ); Org.Mockito.Mockito.DoThrow(new IOException("mock IOException")).When(injector).WriteBlockAfterFlush (); DataNodeFaultInjector.instance = injector; streams.AddItem(@out); @out.WriteBytes("old gs data\n"); @out.Hflush(); /* Test the metric. */ MetricsRecordBuilder dnMetrics = MetricsAsserts.GetMetrics(cluster.GetDataNodes() [0].GetMetrics().Name()); MetricsAsserts.AssertCounter("DatanodeNetworkErrors", 1L, dnMetrics); /* Test JMX datanode network counts. */ MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=DataNode,name=DataNodeInfo" ); object dnc = mbs.GetAttribute(mxbeanName, "DatanodeNetworkCounts"); string allDnc = dnc.ToString(); NUnit.Framework.Assert.IsTrue("expected to see loopback address", allDnc.IndexOf( "127.0.0.1") >= 0); NUnit.Framework.Assert.IsTrue("expected to see networkErrors", allDnc.IndexOf("networkErrors" ) >= 0); } finally { IOUtils.Cleanup(Log, Sharpen.Collections.ToArray(streams, new IDisposable[0])); if (cluster != null) { cluster.Shutdown(); } DataNodeFaultInjector.instance = new DataNodeFaultInjector(); } }