summaryrefslogtreecommitdiff
path: root/web/src/actions
diff options
context:
space:
mode:
authorTristan Cacqueray <tdecacqu@redhat.com>2018-12-14 05:59:33 +0000
committerTristan Cacqueray <tdecacqu@redhat.com>2018-12-14 08:33:48 +0000
commit2f8a1be7c9a5ad6b6afe4512817be2948d9c41c5 (patch)
tree7f5b32dacfb8432947338e60f961448b99895bee /web/src/actions
parented1d588785fc336fc5933e26083c843357a929db (diff)
downloadzuul-2f8a1be7c9a5ad6b6afe4512817be2948d9c41c5.tar.gz
web: add errors from the job-output to the build page
This change updates the build page to fetch the job-output.json file and display the failed tasks. Logserver needs to enables CORS header for the zuul-web service. Change-Id: Ied9d1bb6489f608bc5402a98c8ae3a24b37b91e2
Diffstat (limited to 'web/src/actions')
-rw-r--r--web/src/actions/build.js69
1 files changed, 68 insertions, 1 deletions
diff --git a/web/src/actions/build.js b/web/src/actions/build.js
index 78f69f93b..b291c88b8 100644
--- a/web/src/actions/build.js
+++ b/web/src/actions/build.js
@@ -12,11 +12,14 @@
// License for the specific language governing permissions and limitations
// under the License.
+import Axios from 'axios'
+
import * as API from '../api'
export const BUILD_FETCH_REQUEST = 'BUILD_FETCH_REQUEST'
export const BUILD_FETCH_SUCCESS = 'BUILD_FETCH_SUCCESS'
export const BUILD_FETCH_FAIL = 'BUILD_FETCH_FAIL'
+export const BUILD_OUTPUT_FETCH_SUCCESS = 'BUILD_OUTPUT_FETCH_SUCCESS'
export const requestBuild = () => ({
type: BUILD_FETCH_REQUEST
@@ -29,6 +32,51 @@ export const receiveBuild = (buildId, build) => ({
receivedAt: Date.now()
})
+const receiveBuildOutput = (buildId, output) => {
+ const hosts = {}
+ // Compute stats
+ output.forEach(phase => {
+ Object.entries(phase.stats).forEach(([host, stats]) => {
+ if (!hosts[host]) {
+ hosts[host] = stats
+ hosts[host].failed = []
+ } else {
+ hosts[host].changed += stats.changed
+ hosts[host].failures += stats.failures
+ hosts[host].ok += stats.ok
+ }
+ if (stats.failures > 0) {
+ // Look for failed tasks
+ phase.plays.forEach(play => {
+ play.tasks.forEach(task => {
+ if (task.hosts[host]) {
+ if (task.hosts[host].results &&
+ task.hosts[host].results.length > 0) {
+ task.hosts[host].results.forEach(result => {
+ if (result.failed) {
+ result.name = task.task.name
+ hosts[host].failed.push(result)
+ }
+ })
+ } else if (task.hosts[host].rc || task.hosts[host].failed) {
+ let result = task.hosts[host]
+ result.name = task.task.name
+ hosts[host].failed.push(result)
+ }
+ }
+ })
+ })
+ }
+ })
+ })
+ return {
+ type: BUILD_OUTPUT_FETCH_SUCCESS,
+ buildId: buildId,
+ output: hosts,
+ receivedAt: Date.now()
+ }
+}
+
const failedBuild = error => ({
type: BUILD_FETCH_FAIL,
error
@@ -37,7 +85,26 @@ const failedBuild = error => ({
const fetchBuild = (tenant, build) => dispatch => {
dispatch(requestBuild())
return API.fetchBuild(tenant.apiPrefix, build)
- .then(response => dispatch(receiveBuild(build, response.data)))
+ .then(response => {
+ dispatch(receiveBuild(build, response.data))
+ if (response.data.log_url) {
+ const url = response.data.log_url.substr(
+ 0, response.data.log_url.lastIndexOf('/') + 1)
+ Axios.get(url + 'job-output.json.gz')
+ .then(response => dispatch(receiveBuildOutput(build, response.data)))
+ .catch(error => {
+ if (!error.request) {
+ throw error
+ }
+ // Try without compression
+ Axios.get(url + 'job-output.json')
+ .then(response => dispatch(receiveBuildOutput(
+ build, response.data)))
+ })
+ .catch(error => console.error(
+ 'Couldn\'t decode job-output...', error))
+ }
+ })
.catch(error => dispatch(failedBuild(error)))
}