This is an automated email from the ASF dual-hosted git repository.
wuzhiguo pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new baead3e698 AMBARI-25204: Ambari returns stack trace in HTML doc when
an error occurs retrieving details for an Ambari View resource that does not
exist (#3439)
baead3e698 is described below
commit baead3e698de627d82d9a978d477a4f2bdc87c7c
Author: Zhiguo Wu <[email protected]>
AuthorDate: Thu Oct 27 14:37:01 2022 +0800
AMBARI-25204: Ambari returns stack trace in HTML doc when an error occurs
retrieving details for an Ambari View resource that does not exist (#3439)
---
.../ambari/server/api/services/BaseService.java | 1 +
.../api/services/views/ViewInstanceService.java | 140 ++++++++++++++++++++-
2 files changed, 137 insertions(+), 4 deletions(-)
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseService.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseService.java
index b14ffa713e..c439524218 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseService.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseService.java
@@ -55,6 +55,7 @@ public abstract class BaseService {
public static final String MSG_INVALID_REQUEST = "Invalid request";
public static final String MSG_CLUSTER_NOT_FOUND = "Cluster not found";
public static final String MSG_CLUSTER_OR_HOST_NOT_FOUND = "Cluster or host
not found";
+ public static final String MSG_VIEW_NOT_FOUND = "View not found";
public static final String MSG_NOT_AUTHENTICATED = "Not authenticated";
public static final String MSG_PERMISSION_DENIED = "Not permitted to perform
the operation";
public static final String MSG_SERVER_ERROR = "Internal server error";
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java
index bad03f0fa7..a922eca755 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/views/ViewInstanceService.java
@@ -38,6 +38,10 @@ import javax.ws.rs.core.UriInfo;
import org.apache.ambari.server.api.resources.ResourceInstance;
import org.apache.ambari.server.api.services.BaseService;
import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultImpl;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.api.services.serializers.JsonSerializer;
import org.apache.ambari.server.controller.ViewInstanceResponse;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
@@ -315,19 +319,147 @@ public class ViewInstanceService extends BaseService {
ViewRegistry.getInstance().getInstanceDefinition(viewName, version,
instanceName);
if (instanceDefinition == null) {
- throw new IllegalArgumentException("A view instance " +
- viewName + "/" + instanceName + " can not be found.");
+ String msg = "A view instance " +
+ viewName + "/" + instanceName + " can not be found.";
+
+ return new NotFoundResponse(msg);
}
Object service = instanceDefinition.getService(resources);
if (service == null) {
- throw new IllegalArgumentException("A resource type " + resources + "
for view instance " +
- viewName + "/" + instanceName + " can not be found.");
+ String msg = "A resource type " + resources + " for view instance " +
+ viewName + "/" + instanceName + " can not be found.";
+ return new NotFoundResponse(msg);
}
return service;
}
+ /**
+ * Stub class for 404 error response
+ *
+ */
+ @Path("/")
+ public class NotFoundResponse {
+
+ String msg;
+
+ NotFoundResponse(String msg){
+ this.msg=msg;
+ }
+
+ /**
+ * Handles: GET /{resourceName}
+ * Handle GET resource with 404 response
+ * @return 404 response with msg
+ */
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(value = "Handle GET resource with 404 response")
+ public Response get() {
+ return getResponse();
+ }
+
+ /**
+ * Handles: POST /{resourceName}
+ * Handle POST resource with 404 response
+ * @return 404 response with msg
+ */
+ @POST
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(value = "Handle POST resource with 404 response")
+ public Response post() {
+ return getResponse();
+ }
+
+ /**
+ * Handles: PUT /{resourceName}
+ * Handle PUT resource with 404 response
+ * @return 404 response with msg
+ */
+ @PUT
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(value = "Handle PUT resource with 404 response")
+ public Response put() {
+ return getResponse();
+ }
+
+ /**
+ * Handles: DELETE /{resourceName}
+ * Handle DELETE resource with 404 response
+ * @return 404 response with msg
+ */
+ @DELETE
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(value = "Handle DELETE resource with 404 response")
+ public Response delete() {
+ return getResponse();
+ }
+
+ /**
+ * Handles: GET /{resourceName}/{.*}
+ * Handle GET sub-resource with 404 response
+ * @return 404 response with msg
+ */
+ @GET
+ @Path("{path: .*}")
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(value = "Handle GET sub-resource with 404 response")
+ public Response getSub() {
+ return getResponse();
+ }
+
+ /**
+ * Handles: POST /{resourceName}/{.*}
+ * Handle POST sub-resource with 404 response
+ * @return 404 response with msg
+ */
+ @POST
+ @Path("{path: .*}")
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(value = "Handle POST sub-resource with 404 response")
+ public Response postSub() {
+ return getResponse();
+ }
+
+ /**
+ * Handles: PUT /{resourceName}/{.*}
+ * Handle PUT sub-resource with 404 response
+ * @return 404 response with msg
+ */
+ @PUT
+ @Path("{path: .*}")
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(value = "Handle PUT sub-resource with 404 response")
+ public Response putSub() {
+ return getResponse();
+ }
+
+ /**
+ * Handles: DELETE /{resourceName}/{.*}
+ * Handle DELETE sub-resource with 404 response
+ * @return 404 response with msg
+ */
+ @DELETE
+ @Path("{path: .*}")
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(value = "Handle DELETE sub-resource with 404 response")
+ public Response deleteSub() {
+ return getResponse();
+ }
+
+ /**
+ * Build 404 response with msg
+ * @return 404 response with msg
+ */
+ public Response getResponse() {
+ Result result = new ResultImpl(new
ResultStatus(ResultStatus.STATUS.NOT_FOUND, msg));
+ Response.ResponseBuilder builder =
Response.status(result.getStatus().getStatusCode()).entity(new
JsonSerializer().serialize(result));
+ return builder.build();
+ }
+
+ }
+
// ----- helper methods ----------------------------------------------------
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]