Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions regression-tests/daaltkregtests/lib/daaltk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ def get_context():
'spark.eventLog.enabled': 'false',
'spark.sql.shuffle.partitions': '6'}
if config.run_mode:
print "initializing context"
print ""
print ""
print ""
global_tc = stk.TkContext(master='yarn-client', other_libs=[daaltk])

else:
Expand Down
84 changes: 84 additions & 0 deletions regression-tests/daaltkregtests/lib/score_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# vim: set encoding=utf-8

# Copyright (c) 2016 Intel Corporation 
#
# 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.
#


""" Library to support scoring in TAP for the ATK service """
import subprocess as sp
import requests
import time
import signal
import os
import config
from ConfigParser import SafeConfigParser

class scorer(object):

def __init__(self, model_path, port_id, host=config.scoring_engine_host):
"""Set up the server location, port and model file"""
self.hdfs_path = model_path
self.name = host.split('.')[0]
self.host = host
#set port
config = SafeConfigParser()
filepath = os.path.abspath(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"port.ini"))
config.read(filepath)
self.port = config.get('port', port_id)
self.scoring_process = None

def __enter__(self):
"""Activate the Server"""
#change current working directory to point at scoring_engine dir
run_path = os.path.abspath(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"..", "..", "..", "scoring", "scoring_engine"))

#keep track of cwd for future
test_dir = os.getcwd()
os.chdir(run_path)
# make a new process group
self.scoring_process = sp.Popen(
["./bin/model-scoring.sh", "-Dtrustedanalytics.scoring-engine.archive-mar=%s" % self.hdfs_path,
"-Dtrustedanalytics.scoring.port=%s" % self.port],
preexec_fn=os.setsid)

#restore cwd
os.chdir(test_dir)

# wait for server to start
time.sleep(20)
return self

def __exit__(self, *args):
"""Teardown the server"""
# Get the process group to kill all of the suprocesses
pgrp = os.getpgid(self.scoring_process.pid)
os.killpg(pgrp, signal.SIGKILL)

def score(self, data_val):
"""score the json set data_val"""

# Magic headers to make the server respond appropriately
# Ask the head of scoring why these
headers = {'Content-type': 'application/json',
'Accept': 'application/json,text/plain'}

scoring_host = self.host + ":" + self.port
submit_string = 'http://'+scoring_host+'/v2/score'
response = requests.post(submit_string, json={"records":data_val}, headers=headers)
return response

This file was deleted.

Loading