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);
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations