storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject [01/36] storm git commit: STORM-1311: UI Migration from clj to java
Date Fri, 03 Aug 2018 20:45:50 GMT
Repository: storm
Updated Branches:
  refs/heads/master d64463609 -> 1828a17e5


http://git-wip-us.apache.org/repos/asf/storm/blob/034ac677/storm-webapp/src/main/java/org/apache/storm/daemon/ui/exceptionmappers/NotAliveExceptionMapper.java
----------------------------------------------------------------------
diff --git a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/exceptionmappers/NotAliveExceptionMapper.java b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/exceptionmappers/NotAliveExceptionMapper.java
new file mode 100644
index 0000000..0cff689
--- /dev/null
+++ b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/exceptionmappers/NotAliveExceptionMapper.java
@@ -0,0 +1,40 @@
+/*
+ * 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.exceptionmappers;
+
+import static org.apache.storm.daemon.ui.exceptionmappers.ExceptionMapperUtils.getResponse;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+import org.apache.storm.generated.NotAliveException;
+
+
+@Provider
+public class NotAliveExceptionMapper implements ExceptionMapper<NotAliveException> {
+
+    @Inject
+    public javax.inject.Provider<HttpServletRequest> request;
+
+    public Response toResponse(NotAliveException ex) {
+        return getResponse(ex, request);
+    }
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/034ac677/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/AuthorizedUserFilter.java
----------------------------------------------------------------------
diff --git a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/AuthorizedUserFilter.java b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/AuthorizedUserFilter.java
new file mode 100644
index 0000000..c094b82
--- /dev/null
+++ b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/AuthorizedUserFilter.java
@@ -0,0 +1,177 @@
+/*
+ * 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.filters;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.security.Principal;
+import java.util.Map;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ResourceInfo;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.commons.codec.Charsets;
+import org.apache.commons.io.IOUtils;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.daemon.StormCommon;
+import org.apache.storm.daemon.common.JsonResponseBuilder;
+import org.apache.storm.daemon.ui.UIHelpers;
+import org.apache.storm.daemon.ui.resources.AuthNimbusOp;
+import org.apache.storm.daemon.ui.resources.StormApiResource;
+import org.apache.storm.generated.AuthorizationException;
+import org.apache.storm.security.auth.IAuthorizer;
+import org.apache.storm.security.auth.ReqContext;
+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;
+
+@Provider
+public class AuthorizedUserFilter implements ContainerRequestFilter {
+
+    public static final Logger LOG = LoggerFactory.getLogger(AuthorizedUserFilter.class);
+    public static Map<String, Object> conf = Utils.readStormConfig();
+    public static IAuthorizer uiImpersonationHandler;
+    public static IAuthorizer uiAclHandler;
+
+    @Context private ResourceInfo resourceInfo;
+
+    static {
+        try {
+            uiImpersonationHandler = StormCommon.mkAuthorizationHandler(
+                        (String) conf.get(DaemonConfig.NIMBUS_IMPERSONATION_AUTHORIZER), conf);
+            uiAclHandler = StormCommon.mkAuthorizationHandler(
+                    (String) conf.get(DaemonConfig.NIMBUS_AUTHORIZER), conf);
+        } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
+            LOG.error("Error initializing AuthorizedUserFilter: ", e);
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * makeResponse.
+     * @param ex ex
+     * @param request request
+     * @param statusCode statusCode
+     * @return error response
+     */
+    public static Response makeResponse(Exception ex, ContainerRequestContext request, int statusCode) {
+        String callback = null;
+
+        if (request.getMediaType().toString().contains("application/json")) {
+            try {
+                String json = IOUtils.toString(request.getEntityStream(), Charsets.UTF_8);
+                InputStream in = IOUtils.toInputStream(json);
+                request.setEntityStream(in);
+                Map<String, Object> requestBody = (Map<String, Object>) JSONValue.parse(json);
+                if (requestBody.containsKey(StormApiResource.callbackParameterName)) {
+                    callback = String.valueOf(requestBody.get(StormApiResource.callbackParameterName));
+                }
+            } catch (IOException e) {
+                LOG.error("Exception while trying to get callback ", e);
+            }
+        }
+        return new JsonResponseBuilder().setData(
+                        UIHelpers.exceptionToJson(ex, statusCode)).setCallback(callback)
+                        .setStatus(statusCode).build();
+    }
+
+    @Override
+    public void filter(ContainerRequestContext containerRequestContext) throws IOException {
+        AuthNimbusOp annotation = resourceInfo.getResourceMethod().getAnnotation(AuthNimbusOp.class);
+        if (annotation == null) {
+            return;
+        }
+        String op = annotation.value();
+        if (op == null) {
+            return;
+        }
+
+        Map topoConf = null;
+        if (annotation.needsTopoId()) {
+            NimbusClient nimbusClient = NimbusClient.getConfiguredClient(Utils.readStormConfig());
+            try {
+                topoConf = (Map) JSONValue.parse(nimbusClient.getClient().getTopologyConf(
+                        containerRequestContext.getUriInfo().getPathParameters().get("id").get(0)));
+            } catch (TException e) {
+                LOG.error("Unable to fetch topo conf for topo id due to ", e);
+                containerRequestContext.abortWith(
+                    makeResponse(new IOException("Unable to fetch topo conf for topo id " +
+                            containerRequestContext.getUriInfo().getPathParameters().get("id").get(0)),
+                            containerRequestContext, 500)
+                );
+            }
+        }
+
+        ReqContext reqContext = ReqContext.context();
+
+        if (reqContext.isImpersonating()) {
+            if (uiImpersonationHandler != null) {
+                if (!uiImpersonationHandler.permit(reqContext, op, topoConf)) {
+                    Principal realPrincipal = reqContext.realPrincipal();
+                    Principal principal = reqContext.principal();
+                    String user = "unknown";
+                    if (principal != null) {
+                        user = principal.getName();
+                    }
+                    String realUser = "unknown";
+                    if (realPrincipal != null) {
+                        realUser = realPrincipal.getName();
+                    }
+                    InetAddress remoteAddress = reqContext.remoteAddress();
+
+                    containerRequestContext.abortWith(
+                            makeResponse(new AuthorizationException(
+                                    "user '" + realUser +  "' is not authorized to impersonate user '"
+                                            + user + "' from host '" + remoteAddress.toString() + "'. Please"
+                                            + "see SECURITY.MD to learn how to configure impersonation ACL."
+                            ), containerRequestContext, 401)
+                    );
+                }
+
+            LOG.warn(" principal {} is trying to impersonate {} but {} has no authorizer configured. "
+                            + "This is a potential security hole. Please see SECURITY.MD to learn how to "
+                            + "configure an impersonation authorizer.",
+                    reqContext.realPrincipal().toString(), reqContext.principal().toString(),
+                    conf.get(DaemonConfig.NIMBUS_IMPERSONATION_AUTHORIZER));
+            }
+        }
+
+        if (uiAclHandler != null) {
+            if (!uiAclHandler.permit(reqContext, op, conf)) {
+                Principal principal = reqContext.principal();
+                String user = "unknown";
+                if (principal != null) {
+                    user = principal.getName();
+                }
+                containerRequestContext.abortWith(
+                        makeResponse(new AuthorizationException("UI request '" + op + "' for '"
+                                        + user + "' user is not authorized"),
+                                containerRequestContext, 401)
+                );
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/034ac677/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/HeaderResponseFilter.java
----------------------------------------------------------------------
diff --git a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/HeaderResponseFilter.java b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/HeaderResponseFilter.java
new file mode 100644
index 0000000..962a45f
--- /dev/null
+++ b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/HeaderResponseFilter.java
@@ -0,0 +1,44 @@
+/*
+ * 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.filters;
+
+import com.codahale.metrics.Meter;
+import java.io.IOException;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.ext.Provider;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@Provider
+public class HeaderResponseFilter implements ContainerResponseFilter {
+    public static final Logger LOG = LoggerFactory.getLogger(HeaderResponseFilter.class);
+
+    public static Meter webRequestMeter =
+            StormMetricsRegistry.registerMeter("num-web-requests");
+
+    @Override
+    public void filter(ContainerRequestContext containerRequestContext,
+                       ContainerResponseContext containerResponseContext) throws IOException {
+        webRequestMeter.mark();
+    }
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/034ac677/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/HeaderResponseServletFilter.java
----------------------------------------------------------------------
diff --git a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/HeaderResponseServletFilter.java b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/HeaderResponseServletFilter.java
new file mode 100644
index 0000000..84c424a
--- /dev/null
+++ b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/filters/HeaderResponseServletFilter.java
@@ -0,0 +1,66 @@
+/*
+ * 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.filters;
+
+import com.codahale.metrics.Meter;
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HeaderResponseServletFilter implements Filter {
+    public static final Logger LOG = LoggerFactory.getLogger(HeaderResponseServletFilter.class);
+
+    public static Meter webRequestMeter =
+            StormMetricsRegistry.registerMeter("num-web-requests");
+
+    public static Meter mainPageRequestMeter =
+            StormMetricsRegistry.registerMeter("ui:num-main-page-http-requests");
+
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+
+    }
+
+    @Override
+    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
+                         FilterChain filterChain) throws IOException, ServletException {
+        webRequestMeter.mark();
+        HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
+        HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
+        if ((httpRequest.getPathInfo()).equals("/index.html")) {
+            mainPageRequestMeter.mark();
+            httpResponse.addHeader("Cache-Control", "no-cache");
+        }
+        filterChain.doFilter(servletRequest, servletResponse);
+    }
+
+    @Override
+    public void destroy() {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/034ac677/storm-webapp/src/main/java/org/apache/storm/daemon/ui/resources/AuthNimbusOp.java
----------------------------------------------------------------------
diff --git a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/resources/AuthNimbusOp.java b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/resources/AuthNimbusOp.java
new file mode 100644
index 0000000..530f4af
--- /dev/null
+++ b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/resources/AuthNimbusOp.java
@@ -0,0 +1,39 @@
+/*
+ * 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 java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Documented
+@Retention(value = RetentionPolicy.RUNTIME)
+public @interface AuthNimbusOp {
+    /**
+     * nimbusOP.
+     * @return nimbusOp
+     */
+    String value();
+
+    /**
+     * needsTopoId.
+     * @return needsTopoId
+     */
+    boolean needsTopoId() default false;
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/034ac677/storm-webapp/src/main/java/org/apache/storm/daemon/ui/resources/StormApiResource.java
----------------------------------------------------------------------
diff --git a/storm-webapp/src/main/java/org/apache/storm/daemon/ui/resources/StormApiResource.java b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/resources/StormApiResource.java
new file mode 100644
index 0000000..6b3c014
--- /dev/null
+++ b/storm-webapp/src/main/java/org/apache/storm/daemon/ui/resources/StormApiResource.java
@@ -0,0 +1,711 @@
+/*
+ * 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);
+
+    public static final String callbackParameterName = "callback";
+
+    @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(callbackParameterName) String callback) throws TException {
+        clusterConfigurationRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    nimbusClient.getClient().getNimbusConf(),
+                    callback, false, Response.Status.OK
+            );
+        }
+    }
+
+    /**
+     * /api/v1/cluster/summary -> cluster summary.
+     */
+    @GET
+    @Path("/cluster/summary")
+    @AuthNimbusOp("getClusterInfo")
+    @Produces("application/json")
+    public Response getClusterSummary(@QueryParam(callbackParameterName) 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")
+    @AuthNimbusOp("getClusterInfo")
+    @Produces("application/json")
+    public Response getNimbusSummary(@QueryParam(callbackParameterName) 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")
+    @AuthNimbusOp("getOwnerResourceSummaries")
+    @Produces("application/json")
+    public Response getOwnerResources(@QueryParam(callbackParameterName) 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}")
+    @AuthNimbusOp(value = "getOwnerResourceSummaries", needsTopoId = true)
+    @Produces("application/json")
+    public Response getOwnerResource(@PathParam("id") String id,
+                                     @QueryParam(callbackParameterName) String callback) throws TException {
+        getOwnerResourceSummariesMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getOwnerResourceSummary(
+                            nimbusClient.getClient().getOwnerResourceSummaries(id), nimbusClient.getClient(),
+                            id, config),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/history/summary -> topo history.
+     */
+    @GET
+    @Path("/history/summary")
+    @Produces("application/json")
+    public Response getHistorySummary(@QueryParam(callbackParameterName) String callback) throws TException {
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            String user = servletRequest.getRemoteUser();
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologyHistoryInfo(
+                            nimbusClient.getClient().getTopologyHistory(user)),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/supervisor/summary -> topo history.
+     */
+    @GET
+    @Path("/supervisor/summary")
+    @AuthNimbusOp("getClusterInfo")
+    @Produces("application/json")
+    public Response getSupervisorSummary(@Context SecurityContext securityContext,
+                                         @QueryParam(callbackParameterName) String callback) throws TException {
+        supervisorSummaryRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getSupervisorSummary(
+                            nimbusClient.getClient().getClusterInfo().get_supervisors(),
+                            securityContext, config
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/supervisor -> topo history.
+     */
+    @GET
+    @Path("/supervisor")
+    @AuthNimbusOp("getSupervisorPageInfo")
+    @Produces("application/json")
+    public Response getSupervisor(@QueryParam("id") String id,
+                                  @QueryParam("host") String host,
+                                  @QueryParam("sys") boolean sys,
+                                  @QueryParam(callbackParameterName) String callback) throws TException {
+        supervisorRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getSupervisorPageInfo(
+                            nimbusClient.getClient().getSupervisorPageInfo(id, host, sys),
+                            config
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/summary -> topo history.
+     */
+    @GET
+    @Path("/topology/summary")
+    @AuthNimbusOp("getClusterInfo")
+    @Produces("application/json")
+    public Response getTopologySummary(@Context SecurityContext securityContext,
+                                       @QueryParam(callbackParameterName) String callback) throws TException {
+        allTopologiesSummaryRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getAllTopologiesSummary(
+                            nimbusClient.getClient().getClusterInfo().get_topologies(),
+                            config
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology -> topo.
+     */
+    @GET
+    @Path("/topology/{id}")
+    @AuthNimbusOp(value = "getTopology", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopology(@PathParam("id") String id,
+                                @DefaultValue(":all-time") @QueryParam("window") String window,
+                                @QueryParam("sys") boolean sys,
+                                @QueryParam(callbackParameterName) String callback) throws TException {
+        topologyPageRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologySummary(
+                            nimbusClient.getClient().getTopologyPageInfo(id, window, sys),
+                            window, config,
+                            servletRequest.getRemoteUser()
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology-workers/:id -> topo workers.
+     */
+    @GET
+    @Path("/topology-workers/{id}")
+    @AuthNimbusOp(value = "getTopology", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyWorkers(@PathParam("id") String id,
+                                       @QueryParam(callbackParameterName) String callback) throws TException {
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            id = URLDecoder.decode(id);
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologyWorkers(
+                            nimbusClient.getClient().getTopologyInfo(id), config
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/metrics -> metrics.
+     */
+    @GET
+    @Path("/topology/{id}/metrics")
+    @AuthNimbusOp(value = "getTopology", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyMetrics(@PathParam("id") String id,
+                                       @DefaultValue(":all-time") @QueryParam("window") String window,
+                                       @QueryParam("sys") boolean sys,
+                                       @QueryParam(callbackParameterName) String callback) throws TException {
+        topologyMetricRequestMeter.mark();
+        String user = servletRequest.getRemoteUser();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologySummary(
+                            nimbusClient.getClient().getTopologyPageInfo(id, window, sys), window, config, user
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/lag -> lag.
+     */
+    @GET
+    @Path("/topology/{id}/lag")
+    @AuthNimbusOp(value = "getTopology", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyLag(@PathParam("id") String id,
+                                   @QueryParam(callbackParameterName) String callback) throws TException {
+        topologyLagRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologyLag(nimbusClient.getClient().getTopology(id), config),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/visualization-init -> visualization-init.
+     */
+    @GET
+    @Path("/topology/{id}/visualization-init")
+    @AuthNimbusOp(value = "getTopology", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyVisializationInit(@PathParam("id") String id,
+                                                 @QueryParam("sys") boolean sys,
+                                                 @QueryParam(callbackParameterName) String callback,
+                                                 @DefaultValue(":all-time") @QueryParam("window") String window
+    ) throws TException {
+        mkVisualizationDataRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getBuildVisualization(nimbusClient.getClient(), config, window, id, sys),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/visualization -> visualization.
+     */
+    @GET
+    @Path("/topology/{id}/visualization")
+    @AuthNimbusOp(value = "getTopology", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyVisualization(@PathParam("id") String id,
+                                             @QueryParam("sys") boolean sys,
+                                             @QueryParam(callbackParameterName) String callback,
+                                             @DefaultValue(":all-time") @QueryParam("window") String window
+    ) throws TException {
+        buildVisualizationRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getVisualizationData(nimbusClient.getClient(), window, id, sys),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1//topology/:id/component/:component -> component.
+     */
+    @GET
+    @Path("/topology/{id}/component/{component}")
+    @AuthNimbusOp(value = "getTopology", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyComponent(@PathParam("id") String id,
+                                         @PathParam("component") String component,
+                                         @QueryParam("sys") boolean sys,
+                                         @QueryParam(callbackParameterName) String callback,
+                                         @DefaultValue(":all-time") @QueryParam("window") String window
+                                         ) throws TException {
+        componentPageRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            String user = servletRequest.getRemoteUser();
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getComponentPage(
+                            nimbusClient.getClient(), id, component,
+                            window, sys, user, config
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/logconfig -> logconfig.
+     */
+    @GET
+    @Path("/topology/{id}/logconfig")
+    @AuthNimbusOp(value = "getTopology", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyLogconfig(@PathParam("id") String id,
+                                         @QueryParam(callbackParameterName) String callback) throws TException {
+        logConfigRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopolgoyLogConfig(nimbusClient.getClient().getLogConfig(id)),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/logconfig -> logconfig.
+     */
+    @POST
+    @Path("/topology/{id}/logconfig")
+    @AuthNimbusOp(value = "setLogConfig", needsTopoId = true)
+    @Produces("application/json")
+    @Consumes("application/json")
+    public Response putTopologyLogconfig(@PathParam("id") String id, String body,
+                                         @QueryParam(callbackParameterName) String callback) throws TException {
+        topologyOpResponseMeter.mark();
+        LOG.info("HELLISh");
+        LOG.info(body);
+        LOG.info(id);
+        LOG.info(callback);
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.putTopologyLogLevel(nimbusClient.getClient(),
+                            ((Map<String, Map>) JSONValue.parse(body)).get("namedLoggerLevels"), id),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/activate -> topology activate.
+     */
+    @POST
+    @Path("/topology/{id}/activate")
+    @AuthNimbusOp(value = "activate", needsTopoId = true)
+    @Produces("application/json")
+    public Response putTopologyActivate(@PathParam("id") String id,
+                                        @QueryParam(callbackParameterName) String callback) throws TException {
+        activateTopologyRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.putTopologyActivate(nimbusClient.getClient(), id),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/deactivate -> topology deactivate.
+     */
+    @POST
+    @Path("/topology/{id}/deactivate")
+    @AuthNimbusOp(value = "deactivate", needsTopoId = true)
+    @Produces("application/json")
+    public Response putTopologyDeactivate(@PathParam("id") String id,
+                                          @QueryParam(callbackParameterName) String callback) throws TException {
+        deactivateTopologyRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.putTopologyDeactivate(nimbusClient.getClient(), id),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/debug/:action/:spct -> debug action.
+     */
+    @POST
+    @Path("/topology/{id}/debug/{action}/{spct}")
+    @AuthNimbusOp(value = "debug", needsTopoId = true)
+    @Produces("application/json")
+    public Response putTopologyDebugActionSpct(@PathParam("id") String id,
+                                               @PathParam("action") String action,
+                                               @PathParam("spct") String spct,
+                                               @QueryParam(callbackParameterName) String callback) throws TException {
+        debugTopologyRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.putTopologyDebugActionSpct(
+                            nimbusClient.getClient(), id, action, spct, ""
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/component/:component/debug/:action/:spct -> debug component action.
+     */
+    @POST
+    @Path("/topology/{id}/component/{component}/debug/{action}/{spct}")
+    @AuthNimbusOp(value = "debug", needsTopoId = true)
+    @Produces("application/json")
+    public Response putTopologyComponentDebugActionSpct(
+            @PathParam("id") String id,
+            @PathParam("component") String component,
+            @PathParam("action") String action,
+            @PathParam("spct") String spct,
+            @QueryParam(callbackParameterName) String callback) throws TException {
+        componentOpResponseRequestMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.putTopologyDebugActionSpct(
+                            nimbusClient.getClient(), id, component, action, spct
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/rebalance/:wait-time -> topology rebalance.
+     */
+    @POST
+    @Path("/topology/{id}/rebalance/{wait-time}")
+    @AuthNimbusOp(value = "rebalance", needsTopoId = true)
+    @Produces("application/json")
+    public Response putTopologyRebalance(@PathParam("id") String id,
+                                         @PathParam("wait-time") String waitTime,
+                                         @QueryParam(callbackParameterName) String callback) throws TException {
+        topologyOpResponseMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.putTopologyRebalance(
+                            nimbusClient.getClient(), id, waitTime
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/kill/:wait-time -> topology kill.
+     */
+    @POST
+    @Path("/topology/{id}/kill/{wait-time}")
+    @AuthNimbusOp(value = "killTopology", needsTopoId = true)
+    @Produces("application/json")
+    public Response putTopologyKill(
+            @PathParam("id") String id,
+            @PathParam("wait-time") String waitTime,
+            @QueryParam(callbackParameterName) String callback) throws TException {
+            topologyOpResponseMeter.mark();
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.putTopologyKill(nimbusClient.getClient(), id, waitTime),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/profiling/start/:host-port/:timeout -> profiling tart.
+     */
+    @GET
+    @Path("/topology/{id}/profiling/start/{host-port}/{timeout}")
+    @AuthNimbusOp(value = "setWorkerProfiler", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyProfilingStart(@PathParam("id") String id,
+                                              @PathParam("host-port") String hostPort,
+                                              @PathParam("timeout") String timeout,
+                                              @QueryParam(callbackParameterName) String callback) throws TException {
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologyProfilingStart(nimbusClient.getClient(), id, hostPort, timeout, config),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/profiling/stop/:host-port/:timeout -> profiling stop.
+     */
+    @GET
+    @Path("/topology/{id}/profiling/stop/{host-port}/{timeout}")
+    @AuthNimbusOp(value = "setWorkerProfiler", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyProfilingStop(@PathParam("id") String id,
+                                             @PathParam("host-port") String hostPort,
+                                             @PathParam("timeout") String timeout,
+                                             @QueryParam(callbackParameterName) String callback) throws TException {
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologyProfilingStop(nimbusClient.getClient(), id, hostPort, timeout, config),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/profiling/dumpprofile/:host-port/:timeout -> dump profile.
+     */
+    @GET
+    @Path("/topology/{id}/profiling/dumpprofile/{host-port}/{timeout}")
+    @AuthNimbusOp(value = "setWorkerProfiler", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyProfilingDumpProfile(@PathParam("id") String id,
+                                                    @PathParam("host-port") String hostPort,
+                                                    @PathParam("timeout") String timeout,
+                                                    @QueryParam(callbackParameterName) String callback) throws TException {
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologyProfilingDump(nimbusClient.getClient(), id, hostPort, timeout, config),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/profiling/restartworker/:host-port/:timeout -> restart worker.
+     */
+    @GET
+    @Path("/topology/{id}/profiling/restartworker/{host-port}/{timeout}")
+    @AuthNimbusOp(value = "setWorkerProfiler", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyProfilingRestartWorker(@PathParam("id") String id,
+                                                      @PathParam("host-port") String hostPort,
+                                                      @PathParam("timeout") String timeout,
+                                                      @QueryParam(callbackParameterName) String callback) throws TException {
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologyProfilingRestartWorker(
+                            nimbusClient.getClient(), id, hostPort, timeout, config
+                    ),
+                    callback
+            );
+        }
+    }
+
+    /**
+     * /api/v1/topology/:id/profiling/dumpheap/:host-port/:timeout -> dump heap.
+     */
+    @GET
+    @Path("/topology/{id}/profiling/dumpheap/{host-port}/{timeout}")
+    @AuthNimbusOp(value = "setWorkerProfiler", needsTopoId = true)
+    @Produces("application/json")
+    public Response getTopologyProfilingDumpheap(@PathParam("id") String id,
+                                                 @PathParam("host-port") String hostPort,
+                                                 @PathParam("timeout") String timeout,
+                                                 @QueryParam(callbackParameterName) String callback) throws TException {
+        try (NimbusClient nimbusClient = NimbusClient.getConfiguredClient(config)) {
+            return UIHelpers.makeStandardResponse(
+                    UIHelpers.getTopologyProfilingDumpHeap(
+                            nimbusClient.getClient(), id, hostPort, timeout, config
+                    ),
+                    callback
+            );
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/034ac677/storm-webapp/src/test/java/org/apache/storm/daemon/logviewer/handler/LogviewerLogSearchHandlerTest.java
----------------------------------------------------------------------
diff --git a/storm-webapp/src/test/java/org/apache/storm/daemon/logviewer/handler/LogviewerLogSearchHandlerTest.java b/storm-webapp/src/test/java/org/apache/storm/daemon/logviewer/handler/LogviewerLogSearchHandlerTest.java
index 32d9435..c7a1fd8 100644
--- a/storm-webapp/src/test/java/org/apache/storm/daemon/logviewer/handler/LogviewerLogSearchHandlerTest.java
+++ b/storm-webapp/src/test/java/org/apache/storm/daemon/logviewer/handler/LogviewerLogSearchHandlerTest.java
@@ -52,7 +52,7 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.storm.DaemonConfig;
 import org.apache.storm.daemon.logviewer.LogviewerConstant;
 import org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer;
-import org.apache.storm.ui.InvalidRequestException;
+import org.apache.storm.daemon.ui.InvalidRequestException;
 import org.apache.storm.utils.Utils;
 import org.jooq.lambda.Seq;
 import org.jooq.lambda.Unchecked;


Mime
View raw message