Add the test back and include BytecodeAssembler in tree.
Change-Id: I5ef7469cb98d05cb78b27c5a6455d366885c1143
This commit is contained in:
parent
fc12dd7ffd
commit
b93b416fb4
2
Makefile
2
Makefile
@ -24,7 +24,7 @@ style:
|
||||
|
||||
start:
|
||||
bash -c "sleep 7; curl -H \"Content-Type: application/json\" -d '{\"action\": \"start_streaming\"}' http://localhost:3000/" &
|
||||
$(PYTHON) run.py -p ~/spark -c ./config/metric_experiments.json -l ./config/logging.json
|
||||
$(PYTHON) run.py -p ~/spark/spark-1.6.1 -c ./config/metric_experiments.json -l ./config/logging.json
|
||||
|
||||
|
||||
.PHONY: all test clean style testspec
|
||||
|
@ -46,13 +46,13 @@ if [ "$VAGRANT_ENV" ]; then
|
||||
echo "-------------------------"
|
||||
echo "unzip spark to ~/spark"
|
||||
tar -xzf spark.tgz
|
||||
mv spark-1.6.1/ ~/spark
|
||||
cd ~/spark
|
||||
mv spark-1.6.1/ ~/spark/spark-1.6.1
|
||||
cd ~/spark/spark-1.6.1
|
||||
mvn -DskipTests clean package
|
||||
cd ~/tmp
|
||||
# config for logging in spark
|
||||
cp ~/spark/conf/log4j.properties.template ~/spark/conf/log4j.properties
|
||||
sed -i 's/log4j.rootCategory=INFO/log4j.rootCategory=ERROR/g' ~/spark/conf/log4j.properties
|
||||
cp ~/spark/spark-1.6.1/conf/log4j.properties.template ~/spark/spark-1.6.1/conf/log4j.properties
|
||||
sed -i 's/log4j.rootCategory=INFO/log4j.rootCategory=ERROR/g' ~/spark/spark-1.6.1/conf/log4j.properties
|
||||
|
||||
# Kafka
|
||||
mkdir ~/kafka
|
||||
@ -81,7 +81,7 @@ if [ "$VAGRANT_ENV" ]; then
|
||||
|
||||
# Environment setup
|
||||
set -v
|
||||
echo 'export SPARK_HOME=~/spark' >> $HOME/.profile
|
||||
echo 'export SPARK_HOME=~/spark/spark-1.6.1' >> $HOME/.profile
|
||||
echo 'export PYTHONPATH=$SPARK_HOME/python:$SPARK_HOME/python/lib/py4j-0.9-src.zip:$PYTHONPATH' >> $HOME/.profile
|
||||
set +v
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (c) 2016 Hewlett Packard Enterprise Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from expression import create_fn_with_config
|
||||
from expression import validate_environment
|
||||
from expression import validate_expression
|
||||
from expression import validate_name_binding
|
||||
|
||||
create_fn_with_config = create_fn_with_config
|
||||
validate_expression = validate_expression
|
||||
validate_environment = validate_environment
|
||||
validate_name_binding = validate_name_binding
|
25
monasca_analytics/banana/api.py
Normal file
25
monasca_analytics/banana/api.py
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (c) 2016 Hewlett Packard Enterprise Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from expression import create_fn_with_config
|
||||
from expression import validate_environment
|
||||
from expression import validate_expression
|
||||
from expression import validate_name_binding
|
||||
|
||||
create_fn_with_config = create_fn_with_config
|
||||
validate_expression = validate_expression
|
||||
validate_environment = validate_environment
|
||||
validate_name_binding = validate_name_binding
|
0
monasca_analytics/banana/bytecode/__init__.py
Normal file
0
monasca_analytics/banana/bytecode/__init__.py
Normal file
1004
monasca_analytics/banana/bytecode/assembler.py
Normal file
1004
monasca_analytics/banana/bytecode/assembler.py
Normal file
File diff suppressed because it is too large
Load Diff
104
monasca_analytics/banana/bytecode/decorators.py
Normal file
104
monasca_analytics/banana/bytecode/decorators.py
Normal file
@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (c) 2016 Hewlett Packard Enterprise Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
# This file is an adaptation of BytecodeAssembler:
|
||||
#
|
||||
# http://peak.telecommunity.com/DevCenter/BytecodeAssembler#toc
|
||||
#
|
||||
# It has been adapted to match the requirements of monasca_analytics
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def enclosing_frame(frame=None, level=3):
|
||||
"""Get an enclosing frame that skips DecoratorTools callback code"""
|
||||
frame = frame or sys._getframe(level)
|
||||
while frame.f_globals.get('__name__') == __name__:
|
||||
frame = frame.f_back
|
||||
return frame
|
||||
|
||||
|
||||
def decorate_assignment(callback, depth=2, frame=None):
|
||||
"""Invoke 'callback(frame,name,value,old_locals)' on next assign in 'frame'
|
||||
|
||||
The frame monitored is determined by the 'depth' argument, which gets
|
||||
passed to 'sys._getframe()'. When 'callback' is invoked, 'old_locals'
|
||||
contains a copy of the frame's local variables as they were before the
|
||||
assignment took place, allowing the callback to access the previous value
|
||||
of the assigned variable, if any. The callback's return value will become
|
||||
the new value of the variable. 'name' is the name of the variable being
|
||||
created or modified, and 'value' is its value (the same as
|
||||
'frame.f_locals[name]').
|
||||
|
||||
This function also returns a decorator function for forward-compatibility
|
||||
with Python 2.4 '@' syntax. Note, however, that if the returned decorator
|
||||
is used with Python 2.4 '@' syntax, the callback 'name' argument may be
|
||||
'None' or incorrect, if the 'value' is not the original function (e.g.
|
||||
when multiple decorators are used).
|
||||
"""
|
||||
frame = enclosing_frame(frame, depth + 1)
|
||||
oldtrace = [frame.f_trace]
|
||||
old_locals = frame.f_locals.copy()
|
||||
|
||||
def tracer(frm, event, arg):
|
||||
if event == 'call':
|
||||
# We don't want to trace into any calls
|
||||
if oldtrace[0]:
|
||||
# ...but give the previous tracer a chance to, if it wants
|
||||
return oldtrace[0](frm, event, arg)
|
||||
else:
|
||||
return None
|
||||
|
||||
try:
|
||||
if frm is frame and event != 'exception':
|
||||
# Aha, time to check for an assignment...
|
||||
for k, v in frm.f_locals.items():
|
||||
if k not in old_locals or old_locals[k] is not v:
|
||||
break
|
||||
else:
|
||||
# No luck, keep tracing
|
||||
return tracer
|
||||
|
||||
# Got it, fire the callback, then get the heck outta here...
|
||||
frm.f_locals[k] = callback(frm, k, v, old_locals)
|
||||
|
||||
finally:
|
||||
# Give the previous tracer a chance to run before we return
|
||||
if oldtrace[0]:
|
||||
# And allow it to replace our idea of the "previous" tracer
|
||||
oldtrace[0] = oldtrace[0](frm, event, arg)
|
||||
|
||||
uninstall()
|
||||
return oldtrace[0]
|
||||
|
||||
def uninstall():
|
||||
# Unlink ourselves from the trace chain.
|
||||
frame.f_trace = oldtrace[0]
|
||||
sys.settrace(oldtrace[0])
|
||||
|
||||
# Install the trace function
|
||||
frame.f_trace = tracer
|
||||
sys.settrace(tracer)
|
||||
|
||||
def do_decorate(f):
|
||||
# Python 2.4 '@' compatibility; call the callback
|
||||
uninstall()
|
||||
frame = sys._getframe(1)
|
||||
return callback(
|
||||
frame, getattr(f, '__name__', None), f, frame.f_locals
|
||||
)
|
||||
|
||||
return do_decorate
|
51
monasca_analytics/banana/bytecode/symbols.py
Normal file
51
monasca_analytics/banana/bytecode/symbols.py
Normal file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (c) 2016 Hewlett Packard Enterprise Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
# This file is an adaptation of BytecodeAssembler:
|
||||
#
|
||||
# http://peak.telecommunity.com/DevCenter/BytecodeAssembler#toc
|
||||
#
|
||||
# It has been adapted to match the requirements of monasca_analytics
|
||||
|
||||
"""Symbolic global constants, like 'None', 'NOT_FOUND', etc."""
|
||||
|
||||
|
||||
class Symbol(object):
|
||||
|
||||
"""Symbolic global constant"""
|
||||
|
||||
__slots__ = ['_name', '_module']
|
||||
__name__ = property(lambda self: self._name)
|
||||
__module__ = property(lambda self: self._module)
|
||||
|
||||
def __init__(self, symbol, module_name):
|
||||
self.__class__._name.__set__(self, symbol)
|
||||
self.__class__._module.__set__(self, module_name)
|
||||
|
||||
def __reduce__(self):
|
||||
return self._name
|
||||
|
||||
def __setattr__(self, attr, val):
|
||||
raise TypeError("Symbols are immutable")
|
||||
|
||||
def __repr__(self):
|
||||
return self.__name__
|
||||
|
||||
__str__ = __repr__
|
||||
|
||||
|
||||
NOT_GIVEN = Symbol("NOT_GIVEN", __name__)
|
||||
NOT_FOUND = Symbol("NOT_FOUND", __name__)
|
@ -17,9 +17,9 @@
|
||||
import logging
|
||||
import types
|
||||
|
||||
import monasca_analytics.banana.bytecode.assembler as asbl
|
||||
import monasca_analytics.banana.private as priv
|
||||
import monasca_analytics.exception.banana as exception
|
||||
import peak.util.assembler as ass
|
||||
import private as priv
|
||||
import pyparsing as p
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ class ExpressionParser(object):
|
||||
(p.oneOf('+ -'), 2, p.opAssoc.LEFT)
|
||||
])
|
||||
|
||||
def parse(self, string, code=ass.Code()):
|
||||
def parse(self, string, code=asbl.Code()):
|
||||
"""
|
||||
Parse a given string and construct an Evaluator
|
||||
:type string: basestring
|
||||
@ -78,7 +78,7 @@ class ExpressionParser(object):
|
||||
pushed_one_stack_value = False
|
||||
for child in filter(priv.is_not_op, subtree):
|
||||
if isinstance(child, basestring):
|
||||
code(ass.Local(child))
|
||||
code(asbl.Local(child))
|
||||
if not pushed_one_stack_value:
|
||||
pushed_one_stack_value = True
|
||||
else:
|
||||
@ -114,17 +114,17 @@ def create_fn_with_config(env, expr_string):
|
||||
:returns: Returns a function that accept one argument
|
||||
expected to be the environment.
|
||||
"""
|
||||
code = ass.Code()
|
||||
code = asbl.Code()
|
||||
# Argument
|
||||
code(ass.Local('__monanas__env'))
|
||||
code(asbl.Local('__monanas__env'))
|
||||
code.co_argcount = 1
|
||||
# Create local variables
|
||||
for key, value in env.iteritems():
|
||||
code(ass.Call(
|
||||
ass.Getattr(
|
||||
ass.Local('__monanas__env'), 'get'),
|
||||
[ass.Const(value)]),
|
||||
ass.LocalAssign(str(key)))
|
||||
code(asbl.Call(
|
||||
asbl.Getattr(
|
||||
asbl.Local('__monanas__env'), 'get'),
|
||||
[asbl.Const(value)]),
|
||||
asbl.LocalAssign(str(key)))
|
||||
parser = ExpressionParser()
|
||||
try:
|
||||
parser.parse(expr_string, code)
|
||||
|
@ -17,7 +17,7 @@
|
||||
import logging
|
||||
import voluptuous
|
||||
|
||||
import monasca_analytics.banana as banana
|
||||
import monasca_analytics.banana.api as banana
|
||||
import monasca_analytics.ldp.base as bt
|
||||
import monasca_analytics.ldp.monasca.helpers as helpers
|
||||
import monasca_analytics.util.spark_func as fn
|
||||
|
@ -45,8 +45,8 @@ class MonanasHandler(web.RequestHandler):
|
||||
|
||||
try:
|
||||
body = json.loads(self.request.body)
|
||||
validated_body = getattr(web_service_model, "action_model")(body)
|
||||
getattr(self._monanas, validated_body["action"])()
|
||||
getattr(web_service_model, "action_model")(body)
|
||||
getattr(self._monanas, body["action"])()
|
||||
except (AttributeError, voluptuous.Invalid, ValueError):
|
||||
self.set_status(400, "The request body was malformed.")
|
||||
except (err.MonanasBindSourcesError,
|
||||
|
@ -122,7 +122,6 @@ class CommonUtilTest(unittest.TestCase):
|
||||
self.assertItemsEqual(["PickIndexVoter"], names)
|
||||
|
||||
def test_get_available_ldp_class_names(self):
|
||||
return
|
||||
names = common_util.get_available_ldp_class_names()
|
||||
self.assertItemsEqual([
|
||||
"CloudCausalityLDP", "IptablesLDP",
|
||||
|
Loading…
Reference in New Issue
Block a user