use of com.alibaba.jstorm.blobstore.LocalFsBlobStore in project jstorm by alibaba.
the class ServiceHandler method createStateInZookeeper.
@Override
public void createStateInZookeeper(String key) throws TException {
BlobStore blobStore = data.getBlobStore();
NimbusInfo nimbusInfo = data.getNimbusHostPortInfo();
if (blobStore instanceof LocalFsBlobStore) {
int versionForKey = BlobStoreUtils.getVersionForKey(key, nimbusInfo, data.getConf());
try {
data.getStormClusterState().setup_blobstore(key, nimbusInfo, versionForKey);
} catch (Exception e) {
throw new TException("create state in zookeeper error", e);
}
}
LOG.debug("Created state in zookeeper for key:{} for nimbus:{}", key, nimbusInfo);
}
use of com.alibaba.jstorm.blobstore.LocalFsBlobStore in project jstorm by alibaba.
the class ServiceHandler method setupStormCode.
/**
* create local topology files in blobstore and sync metadata to zk
*/
private void setupStormCode(Map<Object, Object> conf, String topologyId, String tmpJarLocation, Map<Object, Object> stormConf, StormTopology topology) throws Exception {
StormClusterState clusterState = data.getStormClusterState();
BlobStore blobStore = data.getBlobStore();
NimbusInfo nimbusInfo = data.getNimbusHostPortInfo();
String codeKey = StormConfig.master_stormcode_key(topologyId);
String confKey = StormConfig.master_stormconf_key(topologyId);
// in local mode there is no jar
if (tmpJarLocation != null) {
setupJar(tmpJarLocation, topologyId, blobStore, clusterState, nimbusInfo, false);
}
blobStore.createBlob(confKey, Utils.serialize(stormConf), new SettableBlobMeta());
blobStore.createBlob(codeKey, Utils.serialize(topology), new SettableBlobMeta());
if (blobStore instanceof LocalFsBlobStore) {
clusterState.setup_blobstore(confKey, nimbusInfo, BlobStoreUtils.getVersionForKey(confKey, nimbusInfo, conf));
clusterState.setup_blobstore(codeKey, nimbusInfo, BlobStoreUtils.getVersionForKey(codeKey, nimbusInfo, conf));
}
LOG.info("Successfully create blobstore for topology {}", topologyId);
}
use of com.alibaba.jstorm.blobstore.LocalFsBlobStore in project jstorm by alibaba.
the class ServiceHandler method updateTopology.
@Override
public void updateTopology(String name, String uploadedLocation, String updateConf) throws NotAliveException, InvalidTopologyException, TException {
try {
//firstly update jar and conf
checkTopologyActive(data, name, true);
String topologyId = null;
StormClusterState stormClusterState = data.getStormClusterState();
topologyId = Cluster.get_topology_id(stormClusterState, name);
if (topologyId == null) {
throw new NotAliveException(name);
}
BlobStore blobStore = data.getBlobStore();
StormClusterState clusterState = data.getStormClusterState();
NimbusInfo nimbusInfo = data.getNimbusHostPortInfo();
if (uploadedLocation != null) {
setupJar(uploadedLocation, topologyId, blobStore, clusterState, nimbusInfo, true);
}
Map topoConf = StormConfig.read_nimbus_topology_conf(topologyId, data.getBlobStore());
Map<Object, Object> config = (Map<Object, Object>) JStormUtils.from_json(updateConf);
topoConf.putAll(config);
String confKey = StormConfig.master_stormconf_key(topologyId);
BlobStoreUtils.updateBlob(blobStore, confKey, Utils.serialize(topoConf));
if (blobStore instanceof LocalFsBlobStore) {
clusterState.setup_blobstore(confKey, nimbusInfo, BlobStoreUtils.getVersionForKey(confKey, nimbusInfo, conf));
}
NimbusUtils.transitionName(data, name, true, StatusType.update_topology, config);
LOG.info("update topology " + name + " successfully");
notifyTopologyActionListener(name, "updateTopology");
} catch (NotAliveException e) {
String errMsg = "Error, no this topology " + name;
LOG.error(errMsg, e);
throw new NotAliveException(errMsg);
} catch (Exception e) {
String errMsg = "Failed to update topology " + name;
LOG.error(errMsg, e);
throw new TException(errMsg);
}
}
use of com.alibaba.jstorm.blobstore.LocalFsBlobStore in project jstorm by alibaba.
the class ServiceHandler method setupJar.
public void setupJar(String tmpJarLocation, String topologyId, BlobStore blobStore, StormClusterState clusterState, NimbusInfo nimbusInfo, boolean update) throws Exception {
// setup lib files
boolean existLibs = true;
String srcLibPath = StormConfig.stormlib_path(tmpJarLocation);
File srcFile = new File(srcLibPath);
if (srcFile.exists()) {
File[] libJars = srcFile.listFiles();
if (libJars != null) {
for (File jar : libJars) {
if (jar.isFile()) {
String libJarKey = StormConfig.master_stormlib_key(topologyId, jar.getName());
if (update) {
BlobStoreUtils.updateBlob(blobStore, libJarKey, new FileInputStream(jar));
} else {
blobStore.createBlob(libJarKey, new FileInputStream(jar), new SettableBlobMeta());
}
if (blobStore instanceof LocalFsBlobStore) {
clusterState.setup_blobstore(libJarKey, nimbusInfo, BlobStoreUtils.getVersionForKey(libJarKey, nimbusInfo, conf));
}
}
}
}
} else {
LOG.info("No lib jars " + srcLibPath);
existLibs = false;
}
// find storm jar path
String jarPath = null;
List<String> files = PathUtils.read_dir_contents(tmpJarLocation);
for (String file : files) {
if (file.endsWith(".jar")) {
jarPath = tmpJarLocation + PathUtils.SEPERATOR + file;
break;
}
}
if (jarPath == null) {
if (!existLibs) {
throw new IllegalArgumentException("No jar under " + tmpJarLocation);
} else {
LOG.info("No submit jar");
return;
}
}
// setup storm jar
String jarKey = StormConfig.master_stormjar_key(topologyId);
if (update) {
BlobStoreUtils.updateBlob(blobStore, jarKey, new FileInputStream(jarPath));
} else {
blobStore.createBlob(jarKey, new FileInputStream(jarPath), new SettableBlobMeta());
}
if (blobStore instanceof LocalFsBlobStore) {
int versionInfo = BlobStoreUtils.getVersionForKey(jarKey, nimbusInfo, conf);
clusterState.setup_blobstore(jarKey, nimbusInfo, versionInfo);
}
PathUtils.rmr(tmpJarLocation);
}
use of com.alibaba.jstorm.blobstore.LocalFsBlobStore in project jstorm by alibaba.
the class StormConfig method write_nimbus_topology_code.
public static void write_nimbus_topology_code(String topologyId, byte[] data, NimbusData nimbusData) throws Exception {
String codeKey = master_stormcode_key(topologyId);
AtomicOutputStream out = nimbusData.getBlobStore().updateBlob(codeKey);
out.write(data);
out.close();
if (nimbusData.getBlobStore() instanceof LocalFsBlobStore) {
NimbusInfo nimbusInfo = nimbusData.getNimbusHostPortInfo();
int versionForKey = BlobStoreUtils.getVersionForKey(codeKey, nimbusInfo, nimbusData.getConf());
nimbusData.getStormClusterState().setup_blobstore(codeKey, nimbusInfo, versionForKey);
}
}
Aggregations