class ConfigDatabaseEventManager(EventManager): def __init__(self, config, unit_names): table = 'ObjectConfigDatabaseInfo' type_info = EventManagerTypeInfo( object_table=table, module_type=Module.CONFIG_DATABASE_NODE_MGR, sandesh_packages=['database.sandesh']) super(ConfigDatabaseEventManager, self).__init__( config, type_info, unit_names) self.cassandra_repair_interval = config.cassandra_repair_interval self.cassandra_mgr = CassandraManager( config.cassandra_repair_logdir, 'config', table, config.hostip, config.minimum_diskgb, config.db_port, config.db_jmx_port, config.db_use_ssl, config.db_user, config.db_password, self.process_info_manager) def get_failbits_nodespecific_desc(self, fail_status_bits): return self.cassandra_mgr.get_failbits_nodespecific_desc( self, fail_status_bits) def do_periodic_events(self): self.cassandra_mgr.database_periodic(self) # Perform nodetool repair every cassandra_repair_interval hours if self.tick_count % (60 * self.cassandra_repair_interval) == 0: self.cassandra_mgr.repair() super(ConfigDatabaseEventManager, self).do_periodic_events()
class DatabaseEventManager(EventManager): def __init__(self, config, unit_names): type_info = EventManagerTypeInfo(object_table="ObjectDatabaseInfo", module_type=Module.DATABASE_NODE_MGR, sandesh_packages=['database.sandesh']) super(DatabaseEventManager, self).__init__(config, type_info, sandesh_global, unit_names) # TODO: try to understand is next needed here and use it or remove #self.cassandra_repair_interval = config.cassandra_repair_interval self.cassandra_mgr = CassandraManager( config.cassandra_repair_logdir, 'analytics', config.contrail_databases, config.hostip, config.minimum_diskgb, config.db_port, config.db_jmx_port, config.db_user, config.db_password, self.process_info_manager) def get_failbits_nodespecific_desc(self, fail_status_bits): description = "" if fail_status_bits & self.FAIL_STATUS_DISK_SPACE: description += "Disk for analytics db is too low," + \ " cassandra stopped." if fail_status_bits & self.FAIL_STATUS_SERVER_PORT: if description != "": description += " " description += "Cassandra state detected DOWN." if fail_status_bits & self.FAIL_STATUS_DISK_SPACE_NA: description += "Disk space for analytics db not retrievable." return description def do_periodic_events(self): self.cassandra_mgr.database_periodic(self) super(DatabaseEventManager, self).do_periodic_events()
class ConfigEventManager(EventManager): def __init__(self, config, unit_names): type_info = EventManagerTypeInfo(module_type=Module.CONFIG_NODE_MGR, object_table='ObjectConfigNode', sandesh_packages=['database.sandesh']) super(ConfigEventManager, self).__init__(config, type_info, sandesh_global, unit_names) self.cassandra_repair_interval = config.cassandra_repair_interval self.cassandra_mgr = CassandraManager( config.cassandra_repair_logdir, 'config', config.contrail_databases, config.hostip, config.minimum_diskgb, config.db_port, config.db_jmx_port, config.db_user, config.db_password, self.process_info_manager) def get_failbits_nodespecific_desc(self, fail_status_bits): description = "" if fail_status_bits & self.FAIL_STATUS_DISK_SPACE: description += "Disk for config db is too low," + \ " cassandra stopped." if fail_status_bits & self.FAIL_STATUS_SERVER_PORT: if description != "": description += " " description += "Cassandra state detected DOWN." if fail_status_bits & self.FAIL_STATUS_DISK_SPACE_NA: description += "Disk space for config db not retrievable." return description def do_periodic_events(self): self.cassandra_mgr.database_periodic(self) # Perform nodetool repair every cassandra_repair_interval hours if self.tick_count % (60 * self.cassandra_repair_interval) == 0: self.cassandra_mgr.repair() super(ConfigEventManager, self).do_periodic_events()
class ConfigDatabaseEventManager(EventManager): def __init__(self, config, unit_names): table = 'ObjectConfigDatabaseInfo' type_info = EventManagerTypeInfo( object_table=table, module_type=Module.CONFIG_DATABASE_NODE_MGR, sandesh_packages=['database.sandesh']) super(ConfigDatabaseEventManager, self).__init__( config, type_info, unit_names) self.cassandra_repair_interval = config.cassandra_repair_interval self.cassandra_mgr = CassandraManager( config.cassandra_repair_logdir, 'config', table, config.hostip, config.minimum_diskgb, config.db_port, config.db_jmx_port, config.db_use_ssl, config.db_user, config.db_password, self.process_info_manager, hostname=config.hostname) def get_failbits_nodespecific_desc(self, fail_status_bits): return self.cassandra_mgr.get_failbits_nodespecific_desc( self, fail_status_bits) def do_periodic_events(self): self.cassandra_mgr.database_periodic(self) # Perform nodetool repair every cassandra_repair_interval hours if self.tick_count % (60 * self.cassandra_repair_interval) == 0: self.cassandra_mgr.repair(self) super(ConfigDatabaseEventManager, self).do_periodic_events()
class AnalyticsDatabaseEventManager(EventManager): def __init__(self, config, unit_names): table = 'ObjectDatabaseInfo' type_info = EventManagerTypeInfo(object_table=table, module_type=Module.DATABASE_NODE_MGR, sandesh_packages=['database.sandesh']) super(AnalyticsDatabaseEventManager, self).__init__(config, type_info, unit_names) # TODO: try to understand is next needed here and use it or remove #self.cassandra_repair_interval = config.cassandra_repair_interval self.cassandra_mgr = CassandraManager(config.cassandra_repair_logdir, 'analytics', table, config.hostip, config.minimum_diskgb, config.db_port, config.db_jmx_port, config.db_use_ssl, config.db_user, config.db_password, self.process_info_manager, hostname=config.hostname) def get_failbits_nodespecific_desc(self, fail_status_bits): return self.cassandra_mgr.get_failbits_nodespecific_desc( self, fail_status_bits) def do_periodic_events(self): self.cassandra_mgr.database_periodic(self) super(AnalyticsDatabaseEventManager, self).do_periodic_events()
class AnalyticsDatabaseEventManager(EventManager): def __init__(self, config, unit_names): table = 'ObjectDatabaseInfo' type_info = EventManagerTypeInfo( object_table=table, module_type=Module.DATABASE_NODE_MGR, sandesh_packages=['database.sandesh']) super(AnalyticsDatabaseEventManager, self).__init__( config, type_info, unit_names) # TODO: try to understand is next needed here and use it or remove #self.cassandra_repair_interval = config.cassandra_repair_interval self.cassandra_mgr = CassandraManager( config.cassandra_repair_logdir, 'analytics', table, config.hostip, config.minimum_diskgb, config.db_port, config.db_jmx_port, config.db_use_ssl, config.db_user, config.db_password, self.process_info_manager) def get_failbits_nodespecific_desc(self, fail_status_bits): return self.cassandra_mgr.get_failbits_nodespecific_desc( self, fail_status_bits) def do_periodic_events(self): self.cassandra_mgr.database_periodic(self) super(AnalyticsDatabaseEventManager, self).do_periodic_events()
class DatabaseEventManager(EventManager): def __init__(self, config, rule_file, unit_names): if os.path.exists('/tmp/supervisord_database.sock'): supervisor_serverurl = "unix:///tmp/supervisord_database.sock" else: supervisor_serverurl = "unix:///var/run/supervisord_database.sock" type_info = EventManagerTypeInfo( package_name='contrail-database-common', object_table="ObjectDatabaseInfo", module_type=Module.DATABASE_NODE_MGR, supervisor_serverurl=supervisor_serverurl, third_party_processes={ "cassandra": "Dcassandra-pidfile=.*cassandra\.pid", "zookeeper": "org.apache.zookeeper.server.quorum.QuorumPeerMain" }, sandesh_packages=['database.sandesh']) super(DatabaseEventManager, self).__init__(config, type_info, rule_file, sandesh_global, unit_names) self.hostip = config.hostip self.db_port = config.db_port self.minimum_diskgb = config.minimum_diskgb self.contrail_databases = config.contrail_databases # TODO: try to understand is next needed for analytics db and use it or remove #self.cassandra_repair_interval = config.cassandra_repair_interval self.cassandra_mgr = CassandraManager(config.cassandra_repair_logdir, 'analyticsDb', self.contrail_databases, self.hostip, self.minimum_diskgb, self.db_port, self.process_info_manager) # end __init__ def get_failbits_nodespecific_desc(self, fail_status_bits): description = "" if fail_status_bits & self.FAIL_STATUS_DISK_SPACE: description += "Disk for analytics db is too low," + \ " cassandra stopped." if fail_status_bits & self.FAIL_STATUS_SERVER_PORT: if description != "": description += " " description += "Cassandra state detected DOWN." if fail_status_bits & self.FAIL_STATUS_DISK_SPACE_NA: description += "Disk space for analytics db not retrievable." return description def do_periodic_events(self): if self.cassandra_mgr.can_serve(): self.cassandra_mgr.database_periodic(self) self.event_tick_60() # end do_periodic_events def process(self): if self.cassandra_mgr.can_serve(): self.cassandra_mgr.process(self)
class ConfigEventManager(EventManager): def __init__(self, config, rule_file, unit_names): if os.path.exists('/tmp/supervisord_config.sock'): supervisor_serverurl = "unix:///tmp/supervisord_config.sock" else: supervisor_serverurl = "unix:///var/run/supervisord_config.sock" type_info = EventManagerTypeInfo(package_name = 'contrail-config', module_type = Module.CONFIG_NODE_MGR, object_table = 'ObjectConfigNode', supervisor_serverurl = supervisor_serverurl, third_party_processes = { "cassandra" : "Dcassandra-pidfile=.*cassandra\.pid", "zookeeper" : "org.apache.zookeeper.server.quorum.QuorumPeerMain" }, sandesh_packages = ['database.sandesh']) super(ConfigEventManager, self).__init__(config, type_info, rule_file, sandesh_global, unit_names) self.hostip = config.hostip self.db_port = config.db_port self.minimum_diskgb = config.minimum_diskgb self.contrail_databases = config.contrail_databases self.cassandra_repair_interval = config.cassandra_repair_interval self.cassandra_mgr = CassandraManager(config.cassandra_repair_logdir, 'configDb', self.contrail_databases, self.hostip, self.minimum_diskgb, self.db_port, self.process_info_manager) if self.cassandra_mgr.can_serve(): self.add_unit_name('contrail-database.service') # end __init__ def get_failbits_nodespecific_desc(self, fail_status_bits): description = "" if fail_status_bits & self.FAIL_STATUS_DISK_SPACE: description += "Disk for config db is too low," + \ " cassandra stopped." if fail_status_bits & self.FAIL_STATUS_SERVER_PORT: if description != "": description += " " description += "Cassandra state detected DOWN." if fail_status_bits & self.FAIL_STATUS_DISK_SPACE_NA: description += "Disk space for config db not retrievable." return description def do_periodic_events(self): if self.cassandra_mgr.can_serve(): self.cassandra_mgr.database_periodic(self) # Perform nodetool repair every cassandra_repair_interval hours if self.tick_count % (60 * self.cassandra_repair_interval) == 0: self.cassandra_mgr.repair() self.event_tick_60() # end do_periodic_events def process(self): if self.cassandra_mgr.can_serve(): self.cassandra_mgr.process(self)
class ConfigEventManager(EventManager): def __init__(self, config, rule_file, unit_names): if os.path.exists('/tmp/supervisord_config.sock'): supervisor_serverurl = "unix:///tmp/supervisord_config.sock" else: supervisor_serverurl = "unix:///var/run/supervisord_config.sock" self.db = package_installed('contrail-openstack-database') self.config_db = package_installed('contrail-database-common') if not self.db and self.config_db: unit_names.append('contrail-database.service') type_info = EventManagerTypeInfo(package_name = 'contrail-config', module_type = Module.CONFIG_NODE_MGR, object_table = 'ObjectConfigNode', supervisor_serverurl = supervisor_serverurl, third_party_processes = { "cassandra" : "Dcassandra-pidfile=.*cassandra\.pid", "zookeeper" : "org.apache.zookeeper.server.quorum.QuorumPeerMain" }, sandesh_packages = ['database.sandesh'], unit_names = unit_names) super(ConfigEventManager, self).__init__(config, type_info, rule_file, sandesh_global) self.hostip = config.hostip self.db_port = config.db_port self.minimum_diskgb = config.minimum_diskgb self.contrail_databases = config.contrail_databases self.cassandra_repair_interval = config.cassandra_repair_interval self.cassandra_repair_logdir = config.cassandra_repair_logdir self.cassandra_mgr = CassandraManager(self.cassandra_repair_logdir, 'configDb', self.contrail_databases, self.hostip, self.minimum_diskgb, self.db_port) # end __init__ def get_failbits_nodespecific_desc(self, fail_status_bits): description = "" if fail_status_bits & self.FAIL_STATUS_DISK_SPACE: description += "Disk for config db is too low," + \ " cassandra stopped." if fail_status_bits & self.FAIL_STATUS_SERVER_PORT: if description != "": description += " " description += "Cassandra state detected DOWN." if fail_status_bits & self.FAIL_STATUS_DISK_SPACE_NA: description += "Disk space for config db not retrievable." return description def do_periodic_events(self): if not self.db and self.config_db: self.cassandra_mgr.database_periodic(self) # Perform nodetool repair every cassandra_repair_interval hours if self.tick_count % (60 * self.cassandra_repair_interval) == 0: self.cassandra_mgr.repair() self.event_tick_60() # end do_periodic_events def process(self): if not self.db and self.config_db: self.cassandra_mgr.process(self)
class DatabaseEventManager(EventManager): def __init__(self, rule_file, discovery_server, discovery_port, collector_addr, hostip, db_port, minimum_diskgb, contrail_databases, cassandra_repair_interval, cassandra_repair_logdir, **dss_kwargs): self.node_type = "contrail-database" self.uve_node_type = UVENodeTypeNames[NodeType.DATABASE] self.table = "ObjectDatabaseInfo" self.module = Module.DATABASE_NODE_MGR self.module_id = ModuleNames[self.module] self.hostip = hostip self.db_port = db_port self.minimum_diskgb = minimum_diskgb self.contrail_databases = contrail_databases self.cassandra_repair_interval = cassandra_repair_interval self.cassandra_repair_logdir = cassandra_repair_logdir self.cassandra_mgr = CassandraManager(self.cassandra_repair_logdir, 'analyticsDb', self.table, self.contrail_databases, self.hostip, self.minimum_diskgb, self.db_port) if os.path.exists('/tmp/supervisord_database.sock'): self.supervisor_serverurl = "unix:///tmp/supervisord_database.sock" else: self.supervisor_serverurl = "unix:///var/run/supervisord_database.sock" self.add_current_process() node_type = Module2NodeType[self.module] node_type_name = NodeTypeNames[node_type] self.sandesh_global = sandesh_global EventManager.__init__( self, rule_file, discovery_server, discovery_port, collector_addr, sandesh_global, **dss_kwargs) self.sandesh_global = sandesh_global if self.rule_file is '': self.rule_file = "/etc/contrail/" + \ "supervisord_database_files/contrail-database.rules" json_file = open(self.rule_file) self.rules_data = json.load(json_file) _disc = self.get_discovery_client() sandesh_global.init_generator( self.module_id, socket.gethostname(), node_type_name, self.instance_id, self.collector_addr, self.module_id, 8103, ['database.sandesh', 'nodemgr.common.sandesh'], _disc) sandesh_global.set_logging_params(enable_local_log=True) ConnectionState.init(sandesh_global, socket.gethostname(), self.module_id, self.instance_id, staticmethod(ConnectionState.get_conn_state_cb), NodeStatusUVE, NodeStatus, self.table, self.get_process_state_cb) self.send_init_info() self.third_party_process_dict = {} self.third_party_process_dict["cassandra"] = "Dcassandra-pidfile=.*cassandra\.pid" self.third_party_process_dict["zookeeper"] = "org.apache.zookeeper.server.quorum.QuorumPeerMain" # end __init__ def _get_cassandra_config_option(self, config): (linux_dist, x, y) = platform.linux_distribution() if (linux_dist in ['Ubuntu', 'debian']): yamlstream = open("/etc/cassandra/cassandra.yaml", 'r') else: yamlstream = open("/etc/cassandra/conf/cassandra.yaml", 'r') cfg = yaml.safe_load(yamlstream) yamlstream.close() return cfg[config] def msg_log(self, msg, level): self.sandesh_global.logger().log(SandeshLogger.get_py_logger_level( level), msg) def send_process_state_db(self, group_names): self.send_process_state_db_base( group_names, ProcessInfo) def send_nodemgr_process_status(self): self.send_nodemgr_process_status_base( ProcessStateNames, ProcessState, ProcessStatus) def get_node_third_party_process_dict(self): return self.third_party_process_dict def get_process_state(self, fail_status_bits): return self.get_process_state_base( fail_status_bits, ProcessStateNames, ProcessState) def get_failbits_nodespecific_desc(self, fail_status_bits): description = "" if fail_status_bits & self.FAIL_STATUS_DISK_SPACE: description += "Disk for analytics db is too low," + \ " cassandra stopped." if fail_status_bits & self.FAIL_STATUS_SERVER_PORT: if description != "": description += " " description += "Cassandra state detected DOWN." if fail_status_bits & self.FAIL_STATUS_DISK_SPACE_NA: description += "Disk space for analytics db not retrievable." return description def runforever(self, test=False): self.prev_current_time = int(time.time()) # Initialize tpstat structures self.cassandra_status_old = CassandraStatusData() self.cassandra_status_old.cassandra_compaction_task = CassandraCompactionTask() self.cassandra_status_old.thread_pool_stats = [] while 1: # we explicitly use self.stdin, self.stdout, and self.stderr # instead of sys.* so we can unit test this code headers, payload = self.listener_nodemgr.wait( self.stdin, self.stdout) # self.stderr.write("headers:\n" + str(headers) + '\n') # self.stderr.write("payload:\n" + str(payload) + '\n') pheaders, pdata = childutils.eventdata(payload + '\n') # self.stderr.write("pheaders:\n" + str(pheaders)+'\n') # self.stderr.write("pdata:\n" + str(pdata)) # check for process state change events if headers['eventname'].startswith("PROCESS_STATE"): self.event_process_state(pheaders, headers) # check for flag value change events if headers['eventname'].startswith("PROCESS_COMMUNICATION"): self.event_process_communication(pdata) # do periodic events if headers['eventname'].startswith("TICK_60"): self.cassandra_mgr.database_periodic(self) self.event_tick_60() self.listener_nodemgr.ok(self.stdout) def get_package_name(self): return self.node_type def process(self): self.cassandra_mgr.process(self)