def on_init(self): if not HighAvailabilityCore: msg = "HighAvailabilityCore isn't available. Use autolaunch.cfg buildout" log.error(msg) return cfg = self.CFG.get_safe("highavailability") # use default PD name as the sole PD if none are provided in config self.pds = self.CFG.get_safe("highavailability.process_dispatchers", [ProcessDispatcherService.name]) if not len(self.pds) == 1: raise Exception( "HA Service doesn't support multiple Process Dispatchers") self.process_definition_id, self.process_definition = self._get_process_definition( ) self.process_configuration = self.CFG.get_safe( "highavailability.process_configuration") aggregator_config = _get_aggregator_config(self.CFG) self.service_id, self.service_name = self._register_service() self.policy_event = Event() stored_policy = self._stored_policy if stored_policy != {}: policy_name = stored_policy.get('name') policy_parameters = stored_policy.get('parameters') self._validate_policy_name(policy_name) self.policy_name = policy_name.lower() self.policy_parameters = policy_parameters else: policy_name = self.CFG.get_safe("highavailability.policy.name") self._validate_policy_name(policy_name) self.policy_name = policy_name.lower() self.policy_parameters = self.CFG.get_safe( "highavailability.policy.parameters") self.policy_interval = self.CFG.get_safe( "highavailability.policy.interval", DEFAULT_INTERVAL) self.logprefix = "HA Agent (%s): " % self.service_name self.control = HAProcessControl(self.pds[0], self.container.resource_registry, self.service_id, self.policy_event.set, logprefix=self.logprefix) self.core = HighAvailabilityCore( cfg, self.control, self.pds, self.policy_name, process_definition_id=self.process_definition_id, parameters=self.policy_parameters, process_configuration=self.process_configuration, aggregator_config=aggregator_config, name=self.service_name) dashi_messaging = self.CFG.get_safe("highavailability.dashi_messaging", False) if dashi_messaging: dashi_name = self.CFG.get_safe("highavailability.dashi_name") if not dashi_name: raise Exception("dashi_name unknown") dashi_uri = self.CFG.get_safe("highavailability.dashi_uri") if not dashi_uri: rabbit_host = self.CFG.get_safe("server.amqp.host") rabbit_user = self.CFG.get_safe("server.amqp.username") rabbit_pass = self.CFG.get_safe("server.amqp.password") if not (rabbit_host and rabbit_user and rabbit_pass): raise Exception("cannot form dashi URI") dashi_uri = "amqp://%s:%s@%s/" % (rabbit_user, rabbit_pass, rabbit_host) dashi_exchange = self.CFG.get_safe( "highavailability.dashi_exchange") if not dashi_exchange: dashi_exchange = get_sys_name() self.dashi_handler = HADashiHandler(self, dashi_name, dashi_uri, dashi_exchange) else: self.dashi_handler = None
def on_init(self): if not HighAvailabilityCore: msg = "HighAvailabilityCore isn't available. Use autolaunch.cfg buildout" log.error(msg) return log.debug("HighAvailabilityCore Pyon on_init") policy_name = self.CFG.get_safe("highavailability.policy.name") if policy_name is None: msg = "HA service requires a policy name at CFG.highavailability.policy.name" raise Exception(msg) try: self.policy = policy.policy_map[policy_name.lower()] except KeyError: raise Exception("HA Service doesn't support '%s' policy" % policy_name) policy_parameters = self.CFG.get_safe("highavailability.policy.parameters") self.policy_interval = self.CFG.get_safe("highavailability.policy.interval", DEFAULT_INTERVAL) cfg = self.CFG.get_safe("highavailability") # use default PD name as the sole PD if none are provided in config self.pds = self.CFG.get_safe("highavailability.process_dispatchers", [ProcessDispatcherService.name]) self.process_definition_id = self.CFG.get_safe("highavailability.process_definition_id") self.process_configuration = self.CFG.get_safe("highavailability.process_configuration") aggregator_config = self.CFG.get_safe("highavailability.aggregator") self.service_id = self._register_service() # TODO: Allow other core class? self.core = HighAvailabilityCore(cfg, ProcessDispatcherSimpleAPIClient, self.pds, self.policy, process_definition_id=self.process_definition_id, parameters=policy_parameters, process_configuration=self.process_configuration, aggregator_config=aggregator_config, pd_client_kwargs={'container': self.container, 'service_id': self.service_id}) self.policy_thread = looping_call(self.policy_interval, self.core.apply_policy) dashi_messaging = self.CFG.get_safe("highavailability.dashi_messaging", False) if dashi_messaging: dashi_name = self.CFG.get_safe("highavailability.dashi_name") if not dashi_name: raise Exception("dashi_name unknown") dashi_uri = self.CFG.get_safe("highavailability.dashi_uri") if not dashi_uri: rabbit_host = self.CFG.get_safe("server.amqp.host") rabbit_user = self.CFG.get_safe("server.amqp.username") rabbit_pass = self.CFG.get_safe("server.amqp.password") if not (rabbit_host and rabbit_user and rabbit_pass): raise Exception("cannot form dashi URI") dashi_uri = "amqp://%s:%s@%s/" % (rabbit_user, rabbit_pass, rabbit_host) dashi_exchange = self.CFG.get_safe("highavailability.dashi_exchange") if not dashi_exchange: dashi_exchange = get_sys_name() self.dashi_handler = HADashiHandler(self, dashi_name, dashi_uri, dashi_exchange) else: self.dashi_handler = None