github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/api/ui/debug/js/snapshot.js (about)

     1  //  Copyright (c) 2017-2018 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  var upsertbatchTable;
    16  
    17  function initSchedulerViewer() {
    18      // Disable null value warning from data table.
    19      $.fn.dataTable.ext.errMode = 'none';
    20  
    21      $.ajax({
    22              url: "/dbg/jobs/snapshot",
    23              success: function (body) {
    24                  var runningJobData = [];
    25                  var pastRunsData = [];
    26                  for (var key in body) {
    27                      var strs = key.split("|");
    28                      var row = body[key];
    29                      row['table'] = strs[0];
    30                      row['shard'] = strs[1];
    31                      row['type'] = strs[2];
    32                      if ('lastDuration' in row) {
    33                          row['lastDuration'] = row['lastDuration'].toDuration();
    34                      }
    35  
    36                      if ('lockDuration' in row) {
    37                          row['lockDuration'] = row['lockDuration'].toDuration();
    38                      }
    39  
    40                      if (row['status'] == 'running') {
    41                          runningJobData.push(row);
    42                      } else {
    43                          pastRunsData.push(row);
    44                      }
    45                  }
    46                  initRunningJobTable(runningJobData);
    47                  initPastRunTable(pastRunsData);
    48              },
    49              error: function (xhr) {
    50                  alert(xhr.responseText);
    51              }
    52          }
    53      );
    54  }
    55  
    56  function submitsnapshotJob(table, shard) {
    57      var url = "/dbg/{0}/{1}/snapshot".format(table, shard)
    58      $.ajax({
    59              url: url,
    60              method: "POST",
    61              dataType: 'json',
    62              success: function (body) {
    63                  alert(body);
    64                  reloadCurrentTab();
    65              },
    66              error: function (xhr) {
    67                  alert(xhr.responseText);
    68              }
    69          }
    70      )
    71  }
    72  
    73  function initRunningJobTable(data) {
    74      $('#running-job-table').DataTable({
    75          paging: false,
    76          searching: false,
    77          aoColumns: [
    78              {title: "Table", data: "table"},
    79              {title: "Shard", data: "shard", type: "num"},
    80              {title: "Type", data: "type"},
    81          ],
    82          aaData: data,
    83      });
    84  }
    85  
    86  function initPastRunTable(data) {
    87      $('#past-runs-table').DataTable({
    88          paging: true,
    89          searching: true,
    90          pageLength: 20,
    91          lengthMenu: [[1, 10, 25, 50, 100], [1, 10, 25, 50, 100]],
    92          aoColumns: [
    93              {title: "Table", data: "table"},
    94              {title: "Shard", data: "shard", type: "num"},
    95              {title: "Type", data: "type"},
    96              {title: "Status", data: "status"},
    97              {title: "Number of Mutations since Last Snapshot", data: "numMutations", type: "num"},
    98              {
    99                  title: "Action",
   100                  mData: null,
   101                  bSortable: false,
   102                  mRender: function (data, type, row) {
   103                      var table = row['table']
   104                      var shard = row['shard']
   105                      return $("<div />").append($(
   106                          "<button class='ui-button' onclick=\"submitsnapshotJob('" + table + "'," + shard + ")\">snapshot</button>")).html();
   107                  },
   108              },
   109              {
   110                  title: "Last Error",
   111                  data: "lastError",
   112                  type: "string",
   113                  render: function (data) {
   114                      return JSON.stringify(data);
   115                  }
   116              },
   117              {
   118                  title: "Last Start Time",
   119                  data: "lastStartTime",
   120                  type: "date",
   121                  render: function (data) {
   122                      return new Date(data).toLocaleString();
   123                  }
   124              },
   125              {title: "Last Duration", data: "lastDuration", type: "string"},
   126              {title: "Redo Log File", data: "redologFile", type: "number"},
   127              {title: "Batch Offset", data: "batchOffset", type: "number"},
   128          ],
   129          aaData: data,
   130      });
   131  }