Esempio n. 1
0
 def jsonrpc_delete(self, cascade=False):
     try:
         b = Backend()
         resp = yield b.delete([self.path], cascade)
         defer.returnValue(resp)
     except:
         raise
Esempio n. 2
0
def _init(config, mode='normal'):
    from almar.global_config import GlobalConfig, MODE_PROXY, MODE_WORKER
    g = GlobalConfig.create_instance(config)

    # configure web service
    from almar.service import worker_root, proxy_root
    from twisted.web import server

    if mode == 'proxy':
        g.server_mode = MODE_PROXY
        if not g.proxy or not g.searcher:
            fatal_out('proxy configuration is invalid')
        # configure reactor
        reactor.suggestThreadPoolSize(int(g.proxy.max_threads))
        return int(g.proxy.port), server.Site(proxy_root)
    else:
        if not g.server or not g.model or not g.database:
            fatal_out('server configuration is invalid')
        # configure reactor
        reactor.suggestThreadPoolSize(int(g.server.max_threads))
        g.server_mode = MODE_WORKER

        # configure database
        from txpostgres import txpostgres
        txpostgres.ConnectionPool.min = int(g.database.min_connections)
        txpostgres.ConnectionPool.max = int(g.database.max_connections)

        from almar.backend.postgresql import PostgreSQLBackend as Backend
        Backend.create_instance(g.database)

        return int(g.server.port), server.Site(worker_root)
Esempio n. 3
0
    def async_GET(self, request):
        b = Backend()
        result = yield b.get([self.path], self.method)
        if self.method == 'descendant':
            retval = RESTResult(code=200, content=result)
        else:
            retval = RESTResult(code=200, content=result[0][1])

        defer.returnValue(retval)
Esempio n. 4
0
 def jsonrpc_get(self):
     try:
         b = Backend()
         resp = yield b.get([self.path], None)
         if resp:
             defer.returnValue(resp[0][1])
         else:
             defer.returnValue(dict())
     except:
         raise
Esempio n. 5
0
 def jsonrpc_upsert(self, lst):
     try:
         b = Backend()
         result = yield b.upsert(lst)
         defer.returnValue(result)
     except exception.ModelNotExistError as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.MissingFieldError as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.KeyNotDefinedError as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.ConstraintViolationError as e:
         defer.returnValue(Fault(exception.CONSTRAINT_VIOLATION, str(e)))
     except Exception as e:
         raise
Esempio n. 6
0
 def jsonrpc_push(self, lst):
     try:
         b = Backend()
         resp = yield b.push(self.path, lst)
         defer.returnValue(resp)
     except exception.MissingFieldError as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.ModelNotExistError as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.KeyNotDefinedError as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.MalformedIncomingData as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.ConstraintViolationError as e:
         defer.returnValue(Fault(exception.CONSTRAINT_VIOLATION, str(e)))
     except:
         raise
Esempio n. 7
0
    def makeService(self, options):
        from almar import _init as almar_init

        # get site and default port
        port_no, site = almar_init(options["config"], mode=("normal", "proxy")[options["proxy"]])

        # override port use user specified option
        if "port" in options and options["port"]:
            port_no = int(options["port"])

        # start database connection
        if options["proxy"] == "normal":
            from almar.backend.postgresql import PostgreSQLBackend as Backend

            b = Backend()
            b.start()

        return internet.TCPServer(port_no, site)
Esempio n. 8
0
 def jsonrpc_update(self, item):
     try:
         b = Backend()
         if isinstance(item, dict):
             item['path'] = self.path
             resp = yield b.upsert([item])
             defer.returnValue(resp)
         else:
             defer.returnValue(Fault(exception.INVALID_INPUT,
                                     "content must be json dict"))
     except exception.MissingFieldError as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.ModelNotExistError as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.KeyNotDefinedError as e:
         defer.returnValue(Fault(exception.INVALID_INPUT, str(e)))
     except exception.ConstraintViolationError as e:
         defer.returnValue(Fault(exception.CONSTRAINT_VIOLATION, str(e)))
     except:
         raise
Esempio n. 9
0
 def async_DELETE(self, request):
     b = Backend()
     result = yield b.delete([self.path], False)
     defer.returnValue(result)
Esempio n. 10
0
    def async_POST(self, request):
        b = Backend()

        self.postdata['path'] = self.path
        result = yield b.upsert([self.postdata])
        defer.returnValue(RESTResult(code=200, content=result))
Esempio n. 11
0
 def jsonrpc_search(self, query):
     b = Backend()
     result = yield b.search(query)
     defer.returnValue(result)
Esempio n. 12
0
 def jsonrpc_touch(self, paths):
     b = Backend()
     return b.touch(paths)
Esempio n. 13
0
 def jsonrpc_delete(self, paths, cascade=False):
     print paths, cascade
     b = Backend()
     return b.delete(paths, cascade)
Esempio n. 14
0
 def jsonrpc_get(self, paths, method='self'):
     b = Backend()
     return b.get(paths, method)