Browse Source

AMBARI-17962. Coverity Scan Security Vulnerability - SQL injection (rlevas)

Robert Levas 9 years ago
parent
commit
433698901b

+ 0 - 56
ambari-server/src/main/java/org/apache/ambari/eventdb/db/DBConnector.java

@@ -1,56 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.eventdb.db;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.ambari.eventdb.model.DataTable;
-import org.apache.ambari.eventdb.model.Jobs.JobDBEntry;
-import org.apache.ambari.eventdb.model.TaskAttempt;
-import org.apache.ambari.eventdb.model.WorkflowContext;
-import org.apache.ambari.eventdb.model.Workflows;
-import org.apache.ambari.eventdb.model.Workflows.WorkflowDBEntry.WorkflowFields;
-
-public interface DBConnector {
-  public void submitJob(JobDBEntry j, WorkflowContext context) throws IOException;
-  
-  public void updateJob(JobDBEntry j) throws IOException;
-  
-  public Workflows fetchWorkflows() throws IOException;
-  
-  public Workflows fetchWorkflows(WorkflowFields field, boolean sortAscending, int offset, int limit) throws IOException;
-  
-  public DataTable fetchWorkflows(int offset, int limit, String searchTerm, int echo, WorkflowFields field, boolean sortAscending, String searchWorkflowId,
-      String searchWorkflowName, String searchWorkflowType, String searchUserName, int minJobs, int maxJobs, long minInputBytes, long maxInputBytes,
-      long minOutputBytes, long maxOutputBytes, long minDuration, long maxDuration, long minStartTime, long maxStartTime, long minFinishTime, long maxFinishTime)
-      throws IOException;
-  
-  public List<JobDBEntry> fetchJobDetails(String workflowID) throws IOException;
-  
-  public List<JobDBEntry> fetchJobDetails(long minFinishTime, long maxStartTime) throws IOException;
-  
-  public long[] fetchJobStartStopTimes(String jobID) throws IOException;
-  
-  public List<TaskAttempt> fetchJobTaskAttempts(String jobID) throws IOException;
-  
-  public List<TaskAttempt> fetchWorkflowTaskAttempts(String workflowID) throws IOException;
-  
-  public List<TaskAttempt> fetchTaskAttempts(long minFinishTime, long maxStartTime) throws IOException;
-  
-  public void close();
-}

+ 0 - 38
ambari-server/src/main/java/org/apache/ambari/eventdb/db/MySQLConnector.java

@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.eventdb.db;
-
-import org.apache.ambari.eventdb.model.Workflows;
-
-import java.io.IOException;
-import java.sql.PreparedStatement;
-
-public class MySQLConnector extends PostgresConnector {
-  public MySQLConnector(String connectionURL, String driverName, String username, String password) throws IOException {
-    super(connectionURL, driverName, username, password);
-  }
-
-  @Override
-  protected PreparedStatement getQualifiedPS(Statements statement, String searchClause, Workflows.WorkflowDBEntry.WorkflowFields field, boolean sortAscending, int offset, int limit) throws IOException {
-    if (db == null)
-      throw new IOException("postgres db not initialized");
-    String limitClause = " ORDER BY " + field.toString() + " " + (sortAscending ? SORT_ASC : SORT_DESC) + " LIMIT " + (limit >= 0 ? limit : DEFAULT_LIMIT) + " OFFSET " + offset;
-    return getQualifiedPS(statement, searchClause + limitClause);
-  }
-}

+ 0 - 58
ambari-server/src/main/java/org/apache/ambari/eventdb/db/OracleConnector.java

@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.eventdb.db;
-
-import org.apache.ambari.eventdb.model.Workflows;
-
-import java.io.IOException;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-public class OracleConnector extends PostgresConnector {
-
-  public OracleConnector(String connectionURL, String driverName, String username, String password) throws IOException {
-    super(connectionURL, driverName, username, password);
-  }
-
-  @Override
-  protected PreparedStatement getQualifiedPS(Statements statement, String searchClause, Workflows.WorkflowDBEntry.WorkflowFields field, boolean sortAscending, int offset, int limit) throws IOException {
-    if (db == null)
-      throw new IOException("db not initialized");
-
-    String order = " ORDER BY " + field.toString() + " " + (sortAscending ? SORT_ASC : SORT_DESC);
-
-    String query = "select * \n" +
-        "  from ( select " +
-//        "/*+ FIRST_ROWS(n) */ \n" +
-        "  a.*, ROWNUM rnum \n" +
-        "      from ("
-        + statement.getStatementString() + searchClause + order +
-        ") a \n" +
-        "      where ROWNUM <= " + (offset + limit) + ") \n" +
-        "where rnum  >= " + offset;
-
-    try {
-      return db.prepareStatement(query);
-    } catch (SQLException e) {
-      throw new IOException(e);
-    }
-
-  }
-
-
-}

+ 0 - 608
ambari-server/src/main/java/org/apache/ambari/eventdb/db/PostgresConnector.java

