Java Code Examples for hudson.model.Queue#Executable
The following examples show how to use
hudson.model.Queue#Executable .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockerOnceRetentionStrategy.java From yet-another-docker-plugin with MIT License | 6 votes |
protected void done(Executor executor) { final AbstractCloudComputer<?> c = (AbstractCloudComputer) executor.getOwner(); Queue.Executable exec = executor.getCurrentExecutable(); if (executor instanceof OneOffExecutor) { LOG.debug("Not terminating {} because {} was a flyweight task", c.getName(), exec); return; } if (exec instanceof ContinuableExecutable && ((ContinuableExecutable) exec).willContinue()) { LOG.debug("not terminating {} because {} says it will be continued", c.getName(), exec); return; } LOG.debug("terminating {} since {} seems to be finished", c.getName(), exec); done(c); }
Example 2
Source File: KubernetesSlave.java From kubernetes-plugin with Apache License 2.0 | 6 votes |
@Override public Launcher createLauncher(TaskListener listener) { Launcher launcher = super.createLauncher(listener); if (template != null) { Executor executor = Executor.currentExecutor(); if (executor != null) { Queue.Executable currentExecutable = executor.getCurrentExecutable(); if (currentExecutable != null && executables.add(currentExecutable)) { listener.getLogger().println(Messages.KubernetesSlave_AgentIsProvisionedFromTemplate( ModelHyperlinkNote.encodeTo("/computer/" + getNodeName(), getNodeName()), getTemplate().getName()) ); printAgentDescription(listener); checkHomeAndWarnIfNeeded(listener); } } } return launcher; }
Example 3
Source File: JenkinsRule.java From jenkins-test-harness with MIT License | 5 votes |
/** * Runs specified job and asserts that in finished with given build result. * @since TODO */ @Nonnull public <J extends Job<J,R> & ParameterizedJobMixIn.ParameterizedJob<J,R>,R extends Run<J,R> & Queue.Executable> R buildAndAssertStatus(@Nonnull Result status, @Nonnull J job) throws Exception { final QueueTaskFuture<R> f = new ParameterizedJobMixIn<J, R>() { @Override protected J asJob() { return job; } }.scheduleBuild2(0); return assertBuildStatus(status, f); }
Example 4
Source File: DockerOnceRetentionStrategy.java From docker-plugin with MIT License | 5 votes |
private void done(Executor executor) { final DockerComputer c = (DockerComputer) executor.getOwner(); Queue.Executable exec = executor.getCurrentExecutable(); if (exec instanceof ContinuableExecutable && ((ContinuableExecutable) exec).willContinue()) { LOGGER.log(Level.FINE, "not terminating {0} because {1} says it will be continued", new Object[]{c.getName(), exec}); return; } LOGGER.log(Level.FINE, "terminating {0} since {1} seems to be finished", new Object[]{c.getName(), exec}); done(c); }
Example 5
Source File: KubernetesComputer.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Override public void taskCompleted(Executor executor, Queue.Task task, long durationMS) { Queue.Executable exec = executor.getCurrentExecutable(); LOGGER.log(Level.FINE, " Computer {0} completed task {1}", new Object[] {this, exec}); // May take the agent offline and remove it, in which case getNode() // above would return null and we'd not find our DockerSlave anymore. super.taskCompleted(executor, task, durationMS); }
Example 6
Source File: DockerSwarmAgentRetentionStrategy.java From docker-swarm-plugin with MIT License | 5 votes |
private void done(Executor executor) { final DockerSwarmComputer c = (DockerSwarmComputer) executor.getOwner(); Queue.Executable exec = executor.getCurrentExecutable(); if (exec instanceof ContinuableExecutable && ((ContinuableExecutable) exec).willContinue()) { LOGGER.log(Level.FINE, "not terminating {0} because {1} says it will be continued", new Object[] { c.getName(), exec }); return; } LOGGER.log(Level.FINE, "terminating {0} since {1} seems to be finished", new Object[] { c.getName(), exec }); done(c); }
Example 7
Source File: PipelineEventListener.java From blueocean-plugin with MIT License | 5 votes |
private static @CheckForNull Run<?, ?> runFor(FlowExecution exec) { Queue.Executable executable; try { executable = exec.getOwner().getExecutable(); } catch (IOException x) { LOGGER.log(Level.WARNING, null, x); return null; } if (executable instanceof Run) { return (Run<?, ?>) executable; } else { return null; } }
Example 8
Source File: LinkResolverImpl.java From blueocean-plugin with MIT License | 5 votes |
private BlueRun resolveFlowNodeRun(FlowNode flowNode) { try { Queue.Executable executable = flowNode.getExecution().getOwner().getExecutable(); if (executable != null && executable instanceof WorkflowRun) { WorkflowRun run = (WorkflowRun) executable; return (BlueRun) resolveRun(run); } } catch (IOException e) { logger.error(e.getMessage(), e); return null; } return null; }
Example 9
Source File: GithubBuildStatusGraphListener.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Gets the jenkins run object of the specified executing workflow. * * @param exec execution of a workflow * @return jenkins run object of a job */ private static @CheckForNull Run<?, ?> runFor(FlowExecution exec) { Queue.Executable executable; try { executable = exec.getOwner().getExecutable(); } catch (IOException x) { getLogger().log(Level.WARNING, null, x); return null; } if (executable instanceof Run) { return (Run<?, ?>) executable; } else { return null; } }
Example 10
Source File: DockerSwarmComputer.java From docker-swarm-plugin with MIT License | 5 votes |
public Queue.Executable getCurrentBuild() { if (!Iterables.isEmpty(getExecutors())) { final Executor exec = getExecutors().get(0); return exec.getCurrentExecutable() == null ? null : exec.getCurrentExecutable(); } return null; }
Example 11
Source File: EC2FleetAutoResubmitComputerLauncher.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
/** * {@link ComputerLauncher#afterDisconnect(SlaveComputer, TaskListener)} * <p> * EC2 Fleet plugin overrides this method to detect jobs which were failed because of * EC2 instance was terminated/stopped. It could be manual stop or because of Spot marked. * In all cases as soon as job aborted because of broken connection and slave is offline * it will try to resubmit aborted job back to the queue, so user doesn't need to do that manually * and another slave could take it. * <p> * Implementation details * <p> * There is no official recommendation about way how to resubmit job according to * https://issues.jenkins-ci.org/browse/JENKINS-49707 moreover some of Jenkins code says it impossible. * <p> * method checks {@link SlaveComputer#getOfflineCause()} for disconnect because of EC2 instance termination * it returns * <code> * result = {OfflineCause$ChannelTermination@13708} "Connection was broken: java.io.IOException: * Unexpected termination of the channel\n\tat hudson.remoting.SynchronousCommandTransport$ReaderThread... * cause = {IOException@13721} "java.io.IOException: Unexpected termination of the channel" * timestamp = 1561067177837 * </code> * * @param computer computer * @param listener listener */ @Override public void afterDisconnect(final SlaveComputer computer, final TaskListener listener) { // according to jenkins docs could be null in edge cases, check ComputerLauncher.afterDisconnect if (computer == null) return; // in some multi-thread edge cases cloud could be null for some time, just be ok with that final EC2FleetCloud cloud = ((EC2FleetNodeComputer) computer).getCloud(); if (cloud == null) { LOGGER.warning("Edge case cloud is null for computer " + computer.getDisplayName() + " should be autofixed in a few minutes, if no please create issue for plugin"); return; } final boolean unexpectedDisconnect = computer.isOffline() && computer.getOfflineCause() instanceof OfflineCause.ChannelTermination; if (!cloud.isDisableTaskResubmit() && unexpectedDisconnect) { final List<Executor> executors = computer.getExecutors(); LOGGER.log(LOG_LEVEL, "Unexpected " + computer.getDisplayName() + " termination, resubmit"); for (Executor executor : executors) { if (executor.getCurrentExecutable() != null) { executor.interrupt(Result.ABORTED, new EC2TerminationCause(computer.getDisplayName())); final Queue.Executable executable = executor.getCurrentExecutable(); // if executor is not idle if (executable != null) { final SubTask subTask = executable.getParent(); final Queue.Task task = subTask.getOwnerTask(); List<Action> actions = new ArrayList<>(); if (executable instanceof Actionable) { actions = ((Actionable) executable).getActions(); } Queue.getInstance().schedule2(task, RESCHEDULE_QUIET_PERIOD_SEC, actions); LOGGER.log(LOG_LEVEL, "Unexpected " + computer.getDisplayName() + " termination, resubmit " + task + " with actions " + actions); } } } LOGGER.log(LOG_LEVEL, "Unexpected " + computer.getDisplayName() + " termination, resubmit finished"); } else { LOGGER.log(LOG_LEVEL, "Unexpected " + computer.getDisplayName() + " termination but resubmit disabled, no actions, disableTaskResubmit: " + cloud.isDisableTaskResubmit() + ", offline: " + computer.isOffline() + ", offlineCause: " + (computer.getOfflineCause() != null ? computer.getOfflineCause().getClass() : "null")); } // call parent super.afterDisconnect(computer, listener); }
Example 12
Source File: JenkinsRule.java From jenkins-test-harness with MIT License | 4 votes |
@Nonnull public <J extends Job<J,R> & ParameterizedJobMixIn.ParameterizedJob<J,R>,R extends Run<J,R> & Queue.Executable> R buildAndAssertSuccess(@Nonnull J job) throws Exception { return buildAndAssertStatus(Result.SUCCESS, job); }
Example 13
Source File: KubernetesComputer.java From kubernetes-plugin with Apache License 2.0 | 4 votes |
@Override public void taskAccepted(Executor executor, Queue.Task task) { super.taskAccepted(executor, task); Queue.Executable exec = executor.getCurrentExecutable(); LOGGER.log(Level.FINE, " Computer {0} accepted task {1}", new Object[] {this, exec}); }
Example 14
Source File: KubernetesComputer.java From kubernetes-plugin with Apache License 2.0 | 4 votes |
@Override public void taskCompletedWithProblems(Executor executor, Queue.Task task, long durationMS, Throwable problems) { super.taskCompletedWithProblems(executor, task, durationMS, problems); Queue.Executable exec = executor.getCurrentExecutable(); LOGGER.log(Level.FINE, " Computer {0} completed task {1} with problems", new Object[] {this, exec}); }
Example 15
Source File: YamlFlowDefinition.java From simple-pull-request-job-plugin with Apache License 2.0 | 4 votes |
@Override public FlowExecution create(FlowExecutionOwner owner, TaskListener listener, List<? extends Action> actions) throws Exception { Queue.Executable exec = owner.getExecutable(); if (!(exec instanceof WorkflowRun)) { throw new IllegalStateException("inappropriate context"); } WorkflowRun build = (WorkflowRun) exec; WorkflowJob job = build.getParent(); BranchJobProperty property = job.getProperty(BranchJobProperty.class); Branch branch = property.getBranch(); ItemGroup<?> parent = job.getParent(); if (!(parent instanceof WorkflowMultiBranchProject)) { throw new IllegalStateException("inappropriate context"); } SCMSource scmSource = ((WorkflowMultiBranchProject) parent).getSCMSource(branch.getSourceId()); if (scmSource == null) { throw new IllegalStateException(branch.getSourceId() + " not found"); } GitConfig gitConfig = new GitConfig(); SCMHead head = branch.getHead(); if ("Pull Request".equals(head.getPronoun())) { ChangeRequestSCMHead2 changeRequestSCMHead2 = (ChangeRequestSCMHead2) branch.getHead(); head = changeRequestSCMHead2.getTarget(); } SCMRevision tip = scmSource.fetch(head, listener); if (tip == null) { throw new IllegalStateException("Cannot determine the revision."); } SCMRevision rev = scmSource.getTrustedRevision(tip, listener); GitSCM gitSCM = (GitSCM) scmSource.build(head, rev); gitConfig.setGitUrl(gitSCM.getUserRemoteConfigs().get(0).getUrl()); gitConfig.setCredentialsId(gitSCM.getUserRemoteConfigs().get(0).getCredentialsId()); gitConfig.setGitBranch(head.getName()); String script; try (SCMFileSystem fs = SCMFileSystem.of(scmSource, head, rev)) { if (fs != null) { InputStream yamlInputStream = fs.child(scriptPath).content(); listener.getLogger().println("Path of yaml/yml config file: " + fs.child(scriptPath).getPath()); YamlToPipeline y = new YamlToPipeline(); script = y.generatePipeline(yamlInputStream, gitConfig, listener); } else { throw new IOException("SCM not supported"); // FIXME implement full checkout } } listener.getLogger().println(script); return new CpsFlowExecution(script, false, owner); }
Example 16
Source File: DockerTask.java From yet-another-docker-plugin with MIT License | 4 votes |
@Override public Queue.Executable createExecutable() throws IOException { return new MyExecutable(this); }
Example 17
Source File: JobRunnerForCause.java From github-integration-plugin with MIT License | 4 votes |
public synchronized int abortRunning(int number) throws IllegalAccessException { int aborted = 0; Computer[] computers = getJenkinsInstance().getComputers(); for (Computer computer : computers) { if (isNull(computer)) { continue; } List<Executor> executors = computer.getExecutors(); executors.addAll(computer.getOneOffExecutors()); for (Executor executor : executors) { if (isNull(executor) || !executor.isBusy() || nonNull(executor.getCauseOfDeath()) || !getInterruptCauses(executor).isEmpty() || getInterruptStatus(executor) == Result.ABORTED) { continue; } Queue.Executable executable = executor.getCurrentExecutable(); final SubTask parent = executable.getParent(); if (!(executable instanceof Run)) { continue; } final Run executableRun = (Run) executable; if (!(parent instanceof Job)) { continue; } final Job parentJob = (Job) parent; if (!parentJob.getFullName().equals(job.getFullName())) { // name doesn't match continue; } if (executableRun.getResult() == Result.ABORTED) { // was already aborted continue; } if (executableRun instanceof MatrixRun) { // the whole MatrixBuild will be aborted continue; } // if (executable instanceof MatrixBuild) { // final MatrixBuild executable1 = (MatrixBuild) executable; // executable1.doStop() // } final GitHubPRCause causeAction = (GitHubPRCause) executableRun.getCause(GitHubPRCause.class); if (nonNull(causeAction) && causeAction.getNumber() == number) { LOGGER.info("Aborting '{}', by interrupting '{}'", executableRun, executor); executor.interrupt(Result.ABORTED, new NewPRInterruptCause()); aborted++; } } } return aborted; }