Example #1
0
        public async Task <JsonResult> GetTemplateList()
        {
            var condition = new TemplateCondition();

            condition.AppId = AppId;
            condition.EnvId = EnvId;
            var list = await _templateService.GetTemplateList(condition);

            var appName = await _appService.GetAppNameById(AppId);

            var envName = await _envService.GetEnvNameById(EnvId);

            foreach (var s in list)
            {
                try
                {
                    var path = DisconfWatcher.GetPath(s.Name, appName, s.Version, envName, s.Type);
                    s.ZookeeperChildren = string.Join("<br>", DisconfWatcher.GetChildren(path));
                }
                catch (Exception ex)
                {
                }
            }
            var vmModel = list.OrderBy(s => s.Version).GroupBy(s => s.Version).Select(t => new TemplateView
            {
                List    = t.ToList(),
                Version = t.FirstOrDefault().Version,
            }).ToList();

            return(Json(vmModel, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public async Task <JsonResult> InitZookeeper(int id, string appName)
        {
            try
            {
                TemplateCondition condition = new TemplateCondition
                {
                    AppId = id
                };
                var temList = await _templateService.GetList(condition);

                if (temList != null && temList.Count() != 0)
                {
                    var configList = await _configService.GetConfigsByTemplateIds(string.Join(",", temList.Select(s => s.Id)));

                    foreach (var item in configList)
                    {
                        var tem     = temList.Where(s => s.Id == item.TemplateId).FirstOrDefault();
                        var envName = await _envService.GetEnvNameById(item.EnvId);

                        var path = DisconfWatcher.GetPath(tem.Name, appName, tem.Version, envName, tem.Type);
                        DisconfWatcher.AddOrSetData(path);
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="templateId"></param>
        /// <param name="value"></param>
        /// <param name="version"></param>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public async Task <JsonResult> UpdateConfig(long?templateId, string value, string version, string name, int type)
        {
            var result = new QueryResult <long>();

            if (!templateId.HasValue)
            {
                result.IsSuccess = false;
                result.ErrorMsg  = "错误,请重新进入编辑页面";
            }
            else
            {
                var log       = new OperationLog();
                var condition = new ConfigCondition
                {
                    EnvId      = EnvId,
                    TemplateId = templateId
                };

                value = value == null ? string.Empty : value.Trim();
                var list = await _configService.GetList(condition);

                if (list != null && list.ToList().Count > 0)
                {
                    var obj = list.FirstOrDefault();
                    obj.Value        = value;
                    log.Content      = "更新配置 请求内容:更新" + obj.Value + "变更为" + value;
                    obj.Mtime        = DateTime.Now;
                    result.IsSuccess = await _configService.Update(obj);

                    DisconfigCache.UpdateCache(AppId + version + EnvId, value, type, name);
                }
                else
                {
                    var obj = new Configs
                    {
                        TemplateId = templateId.Value,
                        EnvId      = EnvId,
                        Value      = value
                    };
                    log.Content      = "启用配置 请求内容:启用;" + value;
                    result.IsSuccess = await _configService.Insert(obj);

                    DisconfigCache.AddCache(AppId + version + EnvId, value, type, name);
                }
                ConfigLog(log);
                result.Data = EnvId;
                var appName = await _appService.GetAppNameById(AppId);

                var envName = await _envService.GetEnvNameById(EnvId);

                var path = DisconfWatcher.GetPath(name, appName, version, envName, type);
                DisconfWatcher.AddOrSetData(path);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }