You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by hustfxj <gi...@git.apache.org> on 2016/02/26 16:17:32 UTC
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
GitHub user hustfxj opened a pull request:
https://github.com/apache/storm/pull/1156
[STORM-1270] [STORM-1274] port drpc&LocalDRPC to java
1. Port "org.apache.storm.daemon.drpc" to java at "org.apache.storm.daemon.DrpcServer".
2. Port "org.apache.storm.LocalDRPC" to java at "org.apache.storm.LocalDRPC".
3. I keep the "webapp" of drpc.clj , as it's hard to translate and we will move ring to other REST framework.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/hustfxj/storm DRPC
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/storm/pull/1156.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1156
----
commit 2040fee56e9a3c0614cd50e30a93389ea2843a77
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-19T00:59:43Z
port drpc.clj to java
commit 2854d9ee357bf2b03af5801ffe64b3380bd621b6
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-23T04:18:31Z
rename DrpcProcess
commit 9178b1c8fb7a77dde0608a285d9adc8d0b767867
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-26T06:13:23Z
Merge branch 'master' into LocalDRPC
commit 802d28e607ce953664fcea7356eac98fb354683f
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-26T12:32:29Z
update some tests about drpc
commit 8e350d1cf1f16b0101d699de0016bb762061f1e3
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-26T14:59:02Z
let ManualDRPC throw Exception
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54632535
--- Diff: storm-core/test/clj/org/apache/storm/security/auth/auth_test.clj ---
@@ -27,6 +27,8 @@
(:import [javax.security.auth Subject])
(:import [java.net InetAddress])
(:import [org.apache.storm Config])
+ (:import [org.mockito Mockito])
+ (:import [org.mockito.exceptions.base MockitoAssertionError])
--- End diff --
Are these needed? If not please revert. If so how did this work before?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54304501
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
--- End diff --
minor nit. There were parens around the funcArgs
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54626696
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,383 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ //TODO: To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+
+ //TODO: to be replaced by a common registry
+ private final static Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ //TODO: to be removed
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception{
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ //TODO: To be replaced by Common.StartMetricsReporters
--- End diff --
This should probably be moved into #1171 and just do it there.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55503401
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
--- End diff --
@revans2 I can see the same errors when I run Drpc of master branch. Later I find we maybe misunderstand it. As follows:
$ curl http://localhost:3774/drpc/exclamation/hi
hi!
It's ok. So the URL should like ""/drpc/:func/*"
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55392686
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, InternalRequest> e : outstandingRequests.entrySet()) {
+ InternalRequest internalRequest = e.getValue();
+ if (Time.deltaSecs(internalRequest.startTimeSecs) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS))) {
+ String id = e.getKey();
+ Semaphore sem = internalRequest.sem;
+ if (sem != null) {
+ String func = internalRequest.function;
+ acquireQueue(func).remove(internalRequest.request);
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer() throws Exception {
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ initThrift();
+ initHttp();
+ }
+
+ @Override
+ public void close() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ outstandingRequests.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} ({}) at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int newid = 0;
+ int orig = 0;
+ do {
+ orig = ctr.get();
+ newid = (orig + 1) % 1000000000;
+ } while (!ctr.compareAndSet(orig, newid));
+ String strid = String.valueOf(newid);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ InternalRequest internalRequest = new InternalRequest(functionName, req);
+ this.outstandingRequests.put(strid, internalRequest);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ internalRequest.sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = internalRequest.result;
+
+ LOG.debug("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return (String) result;
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ InternalRequest internalRequest = this.outstandingRequests.get(id);
+ if (internalRequest != null) {
+ Map<String, String> map = ImmutableMap.of(DRPCAuthorizerBase.FUNCTION_NAME, internalRequest.function);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = internalRequest.sem;
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ internalRequest.result = result;
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ InternalRequest internalRequest = this.outstandingRequests.get(id);
+ if (internalRequest != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, internalRequest.function);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = internalRequest.sem;
+ if (sem != null) {
+ internalRequest.result = new DRPCExecutionException("Request failed");
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<>();
+ ConcurrentLinkedQueue<DRPCRequest> old = requestQueues.putIfAbsent(function, reqQueue);
+ if (old != null) {
+ reqQueue = old;
+ }
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
--- End diff --
It is called, on line 337
```
private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation) throws AuthorizationException {
checkAuthorization(aclHandler, mapping, operation, ReqContext.context());
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj closed the pull request at:
https://github.com/apache/storm/pull/1156
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54622613
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,383 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ //TODO: To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+
+ //TODO: to be replaced by a common registry
+ private final static Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ //TODO: to be removed
--- End diff --
Please remove this comment.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54622279
--- Diff: storm-core/src/jvm/org/apache/storm/LocalDRPC.java ---
@@ -0,0 +1,80 @@
+/**
+ * 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;
+
+import org.apache.log4j.Logger;
+import org.apache.storm.daemon.DrpcServer;
+import org.apache.storm.generated.AuthorizationException;
+import org.apache.storm.generated.DRPCExecutionException;
+import org.apache.storm.generated.DRPCRequest;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.ServiceRegistry;
+import org.apache.storm.utils.Utils;
+import org.apache.thrift.TException;
+
+import java.util.Map;
+
+public class LocalDRPC implements ILocalDRPC {
+ private static final Logger LOG = Logger.getLogger(LocalDRPC.class);
+
+ private DrpcServer handler = new DrpcServer();
+ private Thread thread;
--- End diff --
This is never used and should be removed.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54300044
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
--- End diff --
To make code more clean, can we have methods like below
```
String registerRequest(functionName, functionArgs) - Creates a new id with the function name
awaitOnResult(id) - blocks on the semaphore associated with the id
notifyOnResult(id) - releases the semaphore associated with the id
updateResult(id, Object result) - update the result
removeRequest(id) - Cleanup the request
```
The above four methods can go into a class named DRPCState/DRPCRequestRegistry. what do you think?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54307415
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = this.idtoSem.get(id);
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ this.idtoResult.put(id, result);
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = this.idtoSem.get(id);
+ if (sem != null) {
+ this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<DRPCRequest>();
+ requestQueues.put(function, reqQueue);
--- End diff --
This should be a putIfAbsent.
```
protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
if (reqQueue == null) {
reqQueue = new ConcurrentLinkedQueue<>();
ConcurrentLinkedQueue<DRPCRequest> old = requestQueues.putIfAbsent(function, reqQueue);
if (old != null) {
reqQueue = old;
}
}
return reqQueue;
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54299455
--- Diff: examples/storm-starter/src/jvm/org/apache/storm/starter/ManualDRPC.java ---
@@ -30,39 +30,37 @@
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;
-
public class ManualDRPC {
- public static class ExclamationBolt extends BaseBasicBolt {
-
- @Override
- public void declareOutputFields(OutputFieldsDeclarer declarer) {
- declarer.declare(new Fields("result", "return-info"));
- }
+ public static class ExclamationBolt extends BaseBasicBolt {
- @Override
- public void execute(Tuple tuple, BasicOutputCollector collector) {
- String arg = tuple.getString(0);
- Object retInfo = tuple.getValue(1);
- collector.emit(new Values(arg + "!!!", retInfo));
- }
+ @Override
+ public void declareOutputFields(OutputFieldsDeclarer declarer) {
+ declarer.declare(new Fields("result", "return-info"));
+ }
- }
+ @Override
+ public void execute(Tuple tuple, BasicOutputCollector collector) {
+ String arg = tuple.getString(0);
+ Object retInfo = tuple.getValue(1);
+ collector.emit(new Values(arg + "!!!", retInfo));
+ }
- public static void main(String[] args) {
- TopologyBuilder builder = new TopologyBuilder();
- LocalDRPC drpc = new LocalDRPC();
+ }
- DRPCSpout spout = new DRPCSpout("exclamation", drpc);
- builder.setSpout("drpc", spout);
- builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc");
- builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim");
+ public static void main(String[] args) throws Exception{
+ TopologyBuilder builder = new TopologyBuilder();
+ LocalDRPC drpc = new LocalDRPC();
- LocalCluster cluster = new LocalCluster();
- Config conf = new Config();
- cluster.submitTopology("exclaim", conf, builder.createTopology());
+ DRPCSpout spout = new DRPCSpout("exclamation", drpc);
+ builder.setSpout("drpc", spout);
+ builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc");
+ builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim");
- System.out.println(drpc.execute("exclamation", "aaa"));
- System.out.println(drpc.execute("exclamation", "bbb"));
+ LocalCluster cluster = new LocalCluster();
+ Config conf = new Config();
+ cluster.submitTopology("exclaim", conf, builder.createTopology());
- }
+ System.out.println(drpc.execute("exclamation", "aaa"));
+ System.out.println(drpc.execute("exclamation", "bbb"));
+ }
}
--- End diff --
Please don't change the spacing/formatting for files you didn't touch otherwise.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54623479
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,383 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ //TODO: To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+
+ //TODO: to be replaced by a common registry
+ private final static Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ //TODO: to be removed
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception{
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ //TODO: To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin: {}", reporter);
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, InternalRequest> e : outstandingRequests.entrySet()) {
+ InternalRequest internalRequest = e.getValue();
+ if (Time.deltaSecs(internalRequest.startTimeSecs) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
--- End diff --
There was no default of 0 in the original code and we should probably not have one here either.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55392710
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = this.idtoSem.get(id);
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ this.idtoResult.put(id, result);
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = this.idtoSem.get(id);
+ if (sem != null) {
+ this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<DRPCRequest>();
+ requestQueues.put(function, reqQueue);
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
+ if (reqContext != null) {
+ ThriftAccessLogger.logAccess(reqContext.requestID(), reqContext.remoteAddress(), reqContext.principal(), operation);
+ }
+ if (aclHandler != null) {
+ if (reqContext == null)
+ reqContext = ReqContext.context();
+ if (!aclHandler.permit(reqContext, operation, mapping)) {
+ Principal principal = reqContext.principal();
+ String user = (principal != null) ? principal.getName() : "unknown";
+ throw new AuthorizationException("DRPC request '" + operation + "' for '" + user + "' user is not authorized");
+ }
+ }
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation) throws AuthorizationException {
+ checkAuthorization(aclHandler, mapping, operation, ReqContext.context());
+ }
+
+ // TO be replaced by Common.mkAuthorizationHandler
--- End diff --
OK
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55354774
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, InternalRequest> e : outstandingRequests.entrySet()) {
+ InternalRequest internalRequest = e.getValue();
+ if (Time.deltaSecs(internalRequest.startTimeSecs) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS))) {
+ String id = e.getKey();
+ Semaphore sem = internalRequest.sem;
+ if (sem != null) {
+ String func = internalRequest.function;
+ acquireQueue(func).remove(internalRequest.request);
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer() throws Exception {
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ initThrift();
+ initHttp();
+ }
+
+ @Override
+ public void close() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ outstandingRequests.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} ({}) at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int newid = 0;
+ int orig = 0;
+ do {
+ orig = ctr.get();
+ newid = (orig + 1) % 1000000000;
+ } while (!ctr.compareAndSet(orig, newid));
+ String strid = String.valueOf(newid);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ InternalRequest internalRequest = new InternalRequest(functionName, req);
+ this.outstandingRequests.put(strid, internalRequest);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ internalRequest.sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = internalRequest.result;
+
+ LOG.debug("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return (String) result;
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ InternalRequest internalRequest = this.outstandingRequests.get(id);
+ if (internalRequest != null) {
+ Map<String, String> map = ImmutableMap.of(DRPCAuthorizerBase.FUNCTION_NAME, internalRequest.function);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = internalRequest.sem;
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ internalRequest.result = result;
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ InternalRequest internalRequest = this.outstandingRequests.get(id);
+ if (internalRequest != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, internalRequest.function);
+ checkAuthorization(authorizer, map, "failRequest");
--- End diff --
It would be good to have operation names declared as public static variables.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54632449
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = this.idtoSem.get(id);
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ this.idtoResult.put(id, result);
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = this.idtoSem.get(id);
+ if (sem != null) {
+ this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<DRPCRequest>();
+ requestQueues.put(function, reqQueue);
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
+ if (reqContext != null) {
+ ThriftAccessLogger.logAccess(reqContext.requestID(), reqContext.remoteAddress(), reqContext.principal(), operation);
+ }
+ if (aclHandler != null) {
+ if (reqContext == null)
+ reqContext = ReqContext.context();
+ if (!aclHandler.permit(reqContext, operation, mapping)) {
+ Principal principal = reqContext.principal();
+ String user = (principal != null) ? principal.getName() : "unknown";
+ throw new AuthorizationException("DRPC request '" + operation + "' for '" + user + "' user is not authorized");
+ }
+ }
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation) throws AuthorizationException {
+ checkAuthorization(aclHandler, mapping, operation, ReqContext.context());
+ }
+
+ // TO be replaced by Common.mkAuthorizationHandler
+ private IAuthorizer mkAuthorizationHandler(String klassname, Map conf) {
+ IAuthorizer authorizer = null;
+ Class aznClass = null;
+ if (StringUtils.isNotBlank(klassname)) {
+ try {
+ aznClass = Class.forName(klassname);
+ authorizer = (IAuthorizer) aznClass.newInstance();
+ if (authorizer != null) {
--- End diff --
This is still an issue to be fixed.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54333182
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = this.idtoSem.get(id);
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ this.idtoResult.put(id, result);
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = this.idtoSem.get(id);
+ if (sem != null) {
+ this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<DRPCRequest>();
+ requestQueues.put(function, reqQueue);
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
+ if (reqContext != null) {
+ ThriftAccessLogger.logAccess(reqContext.requestID(), reqContext.remoteAddress(), reqContext.principal(), operation);
+ }
+ if (aclHandler != null) {
+ if (reqContext == null)
+ reqContext = ReqContext.context();
+ if (!aclHandler.permit(reqContext, operation, mapping)) {
+ Principal principal = reqContext.principal();
+ String user = (principal != null) ? principal.getName() : "unknown";
+ throw new AuthorizationException("DRPC request '" + operation + "' for '" + user + "' user is not authorized");
+ }
+ }
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation) throws AuthorizationException {
+ checkAuthorization(aclHandler, mapping, operation, ReqContext.context());
+ }
+
+ // TO be replaced by Common.mkAuthorizationHandler
--- End diff --
common.clj maybe submit soon
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54287568
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
--- End diff --
Duplicate log statement
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54624316
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
--- End diff --
Yes it should the original code was more of
```
if (handlerServer != null) handlerServer.stop();
invokeServer.stop();
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54298226
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = this.idtoSem.get(id);
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ this.idtoResult.put(id, result);
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = this.idtoSem.get(id);
+ if (sem != null) {
+ this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<DRPCRequest>();
+ requestQueues.put(function, reqQueue);
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
+ if (reqContext != null) {
+ ThriftAccessLogger.logAccess(reqContext.requestID(), reqContext.remoteAddress(), reqContext.principal(), operation);
+ }
+ if (aclHandler != null) {
+ if (reqContext == null)
+ reqContext = ReqContext.context();
+ if (!aclHandler.permit(reqContext, operation, mapping)) {
+ Principal principal = reqContext.principal();
+ String user = (principal != null) ? principal.getName() : "unknown";
+ throw new AuthorizationException("DRPC request '" + operation + "' for '" + user + "' user is not authorized");
+ }
+ }
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation) throws AuthorizationException {
+ checkAuthorization(aclHandler, mapping, operation, ReqContext.context());
+ }
+
+ // TO be replaced by Common.mkAuthorizationHandler
+ private IAuthorizer mkAuthorizationHandler(String klassname, Map conf) {
+ IAuthorizer authorizer = null;
+ Class aznClass = null;
+ if (StringUtils.isNotBlank(klassname)) {
+ try {
+ aznClass = Class.forName(klassname);
+ authorizer = (IAuthorizer) aznClass.newInstance();
+ if (authorizer != null) {
--- End diff --
newInstance shouldn't return null
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54302621
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
--- End diff --
the set and get of HttpCredsHandler is never used.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55503487
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
--- End diff --
@revans2 I have adjust the order of initHttp(). Thank you again.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54300063
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
--- End diff --
We should not be using com.sun internal classes. We didn't use them before we should not use them now.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54304399
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
--- End diff --
Never mind the old code launched the clear-thread in service-handler. To me it feels cleaner to have the Constructor act like service-handler and launchServer to start up the thrift servers and HTTP Server.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
GitHub user hustfxj reopened a pull request:
https://github.com/apache/storm/pull/1156
[STORM-1270] [STORM-1274] port drpc&LocalDRPC to java
1. Port "org.apache.storm.daemon.drpc" to java at "org.apache.storm.daemon.DrpcServer".
2. Port "org.apache.storm.LocalDRPC" to java at "org.apache.storm.LocalDRPC".
3. I keep the "webapp" of drpc.clj , as it's hard to translate and we will move ring to other REST framework.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/hustfxj/storm DRPC
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/storm/pull/1156.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1156
----
commit 2040fee56e9a3c0614cd50e30a93389ea2843a77
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-19T00:59:43Z
port drpc.clj to java
commit 2854d9ee357bf2b03af5801ffe64b3380bd621b6
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-23T04:18:31Z
rename DrpcProcess
commit 9178b1c8fb7a77dde0608a285d9adc8d0b767867
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-26T06:13:23Z
Merge branch 'master' into LocalDRPC
commit 802d28e607ce953664fcea7356eac98fb354683f
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-26T12:32:29Z
update some tests about drpc
commit 8e350d1cf1f16b0101d699de0016bb762061f1e3
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-26T14:59:02Z
let ManualDRPC throw Exception
commit 491ff9856eaaa8bc0bab6dbc073016b920500216
Author: xiaojian.fxj <xi...@alibaba-inc.com>
Date: 2016-02-27T03:59:05Z
update DrpcServer code based on revans2 and abhishekagarwal87
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54664622
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
--- End diff --
sorry. I make mistake
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54307644
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = this.idtoSem.get(id);
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ this.idtoResult.put(id, result);
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = this.idtoSem.get(id);
+ if (sem != null) {
+ this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<DRPCRequest>();
+ requestQueues.put(function, reqQueue);
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
+ if (reqContext != null) {
+ ThriftAccessLogger.logAccess(reqContext.requestID(), reqContext.remoteAddress(), reqContext.principal(), operation);
+ }
+ if (aclHandler != null) {
+ if (reqContext == null)
+ reqContext = ReqContext.context();
+ if (!aclHandler.permit(reqContext, operation, mapping)) {
+ Principal principal = reqContext.principal();
+ String user = (principal != null) ? principal.getName() : "unknown";
+ throw new AuthorizationException("DRPC request '" + operation + "' for '" + user + "' user is not authorized");
+ }
+ }
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation) throws AuthorizationException {
+ checkAuthorization(aclHandler, mapping, operation, ReqContext.context());
+ }
+
+ // TO be replaced by Common.mkAuthorizationHandler
--- End diff --
Then lets create the file and just put it in there now, so the next person does not have to do it later.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54622905
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,383 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ //TODO: To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+
+ //TODO: to be replaced by a common registry
+ private final static Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
--- End diff --
In the original code clear-thread was started in the service-handler (which is the equivalent of the constructor). I would like to see it started here too, but that will require the constructor to take the Config.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54330354
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
--- End diff --
You can add them in the InternalRequest class suggested by Robert.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54299761
--- Diff: storm-core/src/clj/org/apache/storm/daemon/drpc.clj ---
@@ -210,67 +63,19 @@
(wrap-reload '[org.apache.storm.daemon.drpc])
handle-request))
+
(defn launch-server!
([]
- (log-message "Starting drpc server for storm version '" STORM-VERSION "'")
(let [conf (clojurify-structure (ConfigUtils/readStormConfig))
- worker-threads (int (conf DRPC-WORKER-THREADS))
- queue-size (int (conf DRPC-QUEUE-SIZE))
drpc-http-port (int (conf DRPC-HTTP-PORT))
- drpc-port (int (conf DRPC-PORT))
- drpc-service-handler (service-handler conf)
- ;; requests and returns need to be on separate thread pools, since calls to
- ;; "execute" don't unblock until other thrift methods are called. So if
- ;; 64 threads are calling execute, the server won't accept the result
- ;; invocations that will unblock those threads
- handler-server (when (> drpc-port 0)
- (ThriftServer. conf
- (DistributedRPC$Processor. drpc-service-handler)
- ThriftConnectionType/DRPC))
- invoke-server (ThriftServer. conf
- (DistributedRPCInvocations$Processor. drpc-service-handler)
- ThriftConnectionType/DRPC_INVOCATIONS)
+ drpc-server (DrpcServer.)
http-creds-handler (AuthUtils/GetDrpcHttpCredentialsPlugin conf)]
- (Utils/addShutdownHookWithForceKillIn1Sec (fn []
- (if handler-server (.stop handler-server))
- (.stop invoke-server)))
- (log-message "Starting Distributed RPC servers...")
- (future (.serve invoke-server))
(when (> drpc-http-port 0)
- (let [app (-> (webapp drpc-service-handler http-creds-handler)
- requests-middleware)
- filter-class (conf DRPC-HTTP-FILTER)
- filter-params (conf DRPC-HTTP-FILTER-PARAMS)
- filters-confs [(FilterConfiguration. filter-class filter-params)]
- https-port (int (or (conf DRPC-HTTPS-PORT) 0))
- https-ks-path (conf DRPC-HTTPS-KEYSTORE-PATH)
- https-ks-password (conf DRPC-HTTPS-KEYSTORE-PASSWORD)
- https-ks-type (conf DRPC-HTTPS-KEYSTORE-TYPE)
- https-key-password (conf DRPC-HTTPS-KEY-PASSWORD)
- https-ts-path (conf DRPC-HTTPS-TRUSTSTORE-PATH)
- https-ts-password (conf DRPC-HTTPS-TRUSTSTORE-PASSWORD)
- https-ts-type (conf DRPC-HTTPS-TRUSTSTORE-TYPE)
- https-want-client-auth (conf DRPC-HTTPS-WANT-CLIENT-AUTH)
- https-need-client-auth (conf DRPC-HTTPS-NEED-CLIENT-AUTH)]
-
- (UIHelpers/stormRunJetty
- (int drpc-http-port)
- (reify IConfigurator (execute [this server]
- (UIHelpers/configSsl server
- https-port
- https-ks-path
- https-ks-password
- https-ks-type
- https-key-password
- https-ts-path
- https-ts-password
- https-ts-type
- https-need-client-auth
- https-want-client-auth)
- (UIHelpers/configFilter server (ring.util.servlet/servlet app) filters-confs))))))
- (start-metrics-reporters conf)
- (when handler-server
- (.serve handler-server)))))
+ (let [app (-> (webapp drpc-server http-creds-handler)
--- End diff --
Can we please have a follow on JIRA to port the webapp portion over to java too? Until it is done I don't consider DRPC moved to java.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54305940
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
--- End diff --
This does not actually do the same thing. what happens if the compareAndSet fails? If you want it the same we have to loop around and try again until it succeeds.
```
int newid = 0;
do {
int orig = ctr.get();
newid = (orig + 1) % 1000000000;
} while (!ctr.compareAndSet(orig, newid));
String strid = String.valueOf(newid);
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54302948
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = this.idtoSem.get(id);
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ this.idtoResult.put(id, result);
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = this.idtoSem.get(id);
+ if (sem != null) {
+ this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<DRPCRequest>();
+ requestQueues.put(function, reqQueue);
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
+ if (reqContext != null) {
+ ThriftAccessLogger.logAccess(reqContext.requestID(), reqContext.remoteAddress(), reqContext.principal(), operation);
+ }
+ if (aclHandler != null) {
+ if (reqContext == null)
+ reqContext = ReqContext.context();
+ if (!aclHandler.permit(reqContext, operation, mapping)) {
+ Principal principal = reqContext.principal();
+ String user = (principal != null) ? principal.getName() : "unknown";
+ throw new AuthorizationException("DRPC request '" + operation + "' for '" + user + "' user is not authorized");
+ }
+ }
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation) throws AuthorizationException {
+ checkAuthorization(aclHandler, mapping, operation, ReqContext.context());
+ }
+
+ // TO be replaced by Common.mkAuthorizationHandler
+ private IAuthorizer mkAuthorizationHandler(String klassname, Map conf) {
+ IAuthorizer authorizer = null;
+ Class aznClass = null;
+ if (StringUtils.isNotBlank(klassname)) {
+ try {
+ aznClass = Class.forName(klassname);
+ authorizer = (IAuthorizer) aznClass.newInstance();
+ if (authorizer != null) {
+ authorizer.prepare(conf);
+ }
+ } catch (Exception e) {
+ LOG.error("mkAuthorizationHandler failed!", e);
+ }
+ }
+ LOG.debug("authorization class name: {} class: {} handler: {}", klassname, aznClass, authorizer);
+ return authorizer;
+ }
+
+ public Map getConf() {
--- End diff --
This is never used.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on the pull request:
https://github.com/apache/storm/pull/1156#issuecomment-193758244
@revans2 @abhishekagarwal87 could you take a look?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54627466
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
--- End diff --
If we move the initClearThread to be called from the constructor, and have the constructor take a conf we can then remove the need for any parameters top be passed in here, and simply have localmode not call this method.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54302312
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
--- End diff --
We cannot just create a new MetricRegistry each time. The metrics will be lost. In the clojure code there is a default registry that is used by all of the metrics. We need a similar one everywhere for all of our code to use (including the clojure code)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on the pull request:
https://github.com/apache/storm/pull/1156#issuecomment-193776807
Thanks @hustfxj . Looks good to me.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54306434
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
--- End diff --
Just cast result to a String, if it is not a String we have an internal error that we need to fix.
Or better yet, in that class I was suggesting we create. Instead of having an Object for the result lets split it into an Exception and a String result.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54622430
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,383 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ //TODO: To be removed after porting drpc.clj
--- End diff --
Just delete the comment, the JIRA you filed should cover this.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the pull request:
https://github.com/apache/storm/pull/1156#issuecomment-190894846
Done with another pass
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54325228
--- Diff: examples/storm-starter/src/jvm/org/apache/storm/starter/ManualDRPC.java ---
@@ -30,39 +30,37 @@
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;
-
public class ManualDRPC {
- public static class ExclamationBolt extends BaseBasicBolt {
-
- @Override
- public void declareOutputFields(OutputFieldsDeclarer declarer) {
- declarer.declare(new Fields("result", "return-info"));
- }
+ public static class ExclamationBolt extends BaseBasicBolt {
- @Override
- public void execute(Tuple tuple, BasicOutputCollector collector) {
- String arg = tuple.getString(0);
- Object retInfo = tuple.getValue(1);
- collector.emit(new Values(arg + "!!!", retInfo));
- }
+ @Override
+ public void declareOutputFields(OutputFieldsDeclarer declarer) {
+ declarer.declare(new Fields("result", "return-info"));
+ }
- }
+ @Override
+ public void execute(Tuple tuple, BasicOutputCollector collector) {
+ String arg = tuple.getString(0);
+ Object retInfo = tuple.getValue(1);
+ collector.emit(new Values(arg + "!!!", retInfo));
+ }
- public static void main(String[] args) {
- TopologyBuilder builder = new TopologyBuilder();
- LocalDRPC drpc = new LocalDRPC();
+ }
- DRPCSpout spout = new DRPCSpout("exclamation", drpc);
- builder.setSpout("drpc", spout);
- builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc");
- builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim");
+ public static void main(String[] args) throws Exception{
+ TopologyBuilder builder = new TopologyBuilder();
+ LocalDRPC drpc = new LocalDRPC();
- LocalCluster cluster = new LocalCluster();
- Config conf = new Config();
- cluster.submitTopology("exclaim", conf, builder.createTopology());
+ DRPCSpout spout = new DRPCSpout("exclamation", drpc);
+ builder.setSpout("drpc", spout);
+ builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc");
+ builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim");
- System.out.println(drpc.execute("exclamation", "aaa"));
- System.out.println(drpc.execute("exclamation", "bbb"));
+ LocalCluster cluster = new LocalCluster();
+ Config conf = new Config();
+ cluster.submitTopology("exclaim", conf, builder.createTopology());
- }
+ System.out.println(drpc.execute("exclamation", "aaa"));
+ System.out.println(drpc.execute("exclamation", "bbb"));
+ }
}
--- End diff --
I will pay attention to this,Thank you for reminding me
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54622564
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,383 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ //TODO: To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+
+ //TODO: to be replaced by a common registry
--- End diff --
I don't want to merge in code with broken functionality. Lets pull in the metrics changes you made first before we pull this JIRA in.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54298391
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
--- End diff --
this variable is not used
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54291910
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = this.idtoSem.get(id);
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ this.idtoResult.put(id, result);
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = this.idtoSem.get(id);
+ if (sem != null) {
+ this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<DRPCRequest>();
+ requestQueues.put(function, reqQueue);
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
+ if (reqContext != null) {
+ ThriftAccessLogger.logAccess(reqContext.requestID(), reqContext.remoteAddress(), reqContext.principal(), operation);
+ }
+ if (aclHandler != null) {
+ if (reqContext == null)
+ reqContext = ReqContext.context();
+ if (!aclHandler.permit(reqContext, operation, mapping)) {
+ Principal principal = reqContext.principal();
+ String user = (principal != null) ? principal.getName() : "unknown";
+ throw new AuthorizationException("DRPC request '" + operation + "' for '" + user + "' user is not authorized");
+ }
+ }
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation) throws AuthorizationException {
+ checkAuthorization(aclHandler, mapping, operation, ReqContext.context());
+ }
+
+ // TO be replaced by Common.mkAuthorizationHandler
+ private IAuthorizer mkAuthorizationHandler(String klassname, Map conf) {
+ IAuthorizer authorizer = null;
+ Class aznClass = null;
+ if (StringUtils.isNotBlank(klassname)) {
+ try {
+ aznClass = Class.forName(klassname);
+ authorizer = (IAuthorizer) aznClass.newInstance();
+ if (authorizer != null) {
+ authorizer.prepare(conf);
+ }
+ } catch (Exception e) {
+ LOG.error("mkAuthorizationHandler failed!", e);
+ }
+ }
+ LOG.debug("authorization class name: {} class: {} handler: {}", klassname, aznClass, authorizer);
+ return authorizer;
+ }
+
+ public Map getConf() {
+ return conf;
+ }
+
+ public static void main(String[] args) throws Exception {
+
--- End diff --
There are extra lines in some places which you can remove.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54293244
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
--- End diff --
You can separate out the implementation of DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable to a class DRPCService. This service class will only contain the business logic and server logic can be inside DRPCServer. Also AutoCloseable should be the interface than Shutdownable.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54302536
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
--- End diff --
This is never used and should be removed.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54325384
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
--- End diff --
@abhishekagarwal87 DRPC have already result fetchRequest execute failRequest, and these are override. I don't want to add some other methods.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55354139
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, InternalRequest> e : outstandingRequests.entrySet()) {
+ InternalRequest internalRequest = e.getValue();
+ if (Time.deltaSecs(internalRequest.startTimeSecs) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS))) {
+ String id = e.getKey();
+ Semaphore sem = internalRequest.sem;
+ if (sem != null) {
+ String func = internalRequest.function;
+ acquireQueue(func).remove(internalRequest.request);
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer() throws Exception {
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ initThrift();
+ initHttp();
+ }
+
+ @Override
+ public void close() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ outstandingRequests.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} ({}) at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int newid = 0;
+ int orig = 0;
+ do {
+ orig = ctr.get();
+ newid = (orig + 1) % 1000000000;
+ } while (!ctr.compareAndSet(orig, newid));
+ String strid = String.valueOf(newid);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ InternalRequest internalRequest = new InternalRequest(functionName, req);
+ this.outstandingRequests.put(strid, internalRequest);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ internalRequest.sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = internalRequest.result;
+
+ LOG.debug("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return (String) result;
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ InternalRequest internalRequest = this.outstandingRequests.get(id);
+ if (internalRequest != null) {
+ Map<String, String> map = ImmutableMap.of(DRPCAuthorizerBase.FUNCTION_NAME, internalRequest.function);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = internalRequest.sem;
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ internalRequest.result = result;
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ InternalRequest internalRequest = this.outstandingRequests.get(id);
+ if (internalRequest != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, internalRequest.function);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = internalRequest.sem;
+ if (sem != null) {
+ internalRequest.result = new DRPCExecutionException("Request failed");
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<>();
+ ConcurrentLinkedQueue<DRPCRequest> old = requestQueues.putIfAbsent(function, reqQueue);
+ if (old != null) {
+ reqQueue = old;
+ }
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
--- End diff --
This is not called in this class and has been marked private. So it can be removed I believe.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55535999
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
--- End diff --
Crap you are right, I totally messed up the URL. Great work!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54292304
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
--- End diff --
This will be logged multiple times or you can add the reporter class
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54623619
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,383 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ //TODO: To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+
+ //TODO: to be replaced by a common registry
+ private final static Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ //TODO: to be removed
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception{
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ //TODO: To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin: {}", reporter);
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, InternalRequest> e : outstandingRequests.entrySet()) {
+ InternalRequest internalRequest = e.getValue();
+ if (Time.deltaSecs(internalRequest.startTimeSecs) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = internalRequest.sem;
+ if (sem != null) {
+ String func = internalRequest.function;
+ acquireQueue(func).remove(internalRequest.request);
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
--- End diff --
This log did not exist in the original code.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54326847
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
--- End diff --
perfect thank you
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55402763
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, InternalRequest> e : outstandingRequests.entrySet()) {
+ InternalRequest internalRequest = e.getValue();
+ if (Time.deltaSecs(internalRequest.startTimeSecs) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS))) {
+ String id = e.getKey();
+ Semaphore sem = internalRequest.sem;
+ if (sem != null) {
+ String func = internalRequest.function;
+ acquireQueue(func).remove(internalRequest.request);
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer() throws Exception {
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ initThrift();
+ initHttp();
+ }
+
+ @Override
+ public void close() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ outstandingRequests.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} ({}) at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int newid = 0;
+ int orig = 0;
+ do {
+ orig = ctr.get();
+ newid = (orig + 1) % 1000000000;
+ } while (!ctr.compareAndSet(orig, newid));
+ String strid = String.valueOf(newid);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ InternalRequest internalRequest = new InternalRequest(functionName, req);
+ this.outstandingRequests.put(strid, internalRequest);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ internalRequest.sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = internalRequest.result;
+
+ LOG.debug("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return (String) result;
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ InternalRequest internalRequest = this.outstandingRequests.get(id);
+ if (internalRequest != null) {
+ Map<String, String> map = ImmutableMap.of(DRPCAuthorizerBase.FUNCTION_NAME, internalRequest.function);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = internalRequest.sem;
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ internalRequest.result = result;
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ InternalRequest internalRequest = this.outstandingRequests.get(id);
+ if (internalRequest != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, internalRequest.function);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = internalRequest.sem;
+ if (sem != null) {
+ internalRequest.result = new DRPCExecutionException("Request failed");
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<>();
+ ConcurrentLinkedQueue<DRPCRequest> old = requestQueues.putIfAbsent(function, reqQueue);
+ if (old != null) {
+ reqQueue = old;
+ }
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
--- End diff --
@revans2 I meant there is no need of overloading function as only one signature is being called. But its fine to merge still.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54304928
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
--- End diff --
Does Guava have a way to create this map cleaner?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54324937
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
--- End diff --
I think we can rename DRPCServer to DRPC later
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55426379
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
--- End diff --
Sorry I missed this before. In the previous code this was the very last thing that happened on the main thread, because this is a blocking call. With this happening before initHttp the HTTP server is never initialized even when it is configured.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55351778
--- Diff: storm-core/src/clj/org/apache/storm/daemon/supervisor.clj ---
@@ -1297,7 +1297,7 @@
(.readBlobTo blob-store (ConfigUtils/masterStormConfKey storm-id) (FileOutputStream. (ConfigUtils/supervisorStormConfPath tmproot)) nil)
(finally
(.shutdown blob-store)))
- (FileUtils/moveDirectory (File. tmproot) (File. stormroot))
--- End diff --
this file can be reverted.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the pull request:
https://github.com/apache/storm/pull/1156#issuecomment-189500334
Done with my first pass through the code.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54325240
--- Diff: storm-core/src/clj/org/apache/storm/daemon/drpc.clj ---
@@ -210,67 +63,19 @@
(wrap-reload '[org.apache.storm.daemon.drpc])
handle-request))
+
(defn launch-server!
([]
- (log-message "Starting drpc server for storm version '" STORM-VERSION "'")
(let [conf (clojurify-structure (ConfigUtils/readStormConfig))
- worker-threads (int (conf DRPC-WORKER-THREADS))
- queue-size (int (conf DRPC-QUEUE-SIZE))
drpc-http-port (int (conf DRPC-HTTP-PORT))
- drpc-port (int (conf DRPC-PORT))
- drpc-service-handler (service-handler conf)
- ;; requests and returns need to be on separate thread pools, since calls to
- ;; "execute" don't unblock until other thrift methods are called. So if
- ;; 64 threads are calling execute, the server won't accept the result
- ;; invocations that will unblock those threads
- handler-server (when (> drpc-port 0)
- (ThriftServer. conf
- (DistributedRPC$Processor. drpc-service-handler)
- ThriftConnectionType/DRPC))
- invoke-server (ThriftServer. conf
- (DistributedRPCInvocations$Processor. drpc-service-handler)
- ThriftConnectionType/DRPC_INVOCATIONS)
+ drpc-server (DrpcServer.)
http-creds-handler (AuthUtils/GetDrpcHttpCredentialsPlugin conf)]
- (Utils/addShutdownHookWithForceKillIn1Sec (fn []
- (if handler-server (.stop handler-server))
- (.stop invoke-server)))
- (log-message "Starting Distributed RPC servers...")
- (future (.serve invoke-server))
(when (> drpc-http-port 0)
- (let [app (-> (webapp drpc-service-handler http-creds-handler)
- requests-middleware)
- filter-class (conf DRPC-HTTP-FILTER)
- filter-params (conf DRPC-HTTP-FILTER-PARAMS)
- filters-confs [(FilterConfiguration. filter-class filter-params)]
- https-port (int (or (conf DRPC-HTTPS-PORT) 0))
- https-ks-path (conf DRPC-HTTPS-KEYSTORE-PATH)
- https-ks-password (conf DRPC-HTTPS-KEYSTORE-PASSWORD)
- https-ks-type (conf DRPC-HTTPS-KEYSTORE-TYPE)
- https-key-password (conf DRPC-HTTPS-KEY-PASSWORD)
- https-ts-path (conf DRPC-HTTPS-TRUSTSTORE-PATH)
- https-ts-password (conf DRPC-HTTPS-TRUSTSTORE-PASSWORD)
- https-ts-type (conf DRPC-HTTPS-TRUSTSTORE-TYPE)
- https-want-client-auth (conf DRPC-HTTPS-WANT-CLIENT-AUTH)
- https-need-client-auth (conf DRPC-HTTPS-NEED-CLIENT-AUTH)]
-
- (UIHelpers/stormRunJetty
- (int drpc-http-port)
- (reify IConfigurator (execute [this server]
- (UIHelpers/configSsl server
- https-port
- https-ks-path
- https-ks-password
- https-ks-type
- https-key-password
- https-ts-path
- https-ts-password
- https-ts-type
- https-need-client-auth
- https-want-client-auth)
- (UIHelpers/configFilter server (ring.util.servlet/servlet app) filters-confs))))))
- (start-metrics-reporters conf)
- (when handler-server
- (.serve handler-server)))))
+ (let [app (-> (webapp drpc-server http-creds-handler)
--- End diff --
ok
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54306040
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
--- End diff --
ImmutableMap.of(DRPCAuthorizerBase.FUNCTION_NAME, functionName)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54302011
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
--- End diff --
This is a perfect place to actually improve things to make them more object oriented. The key to almost all of these maps is the same thing. Why not remove all of the special ordering that we have to do on setup and cleanup.
```
private static class InternalRequest {
public final Semaphore sem;
public final long startTimeSecs;
public final string function;
public final DRPCRequest request;
public volatile Object result;
public InternalRequest(String function, DRPCRequest request) {
sem = new Semaphore(0);
startTimeSecs = Time.currentTimeSecs();
this.function = function;
this.request = request;
}
}
private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the pull request:
https://github.com/apache/storm/pull/1156#issuecomment-193876941
@hustfxj looks good to me I am +1 on this. @abhishekagarwal87 are you OK with merging this in as is. The comments you had looked relatively minor.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/storm/pull/1156
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on the pull request:
https://github.com/apache/storm/pull/1156#issuecomment-193899840
Yes. +1
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54302915
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException) {
+ throw (DRPCExecutionException) result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ return String.valueOf(result);
+ }
+
+ @Override
+ public void result(String id, String result) throws AuthorizationException, TException {
+ meterResultCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "result");
+ Semaphore sem = this.idtoSem.get(id);
+ LOG.debug("Received result {} for {} at {}", result, id, System.currentTimeMillis());
+ if (sem != null) {
+ this.idtoResult.put(id, result);
+ sem.release();
+ }
+ }
+ }
+
+ @Override
+ public DRPCRequest fetchRequest(String functionName) throws AuthorizationException, TException {
+ meterFetchRequestCalls.mark();
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "fetchRequest");
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ DRPCRequest req = queue.poll();
+ if (req != null) {
+ LOG.debug("Fetched request for {} at {}", functionName, System.currentTimeMillis());
+ return req;
+ } else {
+ return new DRPCRequest("", "");
+ }
+ }
+
+ @Override
+ public void failRequest(String id) throws AuthorizationException, TException {
+ meterFailRequestCalls.mark();
+ String func = this.idtoFunction.get(id);
+ if (func != null) {
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, func);
+ checkAuthorization(authorizer, map, "failRequest");
+ Semaphore sem = this.idtoSem.get(id);
+ if (sem != null) {
+ this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
+ sem.release();
+ }
+ }
+ }
+
+ protected ConcurrentLinkedQueue<DRPCRequest> acquireQueue(String function) {
+ ConcurrentLinkedQueue<DRPCRequest> reqQueue = requestQueues.get(function);
+ if (reqQueue == null) {
+ reqQueue = new ConcurrentLinkedQueue<DRPCRequest>();
+ requestQueues.put(function, reqQueue);
+ }
+ return reqQueue;
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation, ReqContext reqContext) throws AuthorizationException {
+ if (reqContext != null) {
+ ThriftAccessLogger.logAccess(reqContext.requestID(), reqContext.remoteAddress(), reqContext.principal(), operation);
+ }
+ if (aclHandler != null) {
+ if (reqContext == null)
+ reqContext = ReqContext.context();
+ if (!aclHandler.permit(reqContext, operation, mapping)) {
+ Principal principal = reqContext.principal();
+ String user = (principal != null) ? principal.getName() : "unknown";
+ throw new AuthorizationException("DRPC request '" + operation + "' for '" + user + "' user is not authorized");
+ }
+ }
+ }
+
+ private void checkAuthorization(IAuthorizer aclHandler, Map mapping, String operation) throws AuthorizationException {
+ checkAuthorization(aclHandler, mapping, operation, ReqContext.context());
+ }
+
+ // TO be replaced by Common.mkAuthorizationHandler
+ private IAuthorizer mkAuthorizationHandler(String klassname, Map conf) {
+ IAuthorizer authorizer = null;
+ Class aznClass = null;
+ if (StringUtils.isNotBlank(klassname)) {
+ try {
+ aznClass = Class.forName(klassname);
+ authorizer = (IAuthorizer) aznClass.newInstance();
+ if (authorizer != null) {
+ authorizer.prepare(conf);
+ }
+ } catch (Exception e) {
+ LOG.error("mkAuthorizationHandler failed!", e);
+ }
+ }
+ LOG.debug("authorization class name: {} class: {} handler: {}", klassname, aznClass, authorizer);
+ return authorizer;
+ }
+
+ public Map getConf() {
+ return conf;
+ }
+
+ public static void main(String[] args) throws Exception {
--- End diff --
This main does not work if we are using HTTP. The servlet is not setup. We should probably remove this until it actually works.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54327041
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
--- End diff --
Can we follow up a JIRA to port a default registry over to java too? I will do it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54300776
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
--- End diff --
All the semaphore/queue related logic will sit together in one class and not dispersed across.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54287032
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
--- End diff --
you can rename it to DRPCServer for consistency.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54298663
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
--- End diff --
shouldn't it try to stop both of them
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54626795
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,383 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ //TODO: To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+
+ //TODO: to be replaced by a common registry
+ private final static Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ //TODO: to be removed
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception{
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ //TODO: To be replaced by Common.StartMetricsReporters
--- End diff --
That way it can use the same MetricsRegistry as the others, which is the key to make this all work.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55429090
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
--- End diff --
Looks like you can just switch the order of doing the init and put initHttp() first in launchServer, but I am getting some problems with using HTTP with the following.
```
$ cat ./conf/storm.yaml
drpc.http.port: 9090
drpc.servers:
- "localhost"
$ ./bin/storm jar ./examples/storm-starter/storm-starter-topologies-2.0.0-SNAPSHOT.jar org.apache.storm.starter.BasicDRPCTopology drpc-test
... wait for to come all the way up
$ curl http://localhost:9090/exclamation/hi
... Error ...
```
from the logs I see
```
2016-03-08 15:17:49.528 o.a.s.s.o.e.j.s.ServletHandler [WARN] /exclamation/hi
java.lang.NullPointerException: Handler returned nil
at org.apache.storm.shade.ring.util.servlet$make_service_method$fn__7738.invoke(servlet.clj:128)
at org.apache.storm.shade.ring.util.servlet$servlet$fn__7742.invoke(servlet.clj:136)
at org.apache.storm.shade.ring.util.servlet.proxy$javax.servlet.http.HttpServlet$ff19274a.service(Unknown Source)
at org.apache.storm.shade.org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:654)
at org.apache.storm.shade.org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1320)
at org.apache.storm.logging.filters.AccessLoggingFilter.handle(AccessLoggingFilter.java:47)
at org.apache.storm.logging.filters.AccessLoggingFilter.doFilter(AccessLoggingFilter.java:39)
at org.apache.storm.shade.org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1291)
at org.apache.storm.shade.org.eclipse.jetty.servlets.CrossOriginFilter.handle(CrossOriginFilter.java:247)
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54628183
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,383 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ //TODO: To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+
+ //TODO: to be replaced by a common registry
+ private final static Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ //TODO: to be removed
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception{
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ //TODO: To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin: {}", reporter);
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, InternalRequest> e : outstandingRequests.entrySet()) {
+ InternalRequest internalRequest = e.getValue();
+ if (Time.deltaSecs(internalRequest.startTimeSecs) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = internalRequest.sem;
+ if (sem != null) {
+ String func = internalRequest.function;
+ acquireQueue(func).remove(internalRequest.request);
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal){
+ initThrift();
+ initHttp();
+ }
+
+ }
+
+ @Override
+ public void close() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ outstandingRequests.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} ({}) at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int newid = 0;
+ int orig = 0;
+ do {
+ orig = ctr.get();
+ newid = (orig + 1) % 1000000000;
+ } while (!ctr.compareAndSet(orig, newid));
+ String strid = String.valueOf(newid);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ InternalRequest internalRequest = new InternalRequest(functionName, req);
+ this.outstandingRequests.put(strid, internalRequest);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ internalRequest.sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = internalRequest.result;
+
+ LOG.debug("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
+
+ this.cleanup(strid);
+
+ if (result instanceof DRPCExecutionException ) {
+ throw (DRPCExecutionException)result;
+ }
+ if (result == null) {
+ throw new DRPCExecutionException("Request timed out");
+ }
+ try {
+ return String.valueOf(result);
+ }catch (Exception e){
+ throw new DRPCExecutionException(e.getMessage());
+ }
--- End diff --
Lets replace this the entire try/catch with.
```
return (String) result;
```
If we ever have anything but a DRPCExecutorionException or a String in there we have an internal error that we need to fix.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54325117
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
--- End diff --
meterHttpRequests is not used as drpc.clj has meter for httpRequests. But we can use this meter after we remove drpc.clj
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54297857
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
+ this.idtoSem.put(strid, sem);
+ this.idtoFunction.put(strid, functionName);
+ this.idtoRequest.put(strid, req);
+ ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName);
+ queue.add(req);
+ LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+ try {
+ sem.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("acquire fail ", e);
+ }
+ LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis());
+
+ Object result = this.idtoResult.get(strid);
+
+ LOG.info("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis()));
--- End diff --
this should be LOG.debug
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on the pull request:
https://github.com/apache/storm/pull/1156#issuecomment-191021959
@revans2 Thank you.I won't wait updating the metric codes util the #1171 about the metrics is merged master.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the pull request:
https://github.com/apache/storm/pull/1156#issuecomment-194358768
+1
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by abhishekagarwal87 <gi...@git.apache.org>.
Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54297736
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
+
+ LOG.info("Starting drpc server for storm version {}", VersionInfo.getVersion());
+ this.conf = conf;
+ authorizer = mkAuthorizationHandler((String) (conf.get(Config.DRPC_AUTHORIZER)), conf);
+
+ initClearThread();
+ if (!isLocal)
+ initServer();
+ }
+
+ @Override
+ public void shutdown() {
+ meterShutdownCalls.mark();
+ clearThread.interrupt();
+ }
+
+ public void cleanup(String id) {
+ idtoSem.remove(id);
+ idtoResult.remove(id);
+ idtoStart.remove(id);
+ idtoFunction.remove(id);
+ idtoRequest.remove(id);
+ }
+
+ @Override
+ public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException {
+ meterExecuteCalls.mark();
+ LOG.debug("Received DRPC request for {} {} at {} ", functionName, funcArgs, System.currentTimeMillis());
+ Map<String, String> map = new HashMap<>();
+ map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName);
+ checkAuthorization(authorizer, map, "execute");
+
+ int idinc = this.ctr.incrementAndGet();
+ int maxvalue = 1000000000;
+ int newid = idinc % maxvalue;
+ if (idinc != newid) {
+ this.ctr.compareAndSet(idinc, newid);
+ }
+
+ String strid = String.valueOf(newid);
+ Semaphore sem = new Semaphore(0);
+
+ DRPCRequest req = new DRPCRequest(funcArgs, strid);
+ this.idtoStart.put(strid, Time.currentTimeSecs());
--- End diff --
minor. can you rename idtoStart to idToStart and similarly other idto* variables.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r55430274
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,356 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private static class InternalRequest {
+ public final Semaphore sem;
+ public final int startTimeSecs;
+ public final String function;
+ public final DRPCRequest request;
+ public volatile Object result;
+
+ public InternalRequest(String function, DRPCRequest request) {
+ sem = new Semaphore(0);
+ startTimeSecs = Time.currentTimeSecs();
+ this.function = function;
+ this.request = request;
+ }
+ }
+
+ private ConcurrentHashMap<String, InternalRequest> outstandingRequests = new ConcurrentHashMap<>();
+
+ private final static Meter meterHttpRequests = StormMetricsRegistry.registerMeter("drpc:num-execute-http-requests");
+ private final static Meter meterExecuteCalls = StormMetricsRegistry.registerMeter("drpc:num-execute-calls");
+ private final static Meter meterResultCalls = StormMetricsRegistry.registerMeter("drpc:num-result-calls");
+ private final static Meter meterFailRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-failRequest-calls");
+ private final static Meter meterFetchRequestCalls = StormMetricsRegistry.registerMeter("drpc:num-fetchRequest-calls");
+ private final static Meter meterShutdownCalls = StormMetricsRegistry.registerMeter("drpc:num-shutdown-calls");
+
+ public DrpcServer(Map conf) {
+ this.conf = conf;
+ this.authorizer = mkAuthorizationHandler((String) (this.conf.get(Config.DRPC_AUTHORIZER)));
+ initClearThread();
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+ private ThriftServer initHandlerServer(final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initHttp() throws Exception {
+ LOG.info("Starting RPC Http servers...");
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ }
+
+ private void initThrift() throws Exception {
+
+ handlerServer = initHandlerServer(this);
+ invokeServer = initInvokeServer(this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null)
+ handlerServer.stop();
+ invokeServer.stop();
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+
+ StormMetricsRegistry.startMetricsReporters(conf);
+
+ if (handlerServer != null)
+ handlerServer.serve();
--- End diff --
OK So the issue with http not working is that the handler is never set for the http server to have access to.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by hustfxj <gi...@git.apache.org>.
Github user hustfxj commented on the pull request:
https://github.com/apache/storm/pull/1156#issuecomment-189637237
@revans2 @abhishekagarwal87 Than you ver much. I are addressing your comments. But I may not understand what you mean about launchServer method, although I update the method. Can you help me review again? I want to follow up a JIRA to port the webapp portion over to java about webapp,
And I want to follow up a JIRA to port a default registry over to java for all of our code to use;
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] storm pull request: [STORM-1270] [STORM-1274] port drpc&LocalDRPC ...
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1156#discussion_r54304122
--- Diff: storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java ---
@@ -0,0 +1,390 @@
+/**
+ * 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;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.sun.net.httpserver.HttpsServer;
+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.Config;
+import org.apache.storm.daemon.metrics.MetricsUtils;
+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;
+import org.apache.storm.generated.*;
+import org.apache.storm.logging.ThriftAccessLogger;
+import org.apache.storm.security.auth.*;
+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;
+import org.apache.storm.ui.FilterConfiguration;
+import org.apache.storm.ui.IConfigurator;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.apache.thrift.TException;
+import org.eclipse.jetty.server.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Servlet;
+import java.security.Principal;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);
+ private final Long timeoutCheckSecs = 5L;
+
+ private Map conf;
+
+ private ThriftServer handlerServer;
+ private ThriftServer invokeServer;
+ private IHttpCredentialsPlugin httpCredsHandler;
+
+ private Thread clearThread;
+
+ private IAuthorizer authorizer;
+
+ // To be removed after porting drpc.clj
+ private Servlet httpServlet;
+
+ private AtomicInteger ctr = new AtomicInteger(0);
+ private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();
+ private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();
+ private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();
+ private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();
+ private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();
+ private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();
+
+ private final Meter meterHttpRequests = new MetricRegistry().meter("drpc:num-execute-http-requests");
+ private final Meter meterExecuteCalls = new MetricRegistry().meter("drpc:num-execute-calls");
+ private final Meter meterResultCalls = new MetricRegistry().meter("drpc:num-result-calls");
+ private final Meter meterFailRequestCalls = new MetricRegistry().meter("drpc:num-failRequest-calls");
+ private final Meter meterFetchRequestCalls = new MetricRegistry().meter("drpc:num-fetchRequest-calls");
+ private final Meter meterShutdownCalls = new MetricRegistry().meter("drpc:num-shutdown-calls");
+
+ public DrpcServer() {
+
+ }
+
+ public IHttpCredentialsPlugin getHttpCredsHandler() {
+ return httpCredsHandler;
+ }
+
+ public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {
+ this.httpCredsHandler = httpCredsHandler;
+ }
+
+ public Servlet getHttpServlet() {
+ return httpServlet;
+ }
+
+ public void setHttpServlet(Servlet httpServlet) {
+ this.httpServlet = httpServlet;
+ }
+
+
+
+ private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {
+ int port = (int) conf.get(Config.DRPC_PORT);
+ if (port > 0) {
+ handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);
+ }
+ return handlerServer;
+ }
+
+ private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {
+ invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),
+ ThriftConnectionType.DRPC_INVOCATIONS);
+ return invokeServer;
+ }
+
+ private void initServer() throws Exception {
+ Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);
+ handlerServer = initHandlerServer(conf, this);
+ invokeServer = initInvokeServer(conf, this);
+ httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);
+ Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {
+ @Override
+ public void run() {
+ if (handlerServer != null) {
+ handlerServer.stop();
+ } else {
+ invokeServer.stop();
+ }
+ }
+ });
+ LOG.info("Starting Distributed RPC servers...");
+
+ LOG.info("Starting Distributed RPC servers...");
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ invokeServer.serve();
+ }
+ }).start();
+ if (drpcHttpPort != null && drpcHttpPort > 0) {
+ String filterClass = (String) (conf.get(Config.DRPC_HTTP_FILTER));
+ Map<String, String> filterParams = (Map<String, String>) (conf.get(Config.DRPC_HTTP_FILTER_PARAMS));
+ FilterConfiguration filterConfiguration = new FilterConfiguration(filterParams, filterClass);
+ final List<FilterConfiguration> filterConfigurations = Arrays.asList(filterConfiguration);
+ final Integer httpsPort = Utils.getInt(conf.get(Config.DRPC_HTTPS_PORT), 0);
+ final String httpsKsPath = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PATH));
+ final String httpsKsPassword = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_PASSWORD));
+ final String httpsKsType = (String) (conf.get(Config.DRPC_HTTPS_KEYSTORE_TYPE));
+ final String httpsKeyPassword = (String) (conf.get(Config.DRPC_HTTPS_KEY_PASSWORD));
+ final String httpsTsPath = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PATH));
+ final String httpsTsPassword = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_PASSWORD));
+ final String httpsTsType = (String) (conf.get(Config.DRPC_HTTPS_TRUSTSTORE_TYPE));
+ final Boolean httpsWantClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_WANT_CLIENT_AUTH));
+ final Boolean httpsNeedClientAuth = (Boolean) (conf.get(Config.DRPC_HTTPS_NEED_CLIENT_AUTH));
+
+ UIHelpers.stormRunJetty(drpcHttpPort, new IConfigurator() {
+ @Override
+ public void execute(Server s) {
+ UIHelpers.configSsl(s, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType,
+ httpsNeedClientAuth, httpsWantClientAuth);
+ UIHelpers.configFilter(s, httpServlet, filterConfigurations);
+ }
+ });
+ }
+
+ // To be replaced by Common.StartMetricsReporters
+ List<PreparableReporter> reporters = MetricsUtils.getPreparableReporters(conf);
+ for (PreparableReporter reporter : reporters) {
+ reporter.prepare(new MetricRegistry(), conf);
+ reporter.start();
+ LOG.info("Started statistics report plugin...");
+ }
+ if (handlerServer != null)
+ handlerServer.serve();
+ }
+
+ private void initClearThread() {
+ clearThread = Utils.asyncLoop(new Callable() {
+
+ @Override
+ public Object call() throws Exception {
+ for (Map.Entry<String, Integer> e : idtoStart.entrySet()) {
+
+ if (Time.deltaSecs(e.getValue()) > Utils.getInt(conf.get(Config.DRPC_REQUEST_TIMEOUT_SECS), 0)) {
+ String id = e.getKey();
+ Semaphore sem = idtoSem.get(id);
+ if (sem != null) {
+ String func = idtoFunction.get(id);
+ acquireQueue(func).remove(idtoRequest.get(id));
+ LOG.warn("Timeout DRPC request id: {} start at {}", id, e.getValue());
+ sem.release();
+ }
+ cleanup(id);
+ LOG.info("Clear request " + id);
+ }
+ }
+ return getTimeoutCheckSecs();
+ }
+ });
+ }
+
+ public Long getTimeoutCheckSecs() {
+ return timeoutCheckSecs;
+ }
+
+ public void launchServer(boolean isLocal, Map conf) throws Exception {
--- End diff --
Why did we combine service-handler and launch-server! into a single launchServer method? The only thing that was missing in local mode that this adds is the clearThread to time out missed tuples. Did you run into issues with testing when this was not included?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---