use of hudson.model.Hudson in project hudson-2.x by hudson.
the class InstallToolCommand method run.
protected int run() throws Exception {
Hudson h = Hudson.getInstance();
h.checkPermission(Hudson.READ);
// where is this build running?
BuildIDs id = channel.call(new BuildIDs());
if (!id.isComplete())
throw new AbortException("This command can be only invoked from a build executing inside Hudson");
AbstractProject p = Hudson.getInstance().getItemByFullName(id.job, AbstractProject.class);
if (p == null)
throw new AbortException("No such job found: " + id.job);
p.checkPermission(Item.CONFIGURE);
List<String> toolTypes = new ArrayList<String>();
for (ToolDescriptor<?> d : ToolInstallation.all()) {
toolTypes.add(d.getDisplayName());
if (d.getDisplayName().equals(toolType)) {
List<String> toolNames = new ArrayList<String>();
for (ToolInstallation t : d.getInstallations()) {
toolNames.add(t.getName());
if (t.getName().equals(toolName))
return install(t, id, p);
}
// didn't find the right tool name
error(toolNames, toolName, "name");
}
}
// didn't find the tool type
error(toolTypes, toolType, "type");
// will never be here
throw new AssertionError();
}
use of hudson.model.Hudson in project hudson-2.x by hudson.
the class SolarisSMFLifecycle method restart.
/**
* In SMF managed environment, just commit a suicide and the service will be restarted by SMF.
*/
@Override
public void restart() throws IOException, InterruptedException {
Hudson h = Hudson.getInstance();
if (h != null)
h.cleanUp();
System.exit(0);
}
use of hudson.model.Hudson in project hudson-2.x by hudson.
the class UnixLifecycle method restart.
@Override
public void restart() throws IOException, InterruptedException {
Hudson h = Hudson.getInstance();
if (h != null)
h.cleanUp();
// close all files upon exec, except stdin, stdout, and stderr
int sz = LIBC.getdtablesize();
for (int i = 3; i < sz; i++) {
int flags = LIBC.fcntl(i, F_GETFD);
if (flags < 0)
continue;
LIBC.fcntl(i, F_SETFD, flags | FD_CLOEXEC);
}
// exec to self
LIBC.execv(Daemon.getCurrentExecutable(), new StringArray(args.toArray(new String[args.size()])));
throw new IOException("Failed to exec " + LIBC.strerror(Native.getLastError()));
}
use of hudson.model.Hudson in project hudson-2.x by hudson.
the class WorkspaceSnapshotSCM method resolve.
/**
* Obtains the {@link WorkspaceSnapshot} object that this {@link SCM} points to,
* or throws {@link ResolvedFailedException} upon failing.
*
* @return never null.
*/
public Snapshot resolve() throws ResolvedFailedException {
Hudson h = Hudson.getInstance();
AbstractProject<?, ?> job = h.getItemByFullName(jobName, AbstractProject.class);
if (job == null) {
if (h.getItemByFullName(jobName) == null) {
AbstractProject nearest = AbstractProject.findNearest(jobName);
throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_NoSuchJob(jobName, nearest.getFullName()));
} else
throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_IncorrectJobType(jobName));
}
PermalinkList permalinks = job.getPermalinks();
Permalink p = permalinks.get(permalink);
if (p == null)
throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_NoSuchPermalink(permalink, jobName));
AbstractBuild<?, ?> b = (AbstractBuild<?, ?>) p.resolve(job);
if (b == null)
throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_NoBuild(permalink, jobName));
WorkspaceSnapshot snapshot = b.getAction(WorkspaceSnapshot.class);
if (snapshot == null)
throw new ResolvedFailedException(Messages.WorkspaceSnapshotSCM_NoWorkspace(jobName, permalink));
return new Snapshot(snapshot, b);
}
use of hudson.model.Hudson in project hudson-2.x by hudson.
the class Trigger method checkTriggers.
public static void checkTriggers(final Calendar cal) {
Hudson inst = Hudson.getInstance();
// Are we using synchronous polling?
SCMTrigger.DescriptorImpl scmd = inst.getDescriptorByType(SCMTrigger.DescriptorImpl.class);
if (scmd.synchronousPolling) {
LOGGER.fine("using synchronous polling");
// Check that previous synchronous polling job is done to prevent piling up too many jobs
if (previousSynchronousPolling == null || previousSynchronousPolling.isDone()) {
// Process SCMTriggers in the order of dependencies. Note that the crontab spec expressed per-project is
// ignored, only the global setting is honored. The polling job is submitted only if the previous job has
// terminated.
// FIXME allow to set a global crontab spec
previousSynchronousPolling = scmd.getExecutor().submit(new DependencyRunner(new ProjectRunnable() {
public void run(AbstractProject p) {
for (Trigger t : (Collection<Trigger>) p.getTriggers().values()) {
if (t instanceof SCMTrigger) {
LOGGER.fine("synchronously triggering SCMTrigger for project " + t.job.getName());
t.run();
}
}
}
}));
} else {
LOGGER.fine("synchronous polling has detected unfinished jobs, will not trigger additional jobs.");
}
}
// Process all triggers, except SCMTriggers when synchronousPolling is set
for (AbstractProject<?, ?> p : inst.getAllItems(AbstractProject.class)) {
for (Trigger t : p.getTriggers().values()) {
if (!(t instanceof SCMTrigger && scmd.synchronousPolling)) {
LOGGER.fine("cron checking " + p.getName());
if (t.tabs.check(cal)) {
LOGGER.config("cron triggered " + p.getName());
try {
t.run();
} catch (Throwable e) {
// t.run() is a plugin, and some of them throw RuntimeException and other things.
// don't let that cancel the polling activity. report and move on.
LOGGER.log(Level.WARNING, t.getClass().getName() + ".run() failed for " + p.getName(), e);
}
}
}
}
}
}
Aggregations