Search in sources :

Example 1 with BootstrapException

use of com.kixeye.chassis.bootstrap.BootstrapException in project chassis by Kixeye.

the class UserData method parse.

public static UserData parse(String userData) {
    if (!StringUtils.isBlank(userData)) {
        StringTokenizer stringTokenizer = new StringTokenizer(userData, "\n");
        while (stringTokenizer.hasMoreTokens()) {
            String line = stringTokenizer.nextToken();
            int envStartIdx = line.indexOf(ENVIRONMENT_TEXT);
            if (envStartIdx >= 0) {
                String env = line.substring(envStartIdx + ENVIRONMENT_TEXT.length());
                return new UserData(StringUtils.trimToNull(env));
            }
        }
    }
    throw new BootstrapException("Found no environment data in user-data " + userData);
}
Also used : StringTokenizer(java.util.StringTokenizer) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException)

Example 2 with BootstrapException

use of com.kixeye.chassis.bootstrap.BootstrapException in project chassis by Kixeye.

the class CuratorFrameworkBuilder method build.

public CuratorFramework build() {
    if (this.exhibitors == null && this.zookeeperConnectionString == null) {
        throw new BootstrapException("Cannot build a CuratorFramework instance because no Zookeeper or Exhibitor connection information was provided.");
    }
    ConcurrentCompositeConfiguration configuration = buildConfiguration();
    CuratorFramework curatorFramework = null;
    if (zookeeperConnectionString != null) {
        curatorFramework = buildCuratorWithZookeeperDirectly(configuration);
    } else {
        curatorFramework = buildCuratorWithExhibitor(configuration);
    }
    if (startOnBuild) {
        try {
            curatorFramework.start();
        } catch (Exception e) {
            BootstrapException.zookeeperInitializationFailed(this.zookeeperConnectionString, this.exhibitors, e);
        }
    }
    return curatorFramework;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException)

Example 3 with BootstrapException

use of com.kixeye.chassis.bootstrap.BootstrapException in project chassis by Kixeye.

the class ZookeeperConfigurationWriter method findDeltas.

private ArrayList<Set<String>> findDeltas(Map<String, ?> configuration) {
    Set<String> keysToWrite = new TreeSet<>();
    Set<String> keysToDelete = new HashSet<>();
    List<String> existingKeys;
    try {
        existingKeys = curatorFramework.getChildren().forPath(configPath);
    } catch (Exception e) {
        throw new BootstrapException("Unable to determine existing keys for path " + configPath, e);
    }
    //figures out which existing keys to keep and which to delete
    for (String existingKey : existingKeys) {
        if (configuration.containsKey(existingKey)) {
            keysToWrite.add(existingKey);
        } else {
            keysToDelete.add(existingKey);
        }
    }
    //add any new keys
    for (String configKey : configuration.keySet()) {
        keysToWrite.add(configKey);
    }
    ArrayList<Set<String>> deltas = new ArrayList<>(2);
    deltas.add(keysToWrite);
    deltas.add(keysToDelete);
    return deltas;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) TreeSet(java.util.TreeSet) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) ArrayList(java.util.ArrayList) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) HashSet(java.util.HashSet)

Example 4 with BootstrapException

use of com.kixeye.chassis.bootstrap.BootstrapException in project chassis by Kixeye.

the class CuratorFrameworkBuilder method buildCuratorWithExhibitor.