@@ -1,608 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.eventdb.db;
-
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.ambari.eventdb.model.DataTable;
-import org.apache.ambari.eventdb.model.DataTable.AvgData;
-import org.apache.ambari.eventdb.model.DataTable.Summary;
-import org.apache.ambari.eventdb.model.DataTable.Summary.SummaryFields;
-import org.apache.ambari.eventdb.model.DataTable.Times;
-import org.apache.ambari.eventdb.model.Jobs.JobDBEntry;
-import org.apache.ambari.eventdb.model.Jobs.JobDBEntry.JobFields;
-import org.apache.ambari.eventdb.model.TaskAttempt;
-import org.apache.ambari.eventdb.model.TaskAttempt.TaskAttemptFields;
-import org.apache.ambari.eventdb.model.WorkflowContext;
-import org.apache.ambari.eventdb.model.Workflows;
-import org.apache.ambari.eventdb.model.Workflows.WorkflowDBEntry;
-import org.apache.ambari.eventdb.model.Workflows.WorkflowDBEntry.WorkflowFields;
-import org.apache.commons.lang.NotImplementedException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-
-public class PostgresConnector implements DBConnector {
-  private static Log LOG = LogFactory.getLog(PostgresConnector.class);
-  private static final String WORKFLOW_TABLE_NAME = "workflow";
-  private static final String JOB_TABLE_NAME = "job";
-  private static final String TASK_ATTEMPT_TABLE_NAME = "taskattempt";
-  public static final String SORT_ASC = "ASC";
-  public static final String SORT_DESC = "DESC";
-  protected static final int DEFAULT_LIMIT = 10;
-  
-  private static final ObjectMapper jsonMapper = new ObjectMapper();
-  
-  protected Connection db;
-  
-  public static enum Statements {
-    SJ_INSERT_JOB_PS(""),
-    SJ_CHECK_WORKFLOW_PS(""),
-    SJ_INSERT_WORKFLOW_PS(""),
-    UJ_UPDATE_JOB_PS(""),
-    UJ_UPDATE_WORKFLOW_PS(""),
-    FW_PS("SELECT " + WorkflowDBEntry.WORKFLOW_FIELDS + " FROM " + WORKFLOW_TABLE_NAME),
-    FW_COUNT_PS("SELECT count(*) as " + SummaryFields.numRows + " FROM " + WORKFLOW_TABLE_NAME),
-    FW_SUMMARY_PS("SELECT count(*) as " + SummaryFields.numRows + ", "
-        + getAvg(WorkflowFields.NUMJOBSTOTAL, SummaryFields.avgJobs, SummaryFields.minJobs, SummaryFields.maxJobs) + ", "
-        + getAvg(WorkflowFields.INPUTBYTES, SummaryFields.avgInput, SummaryFields.minInput, SummaryFields.maxInput) + ", "
-        + getAvg(WorkflowFields.OUTPUTBYTES, SummaryFields.avgOutput, SummaryFields.minOutput, SummaryFields.maxOutput) + ", "
-        + getAvg(WorkflowFields.DURATION, SummaryFields.avgDuration, SummaryFields.minDuration, SummaryFields.maxDuration) + ", min("
-        + WorkflowFields.STARTTIME + ") as " + SummaryFields.oldest + ", max(" + WorkflowFields.STARTTIME + ") as " + SummaryFields.youngest + " FROM "
-        + WORKFLOW_TABLE_NAME),
-    FJD_PS("SELECT " + JobDBEntry.JOB_FIELDS + " FROM " + JOB_TABLE_NAME + " WHERE " + JobFields.WORKFLOWID.toString() + " = ?"),
-    FJD_TIMERANGE_PS("SELECT " + JobDBEntry.JOB_FIELDS + " FROM " + JOB_TABLE_NAME + " WHERE " + JobFields.FINISHTIME.toString() + " >= ? AND "
-        + JobFields.SUBMITTIME.toString() + " <= ? ORDER BY " + JobFields.WORKFLOWID + ", " + JobFields.JOBID),
-    FJSS_PS("SELECT " + JobFields.SUBMITTIME + ", " + JobFields.FINISHTIME + " FROM " + JOB_TABLE_NAME + " WHERE " + JobFields.JOBID + " = ?"),
-    FJTA_PS("SELECT " + TaskAttempt.TASK_ATTEMPT_FIELDS + " FROM " + TASK_ATTEMPT_TABLE_NAME + " WHERE " + TaskAttemptFields.JOBID + " = ? ORDER BY "
-        + TaskAttemptFields.STARTTIME),
-    FWTA_PS("SELECT " + TaskAttemptFields.join(TASK_ATTEMPT_TABLE_NAME) + " FROM " + TASK_ATTEMPT_TABLE_NAME + ", " + JOB_TABLE_NAME + " WHERE "
-        + TASK_ATTEMPT_TABLE_NAME + "." + TaskAttemptFields.JOBID + " = " + JOB_TABLE_NAME + "." + JobFields.JOBID + " AND " + JOB_TABLE_NAME + "."
-        + JobFields.WORKFLOWID + " = ?"
-        + " ORDER BY " + TaskAttemptFields.JOBID + "," + TaskAttemptFields.STARTTIME + ", " + TaskAttemptFields.FINISHTIME),
-    FTA_TIMERANGE_PS("SELECT " + TaskAttempt.TASK_ATTEMPT_FIELDS + " FROM " + TASK_ATTEMPT_TABLE_NAME + " WHERE " + TaskAttemptFields.FINISHTIME + " >= ? AND "
-        + TaskAttemptFields.STARTTIME + " <= ? AND (" + TaskAttemptFields.TASKTYPE + " = 'MAP' OR  " + TaskAttemptFields.TASKTYPE + " = 'REDUCE') ORDER BY "
-        + TaskAttemptFields.STARTTIME);
-    
-    private String statementString;
-    
-    Statements(String statementString) {
-      this.statementString = statementString;
-    }
-    
-    public String getStatementString() {
-      return statementString;
-    }
-    
-    private static String getAvg(WorkflowFields field, SummaryFields avg, SummaryFields min, SummaryFields max) {
-      return "avg(" + field + ") as " + avg + ", min(" + field + ") as " + min + ", max(" + field + ") as " + max;
-    }
-  }
-  
-  private Map<Statements,PreparedStatement> preparedStatements = new EnumMap<Statements,PreparedStatement>(Statements.class);
-  
-  public PostgresConnector(String connectionURL, String driverName, String username, String password) throws IOException {
-    try {
-      Class.forName(driverName);
-      db = DriverManager.getConnection(connectionURL, username, password);
-    } catch (ClassNotFoundException e) {
-      db = null;
-      throw new IOException(e);
-    } catch (SQLException e) {
-      db = null;
-      throw new IOException(e);
-    }
-  }
-  
-  @Override
-  public void submitJob(JobDBEntry j, WorkflowContext context) throws IOException {
-    // PreparedStatement insertJobPS = getPS(Statements.SJ_INSERT_JOB_PS);
-    // PreparedStatement checkWorkflowPS = getPS(Statements.SJ_CHECK_WORKFLOW_PS);
-    // PreparedStatement insertWorkflowPS = getPS(Statements.SJ_INSERT_WORKFLOW_PS);
-    throw new NotImplementedException();
-  }
-  
-  @Override
-  public void updateJob(JobDBEntry j) throws IOException {
-    // PreparedStatement updateJobPS = getPS(Statements.UJ_UPDATE_JOB_PS);
-    // PreparedStatement updateWorkflowPS = getPS(Statements.UJ_UPDATE_WORKFLOW_PS);
-    throw new NotImplementedException();
-  }
-  
-  @Override
-  public Workflows fetchWorkflows() throws IOException {
-    Workflows workflows = new Workflows();
-    workflows.setWorkflows(fetchWorkflows(getPS(Statements.FW_PS)));
-    workflows.setSummary(fetchSummary(getPS(Statements.FW_SUMMARY_PS)));
-    return workflows;
-  }
-  
-  @Override
-  public Workflows fetchWorkflows(WorkflowFields field, boolean sortAscending, int offset, int limit) throws IOException {
-    if (offset < 0)
-      offset = 0;
-    Workflows workflows = new Workflows();
-    workflows.setWorkflows(fetchWorkflows(getQualifiedPS(Statements.FW_PS, "", field, sortAscending, offset, limit)));
-    workflows.setSummary(fetchSummary(getPS(Statements.FW_SUMMARY_PS)));
-    return workflows;
-  }
-  
-  private List<WorkflowDBEntry> fetchWorkflows(PreparedStatement ps) throws IOException {
-    List<WorkflowDBEntry> workflows = new ArrayList<WorkflowDBEntry>();
-    ResultSet rs = null;
-    try {
-      rs = ps.executeQuery();
-      while (rs.next()) {
-        workflows.add(getWorkflowDBEntry(rs));
-      }
-    } catch (SQLException e) {
-      throw new IOException(e);
-    } finally {
-      try {
-        if (rs != null){
-          rs.close();
-        }
-        if (ps != null) {
-          ps.close();
-        }
-      } catch (SQLException e) {
-        LOG.error("Exception while closing ResultSet", e);
-      }
-    }
-    return workflows;
-  }
-  
-  private Summary fetchSummary(PreparedStatement ps) throws IOException {
-    Summary summary = new Summary();
-    ResultSet rs = null;
-    try {
-      rs = ps.executeQuery();
-      if (rs.next()) {
-        summary.setNumRows(SummaryFields.numRows.getInt(rs));
-        summary.setJobs(getAvgData(rs, SummaryFields.avgJobs, SummaryFields.minJobs, SummaryFields.maxJobs));
-        summary.setInput(getAvgData(rs, SummaryFields.avgInput, SummaryFields.minInput, SummaryFields.maxInput));
-        summary.setOutput(getAvgData(rs, SummaryFields.avgOutput, SummaryFields.minOutput, SummaryFields.maxOutput));
-        summary.setDuration(getAvgData(rs, SummaryFields.avgDuration, SummaryFields.minDuration, SummaryFields.maxDuration));
-        Times times = new Times();
-        times.setYoungest(SummaryFields.youngest.getLong(rs));
-        times.setOldest(SummaryFields.oldest.getLong(rs));
-        summary.setTimes(times);
-      }
-    } catch (SQLException e) {
-      throw new IOException(e);
-    } finally {
-      try {
-        if (rs != null) {
-          rs.close();
-        }
-        if (ps != null) {
-          ps.close();
-        }        
-      } catch (SQLException e) {
-        LOG.error("Exception while closing ResultSet", e);
-      }
-    }
-    return summary;
-  }
-  
-  private static WorkflowDBEntry getWorkflowDBEntry(ResultSet rs) throws SQLException, JsonParseException, JsonMappingException, IOException {
-    WorkflowDBEntry w = new WorkflowDBEntry();
-    w.setWorkflowId(WorkflowFields.WORKFLOWID.getString(rs));
-    w.setWorkflowName(WorkflowFields.WORKFLOWNAME.getString(rs));
-    w.setUserName(WorkflowFields.USERNAME.getString(rs));
-    w.setStartTime(WorkflowFields.STARTTIME.getLong(rs));
-    w.setElapsedTime(WorkflowFields.DURATION.getLong(rs));
-    w.setNumJobsTotal(WorkflowFields.NUMJOBSTOTAL.getInt(rs));
-    w.setInputBytes(WorkflowFields.INPUTBYTES.getLong(rs));
-    w.setOutputBytes(WorkflowFields.OUTPUTBYTES.getLong(rs));
-    w.setNumJobsCompleted(WorkflowFields.NUMJOBSCOMPLETED.getInt(rs));
-    w.setWorkflowContext(jsonMapper.readValue(WorkflowFields.WORKFLOWCONTEXT.getString(rs), WorkflowContext.class));
-    return w;
-  }
-  
-  private static AvgData getAvgData(ResultSet rs, SummaryFields avg, SummaryFields min, SummaryFields max) throws SQLException {
-    AvgData avgData = new AvgData();
-    avgData.setAvg(avg.getDouble(rs));
-    avgData.setMin(min.getLong(rs));
-    avgData.setMax(max.getLong(rs));
-    return avgData;
-  }
-  
-  @Override
-  public DataTable fetchWorkflows(int offset, int limit, String searchTerm, int echo, WorkflowFields col, boolean sortAscending, String searchWorkflowId,
-      String searchWorkflowName, String searchWorkflowType, String searchUserName, int minJobs, int maxJobs, long minInputBytes, long maxInputBytes,
-      long minOutputBytes, long maxOutputBytes, long minDuration, long maxDuration, long minStartTime, long maxStartTime, long minFinishTime, long maxFinishTime)
-      throws IOException {
-    int total = 0;
-    PreparedStatement ps = getPS(Statements.FW_COUNT_PS);
-    ResultSet rs = null;
-    try {
-      rs = ps.executeQuery();
-      if (rs.next())
-        total = SummaryFields.numRows.getInt(rs);
-    } catch (SQLException e) {
-      throw new IOException(e);
-    } finally {
-      try {
-        if (rs != null)
-          rs.close();
-      } catch (SQLException e) {
-        LOG.error("Exception while closing ResultSet", e);
-      }
-    }
-    
-    String searchClause = buildSearchClause(searchTerm, searchWorkflowId, searchWorkflowName, searchWorkflowType, searchUserName, minJobs, maxJobs,
-        minInputBytes, maxInputBytes, minOutputBytes, maxOutputBytes, minDuration, maxDuration, minStartTime, maxStartTime, minFinishTime, maxFinishTime);
-    List<WorkflowDBEntry> workflows = fetchWorkflows(getQualifiedPS(Statements.FW_PS, searchClause, col, sortAscending, offset, limit));
-    Summary summary = fetchSummary(getQualifiedPS(Statements.FW_SUMMARY_PS, searchClause));
-    DataTable table = new DataTable();
-    table.setiTotalRecords(total);
-    table.setiTotalDisplayRecords(summary.getNumRows());
-    if (workflows.isEmpty()) {
-      table.setStartIndex(-1);
-      table.setEndIndex(-1);
-    } else {
-      table.setStartIndex(offset);
-      table.setEndIndex(offset + workflows.size() - 1);
-    }
-    table.setAaData(workflows);
-    table.setsEcho(echo);
-    table.setSummary(summary);
-    return table;
-  }
-  
-  private static JobDBEntry getJobDBEntry(ResultSet rs) throws SQLException {
-    JobDBEntry j = new JobDBEntry();
-    j.setConfPath(JobFields.CONFPATH.getString(rs));
-    j.setSubmitTime(JobFields.SUBMITTIME.getLong(rs));
-    long finishTime = JobFields.FINISHTIME.getLong(rs);
-    if (finishTime > j.getSubmitTime())
-      j.setElapsedTime(finishTime - j.getSubmitTime());
-    else
-      j.setElapsedTime(0);
-    j.setInputBytes(JobFields.INPUTBYTES.getLong(rs));
-    j.setJobId(JobFields.JOBID.getString(rs));
-    j.setJobName(JobFields.JOBNAME.getString(rs));
-    j.setMaps(JobFields.MAPS.getInt(rs));
-    j.setOutputBytes(JobFields.OUTPUTBYTES.getLong(rs));
-    j.setReduces(JobFields.REDUCES.getInt(rs));
-    j.setStatus(JobFields.STATUS.getString(rs));
-    j.setUserName(JobFields.USERNAME.getString(rs));
-    j.setWorkflowEntityName(JobFields.WORKFLOWENTITYNAME.getString(rs));
-    j.setWorkflowId(JobFields.WORKFLOWID.getString(rs));
-    return j;
-  }
-  
-  @Override
-  public List<JobDBEntry> fetchJobDetails(String workflowId) throws IOException {
-    PreparedStatement ps = getPS(Statements.FJD_PS);
-    List<JobDBEntry> jobs = new ArrayList<JobDBEntry>();
-    ResultSet rs = null;
-    try {
-      ps.setString(1, workflowId);
-      rs = ps.executeQuery();
-      while (rs.next()) {
-        jobs.add(getJobDBEntry(rs));
-      }
-      rs.close();
-    } catch (SQLException e) {
-      throw new IOException(e);
-    } finally {
-      if (rs != null)
-        try {
-          rs.close();
-        } catch (SQLException e) {
-          LOG.error("Exception while closing ResultSet", e);
-        }
-      
-    }
-    return jobs;
-  }
-  
-  @Override
-  public List<JobDBEntry> fetchJobDetails(long minFinishTime, long maxStartTime) throws IOException {
-    PreparedStatement ps = getPS(Statements.FJD_TIMERANGE_PS);
-    List<JobDBEntry> jobs = new ArrayList<JobDBEntry>();
-    ResultSet rs = null;
-    try {
-      ps.setLong(1, minFinishTime);
-      ps.setLong(2, maxStartTime);
-      rs = ps.executeQuery();
-      while (rs.next()) {
-        jobs.add(getJobDBEntry(rs));
-      }
-      rs.close();
-    } catch (SQLException e) {
-      throw new IOException(e);
-    } finally {
-      if (rs != null)
-        try {
-          rs.close();
-        } catch (SQLException e) {
-          LOG.error("Exception while closing ResultSet", e);
-        }
-      
-    }
-    return jobs;
-  }
-  
-  @Override
-  public long[] fetchJobStartStopTimes(String jobID) throws IOException {
-    PreparedStatement ps = getPS(Statements.FJSS_PS);
-    long[] times = new long[2];
-    ResultSet rs = null;
-    try {
-      ps.setString(1, jobID);
-      rs = ps.executeQuery();
-      if (!rs.next())
-        return null;
-      times[0] = JobFields.SUBMITTIME.getLong(rs);
-      times[1] = JobFields.FINISHTIME.getLong(rs);
-      rs.close();
-    } catch (SQLException e) {
-      throw new IOException(e);
-    } finally {
-      if (rs != null)
-        try {
-          rs.close();
-        } catch (SQLException e) {
-          LOG.error("Exception while closing ResultSet", e);
-        }
-    }
-    if (times[1] == 0)
-      times[1] = System.currentTimeMillis();
-    if (times[1] < times[0])
-      times[1] = times[0];
-    return times;
-  }
-  
-  private static TaskAttempt getTaskAttempt(ResultSet rs) throws SQLException {
-    TaskAttempt t = new TaskAttempt();
-    t.setFinishTime(TaskAttemptFields.FINISHTIME.getLong(rs));
-    t.setInputBytes(TaskAttemptFields.INPUTBYTES.getLong(rs));
-    t.setJobId(TaskAttemptFields.JOBID.getString(rs));
-    t.setLocality(TaskAttemptFields.LOCALITY.getString(rs));
-    t.setMapFinishTime(TaskAttemptFields.MAPFINISHTIME.getLong(rs));
-    t.setOutputBytes(TaskAttemptFields.OUTPUTBYTES.getLong(rs));
-    t.setShuffleFinishTime(TaskAttemptFields.SHUFFLEFINISHTIME.getLong(rs));
-    t.setSortFinishTime(TaskAttemptFields.SORTFINISHTIME.getLong(rs));
-    t.setStartTime(TaskAttemptFields.STARTTIME.getLong(rs));
-    t.setStatus(TaskAttemptFields.STATUS.getString(rs));
-    t.setTaskAttemptId(TaskAttemptFields.TASKATTEMPTID.getString(rs));
-    t.setTaskType(TaskAttemptFields.TASKTYPE.getString(rs));
-    return t;
-  }
-  
-  @Override
-  public List<TaskAttempt> fetchTaskAttempts(long minFinishTime, long maxStartTime) throws IOException {
-    PreparedStatement ps = getPS(Statements.FTA_TIMERANGE_PS);
-    List<TaskAttempt> taskAttempts = new ArrayList<TaskAttempt>();
-    ResultSet rs = null;
-    try {
-      ps.setLong(1, minFinishTime);
-      ps.setLong(2, maxStartTime);
-      rs = ps.executeQuery();
-      while (rs.next()) {
-        taskAttempts.add(getTaskAttempt(rs));
-      }
-      rs.close();
-    } catch (SQLException e) {
-      throw new IOException(e);
-    } finally {
-      if (rs != null)
-        try {
-          rs.close();
-        } catch (SQLException e) {
-          LOG.error("Exception while closing ResultSet", e);
-        }
-    }
-    return taskAttempts;
-  }
-  
-  @Override
-  public List<TaskAttempt> fetchJobTaskAttempts(String jobID) throws IOException {
-    PreparedStatement ps = getPS(Statements.FJTA_PS);
-    List<TaskAttempt> taskAttempts = new ArrayList<TaskAttempt>();
-    ResultSet rs = null;
-    try {
-      ps.setString(1, jobID);
-      rs = ps.executeQuery();
-      while (rs.next()) {
-        taskAttempts.add(getTaskAttempt(rs));
-      }
-      rs.close();
-    } catch (SQLException e) {
-      throw new IOException(e);
-    } finally {
-      if (rs != null)
-        try {
-          rs.close();
-        } catch (SQLException e) {
-          LOG.error("Exception while closing ResultSet", e);
-        }
-    }
-    return taskAttempts;
-  }
-  
-  @Override
-  public List<TaskAttempt> fetchWorkflowTaskAttempts(String workflowId) throws IOException {
-    PreparedStatement ps = getPS(Statements.FWTA_PS);
-    List<TaskAttempt> taskAttempts = new ArrayList<TaskAttempt>();
-    ResultSet rs = null;
-    try {
-      ps.setString(1, workflowId);
-      rs = ps.executeQuery();
-      while (rs.next()) {
-        taskAttempts.add(getTaskAttempt(rs));
-      }
-      rs.close();
-    } catch (SQLException e) {
-      throw new IOException(e);
-    } finally {
-      if (rs != null)
-        try {
-          rs.close();
-        } catch (SQLException e) {
-          LOG.error("Exception while closing ResultSet", e);
-        }
-    }
-    return taskAttempts;
-  }
-  
-  private PreparedStatement getPS(Statements statement) throws IOException {
-    if (db == null)
-      throw new IOException("postgres db not initialized");
-    
-    synchronized (preparedStatements) {
-      if (!preparedStatements.containsKey(statement)) {
-        try {
-          // LOG.debug("preparing " + statement.getStatementString());
-          preparedStatements.put(statement, db.prepareStatement(statement.getStatementString()));
-        } catch (SQLException e) {
-          throw new IOException(e);
-        }
-      }
-    }
-    
-    return preparedStatements.get(statement);
-  }
-  
-  protected PreparedStatement getQualifiedPS(Statements statement, String searchClause) throws IOException {
-    if (db == null)
-      throw new IOException("postgres db not initialized");
-    try {
-      // LOG.debug("preparing " + statement.getStatementString() + searchClause);
-      return db.prepareStatement(statement.getStatementString() + searchClause);
-    } catch (SQLException e) {
-      throw new IOException(e);
-    }
-  }
-  
-  protected PreparedStatement getQualifiedPS(Statements statement, String searchClause, WorkflowFields field, boolean sortAscending, int offset, int limit)
-      throws IOException {
-    if (db == null)
-      throw new IOException("postgres db not initialized");
-    String limitClause = " ORDER BY " + field.toString() + " " + (sortAscending ? SORT_ASC : SORT_DESC) + " OFFSET " + offset
-        + (limit >= 0 ? " LIMIT " + limit : "");
-    return getQualifiedPS(statement, searchClause + limitClause);
-  }
-  
-  private static void addRangeSearch(StringBuilder sb, WorkflowFields field, int min, int max) {
-    if (min >= 0)
-      append(sb, greaterThan(field, Integer.toString(min)));
-    if (max >= 0)
-      append(sb, lessThan(field, Integer.toString(max)));
-  }
-  
-  private static void addRangeSearch(StringBuilder sb, WorkflowFields field, long min, long max) {
-    if (min >= 0)
-      append(sb, greaterThan(field, Long.toString(min)));
-    if (max >= 0)
-      append(sb, lessThan(field, Long.toString(max)));
-  }
-  
-  private static void append(StringBuilder sb, String s) {
-    if (sb.length() > WHERE.length())
-      sb.append(" and ");
-    sb.append(s);
-  }
-  
-  private static String like(WorkflowFields field, String s) {
-    return field.toString() + " like '%" + s + "%'";
-  }
-  
-  private static String startsWith(WorkflowFields field, String s) {
-    return field.toString() + " like '" + s + "%'";
-  }
-  
-  private static String equals(WorkflowFields field, String s) {
-    return field.toString() + " = '" + s + "'";
-  }
-  
-  private static String lessThan(WorkflowFields field, String s) {
-    return field.toString() + " <= " + s;
-  }
-  
-  private static String greaterThan(WorkflowFields field, String s) {
-    return field.toString() + " >= " + s;
-  }
-  
-  private static final String WHERE = " where ";
-  
-  private static String buildSearchClause(String searchTerm, String searchWorkflowId, String searchWorkflowName, String searchWorkflowType,
-      String searchUserName, int minJobs, int maxJobs, long minInputBytes, long maxInputBytes, long minOutputBytes, long maxOutputBytes, long minDuration,
-      long maxDuration, long minStartTime, long maxStartTime, long minFinishTime, long maxFinishTime) {
-    StringBuilder sb = new StringBuilder();
-    sb.append(WHERE);
-    if (searchTerm != null && searchTerm.length() > 0) {
-      sb.append("(");
-      sb.append(like(WorkflowFields.WORKFLOWID, searchTerm));
-      sb.append(" or ");
-      sb.append(like(WorkflowFields.WORKFLOWNAME, searchTerm));
-      sb.append(" or ");
-      sb.append(like(WorkflowFields.USERNAME, searchTerm));
-      sb.append(")");
-    }
-    if (searchWorkflowId != null)
-      append(sb, like(WorkflowFields.WORKFLOWID, searchWorkflowId));
-    if (searchWorkflowName != null)
-      append(sb, like(WorkflowFields.WORKFLOWNAME, searchWorkflowName));
-    if (searchWorkflowType != null)
-      append(sb, startsWith(WorkflowFields.WORKFLOWID, searchWorkflowType));
-    if (searchUserName != null)
-      append(sb, equals(WorkflowFields.USERNAME, searchUserName));
-    addRangeSearch(sb, WorkflowFields.NUMJOBSTOTAL, minJobs, maxJobs);
-    addRangeSearch(sb, WorkflowFields.INPUTBYTES, minInputBytes, maxInputBytes);
-    addRangeSearch(sb, WorkflowFields.OUTPUTBYTES, minOutputBytes, maxOutputBytes);
-    addRangeSearch(sb, WorkflowFields.DURATION, minDuration, maxDuration);
-    addRangeSearch(sb, WorkflowFields.STARTTIME, minStartTime, maxStartTime);
-    addRangeSearch(sb, WorkflowFields.LASTUPDATETIME, minFinishTime, maxFinishTime);
-    
-    if (sb.length() == WHERE.length())
-      return "";
-    else
-      return sb.toString();
-  }
-  
-  @Override
-  public void close() {
-    if (db != null) {
-      try {
-        db.close();
-      } catch (SQLException e) {
-        LOG.error("Exception while closing connector", e);
-      }
-      db = null;
-    }
-  }
-  
-  @Override
-  protected void finalize() throws Throwable {
-    close();
-  }
-}

