-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address translator support and configuration related documentation (#12)
* support for record to table mapping config * some minor bug fixes * error handling and ssl config support * some typo mistake fix * support for address translator * documentation changes for new configs * resolved review comments * renamed ComposeAddressTranslator to ClusterAddressTranslator * addressed review comments
- Loading branch information
1 parent
e177741
commit aa89618
Showing
6 changed files
with
295 additions
and
72 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
93 changes: 93 additions & 0 deletions
93
src/main/java/io/connect/scylladb/ClusterAddressTranslator.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,93 @@ | ||
// Copyright (c) 2016 Compose, an IBM company | ||
// | ||
// MIT License | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
package io.connect.scylladb; | ||
|
||
import com.datastax.driver.core.Cluster; | ||
import com.datastax.driver.core.policies.AddressTranslator; | ||
import java.net.InetSocketAddress; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import org.json.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
class ClusterAddressTranslator implements AddressTranslator { | ||
|
||
public Map<InetSocketAddress, InetSocketAddress> addressMap = new HashMap<>(); | ||
private static final Logger log = LoggerFactory.getLogger(ClusterAddressTranslator.class); | ||
|
||
@Override | ||
public void init(Cluster cluster) { | ||
} | ||
|
||
public void setMap(String addressMapString) { | ||
JSONObject jsonmap; | ||
|
||
if (addressMapString.charAt(0) == '[') { | ||
JSONArray jsonarray = new JSONArray(addressMapString); | ||
log.trace("Address translation map: " + jsonarray.toString()); | ||
Iterator jai = jsonarray.iterator(); | ||
|
||
while (jai.hasNext()) { | ||
JSONObject element = (JSONObject) jai.next(); | ||
Iterator subpart = element.keys(); | ||
String internal = (String) subpart.next(); | ||
String external = element.getString(internal); | ||
addAddresses(internal, external); | ||
} | ||
} else { | ||
jsonmap = new JSONObject(addressMapString); | ||
Iterator keys = jsonmap.keys(); | ||
while (keys.hasNext()) { | ||
String internal = (String) keys.next(); | ||
String external = (String) jsonmap.getString(internal); | ||
addAddresses(internal, external); | ||
} | ||
} | ||
} | ||
|
||
public void addAddresses(String internal, String external) { | ||
String[] internalhostport = internal.split(":"); | ||
String[] externalhostport = external.split(":"); | ||
InetSocketAddress internaladdress = new InetSocketAddress(internalhostport[0], Integer.parseInt(internalhostport[1])); | ||
InetSocketAddress externaladdress = new InetSocketAddress(externalhostport[0], Integer.parseInt(externalhostport[1])); | ||
addressMap.put(internaladdress, externaladdress); | ||
} | ||
|
||
public Collection<InetSocketAddress> getContactPoints() { | ||
return Collections.unmodifiableCollection(addressMap.values()); | ||
} | ||
|
||
@Override | ||
public InetSocketAddress translate(final InetSocketAddress inetSocketAddress) { | ||
return addressMap.getOrDefault(inetSocketAddress, inetSocketAddress); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
} | ||
} |
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
Oops, something went wrong.