public void switchOff() { LOGGER.warn("The process will now stop. "+this.getRunning()+" docker containers will be stopped."); this.waitingBuilds.clear(); for (RunnablePipelineContainer container : this.submittedRunnablePipelineContainers) { container.serialize("ABORT"); container.killDockerContainer(this.getDockerClient(), false); } this.executorService.shutdownNow(); }
public void setDockerImageName(String dockerImageName) { this.dockerImageName = dockerImageName; this.refreshDockerImage(); }
public void submitBuild(Build build) { if (this.limitDateNextRetrieveDockerImage.before(new Date())) { this.refreshDockerImage(); } if (getRunning() < this.nbThreads) { LOGGER.info("Build (id: "+build.getId()+") immediately submitted for running."); this.executorService.submit(this.submitBuild(this.dockerImageId, new InputBuildId(build.getId()))); } else { LOGGER.info("All threads currently running (Limit: "+this.nbThreads+"). Add build (id: "+build.getId()+") to wait list"); if (this.waitingBuilds.size() == this.nbThreads) { Build b = this.waitingBuilds.removeLast(); LOGGER.debug("Remove oldest build (id: "+b.getId()+")"); } this.waitingBuilds.push(build); } }
public void initRunner() { this.setDockerImageName(RepairnatorConfig.getInstance().getDockerImageName()); this.initExecutorService(RepairnatorConfig.getInstance().getNbThreads()); }
@Override public void removeSubmittedRunnablePipelineContainer(RunnablePipelineContainer pipelineContainer) { LOGGER.info("Build (id: "+pipelineContainer.getInputBuildId().getBuggyBuildId()+") has finished."); super.removeSubmittedRunnablePipelineContainer(pipelineContainer); if (!this.waitingBuilds.isEmpty()) { Build build = this.waitingBuilds.pollFirst(); this.submitBuild(build); } } }
/** * This allows us to automatically refresh docker images every 60 minutes */ private void refreshDockerImage() { this.dockerImageId = DockerHelper.findDockerImage(this.dockerImageName, this.getDockerClient()); this.limitDateNextRetrieveDockerImage = new Date(new Date().toInstant().plus(DELAY_BETWEEN_DOCKER_IMAGE_REFRESH, ChronoUnit.MINUTES).toEpochMilli()); LOGGER.debug("Find the following docker image: "+this.dockerImageId); }
public RTScanner(String runId, List<SerializerEngine> engines) { this.engines = engines; this.blackListedRepository = new ArrayList<>(); this.whiteListedRepository = new ArrayList<>(); this.tempBlackList = new HashMap<>(); this.buildRunner = new BuildRunner(this); this.inspectBuilds = new InspectBuilds(this); this.inspectJobs = new InspectJobs(this); this.runId = runId; this.blacklistedSerializer = new BlacklistedSerializer(this.engines, this); }
@Override public void run() { Instant endOfProcessDate = new Date().toInstant().plus(duration); LOGGER.info("The process will finish at: " + endOfProcessDate); while (!new Date().toInstant().isAfter(endOfProcessDate)) { try { Thread.sleep(SLEEP_TIME * 1000); } catch (InterruptedException e) { LOGGER.warn("Sleep interrupted: premature stop will occured."); } } LOGGER.info("The process will now stop."); this.inspectBuilds.switchOff(); this.inspectJobs.switchOff(); this.buildRunner.switchOff(); if (this.endProcessNotifier != null) { this.endProcessNotifier.notifyEnd(); } } }
/** * This method can only be called once. * It starts two or three new thread: * - one thread for build inspection * - one thread for job inspection * * If a duration has been given it also starts a thread for respecting the duration. */ public void launch() { if (!this.running) { LOGGER.info("Start running RTScanner..."); this.buildRunner.initRunner(); new Thread(this.inspectBuilds).start(); new Thread(this.inspectJobs).start(); if(summaryNotifier != null) { new Thread(this.summaryNotifier).start(); } this.running = true; if (RepairnatorConfig.getInstance().getDuration() != null) { InspectProcessDuration inspectProcessDuration; if (this.endProcessNotifier != null) { inspectProcessDuration = new InspectProcessDuration(this.inspectBuilds, this.inspectJobs, this.buildRunner, this.endProcessNotifier); } else { inspectProcessDuration = new InspectProcessDuration(this.inspectBuilds, this.inspectJobs, this.buildRunner); } new Thread(inspectProcessDuration).start(); } } }
/** * This method submits a build to the build runner if and only if the build contained failing tests. */ public void submitBuildToExecution(Build build) { boolean failing = false; List<Job> jobs = build.getJobs(); if (jobs != null) { for (Job job : jobs) { Optional<Log> optionalLog = job.getLog(); if (optionalLog.isPresent()) { Log jobLog = optionalLog.get(); if (jobLog.getTestsInformation() != null && (jobLog.getTestsInformation().getErrored() >= 0 || jobLog.getTestsInformation().getFailing() >= 0)) { failing = true; break; } } } } if (failing) { LOGGER.info("Failing or erroring tests has been found in build (id: "+build.getId()+")"); this.buildRunner.submitBuild(build); } else { LOGGER.info("No failing or erroring test has been found in build (id: "+build.getId()+")"); } }