Esempio n. 1
0
 def locate(host, port=None):
     """Simple class to easily contact an Manager
     """
     p = Proxy(uri=getManagerURI(host, port or MANAGER_DEFAULT_PORT))
     if not p.ping():
         raise ManagerNotFoundException("Couldn't find manager running on %s:%d" % (host, port))
     return p
Esempio n. 2
0
 def locate(host, port=None):
     """Simple class to easily contact an Manager
     """
     p = Proxy(uri=getManagerURI(host, port or MANAGER_DEFAULT_PORT))
     if not p.ping():
         raise ManagerNotFoundException(
             "Couldn't find manager running on %s:%d" % (host, port))
     return p
Esempio n. 3
0
    def getProxy (self, location, name='0', host=None, port=None, lazy=False):
        """
        Get a proxy for the object pointed by location. The given location can contain index
        instead of names, e.g. '/Object/0' to get objects when you don't know their names.

        location can also be a class. getProxy will return an instance
        named 'name' at the given host/port (or on the current
        manager, if None given).

        host and port parameters determines which Manager we will
        lookup for location/instance. If None, look at this
        Manager. host/port is only used when location is a
        class, otherwise, host and port are determined by location
        itself.

        lazy parameter determines if Manager will try to locate the
        selected Manager at host/port and ask them for a valid
        object/instance. If False, Manager just return an proxy for
        the selected parameters but can't guarantee that the returned
        Proxy have an active object bounded.

        For objects managed by this own Manager, lazy is always False.

        @param location: Object location or class.
        @type location: Location or class

        @param name: Instance name.
        @type name: str

        @param host: Manager's hostname.
        @type host: str

        @param port: Manager's port.
        @type port: int

        @param lazy: Manager's laziness (check for already bound objects on host/port Manager)
        @type lazy: bool

        @raises NotValidChimeraObjectException: When a object which doesn't inherites from ChimeraObject is given in location.
        @raises ObjectNotFoundException: When te request object or the Manager was not found.
        @raises InvalidLocationException: When the requested location s invalid.

        @return: Proxy for selected object.
        @rtype: Proxy
        """

        if not location:
            raise ObjectNotFoundException ("Couldn't find an object at the"
                                           " given location %s" % location)

        if not isinstance(location, StringType) and not isinstance(location, Location):

            if issubclass(location, ChimeraObject):
                location = Location(cls=location.__name__, name=name, host=host or self.getHostname(), port=port or self.getPort())
            else:
                raise NotValidChimeraObjectException ("Can't get a proxy from non ChimeraObject's descendent object (%s)." % location)

        else:
            location = Location(location, host=host or self.getHostname(), port=port or self.getPort())

        # who manages this location?
        if self._belongsToMe(location):

            ret = self.resources.get(location)
            
            if not ret:
                raise ObjectNotFoundException ("Couldn't found an object at the"
                                               " given location %s" % location)
            p = Proxy (uri=ret.uri)
            if lazy:
                return p
            else:
                p.ping()
                return p
        else:

            if lazy:
                return Proxy(location)
            else:
                # contact other manager
                try:
                    other = Proxy(location=MANAGER_LOCATION,
                                  host=location.host or host,
                                  port=location.port or port)
                except Pyro.errors.URIError, e:
                    raise InvalidLocationException("Invalid remote location given. '%s' (%s)." % (location, str(e)))

                if not other.ping():
                    raise ObjectNotFoundException ("Can't contact %s manager at %s." % (location, other.URI.address))

                proxy = other.getProxy(location)

                if not proxy:
                    raise ObjectNotFoundException ("Couldn't find an object at the"
                                                   " given location %s" % location)
                else:
                    return proxy
Esempio n. 4
0
    def getProxy(self, location, name='0', host=None, port=None, lazy=False):
        """
        Get a proxy for the object pointed by location. The given location can contain index
        instead of names, e.g. '/Object/0' to get objects when you don't know their names.

        location can also be a class. getProxy will return an instance
        named 'name' at the given host/port (or on the current
        manager, if None given).

        host and port parameters determines which Manager we will
        lookup for location/instance. If None, look at this
        Manager. host/port is only used when location is a
        class, otherwise, host and port are determined by location
        itself.

        lazy parameter determines if Manager will try to locate the
        selected Manager at host/port and ask them for a valid
        object/instance. If False, Manager just return an proxy for
        the selected parameters but can't guarantee that the returned
        Proxy have an active object bounded.

        For objects managed by this own Manager, lazy is always False.

        @param location: Object location or class.
        @type location: Location or class

        @param name: Instance name.
        @type name: str

        @param host: Manager's hostname.
        @type host: str

        @param port: Manager's port.
        @type port: int

        @param lazy: Manager's laziness (check for already bound objects on host/port Manager)
        @type lazy: bool

        @raises NotValidChimeraObjectException: When a object which doesn't inherites from ChimeraObject is given in location.
        @raises ObjectNotFoundException: When te request object or the Manager was not found.
        @raises InvalidLocationException: When the requested location s invalid.

        @return: Proxy for selected object.
        @rtype: Proxy
        """

        if not location:
            raise ObjectNotFoundException("Couldn't find an object at the"
                                          " given location %s" % location)

        if not isinstance(location, StringType) and not isinstance(
                location, Location):

            if issubclass(location, ChimeraObject):
                location = Location(cls=location.__name__,
                                    name=name,
                                    host=host or self.getHostname(),
                                    port=port or self.getPort())
            else:
                raise NotValidChimeraObjectException(
                    "Can't get a proxy from non ChimeraObject's descendent object (%s)."
                    % location)

        else:
            location = Location(location,
                                host=host or self.getHostname(),
                                port=port or self.getPort())

        # who manages this location?
        if self._belongsToMe(location):

            ret = self.resources.get(location)

            if not ret:
                raise ObjectNotFoundException("Couldn't found an object at the"
                                              " given location %s" % location)
            p = Proxy(uri=ret.uri)
            if lazy:
                return p
            else:
                p.ping()
                return p
        else:

            if lazy:
                return Proxy(location)
            else:
                # contact other manager
                try:
                    other = Proxy(location=MANAGER_LOCATION,
                                  host=location.host or host,
                                  port=location.port or port)
                except Pyro.errors.URIError, e:
                    raise InvalidLocationException(
                        "Invalid remote location given. '%s' (%s)." %
                        (location, str(e)))

                if not other.ping():
                    raise ObjectNotFoundException(
                        "Can't contact %s manager at %s." %
                        (location, other.URI.address))

                proxy = other.getProxy(location)

                if not proxy:
                    raise ObjectNotFoundException(
                        "Couldn't find an object at the"
                        " given location %s" % location)
                else:
                    return proxy