Package org.pentaho.platform.api.scheduler2.Job

Examples of org.pentaho.platform.api.scheduler2.Job.JobState


      jobTrigger = simpleJobTrigger;

    } else if ( scheduleRequest.getComplexJobTrigger() != null ) {

      ComplexJobTriggerProxy proxyTrigger = scheduleRequest.getComplexJobTrigger();
      ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
      complexJobTrigger.setStartTime( proxyTrigger.getStartTime() );
      complexJobTrigger.setEndTime( proxyTrigger.getEndTime() );

      if ( proxyTrigger.getDaysOfWeek().length > 0 ) {
        if ( proxyTrigger.getWeeksOfMonth().length > 0 ) {
          for ( int dayOfWeek : proxyTrigger.getDaysOfWeek() ) {
            for ( int weekOfMonth : proxyTrigger.getWeeksOfMonth() ) {

              QualifiedDayOfWeek qualifiedDayOfWeek = new QualifiedDayOfWeek();
              qualifiedDayOfWeek.setDayOfWeek( DayOfWeek.values()[dayOfWeek] );

              if ( weekOfMonth == JobScheduleRequest.LAST_WEEK_OF_MONTH ) {
                qualifiedDayOfWeek.setQualifier( DayOfWeekQualifier.LAST );
              } else {
                qualifiedDayOfWeek.setQualifier( DayOfWeekQualifier.values()[weekOfMonth] );
              }
              complexJobTrigger.addDayOfWeekRecurrence( qualifiedDayOfWeek );
            }
          }
        } else {
          for ( int dayOfWeek : proxyTrigger.getDaysOfWeek() ) {
            complexJobTrigger.addDayOfWeekRecurrence( dayOfWeek + 1 );
          }
        }
      } else if ( proxyTrigger.getDaysOfMonth().length > 0 ) {

        for ( int dayOfMonth : proxyTrigger.getDaysOfMonth() ) {
          complexJobTrigger.addDayOfMonthRecurrence( dayOfMonth );
        }
      }

      for ( int month : proxyTrigger.getMonthsOfYear() ) {
        complexJobTrigger.addMonthlyRecurrence( month + 1 );
      }

      for ( int year : proxyTrigger.getYears() ) {
        complexJobTrigger.addYearlyRecurrence( year );
      }

      Calendar calendar = Calendar.getInstance();
      calendar.setTime( complexJobTrigger.getStartTime() );
      complexJobTrigger.setHourlyRecurrence( calendar.get( Calendar.HOUR_OF_DAY ) );
      complexJobTrigger.setMinuteRecurrence( calendar.get( Calendar.MINUTE ) );
      complexJobTrigger.setUiPassParam( scheduleRequest.getComplexJobTrigger().getUiPassParam() );
      jobTrigger = complexJobTrigger;

    } else if ( scheduleRequest.getCronJobTrigger() != null ) {

      if ( scheduler instanceof QuartzScheduler ) {
        String cronString = scheduleRequest.getCronJobTrigger().getCronString();

        String delims = "[ ]+"; //$NON-NLS-1$
        String[] tokens = cronString.split( delims );
        if ( tokens.length < 7 ) {
          cronString += " *";
        }

        ComplexJobTrigger complexJobTrigger = QuartzScheduler.createComplexTrigger( cronString );
        complexJobTrigger.setStartTime( scheduleRequest.getCronJobTrigger().getStartTime() );
        complexJobTrigger.setEndTime( scheduleRequest.getCronJobTrigger().getEndTime() );
        complexJobTrigger.setUiPassParam( scheduleRequest.getCronJobTrigger().getUiPassParam() );
        jobTrigger = complexJobTrigger;
      } else {
        throw new IllegalArgumentException();
      }
    }
View Full Code Here


      simpleJobTrigger.setRepeatInterval( interval );
      simpleJobTrigger.setRepeatCount( simpleTrigger.getRepeatCount() );
      job.setJobTrigger( simpleJobTrigger );
    } else if ( trigger instanceof CronTrigger ) {
      CronTrigger cronTrigger = (CronTrigger) trigger;
      ComplexJobTrigger complexJobTrigger = createComplexTrigger( cronTrigger.getCronExpression() );
      complexJobTrigger.setUiPassParam( (String) job.getJobParams().get( RESERVEDMAPKEY_UIPASSPARAM ) );
      complexJobTrigger.setCronString( ( (CronTrigger) trigger ).getCronExpression() );
      job.setJobTrigger( complexJobTrigger );
      if ( trigger.getCalendarName() != null ) {
        Calendar calendar = scheduler.getCalendar( trigger.getCalendarName() );
        if ( calendar instanceof QuartzSchedulerAvailability ) {
          QuartzSchedulerAvailability quartzSchedulerAvailability = (QuartzSchedulerAvailability) calendar;
          complexJobTrigger.setStartTime( quartzSchedulerAvailability.getStartTime() );
          complexJobTrigger.setEndTime( quartzSchedulerAvailability.getEndTime() );
        }
      }
      complexJobTrigger.setCronString( ( (CronTrigger) trigger ).getCronExpression() );
    }

    int triggerState = scheduler.getTriggerState( job.getJobId(), groupName );
    switch ( triggerState ) {
      case Trigger.STATE_NORMAL:
View Full Code Here

    Principal p = SecurityHelper.getInstance().getAuthentication();
    return ( p == null ) ? null : p.getName();
  }

  public static ComplexJobTrigger createComplexTrigger( String cronExpression ) {
    ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
    complexJobTrigger.setHourlyRecurrence( (ITimeRecurrence) null );
    complexJobTrigger.setMinuteRecurrence( (ITimeRecurrence) null );
    complexJobTrigger.setSecondRecurrence( (ITimeRecurrence) null );

    for ( ITimeRecurrence recurrence : parseRecurrence( cronExpression, 6 ) ) {
      complexJobTrigger.addYearlyRecurrence( recurrence );
    }
    for ( ITimeRecurrence recurrence : parseRecurrence( cronExpression, 4 ) ) {
      complexJobTrigger.addMonthlyRecurrence( recurrence );
    }
    List<ITimeRecurrence> dayOfWeekRecurrences = parseDayOfWeekRecurrences( cronExpression );
    List<ITimeRecurrence> dayOfMonthRecurrences = parseRecurrence( cronExpression, 3 );
    if ( ( dayOfWeekRecurrences.size() > 0 ) && ( dayOfMonthRecurrences.size() == 0 ) ) {
      for ( ITimeRecurrence recurrence : dayOfWeekRecurrences ) {
        complexJobTrigger.addDayOfWeekRecurrence( recurrence );
      }
    } else if ( ( dayOfWeekRecurrences.size() == 0 ) && ( dayOfMonthRecurrences.size() > 0 ) ) {
      for ( ITimeRecurrence recurrence : dayOfMonthRecurrences ) {
        complexJobTrigger.addDayOfMonthRecurrence( recurrence );
      }
    }
    for ( ITimeRecurrence recurrence : parseRecurrence( cronExpression, 2 ) ) {
      complexJobTrigger.addHourlyRecurrence( recurrence );
    }
    for ( ITimeRecurrence recurrence : parseRecurrence( cronExpression, 1 ) ) {
      complexJobTrigger.addMinuteRecurrence( recurrence );
    }
    for ( ITimeRecurrence recurrence : parseRecurrence( cronExpression, 0 ) ) {
      complexJobTrigger.addSecondRecurrence( recurrence );
    }
    return complexJobTrigger;
  }
View Full Code Here

    SchedulerOutputPathResolver schedulerOutputPathResolver = mock( SchedulerOutputPathResolver.class );
    doReturn( "outputFile" ).when( schedulerOutputPathResolver ).resolveOutputFilePath();

    SimpleJobTrigger simpleJobTrigger = mock( SimpleJobTrigger.class );
    ComplexJobTriggerProxy complexJobTriggerProxy = mock( ComplexJobTriggerProxy.class );
    CronJobTrigger cronJobTrigger = mock( CronJobTrigger.class );

    RepositoryFile repositoryFile = mock( RepositoryFile.class );
    doReturn( "file.ext" ).when( repositoryFile ).getName();

    Map<String, Serializable> metadata = mock( Map.class );
