Notify cfg agent to now handle some hosting devices.

        This notification relieves the cfg agent in <host> of responsibility
        to monitor and configure hosting devices with id specified in <ids>.
480299
def hosting_devices_assigned_to_cfg_agent(self, context, ids, host):
        
        self._host_notification(context,
                                'hosting_devices_assigned_to_cfg_agent',
                                {'hosting_device_ids': ids}, host)
640576
def assign_hosting_device_to_cfg_agent(self, context, cfg_agent_id,
                                           hosting_device_id):
        """"""
        hd_db = self._get_hosting_device(context, hosting_device_id)
        if hd_db.cfg_agent_id:
            if hd_db.cfg_agent_id == cfg_agent_id:
                return
            LOG.debug('Hosting device %(hd_id)s has already been assigned to '
                      'Cisco cfg agent %(agent_id)s',
                      {'hd_id': hosting_device_id, 'agent_id': cfg_agent_id})
            raise ciscocfgagentscheduler.HostingDeviceAssignedToCfgAgent(
                hosting_device_id=hosting_device_id, agent_id=cfg_agent_id)
        cfg_agent_db = get_agent_db_obj(self._get_agent(context, cfg_agent_id))
        if (cfg_agent_db.agent_type != c_constants.AGENT_TYPE_CFG or
                cfg_agent_db.admin_state_up is not True):
            raise ciscocfgagentscheduler.InvalidCfgAgent(agent_id=cfg_agent_id)
        self._bind_hosting_device_to_cfg_agent(context, hd_db, cfg_agent_db)
        cfg_notifier = self.agent_notifiers.get(c_constants.AGENT_TYPE_CFG)
        if cfg_notifier:
            cfg_notifier.hosting_devices_assigned_to_cfg_agent(
                context, [hosting_device_id], cfg_agent_db.host)
1329847
def enable_host_freshness_checks(self):
        
        if not self.my_conf.check_host_freshness:
            self.my_conf.modified_attributes |= \
                DICT_MODATTR["MODATTR_FRESHNESS_CHECKS_ENABLED"].value
            self.my_conf.check_host_freshness = True
            self.my_conf.explode_global_conf()
            self.daemon.update_program_status()
785800
async def handle_agent_job_done(self, agent_addr, message: AgentJobDone):
        """"""

        if agent_addr in self._registered_agents:
            self._logger.info("Job %s %s finished on agent %s", message.job_id[0], message.job_id[1], agent_addr)

            # Remove the job from the list of running jobs
            del self._job_running[message.job_id]

            # Sent the data back to the client
            await ZMQUtils.send_with_addr(self._client_socket, message.job_id[0], BackendJobDone(message.job_id[1], message.result,
                                                                                                 message.grade, message.problems,
                                                                                                 message.tests, message.custom,
                                                                                                 message.state, message.archive,
                                                                                                 message.stdout, message.stderr))

            # The agent is available now
            self._available_agents.append(agent_addr)
        else:
            self._logger.warning("Job result %s %s from non-registered agent %s", message.job_id[0], message.job_id[1], agent_addr)

        # update the queue
        await self.update_queue()
494875
def _agent_notification_bulk(self, context, method, routers,
                                 hosting_device, operation):
        
        admin_context = context.is_admin and context or context.elevated()
        dmplugin = bc.get_plugin(cisco_constants.DEVICE_MANAGER)
        if (hosting_device is not None and extensions.is_extension_supported(
                dmplugin, CFGAGENT_SCHED)):
            agents = dmplugin.get_cfg_agents_for_hosting_devices(
                admin_context, [hosting_device['id']], admin_state_up=True,
                schedule=True)
            if agents:
                agent = agents[0]
                LOG.debug('Notify %(agent_type)s at %(topic)s.%(host)s the '
                          'message %(method)s [BULK]',
                          {'agent_type': agent.agent_type,
                           'topic': CFG_AGENT_L3_ROUTING,
                           'host': agent.host,
                           'method': method})
                cctxt = self.client.prepare(server=agent.host,
                                            version='1.1')
                cctxt.cast(context, method, routers=routers)
