Esempio n. 1
0
        public override AsimovTask GetDeployTask(AsimovVersion version, ParameterValues parameterValues, AsimovUser user)
        {
            var task = new DeployTask(this, version, parameterValues, user);

            task.AddDeployStep <PowerShellDeployStep>();
            return(task);
        }
Esempio n. 2
0
        public override AsimovTask GetDeployTask(AsimovVersion version, ParameterValues parameterValues, AsimovUser user, string correlationId)
        {
            var task = new DeployTask(this, version, parameterValues, user, correlationId);

            task.AddDeployStep <FileCopyDeployStep>();
            return(task);
        }
        public void AddDeployTaskTest()
        {
            _esSession.Open();
            string     basepackageName = "test1";
            DeployTask deployTask      = new DeployTask();

            deployTask.DeviceDn  = "NE=123;NE=1234;NE=34603357;NE=34603313";
            deployTask.Templates = "template1,poweron1";
            var newSource = new { deployTaskName = basepackageName, deviceDn = deployTask.DeviceDn, templates = deployTask.Templates };
            WebOneESightParam <dynamic> postParam = new WebOneESightParam <dynamic>();

            postParam.ESightIP = "127.0.0.1";
            postParam.Param    = newSource;

            LogUtil.HWLogger.API.Info("AddDeployTaskTest postParam:" + JsonUtil.SerializeObject(postParam));

            string  taskName   = _esSession.DeployWorker.AddDeployTask(basepackageName, deployTask);
            JObject taskObject = new JObject();

            taskObject.Add("taskName", taskName);
            WebReturnResult <JObject> taskResult = new WebReturnResult <JObject>();

            taskResult.Data        = taskObject;
            taskResult.Description = "";
            LogUtil.HWLogger.API.Info("AddDeployTaskTest Result:" + JsonUtil.SerializeObject(taskResult));
        }
Esempio n. 4
0
        public DeployTask GetTaskProgress(string taskId)
        {
            try
            {
                var task = _repository.Tasks.Get(taskId);

                var deployTask = new DeployTask
                {
                    Id            = taskId,
                    CompletedTime =
                        !task.CompletedTime.HasValue
                            ? string.Empty
                            : $"Last Deploy: {task.CompletedTime.Value.ToString("dd MMMM yyyy HH:mm")}",
                    State = task.State.ToString(),
                    FinishedSuccessfully = task.FinishedSuccessfully,
                    HasWarningOrErrors   = task.HasWarningsOrErrors,
                    IsCompleted          = task.IsCompleted
                };

                return(deployTask);
            }
            catch (Exception e)
            {
                _log.Error($"Polling of task failed. TaskId: {taskId}", e);
            }

            return(null);
        }
        /// <summary>
        /// 添加部署任务
        /// </summary>
        /// <param name="taskSourceName">任务名,仅仅用做备注任务</param>
        /// <param name="deployTask">部署任务信息,包括模板类型和设备DN</param>
        /// <returns>返回eSight任务名</returns>
        public string AddDeployTask(string taskSourceName, DeployTask deployTask)
        {
            StringBuilder sb = new StringBuilder(ConstMgr.HWESightHost.URL_TASK_DEPLOY);
            IList <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>("templates", deployTask.Templates));
            parameters.Add(new KeyValuePair <string, object>("dn", deployTask.DeviceDn));

            JObject jResult = ESSession.HCPostForm(sb.ToString(), parameters);

            CheckAndThrowException(jResult);
            HWESightTask eSightTask = new HWESightTask();
            QueryObjectResult <JObject> queryObjectResult = jResult.ToObject <QueryObjectResult <JObject> >();

            eSightTask.HWESightHostID     = this.ESSession.HWESightHost.ID;
            eSightTask.TaskName           = JsonUtil.GetJObjectPropVal <string>(queryObjectResult.Data, "taskName");
            eSightTask.SoftWareSourceName = taskSourceName;
            eSightTask.TaskStatus         = ConstMgr.HWESightTask.TASK_STATUS_RUNNING;//初始化。
            eSightTask.TaskProgress       = 0;
            eSightTask.TaskResult         = "";
            eSightTask.ErrorDetail        = "";
            eSightTask.SyncStatus         = ConstMgr.HWESightTask.SYNC_STATUS_CREATED;
            eSightTask.TaskType           = ConstMgr.HWESightTask.TASK_TYPE_DEPLOY;
            eSightTask.LastModifyTime     = System.DateTime.Now;
            eSightTask.CreateTime         = System.DateTime.Now;
            int taskId = HWESightTaskDal.Instance.InsertEntity(eSightTask);

            eSightTask.ID = taskId;
            InsertHWTaskResourceList(eSightTask, deployTask.DeviceDn);

            LogUtil.HWLogger.API.InfoFormat("AddDeployTask:{0}", taskId);
            return(JsonUtil.GetJObjectPropVal <string>(queryObjectResult.Data, "taskName"));
        }
 public override AsimovTask GetDeployTask(AsimovVersion version, ParameterValues parameterValues, AsimovUser user, string correlationId)
 {
     var task = new DeployTask(this, version, parameterValues, user, correlationId);
     task.AddDeployStep<UpdateWebSite>();
     foreach (var action in Actions.OfType<VerifyCommandUnitAction>())
     {
         task.AddDeployStep(new ExecuteUnitAction(action, user));
     }
     return task;
 }
        public override AsimovTask GetDeployTask(AsimovVersion version, ParameterValues parameterValues, AsimovUser user, string correlationId)
        {
            var task = new DeployTask(this, version, parameterValues, user, correlationId);

            task.AddDeployStep <UpdateWindowsService>();
            foreach (var action in Actions.OfType <CommandUnitAction>())
            {
                task.AddDeployStep(new ExecuteUnitAction(action, user));
            }
            return(task);
        }
        public override AsimovTask GetDeployTask(AsimovVersion version, ParameterValues parameterValues, AsimovUser user)
        {
            var task = new DeployTask(this, version, parameterValues, user);

            task.AddDeployStep <UpdateWebSite>();
            foreach (var action in Actions.OfType <VerifyCommandUnitAction>())
            {
                task.AddDeployStep(new ExecuteUnitAction(action, user));
            }
            return(task);
        }
