Exemplo n.º 1
0
 private static String resolvScriptResource(
     List<Map<String, String>> resources, String script, ApplicationContext context) {
   Matcher m = PT.matcher(script);
   while (m.find()) {
     String s = m.group();
     s = s.substring(s.indexOf('[') + 1, s.indexOf(']'));
     String[] args = StringUtils.split(s, ' ');
     String uri = args[0];
     String name = "";
     String referScript = null;
     String path = uri.substring(uri.lastIndexOf('/') + 1);
     Map<String, String> map = new HashMap<String, String>(2);
     if (uri.startsWith("doc://")) {
       FileManager manager = (FileManager) context.getBean("fileManager");
       FileDescriptor fd = manager.getFile(path);
       name = fd.getName();
       // 把脚本放到map里,减少后面一次getFile调用
       referScript = fd.getContent();
     }
     if (args.length > 1) {
       name = "";
       for (int i = 1; i < args.length; i++) {
         if (i > 1) {
           name += "_";
         }
         name += args[i];
       }
     } else if (args.length == 1) {
       // 没有指定文件名
       if (uri.startsWith("hdfs://")) {
         if (uri.endsWith("/")) {
           continue;
         }
         name = path;
       }
     }
     boolean exist = false;
     for (Map<String, String> ent : resources) {
       if (ent.get("name").equals(name)) {
         exist = true;
         break;
       }
     }
     if (!exist) {
       map.put("uri", uri);
       map.put("name", name);
       resources.add(map);
       // 把脚本放到map里,减少后面一次getFile调用
       if (uri.startsWith("doc://") && referScript != null) {
         map.put("zeus-doc-" + path, resolvScriptResource(resources, referScript, context));
       }
     }
   }
   script = m.replaceAll("");
   return script;
 }
Exemplo n.º 2
0
 public static Job createDebugJob(
     JobContext jobContext,
     DebugHistory history,
     String workDir,
     ApplicationContext applicationContext) {
   jobContext.setDebugHistory(history);
   jobContext.setWorkDir(workDir);
   HierarchyProperties hp = new HierarchyProperties(new HashMap<String, String>());
   String script = history.getScript();
   List<Map<String, String>> resources = new ArrayList<Map<String, String>>();
   // 处理脚本中的 资源引用 语句
   script = resolvScriptResource(resources, script, applicationContext);
   jobContext.setResources(resources);
   hp.setProperty(PropertyKeys.JOB_SCRIPT, script);
   FileManager fileManager = (FileManager) applicationContext.getBean("fileManager");
   ProfileManager profileManager = (ProfileManager) applicationContext.getBean("profileManager");
   String owner = fileManager.getFile(history.getFileId()).getOwner();
   Profile profile = profileManager.findByUid(owner);
   if (profile != null && profile.getHadoopConf() != null) {
     for (String key : profile.getHadoopConf().keySet()) {
       hp.setProperty(key, profile.getHadoopConf().get(key));
     }
   }
   jobContext.setProperties(new RenderHierarchyProperties(hp));
   hp.setProperty("hadoop.mapred.job.zeus_id", "zeus_debug_" + history.getId());
   List<Job> pres = new ArrayList<Job>(1);
   pres.add(new DownloadJob(jobContext));
   Job core = null;
   if (history.getJobRunType() == JobRunType.Hive) {
     core = new HiveJob(jobContext, applicationContext);
   } else if (history.getJobRunType() == JobRunType.Shell) {
     core = new HadoopShellJob(jobContext);
   }
   Job job =
       new WithProcesserJob(jobContext, pres, new ArrayList<Job>(), core, applicationContext);
   return job;
 }