}
}
@Override
public JobModel getUpstreamJob(String jobId) throws GwtException {
JobBean jobBean=permissionGroupManager.getUpstreamJobBean(jobId);
JobModel jobModel=new JobModel();
jobModel.setCronExpression(jobBean.getJobDescriptor().getCronExpression());
jobModel.setDependencies(jobBean.getJobDescriptor().getDependencies());
jobModel.setDesc(jobBean.getJobDescriptor().getDesc());
jobModel.setGroupId(jobBean.getJobDescriptor().getGroupId());
jobModel.setId(jobBean.getJobDescriptor().getId());
String jobRunType=null;
if(jobBean.getJobDescriptor().getJobType()==JobRunType.MapReduce){
jobRunType=JobModel.MapReduce;
}else if(jobBean.getJobDescriptor().getJobType()==JobRunType.Shell){
jobRunType=JobModel.SHELL;
}else if(jobBean.getJobDescriptor().getJobType()==JobRunType.Hive){
jobRunType=JobModel.HIVE;
}
jobModel.setJobRunType(jobRunType);
String jobScheduleType=null;
if(jobBean.getJobDescriptor().getScheduleType()==JobScheduleType.Dependent){
jobScheduleType=JobModel.DEPEND_JOB;
}else if(jobBean.getJobDescriptor().getScheduleType()==JobScheduleType.Independent){
jobScheduleType=JobModel.INDEPEN_JOB;
}
jobModel.setJobScheduleType(jobScheduleType);
jobModel.setLocalProperties(jobBean.getJobDescriptor().getProperties());
jobModel.setName(jobBean.getJobDescriptor().getName());
jobModel.setOwner(jobBean.getJobDescriptor().getOwner());
String ownerName=userManager.findByUid(jobModel.getOwner()).getName();
if(ownerName==null || "".equals(ownerName.trim()) || "null".equals(ownerName)){
ownerName=jobModel.getOwner();
}
jobModel.setOwnerName(ownerName);
jobModel.setLocalResources(jobBean.getJobDescriptor().getResources());
jobModel.setAllProperties(jobBean.getHierarchyProperties().getAllProperties());
jobModel.setAllResources(jobBean.getHierarchyResources());
jobModel.setAuto(jobBean.getJobDescriptor().getAuto());
jobModel.setScript(jobBean.getJobDescriptor().getScript());
List<String> preList=new ArrayList<String>();
if(!jobBean.getJobDescriptor().getPreProcessers().isEmpty()){
for(Processer p:jobBean.getJobDescriptor().getPreProcessers()){
JSONObject o=new JSONObject();
o.put("id", p.getId());
o.put("config", p.getConfig());
preList.add(o.toString());
}
}
jobModel.setPreProcessers(preList);
List<String> postList=new ArrayList<String>();
if(!jobBean.getJobDescriptor().getPostProcessers().isEmpty()){
for(Processer p:jobBean.getJobDescriptor().getPostProcessers()){
JSONObject o=new JSONObject();
o.put("id", p.getId());
o.put("config", p.getConfig());
postList.add(o.toString());
}
}
jobModel.setPostProcessers(postList);
jobModel.setAdmin(permissionGroupManager.hasJobPermission(LoginUser.getUser().getUid(), jobId));
List<ZeusFollow> follows=followManager.findJobFollowers(jobId);
if(follows!=null){
List<String> followNames=new ArrayList<String>();
for(ZeusFollow zf:follows){
String name=userManager.findByUid(zf.getUid()).getName();
if(name==null || "".equals(name.trim())){
name=zf.getUid();
}
followNames.add(name);
}
jobModel.setFollows(followNames);
}
List<String> ladmins=permissionManager.getJobAdmins(jobId);
List<String> admins=new ArrayList<String>();
for(String s:ladmins){
String name=userManager.findByUid(s).getName();
if(name==null || "".equals(name.trim()) || "null".equals(name)){
name=s;
}
admins.add(name);
}
jobModel.setAdmins(admins);
List<String> owners=new ArrayList<String>();
owners.add(jobBean.getJobDescriptor().getOwner());
GroupBean parent=jobBean.getGroupBean();
while(parent!=null){
if(!owners.contains(parent.getGroupDescriptor().getOwner())){
owners.add(parent.getGroupDescriptor().getOwner());
}
parent=parent.getParentGroupBean();
}
jobModel.setOwners(owners);
//所有secret. 开头的配置项都进行权限控制
for(String key:jobModel.getAllProperties().keySet()){
boolean isLocal=jobModel.getLocalProperties().get(key)==null?false:true;
if(key.startsWith("secret.")){
if(!isLocal){
jobModel.getAllProperties().put(key, "*");
}else{
if(!jobModel.getAdmin() && !jobModel.getOwner().equals(LoginUser.getUser().getUid())){
jobModel.getLocalProperties().put(key, "*");
}
}
}
}
//本地配置项中的hadoop.hadoop.job.ugi 只有管理员和owner才能查看,继承配置项不能查看
String SecretKey="core-site.hadoop.job.ugi";
if(jobModel.getLocalProperties().containsKey(SecretKey)){
String value=jobModel.getLocalProperties().get(SecretKey);
if(value.lastIndexOf("#")==-1){
value="*";
}else{
value=value.substring(0, value.lastIndexOf("#"));
value+="#*";
}
if(!jobModel.getAdmin() && !jobModel.getOwner().equals(LoginUser.getUser().getUid())){
jobModel.getLocalProperties().put(SecretKey, value);
}
jobModel.getAllProperties().put(SecretKey, value);
}else if(jobModel.getAllProperties().containsKey(SecretKey)){
String value=jobModel.getAllProperties().get(SecretKey);
if(value.lastIndexOf("#")==-1){
value="*";
}else{
value=value.substring(0, value.lastIndexOf("#"));
value+="#*";
}
jobModel.getAllProperties().put(SecretKey, value);
}
//如果zeus.secret.script=true 并且没有权限,对script进行加密处理
if("true".equalsIgnoreCase(jobModel.getAllProperties().get("zeus.secret.script"))){
if(!jobModel.getAdmin() && !jobModel.getOwner().equals(LoginUser.getUser().getUid())){
jobModel.setScript("脚本已加密,如需查看请联系相关负责人分配权限");
}
}
return jobModel;
}