Exemple #1
0
 def perform_action(self, predicate=None, action=None):
     userid = None  # get from context
     event_pub = EventPublisher(process=self)
     event_pub.publish_event(event_type=OT.ContainerManagementRequest,
                             origin=userid,
                             predicate=predicate,
                             action=action)
Exemple #2
0
 def _publish_access_event(self,
                           access_type,
                           data_product_id=None,
                           access_params=None):
     try:
         pub = EventPublisher(OT.InformationContentAccessedEvent,
                              process=self)
         event_data = dict(origin_type=RT.DataProduct,
                           origin=data_product_id or "",
                           sub_type=access_type,
                           access_params=access_params or {})
         pub.publish_event(**event_data)
     except Exception as ex:
         log.exception(
             "Error publishing InformationContentAccessedEvent for data product: %s",
             data_product_id)
    def test_procs(self):
        # Start procs
        config = {}
        pid1 = self.container.spawn_process("hello1",
                                            __name__,
                                            "CoordinatedProcess",
                                            config=config)
        pid2 = self.container.spawn_process("hello2",
                                            __name__,
                                            "CoordinatedProcess",
                                            config=config)
        pid3 = self.container.spawn_process("hello3",
                                            __name__,
                                            "CoordinatedProcess",
                                            config=config)

        # Wait for them to be ready
        gevent.sleep(0.3)

        # Call service
        evt_pub = EventPublisher(event_type=OT.ResourceCommandEvent)
        hc = HelloServiceClient()
        end_time = get_ion_ts_millis() + 4000
        counter = 0
        while get_ion_ts_millis() < end_time:
            counter += 1
            res = hc.hello("foo")
            evt_pub.publish_event(origin=str(counter))
            gevent.sleep(random.random() * 0.1)

        # Wait for them to be finish
        gevent.sleep(0.3)

        # Wrap up
        self.container.terminate_process(pid1)
        self.container.terminate_process(pid2)
        self.container.terminate_process(pid3)

        evt_count = CoordinatedProcess.evt_count
        log.info("Counters: %s", evt_count)

        self.assertEqual(evt_count["total"], 3 * counter)
        master_evts = evt_count[pid1] + evt_count[pid2] + evt_count[pid3]
        self.assertLessEqual(master_evts, counter)
        if master_evts < counter:
            log.info("Lost %s events - no functioning master",
                     counter - master_evts)
 def on_start(self):
     self.event_pub = EventPublisher(process=self)
Exemple #5
0
 def on_init(self):
     self.rr = self.clients.resource_registry
     self.event_pub = EventPublisher(process=self)
     self.negotiation_handler = Negotiation(self, negotiation_rules,
                                            self.event_pub)
     self.root_org_id = None
    def test_user_role_cache(self):
        #Create a user
        id_client = IdentityManagementServiceClient()

        actor_id, valid_until, registered = id_client.signon(
            USER1_CERTIFICATE, True)

        #Make a request with this new user  to get it into the cache
        response = self.test_app.get(
            '/ion-service/resource_registry/find_resources?name=TestDataProduct&id_only=True&requester='
            + actor_id)
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json['data'])

        #Check the contents of the user role cache for this user
        service_gateway_user_role_cache = self.container.proc_manager.procs_by_name[
            'service_gateway'].user_role_cache
        self.assertEqual(service_gateway_user_role_cache.has_key(actor_id),
                         True)

        role_header = service_gateway_user_role_cache.get(actor_id)
        self.assertIn('ION', role_header)
        self.assertEqual(len(role_header['ION']), 1)
        self.assertIn('ORG_MEMBER', role_header['ION'])

        org_client = OrgManagementServiceClient()

        ion_org = org_client.find_org()
        manager_role = org_client.find_org_role_by_name(
            org_id=ion_org._id, role_name='ORG_MANAGER')

        org_client.grant_role(org_id=ion_org._id,
                              actor_id=actor_id,
                              role_name='ORG_MANAGER')

        #Just allow some time for event processing on slower platforms
        gevent.sleep(2)

        #The user should be evicted from the cache due to a change in roles
        self.assertEqual(service_gateway_user_role_cache.has_key(actor_id),
                         False)

        #Do it again to check for new roles
        response = self.test_app.get(
            '/ion-service/resource_registry/find_resources?name=TestDataProduct&id_only=True&requester='
            + actor_id)
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json['data'])

        #Check the contents of the user role cache for this user
        self.assertEqual(service_gateway_user_role_cache.has_key(actor_id),
                         True)

        role_header = service_gateway_user_role_cache.get(actor_id)
        self.assertIn('ION', role_header)
        self.assertEqual(len(role_header['ION']), 2)
        self.assertIn('ORG_MEMBER', role_header['ION'])
        self.assertIn('ORG_MANAGER', role_header['ION'])

        #Now flush the user_role_cache and make sure it was flushed
        event_publisher = EventPublisher()
        event_publisher.publish_event(event_type=OT.UserRoleCacheResetEvent)

        #Just allow some time for event processing on slower platforms
        gevent.sleep(2)

        self.assertEqual(service_gateway_user_role_cache.has_key(actor_id),
                         False)
        self.assertEqual(service_gateway_user_role_cache.size(), 0)

        #Change the role once again and see if it is there again
        org_client.revoke_role(org_id=ion_org._id,
                               actor_id=actor_id,
                               role_name='ORG_MANAGER')

        #Just allow some time for event processing on slower platforms
        gevent.sleep(2)

        #The user should still not be there
        self.assertEqual(service_gateway_user_role_cache.has_key(actor_id),
                         False)

        #Do it again to check for new roles
        response = self.test_app.get(
            '/ion-service/resource_registry/find_resources?name=TestDataProduct&id_only=True&requester='
            + actor_id)
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json['data'])

        #Check the contents of the user role cache for this user
        self.assertEqual(service_gateway_user_role_cache.has_key(actor_id),
                         True)

        role_header = service_gateway_user_role_cache.get(actor_id)
        self.assertIn('ION', role_header)
        self.assertEqual(len(role_header['ION']), 1)
        self.assertIn('ORG_MEMBER', role_header['ION'])

        id_client.delete_actor_identity(actor_id)
Exemple #7
0
 def on_init(self):
     self.rr = self.clients.resource_registry
     self.event_repo = self.container.event_repository
     self.idm_client = self.clients.identity_management
     self.rm_client = self.clients.resource_management
     self.evt_pub = EventPublisher(process=self)