Esempio n. 1
0
        public string StudentInformation(string studentName)
        {
            var classSubjectsService = ManagementFactory.ClassSubjectDetailsService();
            var gradesManagement     = ManagementFactory.GradesManagement();

            List <int> ClassSubjectIdList = new List <int>();
            string     studentInfo        = "";

            if (DataFactory.GetStudent().RetrieveObjects().Exists(x => x.Name == studentName))
            {
                int studentId      = ManagementFactory.StudentDetailsService().GetStudentId(studentName);
                var studentRecords = DataFactory.GetGrades().RetrieveObjects().Where(x => x.StudentId == studentId);

                studentInfo += "\n" + studentName + " is attending the following classes: \n";

                foreach (var gradeId in studentRecords)
                {
                    ClassSubjectIdList.Add(gradeId.ClassId);
                }

                foreach (var classSubjectId in ClassSubjectIdList.Distinct().ToList())
                {
                    studentInfo += classSubjectsService.GetClassSubjectName(classSubjectId)
                                   + " with " + gradesManagement.PersonalToClassGradeComparer(classSubjectId, studentId, Enums.GradeType.Highest)
                                   + " and " + gradesManagement.PersonalToClassGradeComparer(classSubjectId, studentId, Enums.GradeType.Average)
                                   + "\n";
                }
            }
            else
            {
                studentInfo = "Enter valid student name, please.";
            }
            return(studentInfo);
        }
Esempio n. 2
0
        /// <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();
                }
            }
        }
Esempio n. 3
0
        /// <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;
        }
Esempio n. 4
0
        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();
                }
            }
        }
Esempio n. 5
0
        public virtual void TestNameNode()
        {
            int numDatanodes = 2;

            cluster = new MiniDFSCluster.Builder(config).NumDataNodes(numDatanodes).Build();
            cluster.WaitActive();
            WriteFile(cluster.GetFileSystem(), new Path("/test1"), 2);
            JMXGet jmx         = new JMXGet();
            string serviceName = "NameNode";

            jmx.SetService(serviceName);
            jmx.Init();
            // default lists namenode mbeans only
            NUnit.Framework.Assert.IsTrue("error printAllValues", CheckPrintAllValues(jmx));
            //get some data from different source
            NUnit.Framework.Assert.AreEqual(numDatanodes, System.Convert.ToInt32(jmx.GetValue
                                                                                     ("NumLiveDataNodes")));
            MetricsAsserts.AssertGauge("CorruptBlocks", long.Parse(jmx.GetValue("CorruptBlocks"
                                                                                )), MetricsAsserts.GetMetrics("FSNamesystem"));
            NUnit.Framework.Assert.AreEqual(numDatanodes, System.Convert.ToInt32(jmx.GetValue
                                                                                     ("NumOpenConnections")));
            cluster.Shutdown();
            MBeanServerConnection    mbsc  = ManagementFactory.GetPlatformMBeanServer();
            ObjectName               query = new ObjectName("Hadoop:service=" + serviceName + ",*");
            ICollection <ObjectName> names = mbsc.QueryNames(query, null);

            NUnit.Framework.Assert.IsTrue("No beans should be registered for " + serviceName,
                                          names.IsEmpty());
        }
Esempio n. 6
0
 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)
     {
     }
 }
Esempio n. 7
0
        /// <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);
        }
Esempio n. 8
0
        /// <summary>
        /// To ensure there are not multiple instances of the SCM running on a given
        /// cluster, a global pid file is used.
        /// </summary>
        /// <remarks>
        /// To ensure there are not multiple instances of the SCM running on a given
        /// cluster, a global pid file is used. This file contains the hostname of the
        /// machine that owns the pid file.
        /// </remarks>
        /// <returns>true if the pid file was written, false otherwise</returns>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private bool WriteGlobalCleanerPidFile()
        {
            string root = conf.Get(YarnConfiguration.SharedCacheRoot, YarnConfiguration.DefaultSharedCacheRoot
                                   );
            Path pidPath = new Path(root, GlobalCleanerPid);

            try
            {
                FileSystem fs = FileSystem.Get(this.conf);
                if (fs.Exists(pidPath))
                {
                    return(false);
                }
                FSDataOutputStream os = fs.Create(pidPath, false);
                // write the hostname and the process id in the global cleaner pid file
                string Id = ManagementFactory.GetRuntimeMXBean().GetName();
                os.WriteUTF(Id);
                os.Close();
                // add it to the delete-on-exit to ensure it gets deleted when the JVM
                // exits
                fs.DeleteOnExit(pidPath);
            }
            catch (IOException e)
            {
                throw new YarnException(e);
            }
            Log.Info("Created the global cleaner pid file at " + pidPath.ToString());
            return(true);
        }