+ 0 - 242
ambari-server/src/main/java/org/apache/ambari/eventdb/model/DataTable.java

@@ -1,242 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.eventdb.model;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.apache.ambari.eventdb.model.Workflows.WorkflowDBEntry;
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.FIELD)
-public class DataTable {
-  int sEcho;
-  int iTotalRecords;
-  int iTotalDisplayRecords;
-  int startIndex;
-  int endIndex;
-  List<WorkflowDBEntry> aaData;
-  Summary summary;
-  
-  @XmlRootElement
-  @XmlAccessorType(XmlAccessType.FIELD)
-  public static class Summary {
-    public static enum SummaryFields {
-      numRows,
-      avgJobs,
-      minJobs,
-      maxJobs,
-      avgInput,
-      minInput,
-      maxInput,
-      avgOutput,
-      minOutput,
-      maxOutput,
-      avgDuration,
-      minDuration,
-      maxDuration,
-      youngest,
-      oldest;
-      
-      public int getInt(ResultSet rs) throws SQLException {
-        return rs.getInt(this.toString());
-      }
-      
-      public long getLong(ResultSet rs) throws SQLException {
-        return rs.getLong(this.toString());
-      }
-      
-      public double getDouble(ResultSet rs) throws SQLException {
-        return rs.getDouble(this.toString());
-      }
-    }
-    
-    int numRows;
-    AvgData jobs;
-    AvgData input;
-    AvgData output;
-    AvgData duration;
-    Times times;
-    
-    public int getNumRows() {
-      return numRows;
-    }
-    
-    public void setNumRows(int numRows) {
-      this.numRows = numRows;
-    }
-    
-    public AvgData getJobs() {
-      return jobs;
-    }
-    
-    public void setJobs(AvgData jobs) {
-      this.jobs = jobs;
-    }
-    
-    public AvgData getInput() {
-      return input;
-    }
-    
-    public void setInput(AvgData input) {
-      this.input = input;
-    }
-    
-    public AvgData getOutput() {
-      return output;
-    }
-    
-    public void setOutput(AvgData output) {
-      this.output = output;
-    }
-    
-    public AvgData getDuration() {
-      return duration;
-    }
-    
-    public void setDuration(AvgData duration) {
-      this.duration = duration;
-    }
-    
-    public Times getTimes() {
-      return times;
-    }
-    
-    public void setTimes(Times times) {
-      this.times = times;
-    }
-  }
-  
-  @XmlRootElement
-  @XmlAccessorType(XmlAccessType.FIELD)
-  public static class AvgData {
-    double avg;
-    long min;
-    long max;
-    
-    public double getAvg() {
-      return avg;
-    }
-    
-    public void setAvg(double avg) {
-      this.avg = avg;
-    }
-    
-    public long getMin() {
-      return min;
-    }
-    
-    public void setMin(long min) {
-      this.min = min;
-    }
-    
-    public long getMax() {
-      return max;
-    }
-    
-    public void setMax(long max) {
-      this.max = max;
-    }
-  }
-  
-  @XmlRootElement
-  @XmlAccessorType(XmlAccessType.FIELD)
-  public static class Times {
-    long oldest;
-    long youngest;
-    
-    public long getOldest() {
-      return oldest;
-    }
-    
-    public void setOldest(long oldest) {
-      this.oldest = oldest;
-    }
-    
-    public long getYoungest() {
-      return youngest;
-    }
-    
-    public void setYoungest(long youngest) {
-      this.youngest = youngest;
-    }
-  }
-  
-  public DataTable() {}
-  
-  public int getsEcho() {
-    return sEcho;
-  }
-  
-  public void setsEcho(int sEcho) {
-    this.sEcho = sEcho;
-  }
-  
-  public int getiTotalRecords() {
-    return iTotalRecords;
-  }
-  
-  public void setiTotalRecords(int iTotalRecords) {
-    this.iTotalRecords = iTotalRecords;
-  }
-  
-  public int getiTotalDisplayRecords() {
-    return iTotalDisplayRecords;
-  }
-  
-  public void setiTotalDisplayRecords(int iTotalDisplayRecords) {
-    this.iTotalDisplayRecords = iTotalDisplayRecords;
-  }
-  
-  public int getStartIndex() {
-    return startIndex;
-  }
-  
-  public void setStartIndex(int startIndex) {
-    this.startIndex = startIndex;
-  }
-  
-  public int getEndIndex() {
-    return endIndex;
-  }
-  
-  public void setEndIndex(int endIndex) {
-    this.endIndex = endIndex;
-  }
-  
-  public List<WorkflowDBEntry> getAaData() {
-    return aaData;
-  }
-  
-  public void setAaData(List<WorkflowDBEntry> aaData) {
-    this.aaData = aaData;
-  }
-  
-  public Summary getSummary() {
-    return summary;
-  }
-  
-  public void setSummary(Summary summary) {
-    this.summary = summary;
-  }
-}

