Esempio n. 1
0
        public virtual void TestProcessEvictableResource()
        {
            FileSystem     fs      = Org.Mockito.Mockito.Mock <FileSystem>();
            CleanerMetrics metrics = Org.Mockito.Mockito.Mock <CleanerMetrics>();
            SCMStore       store   = Org.Mockito.Mockito.Mock <SCMStore>();
            CleanerTask    task    = CreateSpiedTask(fs, store, metrics, new ReentrantLock());

            // mock an evictable resource
            Org.Mockito.Mockito.When(store.IsResourceEvictable(Matchers.IsA <string>(), Matchers.IsA
                                                               <FileStatus>())).ThenReturn(true);
            FileStatus status = Org.Mockito.Mockito.Mock <FileStatus>();

            Org.Mockito.Mockito.When(status.GetPath()).ThenReturn(new Path(Root + "/a/b/c/abc"
                                                                           ));
            Org.Mockito.Mockito.When(store.RemoveResource(Matchers.IsA <string>())).ThenReturn
                (true);
            // rename succeeds
            Org.Mockito.Mockito.When(fs.Rename(Matchers.IsA <Path>(), Matchers.IsA <Path>())).ThenReturn
                (true);
            // delete returns true
            Org.Mockito.Mockito.When(fs.Delete(Matchers.IsA <Path>(), Matchers.AnyBoolean())).
            ThenReturn(true);
            // process the resource
            task.ProcessSingleResource(status);
            // the directory should be renamed
            Org.Mockito.Mockito.Verify(fs).Rename(Matchers.Eq(status.GetPath()), Matchers.IsA
                                                  <Path>());
            // metrics should record a deleted file
            Org.Mockito.Mockito.Verify(metrics).ReportAFileDelete();
            Org.Mockito.Mockito.Verify(metrics, Org.Mockito.Mockito.Never()).ReportAFileProcess
                ();
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a cleaner task based on the root directory location and the
 /// filesystem.
 /// </summary>
 internal CleanerTask(string location, long sleepTime, int nestedLevel, FileSystem
                      fs, SCMStore store, CleanerMetrics metrics, Lock cleanerTaskLock)
 {
     this.location        = location;
     this.sleepTime       = sleepTime;
     this.nestedLevel     = nestedLevel;
     this.root            = new Path(location);
     this.fs              = fs;
     this.store           = store;
     this.metrics         = metrics;
     this.cleanerTaskLock = cleanerTaskLock;
 }
Esempio n. 3
0
        public virtual void TestNonExistentRoot()
        {
            FileSystem     fs      = Org.Mockito.Mockito.Mock <FileSystem>();
            CleanerMetrics metrics = Org.Mockito.Mockito.Mock <CleanerMetrics>();
            SCMStore       store   = Org.Mockito.Mockito.Mock <SCMStore>();
            CleanerTask    task    = CreateSpiedTask(fs, store, metrics, new ReentrantLock());

            // the shared cache root does not exist
            Org.Mockito.Mockito.When(fs.Exists(task.GetRootPath())).ThenReturn(false);
            task.Run();
            // process() should not be called
            Org.Mockito.Mockito.Verify(task, Org.Mockito.Mockito.Never()).Process();
        }
Esempio n. 4
0
 public virtual void CleanUp()
 {
     if (store != null)
     {
         store.Stop();
         store = null;
     }
     if (service != null)
     {
         service.Stop();
         service = null;
     }
     if (clientSCMProxy != null)
     {
         RPC.StopProxy(clientSCMProxy);
         clientSCMProxy = null;
     }
 }
Esempio n. 5
0
        private static SCMStore CreateSCMStoreService(Configuration conf)
        {
            Type defaultStoreClass;

            try
            {
                defaultStoreClass = (Type)Sharpen.Runtime.GetType(YarnConfiguration.DefaultScmStoreClass
                                                                  );
            }
            catch (Exception e)
            {
                throw new YarnRuntimeException("Invalid default scm store class" + YarnConfiguration
                                               .DefaultScmStoreClass, e);
            }
            SCMStore store = ReflectionUtils.NewInstance(conf.GetClass <SCMStore>(YarnConfiguration
                                                                                  .ScmStoreClass, defaultStoreClass), conf);

            return(store);
        }
Esempio n. 6
0
 /// <summary>Creates a cleaner task based on the configuration.</summary>
 /// <remarks>
 /// Creates a cleaner task based on the configuration. This is provided for
 /// convenience.
 /// </remarks>
 /// <param name="conf"/>
 /// <param name="store"/>
 /// <param name="metrics"/>
 /// <param name="cleanerTaskLock">
 /// lock that ensures a serial execution of cleaner
 /// task
 /// </param>
 /// <returns>an instance of a CleanerTask</returns>
 public static Org.Apache.Hadoop.Yarn.Server.Sharedcachemanager.CleanerTask Create
     (Configuration conf, SCMStore store, CleanerMetrics metrics, Lock cleanerTaskLock
     )
 {
     try
     {
         // get the root directory for the shared cache
         string location = conf.Get(YarnConfiguration.SharedCacheRoot, YarnConfiguration.DefaultSharedCacheRoot
                                    );
         long sleepTime = conf.GetLong(YarnConfiguration.ScmCleanerResourceSleepMs, YarnConfiguration
                                       .DefaultScmCleanerResourceSleepMs);
         int        nestedLevel = SharedCacheUtil.GetCacheDepth(conf);
         FileSystem fs          = FileSystem.Get(conf);
         return(new Org.Apache.Hadoop.Yarn.Server.Sharedcachemanager.CleanerTask(location,
                                                                                 sleepTime, nestedLevel, fs, store, metrics, cleanerTaskLock));
     }
     catch (IOException e)
     {
         Log.Error("Unable to obtain the filesystem for the cleaner service", e);
         throw new ExceptionInInitializerError(e);
     }
 }
Esempio n. 7
0
        public virtual void StartUp()
        {
            Configuration conf = new Configuration();

            conf.Set(YarnConfiguration.ScmStoreClass, typeof(InMemorySCMStore).FullName);
            conf.Set(YarnConfiguration.SharedCacheRoot, testDir.GetPath());
            AppChecker appChecker = Org.Mockito.Mockito.Spy(new DummyAppChecker());

            store = new InMemorySCMStore(appChecker);
            store.Init(conf);
            store.Start();
            service = new ClientProtocolService(store);
            service.Init(conf);
            service.Start();
            YarnRPC    rpc        = YarnRPC.Create(new Configuration());
            IPEndPoint scmAddress = conf.GetSocketAddr(YarnConfiguration.ScmClientServerAddress
                                                       , YarnConfiguration.DefaultScmClientServerAddress, YarnConfiguration.DefaultScmClientServerPort
                                                       );

            clientSCMProxy = (ClientSCMProtocol)rpc.GetProxy(typeof(ClientSCMProtocol), scmAddress
                                                             , conf);
        }
Esempio n. 8
0
        public virtual void TestResourceIsInUseHasAnActiveApp()
        {
            FileSystem     fs       = Org.Mockito.Mockito.Mock <FileSystem>();
            CleanerMetrics metrics  = Org.Mockito.Mockito.Mock <CleanerMetrics>();
            SCMStore       store    = Org.Mockito.Mockito.Mock <SCMStore>();
            FileStatus     resource = Org.Mockito.Mockito.Mock <FileStatus>();

            Org.Mockito.Mockito.When(resource.GetPath()).ThenReturn(new Path(Root + "/a/b/c/abc"
                                                                             ));
            // resource is stale
            Org.Mockito.Mockito.When(store.IsResourceEvictable(Matchers.IsA <string>(), Matchers.IsA
                                                               <FileStatus>())).ThenReturn(true);
            // but still has appIds
            Org.Mockito.Mockito.When(store.RemoveResource(Matchers.IsA <string>())).ThenReturn
                (false);
            CleanerTask task = CreateSpiedTask(fs, store, metrics, new ReentrantLock());

            // process the resource
            task.ProcessSingleResource(resource);
            // metrics should record a processed file (but not delete)
            Org.Mockito.Mockito.Verify(metrics).ReportAFileProcess();
            Org.Mockito.Mockito.Verify(metrics, Org.Mockito.Mockito.Never()).ReportAFileDelete
                ();
        }
Esempio n. 9
0
        /// <exception cref="System.Exception"/>
        protected override void ServiceInit(Configuration conf)
        {
            this.store = CreateSCMStoreService(conf);
            AddService(store);
            CleanerService cs = CreateCleanerService(store);

            AddService(cs);
            SharedCacheUploaderService nms = CreateNMCacheUploaderSCMProtocolService(store);

            AddService(nms);
            ClientProtocolService cps = CreateClientProtocolService(store);

            AddService(cps);
            SCMAdminProtocolService saps = CreateSCMAdminProtocolService(cs);

            AddService(saps);
            SCMWebServer webUI = CreateSCMWebServer(this);

            AddService(webUI);
            // init metrics
            DefaultMetricsSystem.Initialize("SharedCacheManager");
            JvmMetrics.InitSingleton("SharedCacheManager", null);
            base.ServiceInit(conf);
        }
Esempio n. 10
0
        public virtual void TestProcessFreshResource()
        {
            FileSystem     fs      = Org.Mockito.Mockito.Mock <FileSystem>();
            CleanerMetrics metrics = Org.Mockito.Mockito.Mock <CleanerMetrics>();
            SCMStore       store   = Org.Mockito.Mockito.Mock <SCMStore>();
            CleanerTask    task    = CreateSpiedTask(fs, store, metrics, new ReentrantLock());

            // mock a resource that is not evictable
            Org.Mockito.Mockito.When(store.IsResourceEvictable(Matchers.IsA <string>(), Matchers.IsA
                                                               <FileStatus>())).ThenReturn(false);
            FileStatus status = Org.Mockito.Mockito.Mock <FileStatus>();

            Org.Mockito.Mockito.When(status.GetPath()).ThenReturn(new Path(Root + "/a/b/c/abc"
                                                                           ));
            // process the resource
            task.ProcessSingleResource(status);
            // the directory should not be renamed
            Org.Mockito.Mockito.Verify(fs, Org.Mockito.Mockito.Never()).Rename(Matchers.Eq(status
                                                                                           .GetPath()), Matchers.IsA <Path>());
            // metrics should record a processed file (but not delete)
            Org.Mockito.Mockito.Verify(metrics).ReportAFileProcess();
            Org.Mockito.Mockito.Verify(metrics, Org.Mockito.Mockito.Never()).ReportAFileDelete
                ();
        }
Esempio n. 11
0
 public CleanerService(SCMStore store)
     : base("CleanerService")
 {
     this.store           = store;
     this.cleanerTaskLock = new ReentrantLock();
 }
Esempio n. 12
0
 public SharedCacheUploaderService(SCMStore store)
     : base(typeof(Org.Apache.Hadoop.Yarn.Server.Sharedcachemanager.SharedCacheUploaderService
                   ).FullName)
 {
     this.store = store;
 }
Esempio n. 13
0
 private ClientProtocolService CreateClientProtocolService(SCMStore store)
 {
     return(new ClientProtocolService(store));
 }
Esempio n. 14
0
 private SharedCacheUploaderService CreateNMCacheUploaderSCMProtocolService(SCMStore
                                                                            store)
 {
     return(new SharedCacheUploaderService(store));
 }
Esempio n. 15
0
 private CleanerService CreateCleanerService(SCMStore store)
 {
     return(new CleanerService(store));
 }
Esempio n. 16
0
 public ClientProtocolService(SCMStore store)
     : base(typeof(Org.Apache.Hadoop.Yarn.Server.Sharedcachemanager.ClientProtocolService
                   ).FullName)
 {
     this.store = store;
 }
Esempio n. 17
0
 private CleanerTask CreateSpiedTask(FileSystem fs, SCMStore store, CleanerMetrics
                                     metrics, Lock isCleanerRunning)
 {
     return(Org.Mockito.Mockito.Spy(new CleanerTask(Root, SleepTime, NestedLevel, fs,
                                                    store, metrics, isCleanerRunning)));
 }