Search in sources :

Example 1 with ClusterStateContext

use of org.apache.storm.cluster.ClusterStateContext in project storm by apache.

the class StormClusterStateImplTest method init.

@Before
public void init() throws Exception {
    storage = Mockito.mock(IStateStorage.class);
    context = new ClusterStateContext();
    state = new StormClusterStateImpl(storage, null, /*acls*/
    context, false);
}
Also used : ClusterStateContext(org.apache.storm.cluster.ClusterStateContext) Before(org.junit.Before)

Example 2 with ClusterStateContext

use of org.apache.storm.cluster.ClusterStateContext in project storm by apache.

the class AdminCommands method initialize.

private static void initialize() {
    conf = ConfigUtils.readStormConfig();
    nimbusBlobStore = Utils.getNimbusBlobStore(conf, NimbusInfo.fromConf(conf));
    List<String> servers = (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS);
    Object port = conf.get(Config.STORM_ZOOKEEPER_PORT);
    List<ACL> acls = null;
    if (Utils.isZkAuthenticationConfiguredStormServer(conf)) {
        acls = adminZkAcls();
    }
    try {
        stormClusterState = ClusterUtils.mkStormClusterState(conf, acls, new ClusterStateContext(DaemonType.NIMBUS));
    } catch (Exception e) {
        LOG.error("admin can't create stormClusterState");
        new RuntimeException(e);
    }
    CuratorFramework zk = Zookeeper.mkClient(conf, servers, port, "", new DefaultWatcherCallBack(), conf);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) DefaultWatcherCallBack(org.apache.storm.callback.DefaultWatcherCallBack) ACL(org.apache.zookeeper.data.ACL) ClusterStateContext(org.apache.storm.cluster.ClusterStateContext)

Example 3 with ClusterStateContext

use of org.apache.storm.cluster.ClusterStateContext in project storm by apache.

the class Heartbeats method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        throw new IllegalArgumentException("Command and path arguments must be provided.");
    }
    String command = args[0];
    String path = args[1];
    Map<String, Object> conf = Utils.readStormConfig();
    IStateStorage cluster = ClusterUtils.mkStateStorage(conf, conf, new ClusterStateContext());
    LOG.info("Command: [{}]", command);
    switch(command) {
        case "list":
            handleListCommand(cluster, path);
            break;
        case "get":
            handleGetCommand(cluster, path);
            break;
        default:
            LOG.info("Usage: heartbeats [list|get] path");
    }
    try {
        cluster.close();
    } catch (Exception e) {
        LOG.info("Caught exception: {} on close.", e);
    }
    // force process to be terminated
    System.exit(0);
}
Also used : IStateStorage(org.apache.storm.cluster.IStateStorage) ClusterStateContext(org.apache.storm.cluster.ClusterStateContext)

Example 4 with ClusterStateContext

use of org.apache.storm.cluster.ClusterStateContext in project storm by apache.

the class Worker method start.

public void start() throws Exception {
    LOG.info("Launching worker for {} on {}:{} with id {} and conf {}", topologyId, assignmentId, port, workerId, ConfigUtils.maskPasswords(conf));
    // if ConfigUtils.isLocalMode(conf) returns false then it is in distributed mode.
    if (!ConfigUtils.isLocalMode(conf)) {
        // Distributed mode
        SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
        String pid = Utils.processPid();
        FileUtils.touch(new File(ConfigUtils.workerPidPath(conf, workerId, pid)));
        FileUtils.writeStringToFile(new File(ConfigUtils.workerArtifactsPidPath(conf, topologyId, port)), pid, Charset.forName("UTF-8"));
    }
    ClusterStateContext csContext = new ClusterStateContext(DaemonType.WORKER, topologyConf);
    IStateStorage stateStorage = ClusterUtils.mkStateStorage(conf, topologyConf, csContext);
    IStormClusterState stormClusterState = ClusterUtils.mkStormClusterState(stateStorage, null, csContext);
    metricRegistry.start(topologyConf, port);
    SharedMetricRegistries.add(WORKER_METRICS_REGISTRY, metricRegistry.getRegistry());
    Credentials initialCredentials = stormClusterState.credentials(topologyId, null);
    Map<String, String> initCreds = new HashMap<>();
    if (initialCredentials != null) {
        initCreds.putAll(initialCredentials.get_creds());
    }
    autoCreds = ClientAuthUtils.getAutoCredentials(topologyConf);
    subject = ClientAuthUtils.populateSubject(null, autoCreds, initCreds);
    Subject.doAs(subject, (PrivilegedExceptionAction<Object>) () -> loadWorker(stateStorage, stormClusterState, initCreds, initialCredentials));
}
Also used : HashMap(java.util.HashMap) IStormClusterState(org.apache.storm.cluster.IStormClusterState) File(java.io.File) Credentials(org.apache.storm.generated.Credentials) IAutoCredentials(org.apache.storm.security.auth.IAutoCredentials) ClusterStateContext(org.apache.storm.cluster.ClusterStateContext) IStateStorage(org.apache.storm.cluster.IStateStorage)

Example 5 with ClusterStateContext

use of org.apache.storm.cluster.ClusterStateContext in project storm by apache.

the class LocalFsBlobStore method prepare.

@Override
public void prepare(Map<String, Object> conf, String overrideBase, NimbusInfo nimbusInfo, ILeaderElector leaderElector) {
    this.conf = conf;
    this.nimbusInfo = nimbusInfo;
    zkClient = BlobStoreUtils.createZKClient(conf, DaemonType.NIMBUS);
    if (overrideBase == null) {
        overrideBase = ConfigUtils.absoluteStormBlobStoreDir(conf);
    }
    File baseDir = new File(overrideBase, BASE_BLOBS_DIR_NAME);
    try {
        fbs = new FileBlobStoreImpl(baseDir, conf);
    } catch (IOException e) {
        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("BLOB-STORE-TIMER", true);
    this.leaderElector = leaderElector;
}
Also used : Timer(java.util.Timer) IOException(java.io.IOException) File(java.io.File) NoSuchFileException(java.nio.file.NoSuchFileException) WrappedKeyNotFoundException(org.apache.storm.utils.WrappedKeyNotFoundException) KeeperException(org.apache.storm.shade.org.apache.zookeeper.KeeperException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AuthorizationException(org.apache.storm.generated.AuthorizationException) WrappedKeyAlreadyExistsException(org.apache.storm.utils.WrappedKeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) ClusterStateContext(org.apache.storm.cluster.ClusterStateContext)

Aggregations

ClusterStateContext (org.apache.storm.cluster.ClusterStateContext)6 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 IStateStorage (org.apache.storm.cluster.IStateStorage)2 IStormClusterState (org.apache.storm.cluster.IStormClusterState)2 FileNotFoundException (java.io.FileNotFoundException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Map (java.util.Map)1 Timer (java.util.Timer)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Subject (javax.security.auth.Subject)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 DefaultWatcherCallBack (org.apache.storm.callback.DefaultWatcherCallBack)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1 Credentials (org.apache.storm.generated.Credentials)1 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)1 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)1 Nimbus (org.apache.storm.generated.Nimbus)1