MicroStrategy ONE
Deleting the 3 Longest-Running Jobs
The sample code below illustrates how to delete the three longest-running jobs, if the duration is longer than one minute. It is a good demonstration of how the various features of the API can be combined into single functionality as a part of any customization.
// create a WebObjectsFactory instance
WebObjectsFactory factory = WebObjectsFactory.getInstance();
// Get the job source object
JobSource source = (JobSource) factory.getMonitorSource(EnumWebMonitorType.WebMonitorTypeJob);
// Add a sort criterion that we will sort the duration of the job in descending order
MonitorSort msort = source.getSortCriteria();
msort.add(EnumDSSXMLJobInfo.DssXmlJobInfoDuration, EnumDSSXMLOrder.DssXmlDescending);
// Add a filter condition that we only get jobs whose duration are greater than or equal to 60 seconds
MonitorFilter mf = source.getFilter();
mf.add(EnumDSSXMLJobInfo.DssXmlJobInfoDuration, EnumDSSXMLMonitorFilterOperator.DssXmlGreaterOrEqual, "60");
// Set the maximum count to be 3
source.setMaxCount(3);
// Set the flag to obtain browsing information
source.setLevel(EnumDSSXMLLevelFlags.DssXmlBrowsingLevel);
try {
// Sends the request to Intelligence Server to retrieve job information,
// in this case, the top 3 loggest running jobs, each of which is over 60 seconds
JobResults results = source.getJobs();
// Check whether we have any result returned
if (results.getCount() > 0) {
// Obtain the job manipulator object
JobManipulator jobManipulator = source.getManipulator();
// Adds the job IDs to the deletion task for batch operation
for (int i=0; i < results.getCount(); i++) {
Job jobToDelete = results.get(i);
// Add a batch deletion operation
jobManipulator.addDeletionTask(jobToDelete.getJobID());
}
try {
// Submit the request to delete jobs
jobManipulator.submit();
} catch (MonitorManipulationException mme) {
// We have job deletion falure, so we display the error
MonitorManipulationFailure[] mmf = mme.getFailures();
displayFailure(mmf);
}
}
} catch (WebObjectsAdminException woae) {
woae.printStackTrace();
}