906987
def _treat_devices_added(self):
        """"""
        try:
            devices_details_list = self._plugin_rpc.get_devices_details_list(
                self._context, self._added_ports, self._agent_id)
        except Exception as exc:
            LOG.debug("Unable to get ports details for "
                      "devices %(devices)s: %(exc)s",
                      {'devices': self._added_ports, 'exc': exc})
            return

        for device_details in devices_details_list:
            device = device_details['device']
            LOG.info("Adding port %s", device)
            if 'port_id' in device_details:
                LOG.info("Port %(device)s updated. "
                         "Details: %(device_details)s",
                         {'device': device, 'device_details': device_details})
                eventlet.spawn_n(self.process_added_port, device_details)
            else:
                LOG.debug("Missing port_id from device details: "
                          "%(device)s. Details: %(device_details)s",
                          {'device': device, 'device_details': device_details})

            LOG.debug("Remove the port from added ports set, so it "
                      "doesn't get reprocessed.")
            self._added_ports.discard(device)
653013
def get_hosting_device_configuration(self, context, id):
        
        admin_context = context.is_admin and context or context.elevated()
        agents = self._dmplugin.get_cfg_agents_for_hosting_devices(
            admin_context, [id], admin_state_up=True, schedule=True)
        if agents:
            cctxt = self.client.prepare(server=agents[0].host)
            return cctxt.call(context, 'get_hosting_device_configuration',
                              payload={'hosting_device_id': id})
354781
def enable_host_flap_detection(self, host):
        
        if not host.flap_detection_enabled:
            host.modified_attributes |= \
                DICT_MODATTR["MODATTR_FLAP_DETECTION_ENABLED"].value
            host.flap_detection_enabled = True
            self.send_an_element(host.get_update_status_brok())
929299
def disable_host_notifications(self, host):
        
        if host.notifications_enabled:
            host.modified_attributes |= DICT_MODATTR["MODATTR_NOTIFICATIONS_ENABLED"].value
            host.notifications_enabled = False
            self.send_an_element(host.get_update_status_brok())
607932
def report_dead_hosting_devices(self, context, hd_ids=None):
        
        cctxt = self.client.prepare()
        cctxt.cast(context, 'report_non_responding_hosting_devices',
                   host=self.host, hosting_device_ids=hd_ids)
