Ejemplo n.º 1
0
    def _run(self):
        """Make sure that the status is sane and start a loop."""
        if len(self.name) == 0:
            raise RuntimeError, 'cluster name must be non-empty'

        # Make a listening port
        handler = identification.IdentificationHandler(self)
        self.listening_conn = ListeningConnection(self, handler, self.server)
        self.server = self.listening_conn.getAddress()

        # Connect to a primary master node, verify data, and
        # start the operation. This cycle will be executed permanently,
        # until the user explicitly requests a shutdown.
        self.operational = False
        while True:
            self.cluster_state = None
            if self.master_node is None:
                # look for the primary master
                self.connectToPrimary()
            self.checker = Checker(self)
            self.replicator = Replicator(self)
            self.tm = TransactionManager(self)
            try:
                self.initialize()
                self.doOperation()
                raise RuntimeError, 'should not reach here'
            except StoppedOperation, msg:
                logging.error('operation stopped: %s', msg)
            except PrimaryFailure, msg:
                logging.error('primary master is down: %s', msg)
Ejemplo n.º 2
0
 def getLoopbackConnection(self):
     app = MasterApplication(address=BIND,
         getSSL=NEOCluster.SSL, getReplicas=0, getPartitions=1)
     try:
         handler = EventHandler(app)
         app.listening_conn = ListeningConnection(app, handler, app.server)
         yield ClientConnection(app, handler, app.nm.createMaster(
             address=app.listening_conn.getAddress(), uuid=app.uuid))
     finally:
         app.close()
Ejemplo n.º 3
0
    def getLoopbackConnection(self):
        app = MasterApplication(getSSL=NEOCluster.SSL,
                                getReplicas=0,
                                getPartitions=1)
        handler = EventHandler(app)
        app.listening_conn = ListeningConnection(app, handler, app.server)
        node = app.nm.createMaster(address=app.listening_conn.getAddress(),
                                   uuid=app.uuid)
        conn = ClientConnection.__new__(ClientConnection)

        def reset():
            conn.__dict__.clear()
            conn.__init__(app, handler, node)
            conn.reset = reset

        reset()
        return conn
Ejemplo n.º 4
0
Archivo: app.py Proyecto: pyzh/neoppod
    def _run(self):
        """Make sure that the status is sane and start a loop."""
        if len(self.name) == 0:
            raise RuntimeError, 'cluster name must be non-empty'

        # Make a listening port.
        handler = AdminEventHandler(self)
        self.listening_conn = ListeningConnection(self, handler, self.server)

        while self.cluster_state != ClusterStates.STOPPING:
            self.connectToPrimary()
            try:
                while True:
                    self.em.poll(1)
            except PrimaryFailure:
                logging.error('primary master is down')
        self.listening_conn.close()
        while not self.em.isIdle():
            self.em.poll(1)
Ejemplo n.º 5
0
    def _run(self):
        """Make sure that the status is sane and start a loop."""
        # Make a listening port.
        self.listening_conn = ListeningConnection(self, None, self.server)

        # Start a normal operation.
        while self.cluster_state != ClusterStates.STOPPING:
            # (Re)elect a new primary master.
            self.primary = not self.nm.getMasterList()
            if not self.primary:
                self.electPrimary()
            try:
                if self.primary:
                    self.playPrimaryRole()
                else:
                    self.playSecondaryRole()
                raise RuntimeError, 'should not reach here'
            except (ElectionFailure, PrimaryFailure):
                # Forget all connections.
                for conn in self.em.getClientList():
                    conn.close()
Ejemplo n.º 6
0
 def _run(self):
     self.listening_conn = ListeningConnection(self, None, self.server)
     while True:
         self.playPrimaryRole()
         self.playSecondaryRole()