Exemplo n.º 1
0
  /**
   * Method for adding application creation events to database
   *
   * @param versionHashId version hash id
   * @param event application creation event
   * @return
   * @throws AppCloudException
   */
  public boolean addAppCreationEvent(String versionHashId, Event event, int tenantId)
      throws AppCloudException {

    Connection dbConnection = DBUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    try {
      preparedStatement = dbConnection.prepareStatement(SQLQueryConstants.ADD_APP_CREATION_EVENT);
      preparedStatement.setString(1, event.getEventName());
      preparedStatement.setString(2, event.getEventStatus());
      preparedStatement.setString(3, versionHashId);
      preparedStatement.setTimestamp(4, event.getTimestamp());
      preparedStatement.setString(5, event.getEventDescription());
      preparedStatement.setInt(6, tenantId);

      boolean result = preparedStatement.execute();
      dbConnection.commit();
    } catch (SQLException e) {
      String msg =
          "Error occurred while adding app creation event: "
              + event.getEventName()
              + " status: "
              + event.getEventStatus()
              + " timestamp: "
              + event.getTimestamp();
      log.error(msg, e);
      throw new AppCloudException(msg, e);

    } finally {
      DBUtil.closePreparedStatement(preparedStatement);
      DBUtil.closeConnection(dbConnection);
    }
    return true;
  }
Exemplo n.º 2
0
  /**
   * Delete all the events related to a particular app version
   *
   * @param versionHashId version hash id
   * @return
   * @throws AppCloudException
   */
  public boolean deleteAppVersionEvents(String versionHashId) throws AppCloudException {

    Connection dbConnection = DBUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    try {
      preparedStatement =
          dbConnection.prepareStatement(SQLQueryConstants.DELETE_ALL_APP_VERSION_EVENTS);
      preparedStatement.setString(1, versionHashId);

      int result = preparedStatement.executeUpdate();
      dbConnection.commit();
    } catch (SQLException e) {
      String msg =
          "Error occurred while deleting all the events for the app version has id "
              + versionHashId;
      log.error(msg, e);
      throw new AppCloudException(msg, e);

    } finally {
      DBUtil.closePreparedStatement(preparedStatement);
      DBUtil.closeConnection(dbConnection);
    }
    return true;
  }
Exemplo n.º 3
0
  /**
   * Method to get event stream of an application
   *
   * @param versionHashId application id
   * @return
   * @throws AppCloudException
   */
  public List<Event> getEventsOfApplication(String versionHashId) throws AppCloudException {

    Connection dbConnection = DBUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    List<Event> eventList = new ArrayList<>();

    try {
      preparedStatement =
          dbConnection.prepareStatement(SQLQueryConstants.GET_ALL_EVENTS_OF_APPLICATION);
      preparedStatement.setString(1, versionHashId);

      ResultSet resultSet = preparedStatement.executeQuery();
      Event event;
      while (resultSet.next()) {
        event = new Event();
        event.setEventName(resultSet.getString(SQLQueryConstants.NAME));
        event.setEventStatus(resultSet.getString(SQLQueryConstants.STATUS));
        event.setTimestamp(resultSet.getTimestamp(SQLQueryConstants.EVENT_TIMESTAMP));
        event.setEventDescription(resultSet.getString(SQLQueryConstants.DESCRIPTION));

        eventList.add(event);
      }

    } catch (SQLException e) {
      String msg =
          "Error while retrieving Application creation event stream for application with hash id : "
              + versionHashId;
      log.error(msg, e);
      throw new AppCloudException(msg, e);
    } finally {
      DBUtil.closePreparedStatement(preparedStatement);
      DBUtil.closeConnection(dbConnection);
    }
    return eventList;
  }