You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spot.apache.org by le...@apache.org on 2017/04/17 16:37:34 UTC

[05/16] incubator-spot git commit: Added graphql mutations to reset scored connections, as well as the commented function in the notebooks for all three pipelines

Added graphql mutations to reset scored connections, as well as the commented function in the notebooks for all three pipelines


Project: http://git-wip-us.apache.org/repos/asf/incubator-spot/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-spot/commit/864a452b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-spot/tree/864a452b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-spot/diff/864a452b

Branch: refs/heads/SPOT-35_graphql_api
Commit: 864a452bd8cb254c16dc73f57bb22d5fc4472c0d
Parents: b41e904
Author: LedaLima <le...@apache.org>
Authored: Fri Apr 7 18:06:03 2017 -0500
Committer: LedaLima <le...@apache.org>
Committed: Fri Apr 7 18:06:03 2017 -0500

----------------------------------------------------------------------
 spot-oa/api/graphql/dns/mutation.py             | 20 +++++++++
 spot-oa/api/graphql/flow/mutation.py            | 20 +++++++++
 spot-oa/api/graphql/proxy/mutation.py           | 21 ++++++++++
 .../Edge_Investigation_master.ipynb             | 40 +++++++++++++++++-
 .../Edge_Investigation_master.ipynb             | 44 +++++++++++++++++---
 .../Edge_Investigation_master.ipynb             | 42 ++++++++++++++++++-
 6 files changed, 178 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/864a452b/spot-oa/api/graphql/dns/mutation.py
----------------------------------------------------------------------
diff --git a/spot-oa/api/graphql/dns/mutation.py b/spot-oa/api/graphql/dns/mutation.py
index da93ba6..404896f 100644
--- a/spot-oa/api/graphql/dns/mutation.py
+++ b/spot-oa/api/graphql/dns/mutation.py
@@ -117,6 +117,15 @@ def _create_storyboard(args):
 
     return {'success': result}
 
+
+def _reset_scored_connections(args):
+    _input = args.get('date', date.today()) 
+
+    result = Dns.reset_scored_connections(date=_date)
+
+    return {'success': result}
+
+
 MutationType = GraphQLObjectType(
     name='DnsMutationType',
     fields={
@@ -141,6 +150,17 @@ MutationType = GraphQLObjectType(
                 )
             },
             resolver=lambda root, args, *_: _create_storyboard(args)
+        ),
+        'resetScoredConnections': GraphQLField(
+            type=SpotOperationOutputType,
+            description='Resets all scored connections for a certain day',
+            args={
+                'date': GraphQLArgument(
+                    type=GraphQLNonNull(SpotDateType),
+                    description='Date to clean'
+                )
+            },
+            resolver=lambda root, args, *_: _reset_scored_connections(args)
         )
     }
 )

http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/864a452b/spot-oa/api/graphql/flow/mutation.py
----------------------------------------------------------------------
diff --git a/spot-oa/api/graphql/flow/mutation.py b/spot-oa/api/graphql/flow/mutation.py
index 7650f7e..05e1277 100644
--- a/spot-oa/api/graphql/flow/mutation.py
+++ b/spot-oa/api/graphql/flow/mutation.py
@@ -153,6 +153,15 @@ def _create_storyboard(args):
 
     return {'success': result}
 
+
+def _reset_scored_connections(args):
+    _input = args.get('date', date.today()) 
+
+    result = Flow.reset_scored_connections(date=_date)
+
+    return {'success': result}
+
+
 MutationType = GraphQLObjectType(
     name='NetflowMutationType',
     fields={
@@ -177,6 +186,17 @@ MutationType = GraphQLObjectType(
                 )
             },
             resolver=lambda root, args, *_: _create_storyboard(args)
+        ),
+        'resetScoredConnections': GraphQLField(
+            type=SpotOperationOutputType,
+            description='Resets all scored connections for a certain day',
+            args={
+                'date': GraphQLArgument(
+                    type=GraphQLNonNull(SpotDateType),
+                    description='Date to clean'
+                )
+            },
+            resolver=lambda root, args, *_: _reset_scored_connections(args)
         )
     }
 )

http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/864a452b/spot-oa/api/graphql/proxy/mutation.py
----------------------------------------------------------------------
diff --git a/spot-oa/api/graphql/proxy/mutation.py b/spot-oa/api/graphql/proxy/mutation.py
index 1d08186..82078a8 100644
--- a/spot-oa/api/graphql/proxy/mutation.py
+++ b/spot-oa/api/graphql/proxy/mutation.py
@@ -142,6 +142,7 @@ def _score_connections(args):
         results.append({'success': result})
 
     return results