private CuratorFramework buildCuratorWithExhibitor(Configuration configuration) {
    LOGGER.debug("configuring zookeeper connection through Exhibitor...");
    ExhibitorEnsembleProvider ensembleProvider = new KixeyeExhibitorEnsembleProvider(exhibitors, new KixeyeExhibitorRestClient(configuration.getBoolean(EXHIBITOR_USE_HTTPS.getPropertyName())), configuration.getString(EXHIBITOR_URI_PATH.getPropertyName()), configuration.getInt(EXHIBITOR_POLL_INTERVAL.getPropertyName()), new ExponentialBackoffRetry(configuration.getInt(EXHIBITOR_INITIAL_SLEEP_MILLIS.getPropertyName()), configuration.getInt(EXHIBITOR_MAX_RETRIES.getPropertyName()), configuration.getInt(EXHIBITOR_RETRIES_MAX_MILLIS.getPropertyName())));
    //ensures that the SERVER list from Exhibitor is already downloaded before curator attempts to connect to zookeeper.
    try {
        ensembleProvider.pollForInitialEnsemble();
    } catch (Exception e) {
        try {
            Closeables.close(ensembleProvider, true);
        } catch (IOException e1) {
        }
        throw new BootstrapException("Failed to initialize Exhibitor with host(s) " + exhibitors.getHostnames(), e);
    }
    CuratorFramework curator = CuratorFrameworkFactory.builder().ensembleProvider(ensembleProvider).retryPolicy(buildZookeeperRetryPolicy(configuration)).build();
    curator.getConnectionStateListenable().addListener(new ConnectionStateListener() {

        public void stateChanged(CuratorFramework client, ConnectionState newState) {
            LOGGER.debug("Connection state to ZooKeeper changed: " + newState);
        }
    });
    return curator;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) ExhibitorEnsembleProvider(org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider) IOException(java.io.IOException) ConnectionState(org.apache.curator.framework.state.ConnectionState) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException) ConnectionStateListener(org.apache.curator.framework.state.ConnectionStateListener)

Example 5 with BootstrapException

use of com.kixeye.chassis.bootstrap.BootstrapException in project chassis by Kixeye.

the class DynamicZookeeperConfigurationSource method initializePathChildrenCache.

private void initializePathChildrenCache() {
    pathChildrenCache = new PathChildrenCache(curatorFramework, configPathRoot, true);
    pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {

        @Override
        public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
            LOGGER.debug("Got event {}", event);
            if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED && event.getData().getPath().equals(instanceConfigPath)) {
                //do stuff
                LOGGER.info("Detected creation of node {}. Initializing zookeeper configuration source...", instanceConfigPath);
                try {
                    initializeZookeeperConfigurationSource();
                } catch (BootstrapException e) {
                    LOGGER.error("Failed to initialized zookeeper configuration source for path " + instanceConfigPath, e);
                    throw e;
                }
                return;
            }
            if (event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED && event.getData().getPath().equals(instanceConfigPath)) {
                if (running) {
                    LOGGER.info("Detected deletion of node {}, destroying zookeeper configuration source...", instanceConfigPath);
                    destroyZookeeperCofigurationSource();
                    return;
                }
                LOGGER.warn("Detected deletion of node {}, but zookeeper configuration source not currently running. This should not happen. Ignoring event...", instanceConfigPath);
                return;
            }
            LOGGER.debug("Ignoring event {}", event);
        }
    });
    try {
        pathChildrenCache.start(StartMode.BUILD_INITIAL_CACHE);
    } catch (Exception e) {
        throw new BootstrapException("Failed to initialize zookeeper configuration path cache" + configPathRoot, e);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException)

Aggregations

BootstrapException (com.kixeye.chassis.bootstrap.BootstrapException)8 IOException (java.io.IOException)4 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)2 ListenerDescription (com.amazonaws.services.elasticloadbalancing.model.ListenerDescription)1 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)1 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)1 WatchedUpdateListener (com.netflix.config.WatchedUpdateListener)1 ZooKeeperConfigurationSource (com.netflix.config.source.ZooKeeperConfigurationSource)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 StringTokenizer (java.util.StringTokenizer)1 TreeSet (java.util.TreeSet)1 Nullable (javax.annotation.Nullable)1 ExhibitorEnsembleProvider (org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider)1 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)1 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)1 PathChildrenCacheListener (org.apache.curator.framework.recipes.cache.PathChildrenCacheListener)1 ConnectionState (org.apache.curator.framework.state.ConnectionState)1