Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding support for computed and extended attributes

  • Loading branch information...
commit 6ff8fd201fa7fb6e7ee8f65f9de94d3333bd4faa 1 parent 1755542
@shenrie shenrie authored
2  extern/ion-definitions
@@ -1 +1 @@
-Subproject commit 2e5f9298bcadf9ce126ca4c95b73665d939d72d8
+Subproject commit 63df7c35094e3148279206a7051efd9f72aa5963
View
51 ion/services/coi/identity_management_service.py
@@ -3,14 +3,15 @@
__author__ = 'Thomas R. Lennan'
__license__ = 'Apache 2.0'
-from pyon.core.exception import Conflict, Inconsistent, NotFound
+from pyon.core.exception import Conflict, Inconsistent, NotFound,BadRequest
from pyon.core.security.authentication import Authentication
-from pyon.public import PRED, RT, IonObject
+from pyon.ion.resource import ExtendedResourceContainer
+from pyon.public import PRED, RT, IonObject, OT
from pyon.util.log import log
-
import time
from interface.services.coi.iidentity_management_service import BaseIdentityManagementService
+from interface.services.coi.iorg_management_service import OrgManagementServiceProcessClient
class IdentityManagementService(BaseIdentityManagementService):
@@ -20,6 +21,7 @@ class IdentityManagementService(BaseIdentityManagementService):
def on_init(self):
self.authentication = Authentication()
+ self.extended_resource_handler = ExtendedResourceContainer(self)
def create_actor_identity(self, actor_identity=None):
# Persist ActorIdentity object and return object _id as OOI id
@@ -212,3 +214,46 @@ def signon(self, certificate='', ignore_date_range=False):
self.register_user_credentials(user_id, user_credentials)
log.debug("Signon returning user_id, valid_until, registered: %s, %s, False" % (user_id, valid_until))
return user_id, valid_until, False
+
+ def get_actor_identity_extension(self, user_id='', org_id='', ext_associations=None, ext_exclude=None):
+ """Returns an ActorIdentityExtension object containing additional related information
+
+ @param user_id str
+ @param org_id str
+ @param ext_associations dict
+ @param ext_exclude list
+ @retval actor_identity ActorIdentityExtension
+ @throws BadRequest A parameter is missing
+ @throws NotFound An object with the specified user_id does not exist
+ """
+
+ if not user_id:
+ raise BadRequest("The user_id parameter is empty")
+
+ user = self.clients.resource_registry.read(user_id)
+ if not user:
+ raise NotFound("User %s does not exist" % user_id)
+
+ extended_user = self.extended_resource_handler.create_extended_resource_container(OT.ActorIdentityExtension, user)
+
+ #Fill in related data - refactor when object decorators are available
+ self.extended_resource_handler.get_associated_resources(extended_user, 'credentials', PRED.hasCredentials)
+ self.extended_resource_handler.get_associated_resources(extended_user, 'user_info', PRED.hasInfo)
+ self.extended_resource_handler.get_associated_resources(extended_user, 'policies', PRED.hasPolicy)
+ self.extended_resource_handler.get_associated_resources(extended_user, 'owned_resources', PRED.hasOwner)
+ self.extended_resource_handler.get_associated_resources(extended_user, 'user_requests', PRED.hasRequest)
+ self.extended_resource_handler.get_extended_associations(extended_user, ext_associations)
+
+ #If the org_id is not provided then skip looking for Org related roles.
+ if org_id:
+ #Did not setup a dependency to org_management service to avoid a potential circular bootstrap issue
+ # since this method should never be called until the system is fully running
+ try:
+ org_client = OrgManagementServiceProcessClient(process=self)
+ roles = org_client.find_org_roles_by_user(org_id, user_id)
+ extended_user.roles = roles
+ except Exception,e:
+ #If this information is not available yet, them just move on and caller can retry later
+ pass
+
+ return extended_user
View
34 ion/services/coi/test/test_identity_management_service.py
@@ -13,6 +13,7 @@
from pyon.public import PRED, RT, IonObject
from ion.services.coi.identity_management_service import IdentityManagementService
from interface.services.coi.iidentity_management_service import IdentityManagementServiceClient, IdentityManagementServiceProcessClient
+from interface.services.coi.iorg_management_service import OrgManagementServiceClient
from pyon.util.context import LocalContextMixin
@@ -443,6 +444,7 @@ def setUp(self):
self.identity_management_service = IdentityManagementServiceClient(node=self.container.node)
+ @unittest.skip('skip test')
def test_actor_identity(self):
actor_identity_obj = IonObject("ActorIdentity", {"name": self.subject})
user_id = self.identity_management_service.create_actor_identity(actor_identity_obj)
@@ -462,6 +464,7 @@ def test_actor_identity(self):
self.identity_management_service.delete_actor_identity(user_id)
self.assertTrue("does not exist" in cm.exception.message)
+ @unittest.skip('skip test')
def test_user_credentials(self):
actor_identity_obj = IonObject("ActorIdentity", {"name": self.subject})
user_id = self.identity_management_service.create_actor_identity(actor_identity_obj)
@@ -485,6 +488,7 @@ def test_user_credentials(self):
self.identity_management_service.delete_actor_identity(user_id)
+ @unittest.skip('skip test')
def test_user_info(self):
actor_identity_obj = IonObject("ActorIdentity", {"name": self.subject})
user_id = self.identity_management_service.create_actor_identity(actor_identity_obj)
@@ -533,6 +537,7 @@ def test_user_info(self):
self.identity_management_service.delete_actor_identity(user_id)
+ @unittest.skip('skip test')
def test_signon(self):
certificate = """-----BEGIN CERTIFICATE-----
MIIEMzCCAxugAwIBAgICBQAwDQYJKoZIhvcNAQEFBQAwajETMBEGCgmSJomT8ixkARkWA29yZzEX
@@ -573,3 +578,32 @@ def test_signon(self):
self.assertTrue(registered3)
self.assertTrue(id == id3)
self.assertTrue(valid_until == valid_until3)
+
+
+ def test_get_extended_user_identity(self):
+
+ actor_identity_obj = IonObject("ActorIdentity", {"name": self.subject})
+ user_id = self.identity_management_service.create_actor_identity(actor_identity_obj)
+
+ user_credentials_obj = IonObject("UserCredentials", {"name": self.subject})
+ self.identity_management_service.register_user_credentials(user_id, user_credentials_obj)
+
+ user_info_obj = IonObject("UserInfo", {"name": "Foo"})
+ user_info = self.identity_management_service.create_user_info(user_id, user_info_obj)
+
+ org_client = OrgManagementServiceClient(node=self.container.node)
+ ion_org = org_client.find_org()
+
+ extended_user = self.identity_management_service.get_actor_identity_extension(user_id, ion_org._id)
+ self.assertEqual(actor_identity_obj.type_,extended_user.resource.type_)
+ self.assertEqual(len(extended_user.roles),1)
+
+ extended_user = self.identity_management_service.get_actor_identity_extension(user_id)
+ self.assertEqual(actor_identity_obj.type_,extended_user.resource.type_)
+ self.assertEqual(len(extended_user.roles),0)
+
+ self.identity_management_service.delete_user_info(user_info)
+
+ self.identity_management_service.unregister_user_credentials(user_id, self.subject)
+
+ self.identity_management_service.delete_actor_identity(user_id)
View
59 ion/services/sa/instrument/instrument_management_service.py
@@ -9,12 +9,13 @@
#from pyon.public import Container
from pyon.public import LCE
-from pyon.public import RT, PRED
+from pyon.public import RT, PRED, OT
from pyon.public import CFG
from pyon.core.bootstrap import IonObject
from pyon.core.exception import Inconsistent,BadRequest, NotFound
#from pyon.datastore.datastore import DataStore
#from pyon.net.endpoint import RPCClient
+from pyon.ion.resource import ExtendedResourceContainer
from pyon.util.log import log
from ion.services.sa.instrument.flag import KeywordFlag
import os
@@ -70,6 +71,7 @@ def on_init(self):
self.override_clients(self.clients)
self._pagent = None
+ self.extended_resource_handler = ExtendedResourceContainer(self)
def override_clients(self, new_clients):
"""
@@ -1532,3 +1534,58 @@ def find_stream_defs_for_output_products(self, instrument_device_id=''):
log.debug("mfms:reassign_instrument_device_to_logical_instrument: stream_def_map: %s ", str(stream_def_map))
return stream_def_map
+
+ def get_instrument_device_extension(self, instrument_device_id='', ext_associations=None, ext_exclude=None):
+ """Returns an InstrumentDeviceExtension object containing additional related information
+
+ @param instrument_device_id str
+ @param ext_associations dict
+ @param ext_exclude list
+ @retval instrument_device InstrumentDeviceExtension
+ @throws BadRequest A parameter is missing
+ @throws NotFound An object with the specified instrument_device_id does not exist
+ """
+
+ if not instrument_device_id:
+ raise BadRequest("The instrument_device_id parameter is empty")
+
+ instrument_device = self.clients.resource_registry.read(instrument_device_id)
+ if not instrument_device:
+ raise NotFound("Instrument Device %s does not exist" % instrument_device_id)
+
+ extended_instrument = self.extended_resource_handler.create_extended_resource_container(OT.InstrumentDeviceExtension, instrument_device)
+
+ #Get computed attributes - refactor into ExtendedResourceContainer when object decorators are available
+ extended_instrument.computed = IonObject(OT.InstrumentDeviceComputedAttributes)
+ extended_instrument.computed.software_version = self.get_software_version(instrument_device_id)
+ extended_instrument.computed.attached_sensors = self.get_attached_sensors(instrument_device_id)
+ extended_instrument.computed.location = self.get_location(instrument_device_id)
+ extended_instrument.computed.sensor_count = self.extended_resource_handler.get_association_count(extended_instrument, PRED.hasSensor)
+ extended_instrument.computed.data_produced = self.get_data_produced(instrument_device_id)
+
+ #Fill in related data - refactor into ExtendedResourceContainer when object decorators are available
+ self.extended_resource_handler.get_associated_resources(extended_instrument, 'data_products', PRED.hasOutputProduct)
+ self.extended_resource_handler.get_associated_resources(extended_instrument, 'instrument_model', PRED.hasModel)
+ self.extended_resource_handler.get_associated_resources(extended_instrument, 'instrument_agent', PRED.hasAgentInstance)
+ self.extended_resource_handler.get_associated_resources(extended_instrument, 'policies', PRED.hasPolicy)
+ self.extended_resource_handler.get_owners(extended_instrument, 'owners')
+ self.extended_resource_handler.get_extended_associations(extended_instrument, ext_associations)
+
+
+ return extended_instrument
+
+
+ #Bogus functions for computed attributes
+ def get_software_version(self, instrument_device_id):
+ return "1.1"
+
+ def get_location(self, instrument_device_id):
+ return IonObject(OT.GeospatialBounds)
+
+ def get_attached_sensors(self, instrument_device_id):
+ return ['abc','123']
+
+ def get_data_produced(self, instrument_device_id):
+ return "1.1"
+
+
View
61 ion/services/sa/instrument/test/test_instrument_management_service_integration.py
@@ -34,6 +34,7 @@ def setUp(self):
self.container.start_rel_from_url('res/deploy/r2deploy.yml')
self.RR = ResourceRegistryServiceClient(node=self.container.node)
+ self.IMS = InstrumentManagementServiceClient(node=self.container.node)
print 'started services'
@@ -41,6 +42,7 @@ def setUp(self):
def test_just_the_setup(self):
return
+ @unittest.skip('this test just for debugging setup')
def test_resources_associations(self):
"""
create one of each resource and association used by IMS
@@ -94,3 +96,62 @@ def test_resources_associations(self):
sensor_model_id #is only a target
+
+
+ def test_get_extended_instrument_device(self):
+
+
+ #stuff we control
+ instrument_agent_instance_id, _ = self.RR.create(any_old(RT.InstrumentAgentInstance))
+ instrument_agent_id, _ = self.RR.create(any_old(RT.InstrumentAgent))
+ instrument_device_id, _ = self.RR.create(any_old(RT.InstrumentDevice))
+ instrument_model_id, _ = self.RR.create(any_old(RT.InstrumentModel))
+ platform_agent_instance_id, _ = self.RR.create(any_old(RT.PlatformAgentInstance))
+ platform_agent_id, _ = self.RR.create(any_old(RT.PlatformAgent))
+ platform_device_id, _ = self.RR.create(any_old(RT.PlatformDevice))
+ platform_model_id, _ = self.RR.create(any_old(RT.PlatformModel))
+ sensor_device_id, _ = self.RR.create(any_old(RT.SensorDevice))
+ sensor_model_id, _ = self.RR.create(any_old(RT.SensorModel))
+
+ #stuff we associate to
+ data_producer_id, _ = self.RR.create(any_old(RT.DataProducer))
+
+ instrument_agent_instance_id #is only a target
+
+ #instrument_agent
+ self.RR.create_association(instrument_agent_id, PRED.hasModel, instrument_model_id)
+ self.RR.create_association(instrument_agent_id, PRED.hasInstance, instrument_agent_instance_id)
+
+ #instrument_device
+ self.RR.create_association(instrument_device_id, PRED.hasModel, instrument_model_id)
+ self.RR.create_association(instrument_device_id, PRED.hasAgentInstance, instrument_agent_instance_id)
+ #self.RR.create_association(instrument_device_id, PRED.hasSensor, sensor_device_id)
+ self.RR.create_association(instrument_device_id, PRED.hasDataProducer, data_producer_id)
+
+ instrument_model_id #is only a target
+
+ platform_agent_instance_id #is only a target
+
+ #platform_agent
+ self.RR.create_association(platform_agent_id, PRED.hasModel, platform_model_id)
+ self.RR.create_association(platform_agent_id, PRED.hasInstance, platform_agent_instance_id)
+
+ #platform_device
+ self.RR.create_association(platform_device_id, PRED.hasModel, platform_model_id)
+ self.RR.create_association(platform_device_id, PRED.hasAgentInstance, platform_agent_instance_id)
+ self.RR.create_association(platform_device_id, PRED.hasInstrument, instrument_device_id)
+
+ platform_model_id #is only a target
+
+ #sensor_device
+ self.RR.create_association(sensor_device_id, PRED.hasModel, sensor_model_id)
+
+ #Used for testing of computed attributes for calculating associations
+ self.RR.create_association(instrument_device_id,PRED.hasSensor, sensor_device_id)
+
+ sensor_model_id #is only a target
+
+ extended_instrument = self.IMS.get_instrument_device_extension(instrument_device_id)
+ self.assertEqual(instrument_device_id,extended_instrument._id)
+ self.assertEqual(extended_instrument.computed.sensor_count,1)
+
View
2  obj
Please sign in to comment.
Something went wrong with that request. Please try again.