Exemplo n.º 1
0
 def delete_replica_node(self, app_id, node_id, actor_name, cb=None):
     """
     Delete node_id from the list of replica nodes
     """
     name = calvinuuid.remove_uuid(actor_name)
     _log.debug("Deleting node {} from app {} replica nodes of actor {}".format(node_id, app_id, name))
     self.remove("replica-nodes-", key=app_id + ":" + name, value=[node_id], cb=cb)
Exemplo n.º 2
0
    def add_actor(self, actor, node_id, app_id, cb=None):
        """
        Add actor and its ports to storage
        """
        _log.debug("Add actor %s id %s" % (actor, node_id))

        data = {"name": actor.name, "type": actor._type, "master_nodes": actor.master_nodes, "node_id": node_id, 'app_id': app_id, 'replicate': actor.replicate}

        inports = []
        for p in actor.inports.values():
            port = {"id": p.id, "name": p.name}
            inports.append(port)
            self.add_port(p, node_id, actor.id, "in")
        data["inports"] = inports
        outports = []

        for p in actor.outports.values():
            port = {"id": p.id, "name": p.name}
            outports.append(port)
            self.add_port(p, node_id, actor.id, "out")
        data["outports"] = outports
        data["is_shadow"] = isinstance(actor, ShadowActor)

        if app_id:
            cb = CalvinCB(self.add_actor_to_app, app_id=app_id, actor_id=actor.id, cb=cb)
            name = calvinuuid.remove_uuid(actor.name)
            if node_id:
                cb = CalvinCB(self.add_replica_nodes, app_id=app_id, name=name, node_id=node_id, cb=cb)
                cb = CalvinCB(self.add_node_actor, node_id=node_id, actor_id=actor.id, cb=cb)
            else:
                _log.warning("Tried to add None to replica nodes of app {} actor {}".format(app_id, name))

        self.set(prefix="actor-", key=actor.id, value=data, cb=cb)
        self.trigger_flush()
Exemplo n.º 3
0
    def replication_args(self):
        """Returns args with a name with a random postfix based.

        The name must not contain '-', this will break the web interface
        """
        args = self._get_managed()

        args['name'] = calvinuuid.remove_uuid(self.name) + calvinuuid.uuid("REPLICA")
        args['id'] = calvinuuid.uuid("ACTOR")

        return args
Exemplo n.º 4
0
    def new_replica(self, actor_type, args, state, prev_connections, app_id, callback):
        """Creates a new replica"""
        _log.debug("Creating new replica of type {}, with args {}, prev_connections {}".format(
            actor_type, args, prev_connections))

        state['id'] = args.pop('id')
        state['name'] = args.pop('name')
        state['set_ports'] = False
        _log.debug("New replica with prev connections: {}".format(prev_connections))

        replica_name = calvinuuid.remove_uuid(state['name'])
        for a in self.actors.values():
            if replica_name == calvinuuid.remove_uuid(a.name) and app_id == a.app_id:
                _log.warning("We have replica {} already, aborting replica request".format(replica_name))
                if callback:
                    callback(status=response.CalvinResponse(False, data={'actor_id': None}))
                return

        callback = CalvinCB(self._after_new_replica, state=state, prev_connections=prev_connections, callback=callback)
        self._new(actor_type, args, state, app_id=app_id, master_nodes=state['master_nodes'], callback=callback)
Exemplo n.º 5
0
    def _check_actor_reliability(self, key, value, actors, app_info, names, index, start_time):
        _log.debug("Check reliability for actor: {}".format(key))
        if not value:
            _log.warning("Failed to get actor info from storage: {}".format(key))
            return self._check_actors_reliability(actors=actors, app_info=app_info, names=names, index=index + 1, start_time=start_time)

        name = calvinuuid.remove_uuid(value['name'])
        if value["replicate"] and name not in names:
            try:
                replicator = Replicator(self.node, key, value, app_info['required_reliability'], do_delete=False)
            except Exception as e:
                _log.warning("Failed to create replicator: {}".format(e))
                return
            names.append(name)
            cb = CalvinCB(self._check_actors_reliability, actors=actors, app_info=app_info, names=names, index=index + 1, start_time=start_time)
            replicator.replicate_lost_actor(cb=cb, start_time=start_time)
        else:
            if name in names:
                _log.debug("Already checked reliability of actor: {}".format(name))
            self._check_actors_reliability(actors=actors, app_info=app_info, names=names, index=index + 1, start_time=start_time)
Exemplo n.º 6
0
 def _is_match(self, first, second):
     is_match = calvinuuid.remove_uuid(first) == calvinuuid.remove_uuid(second)
     _log.debug("{} and {} is match: {}".format(first, second, is_match))
     return is_match
Exemplo n.º 7
0
 def get_replica_nodes(self, app_id, actor_name, cb=None):
     """
     Get the nodes for where there exists replicas of the actor actor_name in the app app_id
     """
     return self.get_concat(prefix="replica-nodes-", key=app_id + ":" + calvinuuid.remove_uuid(actor_name), cb=cb)