diff --git a/src/js/modules/projections/controllers/ProjectionsItemDebugCtrl.js b/src/js/modules/projections/controllers/ProjectionsItemDebugCtrl.js deleted file mode 100644 index 5629816c..00000000 --- a/src/js/modules/projections/controllers/ProjectionsItemDebugCtrl.js +++ /dev/null @@ -1,289 +0,0 @@ -define(['./_module'], function (app) { - - 'use strict'; - - return app.controller('ProjectionsItemDebugCtrl', [ - '$scope', '$state', '$stateParams', '$q', '$timeout', '$window', 'ProjectionsService', 'MessageService', - function ($scope, $state, $stateParams, $q, $timeout, $window, projectionsService, msg) { - function updateStatusInfo(message) { - if (!message) { - message = 'N/A'; - } - $scope.statusInfo = message; - } - - function setPartition(partition) { - partition = '(' + partition + ')'; - $scope.currentPartition = partition; - } - - updateStatusInfo(''); - $scope.location = $stateParams.location; - - function queryChanged(){ - $scope.queryUpdated = true; - } - - $scope.aceConfig = { - mode: 'javascript', - useWrapMode: false, - showGutter: true, - theme: 'monokai', - onChange: queryChanged - }; - - $scope.aceEventsConfig = { - mode: 'json', - useWrapMode: false, - showGutter: true, - theme: 'monokai' - }; - - $scope.isRunning = false; - $scope.isUpdating = false; - $scope.query = ''; - $scope.events = ''; - $scope.state = ''; - - var rawEvents, currentEvent, definition, currentPosition, partition, initialized, processor, cachedStates = {}; - - updateStatusInfo('Loading definition...'); - - function loadProjection(){ - //clear the cache - cachedStates = {}; - - var requests = []; - var stats = projectionsService.statistics($scope.location); - var state = projectionsService.state($scope.location, {timeout: 2000}); - var query = projectionsService.query($scope.location); - - requests.push(stats); - requests.push(state); - requests.push(query); - - $q.allSettled(requests) - .then(function (data) { - // 0 - stats - // 1 - state - // 2 - query - var stats = data[0], - state = data[1], - query = data[2], - position; - - if (stats.data.projections[0].status.indexOf('Stopped') > -1 && stats.data.projections[0].status.indexOf('Faulted') > -1) { - $scope.isRunning = true; - } - - position = state.headers()['es-position']; - currentPosition = angular.fromJson(position); - definition = query.data.definition; - - $scope.query = query.data.query; - - if(!currentPosition){ - msg.failure('The projection\`s state query did not return an ES-Position header.\nEnsure that the projection is not Completed/Stopped or Faulted.\nWe cannot continue debugging.', 'Please ensure that the header includes ES-Position.'); - $scope.isRunning = true; - return; - } - - updateStatusInfo(''); - loadEvents(); - }, function (data){ - var stats = data[0], - state = data[1], - query = data[2]; - - if(stats && !stats.data){ - msg.failure('Failed to retrieve projection stats: ' + stats.message); - } - - if(state && !state.data){ - msg.failure('Failed to retrieve projection state: ' + state.message); - } - - if(query && !query.data){ - msg.failure('Failed to retrieve projection query: ' + query.message); - } else{ - $scope.query = query.data.query; - } - }); - } - msg.info('The projection will be stopped for debugging'); - projectionsService.disable($scope.location) - .then(function onProjectionEnabled(){ - loadProjection(); - }, function(error){ - msg.failure('Failed to stop projection: ' + error.message); - }); - var currentLoadEventsTimeout; - function loadEvents() { - projectionsService.readEvents(definition, currentPosition) - .then(function (res) { - var data = res.data; - $scope.events = JSON.stringify(data, undefined, 4); - rawEvents = data.events; - - if (rawEvents && rawEvents.length > 0) { - prepare(); - } else { - updateStatusInfo('No further events are available. Waiting...'); - $scope.isRunning = true; - currentLoadEventsTimeout = $timeout(loadEvents, 1000); - } - - }, function (error) { - msg.failure('Failed to read projection events: ' + error.message); - }); - } - - function prepare() { - currentEvent = rawEvents[0]; - - if (initialized) { - loadState(); - return; - } - - updateStatusInfo('Running the definition...'); - $scope.$broadcast('load-scripts'); - $timeout(loadState, 100); - - } - - function loadState() { - - processor = document.getElementById('script-placeholder').contentWindow.processor; - if (!processor) { - $timeout(loadState, 1000); - return; - } - - initialized = true; - updateStatusInfo(''); - partition = null; - - if (definition.byCustomPartitions) { - partition = processor.get_state_partition( - currentEvent.isJson ? angular.toJson(currentEvent.data) : currentEvent.data, - currentEvent.isJson, - currentEvent.eventStreamId, - currentEvent.eventType, - currentEvent.category, - currentEvent.eventNumber, - currentEvent.isJson ? angular.toJson(currentEvent.metadata) : currentEvent.metadata); - } else if (definition.byStream) { - partition = currentEvent.eventStreamId; - } else { - partition = ''; - } - - setPartition(partition); - - if (cachedStates[partition]) { - stateLoaded(cachedStates[partition]); - } else { - updateStatusInfo('Loading the projection state...'); - projectionsService.state($scope.location, { - partition: partition - }) - .then(function (res) { - stateLoaded(res.data); - }, function (error) { - updateStatusInfo('Failed to load the projection state: ' + error.message); - }); - } - } - - function stateLoaded(data) { - var cached; - updateStatusInfo('Ready for debugging!'); - $scope.isRunning = false; - if (data === '') { - processor.initialize(); - cachedStates[partition] = processor.debugging_get_state(); - } else { - data = tryParseJSON(data) ? data : angular.toJson(data); - cachedStates[partition] = data; - processor.set_state(data); - } - try { - cached = angular.fromJson(cachedStates[partition]); - $scope.state = cached; - } catch (e) { - $scope.state = ''; - } - } - - function tryParseJSON (jsonString){ - try { - var o = JSON.parse(jsonString); - if (o && typeof o === 'object' && o !== null) { - return o; - } - } - catch (e) { } - - return false; - } - - function cancelLoadingEvents(){ - if(currentLoadEventsTimeout){ - $timeout.cancel(currentLoadEventsTimeout); - currentLoadEventsTimeout = null; - } - } - - $scope.runStep = function () { - var state = processor.process_event( - currentEvent.isJson ? JSON.stringify(currentEvent.data) : currentEvent.data, - currentEvent.isJson, - currentEvent.eventStreamId, - currentEvent.eventType, - currentEvent.category, - currentEvent.eventNumber, - currentEvent.isJson ? JSON.stringify(currentEvent.metadata) : currentEvent.metadata, - currentEvent.isJson ? JSON.stringify(currentEvent.linkMetadata) : currentEvent.linkMetadata, - partition); - - cachedStates[partition] = state; - stateLoaded(cachedStates[partition]); - - currentPosition = currentEvent.readerPosition; - loadEvents(); - }; - - $scope.update = function () { - $scope.isUpdating = true; - projectionsService.updateQuery($scope.location, null, $scope.query) - .then(function () { - msg.info('Projection Updated'); - $window.location.reload(); - }, function (error) { - $scope.isUpdating = false; - msg.failure('Failed to update projection: ' + error.message); - }); - }; - - $scope.stop = function () { - cancelLoadingEvents(); - projectionsService.disable($scope.location) - .then(function () { - msg.info('Projection Stopped'); - $scope.isRunning = false; - }, function (error) { - msg.failure('Failed to stop projection: ' + error.message); - }); - }; - - $scope.goBack = function() { - if($stateParams.fromQueryState) { - $state.go('query', {location: $scope.location}); - } else { - $state.go('^.details'); - } - }; - } - ]); -}); diff --git a/src/js/modules/projections/controllers/_index.js b/src/js/modules/projections/controllers/_index.js index 47e9402e..fccc2887 100644 --- a/src/js/modules/projections/controllers/_index.js +++ b/src/js/modules/projections/controllers/_index.js @@ -1,5 +1,4 @@ define([ - './ProjectionsItemDebugCtrl', './ProjectionsItemDeleteCtrl', './ProjectionsItemDetailsCtrl', './ProjectionsItemEditCtrl', diff --git a/src/js/modules/projections/templates/templates.js b/src/js/modules/projections/templates/templates.js index ad2c46c4..6207e043 100644 --- a/src/js/modules/projections/templates/templates.js +++ b/src/js/modules/projections/templates/templates.js @@ -46,7 +46,7 @@ try { } module.run(['$templateCache', function($templateCache) { $templateCache.put('projections.item.details.tpl.html', - '

{{stats.name}} - {{stats.status}}

mode: {{stats.mode}}

{{stats.stateReason}}

Source

Stats
Events/sec{{ stats.eventsPerSecond }}
Buffered events{{ stats.bufferedEvents }}
Events processed{{ stats.eventsProcessedAfterRestart }}
Partitions cached{{ stats.partitionsCached }}
Reads in-progress{{ stats.readsInProgress }}
Writes in-progress{{ stats.writesInProgress }}
Write queue{{ stats.writePendingEventsAfterCheckpoint }}
Write queue (chkp){{ stats.writePendingEventsBeforeCheckpoint }}
Checkpoint status{{ stats.checkpointStatus }}
Position{{ stats.position }}
Last checkpoint{{ stats.lastCheckpoint }}
Results ({{ stream }})
{{result | json}}
State
{{state | json}}
'); + '

{{stats.name}} - {{stats.status}}

mode: {{stats.mode}}

{{stats.stateReason}}

Source

Stats
Events/sec{{ stats.eventsPerSecond }}
Buffered events{{ stats.bufferedEvents }}
Events processed{{ stats.eventsProcessedAfterRestart }}
Partitions cached{{ stats.partitionsCached }}
Reads in-progress{{ stats.readsInProgress }}
Writes in-progress{{ stats.writesInProgress }}
Write queue{{ stats.writePendingEventsAfterCheckpoint }}
Write queue (chkp){{ stats.writePendingEventsBeforeCheckpoint }}
Checkpoint status{{ stats.checkpointStatus }}
Position{{ stats.position }}
Last checkpoint{{ stats.lastCheckpoint }}
Results ({{ stream }})
{{result | json}}
State
{{state | json}}
'); }]); })(); diff --git a/src/js/modules/projections/views/projections.item.debug.tpl.html b/src/js/modules/projections/views/projections.item.debug.tpl.html deleted file mode 100644 index 82b26229..00000000 --- a/src/js/modules/projections/views/projections.item.debug.tpl.html +++ /dev/null @@ -1,63 +0,0 @@ - - -

Current Status: {{statusInfo}}

- -
-
-

Source

-
-

The query has been updated but not saved. Your changes will not take effect until you hit the "Update" button

-
-
- -
-
-

State {{ currentPartition }}

-
-{{ state | json }}
-				
-

Events

-
-
-
- -
-
-
-

Instructions

-
    -
  1. Make sure you use the Google Chrome browser.
  2. -
  3. Open a debugger (Ctrl+Shift+J on Windows).
  4. -
  5. Check the debugger console for errors (occurred while running the projection definition on while loading state and events).
  6. -
  7. Click the ‘Run’ button above.
  8. -
  9. Watch for errors in the debugger console
  10. -
  11. Check the debugging status on XXXXXXXXX.
  12. -
  13. Execution will stop on ‘debugger’ statement immediately before invoking your event handler.
  14. -
-

Any log output and emitted events will appear in the log viewer.

-
-
-
-

Log Viewer

- -
-
-
diff --git a/src/js/modules/projections/views/projections.item.details.tpl.html b/src/js/modules/projections/views/projections.item.details.tpl.html index 3975f755..9162e8c5 100644 --- a/src/js/modules/projections/views/projections.item.details.tpl.html +++ b/src/js/modules/projections/views/projections.item.details.tpl.html @@ -17,10 +17,9 @@

Projection Details

-