public static void main(String[] args) throws JSAPException { RTLauncher rtLauncher = new RTLauncher(args); rtLauncher.initAndRunRTScanner(); }
public void setDockerImageName(String dockerImageName) { this.dockerImageName = dockerImageName; this.refreshDockerImage(); }
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); }
private void initAndRunRTScanner() { LOGGER.info("Init RTScanner..."); LOGGER.info("RTScanner mode : " + this.config.getLauncherMode()); String runId = this.config.getRunId(); HardwareInfoSerializer hardwareInfoSerializer = new HardwareInfoSerializer(this.engines, runId, "rtScanner"); hardwareInfoSerializer.serialize(); RTScanner rtScanner = new RTScanner(runId, this.engines); if (this.summaryNotifier != null) { rtScanner.setSummaryNotifier(this.summaryNotifier); } if (this.config.getDuration() != null && this.endProcessNotifier != null) { rtScanner.setEndProcessNotifier(this.endProcessNotifier); } if (this.config.getWhiteList() != null) { rtScanner.initWhiteListedRepository(this.config.getWhiteList()); } if (this.config.getBlackList() != null) { rtScanner.initBlackListedRepository(this.config.getBlackList()); } LOGGER.info("Start RTScanner..."); rtScanner.launch(); }
private RTLauncher(String[] args) throws JSAPException { JSAP jsap = this.defineArgs(); JSAPResult arguments = jsap.parse(args); LauncherUtils.checkArguments(jsap, arguments, LauncherType.REALTIME); this.initConfig(arguments); this.initSerializerEngines(); this.initNotifiers(); this.initSummaryEmails(); }
@Override public void run() { LOGGER.debug("Start running inspect Jobs..."); if (sleepTime == -1) { throw new RuntimeException("Sleep time has to be set before running this."); } while (!shouldStop) { Optional<List<JobV2>> jobListOpt = RepairnatorConfig.getInstance().getJTravis().job().allFromV2(); if (jobListOpt.isPresent()) { List<JobV2> jobList = jobListOpt.get(); LOGGER.info("Retrieved "+jobList.size()+" jobs"); for (JobV2 job : jobList) { if (this.rtScanner.isRepositoryInteresting(job.getRepositoryId())) { this.rtScanner.submitWaitingBuild(job.getBuildId()); } } } if (this.rtScanner.getInspectBuilds().maxSubmittedBuildsReached() || !jobListOpt.isPresent()) { LOGGER.debug("Max number of submitted builds reached. Sleep for "+sleepTime+" seconds."); try { Thread.sleep(sleepTime * 1000); } catch (InterruptedException e) { e.printStackTrace(); } } } LOGGER.info("This will now stop."); } }
@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(); } } }
private JsonObject serializeAsJson(Repository repo, Reason reason, String comment) { JsonObject result = new JsonObject(); result.addProperty("hostname", Utils.getHostname()); result.addProperty("runId", this.rtScanner.getRunId()); this.addDate(result, "dateBlacklist", new Date()); result.addProperty("dateBlacklistStr", Utils.formatCompleteDate(new Date())); result.addProperty("repoId", repo.getId()); result.addProperty("repoName", repo.getSlug()); result.addProperty("reason", reason.name()); result.addProperty("comment", comment); return result; }
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); } }
/** * 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(); } } }
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 initRunner() { this.setDockerImageName(RepairnatorConfig.getInstance().getDockerImageName()); this.initExecutorService(RepairnatorConfig.getInstance().getNbThreads()); }
public InspectBuilds(RTScanner rtScanner) { this.rtScanner = rtScanner; this.sleepTime = RepairnatorConfig.getInstance().getBuildSleepTime(); this.maxSubmittedBuilds = RepairnatorConfig.getInstance().getMaxInspectedBuilds(); this.watchedBuildSerializer = new WatchedBuildSerializer(this.rtScanner.getEngines(), this.rtScanner); }
private List<Object> serializeAsList(Repository repo, Reason reason, String comment) { List<Object> result = new ArrayList<>(); result.add(Utils.getHostname()); result.add(this.rtScanner.getRunId()); result.add(Utils.formatCompleteDate(new Date())); result.add(repo.getId()); result.add(repo.getSlug()); result.add(reason.name()); result.add(comment); return result; }
private JsonObject serializeAsJson(Build build) { JsonObject result = new JsonObject(); result.addProperty("hostname", Utils.getHostname()); result.addProperty("runId", this.rtScanner.getRunId()); this.addDate(result, "dateWatched", new Date()); result.addProperty("dateWatchedStr", Utils.formatCompleteDate(new Date())); this.addDate(result, "dateBuildEnd", build.getFinishedAt()); result.addProperty("dateBuildEndStr", Utils.formatCompleteDate(build.getFinishedAt())); if (build.getRepository() == null) { result.addProperty("repository", "ID="+build.getRepository().getId()); } else { result.addProperty("repository", build.getRepository().getSlug()); } result.addProperty("buildId", build.getId()); result.addProperty("status", build.getState().name()); return result; }
/** * 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); }
@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); } } }
/** * Use this method to submit a build to the thread which refresh their status. */ public void submitWaitingBuild(int buildId) { Optional<Build> optionalBuild = RepairnatorConfig.getInstance().getJTravis().build().fromId(buildId); if (optionalBuild.isPresent()) { this.inspectBuilds.submitNewBuild(optionalBuild.get()); } } }
private List<Object> serializeAsList(Build build) { List<Object> result = new ArrayList<>(); result.add(Utils.getHostname()); result.add(this.rtScanner.getRunId()); result.add(Utils.formatCompleteDate(new Date())); result.add(Utils.formatCompleteDate(build.getFinishedAt())); if (build.getRepository() == null) { result.add("ID="+build.getRepository().getId()); } else { result.add(build.getRepository().getSlug()); } result.add(build.getId()); result.add(build.getState()); return result; }
public BuildRunner(RTScanner rtScanner) { LOGGER.info("Init build runner"); super.setDockerOutputDir(RepairnatorConfig.getInstance().getLogDirectory()); super.setRunId(RepairnatorConfig.getInstance().getRunId()); super.setEngines(rtScanner.getEngines()); }