Example #1
0
        internal async Task <IIpcResult> AddFileAsync(IDropItem dropItem, Func <string, bool> symlinkTester)
        {
            Contract.Requires(dropItem != null);

            // Check if the file is a symlink, only if the file exists on disk at this point; if it is a symlink, reject it outright.
            if (System.IO.File.Exists(dropItem.FullFilePath) && symlinkTester(dropItem.FullFilePath))
            {
                return(new IpcResult(IpcResultStatus.ExecutionError, SymlinkAddErrorMessagePrefix + dropItem.FullFilePath));
            }

            return(await WrapDropErrorsIntoIpcResult(async() =>
            {
                IDropClient dropClient = await m_dropClientTask;
                AddFileResult result = await dropClient.AddFileAsync(dropItem);

                switch (result)
                {
                case AddFileResult.Associated:
                case AddFileResult.UploadedAndAssociated:
                case AddFileResult.SkippedAsDuplicate:
                    return IpcResult.Success(I($"File '{dropItem.FullFilePath}' {result} under '{dropItem.RelativeDropPath}' in drop '{DropName}'."));

                case AddFileResult.RegisterFileForBuildManifestFailure:
                    return new IpcResult(IpcResultStatus.ExecutionError, $"Failure during BuildManifest Hash generation for File '{dropItem.FullFilePath}' {result} under '{dropItem.RelativeDropPath}' in drop '{DropName}'.");

                default:
                    return new IpcResult(IpcResultStatus.ExecutionError, $"Unhandled drop result: {result}");
                }
            }));
        }
Example #2
0
        /// <summary>
        ///     Invokes the 'drop finalize' operation by delegating to <see cref="IDropClient.FinalizeAsync"/>.
        ///
        ///     If successful, returns <see cref="DropFinalizationEvent"/> with <see cref="DropOperationBaseEvent.Succeeded"/>
        ///     set to true.
        ///
        ///     Doesn't handle any exceptions.
        /// </summary>
        private async Task <DropFinalizationEvent> InternalFinalizeAsync()
        {
            IDropClient dropClient = await m_dropClientTask;
            await dropClient.FinalizeAsync();

            return(new DropFinalizationEvent()
            {
                Succeeded = true,
            });
        }
Example #3
0
        private void WithSetup(IDropClient dropClient, Action <global::Tool.DropDaemon.DropDaemon, DropEtwListener> action, Client apiClient = null)
        {
            var    etwListener  = ConfigureEtwLogging();
            string moniker      = ServicePipDaemon.IpcProvider.RenderConnectionString(ServicePipDaemon.IpcProvider.CreateNewMoniker());
            var    daemonConfig = new DaemonConfig(VoidLogger.Instance, moniker: moniker, enableCloudBuildIntegration: false);
            var    dropConfig   = new DropConfig(string.Empty, null);
            var    daemon       = new global::Tool.DropDaemon.DropDaemon(UnixParser.Instance, daemonConfig, dropConfig, Task.FromResult(dropClient), client: apiClient);

            action(daemon, etwListener);
        }
Example #4
0
        /// <summary>
        ///     Invokes the 'drop create' operation by delegating to <see cref="IDropClient.CreateAsync"/>.
        ///
        ///     If successful, returns <see cref="DropCreationEvent"/> with <see cref="DropOperationBaseEvent.Succeeded"/>
        ///     set to true, <see cref="DropCreationEvent.DropExpirationInDays"/> set to drop expiration in days,
        ///     and <see cref="DropOperationBaseEvent.AdditionalInformation"/> set to the textual representation
        ///     of the returned <see cref="DropItem"/> object.
        ///
        ///     Doesn't handle any exceptions.
        /// </summary>
        private async Task <DropCreationEvent> InternalCreateAsync()
        {
            IDropClient dropClient = await m_dropClientTask;
            DropItem    dropItem   = await dropClient.CreateAsync();

            return(new DropCreationEvent()
            {
                Succeeded = true,
                AdditionalInformation = DropItemToString(dropItem),
                DropExpirationInDays = ComputeDropItemExpiration(dropItem),
            });
        }
