示例#1
0
        /// <summary>Delete a directory/directory tree.</summary>
        /// <remarks>
        /// Delete a directory/directory tree.
        /// It is not an error to delete a path that does not exist
        /// </remarks>
        /// <param name="path">path of operation</param>
        /// <param name="recursive">flag to trigger recursive deletion</param>
        /// <param name="backgroundCallback">
        /// callback; this being set converts the operation
        /// into an async/background operation.
        /// task
        /// </param>
        /// <exception cref="System.IO.IOException">on problems other than no-such-path</exception>
        public virtual void ZkDelete(string path, bool recursive, BackgroundCallback backgroundCallback
                                     )
        {
            CheckServiceLive();
            string fullpath = CreateFullPath(path);

            try
            {
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Deleting {}", fullpath);
                }
                DeleteBuilder delete = curator.Delete();
                if (recursive)
                {
                    delete.DeletingChildrenIfNeeded();
                }
                if (backgroundCallback != null)
                {
                    delete.InBackground(backgroundCallback);
                }
                delete.ForPath(fullpath);
            }
            catch (KeeperException.NoNodeException)
            {
            }
            catch (Exception e)
            {
                // not an error
                throw OperationFailure(fullpath, "delete()", e);
            }
        }
 public AsyncPurge(RegistryAdminService _enclosing, string path, RegistryAdminService.NodeSelector
                   selector, RegistryAdminService.PurgePolicy purgePolicy, BackgroundCallback callback
                   )
 {
     this._enclosing  = _enclosing;
     this.callback    = callback;
     this.selector    = selector;
     this.path        = path;
     this.purgePolicy = purgePolicy;
 }
示例#3
0
        private void background(BackgroundCallback callback)
        {
//			backgroundCompleted = false;
            backgroundWorker1 = new BackgroundWorker();
            backgroundWorker1.WorkerReportsProgress = true;
            backgroundWorker1.DoWork             += new DoWorkEventHandler(callback);
            backgroundWorker1.ProgressChanged    += new ProgressChangedEventHandler(backgroundProgress);
            backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundDone);
            backgroundWorker1.RunWorkerAsync();
            Cursor = Cursors.WaitCursor;
        }
示例#4
0
 private void background(BackgroundCallback callback)
 {
     statusText.Text      = "-";
     statusProgress.Value = 0;
     _worker = new BackgroundWorker();
     _worker.WorkerReportsProgress = true;
     _worker.DoWork             += new DoWorkEventHandler(callback);
     _worker.ProgressChanged    += new ProgressChangedEventHandler(backgroundProgress);
     _worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundDone);
     _worker.RunWorkerAsync();
     Cursor = Cursors.WaitCursor;
 }
示例#5
0
        /// <summary>trigger a purge operation</summary>
        /// <param name="path">pathn</param>
        /// <param name="id">yarn ID</param>
        /// <param name="policyMatch">policy to match ID on</param>
        /// <param name="purgePolicy">policy when there are children under a match</param>
        /// <param name="callback">optional callback</param>
        /// <returns>the number purged</returns>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Sharpen.ExecutionException"/>
        /// <exception cref="System.Exception"/>
        public virtual int Purge(string path, string id, string policyMatch, RegistryAdminService.PurgePolicy
                                 purgePolicy, BackgroundCallback callback)
        {
            Future <int> future = registry.PurgeRecordsAsync(path, id, policyMatch, purgePolicy
                                                             , callback);

            try
            {
                return(future.Get());
            }
            catch (ExecutionException e)
            {
                if (e.InnerException is IOException)
                {
                    throw (IOException)e.InnerException;
                }
                else
                {
                    throw;
                }
            }
        }
        public virtual int Purge(string path, RegistryAdminService.NodeSelector selector,
                                 RegistryAdminService.PurgePolicy purgePolicy, BackgroundCallback callback)
        {
            bool toDelete = false;
            // look at self to see if it has a service record
            IDictionary <string, RegistryPathStatus> childEntries;
            ICollection <RegistryPathStatus>         entries;

            try
            {
                // list this path's children
                childEntries = RegistryUtils.StatChildren(this, path);
                entries      = childEntries.Values;
            }
            catch (PathNotFoundException)
            {
                // there's no record here, it may have been deleted already.
                // exit
                return(0);
            }
            try
            {
                RegistryPathStatus registryPathStatus = Stat(path);
                ServiceRecord      serviceRecord      = Resolve(path);
                // there is now an entry here.
                toDelete = selector.ShouldSelect(path, registryPathStatus, serviceRecord);
            }
            catch (EOFException)
            {
            }
            catch (InvalidRecordException)
            {
            }
            catch (NoRecordException)
            {
            }
            catch (PathNotFoundException)
            {
                // ignore
                // ignore
                // ignore
                // there's no record here, it may have been deleted already.
                // exit
                return(0);
            }
            if (toDelete && !entries.IsEmpty())
            {
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Match on record @ {} with children ", path);
                }
                switch (purgePolicy)
                {
                case RegistryAdminService.PurgePolicy.SkipOnChildren:
                {
                    // there's children
                    // don't do the deletion... continue to next record
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Skipping deletion");
                    }
                    toDelete = false;
                    break;
                }

                case RegistryAdminService.PurgePolicy.PurgeAll:
                {
                    // mark for deletion
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Scheduling for deletion with children");
                    }
                    toDelete = true;
                    entries  = new AList <RegistryPathStatus>(0);
                    break;
                }

                case RegistryAdminService.PurgePolicy.FailOnChildren:
                {
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Failing deletion operation");
                    }
                    throw new PathIsNotEmptyDirectoryException(path);
                }
                }
            }
            int deleteOps = 0;

            if (toDelete)
            {
                try
                {
                    ZkDelete(path, true, callback);
                }
                catch (PathNotFoundException)
                {
                    // sign that the path was deleted during the operation.
                    // this is a no-op, and all children can be skipped
                    return(deleteOps);
                }
                deleteOps++;
            }
            // now go through the children
            foreach (RegistryPathStatus status in entries)
            {
                string childname = status.path;
                string childpath = RegistryPathUtils.Join(path, childname);
                deleteOps += Purge(childpath, selector, purgePolicy, callback);
            }
            return(deleteOps);
        }
示例#7
0
 public virtual Future <int> PurgeRecordsAsync(string path, string id, string persistencePolicyMatch
                                               , RegistryAdminService.PurgePolicy purgePolicy, BackgroundCallback callback)
 {
     Log.Info(" records under {} with ID {} and policy {}: {}", path, id, persistencePolicyMatch
              );
     return(Submit(new RegistryAdminService.AsyncPurge(this, path, new SelectByYarnPersistence
                                                           (id, persistencePolicyMatch), purgePolicy, callback)));
 }