+ 
 
 def _create_storyboard(args):
     _input = args.get('input')
@@ -156,6 +157,15 @@ def _create_storyboard(args):
 
     return {'success': result}
 
+
+def _reset_scored_connections(args):
+    _input = args.get('date', date.today()) 
+
+    result = Proxy.reset_scored_connections(date=_date)
+
+    return {'success': result}
+
+
 MutationType = GraphQLObjectType(
     name='ProxyMutationType',
     fields={
@@ -179,6 +189,17 @@ MutationType = GraphQLObjectType(
                 )
             },
             resolver=lambda root, args, *_: _create_storyboard(args)
+        ),
+        'resetScoredConnections': GraphQLField(
+            type=SpotOperationOutputType,
+            description='Resets all scored connections for a certain day',
+            args={
+                'date': GraphQLArgument(
+                    type=GraphQLNonNull(SpotDateType),
+                    description='Date to clean'
+                )
+            },
+            resolver=lambda root, args, *_: _reset_scored_connections(args)
         )
     }
 )

http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/864a452b/spot-oa/oa/dns/ipynb_templates/Edge_Investigation_master.ipynb
----------------------------------------------------------------------
diff --git a/spot-oa/oa/dns/ipynb_templates/Edge_Investigation_master.ipynb b/spot-oa/oa/dns/ipynb_templates/Edge_Investigation_master.ipynb
index 8cca233..0acd9ac 100644
--- a/spot-oa/oa/dns/ipynb_templates/Edge_Investigation_master.ipynb
+++ b/spot-oa/oa/dns/ipynb_templates/Edge_Investigation_master.ipynb
@@ -186,7 +186,32 @@
     "    data_loader() \n",
     "    print \"Click the 'Save' button when you're finished scoring\" \n",
     "\n",
-    "\n",
+    "        \n",
+    "def reset_scoring():\n",
+    "    response = GraphQLClient.request(\n",
+    "        query=\"\"\"mutation($date:SpotDateType!) {\n",
+    "                dns{\n",
+    "                    resetScoredConnections(date:$date){\n",
+    "                   success\n",
+    "                }\n",
+    "            }\n",
+    "        }\"\"\",\n",
+    "        variables={\n",
+    "            'date': datetime.datetime.strptime(date, '%Y%m%d').strftime('%Y-%m-%d')\n",
+    "        }\n",
+    "    ) \n",
+    "     \n",
+    "    if not 'errors' in response:\n",
+    "        clear_output()    \n",
+    "        display(Javascript(\"$('.widget-area > .widget-subarea > *').remove();\"))\n",
+    "        data_loader() \n",
+    "        display(scoring_form)\n",
+    "        display(Javascript('reloadParentData();')) \n",
+    "        print \"Suspicious connects successfully updated\"\n",
+    "    else:\n",
+    "        print \"An error ocurred: \" + response['errors'][0]['message']\n",
+    "                \n",
+    "        \n",
     "def save(b):    \n",
     "    variables=[]\n",
     "    global score_values\n",
@@ -224,6 +249,17 @@
     "assign_btn.on_click(assign_score)\n",
     "save_btn.on_click(save) "
    ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "# reset_scoring()"
+   ]
   }
  ],
  "metadata": {
@@ -242,7 +278,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython2",
-   "version": "2.7.5"
+   "version": "2.7.10"
   }
  },
  "nbformat": 4,

