def on_initial_bootstrap(self, process, config, **kwargs): org_ms_client = OrgManagementServiceProcessClient(process=process) ex_ms_client = ExchangeManagementServiceProcessClient(process=process) system_actor, _ = process.container.resource_registry.find_resources( restype=RT.ActorIdentity, name=config.system.system_actor, id_only=True) if not system_actor: raise AbortBootstrap("Cannot find system actor") system_actor_id = system_actor[0] # Create root Org: ION root_orgname = config.system.root_org org = Org(name=root_orgname, description="ION Root Org") self.org_id = org_ms_client.create_org(org) # Instantiate initial set of User Roles for this Org ion_manager = UserRole(name=ION_MANAGER, label='ION Manager', description='ION Manager') org_ms_client.add_user_role(self.org_id, ion_manager) org_ms_client.grant_role(self.org_id, system_actor_id, ION_MANAGER) # Make the ION system agent a manager for the ION Org org_ms_client.grant_role(self.org_id, system_actor_id, ORG_MANAGER_ROLE) # Create root ExchangeSpace xs = ExchangeSpace(name=ION_ROOT_XS, description="ION service XS") self.xs_id = ex_ms_client.create_exchange_space(xs, self.org_id)
def __init__(self, container): log.debug("ExchangeManager initializing ...") self.container = container # Define the callables that can be added to Container public API # @TODO: remove self.container_api = [ self.create_xs, self.create_xp, self.create_xn_service, self.create_xn_process, self.create_xn_queue ] # Add the public callables to Container for call in self.container_api: setattr(self.container, call.__name__, call) self.default_xs = ExchangeSpace(self, ION_ROOT_XS) self._xs_cache = {} # caching of xs names to RR objects self._default_xs_obj = None # default XS registry object self.org_id = None # mappings self.xs_by_name = { ION_ROOT_XS: self.default_xs } # friendly named XS to XSO self.xn_by_name = {} # friendly named XN to XNO # xn by xs is a property self._chan = None # @TODO specify our own to_name here so we don't get auto-behavior - tricky chicken/egg self._ems_client = ExchangeManagementServiceProcessClient( process=self.container) self._rr_client = ResourceRegistryServiceProcessClient( process=self.container)
def on_initial_bootstrap(self, process, config, **kwargs): """ Bootstraps initial objects in the system from configuration (pyon.yml) via EMS calls. """ # get default org_id # @TODO: single org assumed for now org_ids = process.container.resource_registry.find_resources( RT.Org, id_only=True) if not (len(org_ids) and len(org_ids[0]) == 1): raise StandardError("Could not determine org_id") org_id = org_ids[0][0] ems_client = ExchangeManagementServiceProcessClient(process=process) # # Create XSs and XPs # for xsname, xsdict in config.get_safe('exchange_spaces', {}).iteritems(): xso = ResExchangeSpace(name=xsname) xso_id = ems_client.create_exchange_space(xso, org_id) log.info("ExchangeSpace %s, id %s", xsname, xso_id) for xpname, xpopts in xsdict.get('exchange_points', {}).iteritems(): # @TODO: some translation for types CFG currentl has it as "topic_tree" and we've been using "ttree" ttype = xpopts.get('type', 'topic_tree') if ttype == "topic_tree": ttype = "ttree" xpo = ResExchangePoint(name=xpname, topology_type=ttype) xpo_id = ems_client.create_exchange_point(xpo, xso_id) log.info("\tExchangePoint %s, id %s", xpname, xpo_id) # # Create and associate brokers with XSs # for brokername in xsdict.get('brokers', []): xbo = ResExchangeBroker(name=brokername) xbo_id = ems_client.create_exchange_broker(xbo) log.info("\tExchangeBroker %s, id %s", brokername, xbo_id) # directly associate broker with XS # @TODO: should EMS provide this? # first find out if the assoc exists already assocs = process.container.resource_registry.find_associations( xso_id, PRED.hasExchangeBroker, id_only=True) if len(assocs) > 0: continue process.container.resource_registry.create_association( xso_id, PRED.hasExchangeBroker, xbo_id)
def on_initial_bootstrap(self, process, config, **kwargs): """ Bootstraps initial objects in the system from configuration (pyon.yml) via EMS calls. """ # Get ION Org root_org_name = config.get_safe('system.root_org' , "ION") org_ids, _ = process.container.resource_registry.find_resources(restype=RT.Org, name=root_org_name, id_only=True) if not org_ids or len(org_ids) > 1: raise StandardError("Could not determine root Org") org_id = org_ids[0] ems_client = ExchangeManagementServiceProcessClient(process=process) # Create XSs and XPs resource objects xs_by_name = {} # Name to resource ID mapping for ExchangeSpace xs_defs = config.get_safe("exchange.exchange_spaces", {}) for xsname, xsdict in xs_defs.iteritems(): xso = ResExchangeSpace(name=xsname, description=xsdict.get("description", "")) xso_id = ems_client.create_exchange_space(xso, org_id) xs_by_name[xsname] = xso_id log.info("ExchangeSpace %s, id %s", xsname, xso_id) for xpname, xpopts in xsdict.get("exchange_points", {}).iteritems(): # Translation for types. CFG currently has it as "topic_tree" and Pyon uses "ttree" xpo = ResExchangePoint(name=xpname, description=xpopts.get("description", ""), topology_type=xpopts.get('type', 'ttree')) xpo_id = ems_client.create_exchange_point(xpo, xso_id) log.info("\tExchangePoint %s, id %s", xpname, xpo_id) # Create XSs and XPs resource objects for brokername, bdict in config.get_safe("exchange.exchange_brokers", {}).iteritems(): xbo = ResExchangeBroker(name=brokername, description=bdict.get("description", "")) xbo_id = ems_client.create_exchange_broker(xbo) log.info("\tExchangeBroker %s, id %s", brokername, xbo_id) for xs_name in bdict.get("join_xs", []): if xs_name in xs_by_name: xs_id = xs_by_name[xs_name] # directly associate broker with XS # @TODO: should EMS provide this? # first find out if the assoc exists already assocs = process.container.resource_registry.find_associations(xso_id, PRED.hasExchangeBroker, id_only=True) if len(assocs) > 0: continue process.container.resource_registry.create_association(xso_id, PRED.hasExchangeBroker, xbo_id) else: log.warn("ExchangeSpace %s unknown. Broker %s cannot join", xs_name, brokername) for xp_name in bdict.get("join_xp", []): pass
def setUp(self): # Start container self._start_container() #Load a deploy file self.container.start_rel_from_url('res/deploy/r2deploy.yml') #Instantiate a process to represent the test process = GovernanceTestProcess() #Load system policies after container has started all of the services LoadSystemPolicy.op_load_system_policies(process) self.rr_client = ResourceRegistryServiceProcessClient( node=self.container.node, process=process) self.id_client = IdentityManagementServiceProcessClient( node=self.container.node, process=process) self.pol_client = PolicyManagementServiceProcessClient( node=self.container.node, process=process) self.org_client = OrgManagementServiceProcessClient( node=self.container.node, process=process) self.ims_client = InstrumentManagementServiceProcessClient( node=self.container.node, process=process) self.ems_client = ExchangeManagementServiceProcessClient( node=self.container.node, process=process) self.ion_org = self.org_client.find_org() self.system_actor = self.id_client.find_actor_identity_by_name( name=CFG.system.system_actor) log.debug('system actor:' + self.system_actor._id) sa_header_roles = get_role_message_headers( self.org_client.find_all_roles_by_user(self.system_actor._id)) self.sa_user_header = { 'ion-actor-id': self.system_actor._id, 'ion-actor-roles': sa_header_roles }
def __init__(self, container): log.debug("ExchangeManager initializing ...") self.container = container # Define the callables that can be added to Container public API # @TODO: remove self.container_api = [ self.create_xs, self.create_xp, self.create_xn_service, self.create_xn_process, self.create_xn_queue ] # Add the public callables to Container for call in self.container_api: setattr(self.container, call.__name__, call) self.default_xs = None self._xs_cache = {} # caching of xs names to RR objects self._default_xs_obj = None # default XS registry object self.org_id = None self._default_xs_declared = False # mappings self.xs_by_name = {} # friendly named XS to XSO self.xn_by_name = {} # friendly named XN to XNO # xn by xs is a property # @TODO specify our own to_name here so we don't get auto-behavior - tricky chicken/egg self._ems_client = ExchangeManagementServiceProcessClient( process=self.container) self._rr_client = ResourceRegistryServiceProcessClient( process=self.container) # mapping of node/ioloop runner by connection name (in config, named via container.messaging.server keys) self._nodes = {} self._ioloops = {} # public toggle switch for if EMS should be used by default self.use_ems = True