use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class Auditer method pollConsumerMessages.
public List<String> pollConsumerMessages(String consumerName) throws InternalErrorException {
if (consumerName == null)
throw new InternalErrorException("Auditer consumer doesn't exist.");
try {
if (jdbc.queryForInt("select count(*) from auditer_consumers where name=?", consumerName) != 1) {
throw new InternalErrorException("Auditer consumer doesn't exist.");
}
int lastProcessedId = getLastProcessedId(consumerName);
int maxId = jdbc.queryForInt("select max(id) from auditer_log");
if (maxId > lastProcessedId) {
List<String> messages = jdbc.query("select " + Auditer.auditMessageMappingSelectQuery + " from auditer_log where id > ? and id <= ? order by id", AUDITER_LOG_MAPPER, lastProcessedId, maxId);
lastProcessedId = maxId;
jdbc.update("update auditer_consumers set last_processed_id=?, modified_at=" + Compatibility.getSysdate() + " where name=?", lastProcessedId, consumerName);
return messages;
}
return new ArrayList<String>();
} catch (Exception ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class Auditer method pollConsumerFullMessages.
public List<String> pollConsumerFullMessages(String consumerName) throws InternalErrorException {
if (consumerName == null)
throw new InternalErrorException("Auditer consumer doesn't exist.");
try {
if (jdbc.queryForInt("select count(*) from auditer_consumers where name=?", consumerName) != 1) {
throw new InternalErrorException("Auditer consumer doesn't exist.");
}
int lastProcessedId = getLastProcessedId(consumerName);
int maxId = jdbc.queryForInt("select max(id) from auditer_log");
if (maxId > lastProcessedId) {
List<String> messages = jdbc.query("select " + Auditer.auditMessageMappingSelectQuery + " from auditer_log where id > ? and id <= ? order by id", AUDITER_FULL_LOG_MAPPER, lastProcessedId, maxId);
lastProcessedId = maxId;
jdbc.update("update auditer_consumers set last_processed_id=?, modified_at=" + Compatibility.getSysdate() + " where name=?", lastProcessedId, consumerName);
return messages;
}
return new ArrayList<String>();
} catch (Exception ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class Auditer method initialize.
public void initialize() throws InternalErrorException {
try {
this.lastProcessedId = jdbc.queryForInt("select max(id) from auditer_log");
log.debug("Auditer initialized with lastProcessedId [{}].", this.lastProcessedId);
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class Auditer method createAuditerConsumer.
public void createAuditerConsumer(String consumerName) throws InternalErrorException {
try {
int lastProcessedId = jdbc.queryForInt("select max(id) from auditer_log");
int consumerId = Utils.getNewId(jdbc, "auditer_consumers_id_seq");
jdbc.update("insert into auditer_consumers (id, name, last_processed_id) values (?,?,?)", consumerId, consumerName, lastProcessedId);
log.debug("New consumer [name: '{}', lastProcessedId: '{}'] created.", consumerName, lastProcessedId);
} catch (Exception e) {
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class Auditer method storeMessageToDb.
/**
* Store the message to the DB.
*
* @param sess
* @param message
*/
public void storeMessageToDb(final PerunSession sess, final String message) {
synchronized (LOCK_DB_TABLE_AUDITER_LOG) {
try {
final int msgId = Utils.getNewId(jdbc, "auditer_log_id_seq");
jdbc.execute("insert into auditer_log (id, msg, actor, created_at, created_by_uid) values (?,?,?," + Compatibility.getSysdate() + ",?)", new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
public void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
ps.setInt(1, msgId);
lobCreator.setClobAsString(ps, 2, message);
ps.setString(3, sess.getPerunPrincipal().getActor());
ps.setInt(4, sess.getPerunPrincipal().getUserId());
}
});
} catch (RuntimeException e) {
log.error("Cannot store auditer log message ['{}'], exception: {}", message, e);
} catch (InternalErrorException e) {
log.error("Cannot get unique id for new auditer log message ['{}'], exception: {}", message, e);
}
}
}
Aggregations