增加auth文件生成部分代码

This commit is contained in:
Administrator 2015-12-14 14:45:30 +08:00
parent 4c55c61633
commit a856953ec9
6 changed files with 397 additions and 1 deletions

View File

@ -0,0 +1,91 @@
package com.ai.cloud.controller;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ai.cloud.util.Constants;
import com.ai.cloud.util.common.StringUtil;
import com.alibaba.fastjson.JSONObject;
@Controller
public class AuthFileCtl {
private static Logger logger = LogManager.getLogger(AlarmRuleCtl.class);
@RequestMapping("/exportAuth/{appCode}")
public void exportApplicationAuthFile(HttpServletRequest request, HttpServletResponse response,
@PathVariable("appCode") String appCode) throws Exception {
HttpSession session = request.getSession();
String uid = (String) session.getAttribute("uid");
JSONObject reJson = new JSONObject();
if (StringUtil.isBlank(uid)) {
reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
return ;
}
String filepath = "sky-walking.auth";
response.reset();
response.setContentType("application/octet-stream");
String fileName = URLDecoder.decode(filepath, "utf-8");
java.net.URLEncoder.encode(fileName, "utf-8");
response.addHeader("Content-Disposition",
"attachment;" + "filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\"");
StringBuilder sb = new StringBuilder("");
sb.append("测试魂牵梦萦魂牵梦萦" + "\r\n");
BufferedOutputStream output = null;
BufferedInputStream input = null;
OutputStream os = null;
try {
os = response.getOutputStream();
byte[] byt = sb.toString().getBytes();
os.write(byt);
} catch (Exception e) {
logger.error("导出 {} 应用制空权文件异常", appCode);
e.printStackTrace();
} finally {
os.flush();
os.close();
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
}
return;
}
@RequestMapping("/confAuthInfo/{appCode}")
public String confAuthInfo(HttpServletRequest request, HttpServletResponse response,
@PathVariable("appCode") String appCode) throws Exception {
HttpSession session = request.getSession();
String uid = (String) session.getAttribute("uid");
JSONObject reJson = new JSONObject();
if (StringUtil.isBlank(uid)) {
reJson.put(Constants.JSON_RESULT_KEY_RESULT, Constants.JSON_RESULT_KEY_RESULT_FAIL);
reJson.put(Constants.JSON_RESULT_KEY_RESULT_MSG, "用户会话超时");
return reJson.toJSONString();
}
return reJson.toJSONString();
}
}

View File

@ -0,0 +1,88 @@
package com.ai.cloud.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
import com.ai.cloud.dao.inter.IAppAuthInfoMDAO;
import com.ai.cloud.vo.mvo.AppAuthInfoMVO;
@Repository
public class AppAuthInfoMDAO implements IAppAuthInfoMDAO {
@Autowired
private JdbcTemplate jdbcTemplate;
private static Logger logger = LogManager.getLogger(AppAuthInfoMDAO.class);
@Override
public AppAuthInfoMVO queryAppAuthInfo(AppAuthInfoMVO rule) {
final AppAuthInfoMVO ruleMVO = new AppAuthInfoMVO();
String sql = "select info_id,app_id,auth_json,create_time,sts,modify_time from app_auth_info where ";
final Object[] params = new Object[] { rule.getInfoId() };
jdbcTemplate.query(sql, params, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
ruleMVO.setInfoId(rs.getString("info_id"));
ruleMVO.setAppId(rs.getString("app_id"));
ruleMVO.setAuthJson(rs.getString("auth_json"));
ruleMVO.setCreateTime(rs.getTimestamp("create_time"));
ruleMVO.setSts(rs.getString("sts"));
ruleMVO.setModifyTime(rs.getTimestamp("modify_time"));
}
});
logger.info("result : {}", ruleMVO);
return ruleMVO;
}
@Override
public AppAuthInfoMVO createAlarmRule(final AppAuthInfoMVO ruleMVO) {
final String sql = "insert into app_auth_info (app_id,auth_json,create_time,sts,modify_time) values (?,?,sysdate(),?,sysdate())";
KeyHolder keyHolder = new GeneratedKeyHolder();
int count = jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement pstmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
int i = 0;
pstmt.setString(++i, ruleMVO.getAppId());
pstmt.setString(++i, ruleMVO.getAuthJson());
pstmt.setString(++i, ruleMVO.getSts());
return pstmt;
}
}, keyHolder);
logger.info("创建授权文件成功:{}", keyHolder.getKey().intValue());
ruleMVO.setInfoId(keyHolder.getKey().toString());
return ruleMVO;
}
@Override
public AppAuthInfoMVO modifyAlarmRule(final AppAuthInfoMVO ruleMVO) {
final String sql = "update app_auth_info set auth_json = ?,modify_time = sysdate() where info_id = ?";
int count = jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement pstmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
int i = 0;
pstmt.setString(++i, ruleMVO.getAuthJson());
pstmt.setString(++i, ruleMVO.getInfoId());
return pstmt;
}
});
return ruleMVO;
}
}

View File

@ -0,0 +1,13 @@
package com.ai.cloud.dao.inter;
import com.ai.cloud.vo.mvo.AppAuthInfoMVO;
public interface IAppAuthInfoMDAO {
AppAuthInfoMVO queryAppAuthInfo(AppAuthInfoMVO rule);
AppAuthInfoMVO createAlarmRule(AppAuthInfoMVO ruleMVO);
AppAuthInfoMVO modifyAlarmRule(AppAuthInfoMVO ruleMVO);
}

View File

@ -0,0 +1,7 @@
package com.ai.cloud.vo.mvo;
import com.ai.cloud.vo.svo.AppAuthInfoSVO;
public class AppAuthInfoMVO extends AppAuthInfoSVO{
}

