Exemplo n.º 1
0
    def delete(self, current=None):
        self.assert_write()
        self.close()
        dc = omero.cmd.Delete2(
            targetObjects={"OriginalFile": [self.file_obj.id.val]}
        )
        handle = self.factory.submit(dc)
        # Copied from clients.py since none is available
        try:
            callback = omero.callbacks.CmdCallbackI(
                current.adapter, handle, "Fake")
        except:
            # Since the callback won't escape this method,
            # close the handle if requested.
            handle.close()
            raise

        try:
            callback.loop(20, 500)
        except LockTimeout:
            callback.close(True)
            raise omero.InternalException(None, None, "delete timed-out")

        rsp = callback.getResponse()
        if isinstance(rsp, omero.cmd.ERR):
            raise omero.InternalException(None, None, str(rsp))

        self.file_obj = None
Exemplo n.º 2
0
def as_stdout(path, readers="", extra_args=None):
    """Returns the import candidates for the given path.

    you can pass more arguments to the `import` command through the
    extra_args argument in the form of a list.

    ..code ::

    >>> as_stdout("/my/dir/with_tifs", extra_args=["--depth", "6"])

    """
    if extra_args is None:
        extra_args = []
    path = _to_list(path)
    readers = str(readers)
    cli = CLI()
    cli.loadplugins()
    if readers:
        cli.invoke(["import", "-l"] + [
            readers,
        ] + extra_args + ["-f"] + path)
    else:
        cli.invoke(["import"] + extra_args + ["-f"] + path)
    if cli.rv != 0:
        raise omero.InternalException(
            None, None, "'import -f' exited with a rc=%s. "
            "See console for more information" % cli.rv)
Exemplo n.º 3
0
 def alreadyDone(self):
     """
     Allows short-cutting various checks if we already
     have a rcode for this popen. A non-None return value
     implies that a process was started and returned
     the given non-None value itself.
     """
     if not self.wasActivated:
         raise omero.InternalException(None, None,
                                       "Process never activated")
     return self.isFinished()
Exemplo n.º 4
0
 def delete(self, current = None):
     self.assert_write()
     self.close()
     prx = self.factory.getDeleteService()
     dc = omero.api.delete.DeleteCommand("/OriginalFile", self.file_obj.id.val, None)
     handle = prx.queueDelete([dc])
     self.file_obj = None
     # TODO: possible just return handle?
     cb = omero.callbacks.DeleteCallbackI(current.adapter, handle)
     count = 10
     while count:
         count -= 1
         rv = cb.block(500)
         if rv is not None:
             report = handle.report()[0]
             if rv > 0:
                 raise omero.InternalException(None, None, report.error)
             else:
                 return
     raise omero.InternalException(None, None, "delete timed-out")
Exemplo n.º 5
0
def as_stdout(path, readers=""):
    path = _to_list(path)
    readers = str(readers)
    cli = CLI()
    cli.loadplugins()
    if readers:
        cli.invoke(["import", "-l", readers, "-f"] + path)
    else:
        cli.invoke(["import", "-f"] + path)
    if cli.rv != 0:
        raise omero.InternalException(
            None, None, "'import -f' exited with a rc=%s. "
            "See console for more information" % cli.rv)
Exemplo n.º 6
0
 def exc_handler(*args, **kwargs):
     try:
         self = args[0]
         log.info(" Meth: %s.%s", self.__class__.__name__, func.func_name)
         rv = func(*args, **kwargs)
         log.info(__RESULT, rv)
         return rv
     except exceptions.Exception, e:
         log.info(__EXCEPT, e)
         if isinstance(e, omero.ServerError):
             raise
         else:
             log.warn("%s raised a non-ServerError (%s): %s", func, type(e), e)
             msg = traceback.format_exc()
             raise omero.InternalException(msg, None, "Internal exception")
