Skip to content

Add initial implementaion of zookeeper-based discovery service. #1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .idea/libraries/zookeeper.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules/elasticsearch-root.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions .idea/modules/plugin-zookeeper.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 131 additions & 0 deletions plugins/zookeeper/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
dependsOn(':elasticsearch')

apply plugin: 'java'
apply plugin: 'maven'

archivesBaseName = "elasticsearch-zookeeper"

explodedDistDir = new File(distsDir, 'exploded')

configurations.compile.transitive = true
configurations.testCompile.transitive = true

// no need to use the resource dir
sourceSets.main.resources.srcDirs 'src/main/java'
sourceSets.test.resources.srcDirs 'src/test/java'

// add the source files to the dist jar
//jar {
// from sourceSets.main.allJava
//}

configurations {
dists
distLib {
visible = false
}
}

dependencies {
compile project(':elasticsearch')
compile("org.apache.zookeeper:zookeeper:3.3.3") { transitive = false }

distLib("org.apache.zookeeper:zookeeper:3.3.3") { transitive = false }
}

task explodedDist(dependsOn: [jar], description: 'Builds the plugin zip file') << {
[explodedDistDir]*.mkdirs()

copy {
from configurations.distLib
into explodedDistDir
}

// remove elasticsearch files (compile above adds the elasticsearch one)
ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*.jar") }

copy {
from libsDir
into explodedDistDir
}

ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-javadoc.jar") }
ant.delete { fileset(dir: explodedDistDir, includes: "elasticsearch-*-sources.jar") }
}

task zip(type: Zip, dependsOn: ['explodedDist']) {
from(explodedDistDir) {
}
}

task release(dependsOn: [zip]) << {
ant.delete(dir: explodedDistDir)
copy {
from distsDir
into(new File(rootProject.distsDir, "plugins"))
}
}

configurations {
deployerJars
}

dependencies {
deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2"
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

jar {
// from sourceSets.main.allJava
manifest {
attributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr)
}
}

artifacts {
archives sourcesJar
archives javadocJar
}

uploadArchives {
repositories.mavenDeployer {
configuration = configurations.deployerJars
repository(url: rootProject.mavenRepoUrl) {
authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass)
}
snapshotRepository(url: rootProject.mavenSnapshotRepoUrl) {
authentication(userName: rootProject.mavenRepoUser, password: rootProject.mavenRepoPass)
}

pom.project {
inceptionYear '2011'
name 'elasticsearch-plugins-zookeeper'
description 'ZooKeeper Plugin for ElasticSearch'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection 'git://github.com/elasticsearch/elasticsearch.git'
developerConnection 'git@github.com:elasticsearch/elasticsearch.git'
url 'http://github.com/elasticsearch/elasticsearch'
}
}

pom.whenConfigured {pom ->
pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones
}
}
}
1 change: 1 addition & 0 deletions plugins/zookeeper/src/main/java/es-plugin.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
plugin=org.elasticsearch.plugin.zookeeper.ZooKeeperPlugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.common.settings.zookeeper;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.loader.SettingsLoader;
import org.elasticsearch.common.settings.loader.SettingsLoaderFactory;
import org.elasticsearch.zookeeper.ZooKeeperEnvironment;
import org.elasticsearch.zookeeper.ZooKeeperFactory;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
* @author imotov
*/
public final class ZooKeeperSettingsLoader {

private ZooKeeperSettingsLoader() {

}

public static Settings loadZooKeeperSettings(Settings settings) {
ZooKeeperFactory zooKeeperFactory = new ZooKeeperFactory(settings);

ClusterName clusterName = ClusterName.clusterNameFromSettings(settings);

ZooKeeperEnvironment zooKeeperEnvironment = new ZooKeeperEnvironment(settings, clusterName);

ZooKeeper zooKeeper = zooKeeperFactory.newZooKeeper();
try {
return ImmutableSettings.settingsBuilder()
.put(loadSettings(zooKeeper, zooKeeperEnvironment.globalSettingsNodePath()))
.put(loadSettings(zooKeeper, zooKeeperEnvironment.clusterSettingsNodePath()))
.build();
} catch (InterruptedException e) {
// Ignore
} catch (KeeperException e) {
throw new ElasticSearchException("Cannot load settings ", e);
} finally {
try {
zooKeeper.close();
} catch (InterruptedException ex) {
// Ignore
}
}
return ImmutableSettings.Builder.EMPTY_SETTINGS;
}

private static Map<String, String> loadSettings(ZooKeeper zooKeeper, String path) throws InterruptedException, KeeperException {
try {
byte[] settingsBytes = zooKeeper.getData(path, null, null);
SettingsLoader loader = SettingsLoaderFactory.loaderFromSource(new String(settingsBytes));
return loader.load(settingsBytes);
} catch (KeeperException.NoNodeException e) {
return Collections.emptyMap();
} catch (IOException ex) {
throw new ElasticSearchException("Cannot load settings ", ex);
}
}
}
Loading