// try acquire lock and then execute the operation // return true if lock acquired and operation executed public static bool TryLockOperation(this IOperationLock lockObj, Action operation, TimeSpan timeout) { var elapsed = TimeSpan.Zero; while (!lockObj.Lock()) { if (elapsed >= timeout) { return(false); } Thread.Sleep(_sleepInterval); elapsed += _sleepInterval; } try { operation(); return(true); } finally { lockObj.Release(); } }
public static void RemoveAppOfflineIfLeft(IEnvironment environment, IOperationLock deploymentLock, ITracer tracer) { string appOfflineFile = null; try { appOfflineFile = Path.Combine(environment.WebRootPath, Constants.AppOfflineFileName); if (FileSystemHelpers.FileExists(appOfflineFile)) { var appOfflineContent = OperationManager.Attempt(() => FileSystemHelpers.ReadAllText(appOfflineFile)); if (appOfflineContent.Contains(Constants.AppOfflineKuduContent)) { if (deploymentLock != null && deploymentLock.IsHeld) { tracer.Trace($"Deployment lock is held, will not remove {appOfflineFile}"); } else { tracer.Trace($"Removing leftover {appOfflineFile}"); OperationManager.Attempt(() => FileSystemHelpers.DeleteFile(appOfflineFile)); } } } } catch (Exception ex) { tracer.TraceError($"Error removing leftover {appOfflineFile} with {ex}"); } }
public Tracer(IFileSystem fileSystem, string path, TraceLevel level, IOperationLock traceLock) { _fileSystem = fileSystem; _path = path; _level = level; _traceLock = traceLock; }
public DeploymentStatusManager(IEnvironment environment, IOperationLock statusLock) { _environment = environment; _statusLock = statusLock; _activeFile = Path.Combine(environment.DeploymentsPath, Constants.ActiveDeploymentFile); }
public static DeploymentStatusFile Open(string id, IEnvironment environment, IAnalytics analytics, IOperationLock statusLock) { return statusLock.LockOperation(() => { string path = Path.Combine(environment.DeploymentsPath, id, StatusFile); if (!FileSystemHelpers.FileExists(path)) { return null; } try { XDocument document = null; using (var stream = FileSystemHelpers.OpenRead(path)) { document = XDocument.Load(stream); } return new DeploymentStatusFile(id, environment, statusLock, document); } catch (Exception ex) { // in the scenario where w3wp is abruptly terminated while xml is being written, // we may end up with corrupted xml. we will handle the error and remove the problematic directory. analytics.UnexpectedException(ex); FileSystemHelpers.DeleteDirectorySafe(Path.GetDirectoryName(path), ignoreErrors: true); // it is ok to return null as callers already handle null. return null; } }, DeploymentStatusManager.LockTimeout); }
public SettingsController( IDeploymentSettingsManager settingsManager, IDictionary <string, IOperationLock> namedLocks) { _settingsManager = settingsManager; _deploymentLock = namedLocks["deployment"]; }
public FetchHandler(ITracer tracer, IDeploymentManager deploymentManager, IDeploymentSettingsManager settings, IDeploymentStatusManager status, IOperationLock deploymentLock, IEnvironment environment, IEnumerable <IServiceHookHandler> serviceHookHandlers, IRepositoryFactory repositoryFactory, IFileSystem fileSystem) { _tracer = tracer; _deploymentLock = deploymentLock; _deploymentManager = deploymentManager; _settings = settings; _status = status; _serviceHookHandlers = serviceHookHandlers; _repositoryFactory = repositoryFactory; _fileSystem = fileSystem; _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 (!_fileSystem.File.Exists(_markerFilePath)) { try { _fileSystem.File.WriteAllText(_markerFilePath, String.Empty); } catch (Exception ex) { tracer.TraceError(ex); } } }
public SSHKeyController(ITracer tracer, ISSHKeyManager sshKeyManager, IFileSystem fileSystem, IOperationLock sshKeyLock) { _tracer = tracer; _sshKeyManager = sshKeyManager; _fileSystem = fileSystem; _sshKeyLock = sshKeyLock; }
private DeploymentStatusFile(string id, IEnvironment environment, IOperationLock statusLock, XDocument document = null) { _activeFile = Path.Combine(environment.DeploymentsPath, Constants.ActiveDeploymentFile); _statusFile = Path.Combine(environment.DeploymentsPath, id, StatusFile); _statusLock = statusLock; Id = id; SiteName = GetSiteName(environment); HostName = System.Environment.GetEnvironmentVariable("HTTP_HOST"); if (document != null) { Initialize(document); } // Ensure that the status file is created before we enter this code block Task ensureLogFileExists = Task.Run(() => OperationManager.Attempt(() => { if (!FileSystemHelpers.FileExists(_statusFile)) { throw new FileNotFoundException("Status file doesn't exist. Will wait for 1 second and retry"); } }, 2, 250)); }
public GitServerHttpHandler(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock, IDeploymentManager deploymentManager) { _gitServer = gitServer; _tracer = tracer; _deploymentLock = deploymentLock; _deploymentManager = deploymentManager; }
public FetchDeploymentManager( IDeploymentSettingsManager settings, IEnvironment environment, ITracer tracer, IOperationLock deploymentLock, IDeploymentManager deploymentManager, IDeploymentStatusManager status) { _settings = settings; _environment = environment; _tracer = tracer; _deploymentLock = deploymentLock; _deploymentManager = deploymentManager; _status = status; _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 UploadPackHandler(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock, IDeploymentManager deploymentManager) : base(tracer, gitServer, deploymentLock, deploymentManager) { }
public static async Task <bool> TryLockOperationAsync(this IOperationLock lockObj, Func <Task> operation, TimeSpan timeout) { var interval = TimeSpan.FromMilliseconds(250); var elapsed = TimeSpan.Zero; while (!lockObj.Lock()) { if (elapsed >= timeout) { return(false); } await Task.Delay(_sleepInterval); elapsed += _sleepInterval; } try { await operation(); return(true); } finally { lockObj.Release(); } }
public ReceivePackHandler(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock, IDeploymentManager deploymentManager, IDeploymentSettingsManager settings) : base(tracer, gitServer, deploymentLock, deploymentManager, settings) { }
public RpcService(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock) { _gitServer = gitServer; _tracer = tracer; _deploymentLock = deploymentLock; }
public LiveScmEditorController(ITracer tracer, IDeploymentManager deploymentManager, IOperationLock operationLock, IEnvironment environment, IRepository repository) : this(tracer, deploymentManager, operationLock, environment, repository, new FileSystem()) { }
public DeploymentController(ITracer tracer, IDeploymentManager deploymentManager, IOperationLock deploymentLock) { _tracer = tracer; _deploymentManager = deploymentManager; _deploymentLock = deploymentLock; }
public RpcController(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock) { _gitServer = gitServer; _tracer = tracer; _deploymentLock = deploymentLock; }
public ReceivePackService(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock) { _gitServer = gitServer; _tracer = tracer; _deploymentLock = deploymentLock; }
public WebHooksManager(ITracer tracer, IEnvironment environment, IOperationLock hooksLock) { _tracer = tracer; _environment = environment; _hooksLock = hooksLock; _hooksFilePath = Path.Combine(_environment.DeploymentsPath, HooksFileName); }
public DeploymentService(ITracer tracer, IDeploymentManager deploymentManager, IOperationLock deploymentLock) { _tracer = tracer; _deploymentManager = deploymentManager; _deploymentLock = deploymentLock; }
// acquire lock and then execute the operation public static void LockOperation(this IOperationLock lockObj, Action operation, TimeSpan timeout) { bool success = lockObj.TryLockOperation(operation, timeout); if (!success) { throw new InvalidOperationException("Unable to acquire lock within a given time."); } }
// acquire lock and then execute the operation public static void LockOperation(this IOperationLock lockObj, Action operation, TimeSpan timeout) { bool success = lockObj.TryLockOperation(operation, timeout); if (!success) { throw new LockOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_OperationLockTimeout, timeout.TotalSeconds)); } }
public GitExeServer(string path, IOperationLock initLock, ITraceFactory traceFactory) { _gitExe = new GitExecutable(path); _gitExe.SetTraceLevel(2); _traceFactory = traceFactory; _repository = new GitExeRepository(path, traceFactory); _repository.SetTraceLevel(2); _initLock = initLock; }
public ReceivePackHandler(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock, IDeploymentManager deploymentManager, IRepositoryFactory repositoryFactory) : base(tracer, gitServer, deploymentLock, deploymentManager) { _repositoryFactory = repositoryFactory; }
public DeploymentStatusManager(IEnvironment environment, IFileSystem fileSystem, IOperationLock statusLock) { _environment = environment; _fileSystem = fileSystem; _statusLock = statusLock; _activeFile = Path.Combine(environment.DeploymentCachePath, Constants.ActiveDeploymentFile); }
public DeploymentStatusManager(IEnvironment environment, IAnalytics analytics, IOperationLock statusLock) { _environment = environment; _analytics = analytics; _statusLock = statusLock; _activeFile = Path.Combine(environment.DeploymentsPath, Constants.ActiveDeploymentFile); }
public static void LockHttpOperation(this IOperationLock lockObj, Action action) { lockObj.LockOperation(action, () => { var response = new HttpResponseMessage(HttpStatusCode.Conflict); response.Content = new StringContent(Resources.Error_DeploymentInProgess); throw new HttpResponseException(response); }); }
public RpcService(ITracer tracer, IGitServer gitServer, IDeploymentManagerFactory deploymentManagerFactory, IOperationLock deploymentLock) { _gitServer = gitServer; _deploymentManagerFactory = deploymentManagerFactory; _tracer = tracer; _deploymentLock = deploymentLock; }
public DeploymentController(ITracer tracer, IDeploymentManager deploymentManager, IOperationLock deploymentLock, RepositoryFactory repositoryFactory) { _tracer = tracer; _deploymentManager = deploymentManager; _deploymentLock = deploymentLock; _repositoryFactory = repositoryFactory; }
protected GitServerHttpHandler(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock, IDeploymentManager deploymentManager) { GitServer = gitServer; Tracer = tracer; DeploymentLock = deploymentLock; DeploymentManager = deploymentManager; }
public LiveScmEditorController(ITracer tracer, IOperationLock operationLock, IEnvironment environment, IRepository repository) : base(tracer, environment, environment.RepositoryPath) { _operationLock = operationLock; _repository = repository; _currentEtag = GetCurrentEtag(); }
// acquire lock and then execute the operation public static void LockOperation(this IOperationLock lockObj, Action operation, string operationName, TimeSpan timeout) { bool success = lockObj.TryLockOperation(operation, operationName, timeout); if (!success) { var lockInfo = lockObj.LockInfo; throw new LockOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_OperationLockTimeout, operationName, lockInfo.OperationName, lockInfo.AcquiredDateTime)); } }
public static async Task LockHttpOperationAsync(this IOperationLock lockObj, Func <Task> action) { bool acquired = await lockObj.TryLockOperationAsync(action, TimeSpan.Zero); if (!acquired) { var response = new HttpResponseMessage(HttpStatusCode.Conflict); response.Content = new StringContent(Resources.Error_DeploymentInProgess); throw new HttpResponseException(response); } }
public static T LockOperationIfNeccessary <T>(this IOperationLock lockObj, Func <T> operation, string operationName, TimeSpan timeout) { try { return(operation()); } catch (Exception) { return(lockObj.LockOperation(operation, operationName, timeout)); } }
public LiveScmEditorController(ITracer tracer, IDeploymentManager deploymentManager, IOperationLock operationLock, IEnvironment environment, IRepositoryFactory repositoryFactory) : base(tracer, environment, environment.RepositoryPath) { _deploymentManager = deploymentManager; _operationLock = operationLock; _repository = repositoryFactory.GetGitRepository(); }
public LockFile(string path, ITraceFactory traceFactory, bool ensureLock = false) { if (!OSDetector.IsOnWindows()) { _lock = new LinuxLockFile(path, traceFactory, ensureLock); } else { _lock = new WindowsLockFile(path, traceFactory, ensureLock); } }
public LockFile(string path) { if (!OSDetector.IsOnWindows()) { _lock = new LinuxLockFile(path); } else { _lock = new WindowsLockFile(path); } }
public DeploymentController(ITracer tracer, IDeploymentManager deploymentManager, IDeploymentStatusManager status, IOperationLock deploymentLock, IRepositoryFactory repositoryFactory) { _tracer = tracer; _deploymentManager = deploymentManager; _status = status; _deploymentLock = deploymentLock; _repositoryFactory = repositoryFactory; }
public FetchHandler(ITracer tracer, IGitServer gitServer, IDeploymentManager deploymentManager, IOperationLock deploymentLock, RepositoryConfiguration configuration) { _gitServer = gitServer; _deploymentManager = deploymentManager; _tracer = tracer; _deploymentLock = deploymentLock; _configuration = configuration; }
public LiveScmEditorController(ITracer tracer, IDeploymentManager deploymentManager, IOperationLock operationLock, IEnvironment environment, IRepository repository, IFileSystem fileSystem) : base(tracer, environment, fileSystem, environment.RepositoryPath) { _deploymentManager = deploymentManager; _operationLock = operationLock; _repository = repository; }
public LiveScmController(ITracer tracer, IOperationLock deploymentLock, IEnvironment environment, IRepository repository, IServerConfiguration serverConfiguration) { _tracer = tracer; _deploymentLock = deploymentLock; _environment = environment; _repository = repository; _serverConfiguration = serverConfiguration; }
public LiveScmController(ITracer tracer, IOperationLock deploymentLock, IEnvironment environment, IServerRepository repository, IServerConfiguration serverConfiguration) { _tracer = tracer; _deploymentLock = deploymentLock; _environment = environment; _repository = repository; _serverConfiguration = serverConfiguration; }
public GitExeServer(string path, IOperationLock initLock, IDeploymentCommandGenerator deploymentCommandGenerator, ITraceFactory traceFactory) { _gitExe = new GitExecutable(path); _gitExe.SetTraceLevel(2); _traceFactory = traceFactory; _repository = new GitExeRepository(path, traceFactory); _repository.SetTraceLevel(2); _initLock = initLock; _deploymentCommandGenerator = deploymentCommandGenerator; // Setup the deployment environment variable to be used by the post receive hook _gitExe.EnvironmentVariables[_deploymentCommandGenerator.DeploymentEnvironmentVariable] = _deploymentCommandGenerator.GetDeploymentExePath(); }
public GitExeServer(string path, IOperationLock initLock, IDeploymentEnvironment deploymentEnvironment, ITraceFactory traceFactory) { _gitExe = new GitExecutable(path); _traceFactory = traceFactory; _repository = new GitExeRepository(path, traceFactory); _initLock = initLock; // Setup the deployment environment variable to be used by the post receive hook _gitExe.EnvironmentVariables[KnownEnviornment.EXEPATH] = deploymentEnvironment.ExePath; _gitExe.EnvironmentVariables[KnownEnviornment.APPPATH] = deploymentEnvironment.ApplicationPath; _gitExe.EnvironmentVariables[KnownEnviornment.MSBUILD] = deploymentEnvironment.MSBuildExtensionsPath; _gitExe.EnvironmentVariables[KnownEnviornment.DEPLOYER] = ""; }
public FetchHandler(ITracer tracer, IGitServer gitServer, IDeploymentManager deploymentManager, IDeploymentSettingsManager settings, IOperationLock deploymentLock, RepositoryConfiguration configuration, IEnvironment environment) : base(tracer, gitServer, deploymentLock, deploymentManager) { _settings = settings; _configuration = configuration; _environment = environment; }
public static DeploymentStatusFile Create(string id, IFileSystem fileSystem, IEnvironment environment, IOperationLock statusLock) { string path = Path.Combine(environment.DeploymentsPath, id); FileSystemHelpers.EnsureDirectory(fileSystem, path); DateTime utcNow = DateTime.UtcNow; return new DeploymentStatusFile(id, environment, fileSystem, statusLock) { StartTime = utcNow, ReceivedTime = utcNow }; }
private DeploymentStatusFile(string id, IEnvironment environment, IFileSystem fileSystem, IOperationLock statusLock, XDocument document = null) { _activeFile = Path.Combine(environment.DeploymentCachePath, Constants.ActiveDeploymentFile); _statusFile = Path.Combine(environment.DeploymentCachePath, id, StatusFile); _fileSystem = fileSystem; _statusLock = statusLock; Id = id; if (document != null) { Initialize(document); } }
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); } } }