Esempio n. 1
0
 def setUUID(self, uuid):
     node = self.nm.getByUUID(uuid)
     if node is not self._node:
         if node:
             node.setUUID(None)
             if node.isConnected(True):
                 node.getConnection().close()
         self._node.setUUID(uuid)
     logging.node(self.name, uuid)
Esempio n. 2
0
    def __init__(self, config):
        super(Application, self).__init__(config.get('ssl'),
                                          config.get('dynamic_master_list'))
        self.tm = TransactionManager(self.onTransactionCommitted)

        self.name = config['cluster']
        self.server = config['bind']
        self.autostart = config.get('autostart')

        self.storage_ready_dict = {}
        self.storage_starting_set = set()
        for master_address in config['masters']:
            self.nm.createMaster(address=master_address)
        self._node = self.nm.createMaster(address=self.server,
                                          uuid=config.get('nid'))
        logging.node(self.name, self.uuid)

        logging.debug('IP address is %s, port is %d', *self.server)

        # Partition table
        replicas = config['replicas']
        partitions = config['partitions']
        if replicas < 0:
            sys.exit('replicas must be a positive integer')
        if partitions <= 0:
            sys.exit('partitions must be more than zero')
        logging.info('Configuration:')
        logging.info('Partitions: %d', partitions)
        logging.info('Replicas  : %d', replicas)
        logging.info('Name      : %s', self.name)
        self.newPartitionTable = partial(PartitionTable, partitions, replicas)

        self.listening_conn = None
        self.cluster_state = None
        self._current_manager = None

        # backup
        upstream_cluster = config.get('upstream_cluster')
        if upstream_cluster:
            if upstream_cluster == self.name:
                raise ValueError("upstream cluster name must be"
                                 " different from cluster name")
            self.backup_app = BackupApplication(self, upstream_cluster,
                                                config['upstream_masters'])

        self.administration_handler = administration.AdministrationHandler(
            self)
        self.election_handler = master.ElectionHandler(self)
        self.secondary_handler = master.SecondaryHandler(self)
        self.client_service_handler = client.ClientServiceHandler(self)
        self.client_ro_service_handler = client.ClientReadOnlyServiceHandler(
            self)
        self.storage_service_handler = storage.StorageServiceHandler(self)

        registerLiveDebugger(on_log=self.log)
Esempio n. 3
0
    def __init__(self, config):
        super(Application, self).__init__(
            config.get('ssl'), config.get('dynamic_master_list'))
        # set the cluster name
        self.name = config['cluster']

        self.dm = buildDatabaseManager(config['adapter'],
            (config['database'], config.get('engine'), config['wait']),
        )
        self.disable_drop_partitions = config.get('disable_drop_partitions',
                                                  False)

        # load master nodes
        for master_address in config['masters']:
            self.nm.createMaster(address=master_address)

        # set the bind address
        self.server = config['bind']
        logging.debug('IP address is %s, port is %d', *self.server)

        # The partition table is initialized after getting the number of
        # partitions.
        self.pt = None

        self.listening_conn = None
        self.master_conn = None
        self.master_node = None

        # operation related data
        self.operational = False

        self.dm.setup(reset=config.get('reset', False),
                      dedup=config.get('dedup', False))
        self.loadConfiguration()
        self.devpath = self.dm.getTopologyPath()

        if config.get('new_nid'):
            self.new_nid = [x[0] for x in self.dm.iterAssignedCells()]
            if not self.new_nid:
                sys.exit('database is empty')
            self.uuid = None
        else:
            self.new_nid = ()
            if 'nid' in config: # for testing purpose only
                self.uuid = config['nid']
                logging.node(self.name, self.uuid)

        registerLiveDebugger(on_log=self.log)
Esempio n. 4
0
    def __init__(self, config):
        BaseApplication.__init__(self, config.get('ssl'),
                                 config.get('dynamic_master_list'))
        for address in config['masters']:
            self.nm.createMaster(address=address)

        self.name = config['cluster']
        self.server = config['bind']

        self.backup_dict = backup_dict = {}
        max_lag = config.get('monitor_maxlag', Backup.max_lag)
        for x in config.get('monitor_backup', ()):
            backup_dict[x] = x = Backup()
            x.max_lag = max_lag
        self.email_list = config.get('monitor_email', ())
        if self.email_list:
            self.smtp_host = config.get('smtp') or 'localhost'
            self.smtp_tls = config.get('smtp_tls')
            if 'smtp_auth' in config:
                user, pwd = config['smtp_auth'].split(':', 1)
                self.smtp_login = user, pwd
            else:
                self.smtp_login = None
            email_from = os.getenv('EMAIL')
            if not email_from:
                try:
                    email_from = getpass.getuser()
                except Exception:
                    email_from = None
            self.email_from = formataddr(("NEO " + self.name, email_from))
        self.smtp_exc = None
        self.smtp_retry = INF
        self.notifying = set()

        logging.debug('IP address is %s, port is %d', *self.server)

        # The partition table is initialized after getting the number of
        # partitions.
        self.pt = None
        self.uuid = config.get('nid')
        logging.node(self.name, self.uuid)
        self.backup_handler = BackupHandler(self)
        self.master_event_handler = MasterEventHandler(self)
        self.upstream_admin_handler = UpstreamAdminHandler(self)
        self.cluster_state = None
        self.upstream_admin = self.upstream_admin_conn = None
        self.reset()
        registerLiveDebugger(on_log=self.log)
Esempio n. 5
0
    def loadConfiguration(self):
        """Load persistent configuration data from the database.
        If data is not present, generate it."""

        dm = self.dm

        # check cluster name
        name = dm.getName()
        if name is None:
            dm.setName(self.name)
        elif name != self.name:
            raise RuntimeError('name %r does not match with the database: %r'
                               % (self.name, name))

        # load configuration
        self.uuid = dm.getUUID()
        logging.node(self.name, self.uuid)

        logging.info('Configuration loaded:')
        logging.info('PTID      : %s', dump(dm.getPTID()))
        logging.info('Name      : %s', self.name)