Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from MauriceManning/develop
Add service skeleton for DataProductManagement service and unit test
- Loading branch information
Showing
4 changed files
with
176 additions
and
0 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
__author__ = 'mauricemanning' | |||
|
105 changes: 105 additions & 0 deletions
105
ion/services/sa/data_product_management/data_product_management.py
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,105 @@ | |||
#!/usr/bin/env python | |||
|
|||
""" | |||
@file ion/services/sa/data_product_management.py | |||
@author | |||
@brief Services related to the activation and registry of data products | |||
""" | |||
|
|||
import ion.util.ionlog | |||
log = ion.util.ionlog.getLogger(__name__) | |||
from twisted.internet import defer | |||
from twisted.python import reflect | |||
|
|||
from ion.core.messaging import message_client | |||
from ion.core.exception import ReceivedError, ApplicationError | |||
|
|||
from ion.core.process.process import ProcessFactory | |||
from ion.core.process.service_process import ServiceProcess, ServiceClient | |||
from ion.services.coi.resource_registry.resource_client import ResourceClient | |||
from ion.core.messaging.message_client import MessageClient | |||
from ion.services.dm.inventory.association_service import AssociationServiceClient | |||
|
|||
class DataProductManagementService(ServiceProcess): | |||
|
|||
# Declaration of service | |||
declare = ServiceProcess.service_declare(name='data_product_mgmt', | |||
version='0.1.0', | |||
dependencies=[]) | |||
|
|||
|
|||
def __init__(self, *args, **kwargs): | |||
|
|||
ServiceProcess.__init__(self, *args, **kwargs) | |||
|
|||
log.debug('DataProductManagementService.__init__()') | |||
|
|||
|
|||
@defer.inlineCallbacks | |||
def op_define_data_product(self, request, headers, msg): | |||
|
|||
assert(isinstance(request, dict)) | |||
response = self.define_data_product(**request) # Unpack dict to kwargs | |||
yield self.reply_ok(msg, response) | |||
|
|||
@defer.inlineCallbacks | |||
def op_find_data_product(self, request, headers, msg): | |||
response = self.find_data_product(**request) # Unpack dict to kwargs | |||
yield self.reply_ok(msg, response) | |||
|
|||
|
|||
def define_data_product(self, owner='default', source='default', description='default desc'): | |||
|
|||
# DefineDataProduct will validate and register a new data product within the system | |||
|
|||
# Validate - TBD by the work that Karen Stocks is driving with John Graybeal | |||
|
|||
# Register - create and store a new DataProduct resource using provided metadata | |||
|
|||
# Create necessary associations to owner, instrument, etc | |||
|
|||
# Call Data Aquisition Mgmt Svc:define_data_producer to coordinate creation of topic and connection to source | |||
|
|||
# Return a resource ref | |||
|
|||
return | |||
|
|||
def find_data_product(self, filter='default'): | |||
|
|||
# Validate the input filter and augment context as required | |||
|
|||
# Call DM DiscoveryService to query the catalog for matches | |||
|
|||
# Organize and return the list of matches | |||
|
|||
|
|||
return | |||
|
|||
|
|||
|
|||
|
|||
class DataProductManagementServiceClient(ServiceClient): | |||
|
|||
""" | |||
This is a service client for DataProductManagementServices. | |||
""" | |||
|
|||
def __init__(self, proc=None, **kwargs): | |||
if not 'targetname' in kwargs: | |||
kwargs['targetname'] = "data_product_mgmt" | |||
ServiceClient.__init__(self, proc, **kwargs) | |||
|
|||
@defer.inlineCallbacks | |||
def define_data_product(self, owner='owner', source='source', description='description'): | |||
(content, headers, msg) = yield self.rpc_send('define_data_product', {'owner':owner, 'source':source, 'description':description}) | |||
defer.returnValue(content) | |||
|
|||
@defer.inlineCallbacks | |||
def find_data_product(self, filter='default'): | |||
(content, headers, msg) = yield self.rpc_send('find_data_product', {'filter':filter}) | |||
defer.returnValue(content) | |||
|
|||
|
|||
# Spawn of the process using the module name | |||
factory = ProcessFactory(DataProductManagementService) | |||
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
__author__ = 'mauricemanning' | |||
|
67 changes: 67 additions & 0 deletions
67
ion/services/sa/data_product_management/test/test_data_product_management.py
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,67 @@ | |||
#!/usr/bin/env python | |||
|
|||
""" | |||
@file ion/services/sa/test/test_data_product_management.py | |||
@test ion.services.sa.data_product_management | |||
@author | |||
""" | |||
|
|||
import ion.util.ionlog | |||
log = ion.util.ionlog.getLogger(__name__) | |||
from twisted.internet import defer | |||
|
|||
from ion.core.process.process import Process | |||
from ion.services.sa.data_product_management.data_product_management import DataProductManagementServiceClient | |||
from ion.test.iontest import IonTestCase | |||
|
|||
|
|||
class DataProductManagementTest(IonTestCase): | |||
""" | |||
Testing data product management service | |||
""" | |||
|
|||
@defer.inlineCallbacks | |||
def setUp(self): | |||
yield self._start_container() | |||
|
|||
services = [ | |||
{ | |||
'name':'dataprodmgmt', | |||
'module':'ion.services.sa.data_product_management.data_product_management', | |||
'class':'DataProductManagementServiceClient' | |||
} | |||
] | |||
|
|||
log.debug('AppIntegrationTest.setUp(): spawning processes') | |||
sup = yield self._spawn_processes(services) | |||
log.debug('AppIntegrationTest.setUp(): spawned processes') | |||
self.sup = sup | |||
|
|||
self.dpmc = DataProductManagementServiceClient(proc=sup) | |||
self._proc = Process() | |||
|
|||
|
|||
@defer.inlineCallbacks | |||
def tearDown(self): | |||
yield self._shutdown_processes() | |||
yield self._stop_container() | |||
|
|||
|
|||
@defer.inlineCallbacks | |||
def test_define_data_product(self): | |||
""" | |||
Accepts a dictionary containing metadata about a data product. | |||
Updates are made to the registries. | |||
""" | |||
|
|||
log.info("test_define_data_product Now testing: Create sample data product") | |||
|
|||
result = yield self.dpmc.define_data_product(owner='Instrument1Owner', source='Instrument1', description='SeaBird') | |||
|
|||
log.info("define_data_product Finished testing: Create sample data product") | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|