public void clear( JobConfiguration jobConfiguration ) { notificationsWithType.get( jobConfiguration.getJobType() ).remove( jobConfiguration.getUid() ); summariesWithType.get( jobConfiguration.getJobType() ).remove( jobConfiguration.getUid() ); } }
public void addSummary( JobConfiguration jobConfiguration, Object summary ) { LinkedHashMap<String, Object> summaries = summariesWithType.get( jobConfiguration.getJobType() ); if ( summaries.size() >= MAX_POOL_TYPE_SIZE ) { String key = (String) summaries.keySet().toArray()[0]; summaries.remove( key ); } summaries.put( jobConfiguration.getUid(), summary ); }
public void add( JobConfiguration jobConfiguration, Notification notification ) { String uid = jobConfiguration.getUid(); LinkedHashMap<String, LinkedList<Notification>> uidNotifications = notificationsWithType .get( jobConfiguration.getJobType() ); LinkedList<Notification> notifications; if ( uidNotifications.containsKey( uid ) ) { notifications = uidNotifications.get( uid ); } else { notifications = new LinkedList<>(); } notifications.addFirst( notification ); if ( uidNotifications.size() >= MAX_POOL_TYPE_SIZE ) { String key = (String) uidNotifications.keySet().toArray()[0]; uidNotifications.remove( key ); } uidNotifications.put( uid, notifications ); notificationsWithType.put( jobConfiguration.getJobType(), uidNotifications ); }
public boolean isJobConfigurationRunning( JobConfiguration jobConfiguration ) { if ( jobConfiguration.isInMemoryJob() ) { return false; } return !jobConfiguration.isContinuousExecution() && runningJobConfigurations.stream().anyMatch( jobConfig -> jobConfig.getJobType().equals( jobConfiguration.getJobType() ) && !jobConfig.isContinuousExecution() ); }
@Override public Notifier notify( JobConfiguration id, NotificationLevel level, String message, boolean completed ) { if ( id != null && !(level != null && level.isOff()) ) { Notification notification = new Notification( level, id.getJobType(), new Date(), message, completed ); notificationMap.add( id, notification ); log.info( notification ); } return this; }
.forEach( configuration -> { List<JobConfiguration> jobConfigurationList = new ArrayList<>(); List<JobConfiguration> oldList = jobConfigurationForJobTypes.get( configuration.getJobType() ); if ( oldList != null ) jobConfigurationForJobTypes.put( configuration.getJobType(), jobConfigurationList ); } ); List<JobConfiguration> listForJobType = jobConfigurationForJobTypes.get( jobConfiguration.getJobType() );
@Override public Notifier clear( JobConfiguration id ) { if ( id != null ) { redisTemplate.delete( generateNotificationKey( id.getJobType(), id.getUid() ) ); redisTemplate.boundHashOps( generateSummaryKey( id.getJobType() ) ).delete( id.getUid() ); redisTemplate.boundZSetOps( generateNotificationOrderKey( id.getJobType() ) ).remove( id.getUid() ); redisTemplate.boundZSetOps( generateSummaryOrderKey( id.getJobType() ) ).remove( id.getUid() ); } return this; }
/** * Method which calls the execute method in the job. The job will run in this thread and finish, either with success * or with an exception. * * @param jobConfiguration the configuration to execute * @param schedulingManager a reference to the scheduling manager * @param clock refers to start time * @throws Exception if the job fails */ private void executeJob( JobConfiguration jobConfiguration, SchedulingManager schedulingManager, Clock clock ) throws Exception { log.debug( "Job '" + jobConfiguration.getName() + "' started" ); schedulingManager.getJob( jobConfiguration.getJobType() ).execute( jobConfiguration ); log.debug( "Job '" + jobConfiguration.getName() + "' executed successfully. Time used: " + clock.time() ); } }
@Override public Notifier notify( JobConfiguration id, NotificationLevel level, String message, boolean completed ) { if ( id != null && !(level != null && level.isOff()) ) { Notification notification = new Notification( level, id.getJobType(), new Date(), message, completed ); String notificationKey = generateNotificationKey( id.getJobType(), id.getUid() ); String notificationOrderKey = generateNotificationOrderKey( id.getJobType() ); Date now = new Date(); try { if ( redisTemplate.boundZSetOps( notificationOrderKey ).zCard() >= MAX_POOL_TYPE_SIZE ) { Set<String> deleteKeys = redisTemplate.boundZSetOps( notificationOrderKey ).range( 0, 0 ); redisTemplate.delete( deleteKeys ); redisTemplate.boundZSetOps( notificationOrderKey ).removeRange( 0, 0 ); } redisTemplate.boundZSetOps( notificationKey ).add( objectMapper.writeValueAsString( notification ), now.getTime() ); redisTemplate.boundZSetOps( notificationOrderKey ).add( id.getUid(), now.getTime() ); } catch ( JsonProcessingException ex ) { log.warn( String.format( NOTIFIER_ERROR, ex.getMessage() ) ); } log.info( notification ); } return this; }
public JobConfigurationWebMessageResponse( JobConfiguration jobConfiguration ) { this.name = jobConfiguration.getDisplayName(); this.id = jobConfiguration.getUid(); this.created = jobConfiguration.getCreated(); this.jobType = jobConfiguration.getJobType(); this.jobStatus = jobConfiguration.getJobStatus(); this.jobParameters = jobConfiguration.getJobParameters(); this.relativeNotifierEndpoint = "/api/system/tasks/" + this.jobType + "/" + this.id; }
String summaryKey = generateSummaryKey( id.getJobType() ); try String existingSummaryTypeStr = redisTemplate.boundValueOps( generateSummaryTypeKey( id.getJobType() ) ) .get(); if ( existingSummaryTypeStr == null ) redisTemplate.boundValueOps( generateSummaryTypeKey( id.getJobType() ) ) .set( jobSummaryType.getName() ); String summaryOrderKey = generateSummaryOrderKey( id.getJobType() ); if ( redisTemplate.boundZSetOps( summaryOrderKey ).zCard() >= MAX_POOL_TYPE_SIZE )
@Override public int compareTo( IdentifiableObject jobConfiguration ) { JobConfiguration compareJobConfiguration = (JobConfiguration) jobConfiguration; if ( jobType != compareJobConfiguration.getJobType() ) { return -1; } if ( jobStatus != compareJobConfiguration.getJobStatus() ) { return -1; } if ( jobParameters != compareJobConfiguration.getJobParameters() ) { return -1; } if ( continuousExecution != compareJobConfiguration.isContinuousExecution() ) { return -1; } if ( enabled != compareJobConfiguration.isEnabled() ) { return -1; } if ( !cronExpression.equals( compareJobConfiguration.getCronExpression() ) ) { return 1; } return -1; }
.add( new ErrorReport( JobConfiguration.class, ErrorCode.E7003, jobConfiguration.getJobType() ) ); Job job = schedulingManager.getJob( jobConfiguration.getJobType() ); ErrorReport jobValidation = job.validate(); if ( jobValidation != null )
String.format( NOT_LEADER_SKIP_LOG, jobConfiguration.getJobType(), jobConfiguration.getName() ) ); return; "Job '" + jobConfiguration.getName() + "' failed, jobtype '" + jobConfiguration.getJobType() + "' is already running." ); "Job '" + jobConfiguration.getName() + "' failed, jobtype '" + jobConfiguration.getJobType() + "' is already running.", new Exception( "Job '" + jobConfiguration.getName() + "' failed" ) );