Beispiel #1
0
    def _fetchNurseryConfig(self):
        (routing, cfgs) = self._keeperClient.getNurseryConfig()
        self._routing = routing
        logging.debug("Nursery client has routing: %s" % str(routing))
        for (clusterId, client) in self._clusterClients.iteritems():
            client.dropConnections()

        self._clusterClients = dict()
        logging.debug("Nursery contains %d clusters", len(cfgs))
        for (clusterId, cfg) in cfgs.iteritems():
            client = ArakoonClient(cfg)
            logging.debug("Adding client for cluster %s" % clusterId)
            self._clusterClients[clusterId] = client
Beispiel #2
0
 def __init__(self, clientConfig):
     self.nurseryClusterId = clientConfig.getClusterId()
     self._keeperClient = ArakoonClient(clientConfig)
     self._clusterClients = dict()
     self._fetchNurseryConfig()
Beispiel #3
0
class NurseryClient:
    def __init__(self, clientConfig):
        self.nurseryClusterId = clientConfig.getClusterId()
        self._keeperClient = ArakoonClient(clientConfig)
        self._clusterClients = dict()
        self._fetchNurseryConfig()

    def _fetchNurseryConfig(self):
        (routing, cfgs) = self._keeperClient.getNurseryConfig()
        self._routing = routing
        logging.debug("Nursery client has routing: %s" % str(routing))
        for (clusterId, client) in self._clusterClients.iteritems():
            client.dropConnections()

        self._clusterClients = dict()
        logging.debug("Nursery contains %d clusters", len(cfgs))
        for (clusterId, cfg) in cfgs.iteritems():
            client = ArakoonClient(cfg)
            logging.debug("Adding client for cluster %s" % clusterId)
            self._clusterClients[clusterId] = client

    def _getArakoonClient(self, key):
        clusterId = self._routing.getClusterId(key)
        logging.debug("Key %s goes to cluster %s" % (key, clusterId))
        if not self._clusterClients.has_key(clusterId):
            raise NurseryInvalidConfig()
        return self._clusterClients[clusterId]

    @retryDuringMigration
    def set(self, key, value):
        """
        Update the value associated with the given key.

        If the key does not yet have a value associated with it, a new key value pair will be created.
        If the key does have a value associated with it, it is overwritten.
        For conditional value updates see L{testAndSet}

        @type key: string
        @type value: string
        @param key: The key whose associated value you want to update
        @param value: The value you want to store with the associated key

        @rtype: void
        """
        client = self._getArakoonClient(key)
        client.set(key, value)

    @retryDuringMigration
    def get(self, key):
        """
        Retrieve a single value from the nursery.

        @type key: string
        @param key: The key you are interested in
        @rtype: string
        @return: The value associated with the given key
        """

        client = self._getArakoonClient(key)
        return client.get(key)

    @retryDuringMigration
    def delete(self, key):
        """
        Remove a key-value pair from the nursery.

        @type key: string
        @param key: Remove this key and its associated value from the nursery

        @rtype: void
        """
        client = self._getArakoonClient(key)
        client.delete(key)
Beispiel #4
0
 def __init__(self, clientConfig):
     self.nurseryClusterId = clientConfig.getClusterId()
     self._keeperClient = ArakoonClient(clientConfig)
     self._clusterClients = dict()
     self._fetchNurseryConfig()
Beispiel #5
0
class NurseryClient:
    def __init__(self, clientConfig):
        self.nurseryClusterId = clientConfig.getClusterId()
        self._keeperClient = ArakoonClient(clientConfig)
        self._clusterClients = dict()
        self._fetchNurseryConfig()

    def _fetchNurseryConfig(self):
        (routing, cfgs) = self._keeperClient.getNurseryConfig()
        self._routing = routing
        logging.debug("Nursery client has routing: %s" % str(routing))
        for (clusterId, client) in self._clusterClients.iteritems():
            client.dropConnections()

        self._clusterClients = dict()
        logging.debug("Nursery contains %d clusters", len(cfgs))
        for (clusterId, cfg) in cfgs.iteritems():
            client = ArakoonClient(cfg)
            logging.debug("Adding client for cluster %s" % clusterId)
            self._clusterClients[clusterId] = client

    def _getArakoonClient(self, key):
        clusterId = self._routing.getClusterId(key)
        logging.debug("Key %s goes to cluster %s" % (key, clusterId))
        if not self._clusterClients.has_key(clusterId):
            raise NurseryInvalidConfig()
        return self._clusterClients[clusterId]

    @retryDuringMigration
    def set(self, key, value):
        """
        Update the value associated with the given key.

        If the key does not yet have a value associated with it, a new key value pair will be created.
        If the key does have a value associated with it, it is overwritten.
        For conditional value updates see L{testAndSet}

        @type key: string
        @type value: string
        @param key: The key whose associated value you want to update
        @param value: The value you want to store with the associated key

        @rtype: void
        """
        client = self._getArakoonClient(key)
        client.set(key, value)

    @retryDuringMigration
    def get(self, key):
        """
        Retrieve a single value from the nursery.

        @type key: string
        @param key: The key you are interested in
        @rtype: string
        @return: The value associated with the given key
        """

        client = self._getArakoonClient(key)
        return client.get(key)

    @retryDuringMigration
    def delete(self, key):
        """
        Remove a key-value pair from the nursery.

        @type key: string
        @param key: Remove this key and its associated value from the nursery

        @rtype: void
        """
        client = self._getArakoonClient(key)
        client.delete(key)