Search in sources :

Example 66 with Jenkins

use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.

the class LoadStats method addContents.

/**
 * {@inheritDoc}
 */
@Override
public void addContents(@NonNull Container container) {
    Jenkins jenkins = Jenkins.getInstance();
    add(container, "no-label", jenkins.unlabeledLoad);
    add(container, "overall", jenkins.overallLoad);
    for (Label l : jenkins.getLabels()) {
        try {
            add(container, String.format("label/%s", URLEncoder.encode(l.getName(), "UTF-8")), l.loadStatistics);
        } catch (UnsupportedEncodingException e) {
        // ignore UTF-8 is required by JLS specification
        }
    }
}
Also used : Jenkins(jenkins.model.Jenkins) Label(hudson.model.Label) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 67 with Jenkins

use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.

the class AdvancedProcFilesRetriever method addUnixContents.

@Override
protected void addUnixContents(@NonNull Container container, @NonNull final Node node) {
    Computer c = node.toComputer();
    if (c == null || c.isOffline()) {
        return;
    }
    // fast path bailout for Windows
    if (!Boolean.TRUE.equals(c.isUnix())) {
        return;
    }
    SystemPlatform nodeSystemPlatform = getSystemPlatform(node);
    if (!SystemPlatform.LINUX.equals(nodeSystemPlatform)) {
        return;
    }
    String name;
    if (node instanceof Jenkins) {
        name = "master";
    } else {
        name = "slave/" + node.getNodeName();
    }
    for (ProcFile procDescriptor : getProcFilesToRetrieve()) {
        container.add(new FilePathContent("nodes/{0}/proc/{1}", new String[] { name, procDescriptor.getName() }, new FilePath(c.getChannel(), procDescriptor.getFile())) {

            @Override
            public boolean shouldBeFiltered() {
                // Whether this specific file should be filtered or not
                return procDescriptor.isFiltered();
            }
        });
    }
    afterAddUnixContents(container, node, name);
}
Also used : Jenkins(jenkins.model.Jenkins) FilePath(hudson.FilePath) FilePathContent(com.cloudbees.jenkins.support.api.FilePathContent) Computer(hudson.model.Computer) SystemPlatform(com.cloudbees.jenkins.support.util.SystemPlatform)

Example 68 with Jenkins

use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.

the class ProcFilesRetriever method addUnixContents.

protected void addUnixContents(@NonNull Container container, @NonNull final Node node) {
    Computer c = node.toComputer();
    if (c == null || c.isOffline()) {
        return;
    }
    // fast path bailout for Windows
    if (!Boolean.TRUE.equals(c.isUnix())) {
        return;
    }
    SystemPlatform nodeSystemPlatform = getSystemPlatform(node);
    if (!SystemPlatform.LINUX.equals(nodeSystemPlatform)) {
        return;
    }
    String name;
    if (node instanceof Jenkins) {
        name = "master";
    } else {
        name = "slave/" + node.getNodeName();
    }
    for (Map.Entry<String, String> procDescriptor : getFilesToRetrieve().entrySet()) {
        container.add(new FilePathContent("nodes/{0}/proc/{1}", new String[] { name, procDescriptor.getValue() }, new FilePath(c.getChannel(), procDescriptor.getKey())));
    }
    afterAddUnixContents(container, node, name);
}
Also used : Jenkins(jenkins.model.Jenkins) FilePath(hudson.FilePath) FilePathContent(com.cloudbees.jenkins.support.api.FilePathContent) Computer(hudson.model.Computer) SystemPlatform(com.cloudbees.jenkins.support.util.SystemPlatform) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap)

Example 69 with Jenkins

use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.

the class ProcFilesRetriever method getNodes.

protected List<Node> getNodes() {
    final Jenkins jenkins = Jenkins.get();
    final List<Node> agents = jenkins.getNodes();
    List<Node> allNodes = new ArrayList<>(agents.size() + 1);
    allNodes.add(jenkins);
    allNodes.addAll(agents);
    return allNodes;
}
Also used : Jenkins(jenkins.model.Jenkins) Node(hudson.model.Node) ArrayList(java.util.ArrayList)

Example 70 with Jenkins

use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.

the class OtherConfigFilesComponent method addContents.

@Override
public void addContents(@NonNull Container container) {
    Jenkins jenkins = Jenkins.getInstanceOrNull();
    if (jenkins != null) {
        File dir = jenkins.getRootDir();
        File[] files = dir.listFiles((dir1, name) -> name.toLowerCase().endsWith(".xml") && !BLACKLISTED_FILENAMES.contains(name));
        if (files != null) {
            for (File configFile : files) {
                if (configFile.exists()) {
                    container.add(new XmlRedactedSecretFileContent("jenkins-root-configuration-files/{0}", new String[] { configFile.getName() }, configFile));
                }
            }
        } else {
            LOGGER.log(Level.WARNING, "Cannot list files in Jenkins root, probably something is wrong with the path");
        }
    }
}
Also used : Jenkins(jenkins.model.Jenkins) File(java.io.File)

Aggregations

Jenkins (jenkins.model.Jenkins)73 Test (org.junit.Test)22 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)13 IOException (java.io.IOException)10 File (java.io.File)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 Statement (org.junit.runners.model.Statement)7 CheckForNull (javax.annotation.CheckForNull)6 FilePath (hudson.FilePath)5 Computer (hudson.model.Computer)5 URL (java.net.URL)5 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)5 Issue (org.jvnet.hudson.test.Issue)5 Item (hudson.model.Item)4 Node (hudson.model.Node)4 Date (java.util.Date)4