+ 0 - 215
ambari-server/src/main/java/org/apache/ambari/eventdb/model/Jobs.java

@@ -1,215 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.eventdb.model;
-
-import org.apache.commons.lang.StringUtils;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.FIELD)
-public class Jobs {
-  int numJobs;
-  List<JobDBEntry> jobs;
-  
-  public static class JobDBEntry {
-    public static enum JobFields {
-      JOBID,
-      JOBNAME,
-      STATUS,
-      USERNAME,
-      SUBMITTIME,
-      FINISHTIME,
-      MAPS,
-      REDUCES,
-      INPUTBYTES,
-      OUTPUTBYTES,
-      CONFPATH,
-      WORKFLOWID,
-      WORKFLOWENTITYNAME;
-      
-      public String getString(ResultSet rs) throws SQLException {
-        return rs.getString(this.toString());
-      }
-      
-      public int getInt(ResultSet rs) throws SQLException {
-        return rs.getInt(this.toString());
-      }
-      
-      public long getLong(ResultSet rs) throws SQLException {
-        return rs.getLong(this.toString());
-      }
-      
-      public static String join() {
-        String[] tmp = new String[JobFields.values().length];
-        for (int i = 0; i < tmp.length; i++)
-          tmp[i] = JobFields.values()[i].toString();
-        return StringUtils.join(tmp, ",");
-      }
-    }
-    
-    @XmlTransient
-    public static final String JOB_FIELDS = JobFields.join();
-    
-    private String jobId;
-    private String jobName;
-    private String status;
-    private String userName;
-    private long submitTime;
-    private long elapsedTime;
-    private int maps;
-    private int reduces;
-    private long inputBytes;
-    private long outputBytes;
-    private String confPath;
-    private String workflowId;
-    private String workflowEntityName;
-    
-    public JobDBEntry() {
-      /* Required by JAXB. */
-    }
-    
-    public String getJobId() {
-      return jobId;
-    }
-    
-    public String getJobName() {
-      return jobName;
-    }
-    
-    public String getStatus() {
-      return status;
-    }
-    
-    public String getUserName() {
-      return userName;
-    }
-    
-    public long getSubmitTime() {
-      return submitTime;
-    }
-    
-    public long getElapsedTime() {
-      return elapsedTime;
-    }
-    
-    public int getMaps() {
-      return maps;
-    }
-    
-    public int getReduces() {
-      return reduces;
-    }
-    
-    public long getInputBytes() {
-      return inputBytes;
-    }
-    
-    public long getOutputBytes() {
-      return outputBytes;
-    }
-    
-    public String getConfPath() {
-      return confPath;
-    }
-    
-    public String getWorkflowId() {
-      return workflowId;
-    }
-    
-    public String getWorkflowEntityName() {
-      return workflowEntityName;
-    }
-    
-    public void setJobId(String jobId) {
-      this.jobId = jobId;
-    }
-    
-    public void setJobName(String jobName) {
-      this.jobName = jobName;
-    }
-    
-    public void setStatus(String status) {
-      this.status = status;
-    }
-    
-    public void setUserName(String userName) {
-      this.userName = userName;
-    }
-    
-    public void setSubmitTime(long submitTime) {
-      this.submitTime = submitTime;
-    }
-    
-    public void setElapsedTime(long elapsedTime) {
-      this.elapsedTime = elapsedTime;
-    }
-    
-    public void setMaps(int maps) {
-      this.maps = maps;
-    }
-    
-    public void setReduces(int reduces) {
-      this.reduces = reduces;
-    }
-    
-    public void setInputBytes(long inputBytes) {
-      this.inputBytes = inputBytes;
-    }
-    
-    public void setOutputBytes(long outputBytes) {
-      this.outputBytes = outputBytes;
-    }
-    
-    public void setConfPath(String confPath) {
-      this.confPath = confPath;
-    }
-    
-    public void setWorkflowId(String workflowId) {
-      this.workflowId = workflowId;
-    }
-    
-    public void setWorkflowEntityName(String workflowEntityName) {
-      this.workflowEntityName = workflowEntityName;
-    }
-  }
-  
-  public Jobs() {}
-  
-  public int getNumJobs() {
-    return numJobs;
-  }
-  
-  public void setNumJobs(int numJobs) {
-    this.numJobs = numJobs;
-  }
-  
-  public List<JobDBEntry> getJobs() {
-    return jobs;
-  }
-  
-  public void setJobs(List<JobDBEntry> jobs) {
-    this.jobs = jobs;
-    this.numJobs = jobs.size();
-  }
-}