292741
@Override
    public void notifyOfHosts(
            int yourHostId,
            int[] hosts,
            SocketChannel[] sockets,
            SSLEngine[] sslEngines,
            InetSocketAddress listeningAddresses[],
            Map<Integer, JSONObject> jos) throws Exception {
        m_localHostId = yourHostId;
        long agreementHSId = getHSIdForLocalSite(AGREEMENT_SITE_ID);

        /*
         * Construct the set of agreement sites based on all the hosts that are connected
         */
        HashSet<Long> agreementSites = new HashSet<Long>();
        agreementSites.add(agreementHSId);

        m_network.start();//network must be running for register to work

        for (int ii = 0; ii < hosts.length; ii++) {
            networkLog.info(yourHostId + " notified of host " + hosts[ii]);
            agreementSites.add(CoreUtils.getHSIdFromHostAndSite(hosts[ii], AGREEMENT_SITE_ID));
            prepSocketChannel(sockets[ii]);
            ForeignHost fhost = null;
            try {
                fhost = new ForeignHost(this, hosts[ii], sockets[ii], m_config.deadHostTimeout,
                        listeningAddresses[ii], createPicoNetwork(sslEngines[ii], sockets[ii], false));
                putForeignHost(hosts[ii], fhost);
            } catch (java.io.IOException e) {
                org.voltdb.VoltDB.crashLocalVoltDB("Failed to instantiate foreign host", true, e);
            }
        }

        m_acceptor.accrue(jos);

        /*
         * Create the local agreement site. It knows that it is recovering because the number of
         * prexisting sites is > 0
         */
        SiteMailbox sm = new SiteMailbox(this, agreementHSId);
        createMailbox(agreementHSId, sm);
        m_agreementSite =
            new AgreementSite(
                    agreementHSId,
                    agreementSites,
                    yourHostId,
                    sm,
                    new InetSocketAddress(
                            m_config.zkInterface.split(":")[0],
                            Integer.parseInt(m_config.zkInterface.split(":")[1])),
                   m_config.backwardsTimeForgivenessWindow,
                   m_failedHostsCallback);

        /*
         * Now that the agreement site mailbox has been created it is safe
         * to enable read
         */
        for (ForeignHost fh : m_foreignHosts.values()) {
            fh.enableRead(VERBOTEN_THREADS);
        }
        m_agreementSite.start();

        /*
         * Do the usual thing of waiting for the agreement site
         * to join the cluster and creating the client
         */
        VERBOTEN_THREADS.addAll(m_network.getThreadIds());
        VERBOTEN_THREADS.addAll(m_agreementSite.getThreadIds());
        m_agreementSite.waitForRecovery();
        m_zk = org.voltcore.zk.ZKUtil.getClient(
                m_config.zkInterface, 60 * 1000, VERBOTEN_THREADS);
        if (m_zk == null) {
            throw new Exception("Timed out trying to connect local ZooKeeper instance");
        }

        /*
         * Publish the address of this node to ZK as seen by the leader
         * Also allows waitForGroupJoin to know the number of nodes in the cluster
         */
        HostInfo hostInfo;
        if (m_config.internalInterface.isEmpty()) {
            hostInfo = new HostInfo(new InetSocketAddress(m_joiner.m_reportedInternalInterface, m_config.internalPort).toString(),
                                    m_config.group, m_config.localSitesCount, m_config.recoveredPartitions);
        } else {
            hostInfo = new HostInfo(new InetSocketAddress(m_config.internalInterface, m_config.internalPort).toString(),
                                    m_config.group, m_config.localSitesCount, m_config.recoveredPartitions);
        }

        m_zk.create(CoreZK.hosts_host + getHostId(), hostInfo.toBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
    }
1335415
def disable_host_svc_notifications(self, host):
        
        for service_id in host.services:
            if service_id in self.daemon.services:
                service = self.daemon.services[service_id]
                self.disable_svc_notifications(service)
                self.send_an_element(service.get_update_status_brok())
764274
def notify_slaves(self):
        """"""
        if self.disable_slave_notify is not None:
            LOGGER.debug('Slave notifications disabled')
            return False

        if self.zone_data()['kind'] == 'Master':
            response_code = self._put('/zones/' + self.domain + '/notify').status_code
            if response_code == 200:
                LOGGER.debug('Slave(s) notified')
                return True
            LOGGER.debug('Slave notification failed with code %i', response_code)
        else:
            LOGGER.debug('Zone type should be \'Master\' for slave notifications')
        return False
798056
@Override
    public synchronized void reportForeignHostFailed(int hostId) {
        long initiatorSiteId = CoreUtils.getHSIdFromHostAndSite(hostId, AGREEMENT_SITE_ID);
        m_agreementSite.reportFault(initiatorSiteId);
        if (!m_shuttingDown) {
            // should be the single console message a user sees when another node fails
            networkLog.warn(String.format("Host %d failed. Cluster remains operational.", hostId));
        }
    }
975791
def enable_host_svc_checks(self, host):
        
        for service_id in host.services:
            if service_id in self.daemon.services:
                service = self.daemon.services[service_id]
                self.enable_svc_check(service)
                self.send_an_element(service.get_update_status_brok())
474937
def activate_host(self, host):
        '''
        
        '''

        logger.debug('Activating host: {0}'.format(host))

        # Add to *both* activated and active - active will reduce as hosts fail
        # but connected will not, enabling us to track failed %.
        self.activated_hosts.add(host)
        self.active_hosts.add(host)
54424
def notice(self, msg, *args, **kw):
        """"""
        if self.isEnabledFor(NOTICE):
            self._log(NOTICE, msg, args, **kw)