public DeployModule(ITaskExecutor taskExecutor, IAsimovConfig config) { _taskExecutor = taskExecutor; Post["/deploy/deploy"] = _ => { var command = this.Bind<DeployCommand>(); var deployUnit = config.GetUnitByName(command.unitName); var packageSource = config.GetPackageSourceFor(deployUnit); var version = packageSource.GetVersion(command.versionId, deployUnit.PackageInfo); var deployTask = deployUnit.GetDeployTask(version, new ParameterValues(command.parameters)); _taskExecutor.AddTask(deployTask); return "OK"; }; Post["/deploy/verify"] = _ => { var command = this.Bind<VerifyCommand>(); var deployUnit = config.GetUnitByName(command.unitName); var verifyTask = deployUnit.GetVerifyTask(); _taskExecutor.AddTask(verifyTask); return "OK"; }; }
public DeployLogModule(IAsimovConfig config) { Get["/deploylog/list/{unitName}"] = parameters => { var deployUnit = config.GetUnitByName((string)parameters.unitName); if (deployUnit == null) { return(404); } var deployedVersions = deployUnit.GetDeployedVersions(); int position = 0; var jsonData = deployedVersions.Select(x => new { timestamp = x.DeployTimestamp.ToString("yyyy-MM-dd HH:mm:ss"), version = x.VersionNumber, commit = x.VersionCommit, branch = x.VersionBranch, status = x.DeployFailed == true ? "DeployFailed" : "Success", userId = x.UserId, username = x.UserName, position = position++, }); return(Response.AsJson(jsonData)); }; Get["/deploylog/file/{unitName}/{position}"] = parameters => { var deployUnit = config.GetUnitByName((string)parameters.unitName); if (deployUnit == null) { return(404); } var deployedVersions = deployUnit.GetDeployedVersions(); var specific = deployedVersions.ElementAtOrDefault((int)parameters.position); if (specific == null) { return(404); } var logFile = Path.Combine(deployUnit.DataDirectory, "Logs", specific.LogFileName); using (var fileStream = new StreamReader(logFile, Encoding.UTF8)) { return(new TextResponse(fileStream.ReadToEnd(), "text/plain; charset=utf-8", Encoding.UTF8)); } }; }
public DeployUnitModule(IAsimovConfig config) { Get["/units/list"] = _ => { var units = GetDeployUnits(config); return Response.AsJson(units); }; Get["/units/list/{group}"] = urlArgs => { var units = GetDeployUnits(config, (string)urlArgs.group); return Response.AsJson(units); }; Get["/units/deploy-parameters/{unitName}"] = urlArgs => { var deployUnit = config.GetUnitByName((string)urlArgs.unitName); if (deployUnit == null) return 404; var parameters = deployUnit.DeployParameters.Select(deployParameter => deployParameter.GetDescriptor()).ToList(); return Response.AsJson(parameters); }; }
public UnitActionModule(ITaskExecutor taskExecutor, IAsimovConfig config) { Post["/action"] = _ => { var command = this.Bind <UnitActionCommand>(); var deployUnit = config.GetUnitByName(command.unitName); var action = deployUnit.Actions[command.actionName]; if (action == null) { return(Response.AsJson(new { OK = false, Message = $"No action found with name {command.actionName}.", AvailableActions = deployUnit.Actions.Select(x => x.Name) }, HttpStatusCode.BadRequest)); } var asimovUser = new AsimovUser() { UserId = command.userId, UserName = command.userName }; var task = action.GetTask(deployUnit, asimovUser, command.correlationId); if (task != null) { taskExecutor.AddTask(task); } return(Response.AsJson(new { OK = true })); }; }
public DeployUnitModule(IAsimovConfig config) { Get["/units/list"] = _ => { var units = GetDeployUnits(config); return(Response.AsJson(units)); }; Get["/units/list/{group}"] = urlArgs => { var units = GetDeployUnits(config, (string)urlArgs.group); return(Response.AsJson(units)); }; Get["/units/deploy-parameters/{unitName}"] = urlArgs => { var deployUnit = config.GetUnitByName((string)urlArgs.unitName); if (deployUnit == null) { return(404); } var parameters = deployUnit.DeployParameters.Select(deployParameter => deployParameter.GetDescriptor()).ToList(); return(Response.AsJson(parameters)); }; }
public DeployLogModule(IAsimovConfig config) { Get["/deploylog/list/{unitName}"] = parameters => { var deployUnit = config.GetUnitByName((string)parameters.unitName); if (deployUnit == null) return 404; var deployedVersions = deployUnit.GetDeployedVersions(); int position = 0; var jsonData = deployedVersions.Select(x => new { timestamp = x.DeployTimestamp.ToString("yyyy-MM-dd HH:mm:ss"), version = x.VersionNumber, commit = x.VersionCommit, branch = x.VersionBranch, status = x.DeployFailed == true ? "DeployFailed" : "Success", userId = x.UserId, username = x.UserName, position = position++, }); return Response.AsJson(jsonData); }; Get["/deploylog/file/{unitName}/{position}"] = parameters => { var deployUnit = config.GetUnitByName((string)parameters.unitName); if (deployUnit == null) return 404; var deployedVersions = deployUnit.GetDeployedVersions(); var specific = deployedVersions.ElementAtOrDefault((int)parameters.position); if (specific == null) return 404; var logFile = Path.Combine(deployUnit.DataDirectory, "Logs", specific.LogFileName); using (var fileStream = new StreamReader(logFile, Encoding.UTF8)) { return new TextResponse(fileStream.ReadToEnd(), "text/plain; charset=utf-8", Encoding.UTF8); } }; }
public DeployUnitModule(IAsimovConfig config) { Get["/units/list"] = _ => { var units = new List <DeployUnitInfoDTO>(); foreach (var deployUnit in config.Units) { var unitInfo = deployUnit.GetUnitInfo(); var unitInfoDto = new DeployUnitInfoDTO(); unitInfoDto.name = unitInfo.Name; unitInfoDto.lastDeployed = unitInfo.LastDeployed; if (unitInfo.DeployStatus != DeployStatus.NA) { unitInfoDto.status = unitInfo.DeployStatus.ToString(); unitInfoDto.lastDeployed = ""; } else { unitInfoDto.status = unitInfo.Status.ToString(); } unitInfoDto.url = unitInfo.Url; unitInfoDto.version = unitInfo.Version.VersionNumber; unitInfoDto.branch = unitInfo.Version.VersionBranch; unitInfoDto.hasDeployParameters = unitInfo.HasDeployParameters; unitInfoDto.actions = deployUnit.Actions.OrderBy(x => x.Sort).Select(x => x.Name).ToArray(); units.Add(unitInfoDto); } return(Response.AsJson(units)); }; Get["/units/deploy-parameters/{unitName}"] = urlArgs => { var deployUnit = config.GetUnitByName((string)urlArgs.unitName); if (deployUnit == null) { return(404); } var parameters = new List <dynamic>(); foreach (var deployParameter in deployUnit.DeployParameters) { parameters.Add(deployParameter.GetDescriptor()); } return(Response.AsJson(parameters)); }; }
public DeployModule(ITaskExecutor taskExecutor, IAsimovConfig config) { Post["/deploy/deploy"] = _ => { var command = this.Bind<DeployCommand>(); var deployUnit = config.GetUnitByName(command.unitName); var user = new AsimovUser() { UserId = command.userId, UserName = command.userName }; var packageSource = config.GetPackageSourceFor(deployUnit); var version = packageSource.GetVersion(command.versionId, deployUnit.PackageInfo); var deployTask = deployUnit.GetDeployTask(version, new ParameterValues(command.parameters), user); taskExecutor.AddTask(deployTask); return Response.AsJson(new { OK = true }); }; }
public UnitActionModule(ITaskExecutor taskExecutor, IAsimovConfig config) { Post["/action"] = _ => { var command = this.Bind<UnitActionCommand>(); var deployUnit = config.GetUnitByName(command.unitName); var action = deployUnit.Actions[command.actionName]; var asimovUser = new AsimovUser() {UserId = command.userId, UserName = command.userName}; var task = action.GetTask(deployUnit,asimovUser, command.correlationId); if(task != null) taskExecutor.AddTask(task); return Response.AsJson(new { OK = true }); }; }
public DeployUnitModule(IAsimovConfig config) { Get["/units/list"] = _ => { var units = new List<DeployUnitInfoDTO>(); foreach (var deployUnit in config.Units) { var unitInfo = deployUnit.GetUnitInfo(); var unitInfoDto = new DeployUnitInfoDTO(); unitInfoDto.name = unitInfo.Name; unitInfoDto.info = unitInfo.Info; if (unitInfo.DeployStatus != DeployStatus.NA) { unitInfoDto.status = unitInfo.DeployStatus.ToString(); unitInfoDto.info = ""; } else unitInfoDto.status = unitInfo.Status.ToString(); unitInfoDto.url = unitInfo.Url; unitInfoDto.version = unitInfo.Version.VersionNumber; unitInfoDto.branch = unitInfo.Version.VersionBranch; unitInfoDto.hasDeployParameters = unitInfo.HasDeployParameters; units.Add(unitInfoDto); } return Response.AsJson(units); }; Get["/units/deploy-parameters/{unitName}"] = urlArgs => { var deployUnit = config.GetUnitByName((string)urlArgs.unitName); if (deployUnit == null) return 404; var parameters = new List<dynamic>(); foreach (var deployParameter in deployUnit.DeployParameters) parameters.Add(deployParameter.GetDescriptor()); return Response.AsJson(parameters); }; }
public DeployModule(ITaskExecutor taskExecutor, IAsimovConfig config) { Post["/deploy/deploy"] = _ => { var command = this.Bind <DeployCommand>(); var deployUnit = config.GetUnitByName(command.unitName); var user = new AsimovUser() { UserId = command.userId, UserName = command.userName }; var packageSource = config.GetPackageSourceFor(deployUnit); var version = packageSource.GetVersion(command.versionId, deployUnit.PackageInfo); var deployTask = deployUnit.GetDeployTask(version, new ParameterValues(command.parameters), user); taskExecutor.AddTask(deployTask); return(Response.AsJson(new { OK = true })); }; }
public VersionsModule(IAsimovConfig config) { Get["/versions/{unitName}"] = parameters => { var unitName = (string) parameters.unitName; var deployUnit = config.GetUnitByName(unitName); var versions = config.GetPackageSourceFor(deployUnit) .GetAvailableVersions(deployUnit.PackageInfo) .Select(x => new DeployUnitVersionDTO() { id = x.Id, timestamp = x.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"), version = x.Number, branch = x.Branch, commit = x.Commit }); return Response.AsJson(versions); }; }
public VersionsModule(IAsimovConfig config) { Get["/versions/{unitName}"] = parameters => { var unitName = (string)parameters.unitName; var deployUnit = config.GetUnitByName(unitName); var versions = config.GetPackageSourceFor(deployUnit) .GetAvailableVersions(deployUnit.PackageInfo) .Select(x => new DeployUnitVersionDTO() { id = x.Id, timestamp = x.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"), version = x.Number, branch = x.Branch, commit = x.Commit }); return(Response.AsJson(versions)); }; }
public UnitActionModule(ITaskExecutor taskExecutor, IAsimovConfig config) { Post["/action"] = _ => { var command = this.Bind <UnitActionCommand>(); var deployUnit = config.GetUnitByName(command.unitName); var action = deployUnit.Actions[command.actionName]; var asimovUser = new AsimovUser() { UserId = command.userId, UserName = command.userName }; var task = action.GetTask(deployUnit, asimovUser); if (task != null) { taskExecutor.AddTask(task); } return(Response.AsJson(new { OK = true })); }; }
public DeployUnitModule(IAsimovConfig config) { Get["/units/list"] = _ => { var request = this.Bind <GetDeployUnitsRequestDto>(); var units = GetDeployUnits(config, request); return(Response.AsJson(units)); }; Get["/units/list/{group}"] = urlArgs => { var units = GetDeployUnits(config, new GetDeployUnitsRequestDto { AgentGroups = new[] { (string)urlArgs.group } }); return(Response.AsJson(units)); }; Get["/units/deploy-parameters/{unitName}"] = urlArgs => { var deployUnit = config.GetUnitByName((string)urlArgs.unitName); if (deployUnit == null) { return(404); } var parameters = deployUnit.GetDeployParameters().Select(deployParameter => deployParameter.GetDescriptor()).ToList(); return(Response.AsJson(parameters)); }; Get["/agent-groups"] = _ => Response.AsJson(config.GetAgentGroups()); Get["/unit-groups"] = _ => Response.AsJson(config.GetUnitGroups()); Get["/unit-types"] = _ => Response.AsJson(config.GetUnitTypes()); Get["/unit-tags"] = _ => Response.AsJson(config.GetUnitTags()); Get["/unit-statuses"] = _ => Response.AsJson(config.GetUnitStatuses()); }