Esempio n. 9
0
        /// <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();
                }
            }
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long estimatedSize(org.neo4j.diagnostics.DiagnosticsReporterProgress progress) throws java.io.IOException
            public long estimatedSize(DiagnosticsReporterProgress progress)
            {
                MemoryMXBean bean        = ManagementFactory.getPlatformMXBean(_outerInstance.mBeanServer, typeof(MemoryMXBean));
                long         totalMemory = bean.HeapMemoryUsage.Committed + bean.NonHeapMemoryUsage.Committed;

                // We first write raw to disk then write to archive, 5x compression is a reasonable worst case estimation
                return(( long )(totalMemory * 1.2));
            }
Esempio n. 11
0
        /// <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"));
        }
Esempio n. 12
0
 public override void Start()
 {
     foreach (BufferPoolMXBean pool in ManagementFactory.getPlatformMXBeans(typeof(BufferPoolMXBean)))
     {
         _registry.register(name(MemoryBuffer, PrettifyName(pool.Name), "count"), (Gauge <long>)pool.getCount);
         _registry.register(name(MemoryBuffer, PrettifyName(pool.Name), "used"), (Gauge <long>)pool.getMemoryUsed);
         _registry.register(name(MemoryBuffer, PrettifyName(pool.Name), "capacity"), (Gauge <long>)pool.getTotalCapacity);
     }
 }
        /**
         * Create the memory manager.
         * @param poolSize the size of the pool.
         */
        public MemoryManager(long poolSize)
        {
#if false
            double maxLoad = OrcConf.MEMORY_POOL.getDouble(conf);
            totalMemoryPool = Math.Round(ManagementFactory.getMemoryMXBean().
                                         getHeapMemoryUsage().getMax() * maxLoad);
#endif
            totalMemoryPool = poolSize;
        }
Esempio n. 14
0
        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();
            }
        }
Esempio n. 15
0
        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();
                }
            }
        }
Esempio n. 16
0
        private IDictionary <string, JvmPauseMonitor.GcTimes> GetGcTimes()
        {
            IDictionary <string, JvmPauseMonitor.GcTimes> map = Maps.NewHashMap();
            IList <GarbageCollectorMXBean> gcBeans            = ManagementFactory.GetGarbageCollectorMXBeans
                                                                    ();

            foreach (GarbageCollectorMXBean gcBean in gcBeans)
            {
                map[gcBean.GetName()] = new JvmPauseMonitor.GcTimes(gcBean);
            }
            return(map);
        }
Esempio n. 17
0
        /// <summary>Get CPU time in nanoseconds. </summary>
        static public long getCpuTime(long id)
        {
            ThreadMXBean bean = ManagementFactory.getThreadMXBean();

            if (!bean.isThreadCpuTimeSupported())
            {
                return(0L);
            }
            else
            {
                return(bean.getThreadCpuTime(id));
            }
        }
Esempio n. 18
0
        private void DoMemoryUpdates()
        {
            MemoryMXBean memoryMXBean = ManagementFactory.GetMemoryMXBean();
            MemoryUsage  memNonHeap   = memoryMXBean.GetNonHeapMemoryUsage();
            MemoryUsage  memHeap      = memoryMXBean.GetHeapMemoryUsage();
            Runtime      runtime      = Runtime.GetRuntime();

            metrics.SetMetric("memNonHeapUsedM", memNonHeap.GetUsed() / M);
            metrics.SetMetric("memNonHeapCommittedM", memNonHeap.GetCommitted() / M);
            metrics.SetMetric("memHeapUsedM", memHeap.GetUsed() / M);
            metrics.SetMetric("memHeapCommittedM", memHeap.GetCommitted() / M);
            metrics.SetMetric("maxMemoryM", runtime.MaxMemory() / M);
        }
Esempio n. 19
0
        public void testConfig()
        {
            Configuration conf = new Configuration();

            conf.set("hive.exec.orc.memory.pool", "0.9");
            MemoryManager mgr = new MemoryManager(conf);
            long          mem = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax();

            System.Console.WriteLine("Memory = " + mem);
            long pool = mgr.getTotalMemoryPool();

            Assert.True("Pool too small: " + pool, mem * 0.899 < pool);
            Assert.True("Pool too big: " + pool, pool < mem * 0.901);
        }
Esempio n. 20
0
        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
                                         ());
        }
Esempio n. 21
0
            public bool Get()
            {
                ThreadMXBean threadBean = ManagementFactory.GetThreadMXBean();

                ThreadInfo[] threads = threadBean.GetThreadInfo(threadBean.GetAllThreadIds(), 1);
                foreach (ThreadInfo thread in threads)
                {
                    if (thread.GetThreadName().StartsWith("TransferFsImageUpload"))
                    {
                        return(false);
                    }
                }
                return(true);
            }
Esempio n. 22
0
        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();
                }
            }
        }
