Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate CloudstackSnitch and remove duplicate code in snitches
The patch also refactors existing cloud snitches to get rid of the duplicate code, this is the logical follow-up of CASSANDRA-16555 where AbstractCloudMetadataServiceConnector was introduced. patch by Stefan Miklosovic; reviewed by Jacek Lewandowski, Jackson Fleming and Maxwell Guo for CASSANDRA-18438
- Loading branch information
1 parent
6f486f5
commit 903857b
Showing
19 changed files
with
564 additions
and
441 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
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
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
108 changes: 108 additions & 0 deletions
108
src/java/org/apache/cassandra/locator/AbstractCloudMetadataServiceSnitch.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,108 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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.apache.cassandra.locator; | ||
|
||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.cassandra.db.SystemKeyspace; | ||
import org.apache.cassandra.gms.ApplicationState; | ||
import org.apache.cassandra.gms.EndpointState; | ||
import org.apache.cassandra.gms.Gossiper; | ||
import org.apache.cassandra.utils.FBUtilities; | ||
import org.apache.cassandra.utils.Pair; | ||
|
||
import static java.lang.String.format; | ||
|
||
abstract class AbstractCloudMetadataServiceSnitch extends AbstractNetworkTopologySnitch | ||
{ | ||
static final Logger logger = LoggerFactory.getLogger(AbstractCloudMetadataServiceSnitch.class); | ||
|
||
static final String DEFAULT_DC = "UNKNOWN-DC"; | ||
static final String DEFAULT_RACK = "UNKNOWN-RACK"; | ||
|
||
protected final AbstractCloudMetadataServiceConnector connector; | ||
protected final SnitchProperties snitchProperties; | ||
|
||
private final String localRack; | ||
private final String localDc; | ||
|
||
private Map<InetAddressAndPort, Map<String, String>> savedEndpoints; | ||
|
||
public AbstractCloudMetadataServiceSnitch(AbstractCloudMetadataServiceConnector connector, | ||
SnitchProperties snitchProperties, | ||
Pair<String, String> dcAndRack) | ||
{ | ||
this.connector = connector; | ||
this.snitchProperties = snitchProperties; | ||
this.localDc = dcAndRack.left; | ||
this.localRack = dcAndRack.right; | ||
|
||
logger.info(format("%s using datacenter: %s, rack: %s, connector: %s, properties: %s", | ||
getClass().getName(), getLocalDatacenter(), getLocalRack(), connector, snitchProperties)); | ||
} | ||
|
||
@Override | ||
public final String getLocalRack() | ||
{ | ||
return localRack; | ||
} | ||
|
||
@Override | ||
public final String getLocalDatacenter() | ||
{ | ||
return localDc; | ||
} | ||
|
||
@Override | ||
public final String getRack(InetAddressAndPort endpoint) | ||
{ | ||
if (endpoint.equals(FBUtilities.getBroadcastAddressAndPort())) | ||
return getLocalRack(); | ||
EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint); | ||
if (state == null || state.getApplicationState(ApplicationState.RACK) == null) | ||
{ | ||
if (savedEndpoints == null) | ||
savedEndpoints = SystemKeyspace.loadDcRackInfo(); | ||
if (savedEndpoints.containsKey(endpoint)) | ||
return savedEndpoints.get(endpoint).get("rack"); | ||
return DEFAULT_RACK; | ||
} | ||
return state.getApplicationState(ApplicationState.RACK).value; | ||
} | ||
|
||
@Override | ||
public final String getDatacenter(InetAddressAndPort endpoint) | ||
{ | ||
if (endpoint.equals(FBUtilities.getBroadcastAddressAndPort())) | ||
return getLocalDatacenter(); | ||
EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint); | ||
if (state == null || state.getApplicationState(ApplicationState.DC) == null) | ||
{ | ||
if (savedEndpoints == null) | ||
savedEndpoints = SystemKeyspace.loadDcRackInfo(); | ||
if (savedEndpoints.containsKey(endpoint)) | ||
return savedEndpoints.get(endpoint).get("data_center"); | ||
return DEFAULT_DC; | ||
} | ||
return state.getApplicationState(ApplicationState.DC).value; | ||
} | ||
} |
Oops, something went wrong.