示例#1
0
        public IHttpActionResult PutDiskChecker(int id, DiskChecker diskChecker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != diskChecker.ID)
            {
                return(BadRequest());
            }

            db.Entry(diskChecker).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DiskCheckerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public ActionResult DeleteConfirmed(int id)
        {
            DiskChecker diskChecker = db.DiskCheckers.Find(id);

            db.DiskCheckers.Remove(diskChecker);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
 /// <exception cref="System.IO.IOException"/>
 private static void ValidateAndCreateJournalDir(FilePath dir)
 {
     if (!dir.IsAbsolute())
     {
         throw new ArgumentException("Journal dir '" + dir + "' should be an absolute path"
                                     );
     }
     DiskChecker.CheckDir(dir);
 }
示例#4
0
 public ActionResult Edit([Bind(Include = "ID,ServerName,DriveLetter,LowDiskPercentage,PollTime,AdminEmailAlert,AlertSubscribers,SubcriptionEmailAddresses,Disable,ShowOnDash,LastRan,DriveSize,AvailableSpace,IgnorePollTimeOnNextRun")] DiskChecker diskChecker)
 {
     if (ModelState.IsValid)
     {
         db.Entry(diskChecker).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(diskChecker));
 }
示例#5
0
        public IHttpActionResult GetDiskChecker(int id)
        {
            DiskChecker diskChecker = db.DiskCheckers.Find(id);

            if (diskChecker == null)
            {
                return(NotFound());
            }

            return(Ok(diskChecker));
        }
示例#6
0
        public IHttpActionResult PostDiskChecker(DiskChecker diskChecker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.DiskCheckers.Add(diskChecker);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = diskChecker.ID }, diskChecker));
        }
示例#7
0
 /// <summary>
 /// This method gets called everytime before any read/write to make sure
 /// that any change to localDirs is reflected immediately.
 /// </summary>
 /// <exception cref="System.IO.IOException"/>
 private void ConfChanged(Configuration conf)
 {
     lock (this)
     {
         string newLocalDirs = conf.Get(contextCfgItemName);
         if (!newLocalDirs.Equals(savedLocalDirs))
         {
             localDirs = StringUtils.GetTrimmedStrings(newLocalDirs);
             localFS   = FileSystem.GetLocal(conf);
             int            numDirs = localDirs.Length;
             AList <string> dirs    = new AList <string>(numDirs);
             AList <DF>     dfList  = new AList <DF>(numDirs);
             for (int i = 0; i < numDirs; i++)
             {
                 try
                 {
                     // filter problematic directories
                     Path tmpDir = new Path(localDirs[i]);
                     if (localFS.Mkdirs(tmpDir) || localFS.Exists(tmpDir))
                     {
                         try
                         {
                             FilePath tmpFile = tmpDir.IsAbsolute() ? new FilePath(localFS.MakeQualified(tmpDir
                                                                                                         ).ToUri()) : new FilePath(localDirs[i]);
                             DiskChecker.CheckDir(tmpFile);
                             dirs.AddItem(tmpFile.GetPath());
                             dfList.AddItem(new DF(tmpFile, 30000));
                         }
                         catch (DiskChecker.DiskErrorException de)
                         {
                             Log.Warn(localDirs[i] + " is not writable\n", de);
                         }
                     }
                     else
                     {
                         Log.Warn("Failed to create " + localDirs[i]);
                     }
                 }
                 catch (IOException ie)
                 {
                     Log.Warn("Failed to create " + localDirs[i] + ": " + ie.Message + "\n", ie);
                 }
             }
             //ignore
             localDirs      = Collections.ToArray(dirs, new string[dirs.Count]);
             dirDF          = Collections.ToArray(dfList, new DF[dirs.Count]);
             savedLocalDirs = newLocalDirs;
             // randomize the first disk picked in the round-robin selection
             dirNumLastAccessed = dirIndexRandomizer.Next(dirs.Count);
         }
     }
 }
示例#8
0
        public IHttpActionResult DeleteDiskChecker(int id)
        {
            DiskChecker diskChecker = db.DiskCheckers.Find(id);

            if (diskChecker == null)
            {
                return(NotFound());
            }

            db.DiskCheckers.Remove(diskChecker);
            db.SaveChanges();

            return(Ok(diskChecker));
        }
示例#9
0
        // GET: DiskCheckers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DiskChecker diskChecker = db.DiskCheckers.Find(id);

            if (diskChecker == null)
            {
                return(HttpNotFound());
            }
            return(View(diskChecker));
        }
示例#10
0
        internal virtual IDictionary <string, DirectoryCollection.DiskErrorInformation> TestDirs
            (IList <string> dirs)
        {
            Dictionary <string, DirectoryCollection.DiskErrorInformation> ret = new Dictionary
                                                                                <string, DirectoryCollection.DiskErrorInformation>();

            foreach (string dir in dirs)
            {
                string msg;
                try
                {
                    FilePath testDir = new FilePath(dir);
                    DiskChecker.CheckDir(testDir);
                    if (IsDiskUsageOverPercentageLimit(testDir))
                    {
                        msg      = "used space above threshold of " + diskUtilizationPercentageCutoff + "%";
                        ret[dir] = new DirectoryCollection.DiskErrorInformation(DirectoryCollection.DiskErrorCause
                                                                                .DiskFull, msg);
                        continue;
                    }
                    else
                    {
                        if (IsDiskFreeSpaceUnderLimit(testDir))
                        {
                            msg      = "free space below limit of " + diskUtilizationSpaceCutoff + "MB";
                            ret[dir] = new DirectoryCollection.DiskErrorInformation(DirectoryCollection.DiskErrorCause
                                                                                    .DiskFull, msg);
                            continue;
                        }
                    }
                    // create a random dir to make sure fs isn't in read-only mode
                    VerifyDirUsingMkdir(testDir);
                }
                catch (IOException ie)
                {
                    ret[dir] = new DirectoryCollection.DiskErrorInformation(DirectoryCollection.DiskErrorCause
                                                                            .Other, ie.Message);
                }
            }
            return(ret);
        }
