public InfoRefsService(ITracer tracer, IGitServer gitServer, IEnvironment environment, RepositoryConfiguration configuration) { _gitServer = gitServer; _tracer = tracer; _deploymentTargetPath = environment.DeploymentTargetPath; _configuration = configuration; }
public string ExecuteMSBuild(ITracer tracer, string arguments, params object[] args) { using (var writer = new ProgressWriter()) { writer.Start(); return _msbuildExe.Execute(tracer, arguments, args).Item1; } }
public PrefetchHelper(ITracer tracer, GVFSEnlistment enlistment, int downloadThreadCount) { HttpGitObjects http = new HttpGitObjects(tracer, enlistment, downloadThreadCount); this.gitObjects = new GitObjects(tracer, enlistment, http); }
private async Task LocalZipHandler(IRepository repository, DeploymentInfoBase deploymentInfo, string targetBranch, ILogger logger, ITracer tracer) { if (_settings.RunFromLocalZip() && deploymentInfo is ZipDeploymentInfo) { ZipDeploymentInfo zipDeploymentInfo = (ZipDeploymentInfo)deploymentInfo; // If this was a request with a Zip URL in the JSON, we first need to get the zip content and write it to the site. if (!string.IsNullOrEmpty(zipDeploymentInfo.ZipURL)) { await WriteSitePackageZip(zipDeploymentInfo, tracer, await DeploymentHelper.GetZipContentFromURL(zipDeploymentInfo, tracer)); } // If this is a Run-From-Zip deployment, then we need to extract function.json // from the zip file into path zipDeploymentInfo.SyncFunctionsTriggersPath ExtractTriggers(repository, zipDeploymentInfo); } else { await LocalZipFetch(repository, deploymentInfo, targetBranch, logger, tracer); } }
private static void OnBeginRequest(object sender, EventArgs e) { _lastRequestDateTime = DateTime.UtcNow; var httpContext = ((HttpApplication)sender).Context; var httpRequest = new HttpRequestWrapper(httpContext.Request); LogBeginRequest(httpContext); // HACK: This is abusing the trace module // Disallow GET requests from CSM extensions bridge // Except if owner or coadmin (aka legacy or non-rbac) or x-ms-client-rolebased-contributor (by FE) authorization if (!String.IsNullOrEmpty(httpRequest.Headers["X-MS-VIA-EXTENSIONS-ROUTE"]) && httpRequest.HttpMethod.Equals(HttpMethod.Get.Method, StringComparison.OrdinalIgnoreCase) && !String.Equals(httpRequest.Headers[Constants.ClientAuthorizationSourceHeader], "legacy", StringComparison.OrdinalIgnoreCase) && httpRequest.Headers[Constants.RoleBasedContributorHeader] != "1" && !IsRbacWhiteListPaths(httpRequest.Url.AbsolutePath)) { httpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized; httpContext.Response.End(); } TryConvertSpecialHeadersToEnvironmentVariable(httpRequest); // HACK: If it's a Razor extension, add a dummy extension to prevent WebPages for blocking it, // as we need to serve those files via /vfs // Yes, this is an abuse of the trace module if (httpRequest.FilePath.IndexOf("vfs/", StringComparison.OrdinalIgnoreCase) >= 0 && (httpRequest.FilePath.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase) || httpRequest.FilePath.EndsWith(".vbhtml", StringComparison.OrdinalIgnoreCase))) { httpContext.Server.TransferRequest(httpRequest.FilePath + Constants.DummyRazorExtension, preserveForm: true); return; } // Always trace the startup request. ITracer tracer = TraceStartup(httpContext); // Trace heartbeat periodically TraceHeartbeat(); // Skip certain paths if (TraceExtensions.ShouldSkipRequest(httpRequest)) { // this is to prevent Kudu being IFrame (typically where host != referer) // to optimize where we return X-FRAME-OPTIONS DENY header, only return when // in Azure env, browser non-ajax requests and referer mismatch with host // since browser uses referer for other scenarios (such as href, redirect), we may return // this header (benign) in such cases. if (Kudu.Core.Environment.IsAzureEnvironment() && !TraceExtensions.IsAjaxRequest(httpRequest) && TraceExtensions.MismatchedHostReferer(httpRequest)) { httpContext.Response.Headers.Add("X-FRAME-OPTIONS", "DENY"); } if (TraceServices.TraceLevel != TraceLevel.Verbose) { TraceServices.RemoveRequestTracer(httpContext); // enable just ETW tracer tracer = TraceServices.EnsureETWTracer(httpContext); } } tracer = tracer ?? TraceServices.CreateRequestTracer(httpContext); if (tracer == null || tracer.TraceLevel <= TraceLevel.Off) { return; } var attribs = GetTraceAttributes(httpContext); AddTraceLevel(httpContext, attribs); foreach (string key in httpContext.Request.Headers) { if (!key.Equals("Authorization", StringComparison.OrdinalIgnoreCase) && !key.Equals("X-MS-CLIENT-PRINCIPAL-NAME", StringComparison.OrdinalIgnoreCase)) { attribs[key] = httpContext.Request.Headers[key]; } else { // for sensitive header, we only trace first 3 characters following by "..." var value = httpContext.Request.Headers[key]; attribs[key] = string.IsNullOrEmpty(value) ? value : (value.Substring(0, Math.Min(3, value.Length)) + "..."); } } httpContext.Items[_stepKey] = tracer.Step(XmlTracer.IncomingRequestTrace, attribs); }
private void EnqueueOperationsFromDiffTreeLine(ITracer activity, string repoRoot, string line) { if (!line.StartsWith(":")) { // Diff-tree starts with metadata we can ignore. // Real diff lines always start with a colon return; } DiffTreeResult result = DiffTreeResult.ParseFromDiffTreeLine(line, repoRoot); if (!this.ResultIsInWhitelist(result)) { return; } if (result.Operation == DiffTreeResult.Operations.Unknown || result.Operation == DiffTreeResult.Operations.Unmerged) { EventMetadata metadata = new EventMetadata(); metadata.Add("Path", result.TargetFilename); metadata.Add("ErrorMessage", "Unexpected diff operation: " + result.Operation); activity.RelatedError(metadata); this.HasFailures = true; return; } // Separate and enqueue all directory operations first. if (result.SourceIsDirectory || result.TargetIsDirectory) { switch (result.Operation) { case DiffTreeResult.Operations.Delete: if (!this.stagedDirectoryOperations.Add(result)) { EventMetadata metadata = new EventMetadata(); metadata.Add("Filename", result.TargetFilename); metadata.Add("Message", "A case change was attempted. It will not be reflected in the working directory."); activity.RelatedEvent(EventLevel.Warning, "CaseConflict", metadata); } break; case DiffTreeResult.Operations.RenameEdit: if (!this.stagedDirectoryOperations.Add(result)) { // This could happen if a directory was deleted and an existing directory was renamed to replace it, but with a different case. EventMetadata metadata = new EventMetadata(); metadata.Add("Filename", result.TargetFilename); metadata.Add("Message", "A case change was attempted. It will not be reflected in the working directory."); activity.RelatedEvent(EventLevel.Warning, "CaseConflict", metadata); // The target of RenameEdit is always akin to an Add, so replacing the delete is the safer thing to do. this.stagedDirectoryOperations.Remove(result); this.stagedDirectoryOperations.Add(result); } if (!result.TargetIsDirectory) { // Handle when a directory becomes a file. // Files becoming directories is handled by HandleAllDirectoryOperations this.EnqueueFileAddOperation(activity, result); } break; case DiffTreeResult.Operations.Add: case DiffTreeResult.Operations.Modify: case DiffTreeResult.Operations.CopyEdit: if (!this.stagedDirectoryOperations.Add(result)) { EventMetadata metadata = new EventMetadata(); metadata.Add("Filename", result.TargetFilename); metadata.Add("Message", "A case change was attempted. It will not be reflected in the working directory."); activity.RelatedEvent(EventLevel.Warning, "CaseConflict", metadata); // Replace the delete with the add to make sure we don't delete a folder from under ourselves this.stagedDirectoryOperations.Remove(result); this.stagedDirectoryOperations.Add(result); } break; default: activity.RelatedError("Unexpected diff operation from line: {0}", line); break; } } else { switch (result.Operation) { case DiffTreeResult.Operations.Delete: this.EnqueueFileDeleteOperation(activity, result.TargetFilename); break; case DiffTreeResult.Operations.RenameEdit: this.EnqueueFileAddOperation(activity, result); this.EnqueueFileDeleteOperation(activity, result.SourceFilename); break; case DiffTreeResult.Operations.Modify: case DiffTreeResult.Operations.CopyEdit: case DiffTreeResult.Operations.Add: this.EnqueueFileAddOperation(activity, result); break; default: activity.RelatedError("Unexpected diff operation from line: {0}", line); break; } } }
private bool CheckGitStatus(ITracer tracer, GVFSEnlistment enlistment, bool fullDehydrate) { if (!this.NoStatus) { this.WriteMessage(tracer, "Running git status before dehydrating to make sure you don't have any pending changes."); if (fullDehydrate) { this.WriteMessage(tracer, "If this takes too long, you can abort and run dehydrate with --no-status to skip this safety check."); } this.Output.WriteLine(); bool isMounted = false; GitProcess.Result statusResult = null; if (!this.ShowStatusWhileRunning( () => { if (this.ExecuteGVFSVerb <StatusVerb>(tracer) != ReturnCode.Success) { return(false); } isMounted = true; GitProcess git = new GitProcess(enlistment); statusResult = git.Status(allowObjectDownloads: false, useStatusCache: false, showUntracked: true); if (statusResult.ExitCodeIsFailure) { return(false); } if (!statusResult.Output.Contains("nothing to commit, working tree clean")) { return(false); } return(true); }, "Running git status", suppressGvfsLogMessage: true)) { this.Output.WriteLine(); if (!isMounted) { this.WriteMessage(tracer, "Failed to run git status because the repo is not mounted"); if (fullDehydrate) { this.WriteMessage(tracer, "Either mount first, or run with --no-status"); } } else if (statusResult.ExitCodeIsFailure) { this.WriteMessage(tracer, "Failed to run git status: " + statusResult.Errors); } else { this.WriteMessage(tracer, statusResult.Output); this.WriteMessage(tracer, "git status reported that you have dirty files"); if (fullDehydrate) { this.WriteMessage(tracer, "Either commit your changes or run dehydrate with --no-status"); } else { this.WriteMessage(tracer, "Either commit your changes or reset and clean your working directory."); } } this.ReportErrorAndExit(tracer, "Dehydrate was aborted"); return(false); } else { return(true); } } return(false); }
public MockPhysicalGitObjects(ITracer tracer, Enlistment enlistment, HttpGitObjects httpGitObjects) : base(tracer, enlistment, httpGitObjects) { }
public abstract void ConfigureVisualStudio(string gitBinPath, ITracer tracer);
public abstract string GetUserIdFromLoginSessionId(int sessionId, ITracer tracer);
public abstract void StartBackgroundProcess(ITracer tracer, string programName, string[] args);
private Result CreateClone( ITracer tracer, GVFSEnlistment enlistment, GitObjectsHttpRequestor objectRequestor, GitRefs refs, string branch) { Result initRepoResult = this.TryInitRepo(tracer, refs, enlistment); if (!initRepoResult.Success) { return(initRepoResult); } PhysicalFileSystem fileSystem = new PhysicalFileSystem(); string errorMessage; if (!this.TryCreateAlternatesFile(fileSystem, enlistment, out errorMessage)) { return(new Result("Error configuring alternate: " + errorMessage)); } GitRepo gitRepo = new GitRepo(tracer, enlistment, fileSystem); GVFSContext context = new GVFSContext(tracer, fileSystem, gitRepo, enlistment); GVFSGitObjects gitObjects = new GVFSGitObjects(context, objectRequestor); if (!this.TryDownloadCommit( refs.GetTipCommitId(branch), enlistment, objectRequestor, gitObjects, gitRepo, out errorMessage)) { return(new Result(errorMessage)); } if (!GVFSVerb.TrySetRequiredGitConfigSettings(enlistment) || !GVFSVerb.TrySetOptionalGitConfigSettings(enlistment)) { return(new Result("Unable to configure git repo")); } CacheServerResolver cacheServerResolver = new CacheServerResolver(tracer, enlistment); if (!cacheServerResolver.TrySaveUrlToLocalConfig(objectRequestor.CacheServer, out errorMessage)) { return(new Result("Unable to configure cache server: " + errorMessage)); } GitProcess git = new GitProcess(enlistment); string originBranchName = "origin/" + branch; GitProcess.Result createBranchResult = git.CreateBranchWithUpstream(branch, originBranchName); if (createBranchResult.ExitCodeIsFailure) { return(new Result("Unable to create branch '" + originBranchName + "': " + createBranchResult.Errors + "\r\n" + createBranchResult.Output)); } File.WriteAllText( Path.Combine(enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Head), "ref: refs/heads/" + branch); if (!this.TryDownloadRootGitAttributes(enlistment, gitObjects, gitRepo, out errorMessage)) { return(new Result(errorMessage)); } this.CreateGitScript(enlistment); string installHooksError; if (!HooksInstaller.InstallHooks(context, out installHooksError)) { tracer.RelatedError(installHooksError); return(new Result(installHooksError)); } GitProcess.Result forceCheckoutResult = git.ForceCheckout(branch); if (forceCheckoutResult.ExitCodeIsFailure && forceCheckoutResult.Errors.IndexOf("unable to read tree") > 0) { // It is possible to have the above TryDownloadCommit() fail because we // already have the commit and root tree we intend to check out, but // don't have a tree further down the working directory. If we fail // checkout here, its' because we don't have these trees and the // read-object hook is not available yet. Force downloading the commit // again and retry the checkout. if (!this.TryDownloadCommit( refs.GetTipCommitId(branch), enlistment, objectRequestor, gitObjects, gitRepo, out errorMessage, checkLocalObjectCache: false)) { return(new Result(errorMessage)); } forceCheckoutResult = git.ForceCheckout(branch); } if (forceCheckoutResult.ExitCodeIsFailure) { string[] errorLines = forceCheckoutResult.Errors.Split('\n'); StringBuilder checkoutErrors = new StringBuilder(); foreach (string gitError in errorLines) { if (IsForceCheckoutErrorCloneFailure(gitError)) { checkoutErrors.AppendLine(gitError); } } if (checkoutErrors.Length > 0) { string error = "Could not complete checkout of branch: " + branch + ", " + checkoutErrors.ToString(); tracer.RelatedError(error); return(new Result(error)); } } if (!RepoMetadata.TryInitialize(tracer, enlistment.DotGVFSRoot, out errorMessage)) { tracer.RelatedError(errorMessage); return(new Result(errorMessage)); } try { RepoMetadata.Instance.SaveCloneMetadata(tracer, enlistment); this.LogEnlistmentInfoAndSetConfigValues(tracer, git, enlistment); } catch (Exception e) { tracer.RelatedError(e.ToString()); return(new Result(e.Message)); } finally { RepoMetadata.Shutdown(); } // Prepare the working directory folder for GVFS last to ensure that gvfs mount will fail if gvfs clone has failed Exception exception; string prepFileSystemError; if (!GVFSPlatform.Instance.KernelDriver.TryPrepareFolderForCallbacks(enlistment.WorkingDirectoryRoot, out prepFileSystemError, out exception)) { EventMetadata metadata = new EventMetadata(); metadata.Add(nameof(prepFileSystemError), prepFileSystemError); if (exception != null) { metadata.Add("Exception", exception.ToString()); } tracer.RelatedError(metadata, $"{nameof(this.CreateClone)}: TryPrepareFolderForCallbacks failed"); return(new Result(prepFileSystemError)); } return(new Result(true)); }
public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger) { string repositoryRoot = _environment.DeploymentRepositoryPath; var configuration = new DeploymentConfiguration(repositoryRoot); // If the repository has an explicit pointer to a project path to be deployed // then use it. string targetProjectPath = configuration.ProjectPath; if (!String.IsNullOrEmpty(targetProjectPath)) { tracer.Trace("Found .deployment file in repository"); // Try to resolve the project return(ResolveProject(repositoryRoot, targetProjectPath, tryWebSiteProject: true, searchOption: SearchOption.TopDirectoryOnly)); } // Get all solutions in the current repository path var solutions = VsHelper.GetSolutions(repositoryRoot).ToList(); if (!solutions.Any()) { return(ResolveProject(repositoryRoot, searchOption: SearchOption.AllDirectories)); } // More than one solution is ambiguous if (solutions.Count > 1) { // TODO: Show relative paths in error messages ThrowAmbiguousSolutionsError(solutions); } // We have a solution VsSolution solution = solutions[0]; // We need to determine what project to deploy so get a list of all web projects and // figure out with some heuristic, which one to deploy. // TODO: Pick only 1 and throw if there's more than one VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite).FirstOrDefault(); if (project == null) { logger.Log(Resources.Log_NoDeployableProjects, solution.Path); return(new BasicBuilder(repositoryRoot, _environment.TempPath)); } if (project.IsWap) { return(new WapBuilder(_propertyProvider, repositoryRoot, project.AbsolutePath, _environment.TempPath, _environment.NuGetCachePath, solution.Path)); } return(new WebSiteBuilder(_propertyProvider, repositoryRoot, project.AbsolutePath, _environment.TempPath, _environment.NuGetCachePath, solution.Path)); }
static int Main(string[] args) { // Turn flag on in app.config to wait for debugger on launch if (ConfigurationManager.AppSettings["WaitForDebuggerOnStart"] == "true") { while (!Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } } if (args.Length < 2) { System.Console.WriteLine("Usage: kudu.exe appRoot wapTargets [deployer]"); return(1); } // The post receive hook launches the exe from sh and intereprets newline differently. // This fixes very wacky issues with how the output shows up in the conosle on push System.Console.Error.NewLine = "\n"; System.Console.Out.NewLine = "\n"; System.Environment.SetEnvironmentVariable("GIT_DIR", null, System.EnvironmentVariableTarget.Process); string appRoot = args[0]; string wapTargets = args[1]; string deployer = args.Length == 2 ? null : args[2]; IEnvironment env = GetEnvironment(appRoot); ISettings settings = new XmlSettings.Settings(GetSettingsPath(env)); IDeploymentSettingsManager settingsManager = new DeploymentSettingsManager(settings); // Adjust repo path env.RepositoryPath = Path.Combine(env.SiteRootPath, settingsManager.GetRepositoryPath()); // Setup the trace IFileSystem fileSystem = new FileSystem(); TraceLevel level = settingsManager.GetTraceLevel(); ITracer tracer = GetTracer(env, level, fileSystem); ITraceFactory traceFactory = new TracerFactory(() => tracer); // Calculate the lock path string lockPath = Path.Combine(env.SiteRootPath, Constants.LockPath); string deploymentLockPath = Path.Combine(lockPath, Constants.DeploymentLockFile); string statusLockPath = Path.Combine(lockPath, Constants.StatusLockFile); IOperationLock deploymentLock = new LockFile(deploymentLockPath, traceFactory, fileSystem); IOperationLock statusLock = new LockFile(statusLockPath, traceFactory, fileSystem); IBuildPropertyProvider buildPropertyProvider = new BuildPropertyProvider(); ISiteBuilderFactory builderFactory = new SiteBuilderFactoryDispatcher(buildPropertyProvider, env); IRepository gitRepository = new GitExeRepository(env, settingsManager, traceFactory); var logger = new ConsoleLogger(); IDeploymentManager deploymentManager = new DeploymentManager(builderFactory, env, fileSystem, traceFactory, settingsManager, new DeploymentStatusManager(env, fileSystem, statusLock), deploymentLock, GetLogger(env, level, logger)); var step = tracer.Step("Executing external process", new Dictionary <string, string> { { "type", "process" }, { "path", "kudu.exe" }, { "arguments", appRoot + " " + wapTargets } }); using (step) { try { deploymentManager.Deploy(gitRepository, changeSet: null, deployer: deployer, clean: false); } catch (Exception e) { System.Console.Error.WriteLine(e.Message); System.Console.Error.WriteLine(Resources.Log_DeploymentError); return(1); } } if (logger.HasErrors) { System.Console.Error.WriteLine(Resources.Log_DeploymentError); return(1); } return(0); }
public abstract FileBasedLock CreateFileBasedLock( PhysicalFileSystem fileSystem, ITracer tracer, string lockPath);
public OpenTracingLogger(ITracer tracer, string categoryName) { _tracer = tracer; _categoryName = categoryName; }
/// <summary> /// Initializes a new instance of the <see cref="StackExchangeRedisCallsCollector"/> class. /// </summary> /// <param name="options">Configuration options for dependencies collector.</param> /// <param name="tracer">Tracer to record traced with.</param> /// <param name="sampler">Sampler to use to sample dependnecy calls.</param> /// <param name="exportComponent">TEMPORARY: handler to send data to.</param> public StackExchangeRedisCallsCollector(StackExchangeRedisCallsCollectorOptions options, ITracer tracer, ISampler sampler, IExportComponent exportComponent) { this.tracer = tracer; this.exporter = exportComponent; this.sampler = sampler; this.cancellationTokenSource = new CancellationTokenSource(); this.cancellationToken = this.cancellationTokenSource.Token; Task.Factory.StartNew(this.DumpEntries, TaskCreationOptions.LongRunning, this.cancellationToken); }
/// <summary> /// Extracts the specified tracer. /// </summary> /// <param name="inputHeaders">The input headers.</param> /// <param name="tracer">The tracer.</param> /// <param name="headers">The headers.</param> /// <returns></returns> public static ISpanContext Extract(this IDictionary <string, object> inputHeaders, ITracer tracer, IStandardHeaders headers) { if (inputHeaders.ContainsKey(headers.TraceSpan.Name)) { var mapping = (DataMappingTextMap)inputHeaders[headers.TraceSpan.Name]; return(tracer.Extract(BuiltinFormats.TextMap, mapping)); } return(null); }
protected MockDeviceBase(ILogger logger, ITracer tracer) : base(logger, tracer) { }
private bool TryBackupFiles(ITracer tracer, GVFSEnlistment enlistment, string backupRoot) { string backupSrc = Path.Combine(backupRoot, "src"); string backupGit = Path.Combine(backupRoot, ".git"); string backupGvfs = Path.Combine(backupRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot); string backupDatabases = Path.Combine(backupGvfs, GVFSConstants.DotGVFS.Databases.Name); string errorMessage = string.Empty; if (!this.ShowStatusWhileRunning( () => { string ioError; if (!this.TryIO(tracer, () => Directory.CreateDirectory(backupRoot), "Create backup directory", out ioError) || !this.TryIO(tracer, () => Directory.CreateDirectory(backupGit), "Create backup .git directory", out ioError) || !this.TryIO(tracer, () => Directory.CreateDirectory(backupGvfs), "Create backup .gvfs directory", out ioError) || !this.TryIO(tracer, () => Directory.CreateDirectory(backupDatabases), "Create backup .gvfs databases directory", out ioError)) { errorMessage = "Failed to create backup folders at " + backupRoot + ": " + ioError; return(false); } // Move the current src folder to the backup location... if (!this.TryIO(tracer, () => Directory.Move(enlistment.WorkingDirectoryRoot, backupSrc), "Move the src folder", out ioError)) { errorMessage = "Failed to move the src folder: " + ioError + Environment.NewLine; errorMessage += "Make sure you have no open handles or running processes in the src folder"; return(false); } // ... but move the .git folder back to the new src folder so we can preserve objects, refs, logs... if (!this.TryIO(tracer, () => Directory.CreateDirectory(enlistment.WorkingDirectoryRoot), "Create new src folder", out errorMessage) || !this.TryIO(tracer, () => Directory.Move(Path.Combine(backupSrc, ".git"), enlistment.DotGitRoot), "Keep existing .git folder", out errorMessage)) { return(false); } // ... backup the .gvfs hydration-related data structures... string databasesFolder = Path.Combine(enlistment.DotGVFSRoot, GVFSConstants.DotGVFS.Databases.Name); if (!this.TryBackupFilesInFolder(tracer, databasesFolder, backupDatabases, searchPattern: "*", filenamesToSkip: "RepoMetadata.dat")) { return(false); } // ... backup everything related to the .git\index... if (!this.TryIO( tracer, () => File.Move( Path.Combine(enlistment.DotGitRoot, GVFSConstants.DotGit.IndexName), Path.Combine(backupGit, GVFSConstants.DotGit.IndexName)), "Backup the git index", out errorMessage) || !this.TryIO( tracer, () => File.Move( Path.Combine(enlistment.DotGVFSRoot, GitIndexProjection.ProjectionIndexBackupName), Path.Combine(backupGvfs, GitIndexProjection.ProjectionIndexBackupName)), "Backup GVFS_projection", out errorMessage)) { return(false); } // ... backup all .git\*.lock files if (!this.TryBackupFilesInFolder(tracer, enlistment.DotGitRoot, backupGit, searchPattern: "*.lock")) { return(false); } return(true); }, "Backing up your files")) { this.Output.WriteLine(); this.WriteMessage(tracer, "ERROR: " + errorMessage); return(false); } return(true); }
public async Task <List <Alert> > AnalyzeResourcesAsync(AnalysisRequest analysisRequest, ITracer tracer, CancellationToken cancellationToken) { this.IsRunning = true; this.AssertAnalysisRequestParameters(analysisRequest.RequestParameters, assertRequestTime: true); await analysisRequest.StateRepository.StoreStateAsync("test key", "test state", cancellationToken); if (this.ShouldStuck) { try { await Task.Delay(int.MaxValue, cancellationToken); } catch (TaskCanceledException) { this.WasCanceled = true; throw; } } if (this.ShouldThrow) { throw this.ExceptionToThrow ?? new DivideByZeroException(); } if (this.ShouldThrowCustom) { throw new CustomException(); } return(new List <Alert> { new TestAlert(analysisRequest.RequestParameters.TargetResources.First(), this.ShouldAutoResolve) }); }
private Tuple <string, string> ExecuteInternal(ITracer tracer, Func <string, bool> onWriteOutput, Func <string, bool> onWriteError, Encoding encoding, string arguments, params object[] args) { var cmdArguments = String.Format(arguments, args); var errorBuffer = new StringBuilder(); var outputBuffer = new StringBuilder(); var idleManager = new IdleManager(IdleTimeout, tracer); var outputStream = new AsyncStreamWriter(data => { idleManager.UpdateActivity(); if (data != null) { if (onWriteOutput(data)) { outputBuffer.AppendLine(Encoding.UTF8.GetString(encoding.GetBytes(data))); } } }, Encoding ?? Console.OutputEncoding); var errorStream = new AsyncStreamWriter(data => { idleManager.UpdateActivity(); if (data != null) { if (onWriteError(data)) { errorBuffer.AppendLine(Encoding.UTF8.GetString(encoding.GetBytes(data))); } } }, Encoding ?? Console.OutputEncoding); int exitCode; try { // common execute exitCode = Task.Run(() => ExecuteAsync(tracer, cmdArguments, outputStream, errorStream, idleManager: idleManager)).Result; } catch (AggregateException ex) { foreach (var inner in ex.Flatten().InnerExceptions) { onWriteError(inner.Message); } throw; } catch (Exception ex) { onWriteError(ex.Message); throw; } finally { // flush out last buffer if any outputStream.Dispose(); errorStream.Dispose(); } string output = outputBuffer.ToString().Trim(); string error = errorBuffer.ToString().Trim(); if (exitCode != 0) { throw new CommandLineException(Path, cmdArguments, error) { ExitCode = exitCode, Output = output, Error = error }; } return(Tuple.Create(output, error)); }
public override void Execute(ITracer tracer = null) { if (tracer != null) { throw new InvalidOperationException("Clone does not support being called with an existing tracer"); } this.CheckElevated(); this.CheckGVFltRunning(); string fullPath = GVFSEnlistment.ToFullPath(this.EnlistmentRootPath, this.GetDefaultEnlistmentRoot()); if (fullPath == null) { this.ReportErrorAndExit("Unable to write to directory " + this.EnlistmentRootPath); } this.EnlistmentRootPath = fullPath; this.Output.WriteLine(); this.Output.WriteLine("Starting clone of {0} into {1}...", this.RepositoryURL, this.EnlistmentRootPath); this.Output.WriteLine(); this.CacheServerUrl = Enlistment.StripObjectsEndpointSuffix(this.CacheServerUrl); try { GVFSEnlistment enlistment; Result cloneResult = this.TryCreateEnlistment(out enlistment); if (cloneResult.Success) { using (JsonEtwTracer cloneTracer = new JsonEtwTracer(GVFSConstants.GVFSEtwProviderName, "GVFSClone")) { cloneTracer.AddLogFileEventListener( GVFSEnlistment.GetNewGVFSLogFileName( Path.Combine(this.EnlistmentRootPath, GVFSConstants.DotGVFSPath, GVFSConstants.GVFSLogFolderName), this.VerbName), EventLevel.Informational, Keywords.Any); cloneTracer.AddConsoleEventListener(EventLevel.Informational, Keywords.Any); cloneTracer.WriteStartEvent( enlistment.EnlistmentRoot, enlistment.RepoUrl, enlistment.CacheServerUrl, new EventMetadata { { "Branch", this.Branch }, { "SingleBranch", this.SingleBranch }, { "NoMount", this.NoMount }, { "NoPrefetch", this.NoPrefetch } }); cloneResult = this.TryClone(cloneTracer, enlistment); if (cloneResult.Success) { this.Output.WriteLine("GVFS Enlistment created @ {0}", this.EnlistmentRootPath); if (!this.NoPrefetch) { PrefetchVerb prefetch = new PrefetchVerb(); prefetch.EnlistmentRootPath = this.EnlistmentRootPath; prefetch.Commits = true; prefetch.Execute(cloneTracer); } if (this.NoMount) { this.Output.WriteLine("\r\nIn order to mount, first cd to within your enlistment, then call: "); this.Output.WriteLine(CloneVerb.MountVerb); } else { MountVerb mount = new MountVerb(); mount.EnlistmentRootPath = this.EnlistmentRootPath; // Tracer will be disposed in mount.Execute to avoid conflicts with the background process. mount.Execute(cloneTracer); } } } } // Write to the output after the tracer is disposed so that the error is the last message // displayed to the user if (!cloneResult.Success) { this.Output.WriteLine("\r\nCannot clone @ {0}", this.EnlistmentRootPath); this.Output.WriteLine("Error: {0}", cloneResult.ErrorMessage); Environment.ExitCode = (int)ReturnCode.GenericError; } } catch (AggregateException e) { this.Output.WriteLine("Cannot clone @ {0}:", this.EnlistmentRootPath); foreach (Exception ex in e.Flatten().InnerExceptions) { this.Output.WriteLine("Exception: {0}", ex.ToString()); } Environment.ExitCode = (int)ReturnCode.GenericError; } catch (VerbAbortedException) { throw; } catch (Exception e) { this.ReportErrorAndExit("Cannot clone @ {0}: {1}", this.EnlistmentRootPath, e.ToString()); } }
public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSettingsManager settings, IRepository repository, DeploymentInfoBase deploymentInfo) { string repositoryRoot = repository.RepositoryPath; // Use the cached vs projects file finder for: a. better performance, b. ignoring solutions/projects under node_modules var fileFinder = new CachedVsProjectsFileFinder(repository); // If there's a custom deployment file then let that take over. var command = settings.GetValue(SettingsKeys.Command); if (!String.IsNullOrEmpty(command)) { return(new CustomBuilder(_environment, settings, _propertyProvider, repositoryRoot, command)); } // If the user provided specific generator arguments, that overrides any detection logic string scriptGeneratorArgs = settings.GetValue(SettingsKeys.ScriptGeneratorArgs); if (!String.IsNullOrEmpty(scriptGeneratorArgs)) { return(new CustomGeneratorCommandSiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, scriptGeneratorArgs)); } // If the repository has an explicit pointer to a project path to be deployed // then use it. string targetProjectPath = settings.GetValue(SettingsKeys.Project); if (!String.IsNullOrEmpty(targetProjectPath)) { tracer.Trace("Specific project was specified: " + targetProjectPath); targetProjectPath = Path.GetFullPath(Path.Combine(repositoryRoot, targetProjectPath.TrimStart('/', '\\'))); } if (deploymentInfo != null && deploymentInfo.Deployer == Constants.OneDeploy) { var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot; return(new OneDeployBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath, deploymentInfo)); } if (settings.RunFromLocalZip()) { return(new RunFromZipSiteBuilder()); } if (!settings.DoBuildDuringDeployment()) { var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot; return(new BasicBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath)); } // Check if we really need a builder for this // If not, return the NoOpBuilder string appFramework = System.Environment.GetEnvironmentVariable("FRAMEWORK"); if (!string.IsNullOrEmpty(appFramework) && string.Equals(appFramework, "STATICSITE", StringComparison.OrdinalIgnoreCase)) { var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot; return(new NoOpBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath)); } // If ENABLE_ORYX_BUILD is not set, for function app, we assume it on by default string enableOryxBuild = System.Environment.GetEnvironmentVariable("ENABLE_ORYX_BUILD"); if (!string.IsNullOrEmpty(enableOryxBuild)) { if (StringUtils.IsTrueLike(enableOryxBuild)) { return(new OryxBuilder(_environment, settings, _propertyProvider, repositoryRoot)); } } else if (FunctionAppHelper.LooksLikeFunctionApp()) { return(new OryxBuilder(_environment, settings, _propertyProvider, repositoryRoot)); } string framework = System.Environment.GetEnvironmentVariable("FRAMEWORK"); if (framework.Equals("ruby", StringComparison.OrdinalIgnoreCase)) { return(new RubySiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, targetProjectPath)); } if (!String.IsNullOrEmpty(targetProjectPath)) { // Try to resolve the project return(ResolveProject(repositoryRoot, targetProjectPath, settings, fileFinder, tryWebSiteProject: true, searchOption: SearchOption.TopDirectoryOnly)); } // Get all solutions in the current repository path var solutions = VsHelper.GetSolutions(repositoryRoot, fileFinder).ToList(); if (!solutions.Any()) { return(ResolveProject(repositoryRoot, settings, fileFinder, searchOption: SearchOption.AllDirectories)); } // More than one solution is ambiguous if (solutions.Count > 1) { // TODO: Show relative paths in error messages ThrowAmbiguousSolutionsError(solutions); } // We have a solution VsSolution solution = solutions[0]; // We need to determine what project to deploy so get a list of all web projects and // figure out with some heuristic, which one to deploy. // TODO: Pick only 1 and throw if there's more than one // shunTODO need to implement this VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite || p.IsAspNetCore || p.IsFunctionApp).FirstOrDefault(); if (project == null) { // Try executable type project project = solution.Projects.Where(p => p.IsExecutable).FirstOrDefault(); if (project != null) { return(new DotNetConsoleBuilder(_environment, settings, _propertyProvider, repositoryRoot, project.AbsolutePath, solution.Path)); } logger.Log(Resources.Log_NoDeployableProjects, solution.Path); // we have a solution file, but no deployable project // shunTODO how often do we run into this return(ResolveNonAspProject(repositoryRoot, null, settings)); } if (project.IsWap) { return(new WapBuilder(_environment, settings, _propertyProvider, repositoryRoot, project.AbsolutePath, solution.Path)); } if (project.IsAspNetCore) { return(new AspNetCoreBuilder(_environment, settings, _propertyProvider, repositoryRoot, project.AbsolutePath, solution.Path)); } if (project.IsWebSite) { return(new WebSiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, project.AbsolutePath, solution.Path)); } return(new FunctionMsbuildBuilder(_environment, settings, _propertyProvider, repositoryRoot, project.AbsolutePath, solution.Path)); }
private static int PerformDeploy( string appRoot, string wapTargets, string deployer, string lockPath, IEnvironment env, IDeploymentSettingsManager settingsManager, TraceLevel level, ITracer tracer, ITraceFactory traceFactory, IOperationLock deploymentLock) { System.Environment.SetEnvironmentVariable("GIT_DIR", null, System.EnvironmentVariableTarget.Process); // Skip SSL Certificate Validate if (System.Environment.GetEnvironmentVariable(SettingsKeys.SkipSslValidation) == "1") { ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; } // Adjust repo path env.RepositoryPath = Path.Combine(env.SiteRootPath, settingsManager.GetRepositoryPath()); string statusLockPath = Path.Combine(lockPath, Constants.StatusLockFile); string hooksLockPath = Path.Combine(lockPath, Constants.HooksLockFile); IOperationLock statusLock = new LockFile(statusLockPath, traceFactory); IOperationLock hooksLock = new LockFile(hooksLockPath, traceFactory); IBuildPropertyProvider buildPropertyProvider = new BuildPropertyProvider(); ISiteBuilderFactory builderFactory = new SiteBuilderFactory(buildPropertyProvider, env); var logger = new ConsoleLogger(); IRepository gitRepository; if (settingsManager.UseLibGit2SharpRepository()) { gitRepository = new LibGit2SharpRepository(env, settingsManager, traceFactory); } else { gitRepository = new GitExeRepository(env, settingsManager, traceFactory); } IServerConfiguration serverConfiguration = new ServerConfiguration(SystemEnvironment.Instance); IAnalytics analytics = new Analytics(settingsManager, serverConfiguration, traceFactory); IWebHooksManager hooksManager = new WebHooksManager(tracer, env, hooksLock); IDeploymentStatusManager deploymentStatusManager = new DeploymentStatusManager(env, analytics, statusLock); IDeploymentManager deploymentManager = new DeploymentManager(builderFactory, env, traceFactory, analytics, settingsManager, deploymentStatusManager, deploymentLock, GetLogger(env, level, logger), hooksManager); var step = tracer.Step(XmlTracer.ExecutingExternalProcessTrace, new Dictionary <string, string> { { "type", "process" }, { "path", "kudu.exe" }, { "arguments", appRoot + " " + wapTargets } }); using (step) { try { // although the api is called DeployAsync, most expensive works are done synchronously. // need to launch separate task to go async explicitly (consistent with FetchDeploymentManager) var deploymentTask = Task.Run(async() => await deploymentManager.DeployAsync(gitRepository, changeSet: null, deployer: deployer, clean: false)); #pragma warning disable 4014 // Track pending task PostDeploymentHelper.TrackPendingOperation(deploymentTask, TimeSpan.Zero); #pragma warning restore 4014 deploymentTask.Wait(); if (PostDeploymentHelper.IsAutoSwapEnabled()) { string branch = settingsManager.GetBranch(); ChangeSet changeSet = gitRepository.GetChangeSet(branch); IDeploymentStatusFile statusFile = deploymentStatusManager.Open(changeSet.Id); if (statusFile != null && statusFile.Status == DeployStatus.Success) { PostDeploymentHelper.PerformAutoSwap(env.RequestId, new PostDeploymentTraceListener(tracer, deploymentManager.GetLogger(changeSet.Id))) .Wait(); } } } catch (Exception e) { tracer.TraceError(e); System.Console.Error.WriteLine(e.GetBaseException().Message); System.Console.Error.WriteLine(Resources.Log_DeploymentError); return(1); } finally { System.Console.WriteLine("Deployment Logs : '" + env.AppBaseUrlPrefix + "/newui/jsonviewer?view_url=/api/deployments/" + gitRepository.GetChangeSet(settingsManager.GetBranch()).Id + "/log'"); } } if (logger.HasErrors) { return(1); } tracer.Step("Perform deploy exiting successfully"); return(0); }
private async Task <string> DeployZipLocally(ZipDeploymentInfo zipDeploymentInfo, ITracer tracer) { var content = await DeploymentHelper.GetZipContentFromURL(zipDeploymentInfo, tracer); var zipFileName = Path.ChangeExtension(Path.GetRandomFileName(), "zip"); var zipFilePath = Path.Combine(_environment.ZipTempPath, zipFileName); using (_tracer.Step("Downloading content from {0} to {1}", zipDeploymentInfo.ZipURL.Split('?')[0], zipFilePath)) { await content.CopyToAsync(zipFilePath, _tracer); } zipDeploymentInfo.RepositoryUrl = zipFilePath; return(zipFilePath); }
private static int Main(string[] args) { // Configure Logging if running on Azure if (System.Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID") != null) { XmlDocument log4netConfig = new XmlDocument(); log4netConfig.Load(File.OpenRead("/opt/Kudu/KuduConsole/log4net.config")); var repo = log4net.LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy)); log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]); } // Turn flag on in app.config to wait for debugger on launch if (ConfigurationManager.AppSettings["WaitForDebuggerOnStart"] == "true") { while (!Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } } if (System.Environment.GetEnvironmentVariable(SettingsKeys.DisableDeploymentOnPush) == "1") { return(0); } if (args.Length < 2) { System.Console.WriteLine("Usage: kudu.exe appRoot wapTargets [deployer]"); return(1); } // The post receive hook launches the exe from sh and intereprets newline differently. // This fixes very wacky issues with how the output shows up in the console on push System.Console.Error.NewLine = "\n"; System.Console.Out.NewLine = "\n"; string appRoot = args[0]; string wapTargets = args[1]; string deployer = args.Length == 2 ? null : args[2]; string requestId = System.Environment.GetEnvironmentVariable(Constants.RequestIdHeader); IEnvironment env = GetEnvironment(appRoot, requestId); ISettings settings = new XmlSettings.Settings(GetSettingsPath(env)); IDeploymentSettingsManager settingsManager = new DeploymentSettingsManager(settings); // Setup the trace TraceLevel level = settingsManager.GetTraceLevel(); ITracer tracer = GetTracer(env, level); ITraceFactory traceFactory = new TracerFactory(() => tracer); // Calculate the lock path string lockPath = Path.Combine(env.SiteRootPath, Constants.LockPath); string deploymentLockPath = Path.Combine(lockPath, Constants.DeploymentLockFile); IOperationLock deploymentLock = DeploymentLockFile.GetInstance(deploymentLockPath, traceFactory); if (deploymentLock.IsHeld) { return(PerformDeploy(appRoot, wapTargets, deployer, lockPath, env, settingsManager, level, tracer, traceFactory, deploymentLock)); } // Cross child process lock is not working on linux via mono. // When we reach here, deployment lock must be HELD! To solve above issue, we lock again before continue. try { return(deploymentLock.LockOperation(() => { return PerformDeploy(appRoot, wapTargets, deployer, lockPath, env, settingsManager, level, tracer, traceFactory, deploymentLock); }, "Performing deployment", TimeSpan.Zero)); } catch (LockOperationException) { return(-1); } }
public Cook(ITracer tracer) { _tracer = tracer; }
private async Task LocalZipFetch(IRepository repository, DeploymentInfoBase deploymentInfo, string targetBranch, ILogger logger, ITracer tracer) { var zipDeploymentInfo = (ZipDeploymentInfo)deploymentInfo; // If this was a request with a Zip URL in the JSON, we need to deploy the zip locally and get the path // Otherwise, for this kind of deployment, RepositoryUrl is a local path. var sourceZipFile = !string.IsNullOrEmpty(zipDeploymentInfo.ZipURL) ? await DeployZipLocally(zipDeploymentInfo, tracer) : zipDeploymentInfo.RepositoryUrl; var extractTargetDirectory = repository.RepositoryPath; var info = FileSystemHelpers.FileInfoFromFileName(sourceZipFile); var sizeInMb = (info.Length / (1024f * 1024f)).ToString("0.00", CultureInfo.InvariantCulture); var message = String.Format( CultureInfo.InvariantCulture, "Cleaning up temp folders from previous zip deployments and extracting pushed zip file {0} ({1} MB) to {2}", info.FullName, sizeInMb, extractTargetDirectory); logger.Log(message); using (tracer.Step(message)) { // If extractTargetDirectory already exists, rename it so we can delete it concurrently with // the unzip (along with any other junk in the folder) var targetInfo = FileSystemHelpers.DirectoryInfoFromDirectoryName(extractTargetDirectory); if (targetInfo.Exists) { var moveTarget = Path.Combine(targetInfo.Parent.FullName, Path.GetRandomFileName()); using (tracer.Step(string.Format("Renaming extractTargetDirectory({0}) to tempDirectory({1})", targetInfo.FullName, moveTarget))) { targetInfo.MoveTo(moveTarget); } } var cleanTask = Task.Run(() => DeleteFilesAndDirsExcept(sourceZipFile, extractTargetDirectory, tracer)); var extractTask = Task.Run(() => { FileSystemHelpers.CreateDirectory(extractTargetDirectory); using (var file = info.OpenRead()) using (var zip = new ZipArchive(file, ZipArchiveMode.Read)) { zip.Extract(extractTargetDirectory, tracer, _settings.GetZipDeployDoNotPreserveFileTime()); } }); await Task.WhenAll(cleanTask, extractTask); } CommitRepo(repository, zipDeploymentInfo); }
public CheckoutJob(int maxParallel, IEnumerable <string> folderList, string targetCommitSha, ITracer tracer, Enlistment enlistment) : base(1) { this.tracer = tracer.StartActivity(AreaPath, EventLevel.Informational, Keywords.Telemetry, metadata: null); this.enlistment = enlistment; this.diff = new DiffHelper(tracer, enlistment, new string[0], folderList); this.targetCommitSha = targetCommitSha; this.AvailableBlobShas = new BlockingCollection <string>(); // Keep track of how parallel we're expected to be later during DoWork // Note that '1' is passed to the Job base object, forcing DoWork to be single threaded // This allows us to control the synchronization between stages by doing the parallization ourselves this.maxParallel = maxParallel; }
private static bool TryCopyNativeLibToAppDirectory(ITracer tracer, PhysicalFileSystem fileSystem, string gvfsAppDirectory) { string installFilePath; string appFilePath; GetNativeLibPaths(gvfsAppDirectory, out installFilePath, out appFilePath); EventMetadata pathMetadata = CreateEventMetadata(); pathMetadata.Add(nameof(gvfsAppDirectory), gvfsAppDirectory); pathMetadata.Add(nameof(installFilePath), installFilePath); pathMetadata.Add(nameof(appFilePath), appFilePath); if (fileSystem.FileExists(installFilePath)) { tracer.RelatedEvent(EventLevel.Informational, $"{nameof(TryCopyNativeLibToAppDirectory)}_CopyingNativeLib", pathMetadata); try { fileSystem.CopyFile(installFilePath, appFilePath, overwrite: true); try { Common.NativeMethods.FlushFileBuffers(appFilePath); } catch (Win32Exception e) { EventMetadata metadata = CreateEventMetadata(e); metadata.Add(nameof(appFilePath), appFilePath); metadata.Add(nameof(installFilePath), installFilePath); tracer.RelatedWarning(metadata, $"{nameof(TryCopyNativeLibToAppDirectory)}: Win32Exception while trying to flush file buffers", Keywords.Telemetry); } } catch (UnauthorizedAccessException e) { EventMetadata metadata = CreateEventMetadata(e); tracer.RelatedError(metadata, $"{nameof(TryCopyNativeLibToAppDirectory)}: UnauthorizedAccessException caught while trying to copy native lib"); return(false); } catch (DirectoryNotFoundException e) { EventMetadata metadata = CreateEventMetadata(e); tracer.RelatedError(metadata, $"{nameof(TryCopyNativeLibToAppDirectory)}: DirectoryNotFoundException caught while trying to copy native lib"); return(false); } catch (FileNotFoundException e) { EventMetadata metadata = CreateEventMetadata(e); tracer.RelatedError(metadata, $"{nameof(TryCopyNativeLibToAppDirectory)}: FileNotFoundException caught while trying to copy native lib"); return(false); } catch (IOException e) { EventMetadata metadata = CreateEventMetadata(e); tracer.RelatedWarning(metadata, $"{nameof(TryCopyNativeLibToAppDirectory)}: IOException caught while trying to copy native lib"); if (fileSystem.FileExists(appFilePath)) { tracer.RelatedWarning( CreateEventMetadata(), "Could not copy native lib to app directory, but file already exists, continuing with install", Keywords.Telemetry); } else { tracer.RelatedError($"{nameof(TryCopyNativeLibToAppDirectory)}: Failed to copy native lib to app directory"); return(false); } } } else { tracer.RelatedError(pathMetadata, $"{nameof(TryCopyNativeLibToAppDirectory)}: Native lib does not exist in install directory"); return(false); } return(true); }
public StandaloneConfiguration([NotNull] ITracer tracer) : base(tracer) { Contract.Requires(tracer != null); }
public GitServerHttpHandler(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock, IDeploymentManager deploymentManager) { _gitServer = gitServer; _tracer = tracer; _deploymentLock = deploymentLock; _deploymentManager = deploymentManager; }
public SSHKeyController(ITracer tracer, ISSHKeyManager sshKeyManager, IFileSystem fileSystem, IOperationLock sshKeyLock) { _tracer = tracer; _sshKeyManager = sshKeyManager; _fileSystem = fileSystem; _sshKeyLock = sshKeyLock; }
public virtual async Task Fetch(IRepository repository, DeploymentInfo deploymentInfo, string targetBranch, ILogger logger, ITracer tracer) { // (A)sync with dropbox var dropboxInfo = (DropboxInfo)deploymentInfo; _dropBoxHelper.Logger = logger; deploymentInfo.TargetChangeset = await _dropBoxHelper.Sync(dropboxInfo, targetBranch, repository, tracer); }
public FetchHandler(ITracer tracer, IDeploymentManager deploymentManager, IDeploymentSettingsManager settings, IDeploymentStatusManager status, IOperationLock deploymentLock, IEnvironment environment, IEnumerable<IServiceHookHandler> serviceHookHandlers, IRepositoryFactory repositoryFactory, IAutoSwapHandler autoSwapHandler) { _tracer = tracer; _deploymentLock = deploymentLock; _environment = environment; _deploymentManager = deploymentManager; _settings = settings; _status = status; _serviceHookHandlers = serviceHookHandlers; _repositoryFactory = repositoryFactory; _autoSwapHandler = autoSwapHandler; _markerFilePath = Path.Combine(environment.DeploymentsPath, "pending"); // Prefer marker creation in ctor to delay create when needed. // This is to keep the code simple and avoid creation synchronization. if (!FileSystemHelpers.FileExists(_markerFilePath)) { try { FileSystemHelpers.WriteAllText(_markerFilePath, String.Empty); } catch (Exception ex) { tracer.TraceError(ex); } } }
public DataEngine(ITracer tracer, string instanceName, int maxConcurrency, IStorageDriver storageDriver, DataContainerDescriptor containerDescriptor) { if (tracer == null) { throw new ArgumentNullException("tracer"); } if (maxConcurrency <= 0 || maxConcurrency > 10000) { throw new ArgumentOutOfRangeException("maxConcurrency"); } if (storageDriver == null) { throw new ArgumentNullException("storageDriver"); } if (containerDescriptor == null) { throw new ArgumentNullException("containerDescriptor"); } m_tracer = tracer; m_containerDescriptor = containerDescriptor; m_maxConcurrency = maxConcurrency; m_parsedRequestCache = new ParsedRequestCache(instanceName); m_storageDriver = storageDriver; m_parser = new QueryParser(containerDescriptor, maxConcurrency); m_activeProcessors = new ConcurrentDictionary<RequestExecutionContext, Task>(m_maxConcurrency, m_maxConcurrency); m_utcLastUsedAt = DateTime.UtcNow; }
public string ExecuteMSBuild(ITracer tracer, string arguments, params object[] args) { using (var writer = new ProgressWriter()) { writer.Start(); // The line with the MSB3644 warnings since it's not important return _msbuildExe.Execute(tracer, output => { if (output.Contains("MSB3644:") || output.Contains("MSB3270:")) { return false; } writer.WriteOutLine(output); return true; }, error => { writer.WriteErrorLine(error); return true; }, Console.OutputEncoding, arguments, args).Item1; } }
public Solution(ITracer tracer, IVsServiceProvider serviceProvider) { Contract.Requires(tracer != null); Contract.Requires(serviceProvider != null); _deferredUpdateThrottle = new DispatcherThrottle(DispatcherPriority.ContextIdle, Update); _tracer = tracer; _serviceProvider = serviceProvider; _specificProjectConfigurations = Projects.ObservableSelectMany(prj => prj.SpecificProjectConfigurations); _solutionContexts = SolutionConfigurations.ObservableSelectMany(cfg => cfg.Contexts); _defaultProjectConfigurations = Projects.ObservableSelect(prj => prj.DefaultProjectConfiguration); _projectConfigurations = new ObservableCompositeCollection<ProjectConfiguration>(_defaultProjectConfigurations, _specificProjectConfigurations); _solutionEvents = Dte?.Events?.SolutionEvents; if (_solutionEvents != null) { _solutionEvents.Opened += Solution_Changed; _solutionEvents.AfterClosing += Solution_Changed; _solutionEvents.ProjectAdded += _ => Solution_Changed(); _solutionEvents.ProjectRemoved += _ => Solution_Changed(); _solutionEvents.ProjectRenamed += (_, __) => Solution_Changed(); } Update(); }
public void ValidateCommandSettings(ITracer tracer) { this.tracer = tracer; this.ValidateAssociatedArtifactConfiguration(); this.ValidateAuthoringUriIsValidAndTemplateIsConfiguredCorrectly(false); this.ValidateTemplateUriIsNotEmpty(); }
public DropboxHandler(ITracer tracer, IDeploymentStatusManager status, IDeploymentSettingsManager settings, IEnvironment environment) { _dropBoxHelper = new DropboxHelper(tracer, status, settings, environment); }
/// <summary> /// Ctr. /// </summary> /// <param name="process">Parent process, receives crash notifications</param> /// <param name="tracer">Tracer object</param> public RequestExecutionContext(IPqlEngineHostProcess process, ITracer tracer) { if (process == null) { throw new ArgumentNullException("process"); } if (tracer == null) { throw new ArgumentNullException("tracer"); } m_tracer = tracer; m_process = process; ParsedRequest = new ParsedRequest(false); Request = new DataRequest(); RequestBulk = new DataRequestBulk(); RequestParameters = new DataRequestParams(); m_buffersRingItems = new [] { new RequestExecutionBuffer(), new RequestExecutionBuffer(), new RequestExecutionBuffer() }; }
public JArray GetTriggerInputs(ITracer tracer) { JArray inputs = new JArray(); foreach (var functionJson in EnumerateFunctionFiles()) { try { var json = JObject.Parse(FileSystemHelpers.ReadAllText(functionJson)); var binding = json.Value<JObject>("bindings"); foreach (JObject input in binding.Value<JArray>("input")) { var type = input.Value<string>("type"); if (type.EndsWith("Trigger", StringComparison.OrdinalIgnoreCase)) { tracer.Trace(String.Format("Sync {0} of {1}", type, functionJson)); inputs.Add(input); } else { tracer.Trace(String.Format("Skip {0} of {1}", type, functionJson)); } } } catch (Exception ex) { tracer.Trace(String.Format("{0} is invalid. {1}", functionJson, ex.Message)); } } return inputs; }
public SiteExtensionLogManager(ITracer tracer, string directoryPath) { _tracer = tracer; _directoryPath = directoryPath; UpdateCurrentPath(); }
/// <summary> /// Gets the path to the guidance document from the current element. /// </summary> /// <remarks> /// Returns the first artifact link with a *.doc extension of the current element. /// </remarks> public static string GetDocumentPath(ITracer tracer, IProductElement element, IUriReferenceService uriService) { // Return path of first reference var references = SolutionArtifactLinkReference.GetResolvedReferences(element, uriService); if (!references.Any()) { tracer.Warn(String.Format(CultureInfo.CurrentCulture, Resources.GuidanceDocumentPathProvider_NoLinksFound, element.InstanceName)); return string.Empty; } else { var reference = references.FirstOrDefault(r => r.PhysicalPath.EndsWith(GuidanceDocumentExtension)); if (reference == null) { tracer.Warn(String.Format(CultureInfo.CurrentCulture, Resources.GuidanceDocumentPathProvider_NoDocumentLinkFound, element.InstanceName)); return string.Empty; } else { tracer.Info(String.Format(CultureInfo.CurrentCulture, Resources.GuidanceDocumentPathProvider_LinkFound, element.InstanceName, reference.PhysicalPath)); return reference.PhysicalPath; } } }
public DietCalculator(Diet diet, IIngredientQuantityRepository ingredientQuantityRepository, ITracer tracer) { _diet = diet; _ingredientQuantityRepository = ingredientQuantityRepository; _tracer = tracer; tracer.WriteTrace("Henter ut ingredienser og måltid"); var ingredients = _diet.DietIngredients.ToList(); var meals = _diet.DietMeals.ToList(); foreach (var di in ingredients) { var quantityConversion = di.Quantity / QuantityConverter.ConvertTo100Grams(di.QuantityTypeId, _ingredientQuantityRepository.GetConvertFactor(di.IngredientId, di.QuantityTypeId)) * di.Day.ToIntArray().Count(); _totalIngredientCarbsGrams += di.Ingredient.Carb * quantityConversion; _totalIngredientFatGrams += di.Ingredient.Fat * quantityConversion; _totalIngredientProteinGrams += di.Ingredient.Protein * quantityConversion; _totalIngredientKcals += di.Ingredient.Kcal * quantityConversion; } foreach (var dm in meals) { var mealDays = dm.Day.ToIntArray().Count(); var mealCalulator = new MealCalculator(dm.Meal, _ingredientQuantityRepository); _totalMealCarbGrams += mealCalulator.CalculateTotalCarb() * mealDays; _totalMealFatGrams += mealCalulator.CalculateTotalFat() * mealDays; _totalMealProteinGrams += mealCalulator.CalculateTotalProtein() * mealDays; _totalMealKcals += mealCalulator.CalculateTotalKcal() * mealDays; } _totalGrams = _totalIngredientCarbsGrams + _totalIngredientFatGrams + _totalIngredientProteinGrams + _totalMealCarbGrams + _totalMealFatGrams + _totalMealProteinGrams; _tracer.WriteTrace("Ferdig med constructor"); }
public PropertiesView(ITracer tracer) { Contract.Requires(tracer != null); _tracer = tracer; InitializeComponent(); }
public TraceActivity(ITracer tracer, string format, params object[] args) { this.displayName = format; if (args != null && args.Length > 0) this.args = args; this.tracer = tracer; this.newId = Guid.NewGuid(); this.oldId = Trace.CorrelationManager.ActivityId; if (this.oldId != Guid.Empty) tracer.Trace(TraceEventType.Transfer, this.newId); Trace.CorrelationManager.ActivityId = newId; if (this.args == null) { this.tracer.Trace(TraceEventType.Start, this.displayName); //Trace.CorrelationManager.StartLogicalOperation(this.displayName); } else { this.tracer.Trace(TraceEventType.Start, this.displayName, args); //Trace.CorrelationManager.StartLogicalOperation(string.Format(displayName, args)); } }
public UploadPackHandler(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock, IDeploymentManager deploymentManager) : base(tracer, gitServer, deploymentLock, deploymentManager) { }
public async Task HandleAutoSwap(string currentDeploymetId, ILogger logger, ITracer tracer) { if (!IsAutoSwapEnabled()) { tracer.Trace("AutoSwap is not enabled"); return; } string jwtToken = System.Environment.GetEnvironmentVariable(Constants.SiteRestrictedJWT); if (string.IsNullOrWhiteSpace(jwtToken)) { tracer.Trace("Jwt token is null"); return; } try { FileSystemHelpers.WriteAllTextToFile(_autoSwapLockFilePath, String.Empty); } catch (Exception ex) { tracer.TraceError(ex); } string operationId = "AUTOSWAP" + Guid.NewGuid(); var queryStrings = HttpUtility.ParseQueryString(string.Empty); queryStrings["slot"] = _autoSwapSlotName; queryStrings["operationId"] = operationId; var client = new OperationClient(tracer); await client.PostAsync<string>("/operations/autoswap?" + queryStrings.ToString()); logger.Log("Requesting auto swap to slot - '{0}' operation id - '{1}' deployment id - '{2}'".FormatInvariant(_autoSwapSlotName, operationId, currentDeploymetId)); }
public DataContainer(ITracer tracer, DataContainerDescriptor dataContainerDescriptor, string storageRoot) { if (tracer == null) { throw new ArgumentNullException("tracer"); } if (dataContainerDescriptor == null) { throw new ArgumentNullException("dataContainerDescriptor"); } // intentionally allowed to be null - in case if we don't want to use any persistence m_storageRoot = storageRoot; m_tracer = tracer; m_memoryPool = new DynamicMemoryPool(); m_dataContainerDescriptor = dataContainerDescriptor; m_documentDataContainers = new Dictionary<int, DocumentDataContainer>(50); m_documentDataContainerLocks = new Dictionary<int, object>(50); foreach (var item in dataContainerDescriptor.EnumerateDocumentTypes()) { m_documentDataContainerLocks.Add(item.DocumentType, new object()); } }
public IdleManager(TimeSpan idleTimeout, ITracer tracer, Stream output = null) { _idleTimeout = idleTimeout; _tracer = tracer; _output = output; _lastActivity = DateTime.UtcNow; }
public static void AddFile(this ZipArchive zipArchive, FileInfoBase file, ITracer tracer, string directoryNameInArchive) { Stream fileStream = null; try { fileStream = file.OpenRead(); } catch (Exception ex) { // tolerate if file in use. // for simplicity, any exception. tracer.TraceError(String.Format("{0}, {1}", file.FullName, ex)); return; } try { string fileName = ForwardSlashCombine(directoryNameInArchive, file.Name); ZipArchiveEntry entry = zipArchive.CreateEntry(fileName, CompressionLevel.Fastest); entry.LastWriteTime = file.LastWriteTime; using (Stream zipStream = entry.Open()) { fileStream.CopyTo(zipStream); } } finally { fileStream.Dispose(); } }
/// <summary> /// Initializes a new instance of the <see cref="Settings"/> class. /// </summary> /// <param name="manager">The settings manager that will read and save data for this instance.</param> public Settings(ISettingsManager manager) { this.tracer = Tracer.Get(this.GetType()); this.manager = manager; this.manager.Read(this); this.IsInitialized = false; }
public static PushStreamContent Create(string fileName, ITracer tracer, Action<ZipArchive> onZip) { var content = new PushStreamContent((outputStream, httpContent, transportContext) => { using (tracer.Step("ZipStreamContent.OnZip")) { try { using (var zip = new ZipArchive(new StreamWrapper(outputStream), ZipArchiveMode.Create, leaveOpen: false)) { onZip(zip); } } catch (Exception ex) { tracer.TraceError(ex); throw; } } }); content.Headers.ContentType = new MediaTypeHeaderValue("application/zip"); content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); content.Headers.ContentDisposition.FileName = fileName; return content; }
public BuildConfigurationView(ITracer tracer) { Contract.Requires(tracer != null); _tracer = tracer; InitializeComponent(); }
public async Task SyncTriggersAsync(ITracer tracer = null) { tracer = tracer ?? _traceFactory.GetTracer(); using (tracer.Step("FunctionManager.SyncTriggers")) { if (!IsFunctionEnabled) { tracer.Trace("This is not a function-enabled site!"); return; } var jwt = System.Environment.GetEnvironmentVariable(Constants.SiteRestrictedJWT); if (String.IsNullOrEmpty(jwt)) { // If there is no token, do nothing. This can happen on non-dynamic stamps tracer.Trace("Ignoring operation as we don't have a token"); return; } var inputs = await GetTriggerInputsAsync(tracer); if (Environment.IsAzureEnvironment()) { var client = new OperationClient(tracer); await client.PostAsync("/operations/settriggers", inputs); } } }
public OneDriveHandler(ITracer tracer, IDeploymentStatusManager status, IDeploymentSettingsManager settings, IEnvironment environment) { _settings = settings; _oneDriveHelper = new OneDriveHelper(tracer, status, settings, environment); }
public DataServiceErrorHandler(ITracer tracer) { if (tracer == null) { throw new ArgumentNullException("tracer"); } m_tracer = tracer; }
public WebHooksManager(ITracer tracer, IEnvironment environment, IOperationLock hooksLock) { _tracer = tracer; _environment = environment; _hooksLock = hooksLock; _hooksFilePath = Path.Combine(_environment.DeploymentsPath, HooksFileName); }