Search in sources :

Example 1 with DeclarativeAgentDescriptor

use of org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor in project blueocean-plugin by jenkinsci.

the class PipelineMetadataService method doAgentMetadata.

/**
 * Function to return all {@link DeclarativeAgent}s present in the system when accessed through the REST API
 */
@GET
@TreeResponse
public ExportedDescribableModel[] doAgentMetadata() {
    List<ExportedDescribableModel> models = new ArrayList<>();
    for (DeclarativeAgentDescriptor d : DeclarativeAgentDescriptor.all()) {
        try {
            DescribableModel<? extends DeclarativeAgent> model = new DescribableModel<>(d.clazz);
            String symbol = symbolForObject(d);
            if ("label".equals(symbol)) {
                // Label has 2 symbols, but we need "node"
                symbol = "node";
            }
            models.add(new ExportedDescribableModel(model, symbol));
        } catch (NoStaplerConstructorException e) {
        // Ignore!
        }
    }
    return models.toArray(new ExportedDescribableModel[models.size()]);
}
Also used : DeclarativeAgentDescriptor(org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor) ArrayList(java.util.ArrayList) DescribableModel(org.jenkinsci.plugins.structs.describable.DescribableModel) NoStaplerConstructorException(org.kohsuke.stapler.NoStaplerConstructorException) TreeResponse(io.jenkins.blueocean.commons.stapler.TreeResponse) GET(org.kohsuke.stapler.verb.GET)

Aggregations

TreeResponse (io.jenkins.blueocean.commons.stapler.TreeResponse)1 ArrayList (java.util.ArrayList)1 DeclarativeAgentDescriptor (org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor)1 DescribableModel (org.jenkinsci.plugins.structs.describable.DescribableModel)1 NoStaplerConstructorException (org.kohsuke.stapler.NoStaplerConstructorException)1 GET (org.kohsuke.stapler.verb.GET)1