Exemplo n.º 1
0
    def doSubmit(self, request, client, test_should_pass=True):
        """
        Performs the request waits on completion and checks that the
        result is not an error.
        """
        sf = client.sf
        prx = sf.submit(request)

        assert not State.FAILURE in prx.getStatus().flags

        cb = CmdCallbackI(client, prx)
        cb.loop(20, 500)

        assert prx.getResponse() != None

        status = prx.getStatus()
        rsp = prx.getResponse()

        if test_should_pass:
            if isinstance(rsp, ERR):
                assert False,\
                    "Found ERR when test_should_pass==true: %s (%s) params=%s" %\
                    (rsp.category, rsp.name, rsp.parameters)
            assert not State.FAILURE in prx.getStatus().flags
        else:
            if isinstance(rsp, OK):
                assert False, "Found OK when test_should_pass==false: %s" % rsp
            assert State.FAILURE in prx.getStatus().flags

        return rsp
Exemplo n.º 2
0
def doChange(gateway, obj_type, obj_ids, group_id, container_id=None,
             test_should_pass=True, return_complete=True):
    """
    Performs the change-group action, waits on completion and checks that the
    result is not an error.
    """
    prx = gateway.chgrpObjects(obj_type, obj_ids, group_id, container_id)

    if not return_complete:
        return prx

    cb = CmdCallbackI(gateway.c, prx)
    try:
        for i in range(10):
            cb.loop(20, 500)
            if prx.getResponse() is not None:
                break

        assert prx.getResponse() is not None

        prx.getStatus()
        rsp = prx.getResponse()

        if test_should_pass:
            assert not isinstance(rsp, ERR), \
                "Found ERR when test_should_pass==true: %s (%s) params=%s" \
                % (rsp.category, rsp.name, rsp.parameters)
            assert State.FAILURE not in prx.getStatus().flags
        else:
            assert not isinstance(rsp, OK), \
                "Found OK when test_should_pass==false: %s" % rsp
            assert State.FAILURE in prx.getStatus().flags
        return rsp
    finally:
        cb.close(True)
Exemplo n.º 3
0
    def doSubmit(self, request, client, test_should_pass=True,
                 omero_group=None):
        """
        Performs the request waits on completion and checks that the
        result is not an error.
        """
        sf = client.sf
        if omero_group is not None:
            prx = sf.submit(request, {'omero.group': str(omero_group)})
        else:
            prx = sf.submit(request)

        assert State.FAILURE not in prx.getStatus().flags

        cb = CmdCallbackI(client, prx)
        cb.loop(20, 500)

        assert prx.getResponse() is not None

        rsp = prx.getResponse()

        if test_should_pass:
            if isinstance(rsp, ERR):
                assert False,\
                    "Found ERR when test_should_pass==true: %s (%s) params=%s" %\
                    (rsp.category, rsp.name, rsp.parameters)
            assert State.FAILURE not in prx.getStatus().flags
        else:
            if isinstance(rsp, OK):
                assert False, "Found OK when test_should_pass==false: %s" % rsp
            assert State.FAILURE in prx.getStatus().flags

        return rsp
