pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] srkukarni commented on a change in pull request #3168: Refactor api commands
Date Thu, 13 Dec 2018 20:50:48 GMT
srkukarni commented on a change in pull request #3168: Refactor api commands
URL: https://github.com/apache/pulsar/pull/3168#discussion_r241556596
 
 

 ##########
 File path: pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java
 ##########
 @@ -1187,58 +1113,49 @@ public Response getFunctionState(final String tenant,
         try (Table<ByteBuf, ByteBuf> table = result(storageClient.get().openTable(tableName)))
{
             try (KeyValue<ByteBuf, ByteBuf> kv = result(table.getKv(Unpooled.wrappedBuffer(key.getBytes(UTF_8)))))
{
                 if (null == kv) {
-                    return Response.status(Status.NOT_FOUND)
-                            .entity(new String("key '" + key + "' doesn't exist."))
-                            .build();
+                    throw new RestException(Status.NOT_FOUND, "key '" + key + "' doesn't
exist.");
                 } else {
                     FunctionState value;
                     if (kv.isNumber()) {
                         value = new FunctionState(key, null, kv.numberValue(), kv.version());
                     } else {
                         value = new FunctionState(key, new String(ByteBufUtil.getBytes(kv.value()),
UTF_8), null, kv.version());
                     }
-                    return Response.status(Status.OK)
-                            .entity(new Gson().toJson(value))
-                            .build();
                 }
             }
         } catch (Exception e) {
             log.error("Error while getFunctionState request @ /{}/{}/{}/{}",
                     tenant, namespace, functionName, key, e);
-            return Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON)
-                    .entity(new ErrorData(e.getMessage())).build();
+            throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
         }
-
     }
 
-    public Response uploadFunction(final InputStream uploadedInputStream, final String path)
{
+    public void uploadFunction(final InputStream uploadedInputStream, final String path)
{
         // validate parameters
         try {
             if (uploadedInputStream == null || path == null) {
                 throw new IllegalArgumentException("Function Package is not provided " +
path);
             }
         } catch (IllegalArgumentException e) {
             log.error("Invalid upload function request @ /{}", path, e);
-            return Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON)
-                    .entity(new ErrorData(e.getMessage())).build();
+            throw new RestException(Status.BAD_REQUEST, e.getMessage());
         }
 
         // Upload to bookkeeper
         try {
             log.info("Uploading function package to {}", path);
-
             Utils.uploadToBookeeper(worker().getDlogNamespace(), uploadedInputStream, path);
         } catch (IOException e) {
             log.error("Error uploading file {}", path, e);
-            return Response.serverError().type(MediaType.APPLICATION_JSON).entity(new ErrorData(e.getMessage()))
-                    .build();
+            throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
         }
 
-        return Response.status(Status.OK).build();
+        //return Response.status(Status.OK).build();
 
 Review comment:
   remove comment

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message