List of usage examples for org.apache.cassandra.gms EndpointState getApplicationState
public VersionedValue getApplicationState(ApplicationState key)
From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java
License:Apache License
public String getRack(InetAddress endpoint) { if (endpoint.equals(FBUtilities.getBroadcastAddress())) return rack; EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint); if (state == null || state.getApplicationState(ApplicationState.RACK) == null) return DEFAULT_RACK; return state.getApplicationState(ApplicationState.RACK).value; }
From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java
License:Apache License
public String getDatacenter(InetAddress endpoint) { if (endpoint.equals(FBUtilities.getBroadcastAddress())) return datacenter; EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint); if (state == null || state.getApplicationState(ApplicationState.DC) == null) return DEFAULT_DC; return state.getApplicationState(ApplicationState.DC).value; }
From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java
License:Apache License
public void onJoin(InetAddress endpoint, EndpointState epState) { if (epState.getApplicationState(ApplicationState.INTERNAL_IP) != null) reConnect(endpoint, epState.getApplicationState(ApplicationState.INTERNAL_IP)); }
From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java
License:Apache License
public void onAlive(InetAddress endpoint, EndpointState state) { if (state.getApplicationState(ApplicationState.INTERNAL_IP) != null) reConnect(endpoint, state.getApplicationState(ApplicationState.INTERNAL_IP)); }
From source file:org.elassandra.discovery.CassandraDiscovery.java
License:Apache License
public void updateNode(InetAddress addr, EndpointState state) { if (DatabaseDescriptor.getEndpointSnitch().getDatacenter(addr).equals(localDc)) { DiscoveryNodeStatus status = (state.isAlive()) ? DiscoveryNode.DiscoveryNodeStatus.ALIVE : DiscoveryNode.DiscoveryNodeStatus.DEAD; boolean updatedNode = false; String hostId = state.getApplicationState(ApplicationState.HOST_ID).value; DiscoveryNode dn = clusterGroup.get(hostId); if (dn == null) { Map<String, String> attrs = Maps.newHashMap(); attrs.put("data", "true"); attrs.put("master", "true"); attrs.put("data_center", localDc); attrs.put("rack", DatabaseDescriptor.getEndpointSnitch().getRack(addr)); InetAddress rpc_address = com.google.common.net.InetAddresses .forString(state.getApplicationState(ApplicationState.RPC_ADDRESS).value); dn = new DiscoveryNode(buildNodeName(addr), hostId.toString(), new InetSocketTransportAddress(rpc_address, publishPort()), attrs, version); dn.status(status);/*from w ww . j a va 2 s . c om*/ logger.debug( "New node soure=updateNode internal_ip={} rpc_address={}, node_name={} host_id={} status={} timestamp={}", NetworkAddress.format(addr), NetworkAddress.format(rpc_address), dn.getId(), dn.getName(), status, state.getUpdateTimestamp()); clusterGroup.members.put(dn.getId(), dn); if (state.getApplicationState(ApplicationState.X1) != null || state.getApplicationState(ApplicationState.X2) != null) { SystemKeyspace.updatePeerInfo(addr, "workload", "elasticsearch"); } updatedNode = true; } else { // may update DiscoveryNode status. if (!dn.getStatus().equals(status)) { dn.status(status); updatedNode = true; } } if (updatedNode) updateRoutingTable("update-node-" + NetworkAddress.format(addr)); } }
From source file:org.elassandra.discovery.CassandraDiscovery.java
License:Apache License
/** * Release listeners who have reached the expected metadat version. *///www. j av a 2 s.com public void checkMetaDataVersion() { for (Iterator<MetaDataVersionListener> it = this.metaDataVersionListeners.iterator(); it.hasNext();) { MetaDataVersionListener listener = it.next(); boolean versionReached = true; for (InetAddress addr : Gossiper.instance.getLiveTokenOwners()) { if (DatabaseDescriptor.getEndpointSnitch().getDatacenter(addr).equals(localDc)) { EndpointState endPointState = Gossiper.instance.getEndpointStateForEndpoint(addr); VersionedValue vv = endPointState.getApplicationState(ELASTIC_META_DATA); if (vv != null && vv.value.lastIndexOf('/') > 0) { Long version = Long.valueOf(vv.value.substring(vv.value.lastIndexOf('/') + 1)); if (version < listener.version()) { versionReached = false; break; } } } } if (versionReached) { logger.debug("MetaData.version = {} reached", listener.version()); listener.release(); metaDataVersionListeners.remove(listener); } } }
From source file:org.elassandra.discovery.CassandraDiscovery.java
License:Apache License
@Override public Map<UUID, ShardRoutingState> getShardRoutingStates(String index) { Map<UUID, ShardRoutingState> shardsStates = new HashMap<UUID, ShardRoutingState>( this.clusterGroup.members.size()); for (Entry<InetAddress, EndpointState> entry : Gossiper.instance.getEndpointStates()) { InetAddress endpoint = entry.getKey(); EndpointState state = entry.getValue(); if (!endpoint.equals(this.localAddress) && DatabaseDescriptor.getEndpointSnitch().getDatacenter(endpoint).equals(this.localDc) && state != null && state.isAlive()) { VersionedValue value = state.getApplicationState(ELASTIC_SHARDS_STATES); if (value != null) { try { Map<String, ShardRoutingState> shardsStateMap = jsonMapper.readValue(value.value, indexShardStateTypeReference); ShardRoutingState shardState = shardsStateMap.get(index); if (shardState != null) { shardsStates.put(Gossiper.instance.getHostId(endpoint), shardState); }//from w w w .j ava 2 s . c o m } catch (Exception e) { logger.warn("Failed to parse gossip index shard state", e); } } } } return shardsStates; }
From source file:org.elassandra.discovery.CassandraDiscovery.java
License:Apache License
/** * add local index shard state to local application state. * @param index/*w ww.ja v a2 s.c om*/ * @param shardRoutingState * @throws JsonGenerationException * @throws JsonMappingException * @throws IOException */ @Override public synchronized void putShardRoutingState(final String index, final ShardRoutingState shardRoutingState) throws JsonGenerationException, JsonMappingException, IOException { if (Gossiper.instance.isEnabled()) { Map<String, ShardRoutingState> shardsStateMap = null; EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(FBUtilities.getBroadcastAddress()); if (state != null) { VersionedValue value = state.getApplicationState(ELASTIC_SHARDS_STATES); if (value != null) { shardsStateMap = (Map<String, ShardRoutingState>) jsonMapper.readValue(value.value, indexShardStateTypeReference); } } if (shardsStateMap == null) { shardsStateMap = new HashMap<String, ShardRoutingState>(); } if (shardRoutingState != null) { shardsStateMap.put(index, shardRoutingState); } else { if (shardsStateMap.containsKey(index)) { shardsStateMap.remove(index); } } String newValue = jsonMapper.writerWithType(indexShardStateTypeReference) .writeValueAsString(shardsStateMap); Gossiper.instance.addLocalApplicationState(ELASTIC_SHARDS_STATES, StorageService.instance.valueFactory.datacenter(newValue)); } else { logger.warn("Cannot put X1 for index={}, gossip not enabled", index); } }
From source file:org.elasticsearch.cassandra.discovery.CassandraDiscovery.java
License:Apache License
public void updateNode(InetAddress addr, EndpointState state) { DiscoveryNodeStatus status = (state.isAlive()) ? DiscoveryNode.DiscoveryNodeStatus.ALIVE : DiscoveryNode.DiscoveryNodeStatus.DEAD; boolean updatedNode = false; if (DatabaseDescriptor.getEndpointSnitch().getDatacenter(addr).equals(localDc)) { String hostId = state.getApplicationState(ApplicationState.HOST_ID).value; DiscoveryNode dn = clusterGroup.get(hostId); if (dn == null) { Map<String, String> attrs = Maps.newHashMap(); attrs.put("data", "true"); attrs.put("master", "true"); attrs.put("data_center", localDc); attrs.put("rack", DatabaseDescriptor.getEndpointSnitch().getRack(addr)); dn = new DiscoveryNode(buildNodeName(addr), hostId.toString(), new InetSocketTransportAddress(addr, settings.getAsInt("transport.tcp.port", 9300)), attrs, version);/*w ww .java 2 s .c om*/ dn.status(status); logger.debug("New node soure=updateNode addr_ip={} node_name={} host_id={} status={} timestamp={}", addr.getHostAddress(), dn.getId(), dn.getName(), status, state.getUpdateTimestamp()); clusterGroup.members.put(dn.getId(), dn); updatedNode = true; } else { // may update DiscoveryNode status. if (!dn.getStatus().equals(status)) { dn.status(status); updatedNode = true; } } } if (updatedNode) updateClusterState("update-node-" + addr.getHostAddress(), null); }
From source file:org.elasticsearch.cassandra.discovery.CassandraDiscovery.java
License:Apache License
public void checkMetaDataVersion() { for (Iterator<MetaDataVersionListener> it = this.metaDataVersionListeners.iterator(); it.hasNext();) { MetaDataVersionListener listener = it.next(); boolean versionReached = true; for (InetAddress addr : Gossiper.instance.getLiveTokenOwners()) { if (DatabaseDescriptor.getEndpointSnitch().getDatacenter(addr).equals(localDc)) { EndpointState endPointState = Gossiper.instance.getEndpointStateForEndpoint(addr); VersionedValue vv = endPointState.getApplicationState(ELASTIC_META_DATA); if (vv != null && vv.value.lastIndexOf('/') > 0) { Long version = Long.valueOf(vv.value.substring(vv.value.lastIndexOf('/') + 1)); if (version < listener.version()) { versionReached = false; break; }/*from w w w . j a va2 s .co m*/ } } } if (versionReached) { logger.debug("MetaData.version = {} reached", listener.version()); listener.release(); metaDataVersionListeners.remove(listener); } } }