Perf dashboard should auto-generate manifest file when one is missing
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jan 2016 00:57:07 +0000 (00:57 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jan 2016 00:57:07 +0000 (00:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152813

Reviewed by Chris Dumez.

When /data/manifest.json is missing, fall back to newly added /api/manifest instead of
silently failing to show the UI. This will make the initial setup easier.

* public/api/manifest.php: Added.
(main):
* public/include/manifest.php:
(Manifest::manifest): Added.
* public/v3/main.js:
(fetchManifest):
(didFetchManifest): Extracted from fetchManifest.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194679 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/public/api/manifest.php [new file with mode: 0644]
Websites/perf.webkit.org/public/include/manifest.php
Websites/perf.webkit.org/public/v3/main.js

index 4e530cb..39aa0ae 100644 (file)
@@ -1,5 +1,23 @@
 2016-01-06  Ryosuke Niwa  <rniwa@webkit.org>
 
+        Perf dashboard should auto-generate manifest file when one is missing
+        https://bugs.webkit.org/show_bug.cgi?id=152813
+
+        Reviewed by Chris Dumez.
+
+        When /data/manifest.json is missing, fall back to newly added /api/manifest instead of
+        silently failing to show the UI. This will make the initial setup easier.
+
+        * public/api/manifest.php: Added.
+        (main):
+        * public/include/manifest.php:
+        (Manifest::manifest): Added.
+        * public/v3/main.js:
+        (fetchManifest):
+        (didFetchManifest): Extracted from fetchManifest.
+
+2016-01-06  Ryosuke Niwa  <rniwa@webkit.org>
+
         Commit another forgotten change, this time, for r194653.
 
         * public/v3/models/measurement-set.js:
diff --git a/Websites/perf.webkit.org/public/api/manifest.php b/Websites/perf.webkit.org/public/api/manifest.php
new file mode 100644 (file)
index 0000000..45be7c0
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+require_once('../include/json-header.php');
+require_once('../include/manifest.php');
+
+function main() {
+    $db = new Database;
+    if (!$db->connect())
+        exit_with_error('DatabaseConnectionFailure');
+
+    $generator = new ManifestGenerator($db);
+    if (!$generator->generate())
+        exit_with_error('FailedToGenerateManifest');
+
+    if (!$generator->store())
+        exit_with_error('FailedToStoreManifest');
+
+    exit_with_success($generator->manifest());
+}
+
+main();
+
+?>
index 812ae60..3530610 100644 (file)
@@ -43,6 +43,8 @@ class ManifestGenerator {
         return TRUE;
     }
 
+    function manifest() { return $this->manifest; }
+
     function store() {
         return generate_data_file('manifest.json', json_encode($this->manifest));
     }
index 81aa298..7329e42 100644 (file)
@@ -56,54 +56,59 @@ function main() {
 
 function fetchManifest()
 {
-    var manifestURL = '../data/manifest.json';
-
-    return getJSON(manifestURL).then(function (rawResponse) {
-        Instrumentation.startMeasuringTime('Manifest', 'constructor');
-
-        var tests = [];
-        var testParentMap = {};
-        for (var testId in rawResponse.tests) {
-            var test = rawResponse.tests[testId];
-            var topLevel = !test.parentId;
-            if (test.parentId)
-                testParentMap[testId] = parseInt(test.parentId);
-            tests.push(new Test(testId, test, topLevel));
-        }
-        for (var testId in testParentMap)
-            Test.findById(testId).setParentTest(Test.findById(testParentMap[testId]));
-
-        function buildObjectsFromIdMap(idMap, constructor, resolver) {
-            for (var id in idMap) {
-                if (resolver)
-                    resolver(idMap[id]);
-                new constructor(id, idMap[id]);
-            }
-        }
-        buildObjectsFromIdMap(rawResponse.metrics, Metric, function (raw) {
-            raw.test = Test.findById(raw.test);
+    return getJSON('../data/manifest.json').then(didFetchManifest, function () {
+        return getJSON('../api/manifest/').then(didFetchManifest, function (error) {
+            alert('Failed to load the site manifest: ' + error);
         });
+    });
+}
 
-        buildObjectsFromIdMap(rawResponse.all, Platform, function (raw) {
-            raw.lastModifiedByMetric = {};
-            raw.lastModified.forEach(function (lastModified, index) {
-                raw.lastModifiedByMetric[raw.metrics[index]] = lastModified;
-            });
-            raw.metrics = raw.metrics.map(function (id) { return Metric.findById(id); });
-        });
-        buildObjectsFromIdMap(rawResponse.builders, Builder);
-        buildObjectsFromIdMap(rawResponse.repositories, Repository);
-        buildObjectsFromIdMap(rawResponse.bugTrackers, BugTracker, function (raw) {
-            raw.repositories = raw.repositories.map(function (id) { return Repository.findById(id); });
+function didFetchManifest(rawResponse)
+{
+    Instrumentation.startMeasuringTime('Main', 'didFetchManifest');
+
+    var tests = [];
+    var testParentMap = {};
+    for (var testId in rawResponse.tests) {
+        var test = rawResponse.tests[testId];
+        var topLevel = !test.parentId;
+        if (test.parentId)
+            testParentMap[testId] = parseInt(test.parentId);
+        tests.push(new Test(testId, test, topLevel));
+    }
+    for (var testId in testParentMap)
+        Test.findById(testId).setParentTest(Test.findById(testParentMap[testId]));
+
+    function buildObjectsFromIdMap(idMap, constructor, resolver) {
+        for (var id in idMap) {
+            if (resolver)
+                resolver(idMap[id]);
+            new constructor(id, idMap[id]);
+        }
+    }
+    buildObjectsFromIdMap(rawResponse.metrics, Metric, function (raw) {
+        raw.test = Test.findById(raw.test);
+    });
+
+    buildObjectsFromIdMap(rawResponse.all, Platform, function (raw) {
+        raw.lastModifiedByMetric = {};
+        raw.lastModified.forEach(function (lastModified, index) {
+            raw.lastModifiedByMetric[raw.metrics[index]] = lastModified;
         });
+        raw.metrics = raw.metrics.map(function (id) { return Metric.findById(id); });
+    });
+    buildObjectsFromIdMap(rawResponse.builders, Builder);
+    buildObjectsFromIdMap(rawResponse.repositories, Repository);
+    buildObjectsFromIdMap(rawResponse.bugTrackers, BugTracker, function (raw) {
+        raw.repositories = raw.repositories.map(function (id) { return Repository.findById(id); });
+    });
 
-        Instrumentation.endMeasuringTime('Manifest', 'constructor');
+    Instrumentation.endMeasuringTime('Main', 'didFetchManifest');
 
-        return {
-            siteTitle: rawResponse.siteTitle,
-            dashboards: rawResponse.dashboards, // FIXME: Add an abstraction around dashboards.
-        }
-    });
+    return {
+        siteTitle: rawResponse.siteTitle,
+        dashboards: rawResponse.dashboards, // FIXME: Add an abstraction around dashboards.
+    }
 }
 
 if (document.readyState != 'loading')