http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/864a452b/spot-oa/oa/flow/ipynb_templates/Edge_Investigation_master.ipynb
----------------------------------------------------------------------
diff --git a/spot-oa/oa/flow/ipynb_templates/Edge_Investigation_master.ipynb b/spot-oa/oa/flow/ipynb_templates/Edge_Investigation_master.ipynb
index 6720de1..ffa6b31 100644
--- a/spot-oa/oa/flow/ipynb_templates/Edge_Investigation_master.ipynb
+++ b/spot-oa/oa/flow/ipynb_templates/Edge_Investigation_master.ipynb
@@ -1,10 +1,8 @@
 {
  "cells": [
   {
-   "cell_type": "code",
-   "execution_count": null,
+   "cell_type": "markdown",
    "metadata": {},
-   "outputs": [],
    "source": [
     "Initialize workflow."
    ]
@@ -244,7 +242,32 @@
     "    \n",
     "    print \"Click the 'Save' button when you're finished scoring\" \n",
     "\n",
-    "\n",
+    "    \n",
+    "def reset_scoring():\n",
+    "    response = GraphQLClient.request(\n",
+    "        query=\"\"\"mutation($date:SpotDateType!) {\n",
+    "                flow{\n",
+    "                    resetScoredConnections(date:$date){\n",
+    "                   success\n",
+    "                }\n",
+    "            }\n",
+    "        }\"\"\",\n",
+    "        variables={\n",
+    "            'date': datetime.datetime.strptime(date, '%Y%m%d').strftime('%Y-%m-%d')\n",
+    "        }\n",
+    "    ) \n",
+    "     \n",
+    "    if not 'errors' in response :\n",
+    "        display(Javascript(\"$('.widget-area > .widget-subarea > *').remove();\"))\n",
+    "        data_loader() \n",
+    "        display(bigBox)\n",
+    "        display(Javascript('reloadParentData();'))         \n",
+    "        print \"Scored connections successfully reset\"        \n",
+    "    else:\n",
+    "        print \"An error ocurred: \" + response['errors'][0]['message']\n",
+    "        \n",
+    "          \n",
+    "    \n",
     "def savesort(b):\n",
     "    global svals\n",
     "    clear_output()    \n",
@@ -284,6 +307,17 @@
     "assignbut.on_click(assign_score)\n",
     "updatebut.on_click(savesort)"
    ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "# reset_scoring()"
+   ]
   }
  ],
  "metadata": {
@@ -302,7 +336,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython2",
-   "version": "2.7.5"
+   "version": "2.7.10"
   }
  },
  "nbformat": 4,

http://git-wip-us.apache.org/repos/asf/incubator-spot/blob/864a452b/spot-oa/oa/proxy/ipynb_templates/Edge_Investigation_master.ipynb
----------------------------------------------------------------------
diff --git a/spot-oa/oa/proxy/ipynb_templates/Edge_Investigation_master.ipynb b/spot-oa/oa/proxy/ipynb_templates/Edge_Investigation_master.ipynb
index b20c65e..209e741 100644
--- a/spot-oa/oa/proxy/ipynb_templates/Edge_Investigation_master.ipynb
+++ b/spot-oa/oa/proxy/ipynb_templates/Edge_Investigation_master.ipynb
@@ -160,6 +160,33 @@
     "    print \"Click the 'Save' button when you're finished scoring\"  \n",
     "\n",
     "\n",
+    "    \n",
+    "def reset_scoring():\n",
+    "    response = GraphQLClient.request(\n",
+    "        query=\"\"\"mutation($date:SpotDateType!) {\n",
+    "                proxy{\n",
+    "                    resetScoredConnections(date:$date){\n",
+    "                   success\n",
+    "                }\n",
+    "            }\n",
+    "        }\"\"\",\n",
+    "        variables={\n",
+    "            'date': datetime.datetime.strptime(date, '%Y%m%d').strftime('%Y-%m-%d')\n",
+    "        }\n",
+    "    ) \n",
+    "     \n",
+    "    if not 'errors' in response:\n",
+    "        clear_output()    \n",
+    "        display(Javascript(\"$('.widget-area > .widget-subarea > *').remove();\"))\n",
+    "        data_loader() \n",
+    "        display(scoring_form)\n",
+    "        display(Javascript('reloadParentData();')) \n",
+    "        print \"Suspicious connects successfully updated\"\n",
+    "    else:\n",
+    "        print \"An error ocurred: \" + response['errors'][0]['message']\n",
+    "             \n",
+    "            \n",
+    "    \n",
     "def save(b):   \n",
     "    variables=[]\n",
     "    global score_values\n",
@@ -196,6 +223,17 @@
     "assign_btn.on_click(assign_score)\n",
     "save_btn.on_click(save)"
    ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "# reset_scoring()"
+   ]
   }
  ],
  "metadata": {
@@ -207,14 +245,14 @@
   "language_info": {
    "codemirror_mode": {
     "name": "ipython",
-    "version": 2.0
+    "version": 2
    },
    "file_extension": ".py",
    "mimetype": "text/x-python",
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython2",
-   "version": "2.7.5"
+   "version": "2.7.10"
   }
  },
  "nbformat": 4,