diff --git a/monitor-ui-common/src/main/java/com/ui/contants/HttpUriContants.java b/monitor-ui-common/src/main/java/com/ui/contants/HttpUriContants.java index 4ea946b..e186341 100644 --- a/monitor-ui-common/src/main/java/com/ui/contants/HttpUriContants.java +++ b/monitor-ui-common/src/main/java/com/ui/contants/HttpUriContants.java @@ -79,6 +79,7 @@ public class HttpUriContants { public static final String BATCHIMPORT_ZK_ROOT_CONFIGCENTER = "/configCenter/batchImport"; public static final String ADD_ZK_ROOT = "/configCenter/addZkConfigRoot"; public static final String GET_ZK_LIST = "/configCenter/getZkConfigList"; + public static final String GET_ZK_LIST_EXPORT = "/configCenter/export"; public static final String ADD_ZKCONFIG_MULTI = "/configCenter/addZkCongfigMulti"; /*** diff --git a/monitor-ui-ctrl/src/main/java/com/ui/ctrl/ConfigCenterCtrl.java b/monitor-ui-ctrl/src/main/java/com/ui/ctrl/ConfigCenterCtrl.java index bdf0cab..5b1e5f0 100644 --- a/monitor-ui-ctrl/src/main/java/com/ui/ctrl/ConfigCenterCtrl.java +++ b/monitor-ui-ctrl/src/main/java/com/ui/ctrl/ConfigCenterCtrl.java @@ -5,6 +5,7 @@ import com.ui.http.HttpRestClient; import com.ui.model.BaseResponse; import com.ui.model.req.ZkDetailReq; import com.ui.model.req.ZkTreeReq; +import org.apache.http.HttpResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -14,6 +15,9 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.OutputStream; import java.util.Properties; /** @@ -58,6 +62,37 @@ public class ConfigCenterCtrl { return response; } + @RequestMapping("/export") + @ResponseBody + public void export(ZkDetailReq req, HttpServletResponse response){ + log.info("export with req is {}", req); + req.setExport(true); + Properties res = httpClient.defaultPost(HttpUriContants.GET_ZK_LIST_EXPORT, req, Properties.class); + if (null == res) { + res = new Properties(); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/x-download"); + response.addHeader("Content-Disposition", "attachment;filename=config.properties"); + + OutputStream out = null; + try { + out = response.getOutputStream(); + res.store(out, "export config info from zk!"); + out.flush(); + } catch (IOException e) { + log.error("export with req is {}", req, e); + } finally { + if (out != null) { + try { + out.close(); + } catch (Exception e) { + + } + } + } + } + @RequestMapping("/editDetail") @ResponseBody public BaseResponse editDetail(ZkDetailReq req){ diff --git a/monitor-ui-web/src/main/webapp/jsp/zkConfigCenter/zkConfigCenterList.jsp b/monitor-ui-web/src/main/webapp/jsp/zkConfigCenter/zkConfigCenterList.jsp index 9ceb282..acb4284 100644 --- a/monitor-ui-web/src/main/webapp/jsp/zkConfigCenter/zkConfigCenterList.jsp +++ b/monitor-ui-web/src/main/webapp/jsp/zkConfigCenter/zkConfigCenterList.jsp @@ -104,6 +104,7 @@ </div> <button id="searchConfigInfoBtn" class="btn btn-primary" style="margin-left: 18px;">查询</button> <button id="importConfigInfoBtn" class="btn btn-warning" style="margin-left: 18px;">导入</button> + <button id="exportConfigInfoBtn" class="btn btn-grey" style="margin-left: 18px;">导出</button> <button id="addRootBtn" class="btn btn-success" style="margin-left: 18px;">新增服务</button> <button id="addConfigBtn" class="btn btn-danger" style="margin-left: 18px;">新增配置</button> </div> @@ -116,6 +117,12 @@ </div> </div> </div> +<form id="form_export" name="form_export" method="post" target="hidden_frame"> + <input type="hidden" id="exIp" name="ip"> + <input type="hidden" id="exZkPath" name="zkPath"> + <input type="hidden" id="exConfigName" name="configName"> +</form> +<iframe name='hidden_frame' id="hidden_frame" style="display: none"></iframe> </body> <script src="<%=basePath %>script/common/genarate_left_panel.js"></script> <script> @@ -127,6 +134,7 @@ $(function () { $("#importConfigInfoBtn").bind("click", importFile); + $("#exportConfigInfoBtn").bind("click", doExport); $("#addRootBtn").bind("click", addRoot); $("#addConfigBtn").bind("click", addMObject); //获取环境下拉列表 @@ -183,22 +191,7 @@ }, { title: "环境", width:"8%", - field: "ip", - formatter : function(value, rowData, rowIndex) { - if(value == "all"){ - return "全部"; - } else if(value == "zookeeper_aws"){ - return "aws"; - } else if(value == "zookeeper_qq"){ - return "qCloud"; - } else if(value == "gray_qq"){ - return "gray"; - } else if(value == "dev"){ - return "dev"; - } else { - return "全部"; - } - } + field: "ip" }, { title: "配置值", width:"15%", @@ -587,5 +580,18 @@ 'configName': configName }); }); + //导出 + function doExport() { + var ip = $("#envType").val(); + var zkPath= $("#zkPath").val(); + var configName=$("#configName").val(); + + $("#exIp").val(ip); + $("#exZkPath").val(zkPath); + $("#exConfigName").val(configName); + + $("#form_export").attr("action", contextPath + "configCenter/export"); + $("#form_export").submit(); + } </script> </html> \ No newline at end of file