Skip to content

Commit

Permalink
more refinements to the logging framework and such #11057
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Dec 30, 2024
1 parent 5c3c554 commit 3de704b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -817,18 +817,36 @@ public void globusUpload(JsonObject jsonData, Dataset dataset, String httpReques

logger.fine("json: " + JsonUtil.prettyPrint(jsonData));

globusLogger.info("Globus upload initiated");

String taskIdentifier = jsonData.getString("taskIdentifier");


globusLogger.info("Globus upload initiated, task "+taskIdentifier);

GlobusEndpoint endpoint = getGlobusEndpoint(dataset);

// The first check on the status of the task:
// It is important to be careful here, and not give up on the task
// prematurely if anything goes wrong during this initial api call!
// So, perhaps a @todo - make a number of attempts until we get a
// valid response ?
GlobusTaskState taskState = getTask(endpoint.getClientToken(), taskIdentifier, globusLogger);

GlobusTaskState taskState = null;

int retriesLimit = 3;
int retries = 0;

while (taskState == null && retries < retriesLimit) {
taskState = getTask(endpoint.getClientToken(), taskIdentifier, globusLogger);
retries++;
try {
Thread.sleep(3000);
} catch (InterruptedException ie) {
logger.warning("caught an Interrupted Exception while trying to sleep for 3 sec. in globusDownload()");
}
}

if (taskState != null) {
globusLogger.info("Task owner: "+taskState.getOwner_id()+", human-friendly owner name: "+taskState.getOwner_string());
}

String ruleId = taskState != null
? getRuleId(endpoint, taskState.getOwner_id(), "rw")
: null;
Expand Down Expand Up @@ -1269,11 +1287,11 @@ public void globusDownload(JsonObject jsonObject, Dataset dataset, User authUser
} else {
globusLogger = logger;
}

globusLogger.info("Starting monitoring a globus download task");


String taskIdentifier = jsonObject.getString("taskIdentifier");

globusLogger.info("Starting monitoring a globus download task "+taskIdentifier);

GlobusEndpoint endpoint = getGlobusEndpoint(dataset);
logger.fine("Endpoint path: " + endpoint.getBasePath());

Expand Down Expand Up @@ -1307,6 +1325,10 @@ public void globusDownload(JsonObject jsonObject, Dataset dataset, User authUser
}
}

if (taskState != null) {
globusLogger.info("Task owner: "+taskState.getOwner_id()+", human-friendly owner name: "+taskState.getOwner_string());
}

