-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" | ||
The sensors module contains the base definition for a generic | ||
sensor call and the implementation of all the specific sensors | ||
""" | ||
|
||
from __future__ import print_function | ||
from qds_sdk.qubole import Qubole | ||
from qds_sdk.resource import Resource | ||
from argparse import ArgumentParser | ||
|
||
import logging | ||
import json | ||
|
||
log = logging.getLogger("qds_sensors") | ||
|
||
|
||
class SensorCmdLine: | ||
|
||
@staticmethod | ||
def check(sensor_class, args): | ||
""" | ||
Method to call Sensor.check after parsing args from cmdline | ||
:param sensor_class: sensor class | ||
:param args: inline arguments | ||
:return: True or False | ||
""" | ||
parser = SensorCmdLine.parsers(sensor_class) | ||
parsed = parser.parse_args(args) | ||
return sensor_class.check(json.loads(parsed.data)) | ||
|
||
@staticmethod | ||
def parsers(sensor_class): | ||
argparser = ArgumentParser(prog=sensor_class.usage, description=sensor_class.description) | ||
subparsers = argparser.add_subparsers() | ||
|
||
#Check | ||
check = subparsers.add_parser("check", help="Check a Sensor") | ||
check.add_argument("-d", "--data", dest="data", required=True, | ||
help="String containing a valid json object") | ||
check.set_defaults(func=Sensor.check) | ||
return argparser | ||
|
||
|
||
class Sensor(Resource): | ||
""" | ||
qds_sdk.Sensor is the base Qubole sensor class. Different types of Qubole | ||
sensors can subclass this. | ||
""" | ||
|
||
@classmethod | ||
def check(cls, data): | ||
""" | ||
Method to call the sensors api with json payload | ||
:param data: valid json object | ||
:return: True or False | ||
""" | ||
conn = Qubole.agent() | ||
return conn.post(cls.rest_entity_path, data=data)['status'] | ||
|
||
|
||
class FileSensor(Sensor): | ||
rest_entity_path = "sensors/file_sensor" | ||
|
||
usage = ("qds.py filesensor check -d 'json string'") | ||
description = "File Sensor client for Qubole Data Services" | ||
|
||
|
||
class PartitionSensor(Sensor): | ||
rest_entity_path = "sensors/partition_sensor" | ||
|
||
usage = ("qds.py partitionsensor check -d 'json string'") | ||
description = "Hive Partition Sensor client for Qubole Data Services" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ def read(fname): | |
|
||
setup( | ||
name="qds_sdk", | ||
version="1.9.5", | ||
version="1.9.6", | ||
author="Qubole", | ||
author_email="[email protected]", | ||
description=("Python SDK for coding to the Qubole Data Service API"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
import os | ||
|
||
if sys.version_info > (2, 7, 0): | ||
import unittest | ||
else: | ||
import unittest2 as unittest | ||
from mock import * | ||
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), '../bin')) | ||
import qds | ||
from qds_sdk.connection import Connection | ||
from test_base import print_command | ||
from test_base import QdsCliTestCase | ||
|
||
|
||
class TestSensorCheck(QdsCliTestCase): | ||
def test_file_sensor(self): | ||
sys.argv = ['qds.py', 'filesensor', 'check', '-d', '{"files":["s3://dev.canopydata.com/airflow"]}'] | ||
print_command() | ||
Connection._api_call = Mock(return_value={'status': True}) | ||
qds.main() | ||
Connection._api_call.assert_called_with( | ||
"POST", "sensors/file_sensor", {'files':['s3://dev.canopydata.com/airflow']}) | ||
|
||
|
||
def test_partition_sensor(self): | ||
sys.argv = ['qds.py', 'partitionsensor', 'check', '-d', '{"schema" : "default", "table" : "nation_s3_rcfile_p", "columns" : [{"column" : "p", "values" : [1, 2]}]}'] | ||
print_command() | ||
Connection._api_call = Mock(return_value={'status': True}) | ||
qds.main() | ||
Connection._api_call.assert_called_with( | ||
"POST", "sensors/partition_sensor", {"schema" : "default", "table" : "nation_s3_rcfile_p", "columns" : [{"column" : "p", "values" : [1, 2]}]}) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |