use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.
the class RootCAs method addContents.
private void addContents(@NonNull Container container, @NonNull final Node node) {
Computer c = node.toComputer();
if (c == null) {
return;
}
String name;
String[] params;
if (node instanceof Jenkins) {
name = "nodes/master/RootCA.txt";
params = new String[0];
} else {
name = "nodes/slave/{0}/RootCA.txt";
params = new String[] { node.getNodeName() };
}
try {
container.add(new UnfilteredStringContent(name, params, getRootCA(node)));
} catch (IOException e) {
container.add(new UnfilteredStringContent(name, params, Functions.printThrowable(e)));
}
}
use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.
the class SupportPlugin method threadDumpStartup.
@Initializer(after = InitMilestone.STARTED)
public static void threadDumpStartup() throws Exception {
if (!logStartupPerformanceIssues)
return;
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
final File f = new File(getRootDirectory(), "/startup-threadDump" + dateFormat.format(new Date()) + ".txt");
if (!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
Thread t = new Thread("Support core plugin startup diagnostics") {
@Override
public void run() {
try {
while (true) {
final Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null || jenkins.getInitLevel() != InitMilestone.COMPLETED) {
continue;
}
try (PrintStream ps = new PrintStream(new FileOutputStream(f, true), false, "UTF-8")) {
ps.println("=== Thread dump at " + new Date() + " ===");
ThreadDumps.threadDump(ps);
// Generate a thread dump every few seconds/minutes
ps.flush();
TimeUnit.SECONDS.sleep(secondsPerThreadDump);
} catch (FileNotFoundException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
};
t.start();
}
use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.
the class ConfigFileComponent method addContents.
@Override
public void addContents(@NonNull Container container) {
Jenkins jenkins = Jenkins.get();
File configFile = new File(jenkins.getRootDir(), "config.xml");
if (configFile.exists()) {
container.add(new XmlRedactedSecretFileContent("jenkins-root-configuration-files/{0}", new String[] { configFile.getName() }, configFile));
} else {
// this should never happen..
LOGGER.log(Level.WARNING, "Jenkins global config file does not exist.");
}
}
use of jenkins.model.Jenkins in project gitea-plugin by jenkinsci.
the class Gitea method jenkinsPluginClassLoader.
public Gitea jenkinsPluginClassLoader() {
// HACK for Jenkins
// by rights this should be the context classloader, but Jenkins does not expose plugins on that
// so we need instead to use the uberClassLoader as that will have the implementations
Jenkins instance = Jenkins.getInstance();
classLoader = instance == null ? getClass().getClassLoader() : instance.getPluginManager().uberClassLoader;
// END HACK
return this;
}
use of jenkins.model.Jenkins in project workflow-cps-plugin by jenkinsci.
the class Snippetizer method doGenerateSnippet.
// accessed via REST API
@Restricted(DoNotUse.class)
public HttpResponse doGenerateSnippet(StaplerRequest req, @QueryParameter String json) throws Exception {
// TODO is there not an easier way to do this? Maybe Descriptor.newInstancesFromHeteroList on a one-element JSONArray?
JSONObject jsonO = JSONObject.fromObject(json);
Jenkins j = Jenkins.getActiveInstance();
Class<?> c = j.getPluginManager().uberClassLoader.loadClass(jsonO.getString("stapler-class"));
Descriptor descriptor = j.getDescriptor(c.asSubclass(Describable.class));
if (descriptor == null) {
return HttpResponses.plainText("<could not find " + c.getName() + ">");
}
Object o;
try {
o = descriptor.newInstance(req, jsonO);
} catch (RuntimeException x) {
// e.g. IllegalArgumentException
return HttpResponses.plainText(Functions.printThrowable(x));
}
try {
Step step = null;
if (o instanceof Step) {
step = (Step) o;
} else {
// Look for a metastep which could take this as its delegate.
for (StepDescriptor d : StepDescriptor.allMeta()) {
if (d.getMetaStepArgumentType().isInstance(o)) {
DescribableModel<?> m = DescribableModel.of(d.clazz);
DescribableParameter soleRequiredParameter = m.getSoleRequiredParameter();
if (soleRequiredParameter != null) {
step = d.newInstance(Collections.singletonMap(soleRequiredParameter.getName(), o));
break;
}
}
}
}
if (step == null) {
return HttpResponses.plainText("Cannot find a step corresponding to " + o.getClass().getName());
}
String groovy = step2Groovy(step);
if (descriptor instanceof StepDescriptor && ((StepDescriptor) descriptor).isAdvanced()) {
String warning = Messages.Snippetizer_this_step_should_not_normally_be_used_in();
groovy = "// " + warning + "\n" + groovy;
}
return HttpResponses.plainText(groovy);
} catch (UnsupportedOperationException x) {
Logger.getLogger(CpsFlowExecution.class.getName()).log(Level.WARNING, "failed to render " + json, x);
return HttpResponses.plainText(x.getMessage());
}
}
Aggregations