+ 0 - 181
ambari-server/src/main/java/org/apache/ambari/eventdb/model/TaskAttempt.java

@@ -1,181 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.eventdb.model;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import org.apache.commons.lang.StringUtils;
-
-/**
- * 
- */
-public class TaskAttempt {
-  public static enum TaskAttemptFields {
-    JOBID,
-    TASKATTEMPTID,
-    TASKTYPE,
-    STARTTIME,
-    FINISHTIME,
-    MAPFINISHTIME,
-    SHUFFLEFINISHTIME,
-    SORTFINISHTIME,
-    INPUTBYTES,
-    OUTPUTBYTES,
-    STATUS,
-    LOCALITY;
-    
-    public String getString(ResultSet rs) throws SQLException {
-      return rs.getString(this.toString());
-    }
-    
-    public int getInt(ResultSet rs) throws SQLException {
-      return rs.getInt(this.toString());
-    }
-    
-    public long getLong(ResultSet rs) throws SQLException {
-      return rs.getLong(this.toString());
-    }
-    
-    public static String join() {
-      String[] tmp = new String[TaskAttemptFields.values().length];
-      for (int i = 0; i < tmp.length; i++)
-        tmp[i] = TaskAttemptFields.values()[i].toString();
-      return StringUtils.join(tmp, ",");
-    }
-
-    public static String join(String tableName) {
-      String[] tmp = new String[TaskAttemptFields.values().length];
-      for (int i = 0; i < tmp.length; i++)
-        tmp[i] = tableName + "." + TaskAttemptFields.values()[i].toString();
-      return StringUtils.join(tmp, ",");
-    }
-  }
-  
-  public static final String TASK_ATTEMPT_FIELDS = TaskAttemptFields.join();
-  
-  private String jobId;
-  private String taskAttemptId;
-  private String taskType;
-  private long startTime;
-  private long finishTime;
-  private long mapFinishTime;
-  private long shuffleFinishTime;
-  private long sortFinishTime;
-  private long inputBytes;
-  private long outputBytes;
-  private String status;
-  private String locality;
-  
-  public TaskAttempt() {}
-  
-  public String getJobId() {
-    return jobId;
-  }
-  
-  public void setJobId(String jobId) {
-    this.jobId = jobId;
-  }
-  
-  public String getTaskAttemptId() {
-    return taskAttemptId;
-  }
-  
-  public void setTaskAttemptId(String taskAttemptId) {
-    this.taskAttemptId = taskAttemptId;
-  }
-  
-  public String getTaskType() {
-    return taskType;
-  }
-  
-  public void setTaskType(String taskType) {
-    this.taskType = taskType;
-  }
-  
-  public long getStartTime() {
-    return startTime;
-  }
-  
-  public void setStartTime(long startTime) {
-    this.startTime = startTime;
-  }
-  
-  public long getFinishTime() {
-    return finishTime;
-  }
-  
-  public void setFinishTime(long finishTime) {
-    this.finishTime = finishTime;
-  }
-  
-  public long getMapFinishTime() {
-    return mapFinishTime;
-  }
-  
-  public void setMapFinishTime(long mapFinishTime) {
-    this.mapFinishTime = mapFinishTime;
-  }
-  
-  public long getShuffleFinishTime() {
-    return shuffleFinishTime;
-  }
-  
-  public void setShuffleFinishTime(long shuffleFinishTime) {
-    this.shuffleFinishTime = shuffleFinishTime;
-  }
-  
-  public long getSortFinishTime() {
-    return sortFinishTime;
-  }
-  
-  public void setSortFinishTime(long sortFinishTime) {
-    this.sortFinishTime = sortFinishTime;
-  }
-  
-  public long getInputBytes() {
-    return inputBytes;
-  }
-  
-  public long getOutputBytes() {
-    return outputBytes;
-  }
-  
-  public void setInputBytes(long inputBytes) {
-    this.inputBytes = inputBytes;
-  }
-  
-  public void setOutputBytes(long outputBytes) {
-    this.outputBytes = outputBytes;
-  }
-  
-  public String getStatus() {
-    return status;
-  }
-  
-  public void setStatus(String status) {
-    this.status = status;
-  }
-  
-  public String getLocality() {
-    return locality;
-  }
-  
-  public void setLocality(String locality) {
-    this.locality = locality;
-  }
-}

+ 0 - 85
ambari-server/src/main/java/org/apache/ambari/eventdb/model/TaskData.java

@@ -1,85 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.eventdb.model;
-
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.FIELD)
-public class TaskData {
-  private List<Point> map;
-  private List<Point> shuffle;
-  private List<Point> reduce;
-  
-  public static class Point {
-    private long x;
-    private int y;
-    
-    public Point() {}
-    
-    public Point(long x, int y) {
-      this.x = x;
-      this.y = y;
-    }
-    
-    public long getX() {
-      return x;
-    }
-    
-    public int getY() {
-      return y;
-    }
-    
-    public void setX(long x) {
-      this.x = x;
-    }
-    
-    public void setY(int y) {
-      this.y = y;
-    }
-  }
-  
-  public TaskData() {}
-  
-  public List<Point> getMapData() {
-    return map;
-  }
-  
-  public void setMapData(List<Point> mapData) {
-    this.map = mapData;
-  }
-  
-  public List<Point> getShuffleData() {
-    return shuffle;
-  }
-  
-  public void setShuffleData(List<Point> shuffleData) {
-    this.shuffle = shuffleData;
-  }
-  
-  public List<Point> getReduceData() {
-    return reduce;
-  }
-  
-  public void setReduceData(List<Point> reduceData) {
-    this.reduce = reduceData;
-  }
-}

+ 0 - 156
ambari-server/src/main/java/org/apache/ambari/eventdb/model/TaskLocalityData.java

@@ -1,156 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.eventdb.model;
-
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.FIELD)
-public class TaskLocalityData {
-  private List<DataPoint> mapNodeLocal;
-  private List<DataPoint> mapRackLocal;
-  private List<DataPoint> mapOffSwitch;
-  private List<DataPoint> reduceOffSwitch;
-  private long submitTime;
-  private long finishTime;
-  
-  public static class DataPoint {
-    private long x;
-    private long y;
-    private long r;
-    private long io;
-    private String label;
-    private String status;
-    
-    public DataPoint() {}
-    
-    public DataPoint(long x) {
-      this(x, 0, 0, 0, null, null);
-    }
-    
-    public DataPoint(long x, long y, long r, long io, String taskAttemptId, String status) {
-      this.x = x;
-      this.y = y;
-      this.r = r;
-      this.io = io;
-      this.label = taskAttemptId;
-      this.status = status;
-    }
-    
-    public long getX() {
-      return x;
-    }
-    
-    public long getY() {
-      return y;
-    }
-    
-    public long getR() {
-      return r;
-    }
-    
-    public long getIO() {
-      return io;
-    }
-    
-    public String getLabel() {
-      return label;
-    }
-    
-    public String getStatus() {
-      return status;
-    }
-    
-    public void setX(long x) {
-      this.x = x;
-    }
-    
-    public void setY(long y) {
-      this.y = y;
-    }
-    
-    public void setR(long r) {
-      this.r = r;
-    }
-    
-    public void setIO(long io) {
-      this.io = io;
-    }
-    
-    public void setLabel(String label) {
-      this.label = label;
-    }
-    
-    public void setStatus(String status) {
-      this.status = status;
-    }
-  }
-  
-  public TaskLocalityData() {}
-  
-  public List<DataPoint> getMapNodeLocal() {
-    return mapNodeLocal;
-  }
-  
-  public void setMapNodeLocal(List<DataPoint> mapNodeLocal) {
-    this.mapNodeLocal = mapNodeLocal;
-  }
-  
-  public List<DataPoint> getMapRackLocal() {
-    return mapRackLocal;
-  }
-  
-  public void setMapRackLocal(List<DataPoint> mapRackLocal) {
-    this.mapRackLocal = mapRackLocal;
-  }
-  
-  public List<DataPoint> getMapOffSwitch() {
-    return mapOffSwitch;
-  }
-  
-  public void setMapOffSwitch(List<DataPoint> mapOffSwitch) {
-    this.mapOffSwitch = mapOffSwitch;
-  }
-  
-  public List<DataPoint> getReduceOffSwitch() {
-    return reduceOffSwitch;
-  }
-  
-  public void setReduceOffSwitch(List<DataPoint> reduceOffSwitch) {
-    this.reduceOffSwitch = reduceOffSwitch;
-  }
-  
-  public long getSubmitTime() {
-    return submitTime;
-  }
-  
-  public void setSubmitTime(long submitTime) {
-    this.submitTime = submitTime;
-  }
-  
-  public long getFinishTime() {
-    return finishTime;
-  }
-  
-  public void setFinishTime(long finishTime) {
-    this.finishTime = finishTime;
-  }
-}

+ 0 - 82
ambari-server/src/main/java/org/apache/ambari/eventdb/model/WorkflowContext.java

@@ -1,82 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.eventdb.model;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.FIELD)
-public class WorkflowContext {
-  
-  private String workflowId;
-  private String workflowName;
-  private String workflowEntityName;
-  
-  private WorkflowDag workflowDag;
-  
-  private WorkflowContext parentWorkflowContext;
-  
-  public WorkflowContext() {
-    /* Required by JAXB. */
-  }
-  
-  /* Getters. */
-  public String getWorkflowId() {
-    return this.workflowId;
-  }
-  
-  public String getWorkflowName() {
-    return this.workflowName;
-  }
-  
-  public String getWorkflowEntityName() {
-    return this.workflowEntityName;
-  }
-  
-  public WorkflowDag getWorkflowDag() {
-    return this.workflowDag;
-  }
-  
-  public WorkflowContext getParentWorkflowContext() {
-    return this.parentWorkflowContext;
-  }
-  
-  /* Setters. */
-  public void setWorkflowId(String wfId) {
-    this.workflowId = wfId;
-  }
-  
-  public void setWorkflowName(String wfName) {
-    this.workflowName = wfName;
-  }
-  
-  public void setWorkflowEntityName(String wfEntityName) {
-    this.workflowEntityName = wfEntityName;
-  }
-  
-  public void setWorkflowDag(WorkflowDag wfDag) {
-    this.workflowDag = wfDag;
-  }
-  
-  public void setParentWorkflowContext(WorkflowContext pWfContext) {
-    this.parentWorkflowContext = pWfContext;
-  }
-}

