protected ServerSessionBase() { SessionId = Guid.NewGuid().ToString("N"); TimeCreated = DateTime.UtcNow; CacheSpan = TimeSpan.FromHours(8); LifeSpan = TimeSpan.FromHours(12); Output = new ScriptOutput(); _log = new Lazy <ILog>(() => LogManager.GetLogger(GetType())); hostList = new ConcurrentDictionary <string, DomainAgentSessionHostBase>(StringComparer.Ordinal); PushedProjectPackageList = new List <PackageReference>(); WorkDirectory = Path.Combine(Configuration.WorkDirectory, SessionId); BinDirectory = Path.Combine(WorkDirectory, "bin"); ContentDirectory = Path.Combine(WorkDirectory, "content"); projectPackages = new ProjectPackageManager { PackageDirectory = Configuration.ProjectPackageDirectory, }; applicationPackages = new ApplicationPackageManager { PackageDirectory = Configuration.ApplicationPackageDirectory, }; ConnectionFactory = new DomainConnectionFactory(); ConnectionFactory.OnConnectionRequest += ConnectionFactory_OnConnectionRequest; PackageClient = new DomainPackageClient(); PackageClient.OnPushProjectPackage += PackageClient_OnPushProjectPackage; PackageClient.OnPushApplicationPackage += PackageClient_OnPushApplicationPackage; PackageClient.OnPullProjectPackage += PackageClient_OnPullProjectPackage; PackageClient.OnPullApplicationPackage += PackageClient_OnPullApplicationPackage; TokenSource = new CancellationTokenSource(); }
public override async Task RunTaskAsync(string taskName, string taskSessionId) { if (taskName == null) { throw new ArgumentNullException(nameof(taskName)); } if (taskSessionId == null) { throw new ArgumentNullException(nameof(taskSessionId)); } var domainOutput = new DomainOutput(); domainOutput.OnWrite += (text, color) => Output.Write(text, color); domainOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color); domainOutput.OnWriteRaw += text => Output.WriteRaw(text); var packageClient = new DomainPackageClient(Packages.Boundary); var applicationClient = new ApplicationManagerClient(Applications.Boundary) { CurrentProjectId = Project.Id, CurrentDeploymentNumber = DeploymentNumber, }; var context = new AgentDeployContext { DeploymentNumber = DeploymentNumber, Project = Project, ProjectPackageId = ProjectPackageId, ProjectPackageVersion = ProjectPackageVersion, AssemblyFilename = AssemblyFilename, TaskName = taskName, WorkDirectory = WorkDirectory, ContentDirectory = ContentDirectory, BinDirectory = BinDirectory, ApplicationsDirectory = ApplicationsDirectory, Output = domainOutput, Packages = packageClient, AgentVariables = AgentVariables, ServerVariables = ServerVariables, Applications = applicationClient, EnvironmentName = EnvironmentName, Agent = Agent, }; try { var task = Task.Run(async() => { await Domain.RunDeployTask(context, TokenSource.Token); }); await taskList.AddOrUpdate(taskSessionId, id => task, (id, _) => task); await task.ContinueWith(t => { taskList.TryRemove(taskSessionId, out _); }); } catch (Exception error) { Exception = error; throw; } }
public override async Task RunTaskAsync(string taskName, string taskSessionId) { using (var contextOutput = new DomainOutput()) { contextOutput.OnWrite += (text, color) => Output.Write(text, color); contextOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color); contextOutput.OnWriteRaw += text => Output.WriteRaw(text); var packageClient = new DomainPackageClient(Packages.Boundary); var applicationClient = new ApplicationManagerClient(Applications.Boundary) { CurrentProjectId = Project.Id, CurrentDeploymentNumber = BuildNumber, // TODO: BuildTask should not have access }; var context = new AgentBuildContext { Project = Project, Agent = Agent, AssemblyFilename = AssemblyFilename, GitRefspec = GitRefspec, TaskName = taskName, WorkDirectory = WorkDirectory, ContentDirectory = ContentDirectory, BinDirectory = BinDirectory, BuildNumber = BuildNumber, Output = contextOutput, Packages = packageClient, ServerVariables = ServerVariables, AgentVariables = AgentVariables, Applications = applicationClient, CommitHash = CommitHash, CommitAuthor = CommitAuthor, CommitMessage = CommitMessage, }; var githubSource = Project?.Source as ProjectGithubSource; var notifyGithub = githubSource != null && githubSource.NotifyOrigin == NotifyOrigin.Agent; if (notifyGithub && SourceCommit != null) { await NotifyGithubStarted(githubSource); } try { var task = Task.Run(async() => { await Domain.RunBuildTask(context, TokenSource.Token); }); await taskList.AddOrUpdate(taskSessionId, id => task, (id, _) => task); await task.ContinueWith(t => { taskList.TryRemove(taskSessionId, out _); }); } catch (Exception error) { Exception = error; throw; } } }
protected AgentSessionBase(MessageTransceiver transceiver, string serverSessionId, string sessionClientId) { this.Transceiver = transceiver; this.ServerSessionId = serverSessionId; this.SessionClientId = sessionClientId; SessionId = Guid.NewGuid().ToString("N"); utcCreated = DateTime.UtcNow; CacheSpan = TimeSpan.FromHours(1); LifeSpan = TimeSpan.FromHours(8); _log = new Lazy <ILog>(() => LogManager.GetLogger(GetType())); Output = new SessionOutput(transceiver, ServerSessionId, SessionClientId); WorkDirectory = Path.Combine(Configuration.WorkDirectory, SessionId); ContentDirectory = Path.Combine(WorkDirectory, "content"); BinDirectory = Path.Combine(WorkDirectory, "bin"); PackageClient = new DomainPackageClient(); PackageClient.OnPushProjectPackage += PackageClient_OnPushProjectPackage; PackageClient.OnPushApplicationPackage += PackageClient_OnPushApplicationPackage; PackageClient.OnPullProjectPackage += PackageClient_OnPullProjectPackage; PackageClient.OnPullApplicationPackage += PackageClient_OnPullApplicationPackage; }
public override async Task RunAsync() { var contextOutput = new DomainOutput(); contextOutput.OnWrite += (text, color) => Output.Write(text, color); contextOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color); contextOutput.OnWriteRaw += text => Output.WriteRaw(text); var packageClient = new DomainPackageClient(Packages.Client); var context = new ServerBuildContext { BuildNumber = Build.Number, Agents = PhotonServer.Instance.Agents.All.ToArray(), Project = Project, AssemblyFilename = AssemblyFilename, PreBuild = PreBuild, TaskName = TaskName, WorkDirectory = WorkDirectory, ContentDirectory = ContentDirectory, BinDirectory = BinDirectory, Packages = packageClient, ConnectionFactory = ConnectionFactory, Output = contextOutput, ServerVariables = Variables, Commit = Commit, }; try { switch (Mode) { case AgentStartModes.All: await RunAll(context); break; case AgentStartModes.Any: await RunAny(context); break; } Build.IsSuccess = true; } catch (OperationCanceledException) { Build.IsCancelled = true; throw; } catch (Exception error) { Build.Exception = error.UnfoldMessages(); throw; } finally { Build.IsComplete = true; Build.Duration = DateTime.UtcNow - Build.Created; Build.ProjectPackages = Packages.PushedProjectPackages.ToArray(); Build.ApplicationPackages = Packages.PushedApplicationPackages.ToArray(); Build.Save(); await Build.SetOutput(Output.GetString()); // TODO: Save alternate version with ansi characters removed } }
public override async Task RunAsync() { var assemblyFilename = Path.Combine(BinDirectory, AssemblyFilename); if (!File.Exists(assemblyFilename)) { throw new FileNotFoundException($"The assembly file '{assemblyFilename}' could not be found!"); } Domain = new ServerDomain(); Domain.Initialize(assemblyFilename); using (var contextOutput = new DomainOutput()) { contextOutput.OnWrite += (text, color) => Output.Write(text, color); contextOutput.OnWriteLine += (text, color) => Output.WriteLine(text, color); contextOutput.OnWriteRaw += (text) => Output.WriteRaw(text); var agents = PhotonServer.Instance.Agents.All.ToArray(); if (!string.IsNullOrEmpty(EnvironmentName)) { var env = Project.Environments .FirstOrDefault(x => string.Equals(x.Name, EnvironmentName)); if (env == null) { throw new ApplicationException($"Environment '{EnvironmentName}' not found!"); } agents = agents.Where(x => env.AgentIdList.Contains(x.Id, StringComparer.OrdinalIgnoreCase)).ToArray(); } var packageClient = new DomainPackageClient(Packages.Client); var context = new ServerDeployContext { DeploymentNumber = Deployment.Number, Project = Project, Agents = agents, ProjectPackageId = ProjectPackageId, ProjectPackageVersion = ProjectPackageVersion, EnvironmentName = EnvironmentName, ScriptName = ScriptName, WorkDirectory = WorkDirectory, BinDirectory = BinDirectory, ContentDirectory = ContentDirectory, Packages = packageClient, ConnectionFactory = ConnectionFactory, Output = contextOutput, ServerVariables = Variables, }; try { await Domain.RunDeployScript(context, TokenSource.Token); Deployment.IsSuccess = true; } catch (OperationCanceledException) { Deployment.IsCancelled = true; throw; } catch (Exception error) { Deployment.Exception = error.UnfoldMessages(); throw; } finally { Deployment.IsComplete = true; Deployment.Duration = DateTime.UtcNow - Deployment.Created; //Deployment.ApplicationPackages = ?; Deployment.Save(); await Deployment.SetOutput(Output.GetString()); // TODO: Save alternate version with ansi characters removed } } }