Skip to content

Commit

Permalink
Remove parameters when job is deleted or retired (#142)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Forer <[email protected]>
  • Loading branch information
seppinho and lukfor authored Mar 13, 2024
1 parent 689ea97 commit 8028905
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/cloudgene/mapred/api/v2/admin/ArchiveJob.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cloudgene.mapred.api.v2.admin;

import cloudgene.mapred.database.ParameterDao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.restlet.data.Parameter;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
Expand Down Expand Up @@ -81,6 +83,9 @@ public Representation get() {
job.setState(AbstractJob.STATE_RETIRED);
dao.update(job);

ParameterDao parameterDao = new ParameterDao(getDatabase());
parameterDao.deleteAllByJob(job);

if (externalWorkspace != null) {
try {
externalWorkspace.delete(job.getId());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/cloudgene/mapred/api/v2/jobs/GetJobDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Vector;

import cloudgene.mapred.database.ParameterDao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.restlet.data.MediaType;
Expand Down Expand Up @@ -148,6 +149,9 @@ public Representation deleteJob(Representation entity) {
job.setState(AbstractJob.STATE_DELETED);
dao.update(job);

ParameterDao parameterDao = new ParameterDao(getDatabase());
parameterDao.deleteAllByJob(job);

Settings settings = getSettings();

IExternalWorkspace externalWorkspace = null;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/cloudgene/mapred/cron/CleanUpTasks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.util.List;

import cloudgene.mapred.database.ParameterDao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand All @@ -25,6 +26,8 @@ public class CleanUpTasks {
public static int executeRetire(Database database, Settings settings) {
JobDao dao = new JobDao(database);

ParameterDao parameterDao = new ParameterDao(database);

List<AbstractJob> oldJobs = dao.findAllNotifiedJobs();

int deleted = 0;
Expand Down Expand Up @@ -53,6 +56,9 @@ public static int executeRetire(Database database, Settings settings) {
job.setState(AbstractJob.STATE_RETIRED);
dao.update(job);


parameterDao.deleteAllByJob(job);

log.info("Job " + job.getId() + " retired.");
deleted++;

Expand Down
25 changes: 24 additions & 1 deletion src/main/java/cloudgene/mapred/database/ParameterDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,30 @@ public CloudgeneParameterOutput findById(int id) {
}
}

class ParameterInputMapper implements IRowMapper {
public boolean deleteAllByJob(AbstractJob job) {
try {

StringBuilder sql = new StringBuilder();
sql.append("delete ");
sql.append("from parameter ");
sql.append("where job_id = ?");

Object[] params = new Object[1];
params[0] = job.getId();

update(sql.toString(), params);

log.debug("delete all parameters by job_id '" + job.getId() + "' successful.");

return true;

} catch (SQLException e) {
log.error("delete all parameters by job_id '" + job.getId() + "' failed.", e);
return false;
}
}

class ParameterInputMapper implements IRowMapper {

@Override
public Object mapRow(ResultSet rs, int row) throws SQLException {
Expand Down

0 comments on commit 8028905

Please sign in to comment.