// Path: build-service/src/main/java/com/ccoe/build/alerts/devx/DevxScheduler.java
// public class DevxScheduler {
// 	
// 	public void run() throws Exception {
// 		Scheduler scheduler  = StdSchedulerFactory.getDefaultScheduler();
// 		JobDetail devxJob = newJob(DevxReportJob.class).withIdentity("devxJob", "group3").build();
// 		
// 		Trigger devxTrigger = newTrigger()
// 				.withIdentity("devxTrigger", "group3")
// 				.withSchedule(cronSchedule(ServiceConfig.get("scheduler.devx.time"))).build();
// 		
// 		scheduler.scheduleJob(devxJob, devxTrigger);
// 		scheduler.start();
// 	}
// 
// }
// 
// Path: build-service/src/main/java/com/ccoe/build/alerts/pfdash/PfDashScheduler.java
// public class PfDashScheduler {
// 	public void run() throws Exception {
// 		Scheduler scheduler  = StdSchedulerFactory.getDefaultScheduler();
// 		JobDetail pfDashJob = newJob(PfDashJob.class)
// 				.withIdentity("pfDashJob", "group3").build();
// 		
// 		Trigger pdDashTrigger = newTrigger()
// 				.withIdentity("pdDashTrigger", "group3")
// 				.withSchedule(cronSchedule(ServiceConfig.get("scheduler.pfdash.time"))).build();
// 		
// 		scheduler.scheduleJob(pfDashJob, pdDashTrigger);
// 		scheduler.start();
// 	}
// }
// 
// Path: core/src/main/java/com/ccoe/build/service/config/BuildServiceConfig.java
// public class BuildServiceConfig {
// 
// 	public BuildServiceConfigBean get(String configName) {
// 		Client client = ClientBuilder.newClient(new ClientConfig());
// 		client.register(JacksonFeature.class);
// 
// 		String target = "http://${HOSTNAME}/build-service/webapi/";
// 		String path = "/config/" + configName;
// 		BuildServiceConfigBean configBean = client.target(target).path(path).request().get(BuildServiceConfigBean.class);
// 		
// 		return configBean;
// 	}
// 	
// 	public static void main(String[] args) {
// 		//System.out.println(new BuildServiceConfig().get("${CONFIG.NAME}").isGlobalSwitch());
// 	}
// }
// 
// Path: build-service/src/main/java/com/ccoe/build/tracking/TrackingScheduler.java
// public class TrackingScheduler {
// 
// 	public void run() throws Exception {
//         System.out.println("[INFO] Running TrackingScheduler...   ");
// 		// Grab the Scheduler instance from the Factory
// 		Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
// 
// 		// define the job and tie it to our BatchUpdateReportJob class
// 		JobDetail batchUpdateDurationJob = newJob(BatchUpdateDurationJob.class)
// 				.withIdentity("batchUpdateDurationJob", "group1").build();
// 		
// 		JobDetail batchUpdateCategoryJob = newJob(BatchUpdateCategoryJob.class)
// 				.withIdentity("batchUpdateCategoryJob", "group1").build();
// 
//     	// Trigger the job to run now, and then repeat every 24 hours
//         Trigger budTrigger = newTrigger()
//                 .withIdentity("batchUpdateDurationTrig", "group1")
//                 .withSchedule(cronSchedule(ServiceConfig.get("scheduler.batchUpdateDuration.time"))).build();
//         
//         Trigger bucTrigger = newTrigger()
//                 .withIdentity("batchUpdateCategoryTrig", "group1")
//                 .withSchedule(cronSchedule(ServiceConfig.get("scheduler.batchUpdateCategory.time"))).build();
// 
// 		// Tell quartz to schedule the job using our trigger
// 		scheduler.scheduleJob(batchUpdateDurationJob, budTrigger);
// 		scheduler.scheduleJob(batchUpdateCategoryJob, bucTrigger);
// 
// 		// and start it off
// 		scheduler.start();
// 		System.out.println("[INFO] TrackingScheduler started.");
// 	}
// 
// 	public static void main(String[] args) {
// 		TrackingScheduler scheduler = new TrackingScheduler();
// 		try {
// 			scheduler.run();
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 	}
// }


