forked from nathanmarz/storm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
afeng
committed
Feb 15, 2013
1 parent
1e17e82
commit 7def91d
Showing
3 changed files
with
195 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,30 @@ | ||
package backtype.storm.utils; | ||
|
||
import backtype.storm.Config; | ||
import backtype.storm.security.auth.ThriftClient; | ||
import backtype.storm.generated.Nimbus; | ||
import java.util.Map; | ||
import org.apache.thrift7.TException; | ||
import org.apache.thrift7.protocol.TBinaryProtocol; | ||
import org.apache.thrift7.transport.TFramedTransport; | ||
import org.apache.thrift7.transport.TSocket; | ||
import org.apache.thrift7.transport.TTransport; | ||
|
||
import java.util.Map; | ||
|
||
public class NimbusClient { | ||
public class NimbusClient extends ThriftClient { | ||
private Nimbus.Client _client; | ||
|
||
public static NimbusClient getConfiguredClient(Map conf) { | ||
String nimbusHost = (String) conf.get(Config.NIMBUS_HOST); | ||
int nimbusPort = Utils.getInt(conf.get(Config.NIMBUS_THRIFT_PORT)); | ||
return new NimbusClient(nimbusHost, nimbusPort); | ||
String nimbusHost = (String) conf.get(Config.NIMBUS_HOST); | ||
int nimbusPort = Utils.getInt(conf.get(Config.NIMBUS_THRIFT_PORT)); | ||
return new NimbusClient(nimbusHost, nimbusPort); | ||
} | ||
|
||
private TTransport conn; | ||
private Nimbus.Client client; | ||
|
||
|
||
public NimbusClient(String host) { | ||
this(host, 6627); | ||
this(host, 6627); | ||
} | ||
|
||
public NimbusClient(String host, int port) { | ||
try { | ||
if(host==null) { | ||
throw new IllegalArgumentException("Nimbus host is not set"); | ||
} | ||
conn = new TFramedTransport(new TSocket(host, port)); | ||
client = new Nimbus.Client(new TBinaryProtocol(conn)); | ||
conn.open(); | ||
} catch(TException e) { | ||
throw new RuntimeException(e); | ||
} | ||
super(host, port, "nimbus_server"); | ||
_client = new Nimbus.Client(_protocol); | ||
} | ||
|
||
public Nimbus.Client getClient() { | ||
return client; | ||
} | ||
|
||
public void close() { | ||
conn.close(); | ||
return _client; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
test/clj/backtype/storm/security/auth/digest_auth_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
(ns backtype.storm.security.auth.digest-auth-test | ||
(:use [clojure test]) | ||
(:require [backtype.storm.daemon [nimbus :as nimbus]]) | ||
(:import [org.apache.thrift7 TException]) | ||
(:import [java.nio.channels Channels WritableByteChannel]) | ||
(:import [backtype.storm.utils NimbusClient]) | ||
(:import [backtype.storm.security.auth ThriftServer ThriftClient ReqContext ReqContext$OperationType]) | ||
(:use [backtype.storm bootstrap util]) | ||
(:use [backtype.storm.daemon common]) | ||
(:use [backtype.storm bootstrap testing]) | ||
(:import [backtype.storm.generated Nimbus Nimbus$Client]) | ||
) | ||
|
||
(bootstrap) | ||
|
||
(def server-port 6627) | ||
|
||
; Exceptions are getting wrapped in RuntimeException. This might be due to | ||
; CLJ-855. | ||
(defn- unpack-runtime-exception [expression] | ||
(try (eval expression) | ||
nil | ||
(catch java.lang.RuntimeException gripe | ||
(throw (.getCause gripe))) | ||
) | ||
) | ||
|
||
(defn launch-test-server [] | ||
(with-inprocess-zookeeper zk-port | ||
(with-local-tmp [nimbus-dir] | ||
(let [conf (merge (read-storm-config) | ||
{STORM-ZOOKEEPER-SERVERS ["localhost"] | ||
STORM-ZOOKEEPER-PORT zk-port | ||
NIMBUS-HOST "localhost" | ||
NIMBUS-THRIFT-PORT server-port | ||
STORM-LOCAL-DIR nimbus-dir}) | ||
nimbus (nimbus/standalone-nimbus) | ||
service-handler (nimbus/service-handler conf nimbus) | ||
server (ThriftServer. (Nimbus$Processor. service-handler) (int (conf NIMBUS-THRIFT-PORT)))] | ||
(.addShutdownHook (Runtime/getRuntime) (Thread. (fn [] (.shutdown service-handler) (.stop server)))) | ||
(log-message "Starting Nimbus server...") | ||
(.serve server))))) | ||
|
||
(defn launch-server-w-wait [] | ||
(future (launch-test-server)) | ||
(log-message "Waiting for Nimbus Server...") | ||
(Thread/sleep 10000)) | ||
|
||
(deftest digest-auth-test | ||
(System/setProperty "java.security.auth.login.config" "./conf/jaas_digest.conf") | ||
(launch-server-w-wait) | ||
(log-message "Starting Nimbus client w/ connection to localhost:" server-port) | ||
(let [client (NimbusClient. "localhost" server-port) | ||
nimbus_client (.getClient client)] | ||
(is (thrown? backtype.storm.generated.NotAliveException (.activate nimbus_client "bogus_topology"))) | ||
(.close client))) |