-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring Gradle project structure; introducing raigad-discovery-pl…
…ugin Zip artifact
- Loading branch information
Showing
17 changed files
with
721 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri May 01 12:00:47 PDT 2015 | ||
#Thu Jun 09 18:03:08 UTC 2016 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip | ||
distributionUrl=http\://artifacts.netflix.com/gradle-netflix-local/netflix/nebula-gradle/3.10.1/nebula-gradle-3.10.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apply plugin: 'osgi' | ||
apply plugin: 'project-report' | ||
apply plugin: 'java' | ||
|
||
task createZip(type: Zip) { | ||
from 'src/main/resources/plugin-metadata' | ||
from jar.archivePath | ||
} | ||
|
||
publishing { | ||
publications { | ||
nebulaIvy(IvyPublication) { | ||
artifact createZip | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
raigad-discovery-plugin/src/main/java/com/netflix/raigad/discovery/RaigadDiscovery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2016 Netflix, Inc. | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 com.netflix.raigad.discovery; | ||
|
||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.discovery.DiscoverySettings; | ||
import org.elasticsearch.discovery.zen.ZenDiscovery; | ||
import org.elasticsearch.discovery.zen.elect.ElectMasterService; | ||
import org.elasticsearch.discovery.zen.ping.ZenPingService; | ||
import org.elasticsearch.node.settings.NodeSettingsService; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
public class RaigadDiscovery extends ZenDiscovery { | ||
public static final String DISCOVERY_TYPE = "raigad"; | ||
public static final String DISCOVERY_TYPE_LOCATION = "discovery.type"; | ||
public static final String DISCOVERY_DESCRIPTION = "Raigad custom discovery plugin"; | ||
|
||
public static final String GET_NODES_ISLAND_URL = "http://127.0.0.1:8080/Raigad/REST/v1/esconfig/get_nodes"; | ||
public static final String GET_NODES_TRIBE_URL_PREFIX = "http://127.0.0.1:8080/Raigad/REST/v1/esconfig/get_tribe_nodes/"; | ||
|
||
@Inject | ||
public RaigadDiscovery(Settings settings, | ||
ClusterName clusterName, | ||
ThreadPool threadPool, | ||
TransportService transportService, | ||
ClusterService clusterService, | ||
NodeSettingsService nodeSettingsService, | ||
ZenPingService pingService, | ||
ElectMasterService electMasterService, | ||
DiscoverySettings discoverySettings) { | ||
super(settings, clusterName, threadPool, transportService, clusterService, | ||
nodeSettingsService, pingService, electMasterService, discoverySettings); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...lugin/src/main/java/com/netflix/raigad/discovery/RaigadDiscoveryUnicastHostsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* Copyright 2016 Netflix, Inc. | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 com.netflix.raigad.discovery; | ||
|
||
import com.netflix.raigad.discovery.utils.DataFetcher; | ||
import com.netflix.raigad.discovery.utils.ElasticsearchUtil; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.common.component.AbstractComponent; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.transport.TransportAddress; | ||
import org.elasticsearch.discovery.zen.ping.unicast.UnicastHostsProvider; | ||
import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class RaigadDiscoveryUnicastHostsProvider extends AbstractComponent implements UnicastHostsProvider { | ||
private final TransportService transportService; | ||
private final Version version; | ||
private final Settings settings; | ||
|
||
@Inject | ||
public RaigadDiscoveryUnicastHostsProvider(Settings settings, TransportService transportService, Version version) { | ||
super(settings); | ||
|
||
this.transportService = transportService; | ||
this.version = version; | ||
this.settings = settings; | ||
} | ||
|
||
@Override | ||
public List<DiscoveryNode> buildDynamicNodes() { | ||
List<DiscoveryNode> discoveryNodes = new ArrayList<>(); | ||
|
||
try { | ||
//Extract tribe ID from name field of settings and query accordingly | ||
String strNodes; | ||
|
||
if (isCurrentNodeTribe(settings)) { | ||
String nodeName = settings.get("name"); | ||
//TODO: Check for null node name | ||
String tribeId = nodeName.substring(nodeName.indexOf("/") + 1); | ||
logger.debug("Tribe node name: {}, tribe ID: {}", nodeName, tribeId); | ||
strNodes = DataFetcher.fetchData(RaigadDiscovery.GET_NODES_TRIBE_URL_PREFIX + tribeId, logger); | ||
} | ||
else { | ||
strNodes = DataFetcher.fetchData(RaigadDiscovery.GET_NODES_ISLAND_URL, logger); | ||
} | ||
|
||
List<RaigadInstance> instances = ElasticsearchUtil.getRaigadInstancesFromJsonString(strNodes, logger); | ||
for (RaigadInstance instance : instances) { | ||
try { | ||
TransportAddress[] addresses = | ||
transportService.addressesFromString(instance.getHostIP(), UnicastZenPing.LIMIT_FOREIGN_PORTS_COUNT); | ||
|
||
// We only limit to 1 port, makes no sense to ping 100 ports | ||
for (int i = 0; (i < addresses.length && i < UnicastZenPing.LIMIT_FOREIGN_PORTS_COUNT); i ++) { | ||
logger.info("Adding instance [{}] (address {}, transport address {})", | ||
instance.getId(), instance.getHostIP(), addresses[i]); | ||
discoveryNodes.add(new DiscoveryNode(instance.getId(), addresses[i], version.minimumCompatibilityVersion())); | ||
} | ||
} | ||
catch (Exception e) { | ||
logger.warn("Failed to add instance {} (address {})", e, instance.getId(), instance.getHostIP()); | ||
} | ||
} | ||
} | ||
catch (Exception e) { | ||
logger.error("Exception while trying to build dynamic discovery nodes", e); | ||
throw new RuntimeException(e); | ||
} | ||
|
||
logger.info("Using the following dynamic discovery nodes: {}", discoveryNodes); | ||
return discoveryNodes; | ||
} | ||
|
||
private boolean isCurrentNodeTribe(Settings settings) { | ||
if (settings == null) { | ||
return false; | ||
} | ||
|
||
String tribeName = settings.get("name"); | ||
if (tribeName == null || tribeName.isEmpty()) { | ||
return false; | ||
} | ||
|
||
return tribeName.contains("/t"); | ||
} | ||
} |
Oops, something went wrong.