Github user revans2 commented on a diff in the pull request: https://github.com/apache/storm/pull/2752#discussion_r206240455 --- Diff: storm-webapp/src/main/java/org/apache/storm/daemon/ui/resources/StormApiResource.java --- @@ -0,0 +1,702 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.storm.daemon.ui.resources; + +import com.codahale.metrics.Meter; +import java.net.URLDecoder; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + +import org.apache.storm.daemon.ui.UIHelpers; +import org.apache.storm.metric.StormMetricsRegistry; +import org.apache.storm.thrift.TException; +import org.apache.storm.utils.NimbusClient; +import org.apache.storm.utils.Utils; +import org.json.simple.JSONValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Root resource (exposed at "storm" path). + */ +@Path("/") +public class StormApiResource { + + public static final Logger LOG = LoggerFactory.getLogger(StormApiResource.class); + + @Context + private HttpServletRequest servletRequest; + + public static Map<String, Object> config = Utils.readStormConfig(); + + public static Meter clusterConfigurationRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-cluster-configuration-http-requests"); + + public static Meter clusterSummaryRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-cluster-summary-http-requests"); + + public static Meter nimbusSummaryRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-nimbus-summary-http-requests"); + + public static Meter supervisorRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-supervisor-http-requests"); + + public static Meter supervisorSummaryRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-supervisor-summary-http-requests"); + + public static Meter allTopologiesSummaryRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-all-topologies-summary-http-requests"); + + public static Meter topologyPageRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-topology-page-http-requests"); + + public static Meter topologyMetricRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-topology-metric-http-requests"); + + public static Meter buildVisualizationRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-build-visualization-http-requests"); + + public static Meter mkVisualizationDataRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-mk-visualization-data-http-requests"); + + public static Meter componentPageRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-component-page-http-requests"); + + public static Meter logConfigRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-log-config-http-requests"); + + public static Meter activateTopologyRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-activate-topology-http-requests"); + + public static Meter deactivateTopologyRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-deactivate-topology-http-requests"); + + public static Meter debugTopologyRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-debug-topology-http-requests"); + + public static Meter componentOpResponseRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-component-op-response-http-requests"); + + public static Meter topologyOpResponseMeter = + StormMetricsRegistry.registerMeter("ui:num-topology-op-response-http-requests"); + + public static Meter topologyLagRequestMeter = + StormMetricsRegistry.registerMeter("ui:num-topology-lag-http-requests"); + + public static Meter getOwnerResourceSummariesMeter = + StormMetricsRegistry.registerMeter("ui:num-get-owner-resource-summaries-http-request"); + + + /** + * /api/v1/cluster/configuration -> nimbus configuration. + */ + + @GET + @Path("/cluster/configuration") + @Produces("application/json") + public Response getClusterConfiguration(@QueryParam("callback") String callback) throws TException { + clusterConfigurationRequestMeter.mark(); + try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) { + return UIHelpers.makeStandardResponse( + nimbusClient.getClient().getNimbusConf(), + callback, false + ); + } + } + + /** + * /api/v1/cluster/summary -> cluster summary. + */ + @GET + @Path("/cluster/summary") + @NimbusOp("getClusterInfo") + @Produces("application/json") + public Response getClusterSummary(@QueryParam("callback") String callback) throws TException { + clusterSummaryRequestMeter.mark(); + try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) { + String user = servletRequest.getRemoteUser(); + return UIHelpers.makeStandardResponse( + UIHelpers.getClusterSummary( + nimbusClient.getClient().getClusterInfo(), user, config), + callback + ); + } + } + + /** + * /api/v1/nimbus/summary -> nimbus summary. + */ + @GET + @Path("/nimbus/summary") + @NimbusOp("getClusterInfo") + @Produces("application/json") + public Response getNimbusSummary(@QueryParam("callback") String callback) throws TException { + nimbusSummaryRequestMeter.mark(); + try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) { + return UIHelpers.makeStandardResponse( + UIHelpers.getNimbusSummary( + nimbusClient.getClient().getClusterInfo(), config), + callback + ); + } + } + + /** + * /api/v1/owner-resources -> owner resources. + */ + @GET + @Path("/owner-resources") + @NimbusOp("getOwnerResourceSummaries") + @Produces("application/json") + public Response getOwnerResources(@QueryParam("callback") String callback) throws TException { + getOwnerResourceSummariesMeter.mark(); + try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) { + return UIHelpers.makeStandardResponse( + UIHelpers.getOwnerResourceSummaries( + nimbusClient.getClient().getOwnerResourceSummaries(null), config), + callback + ); + } + } + + /** + * /api/v1/owner-resources/:id -> owner resources. + */ + @GET + @Path("/owner-resources/{id}") + @NimbusOp("getOwnerResourceSummaries") --- End diff -- If someone forgets to set id, or sets it wrong, what will happen in the Authorization code when processing this NimbusOp?
---