package com.meiyou.bigwhale.service;
import com.meiyou.bigwhale.common.Constant;
import com.meiyou.bigwhale.config.SshConfig;
import com.meiyou.bigwhale.config.YarnConfig;
import com.meiyou.bigwhale.data.service.AbstractMysqlPagingAndSortingQueryService;
import com.meiyou.bigwhale.dto.DtoScript;
import com.meiyou.bigwhale.entity.*;
import com.meiyou.bigwhale.entity.auth.User;
import com.meiyou.bigwhale.service.auth.UserService;
import com.meiyou.bigwhale.util.WebHdfsUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service
public class ScriptServiceImpl extends AbstractMysqlPagingAndSortingQueryService<Script, Integer> implements ScriptService {
private static final Pattern DATE_PATTERN = Pattern.compile("(\\$\\{now(\\s*([-+])\\s*(\\d+)([dhms]))*(@([A-Za-z0-9\\s-':+.]+))*})+");
@Autowired
private MonitorService monitorService;
@Autowired
private ScriptHistoryService scriptHistoryService;
@Autowired
private ClusterService clusterService;
@Autowired
private UserService userService;
@Autowired
private AgentService agentService;
@Autowired
private ClusterUserService clusterUserService;
@Autowired
private SshConfig sshConfig;
@Autowired
private YarnConfig yarnConfig;
@Transactional(rollbackFor = Exception.class)
@Override
public void delete(Script entity) {
//删除jar包
if (entity.isYarn()) {
deleteJar(entity);
}
if (entity.getMonitorId() != null) {
monitorService.deleteById(entity.getMonitorId());
}
super.delete(entity);
}
@Override
public Page<Script> fuzzyPage(DtoScript req) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Script> criteriaQuery = builder.createQuery(clazz);
Root<Script> root = criteriaQuery.from(clazz);
CriteriaQuery<Long> countCriteriaQuery = builder.createQuery(Long.class);
Root<Script> countRoot = countCriteriaQuery.from(clazz);
countCriteriaQuery.select(builder.count(countRoot));
this.predicate(builder, criteriaQuery, root, req);
this.predicate(builder, countCriteriaQuery, countRoot, req);
long totalCount = entityManager.createQuery(countCriteriaQuery).getSingleResult();
int pageNo = req.pageNo - 1;
int pageSize = req.pageSize;
TypedQuery<Script> typedQuery = entityManager.createQuery(criteriaQuery);
typedQuery.setFirstResult(pageNo * pageSize);
typedQuery.setMaxResults(pageSize);
List<Script> entities = typedQuery.getResultList();
return new PageImpl<>(entities, new PageRequest(pageNo, pageSize), totalCount);
}
@Override
public String validate(DtoScript req) {
String msg = checkLegal(req);
if (msg != null) {
return msg;
}
//应用内存资源参数检查和补充必要参数
if (req.isYarn()) {
if (yarnConfig.getAppMemoryThreshold() > 0 && !yarnConfig.getAppWhiteList().contains(req.getApp())) {
try {
int totalMemory = calResource(req.getType(), req.getContent()).get("totalMemory");
if (totalMemory > yarnConfig.getAppMemoryThreshold()) {
//超过阀值
return "内存参数配置达到大内存应用标准【" + yarnConfig.getAppMemoryThreshold() + "MB】 !请调小内存参数或联系管理员升级为大内存应用。";
}
} catch (NumberFormatException e) {
return "内存参数请向上取整";
}
}
appendNecessaryArgs(req);
}
if (req.getId() != null) {
Script dbScript = findById(req.getId());
if (Constant.ScriptType.SPARK_STREAM.equals(dbScript.getType()) || Constant.ScriptType.FLINK_STREAM.equals(dbScript.getType())) {
//更换集群或队列时检查应用是否正在运行
if (checkNeedKillYarnAppIfChangeClusterOrQueue(dbScript, req)) {
return "更换集群或队列前请先关闭正在运行的应用";
}
}
if (dbScript.isYarn()) {
//检查程序包是否变更
String dbJarPath = extractJarPath(dbScript.getContent());
String reqJarPath = extractJarPath(req.getContent());
if (!dbJarPath.equals(reqJarPath)) {
deleteJar(dbScript);
}
}
}
if (StringUtils.isBlank(req.getUser())) {
req.setUser(sshConfig.getUser());
}
return null;
}
@Transactional(rollbackFor = Exception.class)
@Override
public Script update(Script entity, Monitor monitorEntity) {
Monitor monitor = monitorService.save(monitorEntity);
if (entity.getMonitorId() == null) {
entity.setMonitorId(monitor.getId());
}
return super.save(entity);
}
@Override
public ScriptHistory generateHistory(Script script) {
return generateHistory(script, null, null, null, null);
}
@Override
public ScriptHistory generateHistory(Script script, Monitor monitor) {
return generateHistory(script, monitor, null, null, null);
}
@Transactional(rollbackFor = Exception.class)
@Override
public void generateHistory(Schedule schedule, String scheduleInstanceId, String previousScheduleTopNodeId) {
recursiveGenerateHistory(schedule, scheduleInstanceId, previousScheduleTopNodeId);
}
@Transactional(rollbackFor = Exception.class)
@Override
public void reGenerateHistory(Schedule schedule, String scheduleInstanceId, String previousScheduleTopNodeId) {
generateHistory(schedule, scheduleInstanceId, previousScheduleTopNodeId);
}
@Override
public String extractJarPath(String content) {
String [] tokens = content.split(" ");
int jarIndex = -1;
for (int i = 0; i < tokens.length; i ++) {
String token = tokens[i];
if (token.contains(".jar") || token.contains(".py")) {
if (!"--jars".equals(tokens[i - 1]) && !"-j".equals(tokens[i - 1]) && !"--jar".equals(tokens[i - 1])) {
jarIndex = i;
break;
}
}
}
if (jarIndex != -1) {
return tokens[jarIndex];
}
return null;
}
@Override
public void deleteJar(Script entity) {
String jarPath = extractJarPath(entity.getContent());
if (jarPath != null) {
//检查是否还被引用
boolean used = false;
for (Script item : findByQuery("createBy=" + entity.getCreateBy() + ";id!=" + entity.getId())) {
if (jarPath.equals(extractJarPath(item.getContent()))) {
used = true;
break;
}
}
if (!used) {
for (Cluster cluster : clusterService.findAll()) {
if (jarPath.startsWith(cluster.getFsDefaultFs())) {
String fs
没有合适的资源?快使用搜索试试~ 我知道了~
big-whale-master.zip

共1191个文件
js:868个
java:126个
gif:76个

0 下载量 117 浏览量
2023-03-09
11:12:05
上传
评论
收藏 3.83MB ZIP 举报
温馨提示
巨鲸任务调度平台为美柚大数据研发的分布式计算任务调度系统,提供Spark、Flink等批处理任务的DAG调度和流处理任务的运行管理和状态监控,并具有Yarn应用管理、重复应用检测、大内存应用检测等功能。
资源推荐
资源详情
资源评论























收起资源包目录





































































































共 1191 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论


m0_72731342
- 粉丝: 4
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 大数据时代自动化设备采购管理的模式创新.docx
- 数控铣床及加工中心编程全解课件(1).ppt
- 全计算机技术与软件专业技术资格(水平)测验考试网络工程师试卷.doc
- 东北大学接口技术微机原理课程方案设计书大作业.doc
- 压缩机自动控制系统程序设计-正文.doc
- 从零开始-无线网络终极应用宝典.doc
- 软件项目实施保障措施.docx
- 电大2016网络安全专业技术网考答案.doc
- 基于三菱plc的电力系统无功补偿研究设计.doc
- 材资源网站/源码网模板/FE素材网交易平台源码
- web-课程设计-20102344078-庄晓闯.doc
- 试述智慧城市三维GIS在现代化发展前景.docx
- 基于互联网+土木工程专业英语教学改革研究.docx
- 上半信息系统项目管理师上午试题分析与解答.doc
- 基于Hadoop和Spark的可扩展性化工类大数据分析系统设计.docx
- 大数据时代财务报告及其未来模式研究.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