Esempio n. 9
0
        public async void RunMainTask_NoProvider()
        {
            var config = new Dictionary <string, string>();

            var task = new DeployTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _pluginManager.Object, _logger.Object);

            task.SetConfig(config, "working");
            task.Provider = "NotExistHostingProvider";

            var result = await task.RunMainTask(new Dictionary <string, string>());

            Assert.False(result.IsSuccess);
            Assert.Equal("Deploy provider \"NotExistHostingProvider\" could not be found.", result.ErrorMessage);
        }
Esempio n. 10
0
        public IActionResult EventNotify([FromBody] EventNotifyInput input)
        {
            Request.Headers.TryGetValue("X-Gitlab-Token", out var token);
            Request.Headers.TryGetValue("X-Gitlab-Event", out var @event);
            _logger.LogDebug($"token={token} event={@event}");
            var msg         = "";
            var deployTasks = DeployTask.GetDeployTasks();

            if (deployTasks == null || !deployTasks.Any())
            {
                msg = "没有配置DeployTask";
                _logger.LogDebug(msg);
                return(BadRequest(msg));
            }
            else
            {
                var name = input?.project?.name;
                if (string.IsNullOrEmpty(name))
                {
                    return(BadRequest("参数中缺少工程名称"));
                }
                else
                {
                    var activeDeployTasks =
                        deployTasks
                        .Where(item => item.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
                        .ToList();
                    if (!activeDeployTasks.Any())
                    {
                        msg = $"没有与{name}对应的有效DeployTask";
                        _logger.LogDebug(msg);
                        return(BadRequest(msg));
                    }
                    else
                    {
                        foreach (var deployTask in activeDeployTasks)
                        {
                            Task.Run(() =>
                            {
                                deployTask.Ensure();
                                deployTask.Execute(_logger, input).ConfigureAwait(false);
                            });
                        }
                    }
                }
            }
            return(Ok());
        }
Esempio n. 11
0
        public async void RunMainTask_AdditionalConfigSecured()
        {
            _pluginManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string pluginDll, string pluginArgs, string secretProviderArgs) => new Dictionary <string, object>
            {
                { "hostLocation", "https://test.azurewebsites.net" }
            });
            _pluginManager.Setup(p => p.GetPlugins(It.IsAny <string>())).Returns(new List <PluginItem>
            {
                new PluginItem("FakeHostingProvider", "path/to/FakeHostingProvider.dll", new string[] { "GitHub" })
            });
            _externalServiceService.Setup(p => p.GetExternalServiceByName(It.IsAny <string>())).ReturnsAsync((string name) => new ExternalServiceDto
            {
                Name   = name,
                Config = new Dictionary <string, string>
                {
                    { "AuthToken", "123" }
                }
            });

            var config = new Dictionary <string, string>
            {
                { "GitHubExternalService", "github-test" }
            };

            var task = new DeployTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _pluginManager.Object, _logger.Object);

            task.SetConfig(config, "working");
            task.Provider          = "FakeHostingProvider";
            task.AdditionalConfigs = new Dictionary <string, string>
            {
                { "ConnectionString", "Server=localhost;Database=TestProject;User ID=sa;Password=samprod;" }
            };

            var result = await task.RunMainTask(new Dictionary <string, string>());

            Assert.True(result.IsSuccess);
            Assert.Equal("https://test.azurewebsites.net", result.ReturnValue);
            Assert.Equal("The code has been deployed to https://test.azurewebsites.net", result.TaskRemarks);

            Assert.Equal(2, task.AdditionalConfigs.Count);
            Assert.Equal(2, task.SecuredAdditionalConfigs.Count);
            Assert.Equal("***", task.SecuredAdditionalConfigs["AuthToken"]);
            Assert.Equal("***", task.SecuredAdditionalConfigs["ConnectionString"]);
            Assert.Equal("123", task.AdditionalConfigs["AuthToken"]);
            Assert.Equal("Server=localhost;Database=TestProject;User ID=sa;Password=samprod;", task.AdditionalConfigs["ConnectionString"]);
        }
        /// <summary>
        /// 添加模板任务
        /// </summary>
        private WebReturnResult <JObject> Save(object eventData)
        {
            var ret = new WebReturnResult <JObject>()
            {
                Code = CoreUtil.GetObjTranNull <int>(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR)
            };

            try
            {
                //1. 获取UI传来的参数
                var jsData            = JsonUtil.SerializeObject(eventData);
                var webOneESightParam = JsonUtil.DeserializeObject <WebOneESightParam <ParamOfAddDeployTask> >(jsData);
                LogUtil.HWLogger.UI.InfoFormat("Saving template task..., the param is [{0}]", jsData);
                //2. 根据HostIP获取IESSession
                IESSession esSession = ESSessionHelper.GetESSession(webOneESightParam.ESightIP);
                //3. 保存
                DeployTask deployTask = new DeployTask();
                deployTask.DeviceDn  = webOneESightParam.Param.DeviceDn;
                deployTask.Templates = webOneESightParam.Param.Templates;
                string taskName = esSession.DeployWorker.AddDeployTask(webOneESightParam.Param.TaskSourceName, deployTask);
                //4. 返回数据
                JObject taskObject = new JObject();
                taskObject.Add("taskName", taskName);
                ret.Code        = 0;
                ret.Description = "";
                ret.Data        = taskObject;
                LogUtil.HWLogger.UI.InfoFormat("Saving template task completed! the ret is [{0}]", JsonUtil.SerializeObject(ret));
            }
            catch (BaseException ex)
            {
                LogUtil.HWLogger.UI.Error("Saving template task failed: ", ex);
                ret.Code        = CoreUtil.GetObjTranNull <int>(ex.Code);
                ret.ErrorModel  = ex.ErrorModel;
                ret.Description = ex.Message;
                ret.Data        = null;
            }
            catch (Exception ex)
            {
                LogUtil.HWLogger.UI.Error("Saving template task failed: ", ex);
                ret.Code        = CoreUtil.GetObjTranNull <int>(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR);
                ret.Description = ex.InnerException.Message ?? ex.Message;
                ret.Data        = null;
            }
            return(ret);
        }
