예제 #1
0
파일: jsonrpc.py 프로젝트: jianingy/almar
 def jsonrpc_delete(self, cascade=False):
     try:
         b = Backend()
         resp = yield b.delete([self.path], cascade)
         defer.returnValue(resp)
     except:
         raise
예제 #2
0
파일: __init__.py 프로젝트: jianingy/almar
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)
예제 #3
0
파일: rest.py 프로젝트: jianingy/almar
    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)
예제 #4
0
파일: jsonrpc.py 프로젝트: jianingy/almar
 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
예제 #5
0
파일: jsonrpc.py 프로젝트: jianingy/almar
 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
예제 #6
0
파일: jsonrpc.py 프로젝트: jianingy/almar
 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
예제 #7
0
파일: plugin.py 프로젝트: jianingy/almar
    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)
예제 #8
0
파일: jsonrpc.py 프로젝트: jianingy/almar
 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
예제 #9
0
파일: rest.py 프로젝트: jianingy/almar
 def async_DELETE(self, request):
     b = Backend()
     result = yield b.delete([self.path], False)
     defer.returnValue(result)
예제 #10
0
파일: rest.py 프로젝트: jianingy/almar
    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))
예제 #11
0
파일: jsonrpc.py 프로젝트: jianingy/almar
 def jsonrpc_search(self, query):
     b = Backend()
     result = yield b.search(query)
     defer.returnValue(result)
예제 #12
0
파일: jsonrpc.py 프로젝트: jianingy/almar
 def jsonrpc_touch(self, paths):
     b = Backend()
     return b.touch(paths)
예제 #13
0
파일: jsonrpc.py 프로젝트: jianingy/almar
 def jsonrpc_delete(self, paths, cascade=False):
     print paths, cascade
     b = Backend()
     return b.delete(paths, cascade)
예제 #14
0
파일: jsonrpc.py 프로젝트: jianingy/almar
 def jsonrpc_get(self, paths, method='self'):
     b = Backend()
     return b.get(paths, method)