Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2018 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.internet2.middleware.grouper.app.loader;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.hibernate.type.LongType;
import org.hibernate.type.StringType;
import org.quartz.DisallowConcurrentExecution;
import edu.internet2.middleware.grouper.GrouperSession;
import edu.internet2.middleware.grouper.app.loader.db.Hib3GrouperLoaderLog;
import edu.internet2.middleware.grouper.exception.GrouperSessionException;
import edu.internet2.middleware.grouper.hibernate.HibUtils;
import edu.internet2.middleware.grouper.hibernate.HibernateSession;
import edu.internet2.middleware.grouper.misc.GrouperSessionHandler;
import edu.internet2.middleware.grouper.util.GrouperUtil;
import edu.internet2.middleware.grouperClient.collections.MultiKey;
import edu.internet2.middleware.grouperClient.jdbc.GcDbAccess;
import edu.internet2.middleware.grouperClient.util.GrouperClientUtils;
/**
* schedule quartz daemon
*/
@DisallowConcurrentExecution
public class GrouperDaemonSchedulerCheck extends OtherJobBase {
/**
* logger
*/
private static final Log LOG = GrouperUtil.getLog(GrouperDaemonSchedulerCheck.class);
/**
* run the daemon
* @param args
*/
public static void main(String[] args) {
runDaemonStandalone();
}
private static Thread daemonSchedulerCheckThread = new Thread(new Runnable() {
@Override
public void run() {
try {
int rando3_8 = 3 + (int)Math.round((Math.random() * 5.0));
// sleep a few minutes after daemon starts up
Thread.sleep(1000 * 60 * rando3_8);
} catch (InterruptedException ie) {
return;
} catch (Exception e) {
LOG.error("error in scheduler check thread start", e);
// continue
}
while (true) {
try {
int maxMinutesSinceSuccess = GrouperLoaderConfig.retrieveConfig().propertyValueInt("otherJob.schedulerCheckDaemon.maxMinutesSinceSuccess", 35);
// dont worry about it
if (maxMinutesSinceSuccess <= 0) {
return;
}
Thread.sleep(1000*60*maxMinutesSinceSuccess+1);
runDaemonSchedulerCheckNowIfHasntRunRecently();
} catch (InterruptedException ie) {
return;
} catch (Exception e) {
LOG.error("error in scheduler check thread", e);
// continue
}
}
}
});
/**
* if the thread isnt running, and is supposed to run, then start it
*/
public static void startDaemonSchedulerCheckThreadIfNeeded() {
int maxMinutesSinceSuccess = GrouperLoaderConfig.retrieveConfig().propertyValueInt("otherJob.schedulerCheckDaemon.maxMinutesSinceSuccess", 35);
// dont worry about it
if (maxMinutesSinceSuccess <= 0) {
return;
}
if (daemonSchedulerCheckThread.isAlive()) {
return;
}
daemonSchedulerCheckThread.setDaemon(true);
daemonSchedulerCheckThread.start();
}
/**
* run standalone
*/
public static void runDaemonStandalone() {
GrouperSession.internal_callbackRootGrouperSession(new GrouperSessionHandler() {
@Override
public Object callback(GrouperSession grouperSession) throws GrouperSessionException {
String jobName = "OTHER_JOB_schedulerCheckDaemon";
GrouperLoader.runOnceByJobName(grouperSession, jobName);
return null;
}
});
// Hib3GrouperLoaderLog hib3GrouperLoaderLog = new Hib3GrouperLoaderLog();
//
// hib3GrouperLoaderLog.setHost(GrouperUtil.hostname());
//
// hib3GrouperLoaderLog.setJobName(jobName);
// hib3GrouperLoaderLog.setJobType(GrouperLoaderType.OTHER_JOB.name());
// hib3GrouperLoaderLog.setStatus(GrouperLoaderStatus.STARTED.name());
// hib3GrouperLoaderLog.store();
//
// OtherJobInput otherJobInput = new OtherJobInput();
// otherJobInput.setJobName(jobName);
// otherJobInput.setHib3GrouperLoaderLog(hib3GrouperLoaderLog);
// otherJobInput.setGrouperSession(grouperSession);
// new GrouperDaemonSchedulerCheck().run(otherJobInput);
//
// hib3GrouperLoaderLog.setStatus(GrouperLoaderStatus.SUCCESS.name());
// hib3GrouperLoaderLog.store();
}
public static void runDaemonSchedulerCheckNowIfHasntRunRecently() {
if (!Hib3GrouperLoaderLog.hasRecentDaemonSchedulerCheck()) {
LOG.error("Scheduler check daemon did not run from quartz!!!!! running by fallback thread");
runDaemonStandalone();
}
}
/**
* @see edu.internet2.middleware.grouper.app.loader.OtherJobBase#run(edu.internet2.middleware.grouper.app.loader.OtherJobBase.OtherJobInput)
*/
@Override
public OtherJobOutput run(OtherJobInput otherJobInput) {
boolean runNow = GrouperLoader.isJobRunningAsRunNow("OTHER_JOB_schedulerCheckDaemon");
handleBlockedAndAcquiredStates(otherJobInput, runNow);
GrouperDaemonUtils.stopProcessingIfJobPaused();
handleErrorState(otherJobInput, runNow);
GrouperDaemonUtils.stopProcessingIfJobPaused();
handleMissingTriggers(otherJobInput, runNow);
GrouperDaemonUtils.stopProcessingIfJobPaused();
handleJobsWhereJvmDied(otherJobInput);
GrouperDaemonUtils.stopProcessingIfJobPaused();
LOG.info("GrouperDaemonSchedulerCheck finished successfully.");
return null;
}
private void handleJobsWhereJvmDied(OtherJobInput otherJobInput) {
if (!GrouperLoaderConfig.retrieveConfig().propertyValueBoolean("schedulerCheckDaemon.handleJobsWhereJvmDied", true)) {
otherJobInput.getHib3GrouperLoaderLog().appendJobMessage("Skipping handleJobsWhereJvmDied. ");
return;
}
// has status of STARTED or RUNNING
// AND
// - last_updated is in the last 30 seconds
// OR
// - theres a fired triggers with job name that matches
// OR
// - theres a fired triggers with trigger name that matches and the triggers table has a job name that matches
// - AND the triggers instance name matches a scheduler that is alive
// then the job is running
// last checkin in last 50 seconds
long lastCheckinTime = System.currentTimeMillis() - 50000;
List