Esempio n. 13
0
        public override AsimovTask GetDeployTask(AsimovVersion version, ParameterValues parameterValues, AsimovUser user,
                                                 string correlationId)
        {
            var task = new DeployTask(this, version, parameterValues, user, correlationId);

            if (CanInstall())
            {
                task.AddDeployStep(new InstallWebSite(this));
            }
            else
            {
                task.AddDeployStep <UpdateWebSite>();
            }
            foreach (var action in Actions.OfType <VerifyCommandUnitAction>())
            {
                task.AddDeployStep(new ExecuteUnitAction(action, user));
            }
            return(task);
        }
Esempio n. 14
0
        public async void RunMainTask_Failed()
        {
            _pluginManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string pluginDll, string pluginArgs, string secretProviderArgs) => new Dictionary <string, object>
            {
                { "errorMessage", "error-message" }
            });

            var config = new Dictionary <string, string>();

            var task = new DeployTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _pluginManager.Object, _logger.Object);

            task.SetConfig(config, "working");
            task.Provider = "FakeHostingProvider";

            var result = await task.RunMainTask(new Dictionary <string, string>());

            Assert.False(result.IsSuccess);
            Assert.Equal("error-message", result.ErrorMessage);
        }
Esempio n. 15
0
        public async void RunMainTask_Success()
        {
            _pluginManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string pluginDll, string pluginArgs, string secretProviderArgs) => new Dictionary <string, object>
            {
                { "hostLocation", "https://test.azurewebsites.net" }
            });

            var config = new Dictionary <string, string>();

            var task = new DeployTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _pluginManager.Object, _logger.Object);

            task.SetConfig(config, "working");
            task.Provider = "FakeHostingProvider";

            var result = await task.RunMainTask(new Dictionary <string, string>());

            Assert.True(result.IsSuccess);
            Assert.Equal("https://test.azurewebsites.net", result.ReturnValue);
            Assert.Equal("The code has been deployed to https://test.azurewebsites.net", result.TaskRemarks);
        }
Esempio n. 16
0
 public override AsimovTask GetDeployTask(AsimovVersion version, ParameterValues parameterValues)
 {
     var task = new DeployTask(this, version, parameterValues);
     task.AddDeployStep<FileCopyDeployStep>();
     return task;
 }
 public override AsimovTask GetDeployTask(AsimovVersion version, ParameterValues parameterValues)
 {
     var task = new DeployTask(this, version, parameterValues);
     task.AddDeployStep<UpdateWindowsService>();
     return task;
 }
 public override AsimovTask GetDeployTask(AsimovVersion version, ParameterValues parameterValues, AsimovUser user, string correlationId)
 {
     var task = new DeployTask(this, version, parameterValues, user, correlationId);
     task.AddDeployStep<FileCopyDeployStep>();
     return task;
 }