import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.ccoe.build.alerts.devx.DevxScheduler;
import com.ccoe.build.alerts.pfdash.PfDashScheduler;
import com.ccoe.build.service.config.BuildServiceConfig;
import com.ccoe.build.tracking.TrackingScheduler;
		
		BuildServiceScheduler.contextPath = outputPath.getAbsoluteFile();
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("BuildServiceScheduler exit.");
	}

	@Override
	public void contextInitialized(ServletContextEvent contextEvent) {
		String path = contextEvent.getServletContext().getRealPath("generated-source");
		setContextPath(path);
		
		System.out.println("BuildServiceScheduler init start. output path: " + path);
		
		if (isSchedulerEnabled()) {
			PfDashScheduler pfDashScheduler = new PfDashScheduler();
			DevxScheduler devxScheduler = new DevxScheduler();

			try {
				pfDashScheduler.run();
				devxScheduler.run();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		else {
			System.out.println("Scheduler is disabled on this server.");
			
// Path: build-service/src/main/java/com/ccoe/build/alerts/devx/DevxScheduler.java
// public class DevxScheduler {
// 	
// 	public void run() throws Exception {
// 		Scheduler scheduler  = StdSchedulerFactory.getDefaultScheduler();
// 		JobDetail devxJob = newJob(DevxReportJob.class).withIdentity("devxJob", "group3").build();
// 		
// 		Trigger devxTrigger = newTrigger()
// 				.withIdentity("devxTrigger", "group3")
// 				.withSchedule(cronSchedule(ServiceConfig.get("scheduler.devx.time"))).build();
// 		
// 		scheduler.scheduleJob(devxJob, devxTrigger);
// 		scheduler.start();
// 	}
// 
// }
// 
// Path: build-service/src/main/java/com/ccoe/build/alerts/pfdash/PfDashScheduler.java
// public class PfDashScheduler {
// 	public void run() throws Exception {
// 		Scheduler scheduler  = StdSchedulerFactory.getDefaultScheduler();
// 		JobDetail pfDashJob = newJob(PfDashJob.class)
// 				.withIdentity("pfDashJob", "group3").build();
// 		
// 		Trigger pdDashTrigger = newTrigger()
// 				.withIdentity("pdDashTrigger", "group3")
// 				.withSchedule(cronSchedule(ServiceConfig.get("scheduler.pfdash.time"))).build();
// 		
// 		scheduler.scheduleJob(pfDashJob, pdDashTrigger);
// 		scheduler.start();
// 	}
// }
// 
// Path: core/src/main/java/com/ccoe/build/service/config/BuildServiceConfig.java
// public class BuildServiceConfig {
// 
// 	public BuildServiceConfigBean get(String configName) {
// 		Client client = ClientBuilder.newClient(new ClientConfig());
// 		client.register(JacksonFeature.class);
// 
// 		String target = "http://${HOSTNAME}/build-service/webapi/";
// 		String path = "/config/" + configName;
// 		BuildServiceConfigBean configBean = client.target(target).path(path).request().get(BuildServiceConfigBean.class);
// 		
// 		return configBean;
// 	}
// 	
// 	public static void main(String[] args) {
// 		//System.out.println(new BuildServiceConfig().get("${CONFIG.NAME}").isGlobalSwitch());
// 	}
// }
// 
// Path: build-service/src/main/java/com/ccoe/build/tracking/TrackingScheduler.java
// public class TrackingScheduler {
// 
// 	public void run() throws Exception {
//         System.out.println("[INFO] Running TrackingScheduler...   ");
// 		// Grab the Scheduler instance from the Factory
// 		Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
// 
// 		// define the job and tie it to our BatchUpdateReportJob class
// 		JobDetail batchUpdateDurationJob = newJob(BatchUpdateDurationJob.class)
// 				.withIdentity("batchUpdateDurationJob", "group1").build();
// 		
// 		JobDetail batchUpdateCategoryJob = newJob(BatchUpdateCategoryJob.class)
// 				.withIdentity("batchUpdateCategoryJob", "group1").build();
// 
//     	// Trigger the job to run now, and then repeat every 24 hours
//         Trigger budTrigger = newTrigger()
//                 .withIdentity("batchUpdateDurationTrig", "group1")
//                 .withSchedule(cronSchedule(ServiceConfig.get("scheduler.batchUpdateDuration.time"))).build();
//         
//         Trigger bucTrigger = newTrigger()
//                 .withIdentity("batchUpdateCategoryTrig", "group1")
//                 .withSchedule(cronSchedule(ServiceConfig.get("scheduler.batchUpdateCategory.time"))).build();
// 
// 		// Tell quartz to schedule the job using our trigger
// 		scheduler.scheduleJob(batchUpdateDurationJob, budTrigger);
// 		scheduler.scheduleJob(batchUpdateCategoryJob, bucTrigger);
// 
// 		// and start it off
// 		scheduler.start();
// 		System.out.println("[INFO] TrackingScheduler started.");
// 	}
// 
// 	public static void main(String[] args) {
// 		TrackingScheduler scheduler = new TrackingScheduler();
// 		try {
// 			scheduler.run();
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 	}
// }


// Path: build-service/src/main/java/com/ccoe/build/service/BuildServiceScheduler.java
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.ccoe.build.alerts.devx.DevxScheduler;
import com.ccoe.build.alerts.pfdash.PfDashScheduler;
import com.ccoe.build.service.config.BuildServiceConfig;
import com.ccoe.build.tracking.TrackingScheduler;

		
		BuildServiceScheduler.contextPath = outputPath.getAbsoluteFile();
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("BuildServiceScheduler exit.");
	}

	@Override
	public void contextInitialized(ServletContextEvent contextEvent) {
		String path = contextEvent.getServletContext().getRealPath("generated-source");
		setContextPath(path);
		
		System.out.println("BuildServiceScheduler init start. output path: " + path);
		
		if (isSchedulerEnabled()) {
			PfDashScheduler pfDashScheduler = new PfDashScheduler();
			DevxScheduler devxScheduler = new DevxScheduler();

			try {
				pfDashScheduler.run();
				devxScheduler.run();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		else {
			System.out.println("Scheduler is disabled on this server.");
			
			TrackingScheduler tScheduler = new TrackingScheduler();