示例#11
0
        /// <summary>
        /// Function to test whether a dir is working correctly by actually creating a
        /// random directory.
        /// </summary>
        /// <param name="dir">the dir to test</param>
        /// <exception cref="System.IO.IOException"/>
        private void VerifyDirUsingMkdir(FilePath dir)
        {
            string   randomDirName = RandomStringUtils.RandomAlphanumeric(5);
            FilePath target        = new FilePath(dir, randomDirName);
            int      i             = 0;

            while (target.Exists())
            {
                randomDirName = RandomStringUtils.RandomAlphanumeric(5) + i;
                target        = new FilePath(dir, randomDirName);
                i++;
            }
            try
            {
                DiskChecker.CheckDir(target);
            }
            finally
            {
                FileUtils.DeleteQuietly(target);
            }
        }
示例#12
0
            /// <exception cref="System.IO.IOException"/>
            private Path CreatePath(string path, bool checkWrite)
            {
                Path file = new Path(new Path(localDirs[dirNumLastAccessed]), path);

                if (checkWrite)
                {
                    //check whether we are able to create a directory here. If the disk
                    //happens to be RDONLY we will fail
                    try
                    {
                        DiskChecker.CheckDir(new FilePath(file.GetParent().ToUri().GetPath()));
                        return(file);
                    }
                    catch (DiskChecker.DiskErrorException d)
                    {
                        Log.Warn("Disk Error Exception: ", d);
                        return(null);
                    }
                }
                return(file);
            }
示例#13
0
        /// <summary>
        /// Search disks.
        /// </summary>
        private async Task SearchAsync()
        {
            try
            {
                List <DiskInfo> diskRosterPre = null;

                // Get disk information by WMI.
                var searchTask = Task.Run(() => DiskSearcher.Search());

                try
                {
                    diskRosterPre = await searchTask;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Failed to get disk information by WMI. {0}", ex);

                    if (searchTask.Exception != null)
                    {
                        searchTask.Exception.Flatten().InnerExceptions
                        .ToList()
                        .ForEach(x => Debug.WriteLine(x));
                    }
                }

                if (diskRosterPre == null)
                {
                    return;
                }

                // Sort by PhysicalDrive.
                diskRosterPre.Sort();

                foreach (var infoPre in diskRosterPre)
                {
                    DiskInfo infoNew = null;

                    // Add disk information by P/Invoke.
                    var physicalDrive = infoPre.PhysicalDrive;

                    var checkTask = Task.Run(() => DiskChecker.GetDiskInfo(physicalDrive));

                    try
                    {
                        infoNew = await checkTask;
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Failed to get disk information by P/Invoke. {0}", ex);

                        if (checkTask.Exception != null)
                        {
                            checkTask.Exception.Flatten().InnerExceptions
                            .ToList()
                            .ForEach(x => Debug.WriteLine(x));
                        }
                    }

                    if (infoNew == null)
                    {
                        infoNew = new DiskInfo {
                            PhysicalDrive = infoPre.PhysicalDrive
                        };
                    }

                    infoNew.Model                 = infoPre.Model;
                    infoNew.InterfaceType         = infoPre.InterfaceType;
                    infoNew.MediaTypeDiskDrive    = infoPre.MediaTypeDiskDrive;
                    infoNew.MediaTypePhysicalDisk = infoPre.MediaTypePhysicalDisk;
                    infoNew.SpindleSpeed          = infoPre.SpindleSpeed;
                    infoNew.SizeWMI               = infoPre.SizeWMI;

                    // Add disk information to disk roster.
                    int index = 0;

                    if (_diskRoster.Any())
                    {
                        while ((index < _diskRoster.Count) && (infoNew.PhysicalDrive > _diskRoster[index].PhysicalDrive))
                        {
                            index++;
                        }
                    }

                    _diskRoster.Insert(index, infoNew);
                    DiskRosterNames.Insert(index, infoNew.NameBus);

                    if (index == 0)
                    {
                        DiskRosterNamesIndex = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to search disks {0}", ex);
            }
        }
示例#14
0
 /// <exception cref="System.IO.IOException"/>
 internal virtual Callable <Path> Download(Path path, LocalResource rsrc, UserGroupInformation
                                           ugi)
 {
     DiskChecker.CheckDir(new FilePath(path.ToUri().GetRawPath()));
     return(new FSDownload(lfs, ugi, conf, path, rsrc));
 }
示例#15
0
 /// <exception cref="Org.Apache.Hadoop.Util.DiskChecker.DiskErrorException"/>
 internal virtual void CheckDirs()
 {
     DiskChecker.CheckDirs(finalizedDir);
     DiskChecker.CheckDir(tmpDir);
     DiskChecker.CheckDir(rbwDir);
 }