You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spot.apache.org by ev...@apache.org on 2017/01/25 18:36:53 UTC
[41/49] incubator-spot git commit: Ingest summary is now a top level
section
Ingest summary is now a top level section
Project: http://git-wip-us.apache.org/repos/asf/incubator-spot/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-spot/commit/8a695097
Tree: http://git-wip-us.apache.org/repos/asf/incubator-spot/tree/8a695097
Diff: http://git-wip-us.apache.org/repos/asf/incubator-spot/diff/8a695097
Branch: refs/heads/master
Commit: 8a69509780620491de1a2801796b9d764061356c
Parents: 5901e06
Author: Diego Ortiz Huerta <di...@intel.com>
Authored: Tue Dec 6 08:53:11 2016 -0800
Committer: Everardo Lopez Sandoval (Intel) <el...@elopezsa-mac02.ra.intel.com>
Committed: Fri Jan 20 17:01:02 2017 -0800
----------------------------------------------------------------------
spot-oa/ui/flow/ingest-summary.html | 158 -------------
spot-oa/ui/flow/js/actions/InSumActions.js | 12 -
.../js/components/IngestSummaryPanel.react.js | 235 ------------------
.../ui/flow/js/constants/NetflowConstants.js | 9 +-
spot-oa/ui/flow/js/ingest-summary.js | 94 --------
spot-oa/ui/flow/js/stores/IngestSummaryStore.js | 34 +--
spot-oa/ui/flow/package.json | 6 +-
spot-oa/ui/ingest-summary.html | 155 ++++++++++++
spot-oa/ui/js/actions/InSumActions.js | 12 +
.../js/components/IngestSummaryPanel.react.js | 236 +++++++++++++++++++
spot-oa/ui/js/constants/SpotConstants.js | 5 +
spot-oa/ui/js/ingest-summary.js | 94 ++++++++
spot-oa/ui/js/stores/IngestSummaryStore.js | 161 +++++++++++++
spot-oa/ui/package.json | 6 +-
14 files changed, 688 insertions(+), 529 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/flow/ingest-summary.html
----------------------------------------------------------------------
diff --git a/spot-oa/ui/flow/ingest-summary.html b/spot-oa/ui/flow/ingest-summary.html
deleted file mode 100755
index c13ab9f..0000000
--- a/spot-oa/ui/flow/ingest-summary.html
+++ /dev/null
@@ -1,158 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>Netflow :: Ingest Summary</title>
-
- <meta charset="UTF-8">
-
- <!--Bootstrap styles-->
- <link rel="stylesheet" type="text/css" href="../css/bootstrap-spot.min.css" />
- <!--Bootstrap Date picker styles-->
- <link rel="stylesheet" type="text/css" href="../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css" />
- <!-- Spot styles -->
- <link rel="stylesheet" type="text/css" href="../css/main.css" />
- <!-- Favicon -->
- <link rel="apple-touch-icon" sizes="57x57" href="../images/favicon/apple-icon-57x57.png">
- <link rel="apple-touch-icon" sizes="60x60" href="../images/favicon/apple-icon-60x60.png"
- <link rel="apple-touch-icon" sizes="72x72" href="../images/favicon/apple-icon-72x72.png">
- <link rel="apple-touch-icon" sizes="76x76" href="../images/favicon/apple-icon-76x76.png">
- <link rel="apple-touch-icon" sizes="114x114" href="../images/favicon/apple-icon-114x114.png">
- <link rel="apple-touch-icon" sizes="120x120" href="../images/favicon/apple-icon-120x120.png">
- <link rel="apple-touch-icon" sizes="144x144" href="../images/favicon/apple-icon-144x144.png">
- <link rel="apple-touch-icon" sizes="152x152" href="../images/favicon/apple-icon-152x152.png">
- <link rel="apple-touch-icon" sizes="180x180" href="../images/favicon/apple-icon-180x180.png">
- <link rel="icon" type="image/png" sizes="192x192" href="../images/favicon/android-icon-192x192.png">
- <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon/favicon-32x32.png">
- <link rel="icon" type="image/png" sizes="96x96" href="../images/favicon/favicon-96x96.png">
- <link rel="icon" type="image/png" sizes="16x16" href="../images/favicon/favicon-16x16.png">
- <link rel="manifest" href="../images/favicon/manifest.json">
- <meta name="msapplication-TileColor" content="#ffffff">
- <meta name="msapplication-TileImage" content="../images/favicon/ms-icon-144x144.png">
- <meta name="theme-color" content="#ffffff">
- <style type="text/css">
- .spot-row {
- height: 100%;
- }
-
- #spot-is-header {
- width: 100%;
- position: absolute;
- top: 0;
- left: 0;
- z-index: 2;
- height: auto;
- }
-
- #spot-is, #spot-is-summary {
- height: 100%;
- }
-
- .axis {
- shape-rendering: crispEdges;
- }
-
- .axis path, .axis line {
- fill: none;
- }
-
- rect.pane {
- cursor: e-resize;
- fill: none;
- pointer-events: all;
- }
- </style>
-</head>
-<body>
- <nav id="spot-nav" class="navbar navbar-default">
- <div class="container-fluid">
- <!-- App name and toggle get grouped for better mobile display -->
- <div class="navbar-header">
- <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu">
- <span class="sr-only">Toggle navigation</span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <span class="navbar-brand">Apache Spot :: Netflow :: Ingest Summary</span>
- </div>
- <!-- Collect the nav links, forms, and other content for toggling -->
- <div class="collapse navbar-collapse" id="main-menu">
- <ul class="nav navbar-nav navbar-right">
- <li class="dropdown">
- <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
- Flows
- <span class="caret"></span>
- </a>
- <ul class="dropdown-menu" aria-labelledby="flowsMenu">
- <li>
- <a data-href="suspicious.html#date=${end-date}">Suspicious</a>
- </li>
- <li>
- <a data-href="threat-investigation.html#date=${end-date}">Threat Investigation</a>
- </li>
- <li>
- <a data-href="storyboard.html#date=${end-date}">Storyboard</a>
- </li>
- <li>
- <a data-href="ingest-summary.html#end-date=${end-date}">Ingest Summary</a>
- </li>
- </ul>
- </li>
- <li class="dropdown">
- <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
- DNS
- <span class="caret"></span>
- </a>
- <ul class="dropdown-menu" aria-labelledby="dnsMenu">
- <li>
- <a data-href="../dns/suspicious.html#date=${end-date}">Suspicious</a>
- </li>
- <li>
- <a data-href="../dns/threat-investigation.html#date=${end-date}">Threat Investigation</a>
- </li>
- <li>
- <a data-href="../dns/storyboard.html#date=${end-date}">Storyboard</a>
- </li>
- </ul>
- </li>
- <li class="dropdown">
- <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
- Proxy
- <span class="caret"></span>
- </a>
- <ul class="dropdown-menu" aria-labelledby="proxyMenu">
- <li>
- <a data-href="../proxy/suspicious.html#date=${end-date}">Suspicious</a>
- </li>
- <li>
- <a data-href="../proxy/threat-investigation.html#date=${end-date}">Threat Investigation</a>
- </li>
- <li>
- <a data-href="../proxy/storyboard.html#date=${end-date}">Storyboard</a>
- </li>
- </ul>
- </li>
- </ul>
- </div>
- <div id="search-box" class="row text-right">
- <!--Tools Buttons-->
- <div id="nav_form" class="col-md-12">
- <!-- Search form placeholder -->
- </div>
- </div> <!-- /Tools Buttons-->
- </div>
- </nav>
- <div id="spot-content-wrapper" class="container-fluid">
- <!-- Main Content Placeholder -->
- </div>
-
- <!-- SCRIPTS -->
- <script type="application/javascript" src="../node_modules/jquery/dist/jquery.min.js"></script>
- <script type="application/javascript" src="../node_modules/d3/d3.min.js"></script>
- <script type="application/javascript" src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
- <script type="application/javascript" src="../node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
- <script type="application/javascript" src="../node_modules/react/dist/react.min.js"></script>
- <script type="application/javascript" src="../node_modules/react-dom/dist/react-dom.min.js"></script>
- <script type="application/javascript" src="js/ingest-summary.bundle.min.js"></script>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/flow/js/actions/InSumActions.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/flow/js/actions/InSumActions.js b/spot-oa/ui/flow/js/actions/InSumActions.js
deleted file mode 100755
index 7b8f9df..0000000
--- a/spot-oa/ui/flow/js/actions/InSumActions.js
+++ /dev/null
@@ -1,12 +0,0 @@
-var SpotDispatcher = require('../../../js/dispatchers/SpotDispatcher');
-var NetflowConstants = require('../constants/NetflowConstants');
-
-var InSumActions = {
- reloadSummary: function () {
- SpotDispatcher.dispatch({
- actionType: NetflowConstants.RELOAD_INGEST_SUMMARY
- });
- }
-};
-
-module.exports = InSumActions;
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/flow/js/components/IngestSummaryPanel.react.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/flow/js/components/IngestSummaryPanel.react.js b/spot-oa/ui/flow/js/components/IngestSummaryPanel.react.js
deleted file mode 100755
index 77af5dd..0000000
--- a/spot-oa/ui/flow/js/components/IngestSummaryPanel.react.js
+++ /dev/null
@@ -1,235 +0,0 @@
-const $ = require('jquery');
-const d3 = require('d3');
-const React = require('react');
-const ReactDOM = require('react-dom');
-
-var DateUtils = require('../../../js/utils/DateUtils');
-var InSumActions = require('../actions/InSumActions');
-var IngestSummaryStore = require('../stores/IngestSummaryStore');
-
-function initialDraw() {
- var rootNode, format, x, y, xAxis, yAxis, area, svg, rect, total, minDate, maxDate, maxFlows, numberFormat;
-
- rootNode = d3.select(ReactDOM.findDOMNode(this));
-
- // graph dimensions
- var m = [100, 50, 50, 80], // Margin
- w = $(rootNode.node()).width() - m[1] - m[3], // Width
- h = $(rootNode.node()).height() - m[0] - m[2]; // Height
-
- format = d3.time.format("%Y-%m-%d %H:%M");
-
- // Scales.
- x = d3.time.scale().range([0, w]); // get X function
- y = d3.scale.linear().range([h, 0]); // get Y function
- xAxis = d3.svg.axis().scale(x).orient("bottom"); // Get the X axis (Time)
- yAxis = d3.svg.axis().scale(y).orient("left"); // Get Y Axis (Netflows)
-
- // An area generator.
- area = d3.svg.area()
- .x(function (d) {
- return x(d.date);
- })
- .y0(h)
- .y1(function (d) {
- if (!isNaN(d.flows))
- return y(d.flows);
- else
- return y(0);
- });
-
- rootNode.select('svg').remove();
-
- // define the Main SVG
- svg = rootNode.select('#' + this.props.id + '-summary').append("svg")
- .attr("width", w + m[1] + m[3])
- .attr("height", h + m[0] + m[2])
- .append("g")
- .attr("transform", "translate(" + m[3] + "," + m[0] + ")")
-
- // Append the clipPath to avoid the Area overlapping
- svg.append("clipPath")
- .attr("id", "clip")
- .append("rect")
- .attr("x", x(0))
- .attr("y", y(1))
- .attr("width", x(1) - x(0))
- .attr("height", y(0) - y(1));
-
- // Append the Y Axis group
- svg.append("g")
- .attr("class", "y axis");
-
- // Append the X axis group
- svg.append("g")
- .attr("class", "x axis")
- .attr("transform", "translate(0," + h + ")");
-
- // Append a pane rect, which will help us to add the zoom functionality
- rect = svg.append("rect")
- .attr("class", "pane")
- .attr("width", w)
- .attr("height", h);
-
- this.state.data.forEach(function (dataSet)
- {
- var a;
-
- a = [{date: minDate}];
- a.push.apply(a, dataSet);
- minDate = d3.min(a, function (d) { return d.date; });
- a[0] = {date: maxDate, flows: maxFlows};
- maxDate = d3.max(a, function (d) { return d.date; });
- maxFlows = d3.max(a, function (d) { return d.flows; })
- });
-
- !minDate && (minDate = DateUtils.parseDate(IngestSummaryStore.getStartDate()));
- !maxDate && (maxDate = DateUtils.parseDate(IngestSummaryStore.getEndDate()));
-
- // bind the data to the X and Y generators
- x.domain([minDate, maxDate]);
- y.domain([0, maxFlows]);
-
- // Bind the data to our path element.
- svg.selectAll("path.area").data(this.state.data).enter().insert('path', 'g')
- .attr('class', 'area')
- .attr('clip-path', 'url(#clip)')
- .style('fill', '#0071c5')
- .attr('d', function (d) {
- return area(d);
- });
-
- //Add the pane rect the zoom behavior
- rect.call(d3.behavior.zoom().x(x)
- .scaleExtent([0.3, 2300]) // these are magic numbers to avoid the grap be zoomable in/out to the infinity
- .on("zoom", zoom.bind(this)));
-
- function draw () {
- var total, minDate, maxDate, numberFormat;
-
- svg.select("g.x.axis").call(xAxis);
- svg.select("g.y.axis").call(yAxis);
- svg.selectAll("path.area").attr("d", function (d) { return area(d); });
- numberFormat = d3.format(",d"); // number formatter (comma separated number i.e. 100,000,000)
-
- rootNode.select('#' + this.props.id + '-range').html("Seeing total flows <strong>from:</strong> " + x.domain().map(format).join(" <strong>to:</strong> "));
-
- //Calculate the total flows between the displayed date range
-
- total = 0;
- minDate = x.domain()[0];
- maxDate = x.domain()[1];
-
- // Go to the first millisecond on dates
- minDate.setSeconds(0);minDate.setMilliseconds(0);
- maxDate.setSeconds(59);maxDate.setMilliseconds(0);
-
- svg.selectAll("path.area").data().forEach(function (pathData)
- {
- pathData.forEach(function (record)
- {
- // Discard records outside displayed date range
- if (record.date >= minDate && record.date <= maxDate) {
- total += +record.flows;
- }
- });
- });
-
- rootNode.select('#' + this.props.id + '-total').html("<strong>Total netflows in range:</strong> " + numberFormat(total));
- }
-
- /*
- Zoom event handler
- */
- function zoom() {
- if (d3.event.sourceEvent.type == "wheel") {
- if (d3.event.sourceEvent.wheelDelta < 0)
- rect.style("cursor", "zoom-out");
- else
- rect.style("cursor", "zoom-in");
- }
- else if (d3.event.sourceEvent.type == "mousemove") {
- rect.style("cursor", "e-resize");
- }
-
- draw.call(this);
- }
-
- draw.call(this);
-}
-
-var IngestSummaryPanel = React.createClass({
- propTypes: {
- id: React.PropTypes.string
- },
- getDefaultProperties: function () {
- return {
- id: 'spot-is'
- };
- },
- getInitialState: function ()
- {
- return {loading: true};
- },
- render:function()
- {
- var content;
-
- if (this.state.error)
- {
- content = (
- <div className="text-center text-danger">
- {this.state.error}
- </div>
- );
- }
- else if (this.state.loading)
- {
- content = (
- <div className="spot-loader">
- Loading <span className="spinner"></span>
- </div>
- );
- }
- else
- {
- content = (
- <div id={this.props.id} className="text-center">
- <div id={this.props.id + '-header'}>
- <p id={this.props.id + '-range'}></p>
- <p id={this.props.id + '-total'}></p>
- <p id={this.props.id + '-istructions'} className="small">** Zoom in/out using mouse wheel or two fingers in track pad <br /> ** Move across the x-axis by clicking anywhere in the graph and dragging to left or right</p>
- </div>
- <div id={this.props.id + '-summary'}></div>
- </div>
- );
- }
-
- return (
- <div>{content}</div>
- )
- },
- componentDidMount: function()
- {
- IngestSummaryStore.addChangeDataListener(this._onChange);
- window.addEventListener('resize', this.buildGraph);
- },
- componentWillUnmount: function ()
- {
- IngestSummaryStore.removeChangeDataListener(this._onChange);
- window.removeEventListener('resize', this.buildGraph);
- },
- componentDidUpdate: function ()
- {
- if (!this.state.loading && !this.state.error && this.state.data)
- {
- this.buildGraph();
- }
- },
- buildGraph: initialDraw,
- _onChange: function () {
- this.replaceState(IngestSummaryStore.getData());
- }
-});
-
-module.exports = IngestSummaryPanel;
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/flow/js/constants/NetflowConstants.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/flow/js/constants/NetflowConstants.js b/spot-oa/ui/flow/js/constants/NetflowConstants.js
index 92da4b2..c0fc7a8 100755
--- a/spot-oa/ui/flow/js/constants/NetflowConstants.js
+++ b/spot-oa/ui/flow/js/constants/NetflowConstants.js
@@ -1,20 +1,15 @@
var NetflowConstants = {
- // Netflow Actions
- RELOAD_INGEST_SUMMARY: 'RELOAD_INGEST_SUMMARY',
- // INGEST SUMMARY
- START_DATE: 'start-date',
- END_DATE: 'end-date',
// Data source URLS
API_SUSPICIOUS: '../../data/flow/${date}/flow_scores.csv',
API_DETAILS: '../../data/flow/${date}/edge-${src_ip}-${dst_ip}-${time}.tsv',
API_VISUAL_DETAILS: '../../data/flow/${date}/chord-${ip}.tsv',
API_COMMENTS: '../../data/flow/${date}/threats.csv',
API_INCIDENT_PROGRESSION: '../../data/flow/${date}/threat-dendro-${ip}.json',
- API_INGEST_SUMMARY: '../../data/flow/ingest_summary/is_${year}${month}.csv',
+ API_INGEST_SUMMARY: '../data/flow/ingest_summary/is_${year}${month}.csv',
API_IMPACT_ANALYSIS: '../../data/flow/${date}/stats-${ip}.json',
API_GLOBE_VIEW: '../../data/flow/${date}/globe-${ip}.json',
API_WORLD_110M: '../flow/world-110m.json',
- API_TIMELINE: '../../data/flow/${date}/sbdet-${ip}.tsv',
+ API_TIMELINE: '../../data/flow/${date}/sbdet-${ip}.tsv'
};
module.exports = NetflowConstants;
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/flow/js/ingest-summary.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/flow/js/ingest-summary.js b/spot-oa/ui/flow/js/ingest-summary.js
deleted file mode 100755
index 1bf71b7..0000000
--- a/spot-oa/ui/flow/js/ingest-summary.js
+++ /dev/null
@@ -1,94 +0,0 @@
-const React = require('react');
-const ReactDOM = require('react-dom');
-
-const SpotActions = require('../../js/actions/SpotActions');
-const InSumActions = require('./actions/InSumActions');
-const NetflowConstants = require('./constants/NetflowConstants');
-const SpotUtils = require('../../js/utils/SpotUtils');
-const DateUtils = require('../../js/utils/DateUtils');
-
-// Build and Render Toolbar
-const DateInput = require('../../js/components/DateInput.react');
-
-// Find out period
-var startDate, endDate, today;
-
-today = new Date();
-startDate = SpotUtils.getUrlParam(NetflowConstants.START_DATE);
-endDate = SpotUtils.getUrlParam(NetflowConstants.END_DATE);
-
-if (!startDate && endDate)
-{
- startDate = DateUtils.formatDate(DateUtils.calcDate(DateUtils.parseDate(endDate), -7));
-}
-else if (startDate && !endDate)
-{
- endDate = DateUtils.formatDate(DateUtils.calcDate(DateUtils.parseDate(startDate), 7));
-}
-else if (!startDate && !endDate)
-{
- // Default endDate to today and startDate to 7 days before
- startDate = DateUtils.formatDate(DateUtils.calcDate(today, -7));
- endDate = DateUtils.formatDate(today);
-}
-
-// We got values for both dates, make use endDate is after startDate
-if (endDate < startDate)
-{
- // Use today var to switch dates
- today = startDate;
- startDate = endDate;
- endDate = today;
-}
-
-ReactDOM.render(
- (
- <form className="form-inline">
- <div className="form-group">
- <label htmlFor="startDatePicker">Period:</label>
- <div className="input-group input-group-xs">
- <div className="input-group-addon">
- <span className="glyphicon glyphicon-calendar" aria-hidden="true"></span>
- </div>
- <DateInput id="startDatePicker" name={NetflowConstants.START_DATE} value={startDate}/>
- </div>
- </div>
- <div className="form-group">
- <label htmlFor="endDatePicker"> - </label>
- <div className="input-group input-group-xs">
- <DateInput id="endDatePicker" name={NetflowConstants.END_DATE} value={endDate} />
- <div className="input-group-btn">
- <button className="btn btn-default" type="button" title="Reload" onClick={InSumActions.reloadSummary}>
- <span className="glyphicon glyphicon-repeat" aria-hidden="true"></span>
- </button>
- </div>
- </div>
- </div>
- </form>
- ),
- document.getElementById('nav_form')
-);
-
-// Build and Render Edge Investigation's panels
-const PanelRow = require('../../js/components/PanelRow.react');
-const Panel = require('../../js/components/Panel.react');
-//
-const IngestSummaryPanel = require('./components/IngestSummaryPanel.react');
-
-ReactDOM.render(
- <div id="spot-content">
- <PanelRow maximized>
- <Panel title="Ingest Summary" container header={false} className="col-md-12">
- <IngestSummaryPanel id="spot-is" />
- </Panel>
- </PanelRow>
- </div>,
- document.getElementById('spot-content-wrapper')
-);
-
-// Set period
-SpotActions.setDate(startDate, NetflowConstants.START_DATE);
-SpotActions.setDate(endDate, NetflowConstants.END_DATE);
-
-// Load data
-InSumActions.reloadSummary();
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/flow/js/stores/IngestSummaryStore.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/flow/js/stores/IngestSummaryStore.js b/spot-oa/ui/flow/js/stores/IngestSummaryStore.js
index 9e4ccb5..55f2106 100755
--- a/spot-oa/ui/flow/js/stores/IngestSummaryStore.js
+++ b/spot-oa/ui/flow/js/stores/IngestSummaryStore.js
@@ -1,20 +1,20 @@
-var assign = require('object-assign');
-var d3 = require('d3');
+const assign = require('object-assign');
+const d3 = require('d3');
-var SpotDispatcher = require('../../../js/dispatchers/SpotDispatcher');
-var SpotConstants = require('../../../js/constants/SpotConstants');
-var NetflowConstants = require('../constants/NetflowConstants');
-var DateUtils = require('../../../js/utils/DateUtils');
-var RestStore = require('../../../js/stores/RestStore');
+const SpotDispatcher = require('../../../js/dispatchers/SpotDispatcher');
+const SpotConstants = require('../../../js/constants/SpotConstants');
+const NetflowConstants = require('../constants/NetflowConstants');
+const DateUtils = require('../../../js/utils/DateUtils');
+const RestStore = require('../../../js/stores/RestStore');
-var START_DATE_FILTER = NetflowConstants.START_DATE;
-var END_DATE_FILTER = NetflowConstants.END_DATE;
-var CURRENT_DATE_FILTER = 'current_date';
+const START_DATE_FILTER = SpotConstants.START_DATE;
+const END_DATE_FILTER = SpotConstants.END_DATE;
+const CURRENT_DATE_FILTER = 'current_date';
-var requestQueue = [];
-var requestErrors = [];
+const requestQueue = [];
+const requestErrors = [];
-var IngestSummaryStore = assign(new RestStore(NetflowConstants.API_INGEST_SUMMARY), {
+const IngestSummaryStore = assign(new RestStore(NetflowConstants.API_INGEST_SUMMARY), {
errorMessages: {
404: 'No details available'
},
@@ -128,7 +128,7 @@ var IngestSummaryStore = assign(new RestStore(NetflowConstants.API_INGEST_SUMMAR
this._data.loading = requestQueue.length > 0;
if (!this._data.loading) {
- if (this._data.data.length==0) {
+ if (this._data.data && this._data.data.length==0) {
// Broadcast first found error
this._data = requestErrors[0];
}
@@ -144,15 +144,15 @@ SpotDispatcher.register(function (action) {
switch (action.actionType) {
case SpotConstants.UPDATE_DATE:
switch (action.name) {
- case NetflowConstants.START_DATE:
+ case SpotConstants.START_DATE:
IngestSummaryStore.setStartDate(action.date);
break;
- case NetflowConstants.END_DATE:
+ case SpotConstants.END_DATE:
IngestSummaryStore.setEndDate(action.date);
break;
}
break;
- case NetflowConstants.RELOAD_INGEST_SUMMARY:
+ case SpotConstants.RELOAD_INGEST_SUMMARY:
IngestSummaryStore.requestSummary();
break;
}
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/flow/package.json
----------------------------------------------------------------------
diff --git a/spot-oa/ui/flow/package.json b/spot-oa/ui/flow/package.json
index dcf4171..62f47ae 100755
--- a/spot-oa/ui/flow/package.json
+++ b/spot-oa/ui/flow/package.json
@@ -6,12 +6,10 @@
"watch-suspicious": "watchify js/suspicious.js -o js/suspicious.bundle.min.js -v -d",
"watch-threat-investigation": "watchify js/threat-investigation.js -o js/threat-investigation.bundle.min.js -v -d",
"watch-storyboard": "watchify js/storyboard.js -o js/storyboard.bundle.min.js -v -d",
- "watch-ingest-summary": "watchify js/ingest-summary.js -o js/ingest-summary.bundle.min.js -v -d",
- "build-all": "npm run build-suspicious && npm run build-threat-investigation && npm run build-ingest-summary && npm run build-storyboard",
+ "build-all": "npm run build-suspicious && npm run build-threat-investigation && npm run build-storyboard",
"build-suspicious": "browserify js/suspicious.js | uglifyjs -cm > js/suspicious.bundle.min.js",
"build-threat-investigation": "browserify js/threat-investigation.js | uglifyjs -cm > js/threat-investigation.bundle.min.js",
- "build-storyboard": "browserify js/storyboard.js | uglifyjs -cm > js/storyboard.bundle.min.js",
- "build-ingest-summary": "browserify js/ingest-summary.js | uglifyjs -cm > js/ingest-summary.bundle.min.js"
+ "build-storyboard": "browserify js/storyboard.js | uglifyjs -cm > js/storyboard.bundle.min.js"
},
"browserify": {
"transform": [
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/ingest-summary.html
----------------------------------------------------------------------
diff --git a/spot-oa/ui/ingest-summary.html b/spot-oa/ui/ingest-summary.html
new file mode 100755
index 0000000..e694609
--- /dev/null
+++ b/spot-oa/ui/ingest-summary.html
@@ -0,0 +1,155 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Netflow :: Ingest Summary</title>
+
+ <meta charset="UTF-8">
+
+ <!--Bootstrap styles-->
+ <link rel="stylesheet" type="text/css" href="css/bootstrap-spot.min.css" />
+ <!--Bootstrap Date picker styles-->
+ <link rel="stylesheet" type="text/css" href="node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css" />
+ <!-- Spot styles -->
+ <link rel="stylesheet" type="text/css" href="css/main.css" />
+ <!-- Favicon -->
+ <link rel="apple-touch-icon" sizes="57x57" href="images/favicon/apple-icon-57x57.png">
+ <link rel="apple-touch-icon" sizes="60x60" href="images/favicon/apple-icon-60x60.png"
+ <link rel="apple-touch-icon" sizes="72x72" href="images/favicon/apple-icon-72x72.png">
+ <link rel="apple-touch-icon" sizes="76x76" href="images/favicon/apple-icon-76x76.png">
+ <link rel="apple-touch-icon" sizes="114x114" href="images/favicon/apple-icon-114x114.png">
+ <link rel="apple-touch-icon" sizes="120x120" href="images/favicon/apple-icon-120x120.png">
+ <link rel="apple-touch-icon" sizes="144x144" href="images/favicon/apple-icon-144x144.png">
+ <link rel="apple-touch-icon" sizes="152x152" href="images/favicon/apple-icon-152x152.png">
+ <link rel="apple-touch-icon" sizes="180x180" href="images/favicon/apple-icon-180x180.png">
+ <link rel="icon" type="image/png" sizes="192x192" href="images/favicon/android-icon-192x192.png">
+ <link rel="icon" type="image/png" sizes="32x32" href="images/favicon/favicon-32x32.png">
+ <link rel="icon" type="image/png" sizes="96x96" href="images/favicon/favicon-96x96.png">
+ <link rel="icon" type="image/png" sizes="16x16" href="images/favicon/favicon-16x16.png">
+ <link rel="manifest" href="images/favicon/manifest.json">
+ <meta name="msapplication-TileColor" content="#ffffff">
+ <meta name="msapplication-TileImage" content="images/favicon/ms-icon-144x144.png">
+ <meta name="theme-color" content="#ffffff">
+ <style type="text/css">
+ .spot-row {
+ height: 100%;
+ }
+
+ #spot-is-header {
+ width: 100%;
+ position: absolute;
+ top: 0;
+ left: 0;
+ z-index: 2;
+ height: auto;
+ }
+
+ #spot-is, #spot-is-summary {
+ height: 100%;
+ }
+
+ .axis {
+ shape-rendering: crispEdges;
+ }
+
+ .axis path, .axis line {
+ fill: none;
+ }
+
+ rect.pane {
+ cursor: e-resize;
+ fill: none;
+ pointer-events: all;
+ }
+ </style>
+</head>
+<body>
+ <nav id="spot-nav" class="navbar navbar-default">
+ <div class="container-fluid">
+ <!-- App name and toggle get grouped for better mobile display -->
+ <div class="navbar-header">
+ <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu">
+ <span class="sr-only">Toggle navigation</span>
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ </button>
+ <span class="navbar-brand">Apache Spot :: Netflow :: Ingest Summary</span>
+ </div>
+ <!-- Collect the nav links, forms, and other content for toggling -->
+ <div class="collapse navbar-collapse" id="main-menu">
+ <ul class="nav navbar-nav navbar-right">
+ <li class="dropdown">
+ <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
+ Flows
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu" aria-labelledby="flowsMenu">
+ <li>
+ <a data-href="flow/suspicious.html#date=${end-date}">Suspicious</a>
+ </li>
+ <li>
+ <a data-href="flow/threat-investigation.html#date=${end-date}">Threat Investigation</a>
+ </li>
+ <li>
+ <a data-href="flow/storyboard.html#date=${end-date}">Storyboard</a>
+ </li>
+ </ul>
+ </li>
+ <li class="dropdown">
+ <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
+ DNS
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu" aria-labelledby="dnsMenu">
+ <li>
+ <a data-href="dns/suspicious.html#date=${end-date}">Suspicious</a>
+ </li>
+ <li>
+ <a data-href="dns/threat-investigation.html#date=${end-date}">Threat Investigation</a>
+ </li>
+ <li>
+ <a data-href="dns/storyboard.html#date=${end-date}">Storyboard</a>
+ </li>
+ </ul>
+ </li>
+ <li class="dropdown">
+ <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
+ Proxy
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu" aria-labelledby="proxyMenu">
+ <li>
+ <a data-href="proxy/suspicious.html#date=${end-date}">Suspicious</a>
+ </li>
+ <li>
+ <a data-href="proxy/threat-investigation.html#date=${end-date}">Threat Investigation</a>
+ </li>
+ <li>
+ <a data-href="proxy/storyboard.html#date=${end-date}">Storyboard</a>
+ </li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ <div id="search-box" class="row text-right">
+ <!--Tools Buttons-->
+ <div id="nav_form" class="col-md-12">
+ <!-- Search form placeholder -->
+ </div>
+ </div> <!-- /Tools Buttons-->
+ </div>
+ </nav>
+ <div id="spot-content-wrapper" class="container-fluid">
+ <!-- Main Content Placeholder -->
+ </div>
+
+ <!-- SCRIPTS -->
+ <script type="application/javascript" src="node_modules/jquery/dist/jquery.min.js"></script>
+ <script type="application/javascript" src="node_modules/d3/d3.min.js"></script>
+ <script type="application/javascript" src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
+ <script type="application/javascript" src="node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
+ <script type="application/javascript" src="node_modules/react/dist/react.min.js"></script>
+ <script type="application/javascript" src="node_modules/react-dom/dist/react-dom.min.js"></script>
+ <script type="application/javascript" src="js/ingest-summary.bundle.min.js"></script>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/js/actions/InSumActions.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/js/actions/InSumActions.js b/spot-oa/ui/js/actions/InSumActions.js
new file mode 100755
index 0000000..ea15715
--- /dev/null
+++ b/spot-oa/ui/js/actions/InSumActions.js
@@ -0,0 +1,12 @@
+const SpotDispatcher = require('../dispatchers/SpotDispatcher');
+const SpotConstants = require('../constants/SpotConstants');
+
+const InSumActions = {
+ reloadSummary: function () {
+ SpotDispatcher.dispatch({
+ actionType: SpotConstants.RELOAD_INGEST_SUMMARY
+ });
+ }
+};
+
+module.exports = InSumActions;
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/js/components/IngestSummaryPanel.react.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/js/components/IngestSummaryPanel.react.js b/spot-oa/ui/js/components/IngestSummaryPanel.react.js
new file mode 100755
index 0000000..cc951ad
--- /dev/null
+++ b/spot-oa/ui/js/components/IngestSummaryPanel.react.js
@@ -0,0 +1,236 @@
+const $ = require('jquery');
+const d3 = require('d3');
+const React = require('react');
+const ReactDOM = require('react-dom');
+
+const DateUtils = require('../utils/DateUtils');
+const InSumActions = require('../actions/InSumActions');
+
+const NetflowIngestSummaryStore = require('../../flow/js/stores/IngestSummaryStore');
+
+function initialDraw() {
+ var rootNode, format, x, y, xAxis, yAxis, area, svg, rect, total, minDate, maxDate, maxFlows, numberFormat;
+
+ rootNode = d3.select(ReactDOM.findDOMNode(this));
+
+ // graph dimensions
+ var m = [100, 50, 50, 80], // Margin
+ w = $(rootNode.node()).width() - m[1] - m[3], // Width
+ h = $(rootNode.node()).height() - m[0] - m[2]; // Height
+
+ format = d3.time.format("%Y-%m-%d %H:%M");
+
+ // Scales.
+ x = d3.time.scale().range([0, w]); // get X function
+ y = d3.scale.linear().range([h, 0]); // get Y function
+ xAxis = d3.svg.axis().scale(x).orient("bottom"); // Get the X axis (Time)
+ yAxis = d3.svg.axis().scale(y).orient("left"); // Get Y Axis (Netflows)
+
+ // An area generator.
+ area = d3.svg.area()
+ .x(function (d) {
+ return x(d.date);
+ })
+ .y0(h)
+ .y1(function (d) {
+ if (!isNaN(d.total))
+ return y(d.total);
+ else
+ return y(0);
+ });
+
+ rootNode.select('svg').remove();
+
+ // define the Main SVG
+ svg = rootNode.select('#' + this.props.id + '-summary').append("svg")
+ .attr("width", w + m[1] + m[3])
+ .attr("height", h + m[0] + m[2])
+ .append("g")
+ .attr("transform", "translate(" + m[3] + "," + m[0] + ")")
+
+ // Append the clipPath to avoid the Area overlapping
+ svg.append("clipPath")
+ .attr("id", "clip")
+ .append("rect")
+ .attr("x", x(0))
+ .attr("y", y(1))
+ .attr("width", x(1) - x(0))
+ .attr("height", y(0) - y(1));
+
+ // Append the Y Axis group
+ svg.append("g")
+ .attr("class", "y axis");
+
+ // Append the X axis group
+ svg.append("g")
+ .attr("class", "x axis")
+ .attr("transform", "translate(0," + h + ")");
+
+ // Append a pane rect, which will help us to add the zoom functionality
+ rect = svg.append("rect")
+ .attr("class", "pane")
+ .attr("width", w)
+ .attr("height", h);
+
+ this.state.data.forEach(function (dataSet)
+ {
+ var a;
+
+ a = [{date: minDate}];
+ a.push.apply(a, dataSet);
+ minDate = d3.min(a, function (d) { return d.date; });
+ a[0] = {date: maxDate, flows: maxFlows};
+ maxDate = d3.max(a, function (d) { return d.date; });
+ maxFlows = d3.max(a, function (d) { return d.total; })
+ });
+
+ !minDate && (minDate = DateUtils.parseDate(NetflowIngestSummaryStore.getStartDate()));
+ !maxDate && (maxDate = DateUtils.parseDate(NetflowIngestSummaryStore.getEndDate()));
+
+ // bind the data to the X and Y generators
+ x.domain([minDate, maxDate]);
+ y.domain([0, maxFlows]);
+
+ // Bind the data to our path element.
+ svg.selectAll("path.area").data(this.state.data).enter().insert('path', 'g')
+ .attr('class', 'area')
+ .attr('clip-path', 'url(#clip)')
+ .style('fill', '#0071c5')
+ .attr('d', function (d) {
+ return area(d);
+ });
+
+ //Add the pane rect the zoom behavior
+ rect.call(d3.behavior.zoom().x(x)
+ .scaleExtent([0.3, 2300]) // these are magic numbers to avoid the grap be zoomable in/out to the infinity
+ .on("zoom", zoom.bind(this)));
+
+ function draw () {
+ var total, minDate, maxDate, numberFormat;
+
+ svg.select("g.x.axis").call(xAxis);
+ svg.select("g.y.axis").call(yAxis);
+ svg.selectAll("path.area").attr("d", function (d) { return area(d); });
+ numberFormat = d3.format(",d"); // number formatter (comma separated number i.e. 100,000,000)
+
+ rootNode.select('#' + this.props.id + '-range').html("Seeing total flows <strong>from:</strong> " + x.domain().map(format).join(" <strong>to:</strong> "));
+
+ //Calculate the total flows between the displayed date range
+
+ total = 0;
+ minDate = x.domain()[0];
+ maxDate = x.domain()[1];
+
+ // Go to the first millisecond on dates
+ minDate.setSeconds(0);minDate.setMilliseconds(0);
+ maxDate.setSeconds(59);maxDate.setMilliseconds(0);
+
+ svg.selectAll("path.area").data().forEach(function (pathData)
+ {
+ pathData.forEach(function (record)
+ {
+ // Discard records outside displayed date range
+ if (record.date >= minDate && record.date <= maxDate) {
+ total += +record.total;
+ }
+ });
+ });
+
+ rootNode.select('#' + this.props.id + '-total').html("<strong>Total netflows in range:</strong> " + numberFormat(total));
+ }
+
+ /*
+ Zoom event handler
+ */
+ function zoom() {
+ if (d3.event.sourceEvent.type == "wheel") {
+ if (d3.event.sourceEvent.wheelDelta < 0)
+ rect.style("cursor", "zoom-out");
+ else
+ rect.style("cursor", "zoom-in");
+ }
+ else if (d3.event.sourceEvent.type == "mousemove") {
+ rect.style("cursor", "e-resize");
+ }
+
+ draw.call(this);
+ }
+
+ draw.call(this);
+}
+
+var IngestSummaryPanel = React.createClass({
+ propTypes: {
+ id: React.PropTypes.string
+ },
+ getDefaultProperties: function () {
+ return {
+ id: 'spot-is'
+ };
+ },
+ getInitialState: function ()
+ {
+ return {loading: true};
+ },
+ render:function()
+ {
+ var content;
+
+ if (this.state.error)
+ {
+ content = (
+ <div className="text-center text-danger">
+ {this.state.error}
+ </div>
+ );
+ }
+ else if (this.state.loading)
+ {
+ content = (
+ <div className="spot-loader">
+ Loading <span className="spinner"></span>
+ </div>
+ );
+ }
+ else
+ {
+ content = (
+ <div id={this.props.id} className="text-center">
+ <div id={this.props.id + '-header'}>
+ <p id={this.props.id + '-range'}></p>
+ <p id={this.props.id + '-total'}></p>
+ <p id={this.props.id + '-istructions'} className="small">** Zoom in/out using mouse wheel or two fingers in track pad <br /> ** Move across the x-axis by clicking anywhere in the graph and dragging to left or right</p>
+ </div>
+ <div id={this.props.id + '-summary'}></div>
+ </div>
+ );
+ }
+
+ return (
+ <div>{content}</div>
+ )
+ },
+ componentDidMount: function()
+ {
+ NetflowIngestSummaryStore.addChangeDataListener(this._onChange);
+ window.addEventListener('resize', this.buildGraph);
+ },
+ componentWillUnmount: function ()
+ {
+ NetflowIngestSummaryStore.removeChangeDataListener(this._onChange);
+ window.removeEventListener('resize', this.buildGraph);
+ },
+ componentDidUpdate: function ()
+ {
+ if (!this.state.loading && !this.state.error && this.state.data)
+ {
+ this.buildGraph();
+ }
+ },
+ buildGraph: initialDraw,
+ _onChange: function () {
+ this.replaceState(NetflowIngestSummaryStore.getData());
+ }
+});
+
+module.exports = IngestSummaryPanel;
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/js/constants/SpotConstants.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/js/constants/SpotConstants.js b/spot-oa/ui/js/constants/SpotConstants.js
index 03471c4..35e23c4 100755
--- a/spot-oa/ui/js/constants/SpotConstants.js
+++ b/spot-oa/ui/js/constants/SpotConstants.js
@@ -30,6 +30,11 @@ var SpotConstants = {
// Storyboard
RELOAD_COMMENTS: 'RELOAD_COMMENTS',
SELECT_COMMENT: 'SELECT_COMMENT',
+ // INGEST SUMMARY
+ START_DATE: 'start-date',
+ END_DATE: 'end-date',
+ // Ingest summary Actions
+ RELOAD_INGEST_SUMMARY: 'RELOAD_INGEST_SUMMARY',
// Server Paths
NOTEBOOKS_PATH: '/notebooks/ipynb'
};
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/js/ingest-summary.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/js/ingest-summary.js b/spot-oa/ui/js/ingest-summary.js
new file mode 100755
index 0000000..c42ed41
--- /dev/null
+++ b/spot-oa/ui/js/ingest-summary.js
@@ -0,0 +1,94 @@
+const React = require('react');
+const ReactDOM = require('react-dom');
+
+const SpotActions = require('./actions/SpotActions');
+const InSumActions = require('./actions/InSumActions');
+const SpotConstants = require('./constants/SpotConstants');
+const SpotUtils = require('./utils/SpotUtils');
+const DateUtils = require('./utils/DateUtils');
+
+// Build and Render Toolbar
+const DateInput = require('./components/DateInput.react');
+
+// Find out period
+var startDate, endDate, today;
+
+today = new Date();
+startDate = SpotUtils.getUrlParam(SpotConstants.START_DATE);
+endDate = SpotUtils.getUrlParam(SpotConstants.END_DATE);
+
+if (!startDate && endDate)
+{
+ startDate = DateUtils.formatDate(DateUtils.calcDate(DateUtils.parseDate(endDate), -7));
+}
+else if (startDate && !endDate)
+{
+ endDate = DateUtils.formatDate(DateUtils.calcDate(DateUtils.parseDate(startDate), 7));
+}
+else if (!startDate && !endDate)
+{
+ // Default endDate to today and startDate to 7 days before
+ startDate = DateUtils.formatDate(DateUtils.calcDate(today, -7));
+ endDate = DateUtils.formatDate(today);
+}
+
+// We got values for both dates, make use endDate is after startDate
+if (endDate < startDate)
+{
+ // Use today var to switch dates
+ today = startDate;
+ startDate = endDate;
+ endDate = today;
+}
+
+ReactDOM.render(
+ (
+ <form className="form-inline">
+ <div className="form-group">
+ <label htmlFor="startDatePicker">Period:</label>
+ <div className="input-group input-group-xs">
+ <div className="input-group-addon">
+ <span className="glyphicon glyphicon-calendar" aria-hidden="true"></span>
+ </div>
+ <DateInput id="startDatePicker" name={SpotConstants.START_DATE} value={startDate}/>
+ </div>
+ </div>
+ <div className="form-group">
+ <label htmlFor="endDatePicker"> - </label>
+ <div className="input-group input-group-xs">
+ <DateInput id="endDatePicker" name={SpotConstants.END_DATE} value={endDate} />
+ <div className="input-group-btn">
+ <button className="btn btn-default" type="button" title="Reload" onClick={InSumActions.reloadSummary}>
+ <span className="glyphicon glyphicon-repeat" aria-hidden="true"></span>
+ </button>
+ </div>
+ </div>
+ </div>
+ </form>
+ ),
+ document.getElementById('nav_form')
+);
+
+// Build and Render Edge Investigation's panels
+const PanelRow = require('./components/PanelRow.react');
+const Panel = require('./components/Panel.react');
+//
+const IngestSummaryPanel = require('./components/IngestSummaryPanel.react');
+
+ReactDOM.render(
+ <div id="spot-content">
+ <PanelRow maximized>
+ <Panel title="Ingest Summary" container header={false} className="col-md-12">
+ <IngestSummaryPanel id="spot-is" />
+ </Panel>
+ </PanelRow>
+ </div>,
+ document.getElementById('spot-content-wrapper')
+);
+
+// Set period
+SpotActions.setDate(startDate, SpotConstants.START_DATE);
+SpotActions.setDate(endDate, SpotConstants.END_DATE);
+
+// Load data
+InSumActions.reloadSummary();
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/js/stores/IngestSummaryStore.js
----------------------------------------------------------------------
diff --git a/spot-oa/ui/js/stores/IngestSummaryStore.js b/spot-oa/ui/js/stores/IngestSummaryStore.js
new file mode 100755
index 0000000..9e4ccb5
--- /dev/null
+++ b/spot-oa/ui/js/stores/IngestSummaryStore.js
@@ -0,0 +1,161 @@
+var assign = require('object-assign');
+var d3 = require('d3');
+
+var SpotDispatcher = require('../../../js/dispatchers/SpotDispatcher');
+var SpotConstants = require('../../../js/constants/SpotConstants');
+var NetflowConstants = require('../constants/NetflowConstants');
+var DateUtils = require('../../../js/utils/DateUtils');
+var RestStore = require('../../../js/stores/RestStore');
+
+var START_DATE_FILTER = NetflowConstants.START_DATE;
+var END_DATE_FILTER = NetflowConstants.END_DATE;
+var CURRENT_DATE_FILTER = 'current_date';
+
+var requestQueue = [];
+var requestErrors = [];
+
+var IngestSummaryStore = assign(new RestStore(NetflowConstants.API_INGEST_SUMMARY), {
+ errorMessages: {
+ 404: 'No details available'
+ },
+ setStartDate: function (date) {
+ this.setRestFilter(START_DATE_FILTER, date);
+ },
+ getStartDate: function () {
+ return this.getRestFilter(START_DATE_FILTER);
+ },
+ setEndDate: function (date) {
+ this.setRestFilter(END_DATE_FILTER, date);
+ },
+ getEndDate: function () {
+ return this.getRestFilter(END_DATE_FILTER);
+ },
+ /**
+ * Start asking the server for CSV data to create the chart
+ **/
+ requestSummary: function () {
+ var startDate, endDate, date, delta, startRequests, i, month;
+
+ startDate = DateUtils.parseDate(this.getRestFilter(START_DATE_FILTER));
+ endDate = DateUtils.parseDate(this.getRestFilter(END_DATE_FILTER));
+
+ // Find out how many request need to be made
+ delta = (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
+
+ startRequests = requestQueue.length == 0;
+
+ // Go to first day in month
+ date = new Date(startDate);
+ date.setDate(1);
+
+ // Queue date requests
+ requestQueue.push(date);
+ for (i = 1; i <= delta; i++) {
+ requestQueue.push(DateUtils.calcDate(date, i, 'month'));
+ }
+
+ // dequeue is no request is running
+ startRequests && this.dequeue();
+ },
+ dequeue: function () {
+ var date, year, month;
+
+ if (requestQueue.length == 0) return;
+
+ date = requestQueue.shift();
+ this.setRestFilter(CURRENT_DATE_FILTER, date);
+ year = date.getFullYear();
+ month = date.getMonth() + 1 + "";
+ month = month.length == 1 ? "0" + month : month;
+
+ this.setEndpoint(NetflowConstants.API_INGEST_SUMMARY.replace('${year}', year).replace('${month}', month));
+
+ this.reload();
+ },
+ setData: function (data) {
+ var startDate, endDate, date, dayFilter, parse;
+
+ // Does the loading indicator needs to be displayed?
+ if (data.loading) {
+ if (!this._data.loading) {
+ this._data = data;
+ this.emitChangeData();
+ }
+
+ // Do nothing when loading is in progress
+ return;
+ }
+
+ // Store errors for later usage
+ if (data.error) {
+ requestErrors.push(data);
+ }
+ else if (data.data) {
+ parse = d3.time.format("%Y-%m-%d %H:%M").parse; // Date formatting parser
+ startDate = DateUtils.parseDate(this.getRestFilter(START_DATE_FILTER));
+ endDate = DateUtils.parseDate(this.getRestFilter(END_DATE_FILTER));
+ date = DateUtils.parseDate(this.getRestFilter(CURRENT_DATE_FILTER));
+
+ if (date.getFullYear() == startDate.getFullYear() && date.getMonth() == startDate.getMonth()) {
+ dayFilter = startDate.getDate();
+ data.data = data.data.filter(function (row) {
+ return DateUtils.parseDate(row.date, true).getDate() >= dayFilter
+ });
+ }
+
+ if (date.getFullYear() == endDate.getFullYear() && date.getMonth() == endDate.getMonth()) {
+ dayFilter = endDate.getDate();
+ data.data = data.data.filter(function (row) {
+ return DateUtils.parseDate(row.date, true).getDate() <= dayFilter
+ });
+ }
+
+ // Parse dates and numbers.
+ data.data.forEach(function (d) {
+ d.date = parse(d.date);
+ d.flows = +d.flows;
+ });
+
+ // Sort the data by date ASC
+ data.data.sort(function (a, b) {
+ return a.date - b.date;
+ });
+
+ if (!this._data.data) this._data.data = [];
+ this._data.data.push(data.data);
+ }
+
+ this._data.loading = requestQueue.length > 0;
+
+ if (!this._data.loading) {
+ if (this._data.data.length==0) {
+ // Broadcast first found error
+ this._data = requestErrors[0];
+ }
+ this.emitChangeData();
+ }
+ else {
+ setTimeout(this.dequeue.bind(this), 1);
+ }
+ }
+});
+
+SpotDispatcher.register(function (action) {
+ switch (action.actionType) {
+ case SpotConstants.UPDATE_DATE:
+ switch (action.name) {
+ case NetflowConstants.START_DATE:
+ IngestSummaryStore.setStartDate(action.date);
+ break;
+ case NetflowConstants.END_DATE:
+ IngestSummaryStore.setEndDate(action.date);
+ break;
+ }
+ break;
+ case NetflowConstants.RELOAD_INGEST_SUMMARY:
+ IngestSummaryStore.requestSummary();
+ break;
+ }
+});
+
+module.exports = IngestSummaryStore;
http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/8a695097/spot-oa/ui/package.json
----------------------------------------------------------------------
diff --git a/spot-oa/ui/package.json b/spot-oa/ui/package.json
index 2f40acb..724544d 100644
--- a/spot-oa/ui/package.json
+++ b/spot-oa/ui/package.json
@@ -36,10 +36,12 @@
"scripts": {
"test": "jest",
"postinstall": "npm run build-all",
- "build-all": "npm run build-flow && npm run build-dns && npm run build-proxy",
+ "watch-ingest-summary": "watchify js/ingest-summary.js -o js/ingest-summary.bundle.min.js -v -d",
+ "build-all": "npm run build-flow && npm run build-dns && npm run build-proxy && npm run build-ingest-summary",
"build-flow": "cd flow/ && npm run build-all && cd ../",
"build-dns": "cd dns/ && npm run build-all && cd ../",
- "build-proxy": "cd proxy/ && npm run build-all && cd ../"
+ "build-proxy": "cd proxy/ && npm run build-all && cd ../",
+ "build-ingest-summary": "browserify js/ingest-summary.js | uglifyjs -cm > js/ingest-summary.bundle.min.js"
},
"browserify": {
"transform": [