From 596019f863e3b02c6d9db223f55592171df09782 Mon Sep 17 00:00:00 2001 From: Jasper Date: Mon, 27 Sep 2021 11:28:22 +0800 Subject: [PATCH] Expose nodes api to get permanent node info --- README.md | 39 +++++++++++++++++++ .../actions/LabelDashboardAction.java | 12 ++++++ 2 files changed, 51 insertions(+) diff --git a/README.md b/README.md index c840c37..f972726 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Jenkins. The command is `jcli plugin upload`. # API +## labels + URL: `GET http://localhost:8080/labelsdashboard/labelsData` Response: @@ -34,3 +36,40 @@ Response: ] } ``` + +## nodes + +URL: `GET http://localhost:8080/labelsdashboard/nodesData` + +Response: +``` +{ + "status": "ok", + "data": [ + { + "hasMoreThanOneJob": false, + "jobs": [], + "jobsCount": 0, + "jobsWithLabelDefaultValue": [], + "jobsWithLabelDefaultValueCount": 0, + "labelURL": "label/master/", + "name": "Jenkins", + "nodeURL": "computer/(master)/", + "triggeredJobs": [], + "triggeredJobsCount": 0 + }, + { + "hasMoreThanOneJob": false, + "jobs": [], + "jobsCount": 0, + "jobsWithLabelDefaultValue": [], + "jobsWithLabelDefaultValueCount": 0, + "labelURL": "label/macos1/", + "name": "macos1", + "nodeURL": "computer/macos1/", + "triggeredJobs": [], + "triggeredJobsCount": 0 + } + ] +} +``` diff --git a/src/main/java/jenkins/plugins/linkedjobs/actions/LabelDashboardAction.java b/src/main/java/jenkins/plugins/linkedjobs/actions/LabelDashboardAction.java index 67b9dba..c76f040 100644 --- a/src/main/java/jenkins/plugins/linkedjobs/actions/LabelDashboardAction.java +++ b/src/main/java/jenkins/plugins/linkedjobs/actions/LabelDashboardAction.java @@ -444,6 +444,18 @@ public List getSingleNodeJobs() { Collections.sort(result); return result; } + + @StaplerDispatchable + public HttpResponse doNodesData() { + getRefresh(); + Collection nodes = getNodesData(); + if (nodes.size() == 0) { + // sometimes it's empty, in order to have the correct list, try it again + getRefresh(); + nodes = getNodesData(); + } + return HttpResponses.okJSON(JSONArray.fromObject(nodes)); + } /** * This function scans all jobs to find those that are