// 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;
/*
Copyright [2013-2014] eBay Software Foundation

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 com.ccoe.build.service;




public class BuildServiceScheduler implements ServletContextListener {
	public static File contextPath;
	
	public static void setContextPath(String contextPath) {
		File outputPath = new File(contextPath);
		
		if (!outputPath.exists()) {
			outputPath.mkdirs();
		}
		
		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()) {
// 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;

/*
Copyright [2013-2014] eBay Software Foundation

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 com.ccoe.build.service;




public class BuildServiceScheduler implements ServletContextListener {
	public static File contextPath;
	
	public static void setContextPath(String contextPath) {
		File outputPath = new File(contextPath);
		
		if (!outputPath.exists()) {
			outputPath.mkdirs();
		}
		
		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();