/**
         * Creates a file system and waits for it to become available. We recommend to retry these requests
         * so that if you receive a timeout or server error and you won't run into the risk of creating multiple resources.
         *
         * @param fsClient the service client to use to create the File System
         * @param compartmentId the OCID of the compartment where the file system will be created
         * @param availabilityDomain the availability domain where the file system will be created
         *
         * @return the created file system
         */
        private static async Task <FileSystem> CreateFileSystem(FileStorageClient fsClient, string compartmentId,
                                                                string displayName, AvailabilityDomain availabilityDomain)
        {
            logger.Info("Creating file system......");

            CreateFileSystemDetails createDetails = new CreateFileSystemDetails
            {
                DisplayName        = displayName,
                CompartmentId      = compartmentId,
                AvailabilityDomain = availabilityDomain.Name
            };
            CreateFileSystemRequest createRequest = new CreateFileSystemRequest
            {
                CreateFileSystemDetails = createDetails
            };
            CreateFileSystemResponse createResponse = await fsClient.CreateFileSystem(createRequest, new RetryConfiguration
            {
                MaxAttempts = 5
            });

            logger.Info($"Created file system: {createResponse.FileSystem.DisplayName}");

            GetFileSystemRequest getRequest = new GetFileSystemRequest
            {
                FileSystemId = createResponse.FileSystem.Id
            };
            GetFileSystemResponse getResponse = fsClient.Waiters.ForFileSystem(getRequest, FileSystem.LifecycleStateEnum.Active).Execute();

            logger.Info($"Waited for file system to become available: {createResponse.FileSystem.DisplayName}");

            return(getResponse.FileSystem);
        }
예제 #2
0
        private void DisplayTreeStats(IProtoBufSerializer serializer, GetFileSystemResponse response, bool verbose)
        {
            Trace.WriteLine("=====================================================================");
            Trace.WriteLine("FileSystem tree stats:");
            {
                var mem         = new MemoryStream();
                var sw          = new Stopwatch();
                var ipcResponse = new IpcResponse {
                    RequestId = 0,
                    Protocol  = IpcProtocols.TypedMessage,
                    Data      = response
                };
                sw.Start();
                serializer.Serialize(mem, ipcResponse);
                sw.Stop();
                Trace.WriteLine(string.Format("ProtoBuf request of {0:n0} bytes serialized in {1} msec.", mem.Length,
                                              sw.ElapsedMilliseconds));
            }

            var stats = new TreeStats();

            stats.ProcessTree(null, "", response.Tree.Root);
            Trace.WriteLine(string.Format("Directory count: {0:n0}", stats.DirectoryCount));
            Trace.WriteLine(string.Format("File count: {0:n0}", stats.FileCount));
            Trace.WriteLine(string.Format("Total File size: {0:n0} bytes", stats.TotalSize));
            if (verbose)
            {
                Trace.WriteLine("=====================================================================");
                Trace.WriteLine(" Files sorted by count");
                foreach (var item in stats.Extensions.OrderByDescending(x => x.Value.FileCount))
                {
                    Trace.WriteLine(string.Format("Extension \"{0}\": {1:n0} files, {2:n0} bytes", item.Key.ToUpperInvariant(),
                                                  item.Value.FileCount, item.Value.TotalSize));
                }

                Trace.WriteLine("=====================================================================");
                Trace.WriteLine(" Files sorted by total length");
                foreach (var item in stats.Extensions.OrderByDescending(x => x.Value.TotalSize))
                {
                    Trace.WriteLine(string.Format("Extension \"{0}\": {2:n0} bytes, {1:n0} files", item.Key.ToUpperInvariant(),
                                                  item.Value.FileCount, item.Value.TotalSize));
                }

                OutputDirectorytree(0, "", stats.RootDirectory);
            }
        }