Пример #1
0
 private List <FileSystemData> GetFileSystemsData(IEnumerable <RavenJToken> fileSystems)
 {
     return(fileSystems
            .Select(fileSystem =>
     {
         var bundles = new string[] { };
         var settings = fileSystem.Value <RavenJObject>("Settings");
         if (settings != null)
         {
             var activeBundles = settings.Value <string>(RavenConfiguration.GetKey(x => x.Core._ActiveBundlesString));
             if (activeBundles != null)
             {
                 bundles = activeBundles.Split(';');
             }
         }
         var fsName = fileSystem.Value <RavenJObject>("@metadata").Value <string>("@id").Replace(Constants.FileSystem.Prefix, string.Empty);
         return new FileSystemData
         {
             Name = fsName,
             Disabled = fileSystem.Value <bool>("Disabled"),
             Bundles = bundles,
             IsAdminCurrentTenant = true,
             IsLoaded = FileSystemsLandlord.IsFileSystemLoaded(fsName)
         };
     }).ToList());
 }
Пример #2
0
        private List <FileSystemData> GetFileSystemsData(IEnumerable <RavenJToken> fileSystems)
        {
            return(fileSystems
                   .Select(fileSystem =>
            {
                var bundles = new string[] { };
                var settings = fileSystem.Value <RavenJObject>("Settings");
                if (settings != null)
                {
                    var activeBundles = settings.Value <string>("Raven/ActiveBundles");
                    if (activeBundles != null)
                    {
                        bundles = activeBundles.Split(';');
                    }
                }

                var fsName = fileSystem.Value <RavenJObject>("@metadata").Value <string>("@id").Replace(Constants.FileSystem.Prefix, string.Empty);
                var isFileSystemLoaded = FileSystemsLandlord.IsFileSystemLoaded(fsName);
                FileSystemStats stats = null;
                if (isFileSystemLoaded)
                {
                    try
                    {
                        var fs = FileSystemsLandlord.GetResourceInternal(fsName).Result;
                        if (fs != null)
                        {
                            stats = fs.GetFileSystemStats();
                        }
                    }
                    catch (Exception)
                    {
                        //the file system is shutting down or locked
                        //we can ignore this
                    }
                }

                return new FileSystemData
                {
                    Name = fsName,
                    Disabled = fileSystem.Value <bool>("Disabled"),
                    Bundles = bundles,
                    IsAdminCurrentTenant = true,
                    IsLoaded = isFileSystemLoaded,
                    Stats = stats
                };
            }).ToList());
        }
		private void CleanupFileSystems(DatabasesLandlord databaseLandlord, FileSystemsLandlord fileSystemLandlord)
		{
			var systemDatabase = databaseLandlord.SystemDatabase;

			int nextStart = 0;
			var fileSystemDocuments = systemDatabase
				.Documents
                .GetDocumentsWithIdStartingWith(Constants.FileSystem.Prefix, null, null, 0, int.MaxValue, CancellationToken.None, ref nextStart);

			var fileSystemIds = fileSystemDocuments
				.Select(x => ((RavenJObject)x)["@metadata"])
				.Where(x => x != null)
				.Select(x => x.Value<string>("@id"))
				.Where(x => x != null && x != Constants.SystemDatabase)
				.ToList();

			foreach (var fileSystemId in fileSystemIds)
			{
				try
				{
					var key = fileSystemId;
                    if (key.StartsWith(Constants.FileSystem.Prefix))
                        key = key.Substring(Constants.FileSystem.Prefix.Length);

					var shouldCleanup = false;

					DateTime value;
					if (fileSystemLandlord.IsFileSystemLoaded(key) == false) 
						shouldCleanup = true;
					else if (fileSystemLandlord.LastRecentlyUsed.TryGetValue(key, out value) == false || (SystemTime.UtcNow - value) > maxTimeResourceCanBeIdle) 
						shouldCleanup = true;

					if (shouldCleanup == false) 
						continue;

					var configuration = fileSystemLandlord.CreateTenantConfiguration(key, true);

					fileSystemLandlord.Cleanup(key, maxTimeResourceCanBeIdle, database => false);

                    var docKey = Constants.FileSystem.Prefix + key;
					systemDatabase.Documents.Delete(docKey, null, null);

					if (configuration == null)
						continue;

					IOExtensions.DeleteDirectory(configuration.FileSystem.DataDirectory);
				}
				catch (Exception e)
				{
					log.WarnException(string.Format("Failed to cleanup '{0}' filesystem.", fileSystemId), e);
				}
			}
		}
Пример #4
0
        private void CleanupFileSystems(DatabasesLandlord databaseLandlord, FileSystemsLandlord fileSystemLandlord)
        {
            var systemDatabase = databaseLandlord.SystemDatabase;

            int nextStart           = 0;
            var fileSystemDocuments = systemDatabase
                                      .Documents
                                      .GetDocumentsWithIdStartingWith(Constants.FileSystem.Prefix, null, null, 0, int.MaxValue, CancellationToken.None, ref nextStart);

            var fileSystemIds = fileSystemDocuments
                                .Select(x => ((RavenJObject)x)["@metadata"])
                                .Where(x => x != null)
                                .Select(x => x.Value <string>("@id"))
                                .Where(x => x != null && x != Constants.SystemDatabase)
                                .ToList();

            foreach (var fileSystemId in fileSystemIds)
            {
                try
                {
                    var key = fileSystemId;
                    if (key.StartsWith(Constants.FileSystem.Prefix))
                    {
                        key = key.Substring(Constants.FileSystem.Prefix.Length);
                    }

                    var shouldCleanup = false;

                    DateTime value;
                    if (fileSystemLandlord.IsFileSystemLoaded(key) == false)
                    {
                        shouldCleanup = true;
                    }
                    else if (fileSystemLandlord.LastRecentlyUsed.TryGetValue(key, out value) == false || (SystemTime.UtcNow - value) > maxTimeResourceCanBeIdle)
                    {
                        shouldCleanup = true;
                    }

                    if (shouldCleanup == false)
                    {
                        continue;
                    }

                    var configuration = fileSystemLandlord.CreateTenantConfiguration(key, true);

                    fileSystemLandlord.Cleanup(key, maxTimeResourceCanBeIdle, database => false);

                    var docKey = Constants.FileSystem.Prefix + key;
                    systemDatabase.Documents.Delete(docKey, null, null);

                    if (configuration == null)
                    {
                        continue;
                    }

                    IOExtensions.DeleteDirectory(configuration.FileSystem.DataDirectory);
                }
                catch (Exception e)
                {
                    log.WarnException(string.Format("Failed to cleanup '{0}' filesystem.", fileSystemId), e);
                }
            }
        }