You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by bo...@apache.org on 2018/05/04 18:43:15 UTC
[2/6] storm git commit: STORM-2171: Making LocalFsBlobStore conform
better to Blobstore API
STORM-2171: Making LocalFsBlobStore conform better to Blobstore API
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/d5865711
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/d5865711
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/d5865711
Branch: refs/heads/master
Commit: d5865711a7c7ad567295ba53109133702c954033
Parents: 844b2d2
Author: Govind Menon <go...@gmail.com>
Authored: Wed Apr 25 23:45:19 2018 -0500
Committer: Govind Menon <go...@gmail.com>
Committed: Thu May 3 08:56:00 2018 -0500
----------------------------------------------------------------------
.../org/apache/storm/blobstore/BlobStore.java | 9 +
.../storm/cluster/IStormClusterState.java | 2 +-
.../storm/cluster/StormClusterStateImpl.java | 2 +-
.../org/apache/storm/command/AdminCommands.java | 6 -
.../test/clj/org/apache/storm/cluster_test.clj | 4 +-
.../storm/blobstore/BlobSynchronizer.java | 126 -----
.../storm/blobstore/LocalFsBlobStore.java | 128 ++++-
.../blobstore/LocalFsBlobStoreSynchronizer.java | 129 +++++
.../org/apache/storm/daemon/nimbus/Nimbus.java | 156 ++----
.../apache/storm/blobstore/BlobStoreTest.java | 467 ------------------
.../storm/blobstore/BlobSynchronizerTest.java | 136 ------
.../LocalFsBlobStoreSynchronizerTest.java | 136 ++++++
.../storm/blobstore/LocalFsBlobStoreTest.java | 482 +++++++++++++++++++
13 files changed, 916 insertions(+), 867 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-client/src/jvm/org/apache/storm/blobstore/BlobStore.java
----------------------------------------------------------------------
diff --git a/storm-client/src/jvm/org/apache/storm/blobstore/BlobStore.java b/storm-client/src/jvm/org/apache/storm/blobstore/BlobStore.java
index 307ae8f..2cda4db 100644
--- a/storm-client/src/jvm/org/apache/storm/blobstore/BlobStore.java
+++ b/storm-client/src/jvm/org/apache/storm/blobstore/BlobStore.java
@@ -76,6 +76,15 @@ public abstract class BlobStore implements Shutdownable {
public abstract void prepare(Map<String, Object> conf, String baseDir, NimbusInfo nimbusInfo);
/**
+ * Start the syncing blobs between the local running instance of the BlobStore and others.
+ * A no-op for the HdfsBlobStore where HDFS itself does the syncing
+ * but for the LocalFsBlobStore ZK state updates are run periodically here.
+ */
+ public void startSyncBlobs() throws KeyNotFoundException, AuthorizationException {
+ // NO-OP by default
+ }
+
+ /**
* Creates the blob.
*
* @param key Key for the blob.
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-client/src/jvm/org/apache/storm/cluster/IStormClusterState.java
----------------------------------------------------------------------
diff --git a/storm-client/src/jvm/org/apache/storm/cluster/IStormClusterState.java b/storm-client/src/jvm/org/apache/storm/cluster/IStormClusterState.java
index f38c8de..5627997 100644
--- a/storm-client/src/jvm/org/apache/storm/cluster/IStormClusterState.java
+++ b/storm-client/src/jvm/org/apache/storm/cluster/IStormClusterState.java
@@ -199,7 +199,7 @@ public interface IStormClusterState {
void setAssignment(String stormId, Assignment info, Map<String, Object> topoConf);
- void setupBlobstore(String key, NimbusInfo nimbusInfo, Integer versionInfo);
+ void setupBlob(String key, NimbusInfo nimbusInfo, Integer versionInfo);
List<String> activeKeys();
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-client/src/jvm/org/apache/storm/cluster/StormClusterStateImpl.java
----------------------------------------------------------------------
diff --git a/storm-client/src/jvm/org/apache/storm/cluster/StormClusterStateImpl.java b/storm-client/src/jvm/org/apache/storm/cluster/StormClusterStateImpl.java
index 903369e..03dccc6 100644
--- a/storm-client/src/jvm/org/apache/storm/cluster/StormClusterStateImpl.java
+++ b/storm-client/src/jvm/org/apache/storm/cluster/StormClusterStateImpl.java
@@ -697,7 +697,7 @@ public class StormClusterStateImpl implements IStormClusterState {
}
@Override
- public void setupBlobstore(String key, NimbusInfo nimbusInfo, Integer versionInfo) {
+ public void setupBlob(String key, NimbusInfo nimbusInfo, Integer versionInfo) {
String path = ClusterUtils.blobstorePath(key) + ClusterUtils.ZK_SEPERATOR + nimbusInfo.toHostPortString() + "-" + versionInfo;
LOG.info("set-path: {}", path);
stateStorage.mkdirs(ClusterUtils.blobstorePath(key), defaultAcls);
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-core/src/jvm/org/apache/storm/command/AdminCommands.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/org/apache/storm/command/AdminCommands.java b/storm-core/src/jvm/org/apache/storm/command/AdminCommands.java
index 7ae7dbc..9ec9eb4 100644
--- a/storm-core/src/jvm/org/apache/storm/command/AdminCommands.java
+++ b/storm-core/src/jvm/org/apache/storm/command/AdminCommands.java
@@ -83,12 +83,6 @@ public class AdminCommands {
while (corruptTopologies.hasNext()) {
String corruptId = corruptTopologies.next();
stormClusterState.removeStorm(corruptId);
- if (nimbusBlobStore instanceof LocalFsBlobStore) {
- Iterator<String> blobKeys = getKeyListFromId(corruptId).iterator();
- while (blobKeys.hasNext()) {
- stormClusterState.removeBlobstoreKey(blobKeys.next());
- }
- }
}
}
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-core/test/clj/org/apache/storm/cluster_test.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/clj/org/apache/storm/cluster_test.clj b/storm-core/test/clj/org/apache/storm/cluster_test.clj
index 31b74b5..5b93abb 100644
--- a/storm-core/test/clj/org/apache/storm/cluster_test.clj
+++ b/storm-core/test/clj/org/apache/storm/cluster_test.clj
@@ -234,10 +234,10 @@
(is (= {"b" "b"} (.get_creds (.credentials state "storm1" nil))))
(is (= [] (.blobstoreInfo state "")))
- (.setupBlobstore state "key1" nimbusInfo1 (Integer/parseInt "1"))
+ (.setupBlob state "key1" nimbusInfo1 (Integer/parseInt "1"))
(is (= ["key1"] (.blobstoreInfo state "")))
(is (= [(str (.toHostPortString nimbusInfo1) "-1")] (.blobstoreInfo state "key1")))
- (.setupBlobstore state "key1" nimbusInfo2 (Integer/parseInt "1"))
+ (.setupBlob state "key1" nimbusInfo2 (Integer/parseInt "1"))
(is (= #{(str (.toHostPortString nimbusInfo1) "-1")
(str (.toHostPortString nimbusInfo2) "-1")} (set (.blobstoreInfo state "key1"))))
(.removeBlobstoreKey state "key1")
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-server/src/main/java/org/apache/storm/blobstore/BlobSynchronizer.java
----------------------------------------------------------------------
diff --git a/storm-server/src/main/java/org/apache/storm/blobstore/BlobSynchronizer.java b/storm-server/src/main/java/org/apache/storm/blobstore/BlobSynchronizer.java
deleted file mode 100644
index 19351b1..0000000
--- a/storm-server/src/main/java/org/apache/storm/blobstore/BlobSynchronizer.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/**
- * 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.blobstore;
-
-import java.nio.channels.ClosedByInterruptException;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.storm.generated.KeyNotFoundException;
-import org.apache.storm.nimbus.NimbusInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Is called periodically and updates the nimbus with blobs based on the state stored inside the zookeeper
- * for a non leader nimbus trying to be in sync with the operations performed on the leader nimbus.
- */
-public class BlobSynchronizer {
- private static final Logger LOG = LoggerFactory.getLogger(BlobSynchronizer.class);
- private CuratorFramework zkClient;
- private Map<String, Object> conf;
- private BlobStore blobStore;
- private Set<String> blobStoreKeySet = new HashSet<String>();
- private Set<String> zookeeperKeySet = new HashSet<String>();
- private NimbusInfo nimbusInfo;
-
- public BlobSynchronizer(BlobStore blobStore, Map<String, Object> conf) {
- this.blobStore = blobStore;
- this.conf = conf;
- }
-
- public void setNimbusInfo(NimbusInfo nimbusInfo) {
- this.nimbusInfo = nimbusInfo;
- }
-
- public void setZkClient(CuratorFramework zkClient) {
- this.zkClient = zkClient;
- }
-
- public Set<String> getBlobStoreKeySet() {
- Set<String> keySet = new HashSet<String>();
- keySet.addAll(blobStoreKeySet);
- return keySet;
- }
-
- public void setBlobStoreKeySet(Set<String> blobStoreKeySet) {
- this.blobStoreKeySet = blobStoreKeySet;
- }
-
- public Set<String> getZookeeperKeySet() {
- Set<String> keySet = new HashSet<String>();
- keySet.addAll(zookeeperKeySet);
- return keySet;
- }
-
- public void setZookeeperKeySet(Set<String> zookeeperKeySet) {
- this.zookeeperKeySet = zookeeperKeySet;
- }
-
- public synchronized void syncBlobs() {
- try {
- LOG.debug("Sync blobs - blobstore keys {}, zookeeper keys {}", getBlobStoreKeySet(), getZookeeperKeySet());
- deleteKeySetFromBlobStoreNotOnZookeeper(getBlobStoreKeySet(), getZookeeperKeySet());
- updateKeySetForBlobStore(getBlobStoreKeySet());
- Set<String> keySetToDownload = getKeySetToDownload(getBlobStoreKeySet(), getZookeeperKeySet());
- LOG.debug("Key set Blobstore-> Zookeeper-> DownloadSet {}-> {}-> {}", getBlobStoreKeySet(), getZookeeperKeySet(),
- keySetToDownload);
-
- for (String key : keySetToDownload) {
- try {
- Set<NimbusInfo> nimbusInfoSet = BlobStoreUtils.getNimbodesWithLatestSequenceNumberOfBlob(zkClient, key);
- LOG.debug("syncBlobs, key: {}, nimbusInfoSet: {}", key, nimbusInfoSet);
- if (BlobStoreUtils.downloadMissingBlob(conf, blobStore, key, nimbusInfoSet)) {
- BlobStoreUtils.createStateInZookeeper(conf, key, nimbusInfo);
- }
- } catch (KeyNotFoundException e) {
- LOG.debug("Detected deletion for the key {} while downloading - skipping download", key);
- }
- }
- } catch (InterruptedException | ClosedByInterruptException exp) {
- LOG.error("Interrupt Exception {}", exp);
- } catch (Exception exp) {
- throw new RuntimeException(exp);
- }
- }
-
- public void deleteKeySetFromBlobStoreNotOnZookeeper(Set<String> keySetBlobStore, Set<String> keySetZookeeper) throws Exception {
- if (keySetBlobStore.removeAll(keySetZookeeper)
- || (keySetZookeeper.isEmpty() && !keySetBlobStore.isEmpty())) {
- LOG.debug("Key set to delete in blobstore {}", keySetBlobStore);
- for (String key : keySetBlobStore) {
- blobStore.deleteBlob(key, BlobStoreUtils.getNimbusSubject());
- }
- }
- }
-
- // Update current key list inside the blobstore if the version changes
- public void updateKeySetForBlobStore(Set<String> keySetBlobStore) {
- try {
- for (String key : keySetBlobStore) {
- LOG.debug("updating blob");
- BlobStoreUtils.updateKeyForBlobStore(conf, blobStore, zkClient, key, nimbusInfo);
- }
- } catch (Exception exp) {
- throw new RuntimeException(exp);
- }
- }
-
- // Make a key list to download
- public Set<String> getKeySetToDownload(Set<String> blobStoreKeySet, Set<String> zookeeperKeySet) {
- zookeeperKeySet.removeAll(blobStoreKeySet);
- LOG.debug("Key list to download {}", zookeeperKeySet);
- return zookeeperKeySet;
- }
-}
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-server/src/main/java/org/apache/storm/blobstore/LocalFsBlobStore.java
----------------------------------------------------------------------
diff --git a/storm-server/src/main/java/org/apache/storm/blobstore/LocalFsBlobStore.java b/storm-server/src/main/java/org/apache/storm/blobstore/LocalFsBlobStore.java
index 6da1f47..1edcdaf 100644
--- a/storm-server/src/main/java/org/apache/storm/blobstore/LocalFsBlobStore.java
+++ b/storm-server/src/main/java/org/apache/storm/blobstore/LocalFsBlobStore.java
@@ -18,21 +18,34 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.UnknownHostException;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
import javax.security.auth.Subject;
import org.apache.curator.framework.CuratorFramework;
import org.apache.storm.cluster.DaemonType;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.cluster.ClusterStateContext;
+import org.apache.storm.cluster.ClusterUtils;
+import org.apache.storm.cluster.IStormClusterState;
+import org.apache.storm.generated.SettableBlobMeta;
import org.apache.storm.generated.AuthorizationException;
import org.apache.storm.generated.KeyAlreadyExistsException;
import org.apache.storm.generated.KeyNotFoundException;
import org.apache.storm.generated.ReadableBlobMeta;
-import org.apache.storm.generated.SettableBlobMeta;
+
+import org.apache.storm.nimbus.ILeaderElector;
import org.apache.storm.nimbus.NimbusInfo;
import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.ObjectReader;
import org.apache.storm.utils.Utils;
+import org.apache.storm.zookeeper.Zookeeper;
import org.apache.zookeeper.KeeperException.NoNodeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,6 +53,9 @@ import org.slf4j.LoggerFactory;
import static org.apache.storm.blobstore.BlobStoreAclHandler.ADMIN;
import static org.apache.storm.blobstore.BlobStoreAclHandler.READ;
import static org.apache.storm.blobstore.BlobStoreAclHandler.WRITE;
+import static org.apache.storm.daemon.nimbus.Nimbus.NIMBUS_SUBJECT;
+import static org.apache.storm.daemon.nimbus.Nimbus.getNimbusAcls;
+import static org.apache.storm.daemon.nimbus.Nimbus.getVersionForKey;
/**
* Provides a local file system backed blob store implementation for Nimbus.
@@ -70,6 +86,9 @@ public class LocalFsBlobStore extends BlobStore {
private FileBlobStoreImpl fbs;
private Map<String, Object> conf;
private CuratorFramework zkClient;
+ private IStormClusterState stormClusterState;
+ private Timer timer;
+ private ILeaderElector leaderElector;
@Override
public void prepare(Map<String, Object> conf, String overrideBase, NimbusInfo nimbusInfo) {
@@ -86,6 +105,106 @@ public class LocalFsBlobStore extends BlobStore {
throw new RuntimeException(e);
}
_aclHandler = new BlobStoreAclHandler(conf);
+ try {
+ this.stormClusterState = ClusterUtils.mkStormClusterState(conf, new ClusterStateContext(DaemonType.NIMBUS, conf));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ timer = new Timer();
+ try {
+ this.leaderElector = Zookeeper.zkLeaderElector(conf, zkClient, this, null, stormClusterState, getNimbusAcls(conf));
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Sets up blobstore state for all current keys.
+ * @throws KeyNotFoundException
+ * @throws AuthorizationException
+ */
+ private void setupBlobstore() throws AuthorizationException, KeyNotFoundException {
+ IStormClusterState state = stormClusterState;
+ BlobStore store = this;
+ Set<String> localKeys = new HashSet<>();
+ for (Iterator<String> it = store.listKeys(); it.hasNext();) {
+ localKeys.add(it.next());
+ }
+ Set<String> activeKeys = new HashSet<>(state.activeKeys());
+ Set<String> activeLocalKeys = new HashSet<>(localKeys);
+ activeLocalKeys.retainAll(activeKeys);
+ Set<String> keysToDelete = new HashSet<>(localKeys);
+ keysToDelete.removeAll(activeKeys);
+ NimbusInfo nimbusInfo = this.nimbusInfo;
+ LOG.debug("Deleting keys not on the zookeeper {}", keysToDelete);
+ for (String toDelete: keysToDelete) {
+ store.deleteBlob(toDelete, NIMBUS_SUBJECT);
+ }
+ LOG.debug("Creating list of key entries for blobstore inside zookeeper {} local {}", activeKeys, activeLocalKeys);
+ for (String key: activeLocalKeys) {
+ try {
+ state.setupBlob(key, nimbusInfo, getVersionForKey(key, nimbusInfo, zkClient));
+ } catch (KeyNotFoundException e) {
+ // invalid key, remove it from blobstore
+ store.deleteBlob(key, NIMBUS_SUBJECT);
+ }
+ }
+ }
+
+
+ private void blobSync() throws Exception {
+ if ("distributed".equals(conf.get(Config.STORM_CLUSTER_MODE))) {
+ if (!this.leaderElector.isLeader()) {
+ IStormClusterState state = stormClusterState;
+ NimbusInfo nimbusInfo = this.nimbusInfo;
+ BlobStore store = this;
+ Set<String> allKeys = new HashSet<>();
+ for (Iterator<String> it = store.listKeys(); it.hasNext();) {
+ allKeys.add(it.next());
+ }
+ Set<String> zkKeys = new HashSet<>(state.blobstore(() -> {
+ try {
+ this.blobSync();
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+ }));
+ LOG.debug("blob-sync blob-store-keys {} zookeeper-keys {}", allKeys, zkKeys);
+ LocalFsBlobStoreSynchronizer sync = new LocalFsBlobStoreSynchronizer(store, conf);
+ sync.setNimbusInfo(nimbusInfo);
+ sync.setBlobStoreKeySet(allKeys);
+ sync.setZookeeperKeySet(zkKeys);
+ sync.setZkClient(zkClient);
+ sync.syncBlobs();
+ } //else not leader (NOOP)
+ } //else local (NOOP)
+ }
+
+
+ @Override
+ public void startSyncBlobs() throws KeyNotFoundException, AuthorizationException {
+ //register call back for blob-store
+ this.stormClusterState.blobstore(() -> {
+ try {
+ blobSync();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ });
+ setupBlobstore();
+
+ //Schedule nimbus code sync thread to sync code from other nimbuses.
+ this.timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ blobSync();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }, 0, ObjectReader.getInt(conf.get(DaemonConfig.NIMBUS_CODE_SYNC_FREQ_SECS)));
+
}
@Override
@@ -105,9 +224,12 @@ public class LocalFsBlobStore extends BlobStore {
mOut.write(Utils.thriftSerialize(meta));
mOut.close();
mOut = null;
- return new BlobStoreFileOutputStream(fbs.write(DATA_PREFIX + key, true));
+ this.stormClusterState.setupBlob(key, this.nimbusInfo, getVersionForKey(key, this.nimbusInfo, zkClient));
+ return new BlobStoreFileOutputStream(fbs.write(DATA_PREFIX+key, true));
} catch (IOException e) {
throw new RuntimeException(e);
+ } catch (KeyNotFoundException e) {
+ throw new RuntimeException(e);
} finally {
if (mOut != null) {
try {
@@ -234,6 +356,8 @@ public class LocalFsBlobStore extends BlobStore {
} catch (IOException e) {
throw new RuntimeException(e);
}
+ this.stormClusterState.removeBlobstoreKey(key);
+ this.stormClusterState.removeKeyVersion(key);
}
private void checkPermission(String key, Subject who, int mask) throws KeyNotFoundException, AuthorizationException {
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-server/src/main/java/org/apache/storm/blobstore/LocalFsBlobStoreSynchronizer.java
----------------------------------------------------------------------
diff --git a/storm-server/src/main/java/org/apache/storm/blobstore/LocalFsBlobStoreSynchronizer.java b/storm-server/src/main/java/org/apache/storm/blobstore/LocalFsBlobStoreSynchronizer.java
new file mode 100644
index 0000000..133a99b
--- /dev/null
+++ b/storm-server/src/main/java/org/apache/storm/blobstore/LocalFsBlobStoreSynchronizer.java
@@ -0,0 +1,129 @@
+/**
+ * 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.blobstore;
+
+import java.nio.channels.ClosedByInterruptException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.storm.generated.KeyNotFoundException;
+import org.apache.storm.nimbus.NimbusInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Is called periodically and updates the nimbus with blobs based on the state stored inside the zookeeper
+ * for a non leader nimbus trying to be in sync with the operations performed on the leader nimbus.
+ */
+public class LocalFsBlobStoreSynchronizer {
+ private static final Logger LOG = LoggerFactory.getLogger(LocalFsBlobStoreSynchronizer.class);
+ private CuratorFramework zkClient;
+ private Map<String, Object> conf;
+ private BlobStore blobStore;
+ private Set<String> blobStoreKeySet = new HashSet<String>();
+ private Set<String> zookeeperKeySet = new HashSet<String>();
+ private NimbusInfo nimbusInfo;
+
+ public LocalFsBlobStoreSynchronizer(BlobStore blobStore, Map<String, Object> conf) {
+ this.blobStore = blobStore;
+ this.conf = conf;
+ }
+
+ public void setNimbusInfo(NimbusInfo nimbusInfo) {
+ this.nimbusInfo = nimbusInfo;
+ }
+
+ public void setZkClient(CuratorFramework zkClient) {
+ this.zkClient = zkClient;
+ }
+
+ public Set<String> getBlobStoreKeySet() {
+ Set<String> keySet = new HashSet<String>();
+ keySet.addAll(blobStoreKeySet);
+ return keySet;
+ }
+
+ public void setBlobStoreKeySet(Set<String> blobStoreKeySet) {
+ this.blobStoreKeySet = blobStoreKeySet;
+ }
+
+ public Set<String> getZookeeperKeySet() {
+ Set<String> keySet = new HashSet<String>();
+ keySet.addAll(zookeeperKeySet);
+ return keySet;
+ }
+
+ public void setZookeeperKeySet(Set<String> zookeeperKeySet) {
+ this.zookeeperKeySet = zookeeperKeySet;
+ }
+
+ public synchronized void syncBlobs() {
+ try {
+ LOG.debug("Sync blobs - blobstore keys {}, zookeeper keys {}", getBlobStoreKeySet(), getZookeeperKeySet());
+ deleteKeySetFromBlobStoreNotOnZookeeper(getBlobStoreKeySet(), getZookeeperKeySet());
+ updateKeySetForBlobStore(getBlobStoreKeySet());
+ Set<String> keySetToDownload = getKeySetToDownload(getBlobStoreKeySet(), getZookeeperKeySet());
+ LOG.debug("Key set Blobstore-> Zookeeper-> DownloadSet {}-> {}-> {}", getBlobStoreKeySet(), getZookeeperKeySet(),
+ keySetToDownload);
+
+ for (String key : keySetToDownload) {
+ try {
+ Set<NimbusInfo> nimbusInfoSet = BlobStoreUtils.getNimbodesWithLatestSequenceNumberOfBlob(zkClient, key);
+ // Removing self so as not to create a deadlock where a nimbus is trying to download a missing blob
+ // from itself
+ nimbusInfoSet.remove(this.nimbusInfo);
+ LOG.debug("syncBlobs, key: {}, nimbusInfoSet: {}", key, nimbusInfoSet);
+ if (BlobStoreUtils.downloadMissingBlob(conf, blobStore, key, nimbusInfoSet)) {
+ BlobStoreUtils.createStateInZookeeper(conf, key, nimbusInfo);
+ }
+ } catch (KeyNotFoundException e) {
+ LOG.debug("Detected deletion for the key {} while downloading - skipping download", key);
+ }
+ }
+ } catch (InterruptedException | ClosedByInterruptException exp) {
+ LOG.error("Interrupt Exception {}", exp);
+ } catch (Exception exp) {
+ throw new RuntimeException(exp);
+ }
+ }
+
+ public void deleteKeySetFromBlobStoreNotOnZookeeper(Set<String> keySetBlobStore, Set<String> keySetZookeeper) throws Exception {
+ if (keySetBlobStore.removeAll(keySetZookeeper)
+ || (keySetZookeeper.isEmpty() && !keySetBlobStore.isEmpty())) {
+ LOG.debug("Key set to delete in blobstore {}", keySetBlobStore);
+ for (String key : keySetBlobStore) {
+ blobStore.deleteBlob(key, BlobStoreUtils.getNimbusSubject());
+ }
+ }
+ }
+
+ // Update current key list inside the blobstore if the version changes
+ public void updateKeySetForBlobStore(Set<String> keySetBlobStore) {
+ try {
+ for (String key : keySetBlobStore) {
+ LOG.debug("updating blob");
+ BlobStoreUtils.updateKeyForBlobStore(conf, blobStore, zkClient, key, nimbusInfo);
+ }
+ } catch (Exception exp) {
+ throw new RuntimeException(exp);
+ }
+ }
+
+ // Make a key list to download
+ public Set<String> getKeySetToDownload(Set<String> blobStoreKeySet, Set<String> zookeeperKeySet) {
+ zookeeperKeySet.removeAll(blobStoreKeySet);
+ LOG.debug("Key list to download {}", zookeeperKeySet);
+ return zookeeperKeySet;
+ }
+}
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
----------------------------------------------------------------------
diff --git a/storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java b/storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
index d18553f..3c2ff26 100644
--- a/storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
+++ b/storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
@@ -64,7 +64,6 @@ import org.apache.storm.StormTimer;
import org.apache.storm.blobstore.AtomicOutputStream;
import org.apache.storm.blobstore.BlobStore;
import org.apache.storm.blobstore.BlobStoreAclHandler;
-import org.apache.storm.blobstore.BlobSynchronizer;
import org.apache.storm.blobstore.InputStreamWithMeta;
import org.apache.storm.blobstore.KeySequenceNumber;
import org.apache.storm.blobstore.LocalFsBlobStore;
@@ -255,7 +254,22 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
private static final Meter shutdownCalls = StormMetricsRegistry.registerMeter("nimbus:num-shutdown-calls");
private static final Meter processWorkerMetricsCalls = StormMetricsRegistry.registerMeter("nimbus:process-worker-metric-calls");
private static final String STORM_VERSION = VersionInfo.getVersion();
- private static final Subject NIMBUS_SUBJECT = new Subject();
+
+ public static List<ACL> getNimbusAcls(Map<String, Object> conf) {
+ List<ACL> acls = null;
+ if (Utils.isZkAuthenticationConfiguredStormServer(conf)) {
+ acls = ZK_ACLS;
+ }
+ return acls;
+ }
+
+ public static final Subject NIMBUS_SUBJECT = new Subject();
+
+ static {
+ NIMBUS_SUBJECT.getPrincipals().add(new NimbusPrincipal());
+ NIMBUS_SUBJECT.setReadOnly();
+ }
+
private static final TopologyStateTransition NOOP_TRANSITION = (arg, nimbus, topoId, base) -> null;
private static final TopologyStateTransition INACTIVE_TRANSITION = (arg, nimbus, topoId, base) -> Nimbus.make(TopologyStatus.INACTIVE);
private static final TopologyStateTransition ACTIVE_TRANSITION = (arg, nimbus, topoId, base) -> Nimbus.make(TopologyStatus.ACTIVE);
@@ -511,14 +525,6 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
Utils.getConfiguredClasspathVersions(conf, EMPTY_STRING_LIST));// We don't use the classpath part of this, so just an empty list
}
- private static List<ACL> getNimbusAcls(Map<String, Object> conf) {
- List<ACL> acls = null;
- if (Utils.isZkAuthenticationConfiguredStormServer(conf)) {
- acls = ZK_ACLS;
- }
- return acls;
- }
-
// TOPOLOGY STATE TRANSITIONS
private static StormBase make(TopologyStatus status) {
StormBase ret = new StormBase();
@@ -652,9 +658,8 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
}
return ret;
}
-
- private static int getVersionForKey(String key, NimbusInfo nimbusInfo,
- CuratorFramework zkClient) throws KeyNotFoundException {
+ public static int getVersionForKey(String key, NimbusInfo nimbusInfo,
+ CuratorFramework zkClient) throws KeyNotFoundException {
KeySequenceNumber kseq = new KeySequenceNumber(key, nimbusInfo);
return kseq.getKeySequenceNumber(zkClient);
}
@@ -918,9 +923,6 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
private static void rmBlobKey(BlobStore store, String key, IStormClusterState state) {
try {
store.deleteBlob(key, NIMBUS_SUBJECT);
- if (store instanceof LocalFsBlobStore) {
- state.removeBlobstoreKey(key);
- }
} catch (Exception e) {
//Yes eat the exception
LOG.info("Exception {}", e);
@@ -1411,20 +1413,10 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
try (FileInputStream fin = new FileInputStream(tmpJarLocation)) {
store.createBlob(jarKey, fin, new SettableBlobMeta(BlobStoreAclHandler.DEFAULT), subject);
}
- if (store instanceof LocalFsBlobStore) {
- clusterState.setupBlobstore(jarKey, hostPortInfo, getVersionForKey(jarKey, hostPortInfo, zkClient));
- }
}
topoCache.addTopoConf(topoId, subject, topoConf);
- if (store instanceof LocalFsBlobStore) {
- clusterState.setupBlobstore(confKey, hostPortInfo, getVersionForKey(confKey, hostPortInfo, zkClient));
- }
-
topoCache.addTopology(topoId, subject, topology);
- if (store instanceof LocalFsBlobStore) {
- clusterState.setupBlobstore(codeKey, hostPortInfo, getVersionForKey(codeKey, hostPortInfo, zkClient));
- }
}
private void updateTopologyResources(String topoId, Map<String, Map<String, Double>> resourceOverrides, Subject subject)
@@ -2422,40 +2414,6 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
}
}
- /**
- * Sets up blobstore state for all current keys.
- *
- * @throws KeyNotFoundException
- * @throws AuthorizationException
- */
- private void setupBlobstore() throws AuthorizationException, KeyNotFoundException {
- IStormClusterState state = stormClusterState;
- BlobStore store = blobStore;
- Set<String> localKeys = new HashSet<>();
- for (Iterator<String> it = store.listKeys(); it.hasNext(); ) {
- localKeys.add(it.next());
- }
- Set<String> activeKeys = new HashSet<>(state.activeKeys());
- Set<String> activeLocalKeys = new HashSet<>(localKeys);
- activeLocalKeys.retainAll(activeKeys);
- Set<String> keysToDelete = new HashSet<>(localKeys);
- keysToDelete.removeAll(activeKeys);
- NimbusInfo nimbusInfo = nimbusHostPortInfo;
- LOG.debug("Deleting keys not on the zookeeper {}", keysToDelete);
- for (String toDelete : keysToDelete) {
- store.deleteBlob(toDelete, NIMBUS_SUBJECT);
- }
- LOG.debug("Creating list of key entries for blobstore inside zookeeper {} local {}", activeKeys, activeLocalKeys);
- for (String key : activeLocalKeys) {
- try {
- state.setupBlobstore(key, nimbusInfo, getVersionForKey(key, nimbusInfo, zkClient));
- } catch (KeyNotFoundException e) {
- // invalid key, remove it from blobstore
- store.deleteBlob(key, NIMBUS_SUBJECT);
- }
- }
- }
-
private void addTopoToHistoryLog(String topoId, Map<String, Object> topoConf) {
LOG.info("Adding topo to history log: {}", topoId);
LocalState state = topologyHistoryState;
@@ -2540,34 +2498,6 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
}
}
- private void blobSync() throws Exception {
- if ("distributed".equals(conf.get(Config.STORM_CLUSTER_MODE))) {
- if (!isLeader()) {
- IStormClusterState state = stormClusterState;
- NimbusInfo nimbusInfo = nimbusHostPortInfo;
- BlobStore store = blobStore;
- Set<String> allKeys = new HashSet<>();
- for (Iterator<String> it = store.listKeys(); it.hasNext(); ) {
- allKeys.add(it.next());
- }
- Set<String> zkKeys = new HashSet<>(state.blobstore(() -> {
- try {
- this.blobSync();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }));
- LOG.debug("blob-sync blob-store-keys {} zookeeper-keys {}", allKeys, zkKeys);
- BlobSynchronizer sync = new BlobSynchronizer(store, conf);
- sync.setNimbusInfo(nimbusInfo);
- sync.setBlobStoreKeySet(allKeys);
- sync.setZookeeperKeySet(zkKeys);
- sync.setZkClient(zkClient);
- sync.syncBlobs();
- } //else not leader (NOOP)
- } //else local (NOOP)
- }
-
private SupervisorSummary makeSupervisorSummary(String supervisorId, SupervisorInfo info) {
LOG.debug("INFO: {} ID: {}", info, supervisorId);
int numPorts = 0;
@@ -2731,20 +2661,9 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
state.addNimbusHost(hpi.getHost(),
new NimbusSummary(hpi.getHost(), hpi.getPort(), Time.currentTimeSecs(), false, STORM_VERSION));
leaderElector.addToLeaderLockQueue();
-
- if (store instanceof LocalFsBlobStore) {
- //register call back for blob-store
- state.blobstore(() -> {
- try {
- blobSync();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- });
- setupBlobstore();
- }
-
- for (ClusterMetricsConsumerExecutor exec : clusterConsumerExceutors) {
+ this.blobStore.startSyncBlobs();
+
+ for (ClusterMetricsConsumerExecutor exec: clusterConsumerExceutors) {
exec.prepare();
}
@@ -2770,25 +2689,14 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
// Schedule Nimbus inbox cleaner
final int jarExpSecs = ObjectReader.getInt(conf.get(DaemonConfig.NIMBUS_INBOX_JAR_EXPIRATION_SECS));
timer.scheduleRecurring(0, ObjectReader.getInt(conf.get(DaemonConfig.NIMBUS_CLEANUP_INBOX_FREQ_SECS)),
- () -> {
- try {
- cleanInbox(getInbox(), jarExpSecs);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- });
-
- //Schedule nimbus code sync thread to sync code from other nimbuses.
- if (store instanceof LocalFsBlobStore) {
- timer.scheduleRecurring(0, ObjectReader.getInt(conf.get(DaemonConfig.NIMBUS_CODE_SYNC_FREQ_SECS)),
- () -> {
- try {
- blobSync();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- });
- }
+ () -> {
+ try {
+ cleanInbox(getInbox(), jarExpSecs);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ });
+
// Schedule topology history cleaner
Integer interval = ObjectReader.getInt(conf.get(DaemonConfig.LOGVIEWER_CLEANUP_INTERVAL_SECS), null);
@@ -3577,10 +3485,6 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
public void deleteBlob(String key) throws AuthorizationException, KeyNotFoundException, TException {
try {
blobStore.deleteBlob(key, getSubject());
- if (blobStore instanceof LocalFsBlobStore) {
- stormClusterState.removeBlobstoreKey(key);
- stormClusterState.removeKeyVersion(key);
- }
LOG.info("Deleted blob for key {}", key);
} catch (Exception e) {
LOG.warn("delete blob exception.", e);
@@ -3667,7 +3571,7 @@ public class Nimbus implements Iface, Shutdownable, DaemonCommon {
BlobStore store = blobStore;
NimbusInfo ni = nimbusHostPortInfo;
if (store instanceof LocalFsBlobStore) {
- state.setupBlobstore(key, ni, getVersionForKey(key, ni, zkClient));
+ state.setupBlob(key, ni, getVersionForKey(key, ni, zkClient));
}
LOG.debug("Created state in zookeeper {} {} {}", state, store, ni);
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-server/src/test/java/org/apache/storm/blobstore/BlobStoreTest.java
----------------------------------------------------------------------
diff --git a/storm-server/src/test/java/org/apache/storm/blobstore/BlobStoreTest.java b/storm-server/src/test/java/org/apache/storm/blobstore/BlobStoreTest.java
deleted file mode 100644
index 57b0750..0000000
--- a/storm-server/src/test/java/org/apache/storm/blobstore/BlobStoreTest.java
+++ /dev/null
@@ -1,467 +0,0 @@
-/**
- * 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.blobstore;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.file.Files;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import javax.security.auth.Subject;
-import org.apache.commons.io.FileUtils;
-import org.apache.storm.Config;
-import org.apache.storm.generated.AuthorizationException;
-import org.apache.storm.generated.KeyAlreadyExistsException;
-import org.apache.storm.generated.KeyNotFoundException;
-import org.apache.storm.generated.SettableBlobMeta;
-import org.apache.storm.security.auth.NimbusPrincipal;
-import org.apache.storm.security.auth.SingleUserPrincipal;
-import org.apache.storm.utils.Utils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.spy;
-
-public class BlobStoreTest {
- public static final int READ = 0x01;
- public static final int WRITE = 0x02;
- public static final int ADMIN = 0x04;
- private static final Logger LOG = LoggerFactory.getLogger(BlobStoreTest.class);
- private static Map<String, Object> conf = new HashMap();
- URI base;
- File baseFile;
-
- // Method which initializes nimbus admin
- public static void initializeConfigs() {
- conf.put(Config.NIMBUS_ADMINS, "admin");
- conf.put(Config.NIMBUS_SUPERVISOR_USERS, "supervisor");
- }
-
- // Gets Nimbus Subject with NimbusPrincipal set on it
- public static Subject getNimbusSubject() {
- Subject nimbus = new Subject();
- nimbus.getPrincipals().add(new NimbusPrincipal());
- return nimbus;
- }
-
- // Overloading the assertStoreHasExactly method accomodate Subject in order to check for authorization
- public static void assertStoreHasExactly(BlobStore store, Subject who, String... keys)
- throws IOException, KeyNotFoundException, AuthorizationException {
- Set<String> expected = new HashSet<String>(Arrays.asList(keys));
- Set<String> found = new HashSet<String>();
- Iterator<String> c = store.listKeys();
- while (c.hasNext()) {
- String keyName = c.next();
- found.add(keyName);
- }
- Set<String> extra = new HashSet<String>(found);
- extra.removeAll(expected);
- assertTrue("Found extra keys in the blob store " + extra, extra.isEmpty());
- Set<String> missing = new HashSet<String>(expected);
- missing.removeAll(found);
- assertTrue("Found keys missing from the blob store " + missing, missing.isEmpty());
- }
-
- public static void assertStoreHasExactly(BlobStore store, String... keys)
- throws IOException, KeyNotFoundException, AuthorizationException {
- assertStoreHasExactly(store, null, keys);
- }
-
- // Overloading the readInt method accomodate Subject in order to check for authorization (security turned on)
- public static int readInt(BlobStore store, Subject who, String key)
- throws IOException, KeyNotFoundException, AuthorizationException {
- InputStream in = store.getBlob(key, who);
- try {
- return in.read();
- } finally {
- in.close();
- }
- }
-
- public static int readInt(BlobStore store, String key)
- throws IOException, KeyNotFoundException, AuthorizationException {
- return readInt(store, null, key);
- }
-
- public static void readAssertEquals(BlobStore store, String key, int value)
- throws IOException, KeyNotFoundException, AuthorizationException {
- assertEquals(value, readInt(store, key));
- }
-
- @Before
- public void init() {
- initializeConfigs();
- baseFile = new File("target/blob-store-test-" + UUID.randomUUID());
- base = baseFile.toURI();
- }
-
- @After
- public void cleanup() throws IOException {
- FileUtils.deleteDirectory(baseFile);
- }
-
- // Checks for assertion when we turn on security
- public void readAssertEqualsWithAuth(BlobStore store, Subject who, String key, int value)
- throws IOException, KeyNotFoundException, AuthorizationException {
- assertEquals(value, readInt(store, who, key));
- }
-
- private LocalFsBlobStore initLocalFs() {
- LocalFsBlobStore store = new LocalFsBlobStore();
- // Spy object that tries to mock the real object store
- LocalFsBlobStore spy = spy(store);
- Mockito.doNothing().when(spy).checkForBlobUpdate("test");
- Mockito.doNothing().when(spy).checkForBlobUpdate("other");
- Mockito.doNothing().when(spy).checkForBlobUpdate("test-empty-subject-WE");
- Mockito.doNothing().when(spy).checkForBlobUpdate("test-empty-subject-DEF");
- Mockito.doNothing().when(spy).checkForBlobUpdate("test-empty-acls");
- Map<String, Object> conf = Utils.readStormConfig();
- conf.put(Config.STORM_LOCAL_DIR, baseFile.getAbsolutePath());
- conf.put(Config.STORM_PRINCIPAL_TO_LOCAL_PLUGIN, "org.apache.storm.security.auth.DefaultPrincipalToLocal");
- spy.prepare(conf, null, null);
- return spy;
- }
-
- @Test
- public void testLocalFsWithAuth() throws Exception {
- testWithAuthentication(initLocalFs());
- }
-
- @Test
- public void testBasicLocalFs() throws Exception {
- testBasic(initLocalFs());
- }
-
- @Test
- public void testMultipleLocalFs() throws Exception {
- testMultiple(initLocalFs());
- }
-
- @Test
- public void testDeleteAfterFailedCreate() throws Exception {
- //Check that a blob can be deleted when a temporary file exists in the blob directory
- LocalFsBlobStore store = initLocalFs();
-
- String key = "test";
- SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler
- .WORLD_EVERYTHING);
- try (AtomicOutputStream out = store.createBlob(key, metadata, null)) {
- out.write(1);
- File blobDir = store.getKeyDataDir(key);
- Files.createFile(blobDir.toPath().resolve("tempFile.tmp"));
- }
-
- store.deleteBlob("test", null);
-
- }
-
- public Subject getSubject(String name) {
- Subject subject = new Subject();
- SingleUserPrincipal user = new SingleUserPrincipal(name);
- subject.getPrincipals().add(user);
- return subject;
- }
-
- // Check for Blobstore with authentication
- public void testWithAuthentication(BlobStore store) throws Exception {
- //Test for Nimbus Admin
- Subject admin = getSubject("admin");
- assertStoreHasExactly(store);
- SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
- try (AtomicOutputStream out = store.createBlob("test", metadata, admin)) {
- assertStoreHasExactly(store, "test");
- out.write(1);
- }
- store.deleteBlob("test", admin);
-
- //Test for Supervisor Admin
- Subject supervisor = getSubject("supervisor");
- assertStoreHasExactly(store);
- metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
- try (AtomicOutputStream out = store.createBlob("test", metadata, supervisor)) {
- assertStoreHasExactly(store, "test");
- out.write(1);
- }
- store.deleteBlob("test", supervisor);
-
- //Test for Nimbus itself as a user
- Subject nimbus = getNimbusSubject();
- assertStoreHasExactly(store);
- metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
- try (AtomicOutputStream out = store.createBlob("test", metadata, nimbus)) {
- assertStoreHasExactly(store, "test");
- out.write(1);
- }
- store.deleteBlob("test", nimbus);
-
- // Test with a dummy test_subject for cases where subject !=null (security turned on)
- Subject who = getSubject("test_subject");
- assertStoreHasExactly(store);
-
- // Tests for case when subject != null (security turned on) and
- // acls for the blob are set to WORLD_EVERYTHING
- metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
- try (AtomicOutputStream out = store.createBlob("test", metadata, who)) {
- out.write(1);
- }
- assertStoreHasExactly(store, "test");
- // Testing whether acls are set to WORLD_EVERYTHING
- assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
- readAssertEqualsWithAuth(store, who, "test", 1);
-
- LOG.info("Deleting test");
- store.deleteBlob("test", who);
- assertStoreHasExactly(store);
-
- // Tests for case when subject != null (security turned on) and
- // acls are not set for the blob (DEFAULT)
- LOG.info("Creating test again");
- metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
- try (AtomicOutputStream out = store.createBlob("test", metadata, who)) {
- out.write(2);
- }
- assertStoreHasExactly(store, "test");
- // Testing whether acls are set to WORLD_EVERYTHING. Here the acl should not contain WORLD_EVERYTHING because
- // the subject is neither null nor empty. The ACL should however contain USER_EVERYTHING as user needs to have
- // complete access to the blob
- assertTrue("ACL does not contain WORLD_EVERYTHING", !metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
- readAssertEqualsWithAuth(store, who, "test", 2);
-
- LOG.info("Updating test");
- try (AtomicOutputStream out = store.updateBlob("test", who)) {
- out.write(3);
- }
- assertStoreHasExactly(store, "test");
- readAssertEqualsWithAuth(store, who, "test", 3);
-
- LOG.info("Updating test again");
- try (AtomicOutputStream out = store.updateBlob("test", who)) {
- out.write(4);
- out.flush();
- LOG.info("SLEEPING");
- Thread.sleep(2);
- assertStoreHasExactly(store, "test");
- readAssertEqualsWithAuth(store, who, "test", 3);
- }
-
- // Test for subject with no principals and acls set to WORLD_EVERYTHING
- who = new Subject();
- metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
- LOG.info("Creating test");
- try (AtomicOutputStream out = store.createBlob("test-empty-subject-WE", metadata, who)) {
- out.write(2);
- }
- assertStoreHasExactly(store, "test-empty-subject-WE", "test");
- // Testing whether acls are set to WORLD_EVERYTHING
- assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
- readAssertEqualsWithAuth(store, who, "test-empty-subject-WE", 2);
-
- // Test for subject with no principals and acls set to DEFAULT
- who = new Subject();
- metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
- LOG.info("Creating other");
-
- try (AtomicOutputStream out = store.createBlob("test-empty-subject-DEF", metadata, who)) {
- out.write(2);
- }
- assertStoreHasExactly(store, "test-empty-subject-DEF", "test", "test-empty-subject-WE");
- // Testing whether acls are set to WORLD_EVERYTHING
- assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
- readAssertEqualsWithAuth(store, who, "test-empty-subject-DEF", 2);
-
- if (store instanceof LocalFsBlobStore) {
- ((LocalFsBlobStore) store).fullCleanup(1);
- } else {
- fail("Error the blobstore is of unknowntype");
- }
- }
-
- public void testBasic(BlobStore store) throws Exception {
- assertStoreHasExactly(store);
- LOG.info("Creating test");
- // Tests for case when subject == null (security turned off) and
- // acls for the blob are set to WORLD_EVERYTHING
- SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler
- .WORLD_EVERYTHING);
- try (AtomicOutputStream out = store.createBlob("test", metadata, null)) {
- out.write(1);
- }
- assertStoreHasExactly(store, "test");
- // Testing whether acls are set to WORLD_EVERYTHING
- assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
- readAssertEquals(store, "test", 1);
-
- LOG.info("Deleting test");
- store.deleteBlob("test", null);
- assertStoreHasExactly(store);
-
- // The following tests are run for both hdfs and local store to test the
- // update blob interface
- metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
- LOG.info("Creating test again");
- try (AtomicOutputStream out = store.createBlob("test", metadata, null)) {
- out.write(2);
- }
- assertStoreHasExactly(store, "test");
- if (store instanceof LocalFsBlobStore) {
- assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
- }
- readAssertEquals(store, "test", 2);
- LOG.info("Updating test");
- try (AtomicOutputStream out = store.updateBlob("test", null)) {
- out.write(3);
- }
- assertStoreHasExactly(store, "test");
- readAssertEquals(store, "test", 3);
-
- LOG.info("Updating test again");
- try (AtomicOutputStream out = store.updateBlob("test", null)) {
- out.write(4);
- out.flush();
- LOG.info("SLEEPING");
- Thread.sleep(2);
- }
-
- // Tests for case when subject == null (security turned off) and
- // acls for the blob are set to DEFAULT (Empty ACL List) only for LocalFsBlobstore
- if (store instanceof LocalFsBlobStore) {
- metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
- LOG.info("Creating test for empty acls when security is off");
- try (AtomicOutputStream out = store.createBlob("test-empty-acls", metadata, null)) {
- LOG.info("metadata {}", metadata);
- out.write(2);
- }
- assertStoreHasExactly(store, "test-empty-acls", "test");
- // Testing whether acls are set to WORLD_EVERYTHING, Here we are testing only for LocalFsBlobstore
- // as the HdfsBlobstore gets the subject information of the local system user and behaves as it is
- // always authenticated.
- assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.get_acl().toString().contains("OTHER"));
-
- LOG.info("Deleting test-empty-acls");
- store.deleteBlob("test-empty-acls", null);
- }
-
- if (store instanceof LocalFsBlobStore) {
- ((LocalFsBlobStore) store).fullCleanup(1);
- } else {
- fail("Error the blobstore is of unknowntype");
- }
- }
-
-
- public void testMultiple(BlobStore store) throws Exception {
-
- assertStoreHasExactly(store);
- LOG.info("Creating test");
- try (AtomicOutputStream out = store.createBlob("test", new SettableBlobMeta(BlobStoreAclHandler
- .WORLD_EVERYTHING), null)) {
- out.write(1);
- }
- assertStoreHasExactly(store, "test");
- readAssertEquals(store, "test", 1);
-
- LOG.info("Creating other");
- try (AtomicOutputStream out = store.createBlob("other", new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING),
- null)) {
- out.write(2);
- }
- assertStoreHasExactly(store, "test", "other");
- readAssertEquals(store, "test", 1);
- readAssertEquals(store, "other", 2);
-
- LOG.info("Updating other");
- try (AtomicOutputStream out = store.updateBlob("other", null)) {
- out.write(5);
- }
- assertStoreHasExactly(store, "test", "other");
- readAssertEquals(store, "test", 1);
- readAssertEquals(store, "other", 5);
-
- LOG.info("Deleting test");
- store.deleteBlob("test", null);
- assertStoreHasExactly(store, "other");
- readAssertEquals(store, "other", 5);
-
- LOG.info("Creating test again");
- try (AtomicOutputStream out = store.createBlob("test", new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING),
- null)) {
- out.write(2);
- }
- assertStoreHasExactly(store, "test", "other");
- readAssertEquals(store, "test", 2);
- readAssertEquals(store, "other", 5);
-
- LOG.info("Updating test");
- try (AtomicOutputStream out = store.updateBlob("test", null)) {
- out.write(3);
- }
- assertStoreHasExactly(store, "test", "other");
- readAssertEquals(store, "test", 3);
- readAssertEquals(store, "other", 5);
-
- LOG.info("Deleting other");
- store.deleteBlob("other", null);
- assertStoreHasExactly(store, "test");
- readAssertEquals(store, "test", 3);
-
- LOG.info("Updating test again");
-
- // intended to not guarding with try-with-resource since otherwise test will fail
- AtomicOutputStream out = store.updateBlob("test", null);
- out.write(4);
- out.flush();
- LOG.info("SLEEPING");
- Thread.sleep(2);
-
- if (store instanceof LocalFsBlobStore) {
- ((LocalFsBlobStore) store).fullCleanup(1);
- } else {
- fail("Error the blobstore is of unknowntype");
- }
- assertStoreHasExactly(store, "test");
- readAssertEquals(store, "test", 3);
- try {
- out.close();
- } catch (IOException e) {
- // This is likely to happen when we try to commit something that
- // was cleaned up. This is expected and acceptable.
- }
- }
-
- @Test
- public void testGetFileLength()
- throws AuthorizationException, KeyNotFoundException, KeyAlreadyExistsException, IOException {
- LocalFsBlobStore store = initLocalFs();
- try (AtomicOutputStream out = store.createBlob("test", new SettableBlobMeta(BlobStoreAclHandler
- .WORLD_EVERYTHING), null)) {
- out.write(1);
- }
- try (InputStreamWithMeta blobInputStream = store.getBlob("test", null)) {
- assertEquals(1, blobInputStream.getFileLength());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-server/src/test/java/org/apache/storm/blobstore/BlobSynchronizerTest.java
----------------------------------------------------------------------
diff --git a/storm-server/src/test/java/org/apache/storm/blobstore/BlobSynchronizerTest.java b/storm-server/src/test/java/org/apache/storm/blobstore/BlobSynchronizerTest.java
deleted file mode 100644
index d988b48..0000000
--- a/storm-server/src/test/java/org/apache/storm/blobstore/BlobSynchronizerTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * 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.blobstore;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import org.apache.commons.io.FileUtils;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-import org.apache.curator.test.TestingServer;
-import org.apache.storm.Config;
-import org.apache.storm.nimbus.NimbusInfo;
-import org.apache.storm.utils.Utils;
-import org.apache.zookeeper.server.NIOServerCnxnFactory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Unit tests for most of the testable utility methods
- * and BlobSynchronizer class methods
- */
-public class BlobSynchronizerTest {
- private static Map<String, Object> conf = new HashMap();
- private URI base;
- private File baseFile;
- private NIOServerCnxnFactory factory;
-
- // Method which initializes nimbus admin
- public static void initializeConfigs() {
- conf.put(Config.NIMBUS_ADMINS, "admin");
- conf.put(Config.NIMBUS_SUPERVISOR_USERS, "supervisor");
- }
-
- @Before
- public void init() throws Exception {
- initializeConfigs();
- baseFile = new File("target/blob-store-test-" + UUID.randomUUID());
- base = baseFile.toURI();
- }
-
- @After
- public void cleanUp() throws IOException {
- FileUtils.deleteDirectory(baseFile);
- if (factory != null) {
- factory.shutdown();
- }
- }
-
- private LocalFsBlobStore initLocalFs() {
- LocalFsBlobStore store = new LocalFsBlobStore();
- Map<String, Object> conf = Utils.readStormConfig();
- conf.put(Config.STORM_LOCAL_DIR, baseFile.getAbsolutePath());
- conf.put(Config.STORM_PRINCIPAL_TO_LOCAL_PLUGIN, "org.apache.storm.security.auth.DefaultPrincipalToLocal");
- this.conf = conf;
- store.prepare(conf, null, null);
- return store;
- }
-
- @Test
- public void testBlobSynchronizerForKeysToDownload() {
- BlobStore store = initLocalFs();
- BlobSynchronizer sync = new BlobSynchronizer(store, conf);
- // test for keylist to download
- Set<String> zkSet = new HashSet<String>();
- zkSet.add("key1");
- Set<String> blobStoreSet = new HashSet<String>();
- blobStoreSet.add("key1");
- Set<String> resultSet = sync.getKeySetToDownload(blobStoreSet, zkSet);
- assertTrue("Not Empty", resultSet.isEmpty());
- zkSet.add("key1");
- blobStoreSet.add("key2");
- resultSet = sync.getKeySetToDownload(blobStoreSet, zkSet);
- assertTrue("Not Empty", resultSet.isEmpty());
- blobStoreSet.remove("key1");
- blobStoreSet.remove("key2");
- zkSet.add("key1");
- resultSet = sync.getKeySetToDownload(blobStoreSet, zkSet);
- assertTrue("Unexpected keys to download", (resultSet.size() == 1) && (resultSet.contains("key1")));
- }
-
- @Test
- public void testGetLatestSequenceNumber() throws Exception {
- List<String> stateInfoList = new ArrayList<String>();
- stateInfoList.add("nimbus1:8000-2");
- stateInfoList.add("nimbus-1:8000-4");
- assertTrue("Failed to get the latest version", BlobStoreUtils.getLatestSequenceNumber(stateInfoList) == 4);
- }
-
- @Test
- public void testNimbodesWithLatestVersionOfBlob() throws Exception {
- try (TestingServer server = new TestingServer(); CuratorFramework zkClient = CuratorFrameworkFactory
- .newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3))) {
- zkClient.start();
- // Creating nimbus hosts containing latest version of blob
- zkClient.create().creatingParentContainersIfNeeded().forPath("/blobstore/key1/nimbus1:7800-1");
- zkClient.create().creatingParentContainersIfNeeded().forPath("/blobstore/key1/nimbus2:7800-2");
- Set<NimbusInfo> set = BlobStoreUtils.getNimbodesWithLatestSequenceNumberOfBlob(zkClient, "key1");
- assertEquals("Failed to get the correct nimbus hosts with latest blob version", (set.iterator().next()).getHost(), "nimbus2");
- zkClient.delete().deletingChildrenIfNeeded().forPath("/blobstore/key1/nimbus1:7800-1");
- zkClient.delete().deletingChildrenIfNeeded().forPath("/blobstore/key1/nimbus2:7800-2");
- }
- }
-
- @Test
- public void testNormalizeVersionInfo() throws Exception {
- BlobKeySequenceInfo info1 = BlobStoreUtils.normalizeNimbusHostPortSequenceNumberInfo("nimbus1:7800-1");
- assertTrue(info1.getNimbusHostPort().equals("nimbus1:7800"));
- assertTrue(info1.getSequenceNumber().equals("1"));
- BlobKeySequenceInfo info2 = BlobStoreUtils.normalizeNimbusHostPortSequenceNumberInfo("nimbus-1:7800-1");
- assertTrue(info2.getNimbusHostPort().equals("nimbus-1:7800"));
- assertTrue(info2.getSequenceNumber().equals("1"));
- }
-}
http://git-wip-us.apache.org/repos/asf/storm/blob/d5865711/storm-server/src/test/java/org/apache/storm/blobstore/LocalFsBlobStoreSynchronizerTest.java
----------------------------------------------------------------------
diff --git a/storm-server/src/test/java/org/apache/storm/blobstore/LocalFsBlobStoreSynchronizerTest.java b/storm-server/src/test/java/org/apache/storm/blobstore/LocalFsBlobStoreSynchronizerTest.java
new file mode 100644
index 0000000..4b190a6
--- /dev/null
+++ b/storm-server/src/test/java/org/apache/storm/blobstore/LocalFsBlobStoreSynchronizerTest.java
@@ -0,0 +1,136 @@
+/**
+ * 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.blobstore;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.commons.io.FileUtils;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.test.TestingServer;
+import org.apache.storm.Config;
+import org.apache.storm.nimbus.NimbusInfo;
+import org.apache.storm.utils.Utils;
+import org.apache.zookeeper.server.NIOServerCnxnFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for most of the testable utility methods
+ * and LocalFsBlobStoreSynchronizer class methods
+ */
+public class LocalFsBlobStoreSynchronizerTest {
+ private URI base;
+ private File baseFile;
+ private static Map<String, Object> conf = new HashMap();
+ private NIOServerCnxnFactory factory;
+
+ // Method which initializes nimbus admin
+ public static void initializeConfigs() {
+ conf.put(Config.NIMBUS_ADMINS, "admin");
+ conf.put(Config.NIMBUS_SUPERVISOR_USERS, "supervisor");
+ }
+
+ @Before
+ public void init() throws Exception {
+ initializeConfigs();
+ baseFile = new File("target/blob-store-test-" + UUID.randomUUID());
+ base = baseFile.toURI();
+ }
+
+ @After
+ public void cleanUp() throws IOException {
+ FileUtils.deleteDirectory(baseFile);
+ if (factory != null) {
+ factory.shutdown();
+ }
+ }
+
+ private LocalFsBlobStore initLocalFs() {
+ LocalFsBlobStore store = new LocalFsBlobStore();
+ Map<String, Object> conf = Utils.readStormConfig();
+ conf.put(Config.STORM_LOCAL_DIR, baseFile.getAbsolutePath());
+ conf.put(Config.STORM_PRINCIPAL_TO_LOCAL_PLUGIN, "org.apache.storm.security.auth.DefaultPrincipalToLocal");
+ this.conf = conf;
+ store.prepare(conf, null, null);
+ return store;
+ }
+
+ @Test
+ public void testBlobSynchronizerForKeysToDownload() {
+ BlobStore store = initLocalFs();
+ LocalFsBlobStoreSynchronizer sync = new LocalFsBlobStoreSynchronizer(store, conf);
+ // test for keylist to download
+ Set<String> zkSet = new HashSet<String>();
+ zkSet.add("key1");
+ Set<String> blobStoreSet = new HashSet<String>();
+ blobStoreSet.add("key1");
+ Set<String> resultSet = sync.getKeySetToDownload(blobStoreSet, zkSet);
+ assertTrue("Not Empty", resultSet.isEmpty());
+ zkSet.add("key1");
+ blobStoreSet.add("key2");
+ resultSet = sync.getKeySetToDownload(blobStoreSet, zkSet);
+ assertTrue("Not Empty", resultSet.isEmpty());
+ blobStoreSet.remove("key1");
+ blobStoreSet.remove("key2");
+ zkSet.add("key1");
+ resultSet = sync.getKeySetToDownload(blobStoreSet, zkSet);
+ assertTrue("Unexpected keys to download", (resultSet.size() == 1) && (resultSet.contains("key1")));
+ }
+
+ @Test
+ public void testGetLatestSequenceNumber() throws Exception {
+ List<String> stateInfoList = new ArrayList<String>();
+ stateInfoList.add("nimbus1:8000-2");
+ stateInfoList.add("nimbus-1:8000-4");
+ assertTrue("Failed to get the latest version", BlobStoreUtils.getLatestSequenceNumber(stateInfoList) == 4);
+ }
+
+ @Test
+ public void testNimbodesWithLatestVersionOfBlob() throws Exception {
+ try (TestingServer server = new TestingServer(); CuratorFramework zkClient = CuratorFrameworkFactory
+ .newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3))) {
+ zkClient.start();
+ // Creating nimbus hosts containing latest version of blob
+ zkClient.create().creatingParentContainersIfNeeded().forPath("/blobstore/key1/nimbus1:7800-1");
+ zkClient.create().creatingParentContainersIfNeeded().forPath("/blobstore/key1/nimbus2:7800-2");
+ Set<NimbusInfo> set = BlobStoreUtils.getNimbodesWithLatestSequenceNumberOfBlob(zkClient, "key1");
+ assertEquals("Failed to get the correct nimbus hosts with latest blob version", (set.iterator().next()).getHost(), "nimbus2");
+ zkClient.delete().deletingChildrenIfNeeded().forPath("/blobstore/key1/nimbus1:7800-1");
+ zkClient.delete().deletingChildrenIfNeeded().forPath("/blobstore/key1/nimbus2:7800-2");
+ }
+ }
+
+ @Test
+ public void testNormalizeVersionInfo() throws Exception {
+ BlobKeySequenceInfo info1 = BlobStoreUtils.normalizeNimbusHostPortSequenceNumberInfo("nimbus1:7800-1");
+ assertTrue(info1.getNimbusHostPort().equals("nimbus1:7800"));
+ assertTrue(info1.getSequenceNumber().equals("1"));
+ BlobKeySequenceInfo info2 = BlobStoreUtils.normalizeNimbusHostPortSequenceNumberInfo("nimbus-1:7800-1");
+ assertTrue(info2.getNimbusHostPort().equals("nimbus-1:7800"));
+ assertTrue(info2.getSequenceNumber().equals("1"));
+ }
+}