Skip to content

Commit

Permalink
Implement everydayrunner scheduler(#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
canberkizgi committed Dec 25, 2018
1 parent bfd4b51 commit 47149d2
Showing 1 changed file with 54 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;

import com.lbs.tedam.data.service.JobCommandService;
import com.lbs.tedam.data.service.JobDetailService;
import com.lbs.tedam.data.service.JobRunnerDetailCommandService;
Expand All @@ -28,6 +30,7 @@
import com.lbs.tedam.exception.localized.LocalizedException;
import com.lbs.tedam.jobrunner.manager.ClientMapService;
import com.lbs.tedam.jobrunner.manager.JobRunnerManager;
import com.lbs.tedam.jobrunner.manager.JobRunnerScheduler;
import com.lbs.tedam.jobrunner.service.BroadcastService;
import com.lbs.tedam.model.Client;
import com.lbs.tedam.model.Job;
Expand All @@ -52,8 +55,12 @@ public class BroadcastServiceImpl implements BroadcastService, HasLogger {
private final JobRunnerManager jobRunnerManager;
private final PropertyService propertyService;

public BroadcastServiceImpl(JobRunnerManager jobRunnerManager, ClientMapService clientMapService, JobService jobService, JobCommandService jobCommandService,
JobDetailService jobDetailService, JobRunnerDetailCommandService jobRunnerDetailCommandService, PropertyService propertyService) {
@Autowired
private JobRunnerScheduler jobRunnerScheduler;

public BroadcastServiceImpl(JobRunnerManager jobRunnerManager, ClientMapService clientMapService,
JobService jobService, JobCommandService jobCommandService, JobDetailService jobDetailService,
JobRunnerDetailCommandService jobRunnerDetailCommandService, PropertyService propertyService) {
this.jobRunnerManager = jobRunnerManager;
this.jobService = jobService;
this.jobCommandService = jobCommandService;
Expand All @@ -65,18 +72,20 @@ public BroadcastServiceImpl(JobRunnerManager jobRunnerManager, ClientMapService

/**
* this method startJobCommandOperations <br>
*
* @author Canberk.Erkmen
* @param jobCommandId
* @param commandStatusCode
* @param result
* @param description
* <br>
* @param description <br>
* @throws VersionParameterValueException
* @throws LocalizedException
*/
@Override
public void startJobCommandOperations(JobRunnerDetailCommand jobRunnerDetailCommand) throws VersionParameterValueException, LocalizedException {
JobCommand jobCommand = jobRunnerDetailCommandService.getJobCommandByJobRunnerDetailCommand(jobRunnerDetailCommand);
public void startJobCommandOperations(JobRunnerDetailCommand jobRunnerDetailCommand)
throws VersionParameterValueException, LocalizedException {
JobCommand jobCommand = jobRunnerDetailCommandService
.getJobCommandByJobRunnerDetailCommand(jobRunnerDetailCommand);
jobCommandService.updateJobCommand(jobCommand);
JobDetail jobDetail = jobDetailService.getById(jobCommand.getJobDetailId());
Job job = jobService.getById(jobDetail.getJobId());
Expand All @@ -89,7 +98,8 @@ public void startJobCommandOperations(JobRunnerDetailCommand jobRunnerDetailComm
if (CommandStatus.NOT_STARTED == jobDetail.getStatus()) {
startJobDetailInProgressOperations(jobDetail);
if (JobStatus.STARTED != job.getStatus()) {
jobService.updateJobStatusAndExecutedDateByJobId(jobDetail.getJobId(), JobStatus.STARTED, LocalDateTime.now(), null);
jobService.updateJobStatusAndExecutedDateByJobId(jobDetail.getJobId(), JobStatus.STARTED,
LocalDateTime.now(), null);
}
} else if (isJobDetailJobCommandListFinished(jobDetail)) {
startJobDetailCompletedOperations(jobDetail);
Expand All @@ -109,17 +119,26 @@ public void startJobCommandOperations(JobRunnerDetailCommand jobRunnerDetailComm

}

private void startTestRunOperations(JobRunnerDetailCommand jobRunnerDetailCommand, JobCommand jobCommand, JobDetail jobDetail, Job job)
throws VersionParameterValueException, LocalizedException {
jobRunnerDetailCommandService.createTestRunForTestCaseAndTestStep(jobRunnerDetailCommand, jobCommand, jobDetail, job);
private void startTestRunOperations(JobRunnerDetailCommand jobRunnerDetailCommand, JobCommand jobCommand,
JobDetail jobDetail, Job job) throws VersionParameterValueException, LocalizedException {
jobRunnerDetailCommandService.createTestRunForTestCaseAndTestStep(jobRunnerDetailCommand, jobCommand, jobDetail,
job);
}

private void startJobCompletedOperations(JobDetail jobDetail, Job job) throws LocalizedException {
getLogger().info("The job with id: " + jobDetail.getJobId() + " finished");
jobService.updateJobStatusAndExecutedDateByJobId(jobDetail.getJobId(), JobStatus.COMPLETED, job.getLastExecutedStartDate(), LocalDateTime.now());
jobService.resetJobPlannedDate(job.getId());
// String jobReportFilePath = propertyService.getPropertyByNameAndParameter(Constants.PROPERTY_CONFIG, Constants.PROPERTY_TEMP_FILE_PATH).getValue();
// jobReportService.createJobReportFile(jobDetail.getJobId(), jobReportFilePath);
jobService.updateJobStatusAndExecutedDateByJobId(jobDetail.getJobId(), JobStatus.COMPLETED,
job.getLastExecutedStartDate(), LocalDateTime.now());
if (job.getPlannedDate() != null && job.isRunEveryDay()) {
addOneDayMore(job);
} else {
jobService.resetJobPlannedDate(job.getId());
}
// String jobReportFilePath =
// propertyService.getPropertyByNameAndParameter(Constants.PROPERTY_CONFIG,
// Constants.PROPERTY_TEMP_FILE_PATH).getValue();
// jobReportService.createJobReportFile(jobDetail.getJobId(),
// jobReportFilePath);
// jobReportService.removeJobReportMap(jobDetail.getJobId());
jobRunnerManager.removeJobFromRunningJobs(job);
}
Expand All @@ -131,22 +150,26 @@ private void startJobDetailInProgressOperations(JobDetail jobDetail) throws Loca
}

private void startJobDetailCompletedOperations(JobDetail jobDetail) throws LocalizedException {
getLogger().info("The jobdetail with testSetId: " + jobDetail.getTestSet().getId() + " and with jobDetailId: " + jobDetail.getId() + " finished");
getLogger().info("The jobdetail with testSetId: " + jobDetail.getTestSet().getId() + " and with jobDetailId: "
+ jobDetail.getId() + " finished");
Client client = jobDetail.getClient();
jobDetail.setStatus(CommandStatus.COMPLETED);
jobDetail.getTestSet().setTestSetStatus(CommandStatus.COMPLETED);
jobDetail.getTestSet().setExecutionDateTime(LocalDateTime.now());
jobDetail.getJobCommands().clear();
getLogger().info("clientName : " + client.getName() + " clientId : " + client.getId() + " will be set to free.");
getLogger()
.info("clientName : " + client.getName() + " clientId : " + client.getId() + " will be set to free.");
clientMapService.updateClientMap(client, ClientStatus.FREE);
jobDetail.setClient(null);
jobDetailService.save(jobDetail);

}

// private void buildJobReport(JobCommand jobCommand, JobDetail jobDetail) {
// JobReport jobReport = jobReportService.getJobReportByParams(jobCommand.getTestCase(), jobDetail);
// JobReportResult jobReportResult = jobReportService.getJobReportResultByParams(jobCommand);
// JobReport jobReport =
// jobReportService.getJobReportByParams(jobCommand.getTestCase(), jobDetail);
// JobReportResult jobReportResult =
// jobReportService.getJobReportResultByParams(jobCommand);
// jobReportService.addJobReportMap(jobReport, jobReportResult);
// }

Expand All @@ -156,7 +179,8 @@ public boolean isJobCompleted(Job job, JobDetail lastJobDetail) {
if (jobDetail.equals(lastJobDetail) && CommandStatus.COMPLETED.equals(lastJobDetail.getStatus())) {
continue;
}
// If any job detail status is not completed, false is returned because jobDetailList is not complete.
// If any job detail status is not completed, false is returned because
// jobDetailList is not complete.
if (!CommandStatus.COMPLETED.equals(jobDetail.getStatus())) {
return false;
}
Expand All @@ -166,7 +190,8 @@ public boolean isJobCompleted(Job job, JobDetail lastJobDetail) {

public boolean isJobInProgress(Job job) {
for (JobDetail jobDetail : job.getJobDetails()) {
// If any job detail status is not completed, false is returned if jobDetailList is not complete.
// If any job detail status is not completed, false is returned if jobDetailList
// is not complete.
if (CommandStatus.IN_PROGRESS.equals(jobDetail.getStatus())) {
return true;
}
Expand All @@ -183,13 +208,21 @@ public boolean isJobStopped(Job job) {

public boolean isJobDetailJobCommandListFinished(JobDetail jobDetail) {
for (JobCommand jobCommand : jobDetail.getJobCommands()) {
if (!CommandStatus.COMPLETED.equals(jobCommand.getCommandStatus()) && !CommandStatus.BLOCKED.equals(jobCommand.getCommandStatus())) {
if (!CommandStatus.COMPLETED.equals(jobCommand.getCommandStatus())
&& !CommandStatus.BLOCKED.equals(jobCommand.getCommandStatus())) {
return false;
}
}
return true;
}

private void addOneDayMore(Job job) throws LocalizedException {
job.setStatus(JobStatus.PLANNED);
job.setPlannedDate(job.getPlannedDate().plusDays(1));
jobRunnerScheduler.scheduleJob(job);
jobService.save(job);
}

private void sendNotification(Job job) {
NotifierFactory.getNotifier(job.getNotificationGroup().getType()).sendNotification(job);
}
Expand Down

0 comments on commit 47149d2

Please sign in to comment.