def tearDown(self, res=None):
     self.dm.directory_instances = self.old_instances
     self.dm.instances_by_name = self.old_instances_by_name
     d = StorageTableUtil.drop_tables(self.dm.storage,
             (ConfiguredDirectoryTable._table_name,))
     d.addCallback(self.dm.init_cdb_tables)
     return d
Beispiel #2
0
 def tearDown(self, res=None):
     self.dm.directory_instances = self.old_instances
     self.dm.instances_by_name = self.old_instances_by_name
     d = StorageTableUtil.drop_tables(
         self.dm.storage, (ConfiguredDirectoryTable._table_name, ))
     d.addCallback(self.dm.init_cdb_tables)
     return d
Beispiel #3
0
    def doRemoveRow(self, table_name, guid):
        def _get_guid_cb(rows):
            if len(rows) == 0:
                notFound(self.request,
                         "Table %s does not have row with GUID: %s"
                         % (self.table_name,
                            self._query["GUID"][1].encode("hex")))
            elif len(rows) > 1:
                msg = "Multiple rows returned (unexpectedly) by the "\
                        "database and possibly removed."
                lg.error(msg)
                webservice.internalError(request, msg)
            else:
                d = StorageTableUtil.get_connection_if_none(self.db)
                d.addCallback(_do_remove, rows[0])
                return d

        def _do_remove(conn, row):
            d = conn.remove(table_name, row)
            d.addCallback(_remove_cb)
            return d

        def _remove_cb(res):
            if res[0] != Storage.SUCCESS:
                msg = "Remove failed: %s (%s)" %(res[0], res[1])
                lg.error(msg)
                webservice.internalError(msg)

        query = { "GUID" : guid }
        d = StorageTableUtil.get_all_rows_for_query(self.db, table_name, query)
        d.addCallback(_get_guid_cb)
        d.addErrback(self._handle_err)
        return d
Beispiel #4
0
 def doGet(self, table_name, query=None):
     def _process_storage_rows(rows):
         if (len(rows) == 0 and len(query) == 1
                 and query.has_key("GUID")):
             notFound(self.request,
                     "Table %s does not have row with GUID: %s" 
                     %(self.table_name,
                     self._query["GUID"][1].encode("hex")))
         else:
             self.request.write('{"table_name" : "' + table_name + '"')
             self.request.write(', "identifier" : "GUID", "items" : [')
             i = 0
             for row in rows:
                 ui_guid = (row["GUID"][1]).encode("hex")
                 row["GUID"] = ui_guid
                 row["GUID.link"] = u"/ws.v1/storage/%s/table/%s/%s" \
                         %(self.schema.dbname, table_name, ui_guid)
                 self.request.write(simplejson.dumps(row))
                 i += 1
                 if i < len(rows):
                     self.request.write(",")
             self.request.write("]}")
             self.request.finish()
         return
     query = query or {}
     d = StorageTableUtil.get_all_rows_for_query(self.db, table_name, query)
     d.addCallback(_process_storage_rows)
     return d
Beispiel #5
0
    def doModifyRow(self, table_name, row):
        def _do_modify(conn):
            d = conn.modify(table_name, row)
            d.addCallback(_modify_cb)
            return d

        def _modify_cb(res):
            if res[0] == Storage.SUCCESS:
                # TBD: setting response code here is causing errors deep
                # TBD: in twisted.  Need to figure out why.
                #self.request.setResponseCode("204")
                self.request.finish() # No body for 204 response
                return
            else:
                msg = "Modify success callback called with unexpected "\
                      "results"
                lg.error(msg)
                webservice.internalError(self.request, msg)

        # Strip out link entries added by web service
        for k in row.keys():
            if k.endswith(".link"):
                del(row[k])

        d = StorageTableUtil.get_connection_if_none(self.db)
        d.addCallback(_do_modify)
        d.addErrback(self._handle_err)
        return d
 def setUp(self):
     self.old_instances = self.dm.directory_instances
     self.old_instances_by_name = self.dm.instances_by_name
     self._set_directories([])
     d = StorageTableUtil.drop_tables(self.dm.storage,
             (ConfiguredDirectoryTable._table_name,))
     d.addCallback(self.dm.init_cdb_tables)
     return d
Beispiel #7
0
 def setUp(self):
     self.old_instances = self.dm.directory_instances
     self.old_instances_by_name = self.dm.instances_by_name
     self._set_directories([])
     d = StorageTableUtil.drop_tables(
         self.dm.storage, (ConfiguredDirectoryTable._table_name, ))
     d.addCallback(self.dm.init_cdb_tables)
     return d
Beispiel #8
0
 def _get_guid_cb(rows):
     if len(rows) == 0:
         notFound(self.request,
                  "Table %s does not have row with GUID: %s"
                  % (self.table_name,
                     self._query["GUID"][1].encode("hex")))
     elif len(rows) > 1:
         msg = "Multiple rows returned (unexpectedly) by the "\
                 "database and possibly removed."
         lg.error(msg)
         webservice.internalError(request, msg)
     else:
         d = StorageTableUtil.get_connection_if_none(self.db)
         d.addCallback(_do_remove, rows[0])
         return d