Esempio n. 23
0
        private void DoGarbageCollectionUpdates()
        {
            IList <GarbageCollectorMXBean> gcBeans = ManagementFactory.GetGarbageCollectorMXBeans
                                                         ();
            long count      = 0;
            long timeMillis = 0;

            foreach (GarbageCollectorMXBean gcBean in gcBeans)
            {
                count      += gcBean.GetCollectionCount();
                timeMillis += gcBean.GetCollectionTime();
            }
            metrics.IncrMetric("gcCount", (int)(count - gcCount));
            metrics.IncrMetric("gcTimeMillis", (int)(timeMillis - gcTimeMillis));
            gcCount      = count;
            gcTimeMillis = timeMillis;
        }
Esempio n. 24
0
        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();
                }
            }
        }
            public virtual void Run()
            {
                long startTime = ManagementFactory.GetThreadMXBean().GetThreadCpuTime(jvmThreadId);

                foreach (T datum in queue)
                {
                    localLogLikelihood += fn.GetSummaryForInstance(datum, weights, localDerivative);
                    // Check for user interrupt
                    if (mainWorker.isFinished)
                    {
                        return;
                    }
                }
                finishedAtTime = Runtime.CurrentTimeMillis();
                long endTime = ManagementFactory.GetThreadMXBean().GetThreadCpuTime(jvmThreadId);

                cpuTimeRequired = endTime - startTime;
            }
Esempio n. 26
0
        /// <summary>
        /// Assert that there are no threads running whose name matches the
        /// given regular expression.
        /// </summary>
        /// <param name="regex">the regex to match against</param>
        public static void AssertNoThreadsMatching(string regex)
        {
            Pattern      pattern    = Pattern.Compile(regex);
            ThreadMXBean threadBean = ManagementFactory.GetThreadMXBean();

            ThreadInfo[] infos = threadBean.GetThreadInfo(threadBean.GetAllThreadIds(), 20);
            foreach (ThreadInfo info in infos)
            {
                if (info == null)
                {
                    continue;
                }
                if (pattern.Matcher(info.GetThreadName()).Matches())
                {
                    NUnit.Framework.Assert.Fail("Leaked thread: " + info + "\n" + Joiner.On("\n").Join
                                                    (info.GetStackTrace()));
                }
            }
        }
Esempio n. 27
0
        /// <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();
            }
        }
Esempio n. 28
0
        public static void Unregister(ObjectName mbeanName)
        {
            Log.Debug("Unregistering " + mbeanName);
            MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer();

            if (mbeanName == null)
            {
                Log.Debug("Stacktrace: ", new Exception());
                return;
            }
            try
            {
                mbs.UnregisterMBean(mbeanName);
            }
            catch (Exception e)
            {
                Log.Warn("Error unregistering " + mbeanName, e);
            }
            DefaultMetricsSystem.RemoveMBeanName(mbeanName);
        }
Esempio n. 29
0
        public virtual void TestSnapshotStatsMXBeanInfo()
        {
            Configuration  conf     = new Configuration();
            MiniDFSCluster cluster  = null;
            string         pathName = "/snapshot";
            Path           path     = new Path(pathName);

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).Build();
                cluster.WaitActive();
                SnapshotManager       sm  = cluster.GetNamesystem().GetSnapshotManager();
                DistributedFileSystem dfs = (DistributedFileSystem)cluster.GetFileSystem();
                dfs.Mkdirs(path);
                dfs.AllowSnapshot(path);
                dfs.CreateSnapshot(path);
                MBeanServer mbs        = ManagementFactory.GetPlatformMBeanServer();
                ObjectName  mxbeanName = new ObjectName("Hadoop:service=NameNode,name=SnapshotInfo"
                                                        );
                CompositeData[] directories = (CompositeData[])mbs.GetAttribute(mxbeanName, "SnapshottableDirectories"
                                                                                );
                int numDirectories = Sharpen.Runtime.GetArrayLength(directories);
                NUnit.Framework.Assert.AreEqual(sm.GetNumSnapshottableDirs(), numDirectories);
                CompositeData[] snapshots = (CompositeData[])mbs.GetAttribute(mxbeanName, "Snapshots"
                                                                              );
                int numSnapshots = Sharpen.Runtime.GetArrayLength(snapshots);
                NUnit.Framework.Assert.AreEqual(sm.GetNumSnapshots(), numSnapshots);
                CompositeData d = (CompositeData)Sharpen.Runtime.GetArrayValue(directories, 0);
                CompositeData s = (CompositeData)Sharpen.Runtime.GetArrayValue(snapshots, 0);
                NUnit.Framework.Assert.IsTrue(((string)d.Get("path")).Contains(pathName));
                NUnit.Framework.Assert.IsTrue(((string)s.Get("snapshotDirectory")).Contains(pathName
                                                                                            ));
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Esempio n. 30
0
        public static void UnregisterMBean(ObjectName mbeanName)
        {
            MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer();

            if (mbeanName == null)
            {
                return;
            }
            try
            {
                mbs.UnregisterMBean(mbeanName);
            }
            catch (InstanceNotFoundException)
            {
            }
            catch (Exception e)
            {
                // ignore
                Runtime.PrintStackTrace(e);
            }
        }