Example #1
0
  @Override
  public void init(ServletConfig config) throws ServletException {

    try {

      // init file stream http server
      server = new JettyStreamServer(new FileSaveCallback());
      WebCenterContext.put(Constants.FILE_SERVER_PORT, server.getPort());

      // init WebCenterContext
      String dewHome = System.getenv("DEW_HOME");
      Map<String, String> conf = Files.loadPropertiesFile("/conf.properties.default");
      File confFile = new File(dewHome, "app.webcenter/conf.properties");
      if (confFile.exists()) {
        System.out.println("Load conf from " + confFile.getAbsolutePath());
        Map<String, String> userConf = Files.loadPropertiesFile(new FileInputStream(confFile));
        conf.putAll(userConf);
      }
      WebCenterContext.putConf(conf);

      try {
        dbExist();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      // init cluster system performance data for home page
      CircleLink cl = CircleLink.getInstance();
      dstatApp = GroupMetricsApp.getInstance();
      dstatApp.startCollectCulsterDstat(cl, DSTAT_INTERVAL);

      // init quartz scheduler
      Timer timer = Timer.getInstance();
      DBOperator operator = new DBOperator();
      ArrayList<JobBean> jobs = operator.getAllJob();
      for (JobBean job : jobs) {
        try {
          timer.schedule(job.getName(), job.getCycle());
        } catch (Throwable e) {
          log.error(e.getMessage());
        }
      }
    } catch (Exception e) {
      log.error(e.getMessage());
    }
  }
Example #2
0
 private void dbExist() throws SQLException {
   Map<String, String> jdbcConf = WebCenterContext.getConf();
   String dbDriver = jdbcConf.get(Constants.DB_DRIVER);
   String dbURL = jdbcConf.get(Constants.DB_URL);
   String dbUsername = jdbcConf.get(Constants.DB_USERNAME);
   String dbPassword = jdbcConf.get(Constants.DB_PASSWORD);
   try {
     Class.forName(dbDriver).newInstance();
     Connection conn = DriverManager.getConnection(dbURL, dbUsername, dbPassword);
     conn.close();
   } catch (Exception e) {
     Connection conn =
         DriverManager.getConnection(
             dbURL + ";create=true;user="******";password="******"create table userinfo(user_id int generated always as identity,name "
             + "varchar(10) NOT NULL,password varchar(20) NOT NULL,type varchar(20) "
             + "NOT NULL,primary key(user_id))");
     st.execute("insert into userinfo(name,password,type) values('admin','admin','Admin')");
     st.execute(
         "create table application(app_id int generated always as identity,name "
             + "varchar(100) NOT NULL,path varchar(1000) NOT NULL,executable varchar(100) "
             + "NOT NULL,strategy varchar(15) NOT NULL,type varchar(15) NOT NULL,"
             + "host varchar(100) NOT NULL,primary key(app_id))");
     st.execute(
         "create table job(job_id int generated always as identity,name "
             + "varchar(100) NOT NULL,defination varchar(2000),cycle varchar(20),user_id int,"
             + "primary key(job_id))");
     st.execute(
         "create table jobrecord(record_id varchar(100) NOT NULL,job_id int "
             + "NOT NULL,starttime timestamp NOT NULL,endtime timestamp NOT NULL,"
             + "result varchar(20) NOT NULL,primary key(record_id))");
     st.execute(
         "create table apprecord(record_id varchar(100) NOT NULL,app_name "
             + "varchar(100) NOT NULL,job_recordid varchar(100) NOT NULL,engin_app_id "
             + "varchar(100),starttime timestamp NOT NULL,endtime timestamp NOT NULL,"
             + "result varchar(20) NOT NULL,primary key(record_id))");
     st.close();
     conn.close();
   }
 }