+ 0 - 93
ambari-server/src/main/java/org/apache/ambari/eventdb/model/WorkflowDag.java

@@ -1,93 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.eventdb.model;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.FIELD)
-public class WorkflowDag {
-  
-  public static class WorkflowDagEntry {
-    
-    private String source;
-    private List<String> targets = new ArrayList<String>();
-    
-    public WorkflowDagEntry() {
-      /* Required by JAXB. */
-    }
-    
-    /* Getters. */
-    public String getSource() {
-      return this.source;
-    }
-    
-    public List<String> getTargets() {
-      return this.targets;
-    }
-    
-    /* Setters. */
-    public void setSource(String source) {
-      this.source = source;
-    }
-    
-    public void setTargets(List<String> targets) {
-      this.targets = targets;
-    }
-    
-    public void addTarget(String target) {
-      this.targets.add(target);
-    }
-  }
-  
-  List<WorkflowDagEntry> entries = new ArrayList<WorkflowDagEntry>();
-  
-  public WorkflowDag() {
-    /* Required by JAXB. */
-  }
-  
-  /* Getters. */
-  public List<WorkflowDagEntry> getEntries() {
-    return this.entries;
-  }
-  
-  /* Setters. */
-  public void setEntries(List<WorkflowDagEntry> entries) {
-    this.entries = entries;
-  }
-  
-  public void addEntry(WorkflowDag.WorkflowDagEntry entry) {
-    this.entries.add(entry);
-  }
-  
-  public int size() {
-    Set<String> nodes = new HashSet<String>();
-    for (WorkflowDagEntry entry : entries) {
-      nodes.add(entry.getSource());
-      nodes.addAll(entry.getTargets());
-    }
-    return nodes.size();
-  }
-}

+ 0 - 197
ambari-server/src/main/java/org/apache/ambari/eventdb/model/Workflows.java

@@ -1,197 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.eventdb.model;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-
-import org.apache.ambari.eventdb.model.DataTable.Summary;
-import org.apache.commons.lang.StringUtils;
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.FIELD)
-public class Workflows {
-  List<WorkflowDBEntry> workflows;
-  Summary summary;
-  
-  public static class WorkflowDBEntry {
-    public static enum WorkflowFields {
-      WORKFLOWID,
-      WORKFLOWNAME,
-      USERNAME,
-      STARTTIME,
-      LASTUPDATETIME,
-      DURATION,
-      NUMJOBSTOTAL,
-      NUMJOBSCOMPLETED,
-      INPUTBYTES,
-      OUTPUTBYTES,
-      PARENTWORKFLOWID,
-      WORKFLOWCONTEXT;
-      
-      public String getString(ResultSet rs) throws SQLException {
-        return rs.getString(this.toString());
-      }
-      
-      public int getInt(ResultSet rs) throws SQLException {
-        return rs.getInt(this.toString());
-      }
-      
-      public long getLong(ResultSet rs) throws SQLException {
-        return rs.getLong(this.toString());
-      }
-      
-      public static String join() {
-        String[] tmp = new String[WorkflowFields.values().length];
-        for (int i = 0; i < tmp.length; i++)
-          tmp[i] = WorkflowFields.values()[i].toString();
-        return StringUtils.join(tmp, ",");
-      }
-    }
-    
-    @XmlTransient
-    public static final String WORKFLOW_FIELDS = WorkflowFields.join();
-    
-    private String workflowId;
-    private String workflowName;
-    private String userName;
-    private long startTime;
-    private long elapsedTime;
-    private long inputBytes;
-    private long outputBytes;
-    private int numJobsTotal;
-    private int numJobsCompleted;
-    private String parentWorkflowId;
-    private WorkflowContext workflowContext;
-    
-    public WorkflowDBEntry() {
-      /* Required by JAXB. */
-    }
-    
-    public String getWorkflowId() {
-      return workflowId;
-    }
-    
-    public String getWorkflowName() {
-      return workflowName;
-    }
-    
-    public String getUserName() {
-      return userName;
-    }
-    
-    public long getStartTime() {
-      return startTime;
-    }
-    
-    public long getElapsedTime() {
-      return elapsedTime;
-    }
-    
-    public int getNumJobsTotal() {
-      return numJobsTotal;
-    }
-    
-    public int getNumJobsCompleted() {
-      return numJobsCompleted;
-    }
-    
-    public String getParentWorkflowId() {
-      return parentWorkflowId;
-    }
-    
-    public WorkflowContext getWorkflowContext() {
-      return workflowContext;
-    }
-    
-    public void setWorkflowId(String workflowId) {
-      this.workflowId = workflowId;
-    }
-    
-    public void setWorkflowName(String workflowName) {
-      this.workflowName = workflowName;
-    }
-    
-    public void setUserName(String userName) {
-      this.userName = userName;
-    }
-    
-    public void setStartTime(long startTime) {
-      this.startTime = startTime;
-    }
-    
-    public void setElapsedTime(long elapsedTime) {
-      this.elapsedTime = elapsedTime;
-    }
-    
-    public void setNumJobsTotal(int numJobsTotal) {
-      this.numJobsTotal = numJobsTotal;
-    }
-    
-    public void setNumJobsCompleted(int numJobsCompleted) {
-      this.numJobsCompleted = numJobsCompleted;
-    }
-    
-    public void setParentWorkflowId(String parentWorkflowId) {
-      this.parentWorkflowId = parentWorkflowId;
-    }
-    
-    public void setWorkflowContext(WorkflowContext workflowContext) {
-      this.workflowContext = workflowContext;
-    }
-    
-    public long getInputBytes() {
-      return inputBytes;
-    }
-    
-    public void setInputBytes(long inputBytes) {
-      this.inputBytes = inputBytes;
-    }
-    
-    public long getOutputBytes() {
-      return outputBytes;
-    }
-    
-    public void setOutputBytes(long outputBytes) {
-      this.outputBytes = outputBytes;
-    }
-  }
-  
-  public Workflows() {}
-  
-  public List<WorkflowDBEntry> getWorkflows() {
-    return workflows;
-  }
-  
-  public void setWorkflows(List<WorkflowDBEntry> workflows) {
-    this.workflows = workflows;
-  }
-  
-  public Summary getSummary() {
-    return summary;
-  }
-  
-  public void setSummary(Summary summary) {
-    this.summary = summary;
-  }
-}

+ 0 - 39
ambari-server/src/main/java/org/apache/ambari/eventdb/webservice/JAXBContextResolver.java

@@ -1,39 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.eventdb.webservice;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.Provider;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-
-@Provider
-public class JAXBContextResolver extends JacksonJaxbJsonProvider {
-  public JAXBContextResolver() {
-    super();
-  }
-  
-  @Override
-  public ObjectMapper locateMapper(Class<?> type, MediaType mediaType) {
-    ObjectMapper mapper = super.locateMapper(type, mediaType);
-    mapper.setSerializationInclusion(Inclusion.NON_NULL);
-    return mapper;
-  }
-}

+ 0 - 497
ambari-server/src/main/java/org/apache/ambari/eventdb/webservice/WorkflowJsonService.java