Exemplo n.º 7
0
    def getSession(self, recreate=True):
        """
        Returns the ServiceFactoryPrx configured for the context if
        available. If the context was not configured for sessions,
        an ApiUsageException will be thrown: servants should know
        whether or not they were configured for sessions.
        See Servant(..., needs_session = True)

        Otherwise, if there is no ServiceFactoryPrx, an attempt will
        be made to create one if recreate == True. If the value is None
        or non can be recreated, an InternalException will be thrown.

        TODO : currently no arguments are provided for re-creating these,
        but also not in Servant.__init__
        """
        if not self.hasSession():
            raise omero.ApiUsageException(
                "Not configured for server connection")

        if self.session:
            try:
                self.session.keepAlive(None)
            except Ice.CommunicatorDestroyedException:
                self.session = None  # Ignore
            except Exception as e:
                self.logger.warn("Connection failure: %s" % e)
                self.session = None

        if self.session is None and recreate:
            try:
                self.newSession()
                self.logger.info("Established connection: %s" % self.session)
            except Exception as e:
                self.logger.warn("Failed to establish connection: %s" % e)

        if self.session is None:
            raise omero.InternalException("No connection to server")

        return self.session
Exemplo n.º 8
0
                self.session.keepAlive(None)
            except Ice.CommunicatorDestroyedException:
                self.session = None # Ignore
            except exceptions.Exception, e:
                self.logger.warn("Connection failure: %s" % e)
                self.session = None

        if self.session is None and recreate:
            try:
                self.newSession()
                self.logger.info("Established connection: %s" % self.session)
            except exceptions.Exception, e:
                self.logger.warn("Failed to establish connection: %s" % e)

        if self.session is None:
            raise omero.InternalException("No connection to server")

        return self.session

    def check(self):
        """
        Calls getSession() but always returns True. This keeps the context
        available in the resources for later uses, and tries to re-establish
        a connection in case Blitz goes down.
        """
        try:
            self.getSession()
        except:
            pass
        return True
Exemplo n.º 9
0
    def process(self,
                client,
                session,
                job,
                current,
                params,
                properties=None,
                iskill=True):
        """
        session: session uuid, used primarily if client is None
        client: an omero.client object which should be attached to a session
        """

        if properties is None:
            properties = {}

        if not session or not job or not job.id:
            raise omero.ApiUsageException("No null arguments")

        file, handle = self.lookup(job)

        try:
            if not file:
                raise omero.ApiUsageException(
                    None, None,
                    "Job should have one executable file attached.")

            sf = self.internal_session()
            if params:
                self.logger.debug("Checking params for job %s" % job.id.val)
                svc = sf.getSessionService()
                inputs = svc.getInputs(session)
                errors = omero.scripts.validate_inputs(params, inputs, svc,
                                                       session)
                if errors:
                    errors = "Invalid parameters:\n%s" % errors
                    raise omero.ValidationException(None, None, errors)

            properties["omero.job"] = str(job.id.val)
            properties["omero.user"] = session
            properties["omero.pass"] = session
            properties["Ice.Default.Router"] = \
                client.getProperty("Ice.Default.Router")

            launcher, ProcessClass = self.find_launcher(current)
            process = ProcessClass(self.ctx,
                                   launcher,
                                   properties,
                                   params,
                                   iskill,
                                   omero_home=self.omero_home)
            self.resources.add(process)

            # client.download(file, str(process.script_path))
            scriptText = sf.getScriptService().getScriptText(file.id.val)
            process.script_path.write_bytes(scriptText)

            self.logger.info("Downloaded file: %s" % file.id.val)
            s = client.sha1(str(process.script_path))
            if not s == file.hash.val:
                msg = "Sha1s don't match! expected %s, found %s" \
                    % (file.hash.val, s)
                self.logger.error(msg)
                process.cleanup()
                raise omero.InternalException(None, None, msg)
            else:
                process.activate()
                handle.setStatus("Running")

            id = None
            if self.category:
                id = Ice.Identity()
                id.name = "Process-%s" % uuid.uuid4()
                id.category = self.category
            prx = self.ctx.add_servant(current, process, ice_identity=id)
            return omero.grid.ProcessPrx.uncheckedCast(prx), process

        finally:
            handle.close()