OIM API to get Scheduler Jobs Status


  1. package com.oimacademy.scheduler;
  2. import com.oimacademy.connection.Platform;
  3. import oracle.iam.scheduler.api.SchedulerService;
  4. import oracle.iam.scheduler.exception.IncorrectScheduleTaskDefinationException;
  5. import oracle.iam.scheduler.exception.SchedulerException;
  6. import oracle.iam.scheduler.vo.JobDetails;
  7. import oracle.iam.scheduler.vo.ScheduledTask;
  8. /**
  9.  *
  10.  *
  11.  */
  12. public class SchedulerJobsStatus {
  13.      SchedulerService schedulerService = Platform.getService(SchedulerService.class);
  14.     public void getDetails() throws IncorrectScheduleTaskDefinationException{
  15.          ScheduledTask task=schedulerService.lookupScheduledTask("LDAP Role Hierarchy Reconciliation");
  16.          System.out.println(""+task.getParameters());
  17.     }    
  18.     public void getJobStatusEnable_OR_Disbale() throws SchedulerException{       
  19.        //String[] taskNames = schedulerService.getAllJobs();
  20.         String[] taskNames =schedulerService.getJobs("LDAP Role Hierarchy Reconciliation");
  21.      if ((taskNames != null) && (taskNames.length != 0)) {
  22.        for (String taskname : taskNames) {
  23.          JobDetails eachTaskDetail = schedulerService.getJobDetail(taskname);
  24.             System.out.println(eachTaskDetail.getCronScheduleType());
  25.             System.out.println(eachTaskDetail.getJobListener());
  26.             System.out.println(eachTaskDetail.getJobScheduleType());        
  27.          if(eachTaskDetail.isTaskStatus()){
  28.                 System.out.println( "  Name  of Task Is : '" + eachTaskDetail.getName() +"' nad it is in ENABLE State. ");
  29.          }else{
  30.                 System.out.println( "  Name  of Task Is : '" + eachTaskDetail.getName() +"' nad it is in "+eachTaskDetail.isTaskStatus()+" DISABLE State. ");
  31.          }
  32.          //to enable/disable a job true/false
  33.         /*  eachTaskDetail.setTaskStatus(true);
  34.          
  35.            try {
  36.                schedulerService.updateJob(eachTaskDetail);
  37.            } catch (RequiredParameterNotSetException ex) {
  38.                Logger.getLogger(SchedulerJobsStatus.class.getName()).log(Level.SEVERE, null, ex);
  39.            } catch (ParameterValueTypeNotSupportedException ex) {
  40.                Logger.getLogger(SchedulerJobsStatus.class.getName()).log(Level.SEVERE, null, ex);
  41.            } catch (IncorrectScheduleTaskDefinationException ex) {
  42.                Logger.getLogger(SchedulerJobsStatus.class.getName()).log(Level.SEVERE, null, ex);
  43.            } catch (StaleDataException ex) {
  44.                Logger.getLogger(SchedulerJobsStatus.class.getName()).log(Level.SEVERE, null, ex);
  45.            } catch (LastModifyDateNotSetException ex) {
  46.                Logger.getLogger(SchedulerJobsStatus.class.getName()).log(Level.SEVERE, null, ex);
  47.            } catch (SchedulerAccessDeniedException ex) {
  48.                Logger.getLogger(SchedulerJobsStatus.class.getName()).log(Level.SEVERE, null, ex);
  49.            } */
  50.        }  
  51.      } 
  52.     }
  53.     public static void main(String[] args) throws Exception{
  54.   new SchedulerJobsStatus().getJobStatusEnable_OR_Disbale();                
  55.                 //new SchedulerJobsStatus().getDetails();
  56.   }    
  57. }

No comments:

Post a Comment