Exemplo n.º 4
0
    def doSubmit(self, request, client, test_should_pass=True):
        """
        Performs the request waits on completion and checks that the
        result is not an error.
        """
        sf = client.sf
        prx = sf.submit(request)

        self.assertFalse(State.FAILURE in prx.getStatus().flags)

        cb = CmdCallbackI(client, prx)
        cb.loop(20, 500)

        self.assertNotEqual(prx.getResponse(), None)

        status = prx.getStatus()
        rsp = prx.getResponse()

        if test_should_pass:
            if isinstance(rsp, ERR):
                self.fail("Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters))
            self.assertFalse(State.FAILURE in prx.getStatus().flags)
        else:
            if isinstance(rsp, OK):
                self.fail("Found OK when test_should_pass==false: %s", rsp)
            self.assertTrue(State.FAILURE in prx.getStatus().flags)

        return rsp
Exemplo n.º 5
0
    def doChange(self, group_id, permissions, test_should_pass=True, return_complete=True):
        """
        Performs the chmod action, waits on completion and checks that the
        result is not an error.
        """
        prx = self.gateway.chmodGroup(group_id, permissions)
        if not return_complete:
            return prx

        cb = CmdCallbackI(self.gateway.c, prx)
        cb.loop(20, 500)    # This fails (see #8439). Can comment out this line and
        # try a different way of waiting for result - This never completes...
        import time
        rsp = prx.getResponse()
        i = 0
        while (rsp is None):
            time.sleep(10)
            rsp = prx.getResponse()
            i += 1
            print "rsp", i, rsp

        self.assertNotEqual(rsp, None)

        status = prx.getStatus()

        if test_should_pass:
            if isinstance(rsp, ERR):
                self.fail("Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters))
            self.assertFalse(State.FAILURE in prx.getStatus().flags)
        else:
            if isinstance(rsp, OK):
                self.fail("Found OK when test_should_pass==false: %s", rsp)
            self.assertTrue(State.FAILURE in prx.getStatus().flags)
        return rsp
Exemplo n.º 6
0
    def doSubmit(self, request, client, test_should_pass=True):
        """
        Performs the request waits on completion and checks that the
        result is not an error.
        """
        sf = client.sf
        prx = sf.submit(request)

        self.assertFalse(State.FAILURE in prx.getStatus().flags)

        cb = CmdCallbackI(client, prx)
        cb.loop(20, 500)

        self.assertNotEqual(prx.getResponse(), None)

        status = prx.getStatus()
        rsp = prx.getResponse()

        if test_should_pass:
            if isinstance(rsp, ERR):
                self.fail(
                    "Found ERR when test_should_pass==true: %s (%s) params=%s"
                    % (rsp.category, rsp.name, rsp.parameters))
            self.assertFalse(State.FAILURE in prx.getStatus().flags)
        else:
            if isinstance(rsp, OK):
                self.fail("Found OK when test_should_pass==false: %s", rsp)
            self.assertTrue(State.FAILURE in prx.getStatus().flags)

        return rsp
Exemplo n.º 7
0
    def doChange(self, obj_type, obj_id, group_id, test_should_pass=True, return_complete=True):
        """
        Performs the change-group action, waits on completion and checks that the 
        result is not an error.
        """
        prx = self.gateway.chgrpObject(obj_type, obj_id, group_id)
        
        if not return_complete:
            return prx
        
        cb = CmdCallbackI(self.gateway.c, prx)
        for i in range(10):
            cb.loop(20, 500)
            if prx.getResponse() != None:
                break

        self.assertNotEqual(prx.getResponse(), None)

        status = prx.getStatus()
        rsp = prx.getResponse()

        if test_should_pass:
            if isinstance(rsp, ERR):
                self.fail("Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters))
            self.assertFalse(State.FAILURE in prx.getStatus().flags)
        else:
            if isinstance(rsp, OK):
                self.fail("Found OK when test_should_pass==false: %s", rsp)
            self.assertTrue(State.FAILURE in prx.getStatus().flags)
        return rsp
Exemplo n.º 8
0
    def testChgrpImage(self):

        # Data Setup
        img = self.new_image()
        img = self.update.saveAndReturnObject(img)

        # New method
        chgrp = omero.cmd.Chgrp2(targetObjects={'Image': [img.id.val]})
        handle = self.sf.submit(chgrp)
        cb = CmdCallbackI(self.client, handle)
        cb.loop(20, 750)

        # Check Data
        self.query.get("Image", img.id.val)
Exemplo n.º 9
0
 def assertImport(self, client, proc, folder):
     hashes = self.upload_folder(proc, folder)
     handle = proc.verifyUpload(hashes)
     cb = CmdCallbackI(client, handle)
     rsp = self.assertPasses(cb)
     assert 1 ==  len(rsp.pixels)
     return rsp
Exemplo n.º 10
0
 def testImport(self):
     import time
     s1 = time.time()
     client = self.new_client()
     mrepo = self.get_managed_repo(client)
     folder = create_path(folder=True)
     for x in range(200):
         name = "%s.unknown" % x
         (folder / name).touch()
     paths = folder.files()
     proc = mrepo.importPaths(paths)
     hashes = self.upload_folder(proc, folder)
     handle = proc.verifyUpload(hashes)
     req = handle.getRequest()
     fs = req.activity.getParent()
     cb = CmdCallbackI(client, handle)
     self.assert_error(cb, loops=200)
     delete = omero.cmd.Delete2()
     delete.targetObjects = {'Fileset': [fs.id.val]}
     s2 = time.time()
     print s2 - s1,
     t1 = time.time()
     client.submit(delete, loops=200)
     t2 = time.time()
     print " ", t2 - t1,
Exemplo n.º 11
0
    def write_to_omero(self):
        to_delete = {"Annotation": self.mapannids + self.fileannids}
        delCmd = omero.cmd.Delete2(targetObjects=to_delete)
        handle = self.client.getSession().submit(delCmd)

        callback = None
        try:
            callback = CmdCallbackI(self.client, handle)
            loops = max(10, len(self.mapannids) / 10)
            delay = 500
            callback.loop(loops, delay)
            rsp = callback.getResponse()
            if isinstance(rsp, omero.cmd.OK):
                ndma = len(
                    rsp.deletedObjects.get(
                        "ome.model.annotations.MapAnnotation", []))
                log.info("Deleted %d MapAnnotation(s)", ndma)
                ndfa = len(
                    rsp.deletedObjects.get(
                        "ome.model.annotations.FileAnnotation", []))
                log.info("Deleted %d FileAnnotation(s)", ndfa)
            else:
                log.error("Delete failed: %s", rsp)
        finally:
            if callback:
                callback.close(True)
            else:
                handle.close()
Exemplo n.º 12
0
    def testChgrpImage(self):

        # One user in two groups
        client, exp = self.new_client_and_user()
        update = client.sf.getUpdateService()
        query = client.sf.getQueryService()

        # Data Setup
        img = self.new_image()
        img = update.saveAndReturnObject(img)

        # New method
        chgrp = omero.cmd.Chgrp(type="/Image", id=img.id.val, options=None)
        handle = client.sf.submit(chgrp)
        cb = CmdCallbackI(client, handle)
        cb.loop(20, 750)

        # Check Data
        query.get("Image", img.id.val)
Exemplo n.º 13
0
    def testChgrpImage(self):

        # One user in two groups
        client, exp = self.new_client_and_user()
        update = client.sf.getUpdateService()
        query = client.sf.getQueryService()

        # Data Setup
        img = self.new_image()
        img = update.saveAndReturnObject(img)

        # New method
        chgrp = omero.cmd.Chgrp(type="/Image", id=img.id.val, options=None)
        handle = client.sf.submit(chgrp)
        cb = CmdCallbackI(client, handle)
        cb.loop(20, 750)

        # Check Data
        query.get("Image", img.id.val)
Exemplo n.º 14
0
    def doSubmit(self,
                 request,
                 client,
                 test_should_pass=True,
                 omero_group=None):
        """
        Performs the request(s), waits on completion and checks that the
        result is not an error. The request can either be a single command
        or a list of commands. If the latter then the request list will be
        wrapped in a DoAll.
        """
        if isinstance(request, list):
            request = DoAll(request)

        sf = client.sf
        if omero_group is not None:
            prx = sf.submit(request, {'omero.group': str(omero_group)})
        else:
            prx = sf.submit(request)

        assert State.FAILURE not in prx.getStatus().flags

        cb = CmdCallbackI(client, prx)
        cb.loop(20, 500)

        assert prx.getResponse() is not None

        rsp = prx.getResponse()

        if test_should_pass:
            if isinstance(rsp, ERR):
                assert False, (
                    "Found ERR when test_should_pass==true: %s (%s) params=%s"
                    % (rsp.category, rsp.name, rsp.parameters))
            assert State.FAILURE not in prx.getStatus().flags
        else:
            if isinstance(rsp, OK):
                assert False, ("Found OK when test_should_pass==false: %s" %
                               rsp)
            assert State.FAILURE in prx.getStatus().flags

        return rsp
Exemplo n.º 15
0
    def deleteRoi(self, roi_id):
        """
        Delete the given ROI
        
        :param roi: an ROI object
        :type roi: `omero.model.Roi`
        """
        from omero.callbacks import CmdCallbackI  # @UnresolvedImport

        handle = self.conn.deleteObjects("Roi", [roi_id],
                                         deleteAnns=True,
                                         deleteChildren=True)
        callback = CmdCallbackI(self.conn.c, handle)

        while not callback.block(500):
            if self.args.verbose:
                print_date(".", newline=False, incl_date=False)
                time.sleep(2)

        callback.close(True)
Exemplo n.º 16
0
    def doChange(self,
                 group_id,
                 permissions,
                 test_should_pass=True,
                 return_complete=True):
        """
        Performs the chmod action, waits on completion and checks that the
        result is not an error.
        """
        prx = self.gateway.chmodGroup(group_id, permissions)
        if not return_complete:
            return prx

        cb = CmdCallbackI(self.gateway.c, prx)
        cb.loop(20,
                500)  # This fails (see #8439). Can comment out this line and
        # try a different way of waiting for result - This never completes...
        import time
        rsp = prx.getResponse()
        i = 0
        while (rsp is None):
            time.sleep(10)
            rsp = prx.getResponse()
            i += 1
            print "rsp", i, rsp

        self.assertNotEqual(rsp, None)

        status = prx.getStatus()

        if test_should_pass:
            if isinstance(rsp, ERR):
                self.fail(
                    "Found ERR when test_should_pass==true: %s (%s) params=%s"
                    % (rsp.category, rsp.name, rsp.parameters))
            self.assertFalse(State.FAILURE in prx.getStatus().flags)
        else:
            if isinstance(rsp, OK):
                self.fail("Found OK when test_should_pass==false: %s", rsp)
            self.assertTrue(State.FAILURE in prx.getStatus().flags)
        return rsp
Exemplo n.º 17
0
 def raw(self, command, args, client=None):
     if client == None:
         client = self.client
     mrepo = self.getManagedRepo(self.client)
     obj = mrepo.root()
     sha = obj.hash.val
     raw_access = omero.grid.RawAccessRequest()
     raw_access.repoUuid = sha
     raw_access.command = command
     raw_access.args = args
     handle = client.sf.submit(raw_access)
     return CmdCallbackI(client, handle)
    def write_to_omero(self):
        to_delete = {"Annotation": self.mapannids + self.fileannids}
        delCmd = omero.cmd.Delete2(targetObjects=to_delete)
        handle = self.client.getSession().submit(delCmd)

        callback = None
        try:
            callback = CmdCallbackI(self.client, handle)
            loops = max(10, len(self.mapannids) / 10)
            delay = 500
            callback.loop(loops, delay)
            rsp = callback.getResponse()
            if isinstance(rsp, omero.cmd.OK):
                ndma = len(rsp.deletedObjects.get(
                    "ome.model.annotations.MapAnnotation", []))
                log.info("Deleted %d MapAnnotation(s)", ndma)
                ndfa = len(rsp.deletedObjects.get(
                    "ome.model.annotations.FileAnnotation", []))
                log.info("Deleted %d FileAnnotation(s)", ndfa)
            else:
                log.error("Delete failed: %s", rsp)
        finally:
            if callback:
                callback.close(True)
            else:
                handle.close()
Exemplo n.º 19
0
 def doChange(self, obj_type, obj_ids, group_id, container_id=None, test_should_pass=True, return_complete=True):
     """
     Performs the change-group action, waits on completion and checks that the 
     result is not an error.
     """
     prx = self.gateway.chgrpObjects(obj_type, obj_ids, group_id, container_id)
     
     if not return_complete:
         return prx
     
     cb = CmdCallbackI(self.gateway.c, prx)
     try:
         for i in range(10):
             cb.loop(20, 500)
             if prx.getResponse() != None:
                 break
 
         self.assertNotEqual(prx.getResponse(), None)
 
         status = prx.getStatus()
         rsp = prx.getResponse()
 
         if test_should_pass:
             if isinstance(rsp, ERR):
                 self.fail("Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters))
             self.assertFalse(State.FAILURE in prx.getStatus().flags)
         else:
             if isinstance(rsp, OK):
                 self.fail("Found OK when test_should_pass==false: %s", rsp)
             self.assertTrue(State.FAILURE in prx.getStatus().flags)
         return rsp
     finally:
         cb.close(True)
Exemplo n.º 20
0
    def wait_on_callback(self, conn, proxy, test_should_pass=True):
        """
        Handles callback on proxy handle and checks that the
        result is not an error.
        """

        cb = CmdCallbackI(conn.c, proxy)
        try:
            for i in range(10):
                cb.loop(20, 500)
                if proxy.getResponse() is not None:
                    break

            assert proxy.getResponse() is not None
            proxy.getStatus()
            rsp = proxy.getResponse()

            if test_should_pass:
                assert not isinstance(rsp, ERR)
                assert State.FAILURE not in proxy.getStatus().flags
            else:
                assert not isinstance(rsp, OK)
                assert State.FAILURE in proxy.getStatus().flags
            return rsp
        finally:
            cb.close(True)
Exemplo n.º 21
0
def fs_usage(client, objecttype, objectid):
    req = DiskUsage2()
    req.targetObjects = {objecttype: [objectid]}

    cb = None
    handle = None
    try:
        handle = client.sf.submit(req)
        cb = CmdCallbackI(client, handle)
        # Wait for finish
        while True:
            found = cb.block(1000)
            if found:
                break

        rsp = cb.getResponse()
        # status = cb.getStatus()
    except KeyboardInterrupt:
        # If user uses Ctrl-C, then cancel
        if handle is not None:
            logging.warning("Attempting cancel...")
            if handle.cancel():
                logging.warning("Cancelled")
            else:
                logging.warning("Failed to cancel")
    finally:
        if cb is not None:
            cb.close(True)  # Close handle

    sizebytes = sum(rsp.totalBytesUsed.values())
    nfiles = sum(rsp.totalFileCount.values())
    return sizebytes, nfiles
Exemplo n.º 22
0
    def doSubmit(self, request, client, test_should_pass=True, omero_group=None):
        """
        Performs the request(s), waits on completion and checks that the
        result is not an error. The request can either be a single command
        or a list of commands. If the latter then the request list will be
        wrapped in a DoAll.
        """
        if isinstance(request, list):
            request = DoAll(request)

        sf = client.sf
        if omero_group is not None:
            prx = sf.submit(request, {"omero.group": str(omero_group)})
        else:
            prx = sf.submit(request)

        assert State.FAILURE not in prx.getStatus().flags

        cb = CmdCallbackI(client, prx)
        cb.loop(20, 500)

        assert prx.getResponse() is not None

        rsp = prx.getResponse()

        if test_should_pass:
            if isinstance(rsp, ERR):
                assert False, "Found ERR when test_should_pass==true: %s (%s) params=%s" % (
                    rsp.category,
                    rsp.name,
                    rsp.parameters,
                )
            assert State.FAILURE not in prx.getStatus().flags
        else:
            if isinstance(rsp, OK):
                assert False, "Found OK when test_should_pass==false: %s" % rsp
            assert State.FAILURE in prx.getStatus().flags

        return rsp
Exemplo n.º 23
0
 def submit(self, req):
     import omero
     handle = self.client.sf.submit(req)
     cb = CmdCallbackI(self.client, handle)
     try:
         cb.loop(50, 1000)
         rsp = cb.getResponse()
         if isinstance(rsp, omero.cmd.ERR):
             raise Exception(rsp)
         return rsp
     finally:
         cb.close(True)
Exemplo n.º 24
0
 def submit(self, req):
     import omero
     handle = self.client.sf.submit(req)
     cb = CmdCallbackI(self.client, handle)
     try:
         cb.loop(50, 1000)
         rsp = cb.getResponse()
         if isinstance(rsp, omero.cmd.ERR):
             raise Exception(rsp)
         return rsp
     finally:
         cb.close(True)
Exemplo n.º 25
0
def assert_import(client, proc, files, wait):
    """Wait and check that we imported an image."""
    hashes = upload_files(proc, files, client)
    print('Hashes:\n  %s' % '\n  '.join(hashes))
    handle = proc.verifyUpload(hashes)
    cb = CmdCallbackI(client, handle)

    # https://github.com/openmicroscopy/openmicroscopy/blob/v5.4.9/components/blitz/src/ome/formats/importer/ImportLibrary.java#L631
    if wait == 0:
        cb.close(False)
        return None
    if wait < 0:
        while not cb.block(2000):
            sys.stdout.write('.')
            sys.stdout.flush()
        sys.stdout.write('\n')
    else:
        cb.loop(wait, 1000)
    rsp = cb.getResponse()
    if isinstance(rsp, omero.cmd.ERR):
        raise Exception(rsp)
    assert len(rsp.pixels) > 0
    return rsp
Exemplo n.º 26
0
def doChange(gateway,
             obj_type,
             obj_ids,
             group_id,
             container_id=None,
             test_should_pass=True,
             return_complete=True):
    """
    Performs the change-group action, waits on completion and checks that the 
    result is not an error.
    """
    prx = gateway.chgrpObjects(obj_type, obj_ids, group_id, container_id)

    if not return_complete:
        return prx

    cb = CmdCallbackI(gateway.c, prx)
    try:
        for i in range(10):
            cb.loop(20, 500)
            if prx.getResponse() != None:
                break

        assert prx.getResponse() is not None

        status = prx.getStatus()
        rsp = prx.getResponse()

        if test_should_pass:
            assert not isinstance(rsp, ERR),\
                   "Found ERR when test_should_pass==true: %s (%s) params=%s" \
                   % (rsp.category, rsp.name, rsp.parameters)
            assert State.FAILURE not in prx.getStatus().flags
        else:
            assert not isinstance(rsp, OK),\
                   "Found OK when test_should_pass==false: %s" % rsp
            assert State.FAILURE in prx.getStatus().flags
        return rsp
    finally:
        cb.close(True)