spacewander commented on a change in pull request #9:
URL:
https://github.com/apache/apisix-python-plugin-runner/pull/9#discussion_r684368491
##########
File path: src/runner/socket/handle.py
##########
@@ -14,65 +14,95 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-from a6pluginproto.Err import Resp as A6ErrResp
+from __future__ import annotations
from a6pluginproto.Err import Code as A6ErrCode
import runner.plugin.cache as RunnerPluginCache
import runner.plugin.execute as RunnerPluginExecute
import runner.http.request as RunnerHttpRequest
import runner.http.response as RunnerHttpResponse
import runner.http.protocol as RunnerHttpProtocol
+import runner.socket.error as RunnerSocketError
-class Handle:
+class New(object):
- def __init__(self, req_type, req_data):
- self.req_type = req_type
- self.req_data = req_data
+ def __init__(self, ty: int = 0, buf: bytes = b''):
+ self.__buffer = buf
+ self.__type = ty
- def RpcPrepareConf(self):
+ def __rpc_config(self) -> RunnerSocketError:
# init request
- req = RunnerHttpRequest.Request(RunnerHttpProtocol.RPC_PREPARE_CONF,
self.req_data)
+ req = RunnerHttpRequest.Request(RunnerHttpProtocol.RPC_PREPARE_CONF,
self.__buffer)
# generate token
token = RunnerPluginCache.generateToken()
# get plugins config
configs = req.getConfigs()
# cache plugins config
- RunnerPluginCache.setConfigByToken(token, configs)
+ ok = RunnerPluginCache.setConfigByToken(token, configs)
+ if not ok:
+ return RunnerSocketError.New(A6ErrCode.Code.SERVICE_UNAVAILABLE,
"cache token failure")
# init response
reps = RunnerHttpResponse.Response(RunnerHttpProtocol.RPC_PREPARE_CONF)
+ response = reps.setToken(token).responseToFlatBuffers()
- return reps.setToken(token).responseToFlatBuffers()
+ return
RunnerSocketError.New(code=RunnerSocketError.RUNNER_SUCCESS_CODE, message="OK",
data=response.Output(),
+ ty=self.__type)
- def RpcHttpReqCall(self):
+ def __rpc_call(self) -> RunnerSocketError:
# init request
- req = RunnerHttpRequest.Request(RunnerHttpProtocol.RPC_HTTP_REQ_CALL,
self.req_data)
+ req = RunnerHttpRequest.Request(RunnerHttpProtocol.RPC_HTTP_REQ_CALL,
self.__buffer)
# get request token
token = req.getConfToken()
# get plugins
configs = RunnerPluginCache.getConfigByToken(token)
+ if len(configs) == 0:
+ return RunnerSocketError.New(A6ErrCode.Code.CONF_TOKEN_NOT_FOUND,
"cache token not found")
# init response
reps =
RunnerHttpResponse.Response(RunnerHttpProtocol.RPC_HTTP_REQ_CALL)
# execute plugins
RunnerPluginExecute.executeFilter(configs, req, reps)
- return reps.responseToFlatBuffers()
+ response = reps.responseToFlatBuffers()
+ return
RunnerSocketError.New(code=RunnerSocketError.RUNNER_SUCCESS_CODE, message="OK",
data=response.Output(),
+ ty=self.__type)
- def RpcTest(self):
- pass
+ def __rpc_test(self) -> RunnerSocketError:
Review comment:
There is no RPC_TEST at all
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]