@@ -1,497 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.eventdb.webservice;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.servlet.ServletContext;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.ambari.eventdb.db.MySQLConnector;
-import org.apache.ambari.eventdb.db.OracleConnector;
-import org.apache.ambari.eventdb.db.PostgresConnector;
-import org.apache.ambari.eventdb.model.DataTable;
-import org.apache.ambari.eventdb.model.Jobs;
-import org.apache.ambari.eventdb.model.Jobs.JobDBEntry;
-import org.apache.ambari.eventdb.model.TaskAttempt;
-import org.apache.ambari.eventdb.model.TaskData;
-import org.apache.ambari.eventdb.model.TaskData.Point;
-import org.apache.ambari.eventdb.model.TaskLocalityData;
-import org.apache.ambari.eventdb.model.TaskLocalityData.DataPoint;
-import org.apache.ambari.eventdb.model.Workflows;
-import org.apache.ambari.eventdb.model.Workflows.WorkflowDBEntry;
-import org.apache.ambari.eventdb.model.Workflows.WorkflowDBEntry.WorkflowFields;
-import org.apache.ambari.server.configuration.Configuration;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Path("/jobhistory")
-public class WorkflowJsonService {
-  private static final String PREFIX = "eventdb.";
-  private static final String HOSTNAME = PREFIX + "db.hostname";
-  private static final String DBNAME = PREFIX + "db.name";
-  private static final String USERNAME = PREFIX + "db.user";
-  private static final String PASSWORD = PREFIX + "db.password";
-  
-  private static String DEFAULT_DRIVER;
-  private static String DEFAULT_URL;
-  private static String DEFAULT_USERNAME = "mapred";
-  private static String DEFAULT_PASSWORD = "mapred";
-  
-  private static final Workflows EMPTY_WORKFLOWS = new Workflows();
-  private static final List<JobDBEntry> EMPTY_JOBS = Collections.emptyList();
-  {
-    List<WorkflowDBEntry> emptyWorkflows = Collections.emptyList();
-    EMPTY_WORKFLOWS.setWorkflows(emptyWorkflows);
-  }
-
-  private static final Logger LOG = LoggerFactory.getLogger(WorkflowJsonService.class);
-  
-  PostgresConnector getConnector() throws IOException {
-    //TODO fix temp hack
-    if (StringUtils.contains(DEFAULT_DRIVER, "oracle")) {
-      return new OracleConnector(DEFAULT_URL, DEFAULT_DRIVER, DEFAULT_USERNAME, DEFAULT_PASSWORD);
-    }else if (StringUtils.contains(DEFAULT_DRIVER, "mysql")) {
-      return new MySQLConnector(DEFAULT_URL, DEFAULT_DRIVER, DEFAULT_USERNAME, DEFAULT_PASSWORD);
-    } else {
-      return new PostgresConnector(DEFAULT_URL, DEFAULT_DRIVER, DEFAULT_USERNAME, DEFAULT_PASSWORD);
-    }
-  }
-
-  public static void setDBProperties(Configuration configuration) {
-    DEFAULT_DRIVER = configuration.getRcaDatabaseDriver();
-    DEFAULT_URL = configuration.getRcaDatabaseUrl();
-    if (DEFAULT_URL.contains(Configuration.HOSTNAME_MACRO)) {
-      DEFAULT_URL = DEFAULT_URL.replace(Configuration.HOSTNAME_MACRO, "localhost");
-    }
-    DEFAULT_USERNAME = configuration.getRcaDatabaseUser();
-    DEFAULT_PASSWORD = configuration.getRcaDatabasePassword();
-  }
-  
-  @Context
-  ServletContext servletContext;
-  
-  @GET
-  @Produces(MediaType.APPLICATION_JSON)
-  @Path("/workflow")
-  public Workflows getWorkflows(@QueryParam("orderBy") String field, @DefaultValue(PostgresConnector.SORT_ASC) @QueryParam("sortDir") String sortDir,
-      @DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("-1") @QueryParam("limit") int limit) {
-    Workflows workflows = EMPTY_WORKFLOWS;
-    PostgresConnector conn = null;
-    try {
-      conn = getConnector();
-      if (field == null)
-        workflows = conn.fetchWorkflows();
-      else {
-        field = field.toUpperCase();
-        if ("ELAPSEDTIME".equals(field))
-          field = "DURATION";
-        workflows = conn.fetchWorkflows(WorkflowFields.valueOf(field), sortDir.toUpperCase().equals(PostgresConnector.SORT_ASC), offset, limit);
-      }
-    } catch (IOException e) {
-      LOG.error("Error interacting with RCA database ", e);
-      workflows = EMPTY_WORKFLOWS;
-    } finally {
-      if (conn != null) {
-        conn.close();
-      }
-    }
-    return workflows;
-  }
-  
-  @GET
-  @Produces(MediaType.APPLICATION_JSON)
-  @Path("/datatable")
-  public DataTable getWorkflowDataTable(@DefaultValue("0") @QueryParam("iDisplayStart") int start,
-      @DefaultValue("10") @QueryParam("iDisplayLength") int amount, @QueryParam("sSearch") String searchTerm, @DefaultValue("0") @QueryParam("sEcho") int echo,
-      @DefaultValue("0") @QueryParam("iSortCol_0") int col, @DefaultValue(PostgresConnector.SORT_ASC) @QueryParam("sSortDir_0") String sdir,
-      @QueryParam("sSearch_0") String workflowId, @QueryParam("sSearch_1") String workflowName, @QueryParam("sSearch_2") String workflowType,
-      @QueryParam("sSearch_3") String userName, @DefaultValue("-1") @QueryParam("minJobs") int minJobs, @DefaultValue("-1") @QueryParam("maxJobs") int maxJobs,
-      @DefaultValue("-1") @QueryParam("minInputBytes") long minInputBytes, @DefaultValue("-1") @QueryParam("maxInputBytes") long maxInputBytes,
-      @DefaultValue("-1") @QueryParam("minOutputBytes") long minOutputBytes, @DefaultValue("-1") @QueryParam("maxOutputBytes") long maxOutputBytes,
-      @DefaultValue("-1") @QueryParam("minDuration") long minDuration, @DefaultValue("-1") @QueryParam("maxDuration") long maxDuration,
-      @DefaultValue("-1") @QueryParam("minStartTime") long minStartTime, @DefaultValue("-1") @QueryParam("maxStartTime") long maxStartTime,
-      @DefaultValue("-1") @QueryParam("minFinishTime") long minFinishTime, @DefaultValue("-1") @QueryParam("maxFinishTime") long maxFinishTime) {
-    
-    if (start < 0)
-      start = 0;
-    if (amount < 10 || amount > 100)
-      amount = 10;
-    
-    boolean sortAscending = true;
-    if (!sdir.toUpperCase().equals(PostgresConnector.SORT_ASC))
-      sortAscending = false;
-    
-    WorkflowFields field = null;
-    switch (col) {
-      case 0: // workflowId
-        field = WorkflowFields.WORKFLOWID;
-        break;
-      case 1: // workflowName
-        field = WorkflowFields.WORKFLOWNAME;
-        break;
-      case 2: // workflowType
-        field = WorkflowFields.WORKFLOWID;
-        break;
-      case 3: // userName
-        field = WorkflowFields.USERNAME;
-        break;
-      case 4: // numJobsTotal
-        field = WorkflowFields.NUMJOBSTOTAL;
-        break;
-      case 5: // inputBytes
-        field = WorkflowFields.INPUTBYTES;
-        break;
-      case 6: // outputBytes
-        field = WorkflowFields.OUTPUTBYTES;
-        break;
-      case 7: // duration
-        field = WorkflowFields.DURATION;
-        break;
-      case 8: // startTime
-        field = WorkflowFields.STARTTIME;
-        break;
-      case 9: // lastUpdateTime
-        field = WorkflowFields.LASTUPDATETIME;
-        break;
-      default:
-        field = WorkflowFields.WORKFLOWID;
-    }
-    
-    DataTable table = null;
-    PostgresConnector conn = null;
-    try {
-      conn = getConnector();
-      table = conn.fetchWorkflows(start, amount, searchTerm, echo, field, sortAscending, workflowId, workflowName, workflowType, userName, minJobs, maxJobs,
-          minInputBytes, maxInputBytes, minOutputBytes, maxOutputBytes, minDuration, maxDuration, minStartTime, maxStartTime, minFinishTime, maxFinishTime);
-    } catch (IOException e) {
-      LOG.error("Error interacting with RCA database ", e);
-    } finally {
-      if (conn != null) {
-        conn.close();
-      }
-    }
-    return table;
-  }
-  
-  @GET
-  @Produces(MediaType.APPLICATION_JSON)
-  @Path("/job")
-  public Jobs getJobs(@QueryParam("workflowId") String workflowId, @DefaultValue("-1") @QueryParam("startTime") long minFinishTime,
-      @DefaultValue("-1") @QueryParam("endTime") long maxStartTime) {
-    Jobs jobs = new Jobs();
-    PostgresConnector conn = null;
-    try {
-      conn = getConnector();
-      if (workflowId != null)
-        jobs.setJobs(conn.fetchJobDetails(workflowId));
-      else if (maxStartTime >= minFinishTime)
-        jobs.setJobs(conn.fetchJobDetails(minFinishTime, maxStartTime));
-    } catch (IOException e) {
-      LOG.error("Error interacting with RCA database ", e);
-      jobs.setJobs(EMPTY_JOBS);
-    } finally {
-      if (conn != null) {
-        conn.close();
-      }
-    }
-    return jobs;
-  }
-  
-  @GET
-  @Produces(MediaType.APPLICATION_JSON)
-  @Path("/task")
-  public TaskData getTaskSummary(@QueryParam("jobId") String jobId, @QueryParam("width") int steps, @QueryParam("workflowId") String workflowId,
-      @DefaultValue("-1") @QueryParam("startTime") long minFinishTime, @DefaultValue("-1") @QueryParam("endTime") long maxStartTime) {
-    TaskData points = new TaskData();
-    PostgresConnector conn = null;
-    try {
-      conn = getConnector();
-      List<TaskAttempt> taskAttempts = null;
-      long startTime = -1;
-      long endTime = -1;
-      if (jobId != null) {
-        long[] times = conn.fetchJobStartStopTimes(jobId);
-        if (times != null) {
-          startTime = times[0];
-          endTime = times[1];
-          taskAttempts = conn.fetchJobTaskAttempts(jobId);
-        }
-      } else {
-        startTime = minFinishTime;
-        endTime = maxStartTime;
-        if (workflowId != null)
-          taskAttempts = conn.fetchWorkflowTaskAttempts(workflowId);
-        else
-          taskAttempts = conn.fetchTaskAttempts(minFinishTime, maxStartTime);
-      }
-      if (startTime > 0 && endTime > 0 && endTime >= startTime) {
-        double submitTimeSecs = startTime / 1000.0;
-        double finishTimeSecs = endTime / 1000.0;
-        double step = (finishTimeSecs - submitTimeSecs) / steps;
-        if (step < 1)
-          step = 1;
-        if (taskAttempts != null)
-          getTaskDetails(taskAttempts, points, submitTimeSecs, finishTimeSecs, step);
-      }
-    } catch (IOException e) {
-      LOG.error("Error interacting with RCA database ", e);
-    } finally {
-      if (conn != null) {
-        conn.close();
-      }
-    }
-    return points;
-  }
-  
-  @GET
-  @Produces(MediaType.APPLICATION_JSON)
-  @Path("/taskdetails")
-  public List<TaskAttempt> getTaskDetails(@QueryParam("jobId") String jobId, @QueryParam("workflowId") String workflowId) {
-    List<TaskAttempt> taskAttempts = new ArrayList<TaskAttempt>();
-    PostgresConnector conn = null;
-    try {
-      conn = getConnector();
-      if (jobId != null) {
-        taskAttempts = conn.fetchJobTaskAttempts(jobId);
-      } else if (workflowId != null) {
-        taskAttempts = conn.fetchWorkflowTaskAttempts(workflowId);
-      }
-    } catch (IOException e) {
-      LOG.error("Error interacting with RCA database ", e);
-    } finally {
-      if (conn != null) {
-        conn.close();
-      }
-    }
-    return taskAttempts;
-  }
-  
-  @GET
-  @Produces(MediaType.APPLICATION_JSON)
-  @Path("/tasklocality")
-  public TaskLocalityData getTaskLocalitySummary(@QueryParam("jobId") String jobId, @DefaultValue("4") @QueryParam("minr") int minr,
-      @DefaultValue("24") @QueryParam("maxr") int maxr, @QueryParam("workflowId") String workflowId) {
-    if (maxr < minr)
-      maxr = minr;
-    TaskLocalityData data = new TaskLocalityData();
-    PostgresConnector conn = null;
-    try {
-      conn = getConnector();
-      if (jobId != null) {
-        long[] times = conn.fetchJobStartStopTimes(jobId);
-        if (times != null) {
-          getApproxTaskAttemptsByLocality(conn.fetchJobTaskAttempts(jobId), times[0], times[1], data, minr, maxr);
-        }
-      } else if (workflowId != null) {
-        getExactTaskAttemptsByLocality(conn.fetchWorkflowTaskAttempts(workflowId), data, minr, maxr);
-      }
-    } catch (IOException e) {
-      LOG.error("Error interacting with RCA database ", e);
-    } finally {
-      if (conn != null) {
-        conn.close();
-      }
-    }
-    return data;
-  }
-  
-  private static void getTaskDetails(List<TaskAttempt> taskAttempts, TaskData points, double submitTimeSecs, double finishTimeSecs, double step)
-      throws IOException {
-    List<Point> mapPoints = new ArrayList<Point>();
-    List<Point> shufflePoints = new ArrayList<Point>();
-    List<Point> reducePoints = new ArrayList<Point>();
-    for (double time = submitTimeSecs; time < finishTimeSecs; time += step) {
-      int numTasks = 0;
-      int numShuffleTasks = 0;
-      int numReduceTasks = 0;
-      for (TaskAttempt taskAttempt : taskAttempts) {
-        if (taskAttempt.getTaskType().equals("MAP")) {
-          if ((taskAttempt.getStartTime() / 1000.0) <= (time + step) && (taskAttempt.getFinishTime() / 1000.0) >= time)
-            numTasks++;
-        } else if (taskAttempt.getTaskType().equals("REDUCE")) {
-          if ((taskAttempt.getStartTime() / 1000.0) <= (time + step) && (taskAttempt.getShuffleFinishTime() / 1000.0) >= time) {
-            numShuffleTasks++;
-          } else if ((taskAttempt.getShuffleFinishTime() / 1000.0) < (time + step) && (taskAttempt.getFinishTime() / 1000.0) >= time) {
-            numReduceTasks++;
-          }
-        }
-      }
-      mapPoints.add(new Point(Math.round(time), numTasks));
-      shufflePoints.add(new Point(Math.round(time), numShuffleTasks));
-      reducePoints.add(new Point(Math.round(time), numReduceTasks));
-    }
-    points.setMapData(mapPoints);
-    points.setShuffleData(shufflePoints);
-    points.setReduceData(reducePoints);
-  }
-  
-  private static void getExactTaskAttemptsByLocality(List<TaskAttempt> taskAttempts, TaskLocalityData data, int minr, int maxr) throws IOException {
-    MinMax io = new MinMax();
-    data.setMapNodeLocal(processExactLocalityData(taskAttempts, "MAP", "NODE_LOCAL", io));
-    data.setMapRackLocal(processExactLocalityData(taskAttempts, "MAP", "RACK_LOCAL", io));
-    data.setMapOffSwitch(processExactLocalityData(taskAttempts, "MAP", "OFF_SWITCH", io));
-    data.setReduceOffSwitch(processExactLocalityData(taskAttempts, "REDUCE", null, io));
-    setRValues(data.getMapNodeLocal(), minr, maxr, io.max);
-    setRValues(data.getMapRackLocal(), minr, maxr, io.max);
-    setRValues(data.getMapOffSwitch(), minr, maxr, io.max);
-    setRValues(data.getReduceOffSwitch(), minr, maxr, io.max);
-  }
-
-  private static void getApproxTaskAttemptsByLocality(List<TaskAttempt> taskAttempts, long submitTime, long finishTime, TaskLocalityData data, int minr,
-      int maxr) throws IOException {
-    long submitTimeX = transformX(submitTime);
-    long finishTimeX = transformX(finishTime);
-    Set<Long> xPoints = getXPoints(taskAttempts, submitTimeX, finishTimeX);
-    Long[] xList = xPoints.toArray(new Long[xPoints.size()]);
-    MinMax io = new MinMax();
-    data.setMapNodeLocal(processLocalityData(taskAttempts, "MAP", "NODE_LOCAL", xList, io));
-    data.setMapRackLocal(processLocalityData(taskAttempts, "MAP", "RACK_LOCAL", xList, io));
-    data.setMapOffSwitch(processLocalityData(taskAttempts, "MAP", "OFF_SWITCH", xList, io));
-    data.setReduceOffSwitch(processLocalityData(taskAttempts, "REDUCE", "OFF_SWITCH", xList, io));
-    setRValues(data.getMapNodeLocal(), minr, maxr, io.max);
-    setRValues(data.getMapRackLocal(), minr, maxr, io.max);
-    setRValues(data.getMapOffSwitch(), minr, maxr, io.max);
-    setRValues(data.getReduceOffSwitch(), minr, maxr, io.max);
-    data.setSubmitTime(submitTimeX);
-    data.setFinishTime(finishTimeX);
-  }
-  
-  private static class MinMax {
-    private long min = Long.MAX_VALUE;
-    private long max = 0;
-  }
-  
-  private static long transformX(long time) {
-    return Math.round(time / 1000.0);
-  }
-  
-  private static long untransformX(long x) {
-    return x * 1000;
-  }
-  
-  private static long transformY(long time) {
-    return time;
-  }
-  
-  private static Set<Long> getXPoints(List<TaskAttempt> taskAttempts, long submitTimeX, long finishTimeX) {
-    TreeSet<Long> xPoints = new TreeSet<Long>();
-    TreeSet<TaskAttempt> sortedAttempts = new TreeSet<TaskAttempt>(new Comparator<TaskAttempt>() {
-      @Override
-      public int compare(TaskAttempt t1, TaskAttempt t2) {
-        if (t1.getStartTime() < t2.getStartTime())
-          return -1;
-        else if (t1.getStartTime() > t2.getStartTime())
-          return 1;
-        return t1.getTaskAttemptId().compareTo(t2.getTaskAttemptId());
-      }
-    });
-    sortedAttempts.addAll(taskAttempts);
-    getXPoints(sortedAttempts, xPoints);
-    xPoints.add(submitTimeX);
-    xPoints.add(finishTimeX);
-    return xPoints;
-  }
-  
-  private static void getXPoints(Iterable<TaskAttempt> taskAttempts, Set<Long> xPoints) {
-    for (TaskAttempt taskAttempt : taskAttempts) {
-      long x = transformX(taskAttempt.getStartTime());
-      while (xPoints.contains(x))
-        x += 1;
-      xPoints.add(x);
-      taskAttempt.setStartTime(untransformX(x));
-    }
-  }
-  
-  private static int addDataPoint(List<DataPoint> data, DataPoint point, int index, Long[] xPoints) {
-    while (index < xPoints.length) {
-      if (point.getX() == xPoints[index]) {
-        index++;
-        break;
-      } else if (point.getX() > xPoints[index]) {
-        data.add(new DataPoint(xPoints[index++]));
-      }
-    }
-    data.add(point);
-    return index;
-  }
-  
-  private static List<DataPoint> processExactLocalityData(List<TaskAttempt> taskAttempts, String taskType, String locality, MinMax io) {
-    List<DataPoint> data = new ArrayList<DataPoint>();
-    for (TaskAttempt taskAttempt : taskAttempts) {
-      if (taskType.equals(taskAttempt.getTaskType()) && (locality == null || locality.equals(taskAttempt.getLocality()))) {
-        DataPoint point = new DataPoint();
-        point.setX(taskAttempt.getStartTime());
-        point.setY(taskAttempt.getFinishTime() - taskAttempt.getStartTime());
-        point.setIO(taskAttempt.getInputBytes() + taskAttempt.getOutputBytes());
-        point.setLabel(taskAttempt.getTaskAttemptId());
-        point.setStatus(taskAttempt.getStatus());
-        data.add(point);
-        io.max = Math.max(io.max, point.getIO());
-        io.min = Math.min(io.min, point.getIO());
-      }
-    }
-    return data;
-  }
-
-  private static List<DataPoint> processLocalityData(List<TaskAttempt> taskAttempts, String taskType, String locality, Long[] xPoints, MinMax io) {
-    List<DataPoint> data = new ArrayList<DataPoint>();
-    int i = 0;
-    for (TaskAttempt taskAttempt : taskAttempts) {
-      if (taskType.equals(taskAttempt.getTaskType()) && locality.equals(taskAttempt.getLocality())) {
-        DataPoint point = new DataPoint();
-        point.setX(transformX(taskAttempt.getStartTime()));
-        point.setY(transformY(taskAttempt.getFinishTime() - taskAttempt.getStartTime()));
-        point.setIO(taskAttempt.getInputBytes() + taskAttempt.getOutputBytes());
-        point.setLabel(taskAttempt.getTaskAttemptId());
-        point.setStatus(taskAttempt.getStatus());
-        i = addDataPoint(data, point, i, xPoints);
-        io.max = Math.max(io.max, point.getIO());
-        io.min = Math.min(io.min, point.getIO());
-      }
-    }
-    while (i < xPoints.length)
-      data.add(new DataPoint(xPoints[i++]));
-    return data;
-  }
-  
-  private static void setRValues(List<DataPoint> data, int minr, int maxr, long maxIO) {
-    for (DataPoint point : data) {
-      if (point.getY() == 0) {
-        continue;
-      }
-      if (maxIO == 0 || maxr == minr) {
-        point.setR(minr);
-        continue;
-      }
-      point.setR(Math.round(Math.sqrt(point.getIO() * 1.0 / maxIO) * (maxr - minr) + minr));
-    }
-  }
-}

+ 0 - 3
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java

@@ -29,7 +29,6 @@ import com.google.inject.Singleton;
 import com.google.inject.name.Named;
 import com.google.inject.persist.Transactional;
 import com.sun.jersey.spi.container.servlet.ServletContainer;
-import org.apache.ambari.eventdb.webservice.WorkflowJsonService;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.StateRecoveryManager;
 import org.apache.ambari.server.StaticallyInject;
@@ -897,8 +896,6 @@ public class AmbariServer {
     StageUtils.setGson(injector.getInstance(Gson.class));
     StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
-    WorkflowJsonService.setDBProperties(
-      injector.getInstance(Configuration.class));
     SecurityFilter.init(injector.getInstance(Configuration.class));
     StackDefinedPropertyProvider.init(injector);
     AbstractControllerResourceProvider.init(injector.getInstance(ResourceProviderFactory.class));