Example #5
0
        internal async Task <IIpcResult> AddFileAsync(IDropItem dropItem, Func <string, bool> symlinkTester)
        {
            Contract.Requires(dropItem != null);

            // Check if the file is a symlink, only if the file exists on disk at this point; if it is a symlink, reject it outright.
            if (System.IO.File.Exists(dropItem.FullFilePath) && symlinkTester(dropItem.FullFilePath))
            {
                return(new IpcResult(IpcResultStatus.ExecutionError, SymlinkAddErrorMessagePrefix + dropItem.FullFilePath));
            }

            return(await WrapDropErrorsIntoIpcResult(async() =>
            {
                IDropClient dropClient = await m_dropClientTask;
                AddFileResult result = await dropClient.AddFileAsync(dropItem);
                return IpcResult.Success(I($"File '{dropItem.FullFilePath}' {result} under '{dropItem.RelativeDropPath}' in drop '{DropName}'."));
            }));
        }
Example #6
0
        /// <remarks>
        /// If an apiClient is not passed (i.e., null by default), we create a new Client that returns success for any bool command called.
        /// </remarks>
        private void WithSetup(IDropClient dropClient, Action <global::Tool.DropDaemon.DropDaemon, DropEtwListener, DropConfig> action, Client apiClient = null)
        {
            var    etwListener       = ConfigureEtwLogging();
            string moniker           = ServicePipDaemon.IpcProvider.RenderConnectionString(ServicePipDaemon.IpcProvider.CreateNewMoniker());
            var    daemonConfig      = new DaemonConfig(VoidLogger.Instance, moniker: moniker, enableCloudBuildIntegration: false);
            var    dropConfig        = new DropConfig("test", new Uri("file://xyz"));
            var    dropServiceConfig = new DropServiceConfig();

            if (apiClient == null)
            {
                apiClient = new Client(new MockClient(ipcOperation => IpcResult.Success("true")));
            }
            var daemon = new global::Tool.DropDaemon.DropDaemon(UnixParser.Instance, daemonConfig, dropServiceConfig, client: apiClient);

            daemon.RegisterDropClientForTesting(dropConfig, dropClient);
            action(daemon, etwListener, dropConfig);
        }
Example #7
0
        private async Task ReportStatisticsAsync()
        {
            IDropClient dropClient = await m_dropClientTask;
            var         stats      = dropClient.GetStats();

            if (stats != null && stats.Any())
            {
                // log stats
                m_logger.Info("Statistics: ");
                m_logger.Info(string.Join(Environment.NewLine, stats.Select(s => s.Key + " = " + s.Value)));

                stats.Add(nameof(DropConfig) + nameof(DropConfig.MaxParallelUploads), DropConfig.MaxParallelUploads);
                stats.Add(nameof(DropConfig) + nameof(DropConfig.NagleTime), (long)DropConfig.NagleTime.TotalMilliseconds);
                stats.Add(nameof(DropConfig) + nameof(DropConfig.BatchSize), DropConfig.BatchSize);
                stats.Add(nameof(DropConfig) + nameof(DropConfig.EnableChunkDedup), DropConfig.EnableChunkDedup ? 1 : 0);
                stats.Add("DaemonConfig" + nameof(Config.MaxConcurrentClients), Config.MaxConcurrentClients);
                stats.Add("DaemonConfig" + nameof(Config.ConnectRetryDelay), (long)Config.ConnectRetryDelay.TotalMilliseconds);
                stats.Add("DaemonConfig" + nameof(Config.MaxConnectRetries), Config.MaxConnectRetries);

                stats.AddRange(m_counters.AsStatistics());

                // report stats to BuildXL (if m_client is specified)
                if (ApiClient != null)
                {
                    var possiblyReported = await ApiClient.ReportStatistics(stats);

                    if (possiblyReported.Succeeded && possiblyReported.Result)
                    {
                        m_logger.Info("Statistics successfully reported to BuildXL.");
                    }
                    else
                    {
                        var errorDescription = possiblyReported.Succeeded ? string.Empty : possiblyReported.Failure.Describe();
                        m_logger.Warning("Reporting stats to BuildXL failed. " + errorDescription);
                    }
                }
            }
            else
            {
                m_logger.Info("No stats recorded by drop client of type " + dropClient.GetType().Name);
            }
        }