View File

@ -0,0 +1,73 @@
package com.ai.cloud.vo.svo;
import java.sql.Timestamp;
public class AppAuthInfoSVO {
private String infoId;
private String appId;
private String authJson;
private Timestamp createTime;
private String sts;
private Timestamp modifyTime;
public String getInfoId() {
return infoId;
}
public void setInfoId(String infoId) {
this.infoId = infoId;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getAuthJson() {
return authJson;
}
public void setAuthJson(String authJson) {
this.authJson = authJson;
}
public Timestamp getCreateTime() {
return createTime;
}
public void setCreateTime(Timestamp createTime) {
this.createTime = createTime;
}
public String getSts() {
return sts;
}
public void setSts(String sts) {
this.sts = sts;
}
public Timestamp getModifyTime() {
return modifyTime;
}
public void setModifyTime(Timestamp modifyTime) {
this.modifyTime = modifyTime;
}
@Override
public String toString() {
return "AppAuthInfo [infoId=" + infoId + ", appId=" + appId + ", authJson=" + authJson + ", createTime="
+ createTime + ", sts=" + sts + ", modifyTime=" + modifyTime + "]";
}
}

View File

@ -91,6 +91,105 @@
</div>
</div>
</div>
<div class="form-horizontal" id="authInfo" style="display:none">
<div class="form-group">
<label for="buriedpoint.printf" class="col-sm-4 control-label">是否打印数据:</label>
<div class="col-sm-4">
<select class="form-control" id="buriedpoint.printf" >
<option value="true">是</option>
<option selected="selected" value="false">否</option>
</select>
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">埋点异常的最大长度(字节)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="buriedpoint.max_exception_stack_length" placeholder="埋点异常的最大长度(字节)" value="4000">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">业务字段的最大长度(字节)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="buriedpoint.max_exception_stack_length" placeholder="业务字段的最大长度" value="300">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">发送的最大长度(字节)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="sender.max_send_length" placeholder="发送的最大长度" value="20000">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">最大发送者的连接数阀比例(百分比)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="sender.max_send_length" placeholder="最大发送者的连接数阀比例" value="100">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">sender的等待周期(秒)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="sender.retry_get_sender_wait_interval" placeholder="当没有Sender时,尝试获取sender的等待周期" value="2000">
</div>
</div>
<div class="form-group">
<label for="sender.is_off" class="col-sm-4 control-label">是否开启发送消息:</label>
<div class="col-sm-4">
<select class="form-control" id="sender.is_off" >
<option value="true">是</option>
<option selected="selected" value="false">否</option>
</select>
</div>
</div>
<div class="form-group">
<label for="mailTemp" class="col-sm-4 control-label">发送服务端配置(,分隔)</label>
<div class="col-sm-4">
<textarea class="form-control" id="sender.servers_addr" rows="4" placeholder="发送服务端配置">127.0.0.1:34000</textarea>
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">最大消费线程数:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="consumer.max_consumer" placeholder="最大消费线程数" value="2">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">消费者最大等待时间(秒)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="consumer.max_wait_time" placeholder="消费者最大等待时间" value="5">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">发送失败等待时间(秒)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="consumer.consumer_fail_retry_wait_interval" placeholder="发送失败等待时间" value="50">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">每个Buffer的最大个数</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="buffer.buffer_max_size" placeholder="每个Buffer的最大个数" value="18000">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">Buffer池的最大长度</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="buffer.pool_size" placeholder="Buffer池的最大长度" value="5">
</div>
</div>
<div class="form-group">
<label for="period" class="col-sm-4 control-label">发送检查线程检查周期(秒)</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="senderchecker.check_polling_time" placeholder="发送检查线程检查周期" value="200">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-4">
<input type='hidden' id="authAppCode">
<button id="export" class="btn btn-lg btn-primary " type="button">生成授权文件</button>
<button id="cannelExport" class="btn btn-lg btn-primary " type="button">取消生成</button>
</div>
</div>
</div>
<table class="table table-condensed">
<caption>
<button id="crtApp" type="button" class="btn btn-warning" href="#">创建应用</button>
@ -114,7 +213,7 @@
<td>${appInfo.appCode!}</td>
<td>
<button name="conf" appId="${appInfo.appId!}" appCode="${appInfo.appCode!}" type="button" class="btn btn-default btn-xs">配置告警规则</button>
<button name="export" appId="${appInfo.appId!}" type="button" class="btn btn-default btn-xs">生成授权</button>
<button name="exportAuthInfo" appId="${appInfo.appId!}" appCode="${appInfo.appCode!}" type="button" class="btn btn-default btn-xs">生成授权</button>
<button name="del" appId="${appInfo.appId!}" type="button" class="btn btn-default btn-xs">删除</button>
</td>
</tr>
@ -123,6 +222,7 @@
</#if>
</table>
</div>
<iframe id="authFiledownLoad" style="width:0px;height:0px;display:none"></iframe>
<!-- script references -->
<@common.importJavaScript />
<script type="text/javascript">
@ -431,6 +531,30 @@
});
}
});
$("button[name='export']").each(function(){
$(this).bind("click",function(){
var downLoadFrame = document.getElementById('authFiledownLoad');
downLoadFrame.src = '${base}/exportAuth/test';
});
});
$("button[name='exportAuthInfo']").each(function(){
$(this).bind("click",function(){
$("#authInfo").show();
$("#authAppCode").val($(this).attr("appCode"));
});
});
$("#export").bind("click",function(){
var downLoadFrame = document.getElementById('authFiledownLoad');
downLoadFrame.src = '${base}/exportAuth/test';
});
$("#cannelExport").bind("click",function(){
$("#authInfo").hide();
});
});
</script>
</body>