use of backtype.storm.generated.KeyNotFoundException in project jstorm by alibaba.
the class LocalFsBlobStore method getStoredBlobMeta.
private SettableBlobMeta getStoredBlobMeta(String key) throws KeyNotFoundException {
InputStream in = null;
try {
LocalFsBlobStoreFile pf = fbs.read(META_PREFIX + key);
try {
in = pf.getInputStream();
} catch (FileNotFoundException fnf) {
throw new KeyNotFoundException(key);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[2048];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
in.close();
in = null;
return JStormUtils.thriftDeserialize(SettableBlobMeta.class, out.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
//Ignored
}
}
}
}
use of backtype.storm.generated.KeyNotFoundException in project jstorm by alibaba.
the class BlobStoreUtils method downloadResourcesAsSupervisor.
/**
* Meant to be called only by the supervisor for stormjar/stormconf/stormcode files.
*
* @param key
* @param localFile
* @param cb
* @throws KeyNotFoundException
* @throws IOException
*/
public static void downloadResourcesAsSupervisor(String key, String localFile, ClientBlobStore cb, Map conf) throws KeyNotFoundException, IOException {
if (cb instanceof NimbusBlobStore) {
List<NimbusInfo> nimbusInfos = null;
CuratorFramework zkClient = null;
try {
zkClient = BlobStoreUtils.createZKClient(conf);
nimbusInfos = Lists.newArrayList(BlobStoreUtils.getNimbodesWithLatestSequenceNumberOfBlob(zkClient, key));
Collections.shuffle(nimbusInfos);
} catch (Exception e) {
LOG.error("get available nimbus for blob key:{} error", e);
return;
} finally {
if (zkClient != null) {
zkClient.close();
zkClient = null;
}
}
if (nimbusInfos != null) {
for (NimbusInfo nimbusInfo : nimbusInfos) {
try {
NimbusClient nimbusClient = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort());
cb.setClient(conf, nimbusClient);
} catch (TTransportException e) {
// ignore
continue;
}
LOG.info("download blob {} from nimbus {}:{}", key, nimbusInfo.getHost(), nimbusInfo.getPort());
downloadResourcesAsSupervisorDirect(key, localFile, cb);
}
}
} else {
downloadResourcesAsSupervisorDirect(key, localFile, cb);
}
}
use of backtype.storm.generated.KeyNotFoundException in project jstorm by alibaba.
the class ServiceHandler method copyBackToInbox.
private void copyBackToInbox(String topologyId, String topologyCodeLocation) throws Exception {
String codeKey = StormConfig.master_stormcode_key(topologyId);
String confKey = StormConfig.master_stormconf_key(topologyId);
String jarKey = StormConfig.master_stormjar_key(topologyId);
data.getBlobStore().readBlobTo(codeKey, new FileOutputStream(StormConfig.stormcode_path(topologyCodeLocation)));
data.getBlobStore().readBlobTo(confKey, new FileOutputStream(StormConfig.stormconf_path(topologyCodeLocation)));
data.getBlobStore().readBlobTo(jarKey, new FileOutputStream(StormConfig.stormjar_path(topologyCodeLocation)));
try {
Map stormConf = StormConfig.read_nimbus_topology_conf(topologyId, data.getBlobStore());
if (stormConf != null) {
List<String> libs = (List<String>) stormConf.get(GenericOptionsParser.TOPOLOGY_LIB_NAME);
FileUtils.forceMkdir(new File(topologyCodeLocation + File.separator + "lib"));
if (libs != null) {
for (String libName : libs) {
String libKey = StormConfig.master_stormlib_key(topologyId, libName);
data.getBlobStore().readBlobTo(libKey, new FileOutputStream(StormConfig.stormlib_path(topologyCodeLocation, libName)));
}
}
}
} catch (KeyNotFoundException e) {
LOG.warn("can't find conf of topology {}", topologyId);
}
}
use of backtype.storm.generated.KeyNotFoundException in project jstorm by alibaba.
the class BlobStoreUtils method downloadUpdatedBlob.
// Download updated blobs from potential nimbodes
public static boolean downloadUpdatedBlob(Map conf, BlobStore blobStore, String key, Set<NimbusInfo> nimbusInfos) throws TTransportException {
NimbusClient client;
ClientBlobStore remoteBlobStore;
InputStreamWithMeta in;
AtomicOutputStream out;
boolean isSuccess = false;
LOG.debug("Download blob NimbusInfos {}", nimbusInfos);
for (NimbusInfo nimbusInfo : nimbusInfos) {
if (isSuccess) {
break;
}
try {
client = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort(), null);
remoteBlobStore = new NimbusBlobStore();
remoteBlobStore.setClient(conf, client);
isSuccess = updateBlob(blobStore, key, remoteBlobStore.getBlob(key));
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (KeyNotFoundException knf) {
// Catching and logging KeyNotFoundException because, if
// there is a subsequent update and delete, the non-leader
// nimbodes might throw an exception.
LOG.info("KeyNotFoundException {}", knf);
} catch (Exception exp) {
// Logging an exception while client is connecting
LOG.error("Exception {}", exp);
}
}
if (!isSuccess) {
LOG.error("Could not update the blob with key" + key);
}
return isSuccess;
}
use of backtype.storm.generated.KeyNotFoundException in project jstorm by alibaba.
the class BlobStoreUtils method downloadMissingBlob.
// Download missing blobs from potential nimbodes
public static boolean downloadMissingBlob(Map conf, BlobStore blobStore, String key, Set<NimbusInfo> nimbusInfos) throws TTransportException {
NimbusClient client;
ReadableBlobMeta rbm;
ClientBlobStore remoteBlobStore;
InputStreamWithMeta in;
boolean isSuccess = false;
LOG.debug("Download blob NimbusInfos {}", nimbusInfos);
for (NimbusInfo nimbusInfo : nimbusInfos) {
if (isSuccess) {
break;
}
try {
client = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort(), null);
rbm = client.getClient().getBlobMeta(key);
remoteBlobStore = new NimbusBlobStore();
remoteBlobStore.setClient(conf, client);
in = remoteBlobStore.getBlob(key);
blobStore.createBlob(key, in, rbm.get_settable());
// if key already exists while creating the blob else update it
Iterator<String> keyIterator = blobStore.listKeys();
while (keyIterator.hasNext()) {
if (keyIterator.next().equals(key)) {
LOG.debug("Success creating key, {}", key);
isSuccess = true;
break;
}
}
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (KeyAlreadyExistsException kae) {
LOG.info("KeyAlreadyExistsException Key: {} {}", key, kae);
} catch (KeyNotFoundException knf) {
// Catching and logging KeyNotFoundException because, if
// there is a subsequent update and delete, the non-leader
// nimbodes might throw an exception.
LOG.info("KeyNotFoundException Key: {} {}", key, knf);
} catch (Exception exp) {
// Logging an exception while client is connecting
LOG.error("Exception ", exp);
}
}
if (!isSuccess) {
LOG.error("Could not download blob with key" + key);
}
return isSuccess;
}
Aggregations