use of jenkins.model.Jenkins in project blueocean-plugin by jenkinsci.
the class PipelineActivityStatePreloader method getPipeline.
private BluePipeline getPipeline(BlueUrlTokenizer blueUrl) {
if (addPipelineRuns(blueUrl)) {
Jenkins jenkins = Jenkins.get();
String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
try {
Item pipelineJob = jenkins.getItemByFullName(pipelineFullName);
return (BluePipeline) BluePipelineFactory.resolve(pipelineJob);
} catch (Exception e) {
LOGGER.log(Level.FINE, String.format("Unable to find Job named '%s'.", pipelineFullName), e);
return null;
}
}
return null;
}
use of jenkins.model.Jenkins in project blueocean-plugin by jenkinsci.
the class PipelineStatePreloader method getFetchData.
@Override
protected FetchData getFetchData(@NonNull BlueUrlTokenizer blueUrl) {
// e.g. /blue/organizations/jenkins/Pipeline (or a url on that)
if (!blueUrl.hasPart(BlueUrlTokenizer.UrlPart.PIPELINE)) {
// Not interested in it
return null;
}
Jenkins jenkins = Jenkins.get();
String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
try {
Item pipelineJobItem = jenkins.getItemByFullName(pipelineFullName);
if (pipelineJobItem != null) {
BluePipeline bluePipeline = (BluePipeline) BluePipelineFactory.resolve(pipelineJobItem);
if (bluePipeline != null) {
try {
return new FetchData(bluePipeline.getLink().getHref(), Export.toJson(bluePipeline));
} catch (IOException e) {
LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Serialization error.", pipelineJobItem.getUrl()), e);
return null;
}
} else {
LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Failed to convert to Blue Ocean Resource.", pipelineJobItem.getUrl()));
return null;
}
}
} catch (Exception e) {
LOGGER.log(Level.FINE, String.format("Unable to find pipeline named '%s'.", pipelineFullName), e);
return null;
}
// Don't preload any data on the page.
return null;
}
use of jenkins.model.Jenkins in project blueocean-plugin by jenkinsci.
the class JobAnalytics method calculateAndSend.
public void calculateAndSend() {
Analytics analytics = Analytics.get();
if (analytics == null) {
return;
}
Jenkins jenkins = Jenkins.get();
ExtensionList<JobAnalyticsCheck> checks = ExtensionList.lookup(JobAnalyticsCheck.class);
ExtensionList<JobAnalyticsExclude> excludes = ExtensionList.lookup(JobAnalyticsExclude.class);
// Initialize the tally
Tally tally = new Tally();
checks.forEach(check -> tally.zero(check.getName()));
tally.zero(OTHER_CATEGORY);
jenkins.allItems().forEach(item -> {
if (excludes.stream().noneMatch(exclude -> exclude.apply(item))) {
boolean matchFound = false;
for (JobAnalyticsCheck check : checks) {
if (check.apply(item)) {
tally.count(check.getName());
matchFound = true;
break;
}
}
if (!matchFound) {
tally.count(OTHER_CATEGORY);
}
}
});
analytics.track(new TrackRequest(JOB_STATS_EVENT_NAME, tally.get()));
}
use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.
the class FileDescriptorLimit method addContents.
@Override
public void addContents(@NonNull Container container) {
Jenkins j = Jenkins.get();
addContents(container, j);
for (Node node : j.getNodes()) {
addContents(container, node);
}
}
use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.
the class FileDescriptorLimit method addContents.
private void addContents(@NonNull Container container, @NonNull final Node node) {
Computer c = node.toComputer();
if (c == null) {
return;
}
if (c instanceof SlaveComputer && !Boolean.TRUE.equals(c.isUnix())) {
return;
}
if (!node.createLauncher(TaskListener.NULL).isUnix()) {
return;
}
String name;
if (node instanceof Jenkins) {
name = "master";
} else {
name = "slave/" + node.getNodeName();
}
container.add(new PrefilteredPrintedContent("nodes/{0}/file-descriptors.txt", name) {
@Override
protected void printTo(PrintWriter out, ContentFilter filter) {
out.println(node.getDisplayName());
out.println("======");
out.println();
try {
out.println(AsyncResultCache.get(node, fileDescriptorCache, new GetUlimit(filter), "file descriptor info", "N/A: Either no connection to node or no cached result"));
} catch (IOException e) {
Functions.printStackTrace(e, out);
} finally {
out.flush();
}
}
});
}
Aggregations