String ruleId = taskState != null
? getRuleId(endpoint, taskState.getOwner_id(), "r")
: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public class GlobusTaskState {
private boolean skip_source_errors;
private String nice_status;
private String nice_status_short_description;
// @todo: add fields for other potentially useful things, like the
// human-friendly name associated with the Globus account, etc.
private String owner_string;

public String getDestination_endpoint_display_name() {
return destination_endpoint_display_name;
Expand Down Expand Up @@ -95,5 +94,12 @@ public void setNice_status(String nice_status) {
public String getNice_status_short_description() {
return nice_status_short_description;
}


public void setOwner_string(String owner_string) {
this.owner_string = owner_string;
}

public String getOwner_string() {
return owner_string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public class TaskMonitoringServiceBean {
@Resource
ManagedScheduledExecutorService scheduler;

@EJB
SystemConfig systemConfig;
@EJB
SettingsServiceBean settingsSvc;
@EJB
Expand All @@ -53,11 +51,13 @@ public void init() {
logger.info("Starting Globus task monitoring service");
int pollingInterval = SystemConfig.getIntLimitFromStringOrDefault(
settingsSvc.getValueForKey(SettingsServiceBean.Key.GlobusPollingInterval), 600);

// Monitoring service scheduler for ongoing upload tasks:
this.scheduler.scheduleWithFixedDelay(this::checkOngoingUploadTasks,
0, pollingInterval,
TimeUnit.SECONDS);

// A separate monitoring service for ongoing download tasks:
// A separate monitoring service scheduler for ongoing download tasks:
this.scheduler.scheduleWithFixedDelay(this::checkOngoingDownloadTasks,
0, pollingInterval,
TimeUnit.SECONDS);
Expand All @@ -79,25 +79,25 @@ public void checkOngoingUploadTasks() {
List<GlobusTaskInProgress> tasks = globusService.findAllOngoingTasks(GlobusTaskInProgress.TaskType.UPLOAD);

tasks.forEach(t -> {
FileHandler taskLogHandler = getTaskLogHandler(t);
Logger taskLogger = getTaskLogger(t, taskLogHandler);

GlobusTaskState retrieved = globusService.getTask(t.getGlobusToken(), t.getTaskId(), taskLogger);
GlobusTaskState retrieved = globusService.getTask(t.getGlobusToken(), t.getTaskId(), null);

if (GlobusUtil.isTaskCompleted(retrieved)) {
FileHandler taskLogHandler = getTaskLogHandler(t);
Logger taskLogger = getTaskLogger(t, taskLogHandler);

// Do our thing, finalize adding the files to the dataset
globusService.processCompletedTask(t, retrieved, GlobusUtil.isTaskSucceeded(retrieved), GlobusUtil.getCompletedTaskStatus(retrieved), taskLogger);
// Whether it finished successfully, or failed in the process,
// there's no need to keep monitoring this task, so we can
// delete it.
//globusService.deleteExternalUploadRecords(t.getTaskId());
globusService.deleteTask(t);

if (taskLogHandler != null) {
taskLogHandler.close();
}
}

if (taskLogHandler != null) {
// @todo it should be prudent to cache these loggers and handlers
// between monitoring runs (should be fairly easy to do)
taskLogHandler.close();
}

});
}

Expand All @@ -111,26 +111,30 @@ public void checkOngoingDownloadTasks() {
List<GlobusTaskInProgress> tasks = globusService.findAllOngoingTasks(GlobusTaskInProgress.TaskType.DOWNLOAD);

tasks.forEach(t -> {
FileHandler taskLogHandler = getTaskLogHandler(t);
Logger taskLogger = getTaskLogger(t, taskLogHandler);

GlobusTaskState retrieved = globusService.getTask(t.getGlobusToken(), t.getTaskId(), taskLogger);

GlobusTaskState retrieved = globusService.getTask(t.getGlobusToken(), t.getTaskId(), null);

if (GlobusUtil.isTaskCompleted(retrieved)) {
FileHandler taskLogHandler = getTaskLogHandler(t);
Logger taskLogger = getTaskLogger(t, taskLogHandler);
String taskStatus = retrieved == null ? "N/A" : retrieved.getStatus();
taskLogger.info("Checking on task " + t.getTaskId() + ", status: " + taskStatus);

globusService.processCompletedTask(t, retrieved, GlobusUtil.isTaskSucceeded(retrieved), GlobusUtil.getCompletedTaskStatus(retrieved), taskLogger);
// globusService.processCompletedTask(t, GlobusUtil.isTaskSucceeded(retrieved), GlobusUtil.getTaskStatus(retrieved), taskLogger);
// Whether it finished successfully or failed, the task can now
// be deleted.
globusService.deleteTask(t);
}

if (taskLogHandler != null) {
// @todo it should be prudent to cache these loggers and handlers
// between monitoring runs (should be fairly easy to do)
taskLogHandler.close();

if (taskLogHandler != null) {
taskLogHandler.close();
}
}
});
}

// @todo: combine the 2 methods below into one (?)
// @todo: move the method(s) below into the GlobusUtil, for the Globus Service to use as well
// @todo: switch to a different log formatter (from the default xml) (?)
private FileHandler getTaskLogHandler(GlobusTaskInProgress task) {
if (task == null) {
return null;
Expand All @@ -146,7 +150,7 @@ private FileHandler getTaskLogHandler(GlobusTaskInProgress task) {
+ ".log";
FileHandler fileHandler;
try {
fileHandler = new FileHandler(logFileName);
fileHandler = new FileHandler(logFileName, true);
} catch (IOException | SecurityException ex) {
// @todo log this error somehow?
fileHandler = null;
Expand Down

0 comments on commit 3de704b

Please sign in to comment.