View Full Code Here

    // remove the scheduling infrastructure properties
    params.remove( QuartzScheduler.RESERVEDMAPKEY_ACTIONCLASS );
    params.remove( QuartzScheduler.RESERVEDMAPKEY_ACTIONID );
    params.remove( QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER );
    final IBackgroundExecutionStreamProvider streamProvider =
        (IBackgroundExecutionStreamProvider) params.get( QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER );
    params.remove( QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER );
    params.remove( QuartzScheduler.RESERVEDMAPKEY_UIPASSPARAM );
    // The scheduled_fire_time is useful only to the blockoutAction see PDI-10171
    if ( actionBean instanceof BlockoutAction ) {
      params.put( IBlockoutManager.SCHEDULED_FIRE_TIME, context.getScheduledFireTime() );
    }

    if ( log.isDebugEnabled() ) {
      log.debug( MessageFormat.format(
          "Scheduling system invoking action {0} as user {1} with params [ {2} ]", actionBean //$NON-NLS-1$
              .getClass().getName(), actionUser, QuartzScheduler.prettyPrintMap( params ) ) );
    }

    Callable<Boolean> actionBeanRunner = new Callable<Boolean>() {

      public Boolean call() throws Exception {
        LocaleHelper.setLocaleOverride( (Locale) params.get( LocaleHelper.USER_LOCALE_PARAM ) );
        // sync job params to the action bean
        ActionHarness actionHarness = new ActionHarness( actionBean );
        boolean updateJob = false;

        final Map<String, Object> actionParams = new HashMap<String, Object>();
        actionParams.putAll( params );
        if ( streamProvider != null ) {
          actionParams.put( "inputStream", streamProvider.getInputStream() );
        }
        actionHarness.setValues( actionParams, new ActionSequenceCompatibilityFormatter() );

        if ( actionBean instanceof IVarArgsAction ) {
          actionParams.remove( "inputStream" );
          actionParams.remove( "outputStream" );
          ( (IVarArgsAction) actionBean ).setVarArgs( actionParams );
        }

        boolean waitForFileCreated = false;
        OutputStream stream = null;
       
        if ( streamProvider != null ) {
          actionParams.remove( "inputStream" );
          if ( actionBean instanceof IStreamingAction ) {
            streamProvider.setStreamingAction( (IStreamingAction) actionBean );
          }

          // BISERVER-9414 - validate that output path still exist
          SchedulerOutputPathResolver resolver =
              new SchedulerOutputPathResolver( streamProvider.getOutputPath(), actionUser );
          String outputPath = resolver.resolveOutputFilePath();
          actionParams.put( "useJcr", Boolean.TRUE );
          actionParams.put( "jcrOutputPath", outputPath.substring( 0, outputPath.lastIndexOf( "/" ) ) );

          if ( !outputPath.equals( streamProvider.getOutputPath() ) ) {
            streamProvider.setOutputFilePath( outputPath ); // set fallback path
            updateJob = true; // job needs to be deleted and recreated with the new output path
          }

          stream = streamProvider.getOutputStream();
          if ( stream instanceof ISourcesStreamEvents ) {
            ( (ISourcesStreamEvents) stream ).addListener( new IStreamListener() {
              public void fileCreated( final String filePath ) {
                synchronized ( lock ) {
                  outputFilePath = filePath;
                  lock.notifyAll();
                }
              }
            } );
            waitForFileCreated = true;
          }
          actionParams.put( "outputStream", stream );
          // The lineage_id is only useful for the metadata and not needed at this level see PDI-10171
          actionParams.remove( QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID );
          actionHarness.setValues( actionParams );
        }

        actionBean.execute();

        if (stream != null) {
          IOUtils.closeQuietly( stream );
        }

        if ( waitForFileCreated ) {
          synchronized ( lock ) {
            if ( outputFilePath == null ) {
              lock.wait();
            }
          }
          sendEmail( actionParams, params, outputFilePath );
        }
       
        return updateJob;
      }
    };

    boolean requiresUpdate = false;
    if ( ( actionUser == null ) || ( actionUser.equals( "system session" ) ) ) { //$NON-NLS-1$
      // For now, don't try to run quartz jobs as authenticated if the user
      // that created the job is a system user. See PPP-2350
      requiresUpdate = SecurityHelper.getInstance().runAsAnonymous( actionBeanRunner );
    } else {
      try {
        requiresUpdate = SecurityHelper.getInstance().runAsUser( actionUser, actionBeanRunner );
      } catch ( Throwable t ) {
        Object restartFlag = jobParams.get( QuartzScheduler.RESERVEDMAPKEY_RESTART_FLAG );
        if ( restartFlag == null ) {
          final SimpleJobTrigger trigger = new SimpleJobTrigger( new Date(), null, 0, 0 );
          final Class<IAction> iaction = (Class<IAction>) actionBean.getClass();
          // recreate the job in the context of the original creator
          SecurityHelper.getInstance().runAsUser( actionUser, new Callable<Void>() {
            @Override
            public Void call() throws Exception {
              if(streamProvider != null) {
                streamProvider.setStreamingAction( null ); // remove generated content 
              }
              QuartzJobKey jobKey = QuartzJobKey.parse( context.getJobDetail().getName() );
              String jobName = jobKey.getJobName();
              jobParams.put( QuartzScheduler.RESERVEDMAPKEY_RESTART_FLAG, Boolean.TRUE );
              scheduler.createJob( jobName, iaction, jobParams, trigger, streamProvider );
              log.warn( "New RunOnce job created for " + jobName + " -> possible startup synchronization error" );
              return null;
            }
          } );
        } else {
          log.warn( "RunOnce already created, skipping" );
          throw new Exception( t );
        }
      }
    }

    scheduler.fireJobCompleted( actionBean, actionUser, params, streamProvider );

    if ( requiresUpdate ) {
      log.warn( "Output path for job: " + context.getJobDetail().getName() + " has changed. Job requires update" );
      try {
        final IJobTrigger trigger = scheduler.getJob( context.getJobDetail().getName() ).getJobTrigger();
        final Class<IAction> iaction = (Class<IAction>) actionBean.getClass();

        // remove job with outdated/invalid output path
        scheduler.removeJob( context.getJobDetail().getName() );

        // recreate the job in the context of the original creator
        SecurityHelper.getInstance().runAsUser( actionUser, new Callable<Void>() {
          @Override
          public Void call() throws Exception {
            streamProvider.setStreamingAction( null ); // remove generated content
            QuartzJobKey jobKey = QuartzJobKey.parse( context.getJobDetail().getName() );
            String jobName = jobKey.getJobName();
            org.pentaho.platform.api.scheduler2.Job j =
                scheduler.createJob( jobName, iaction, jobParams, trigger, streamProvider );
            log.warn( "New Job: " + j.getJobId() + " created" );
View Full Code Here

        List<Date> dates = new ArrayList<Date>();
        boolean endDateIsNull = jobTrigger.getEndTime() == null;
        Trigger trigger = QuartzScheduler.createQuartzTrigger( jobTrigger, new QuartzJobKey( "test", "test" ) ); //$NON-NLS-1$ //$NON-NLS-2$

        // add previous trigger (it might be currently active)
        IBlockoutManager manager = PentahoSystem.get( IBlockoutManager.class, "IBlockoutManager", null ); //$NON-NLS-1$;
        if ( manager != null ) {
          List<Job> blockouts = manager.getBlockOutJobs();
          for ( Job blockout : blockouts ) {
            if ( blockout.getLastRun() != null ) {
              dates.add( blockout.getLastRun() );
            }
          }
View Full Code Here

    IPentahoSession session = getSession();
    final String principalName = session.getName(); // this authentication wasn't matching with the job user name,
    // changed to get name via the current session
    final Boolean canAdminister = canAdminister( session );

    List<Job> jobs = getScheduler().getJobs( new IJobFilter() {
      public boolean accept( Job job ) {
        if ( canAdminister ) {
          return !IBlockoutManager.BLOCK_OUT_JOB_NAME.equals( job.getJobName() );
        }
        return principalName.equals( job.getUserName() );
View Full Code Here

        trigger );
  }

  protected void deleteJobIfNecessary() throws SchedulerException {
    IScheduler scheduler = PentahoSystem.get( IScheduler.class, "IScheduler2", null ); //$NON-NLS-1$
    IJobFilter filter = new IJobFilter() {
      public boolean accept( Job job ) {
        return job.getJobName().contains( EmbeddedVersionCheckSystemListener.VERSION_CHECK_JOBNAME );
      }
    };
View Full Code Here

  }

  @Override
  public List<Job> getBlockOutJobs() {
    try {
      List<Job> jobs = scheduler.getJobs( new IJobFilter() {
        public boolean accept( Job job ) {
          if ( BLOCK_OUT_JOB_NAME.equals( job.getJobName() ) ) {
            job.getJobTrigger().setDuration( ( (Number) job.getJobParams().get( DURATION_PARAM ) ).longValue() );
            return true;
          }
View Full Code Here

  public List<IJobTrigger> willBlockSchedules( IJobTrigger testBlockOutJobTrigger ) {
    List<IJobTrigger> blockedSchedules = new ArrayList<IJobTrigger>();

    List<Job> scheduledJobs = new ArrayList<Job>();
    try {
      scheduledJobs = this.scheduler.getJobs( new IJobFilter() {

        @Override
        public boolean accept( Job job ) {
          return !BLOCK_OUT_JOB_NAME.equals( job.getJobName() );
        }
View Full Code Here

TOP

Related Classes of org.pentaho.platform.api.scheduler2.Job.JobState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.