Search in sources :

Example 1 with KeyNotFoundException

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
            }
        }
    }
}
Also used : KeyNotFoundException(backtype.storm.generated.KeyNotFoundException)

Example 2 with KeyNotFoundException

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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TTransportException(org.apache.thrift.transport.TTransportException) NimbusClient(backtype.storm.utils.NimbusClient) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) IOException(java.io.IOException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException) NimbusInfo(backtype.storm.nimbus.NimbusInfo)

Example 3 with KeyNotFoundException

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);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap) TimeCacheMap(com.alibaba.jstorm.utils.TimeCacheMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) File(java.io.File) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException)

Example 4 with KeyNotFoundException

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;
}
Also used : NimbusClient(backtype.storm.utils.NimbusClient) IOException(java.io.IOException) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) IOException(java.io.IOException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException) NimbusInfo(backtype.storm.nimbus.NimbusInfo)

Example 5 with KeyNotFoundException

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;
}
Also used : ReadableBlobMeta(backtype.storm.generated.ReadableBlobMeta) NimbusClient(backtype.storm.utils.NimbusClient) IOException(java.io.IOException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) IOException(java.io.IOException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException) NimbusInfo(backtype.storm.nimbus.NimbusInfo) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException)

Aggregations

KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)5 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)3 NimbusInfo (backtype.storm.nimbus.NimbusInfo)3 NimbusClient (backtype.storm.utils.NimbusClient)3 IOException (java.io.IOException)3 TException (org.apache.thrift.TException)3 TTransportException (org.apache.thrift.transport.TTransportException)3 ReadableBlobMeta (backtype.storm.generated.ReadableBlobMeta)1 TimeCacheMap (com.alibaba.jstorm.utils.TimeCacheMap)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1