Example #1
0
  public boolean addOneJob(long configID, boolean immediate) {
    ZCDeployJobSchema job = new ZCDeployJobSchema();
    ZCDeployConfigSchema config = new ZCDeployConfigSchema();
    config.setID(configID);
    if (!config.fill()) {
      return false;
    }

    String staticDir =
        Config.getContextRealPath() + Config.getValue("Statical.TargetDir").replace('\\', '/');
    String sourcePath =
        staticDir + "/" + ApplicationPage.getCurrentSiteAlias() + config.getSourceDir();
    job.setID(NoUtil.getMaxID("DeployJobID"));
    job.setConfigID(config.getID());
    job.setSource(sourcePath);
    job.setMethod(config.getMethod());

    String targetDir = config.getTargetDir();
    if (XString.isEmpty(targetDir)) {
      targetDir = "/";
    } else if (!targetDir.endsWith("/")) {
      targetDir = targetDir + "/";
    }

    job.setTarget(targetDir);
    job.setSiteID(config.getSiteID());
    job.setHost(config.getHost());
    job.setPort(config.getPort());
    job.setUserName(config.getUserName());
    job.setPassword(config.getPassword());
    job.setStatus(0L);
    job.setAddTime(new Date());
    job.setAddUser(User.getUserName());

    Transaction trans = new Transaction();
    trans.add(job, OperateType.INSERT);
    if (trans.commit()) {
      if (immediate) {
        executeJob(config, job);
      }
      return true;
    }
    LogUtil.getLogger().info("添加部署任务时,数据库操作失败");
    return false;
  }
Example #2
0
  public ZCDeployJobSet getJobs(long siteID, ArrayList list, String operation) {
    ZCDeployJobSet jobSet = new ZCDeployJobSet();
    for (int j = 0; j < list.size(); j++) {
      String srcPath = (String) list.get(j);
      if (XString.isEmpty(srcPath)) {
        continue;
      }
      srcPath = srcPath.replace('\\', '/').replaceAll("///", "/").replaceAll("//", "/");

      String baseDir =
          Config.getContextRealPath() + Config.getValue("Statical.TargetDir").replace('\\', '/');
      baseDir = baseDir + "/" + SiteUtil.getAlias(siteID);

      baseDir = baseDir.replaceAll("///", "/");
      baseDir = baseDir.replaceAll("//", "/");
      srcPath = srcPath.replaceAll(baseDir, "");

      ZCDeployConfigSchema config = new ZCDeployConfigSchema();

      QueryBuilder qb =
          new QueryBuilder(
              " where UseFlag =1 and siteid=? and ? like concat(sourcedir,'%')", siteID, srcPath);
      if (Config.isSQLServer()) {
        qb.setSQL(" where siteid=? and charindex(sourcedir,?)=0");
      }
      if (Config.isDB2()) {
        qb.setSQL(" where siteid=? and locate(sourcedir,'" + srcPath + "')=0");
        qb.getParams().remove(qb.getParams().size() - 1);
      }

      ZCDeployConfigSet set = config.query(qb);

      for (int i = 0; i < set.size(); i++) {
        config = set.get(i);
        String target = config.getTargetDir();
        if (XString.isEmpty(target)) {
          target = "/";
        } else if (!target.endsWith("/")) {
          target = target + "/";
        }

        String filePath = srcPath;
        if (!config.getSourceDir().equals("/")) {
          filePath = srcPath.replaceAll(config.getSourceDir(), "");
        }
        target = dealFileName(target, filePath);

        ZCDeployJobSchema job = new ZCDeployJobSchema();
        job.setID(NoUtil.getMaxID("DeployJobID"));
        job.setConfigID(config.getID());
        job.setSource(baseDir + srcPath);
        job.setMethod(config.getMethod());
        job.setTarget(target);
        job.setSiteID(config.getSiteID());
        job.setHost(config.getHost());
        job.setPort(config.getPort());
        job.setUserName(config.getUserName());
        job.setPassword(config.getPassword());
        job.setRetryCount(0L);
        job.setStatus(0L);
        job.setOperation(operation);
        job.setAddTime(new Date());
        if (User.getCurrent() != null) job.setAddUser(User.getUserName());
        else {
          job.setAddUser("SYS");
        }

        jobSet.add(job);
      }
    }

    return jobSet;
  }