diff --git a/src/com/platform/controller/DataModelController.java b/src/com/platform/controller/DataModelController.java index 229401e3..a55ebd5c 100644 --- a/src/com/platform/controller/DataModelController.java +++ b/src/com/platform/controller/DataModelController.java @@ -1,501 +1,501 @@ -package com.platform.controller; - -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - -import com.base.BaseController; -import com.platform.entities.BasedTask; -import com.platform.entities.DataInfoEntity; -import com.platform.entities.DataInfoEntityMoveTmp; -import com.platform.entities.GatherOracleInfo; -import com.platform.entities.OracleConnectorParams; -import com.platform.entities.OracleExtractExecuter; -import com.platform.form.PagerOptions; -import com.platform.form.oracleForm; -import com.platform.form.volumeMoveForm; -import com.platform.service.DataInfoService; -import com.platform.service.ICodeService; -import com.platform.service.IGatherOracleService; -import com.platform.service.ILogRead; -import com.platform.service.IMoveDataService; -import com.platform.service.IOracleExtractService; -import com.platform.service.IVolumeService; -import com.platform.service.OracleExtractTask; -import com.platform.service.OracleStatusService; -import com.platform.utils.CacheSetCantDelete; -import com.platform.utils.Configs; -import com.platform.utils.Constant; -import com.platform.utils.ThreadVolumeImm; -import com.platform.utils.UtilsHelper; - -/** - * 数据管理 - * - * @author chen - * - */ -@Controller -public class DataModelController extends BaseController { - - public static Logger log = Logger.getLogger(DataModelController.class); - - /** - * 数据管理--业务类 - */ - @Resource(name = "dataInfoService") - private DataInfoService dfs; - - /** - * gfs业务类 - */ - @Resource(name = "volumeService") - private IVolumeService volumeService; - - /** - * mysql相关业务 - */ - @Resource(name = "mySqlService") - private IGatherOracleService mySqlService; - - /** - * oracle汇总功能业务 - */ - @Resource(name = "OracleExtract") - private IOracleExtractService OracleExtract; - - /** - * 迁移数据业务类 - */ - @Resource(name = "moveDataService") - private IMoveDataService moveDataService; - - /** - * 地区、系统code业务类 - */ - @Resource(name = "codeService") - private ICodeService codeService; - - /** - * 日志业务管理类 - */ - @Resource(name = "logReadService") - private ILogRead logReadService; - - public void setDfsImp(DataInfoService dfs) { - this.dfs = dfs; - } - - /** - * 数据管理--分页查询数据 - * - * @param res - * @param req - * @return - * @throws Exception - */ - @RequestMapping("/data.json") - @ResponseBody - public ModelMap getAllDataToJson(HttpServletRequest res, - HttpServletResponse req) throws Exception { - log.info("-----------/data.json-----------"); - res.setCharacterEncoding("UTF-8"); - Map paramMap = res.getParameterMap(); - Set keySet = paramMap.keySet(); - Map params = new HashMap(); - StringBuffer sb = new StringBuffer().append("当前的请求参数:{"); - for (String str : keySet) { - String value = paramMap.get(str)[0]; - if (StringUtils.isNotEmpty(value)) { - params.put(str, value); - sb.append(str).append(":").append(value).append(","); - } else { - sb.append(str).append(":").append("null").append(","); - } - } - log.info(sb.deleteCharAt(sb.length() - 1).append("}").toString()); - PagerOptions pagerOptions = (PagerOptions) UtilsHelper - .newObjAndSetAttrsByClass(PagerOptions.class, params); - pagerOptions.setCurrentPageNum(Integer.valueOf(params - .get("currentPageNum"))); - // 冷热区查询字段mark - pagerOptions.setMark(pagerOptions.getVolumeType().trim()); - return dfs.getPagerTableData(pagerOptions); - } - - /** - * 数据管理--删除数据 - * - * @param res - * @param req - * @throws Exception - */ - @RequestMapping(value = "/delete/data") - @ResponseBody - public ModelMap deleteData(HttpServletRequest res, HttpServletResponse req) - throws Exception { - log.info("-----------/delete/data-----------"); - ModelMap mode = new ModelMap(); - res.setCharacterEncoding("UTF-8"); - Map paramMap = res.getParameterMap(); - String[] data = paramMap.get("data"); - if (null != data && data.length > 0) { - List list = new ArrayList(); - List errList = new ArrayList(); - // 判断是否有 不能删除的。 - for (String dataId : data) { - if (CacheSetCantDelete.containsId(dataId)) - errList.add(dataId); - else - list.add(dataId); - } - if (list.size() > 0) { - String[] ids = list.toArray(new String[list.size()]); - dfs.deleteData(ids); - req.setStatus(200); - } - if (errList.size() > 0) { - mode.put("err", errList); - req.setStatus(500); - } - - } - return mode; - } - - /** - * 连接oracle - * - * @param res - * @param req - * @throws UnsupportedEncodingException - */ - @RequestMapping("/connectOracle") - public void connectOracle(HttpServletRequest res, HttpServletResponse req) - throws UnsupportedEncodingException { - res.setCharacterEncoding("UTF-8"); - Map paramMap = res.getParameterMap(); - String[] oraclesName = paramMap.get("oracleName"); - if (oraclesName != null) - for (String rcName : oraclesName) { - log.info("执行连接\t" + rcName); - - String cmd = "kubectl --server " + Configs.KUBE_MASTER_ADDRESS - + " label --overwrite rc " + rcName + " status=0"; - - List rList = Constant.ganymedSSH - .execCmdWaitAcquiescent(cmd); - StringBuffer sb = new StringBuffer(); - for (String string : rList) - sb.append(string).append("\n"); - log.info(sb.toString()); - new OracleStatusService().connectToOracle(rcName); - } - req.setStatus(200); - } - - /** - * 断开oracle连接 - * - * @param res - * @param req - * @throws UnsupportedEncodingException - */ - @RequestMapping("/cancelOracleConection") - public void cancelOracleConnection(HttpServletRequest res, - HttpServletResponse req) throws UnsupportedEncodingException { - res.setCharacterEncoding("UTF-8"); - Map paramMap = res.getParameterMap(); - String[] oraclesName = paramMap.get("oracleName"); - String operate = paramMap.get("operation")[0]; - if (null != oraclesName) { - for (String rcName : oraclesName) { - log.info("取消连接:\t" + rcName); - new OracleStatusService().cancelToOracle(rcName, operate); - } - } - req.setStatus(200); - } - - /** - * gfs的 volume节点的查询 - * - * @return - * @throws Exception - */ - @RequestMapping(value = "/volume/list", method = RequestMethod.POST) - @ResponseBody - public String volumeList() throws Exception { - log.info("-----/volume/list------"); - String rest = volumeService.getAllvolume(); - new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-volumeList") - .start(); - return rest; - } - - /** - * 数据迁移功能 - * - * @param res - * @param req - * @param form - * @throws Exception - */ - @RequestMapping(value = "/volume/{name}/move", method = RequestMethod.POST) - @ResponseBody - public void volumeMove(HttpServletRequest res, HttpServletResponse req, - @RequestBody volumeMoveForm form) throws Exception { - List datas = new ArrayList(); - List selectItems = form.getSelectItems(); - if (null == selectItems) { - req.setStatus(200); - return; - } - datas.addAll(selectItems); - - log.info("------/volume/{name}/move--------"); - if (datas.size() > 0) { - moveDataService.moveData(datas, form.getSelectNode()); - } - req.setStatus(200); - } - - /** - * oracle的 汇总功能 - * - * @param res - * @param req - * @param form - * @throws Exception - */ - @RequestMapping(value = "/oracle/{name}/extract", method = RequestMethod.POST) - public void oracleExtract(HttpServletRequest res, HttpServletResponse req, - @RequestBody oracleForm form) throws Exception { - log.info("/oracle/{name}/extract"); - if (null != form.getTarget()) { // 检查请求参数中是否包含汇总库信息 - boolean isConnect = OracleExtract.isConnectTotalOracle(form - .getTarget()); // 检查汇总库是否可以连接成功,连接成功返回200状态吗,连接失败返回500状态吗 - if (isConnect) { - req.setStatus(200); - if (null != form.getInneed() && form.getInneed().size() > 0) { - for (OracleConnectorParams oracleParams : form.getInneed()) { - BasedTask task = new OracleExtractTask( - oracleParams.getName(), form.getTarget(), - oracleParams, OracleExtract); - OracleExtractExecuter oee = new OracleExtractExecuter( - task); - new Thread(oee, oracleParams.getName()).start(); - } - } - } else - req.setStatus(500); - } - - } - - /** - * oracle汇总、抽取库的 查询 - * - * @return - * @throws Exception - */ - @RequestMapping(value = "/oracle/list", method = RequestMethod.POST) - @ResponseBody - public List oracleList() throws Exception { - log.info("----------getOracleInfo-----------------------"); - List result = mySqlService.findAllOracle(); - return result; - } - - /** - * oracle汇总、抽取库的 删除 - * - * @param req - * @param res - * @param id - * @throws Exception - */ - @RequestMapping(value = "/oracle/{id}/delete", method = RequestMethod.POST) - public void oracleDelete(HttpServletRequest req, HttpServletResponse res, - @PathVariable String id) throws Exception { - log.info("----------deleteOracleInfo----------------"); - Integer num = Integer.valueOf(id); - Integer result = mySqlService.deleteOracle(num); - log.info("oracleDelete : " + result); - res.setStatus(200); - } - - /** - * oracle汇总、抽取库的 新增 - * - * @param res - * @param req - * @param id - * @param oracle - * @throws Exception - */ - @RequestMapping(value = "/oracle/{id}/insert", method = RequestMethod.POST) - @ResponseBody - public void oracleInsert(HttpServletRequest res, HttpServletResponse req, - @PathVariable String id, @RequestBody GatherOracleInfo oracle) - throws Exception { - log.info("----------insertOracleInfo----------------"); - oracle.setId(Integer.valueOf(id)); - mySqlService.insertOracle(oracle); - req.setStatus(200); - } - - /** - * oracle汇总、抽取库的 更新 - * - * @param res - * @param req - * @param id - * @param oracle - * @throws Exception - */ - @RequestMapping(value = "/oracle/{id}/update", method = RequestMethod.POST) - @ResponseBody - public void oracleUpdate(HttpServletRequest res, HttpServletResponse req, - @PathVariable("id") String id, @RequestBody GatherOracleInfo oracle) - throws Exception { - log.info("----------updateOracleInfo-----------------------"); - log.info(oracle); - mySqlService.updateOracle(oracle); - req.setStatus(200); - } - - /** - * 迁移任务 的查询 - * - * @return - * @throws Exception - */ - @RequestMapping(value = "/task/transfer/list", method = RequestMethod.POST) - @ResponseBody - public Object taskTransferList() throws Exception { - log.debug("----------/task/transfer/list-----------------------"); - List result = moveDataService.findAll(); - return result; - } - - /** - * 迁移完成后的 删除记录功能 - * - * @param res - * @param req - * @param id - * @return - * @throws Exception - */ - @RequestMapping(value = "/task/transfer/{id}/delete", method = RequestMethod.POST) - @ResponseBody - public Object taskTransferDelete(HttpServletRequest res, - HttpServletResponse req, @PathVariable String id) throws Exception { - log.info("----------/task/transfer/{id}/delete-----------------------"); - DataInfoEntityMoveTmp move = new DataInfoEntityMoveTmp(); - move.setId(Integer.valueOf(id)); - int result = moveDataService.delete(move); - req.setStatus(200); - return result; - } - - /** - * 迁移完成后的 删除记录功能 - * - * @param res - * @param req - * @param id - * @return - * @throws Exception - */ - @RequestMapping(value = "/task/transfer/deletes", method = RequestMethod.POST) - @ResponseBody - public Object taskTransferDeletes(HttpServletRequest res, - HttpServletResponse req, @RequestBody String[] ids) throws Exception { - log.info("---------/task/transfer/deletes----------------------"); - req.setStatus(200); - int result = 0; - if (ids != null ) { -// String[] ids = idsString.split(","); - result = moveDataService.delete(ids); - } - else { - req.setStatus(500); - } - return result; - } - - /** - * 迁移数据完成后新增一条数据(暂时去掉,新增功能不在此) - * - * @param res - * @param req - * @param move - * @return - * @throws Exception - */ - @RequestMapping(value = "/task/transfer/save", method = RequestMethod.POST) - @ResponseBody - public Object taskTransferSave(HttpServletRequest res, - HttpServletResponse req, @RequestBody DataInfoEntity move) - throws Exception { - log.info("---------/task/transfer/save-----------------------"); - // int result = dfs.save(move); - req.setStatus(200); - return 1; - } - - /** - * 地区和系统的 code 对应的名称 的 获取 - * - * @return - * @throws Exception - */ - @RequestMapping(value = "/code/list", method = RequestMethod.POST) - @ResponseBody - public Object findCodeList() throws Exception { - log.info("---------/findSystemCode-----------------------"); - Map result = codeService.findAll(); - return result; - } - - /** - * oracle 汇总的 日志 读取 - * - * @param name - * @param res - * @param req - * @return - * @throws Exception - */ - @RequestMapping(value = "/oracle/extract/log", method = RequestMethod.POST) - @ResponseBody - public Object getExtractLog(@RequestParam("rcName") String name, - HttpServletRequest res, HttpServletResponse req) throws Exception { - log.info("---------/oracle/extract/log-------------------"); - String result = logReadService.readLog(name); - // "查看相应日志" - Map log = new HashMap(); - log.put(name, result + "\r\n"); - return log; - } -} +package com.platform.controller; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.base.BaseController; +import com.platform.entities.BasedTask; +import com.platform.entities.DataInfoEntity; +import com.platform.entities.DataInfoEntityMoveTmp; +import com.platform.entities.GatherOracleInfo; +import com.platform.entities.OracleConnectorParams; +import com.platform.entities.OracleExtractExecuter; +import com.platform.form.PagerOptions; +import com.platform.form.oracleForm; +import com.platform.form.volumeMoveForm; +import com.platform.service.DataInfoService; +import com.platform.service.ICodeService; +import com.platform.service.IGatherOracleService; +import com.platform.service.ILogRead; +import com.platform.service.IMoveDataService; +import com.platform.service.IOracleExtractService; +import com.platform.service.IVolumeService; +import com.platform.service.OracleExtractTask; +import com.platform.service.OracleStatusService; +import com.platform.utils.CacheSetCantDelete; +import com.platform.utils.Configs; +import com.platform.utils.Constant; +import com.platform.utils.ThreadVolumeImm; +import com.platform.utils.UtilsHelper; + +/** + * 数据管理 + * + * @author chen + * + */ +@Controller +public class DataModelController extends BaseController { + + public static Logger log = Logger.getLogger(DataModelController.class); + + /** + * 数据管理--业务类 + */ + @Resource(name = "dataInfoService") + private DataInfoService dfs; + + /** + * gfs业务类 + */ + @Resource(name = "volumeService") + private IVolumeService volumeService; + + /** + * mysql相关业务 + */ + @Resource(name = "mySqlService") + private IGatherOracleService mySqlService; + + /** + * oracle汇总功能业务 + */ + @Resource(name = "OracleExtract") + private IOracleExtractService OracleExtract; + + /** + * 迁移数据业务类 + */ + @Resource(name = "moveDataService") + private IMoveDataService moveDataService; + + /** + * 地区、系统code业务类 + */ + @Resource(name = "codeService") + private ICodeService codeService; + + /** + * 日志业务管理类 + */ + @Resource(name = "logReadService") + private ILogRead logReadService; + + public void setDfsImp(DataInfoService dfs) { + this.dfs = dfs; + } + + /** + * 数据管理--分页查询数据 + * + * @param res + * @param req + * @return + * @throws Exception + */ + @RequestMapping("/data.json") + @ResponseBody + public ModelMap getAllDataToJson(HttpServletRequest res, + HttpServletResponse req) throws Exception { + log.info("-----------/data.json-----------"); + res.setCharacterEncoding("UTF-8"); + Map paramMap = res.getParameterMap(); + Set keySet = paramMap.keySet(); + Map params = new HashMap(); + StringBuffer sb = new StringBuffer().append("当前的请求参数:{"); + for (String str : keySet) { + String value = paramMap.get(str)[0]; + if (StringUtils.isNotEmpty(value)) { + params.put(str, value); + sb.append(str).append(":").append(value).append(","); + } else { + sb.append(str).append(":").append("null").append(","); + } + } + log.info(sb.deleteCharAt(sb.length() - 1).append("}").toString()); + PagerOptions pagerOptions = (PagerOptions) UtilsHelper + .newObjAndSetAttrsByClass(PagerOptions.class, params); + pagerOptions.setCurrentPageNum(Integer.valueOf(params + .get("currentPageNum"))); + // 冷热区查询字段mark + pagerOptions.setMark(pagerOptions.getVolumeType().trim()); + return dfs.getPagerTableData(pagerOptions); + } + + /** + * 数据管理--删除数据 + * + * @param res + * @param req + * @throws Exception + */ + @RequestMapping(value = "/delete/data") + @ResponseBody + public ModelMap deleteData(HttpServletRequest res, HttpServletResponse req) + throws Exception { + log.info("-----------/delete/data-----------"); + ModelMap mode = new ModelMap(); + res.setCharacterEncoding("UTF-8"); + Map paramMap = res.getParameterMap(); + String[] data = paramMap.get("data"); + if (null != data && data.length > 0) { + List list = new ArrayList(); + List errList = new ArrayList(); + // 判断是否有 不能删除的。 + for (String dataId : data) { + if (CacheSetCantDelete.containsId(dataId)) + errList.add(dataId); + else + list.add(dataId); + } + if (list.size() > 0) { + String[] ids = list.toArray(new String[list.size()]); + dfs.deleteData(ids); + req.setStatus(200); + } + if (errList.size() > 0) { + mode.put("err", errList); + req.setStatus(500); + } + + } + return mode; + } + + /** + * 连接oracle + * + * @param res + * @param req + * @throws UnsupportedEncodingException + */ + @RequestMapping("/connectOracle") + public void connectOracle(HttpServletRequest res, HttpServletResponse req) + throws UnsupportedEncodingException { + res.setCharacterEncoding("UTF-8"); + Map paramMap = res.getParameterMap(); + String[] oraclesName = paramMap.get("oracleName"); + if (oraclesName != null) + for (String rcName : oraclesName) { + log.info("执行连接\t" + rcName); + + String cmd = "kubectl --server " + Configs.KUBE_MASTER_ADDRESS + + " label --overwrite rc " + rcName + " status=0"; + + List rList = Constant.ganymedSSH + .execCmdWaitAcquiescent(cmd); + StringBuffer sb = new StringBuffer(); + for (String string : rList) + sb.append(string).append("\n"); + log.info(sb.toString()); + new OracleStatusService().connectToOracle(rcName); + } + req.setStatus(200); + } + + /** + * 断开oracle连接 + * + * @param res + * @param req + * @throws UnsupportedEncodingException + */ + @RequestMapping("/cancelOracleConection") + public void cancelOracleConnection(HttpServletRequest res, + HttpServletResponse req) throws UnsupportedEncodingException { + res.setCharacterEncoding("UTF-8"); + Map paramMap = res.getParameterMap(); + String[] oraclesName = paramMap.get("oracleName"); + String operate = paramMap.get("operation")[0]; + if (null != oraclesName) { + for (String rcName : oraclesName) { + log.info("取消连接:\t" + rcName); + new OracleStatusService().cancelToOracle(rcName, operate); + } + } + req.setStatus(200); + } + + /** + * gfs的 volume节点的查询 + * + * @return + * @throws Exception + */ + @RequestMapping(value = "/volume/list", method = RequestMethod.POST) + @ResponseBody + public String volumeList() throws Exception { + log.info("-----/volume/list------"); + String rest = volumeService.getAllvolume(); + new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-volumeList") + .start(); + return rest; + } + + /** + * 数据迁移功能 + * + * @param res + * @param req + * @param form + * @throws Exception + */ + @RequestMapping(value = "/volume/{name}/move", method = RequestMethod.POST) + @ResponseBody + public void volumeMove(HttpServletRequest res, HttpServletResponse req, + @RequestBody volumeMoveForm form) throws Exception { + List datas = new ArrayList(); + List selectItems = form.getSelectItems(); + if (null == selectItems) { + req.setStatus(200); + return; + } + datas.addAll(selectItems); + + log.info("------/volume/{name}/move--------"); + if (datas.size() > 0) { + moveDataService.moveData(datas, form.getSelectNode()); + } + req.setStatus(200); + } + + /** + * oracle的 汇总功能 + * + * @param res + * @param req + * @param form + * @throws Exception + */ + @RequestMapping(value = "/oracle/{name}/extract", method = RequestMethod.POST) + public void oracleExtract(HttpServletRequest res, HttpServletResponse req, + @RequestBody oracleForm form) throws Exception { + log.info("/oracle/{name}/extract"); + if (null != form.getTarget()) { // 检查请求参数中是否包含汇总库信息 + boolean isConnect = OracleExtract.isConnectTotalOracle(form + .getTarget()); // 检查汇总库是否可以连接成功,连接成功返回200状态吗,连接失败返回500状态吗 + if (isConnect) { + req.setStatus(200); + if (null != form.getInneed() && form.getInneed().size() > 0) { + for (OracleConnectorParams oracleParams : form.getInneed()) { + BasedTask task = new OracleExtractTask( + oracleParams.getName(), form.getTarget(), + oracleParams, OracleExtract); + OracleExtractExecuter oee = new OracleExtractExecuter( + task); + new Thread(oee, oracleParams.getName()).start(); + } + } + } else + req.setStatus(500); + } + + } + + /** + * oracle汇总、抽取库的 查询 + * + * @return + * @throws Exception + */ + @RequestMapping(value = "/oracle/list", method = RequestMethod.POST) + @ResponseBody + public List oracleList() throws Exception { + log.info("----------getOracleInfo-----------------------"); + List result = mySqlService.findAllOracle(); + return result; + } + + /** + * oracle汇总、抽取库的 删除 + * + * @param req + * @param res + * @param id + * @throws Exception + */ + @RequestMapping(value = "/oracle/{id}/delete", method = RequestMethod.POST) + public void oracleDelete(HttpServletRequest req, HttpServletResponse res, + @PathVariable String id) throws Exception { + log.info("----------deleteOracleInfo----------------"); + Integer num = Integer.valueOf(id); + Integer result = mySqlService.deleteOracle(num); + log.info("oracleDelete : " + result); + res.setStatus(200); + } + + /** + * oracle汇总、抽取库的 新增 + * + * @param res + * @param req + * @param id + * @param oracle + * @throws Exception + */ + @RequestMapping(value = "/oracle/{id}/insert", method = RequestMethod.POST) + @ResponseBody + public void oracleInsert(HttpServletRequest res, HttpServletResponse req, + @PathVariable String id, @RequestBody GatherOracleInfo oracle) + throws Exception { + log.info("----------insertOracleInfo----------------"); + oracle.setId(Integer.valueOf(id)); + mySqlService.insertOracle(oracle); + req.setStatus(200); + } + + /** + * oracle汇总、抽取库的 更新 + * + * @param res + * @param req + * @param id + * @param oracle + * @throws Exception + */ + @RequestMapping(value = "/oracle/{id}/update", method = RequestMethod.POST) + @ResponseBody + public void oracleUpdate(HttpServletRequest res, HttpServletResponse req, + @PathVariable("id") String id, @RequestBody GatherOracleInfo oracle) + throws Exception { + log.info("----------updateOracleInfo-----------------------"); + log.info(oracle); + mySqlService.updateOracle(oracle); + req.setStatus(200); + } + + /** + * 迁移任务 的查询 + * + * @return + * @throws Exception + */ + @RequestMapping(value = "/task/transfer/list", method = RequestMethod.POST) + @ResponseBody + public Object taskTransferList() throws Exception { + log.debug("----------/task/transfer/list-----------------------"); + List result = moveDataService.findAll(); + return result; + } + + /** + * 迁移完成后的 删除记录功能 + * + * @param res + * @param req + * @param id + * @return + * @throws Exception + */ + @RequestMapping(value = "/task/transfer/{id}/delete", method = RequestMethod.POST) + @ResponseBody + public Object taskTransferDelete(HttpServletRequest res, + HttpServletResponse req, @PathVariable String id) throws Exception { + log.info("----------/task/transfer/{id}/delete-----------------------"); + DataInfoEntityMoveTmp move = new DataInfoEntityMoveTmp(); + move.setId(Integer.valueOf(id)); + int result = moveDataService.delete(move); + req.setStatus(200); + return result; + } + + /** + * 迁移完成后的 删除记录功能 + * + * @param res + * @param req + * @param id + * @return + * @throws Exception + */ + @RequestMapping(value = "/task/transfer/deletes", method = RequestMethod.POST) + @ResponseBody + public Object taskTransferDeletes(HttpServletRequest res, + HttpServletResponse req, @RequestBody String[] ids) throws Exception { + log.info("---------/task/transfer/deletes----------------------"); + req.setStatus(200); + int result = 0; + if (ids != null ) { +// String[] ids = idsString.split(","); + result = moveDataService.delete(ids); + } + else { + req.setStatus(500); + } + return result; + } + + /** + * 迁移数据完成后新增一条数据(暂时去掉,新增功能不在此) + * + * @param res + * @param req + * @param move + * @return + * @throws Exception + */ + @RequestMapping(value = "/task/transfer/save", method = RequestMethod.POST) + @ResponseBody + public Object taskTransferSave(HttpServletRequest res, + HttpServletResponse req, @RequestBody DataInfoEntity move) + throws Exception { + log.info("---------/task/transfer/save-----------------------"); + // int result = dfs.save(move); + req.setStatus(200); + return 1; + } + + /** + * 地区和系统的 code 对应的名称 的 获取 + * + * @return + * @throws Exception + */ + @RequestMapping(value = "/code/list", method = RequestMethod.POST) + @ResponseBody + public Object findCodeList() throws Exception { + log.info("---------/findSystemCode-----------------------"); + Map result = codeService.findAll(); + return result; + } + + /** + * oracle 汇总的 日志 读取 + * + * @param name + * @param res + * @param req + * @return + * @throws Exception + */ + @RequestMapping(value = "/oracle/extract/log", method = RequestMethod.POST) + @ResponseBody + public Object getExtractLog(@RequestParam("rcName") String name, + HttpServletRequest res, HttpServletResponse req) throws Exception { + log.info("---------/oracle/extract/log-------------------"); + String result = logReadService.readLog(name); + // "查看相应日志" + Map log = new HashMap(); + log.put(name, result + "\r\n"); + return log; + } +} diff --git a/src/com/platform/oracle/OracleConnector.java b/src/com/platform/oracle/OracleConnector.java index 61270ee0..bd7b2e7b 100644 --- a/src/com/platform/oracle/OracleConnector.java +++ b/src/com/platform/oracle/OracleConnector.java @@ -152,13 +152,21 @@ public class OracleConnector { flag = true; FileOperateHelper.fileWrite(filePath + ".log", "执行结果:" + res + " \r\n"); - statement.close(); } catch (SQLException e) { flag = false; FileOperateHelper.fileWrite(filePath + ".log", e.getMessage() + "\r\n"); log.error(Custom4exception.OracleSQL_Except, e); } + finally { + if (null != statement) { + try { + statement.close(); + } catch (SQLException e) { + log.error(Custom4exception.OracleSQL_Except, e); + } + } + } return flag ; } @@ -184,7 +192,7 @@ public class OracleConnector { flag = true; FileOperateHelper.fileWrite(filePath + ".log", "执行结果:"+ res + " \r\n"); - statement.close(); + if (res < 1) { flag = false; } @@ -194,7 +202,17 @@ public class OracleConnector { FileOperateHelper.fileWrite(filePath + ".log", e.getMessage() + "\r\n"); log.error(Custom4exception.OracleSQL_Except, e); - } + } + finally{ + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } return flag; } } \ No newline at end of file diff --git a/src/com/platform/service/OracleExtractHelper.java b/src/com/platform/service/OracleExtractHelper.java index e0bc4727..f7430a17 100644 --- a/src/com/platform/service/OracleExtractHelper.java +++ b/src/com/platform/service/OracleExtractHelper.java @@ -46,7 +46,6 @@ public class OracleExtractHelper { } FileOperateHelper.fileWrite(filePath + ".log", sql + "\r\n" + "OK \r\n"); - statement.close(); } catch (Exception e) { FileOperateHelper.fileWrite(filePath, sql + "\r\n" + e.getMessage() @@ -288,10 +287,18 @@ public class OracleExtractHelper { log.error(Custom4exception.threadVolume_Oracle_Except, e); } } - statement.close(); } catch (SQLException e) { log.error(Custom4exception.threadVolume_Oracle_Except, e); } + finally { + if (null != statement) { + try { + statement.close(); + } catch (SQLException e) { + log.error(Custom4exception.OracleSQL_Except, e); + } + } + } } @@ -303,15 +310,24 @@ public class OracleExtractHelper { public boolean testConnect(Connection conn) { String testSql = "select count(*) from user_tables"; boolean flag = false; + Statement statement = null; try { - Statement statement = conn.createStatement(); + statement = conn.createStatement(); if (statement.executeUpdate(testSql) > 0) flag = true; - statement.close(); } catch (SQLException e) { flag = false; log.error(Custom4exception.threadVolume_Oracle_Except, e); } + finally { + if (null != statement) { + try { + statement.close(); + } catch (SQLException e) { + log.error(Custom4exception.OracleSQL_Except, e); + } + } + } return flag; } diff --git a/src/com/platform/utils/Configs.java b/src/com/platform/utils/Configs.java index 9f789c00..878fc577 100644 --- a/src/com/platform/utils/Configs.java +++ b/src/com/platform/utils/Configs.java @@ -1,130 +1,130 @@ -package com.platform.utils; - -import org.apache.log4j.Logger; - -/** 配置启动 变量 - * @author chen - * - */ -public class Configs { - - /** 全局自定义异常--编码 */ - public static final String GLOBAL_EXP_CUSTOM = "3001001001"; - - /** 全局非自定义异常--编码 */ - public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002"; - - public static final String CONFIG_LOCALTION = "WebContent/WEB-INF/config/config.properties"; - - public static final Logger CONSOLE_LOGGER = Logger.getLogger("console"); - - public static final Logger DAILY_ROLLING_LOGGER = Logger - .getLogger("dailyRollingFile"); - - public static final Logger DAILY_LOGGER = Logger.getLogger("railyFile"); - - public static final Logger LOGGER = Logger.getLogger(Configs.class); - - public static String KUBE_MASTER_URL = "http://192.168.0.110:8080/"; // kubernetes集群的maser - // URl - - public static String KUBE_MASTER_ADDRESS="127.0.0.1:8080"; - - - public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号 - - public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名 - - public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码 - - public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名 - - public static String GATHER_PORT ="1521"; //汇总库的端口号 - - public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名 - - public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码 - - /** 抽取标准表 的 标准表所在 用户 */ - public static String GATHER_STANDARD_USER_NAME = "u_bzbjy"; - - /** 可执行表名 */ - public static String GATHER_STANDARD_EXEC_TABLE_NAME = "kzxzb"; - - /** 可支付表名 */ - public static String GATHER_STANDARD_PAY_TABLE_NAME = "zfxxb"; - - public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名 - - public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名 - - public static String EXTRACT_LOG_LOCALTION = "D:\\log"; //数据汇总日志保存位置 - - public static String EXTRACT_STANDARD_LOG_LOCALTION = "D:\\log2"; //数据抽取日志保存位置 - - public static String GATHER_TABLESPACE_NAME=""; //表空间名 - - public static String GATHER_TABLESPACE_PATH=""; //表空间路径 - - public static String GATHER_TABLE_PASSWORD="1"; //登入密码 - - /** excel上传路径 */ - public static String FILE_UPLOAD_PATH=""; - - /** excel下载路经 */ - public static String FILE_DOWNLOAD_PATH=""; - - /** 包下载路径 */ - public static String PACKAGE_DOWNLOAD_PATH=""; - - /** 下载包名 */ - public static String PACKAGE_NAME=""; - - /** - * 最新脚本的位置 - */ - public static String SQL_SCRIPT_PATH_LAST="D:\\test\\sql_script_last\\"; - /** 归档脚本的位置 */ - public static String SQL_SCRIPT_PATH_STANDARD="D:\\test\\sql_script_standard\\"; - - /** - * 多少 个月前的数据 - */ - public static int dataBefore = 6; - - /** - * excel导入一次批量导入5个 - */ - public static int NUM_ONE_IMPORT_EXCEL = 5; - - /** - * docker启动的 oracle服务 的 实例名称 - */ - public static String ORACLE_ORCL = "orcl"; - - /** - * docker启动的 oracle服务 的 实例登陆用户名 - */ - public static String ORACLE_USER = "system"; - - /** - * docker启动的 oracle服务 的 实例登陆密码 - */ - public static String ORACLE_PSW = "oracle"; - - /** - * 采集库中的 标准表所在 的 用户 - */ - public static String COLLECT_STANDARD_TABLE_USER = "u_bzbjy"; - - /** - * 可执行的 标准表的 名 - */ - public static String COLLECT_EXEC_TABLE = "kzxzb"; - - /** - * 支付的 标准表的 名 - */ - public static String COLLECT_PAY_TABLE = "zfxxb"; - -} +package com.platform.utils; + +import org.apache.log4j.Logger; + +/** 配置启动 变量 + * @author chen + * + */ +public class Configs { + + /** 全局自定义异常--编码 */ + public static final String GLOBAL_EXP_CUSTOM = "3001001001"; + + /** 全局非自定义异常--编码 */ + public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002"; + + public static final String CONFIG_LOCALTION = "WebContent/WEB-INF/config/config.properties"; + + public static final Logger CONSOLE_LOGGER = Logger.getLogger("console"); + + public static final Logger DAILY_ROLLING_LOGGER = Logger + .getLogger("dailyRollingFile"); + + public static final Logger DAILY_LOGGER = Logger.getLogger("railyFile"); + + public static final Logger LOGGER = Logger.getLogger(Configs.class); + + public static String KUBE_MASTER_URL = "http://192.168.0.110:8080/"; // kubernetes集群的maser + // URl + + public static String KUBE_MASTER_ADDRESS="127.0.0.1:8080"; + + + public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号 + + public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名 + + public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码 + + public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名 + + public static String GATHER_PORT ="1521"; //汇总库的端口号 + + public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名 + + public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码 + + /** 抽取标准表 的 标准表所在 用户 */ + public static String GATHER_STANDARD_USER_NAME = "u_bzbjy"; + + /** 可执行表名 */ + public static String GATHER_STANDARD_EXEC_TABLE_NAME = "kzxzb"; + + /** 可支付表名 */ + public static String GATHER_STANDARD_PAY_TABLE_NAME = "zfxxb"; + + public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名 + + public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名 + + public static String EXTRACT_LOG_LOCALTION = "D:\\log"; //数据汇总日志保存位置 + + public static String EXTRACT_STANDARD_LOG_LOCALTION = "D:\\log2"; //数据抽取日志保存位置 + + public static String GATHER_TABLESPACE_NAME=""; //表空间名 + + public static String GATHER_TABLESPACE_PATH=""; //表空间路径 + + public static String GATHER_TABLE_PASSWORD="1"; //登入密码 + + /** excel上传路径 */ + public static String FILE_UPLOAD_PATH=""; + + /** excel下载路经 */ + public static String FILE_DOWNLOAD_PATH=""; + + /** 包下载路径 */ + public static String PACKAGE_DOWNLOAD_PATH=""; + + /** 下载包名 */ + public static String PACKAGE_NAME=""; + + /** + * 最新脚本的位置 + */ + public static String SQL_SCRIPT_PATH_LAST="D:\\test\\sql_script_last\\"; + /** 归档脚本的位置 */ + public static String SQL_SCRIPT_PATH_STANDARD="D:\\test\\sql_script_standard\\"; + + /** + * 多少 个月前的数据 + */ + public static int dataBefore = 6; + + /** + * excel导入一次批量导入5个 + */ + public static int NUM_ONE_IMPORT_EXCEL = 5; + + /** + * docker启动的 oracle服务 的 实例名称 + */ + public static String ORACLE_ORCL = "orcl"; + + /** + * docker启动的 oracle服务 的 实例登陆用户名 + */ + public static String ORACLE_USER = "system"; + + /** + * docker启动的 oracle服务 的 实例登陆密码 + */ + public static String ORACLE_PSW = "oracle"; + + /** + * 采集库中的 标准表所在 的 用户 + */ + public static String COLLECT_STANDARD_TABLE_USER = "u_bzbjy"; + + /** + * 可执行的 标准表的 名 + */ + public static String COLLECT_EXEC_TABLE = "kzxzb"; + + /** + * 支付的 标准表的 名 + */ + public static String COLLECT_PAY_TABLE = "zfxxb"; + +} diff --git a/test/com/platform/test/testStateThread.java b/test/com/platform/test/testStateThread.java new file mode 100644 index 00000000..ba3510c3 --- /dev/null +++ b/test/com/platform/test/testStateThread.java @@ -0,0 +1,20 @@ +package com.platform.test; + +public class testStateThread { + + public static void main(String[] args) { + + for (int i = 0; i < 100; i++) { + Thread t1 = new Thread(new testStatement(), "线程-"+i); + t1.setDaemon(true); + t1.start(); + } + try { + Thread.sleep(50000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/test/com/platform/test/testStatement.java b/test/com/platform/test/testStatement.java new file mode 100644 index 00000000..e8dfe680 --- /dev/null +++ b/test/com/platform/test/testStatement.java @@ -0,0 +1,63 @@ +package com.platform.test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; + +public class testStatement implements Runnable{ + + private static Connection createConnect() { + + Connection conn = null; + try { + Class.forName("oracle.jdbc.driver.OracleDriver"); + conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.110:1590:ORCL", "system", "oracle"); + } catch (SQLException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return conn; + + } + + @Override + public void run() { + + Connection conn = createConnect(); + + for(int i=0;i<1000;i++) + { + Statement prepstmt = null; + try { +// PreparedStatement prepstmt = conn.prepareStatement("select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME = 'ORCL'"); +// int numi = prepstmt.executeUpdate(); + prepstmt = conn.createStatement(); + int numi = prepstmt.executeUpdate("select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME = 'ORCL'"); + + + System.out.println(Thread.currentThread().getName()+" "+i +" : "+ numi); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + finally{ + if (prepstmt != null) { + try { + prepstmt.close(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + + + } + +}