use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class OpenReplicatorEventProducer method processUri.
/**
*
* Responsible for parsing the URI and setting up OpenReplicator connectivity information
* @param uri Open Replicator URI
* @param or Open Replicator
* @return Bin Log Prefix
* @throws InvalidConfigException if URI is incorrect or missing information
*/
public static String processUri(URI uri, OpenReplicator or) throws InvalidConfigException {
String userInfo = uri.getUserInfo();
if (null == userInfo)
throw new InvalidConfigException("missing user info in: " + uri);
int slashPos = userInfo.indexOf('/');
if (slashPos < 0)
slashPos = userInfo.length();
else if (0 == slashPos)
throw new InvalidConfigException("missing user name in user info: " + userInfo);
String userName = userInfo.substring(0, slashPos);
String userPass = slashPos < userInfo.length() - 1 ? userInfo.substring(slashPos + 1) : null;
String hostName = uri.getHost();
int port = uri.getPort();
if (port < 0)
port = DEFAULT_MYSQL_PORT;
String path = uri.getPath();
if (null == path)
throw new InvalidConfigException("missing path: " + uri);
Matcher m = PATH_PATTERN.matcher(path);
if (!m.matches())
throw new InvalidConfigException("invalid path:" + path);
String[] gp = m.group().split("/");
if (gp.length != 3)
throw new InvalidConfigException("Invalid format " + Arrays.toString(gp));
String serverIdStr = gp[1];
int serverId = -1;
try {
serverId = Integer.parseInt(serverIdStr);
} catch (NumberFormatException e) {
throw new InvalidConfigException("incorrect mysql serverid:" + serverId);
}
// Assign them to incoming variables
if (null != or) {
or.setUser(userName);
if (null != userPass)
or.setPassword(userPass);
or.setHost(hostName);
or.setPort(port);
or.setServerId(serverId);
}
return gp[2];
}
use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class DbusClientClusterUtil method main.
/**
* @param args
* DbusClientClusterUtil -s <serverList> -n <namespace> -g <group> -d <dir> members
* leader
* keys
* readSCN <key>
* writeSCN <key> SCN [OFFSET]
* remove <key>
* readLastTS
* writeLastTS TIMESTAMP
*/
public static void main(String[] args) {
try {
GnuParser cmdLineParser = new GnuParser();
Options options = new Options();
options.addOption("n", true, "Zookeeper namespace [/DatabusClient").addOption("g", true, "Groupname [default-group-name] ").addOption("d", true, "Shared directory name [shareddata] ").addOption("s", true, "Zookeeper server list [localhost:2181] ").addOption("h", false, "help");
CommandLine cmdLineArgs = cmdLineParser.parse(options, args, false);
if (cmdLineArgs.hasOption('h')) {
usage();
System.exit(0);
}
String namespace = cmdLineArgs.getOptionValue('n');
if (namespace == null || namespace.isEmpty()) {
namespace = "/DatabusClient";
}
String groupname = cmdLineArgs.getOptionValue('g');
if (groupname == null || groupname.isEmpty()) {
groupname = "default-group-name";
}
String sharedDir = cmdLineArgs.getOptionValue('d');
if (sharedDir == null || sharedDir.isEmpty()) {
sharedDir = "shareddata";
}
String serverList = cmdLineArgs.getOptionValue('s');
if (serverList == null || serverList.isEmpty()) {
serverList = "localhost:2181";
}
String[] fns = cmdLineArgs.getArgs();
if (fns.length < 1) {
usage();
System.exit(1);
}
String function = fns[0];
String arg1 = (fns.length > 1) ? fns[1] : null;
String arg2 = (fns.length > 2) ? fns[2] : null;
try {
String memberName = "cmd-line-tool";
DatabusClientNode clusterNode = new DatabusClientNode(new DatabusClientNode.StaticConfig(true, serverList, 2000, 5000, namespace, groupname, memberName, false, sharedDir));
DatabusClientGroupMember member = clusterNode.getMember(namespace, groupname, memberName);
if (member == null || !member.joinWithoutLeadershipDuties()) {
System.err.println("Initialization failed for: " + member);
System.exit(1);
}
if (function.equals("members")) {
List<String> mlist = member.getMembers();
for (String m : mlist) {
System.out.println(m);
}
} else if (function.equals("leader")) {
String leader = member.getLeader();
System.out.println(leader);
} else if (function.equals("keys")) {
List<String> keyList = member.getSharedKeys();
if (keyList != null) {
for (String m : keyList) {
System.out.println(m);
}
}
} else if (function.equals("readSCN")) {
List<String> keyList;
if (arg1 == null) {
keyList = member.getSharedKeys();
} else {
keyList = new ArrayList<String>();
keyList.add(arg1);
}
if (keyList != null) {
for (String k : keyList) {
if (!k.equals(DatabusClientDSCUpdater.DSCKEY)) {
Checkpoint cp = (Checkpoint) member.readSharedData(k);
if (cp != null) {
System.out.println(k + " " + cp.getWindowScn() + " " + cp.getWindowOffset());
} else {
System.err.println(k + " null null");
}
}
}
}
} else if (function.equals("writeSCN")) {
if (arg1 != null && arg2 != null) {
Checkpoint cp = new Checkpoint();
cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
cp.setWindowScn(Long.parseLong(arg2));
if (fns.length > 3) {
cp.setWindowOffset(Integer.parseInt(fns[3]));
} else {
cp.setWindowOffset(-1);
}
if (member.writeSharedData(arg1, cp)) {
System.out.println(arg1 + " " + cp.getWindowScn() + " " + cp.getWindowOffset());
} else {
System.err.println("Write failed! " + member + " couldn't write key=" + arg1);
System.exit(1);
}
} else {
usage();
System.exit(1);
}
} else if (function.equals("readLastTs")) {
Long timeInMs = (Long) member.readSharedData(DatabusClientDSCUpdater.DSCKEY);
if (timeInMs != null) {
System.out.println(DatabusClientDSCUpdater.DSCKEY + " " + timeInMs.longValue());
} else {
System.err.println(DatabusClientDSCUpdater.DSCKEY + " null");
}
} else if (function.equals("writeLastTs")) {
if (arg1 != null) {
Long ts = Long.parseLong(arg1);
if (member.writeSharedData(DatabusClientDSCUpdater.DSCKEY, ts)) {
System.out.println(DatabusClientDSCUpdater.DSCKEY + " " + ts);
} else {
System.err.println("Write failed! " + member + " couldn't write key=" + DatabusClientDSCUpdater.DSCKEY);
System.exit(1);
}
} else {
usage();
System.exit(1);
}
} else if (function.equals("remove")) {
if (!member.removeSharedData(arg1)) {
System.err.println("Remove failed! " + arg1);
System.exit(1);
}
} else if (function.equals("create")) {
if (!member.createPaths()) {
System.err.println("Create path failed!");
System.exit(1);
}
} else {
usage();
System.exit(1);
}
} catch (InvalidConfigException e) {
e.printStackTrace();
usage();
System.exit(1);
}
} catch (ParseException e) {
usage();
System.exit(1);
}
}
use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class PhysicalSourceConfig method build.
@Override
public PhysicalSourceStaticConfig build() throws InvalidConfigException {
checkForNulls();
//check config options for chained relays
if (_largestEventSizeInBytes >= _largestWindowSizeInBytes) {
throw new InvalidConfigException("Invalid relay config: largestEventSizeInBytes has to be lesser than largestWindowSizeInBytes:" + " largestEventSizeInBytes=" + _largestEventSizeInBytes + " largestWindowSizeInBytes=" + _largestWindowSizeInBytes);
}
LogicalSourceStaticConfig[] sourcesStaticConfigs = new LogicalSourceStaticConfig[_sources.size()];
for (int i = 0; i < _sources.size(); ++i) {
sourcesStaticConfigs[i] = _sources.get(i).build();
}
ChunkingType chunkingType = ChunkingType.valueOf(_chunkingType);
return new PhysicalSourceStaticConfig(_name, _id, _uri, _resourceKey, sourcesStaticConfigs, _role, _slowSourceQueryThreshold, _restartScnOffset, _retries.build(), chunkingType, _txnsPerChunk, _scnChunkSize, _chunkedScnThreshold, _maxScnDelayMs, _eventRatePerSec, _maxThrottleDurationInSecs, isDbusEventBufferSet() ? _dbusEventBuffer.build() : null, _largestEventSizeInBytes, _largestWindowSizeInBytes, _errorOnMissingFields, _xmlVersion, _xmlEncoding, _replBitSetter.build());
}
use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class ReplicationBitSetterConfig method build.
@Override
public ReplicationBitSetterStaticConfig build() throws InvalidConfigException {
SourceType type = null;
try {
type = SourceType.valueOf(_sourceType);
} catch (IllegalArgumentException iae) {
throw new InvalidConfigException("Source Types should be one of (" + Arrays.asList(SourceType.values()) + ") but is (" + _sourceType + ")");
}
MissingValueBehavior missingValueForDelete = null;
try {
missingValueForDelete = MissingValueBehavior.valueOf(_missingValueBehavior);
} catch (IllegalArgumentException iae) {
throw new InvalidConfigException("Missing Value For Delete Behavior should be one of (" + Arrays.asList(MissingValueBehavior.values()) + ") but is (" + _missingValueBehavior + ")");
}
return new ReplicationBitSetterStaticConfig(type, _fieldName, _remoteUpdateValueRegex, missingValueForDelete);
}
use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class ConfigRequestProcessor method doPutConfig.
private void doPutConfig(DatabusRequest request) throws IOException, RequestProcessingException {
Properties cmdParams = request.getParams();
try {
_serverContainer.getContainerRuntimeConfigMgr().loadConfig(cmdParams);
} catch (InvalidConfigException ice) {
throw new RequestProcessingException("config load failed", ice);
}
ServerContainer.RuntimeConfig newConfig = _serverContainer.getContainerRuntimeConfigMgr().getReadOnlyConfig();
serializeConfig(newConfig, request.getResponseContent());
}
Aggregations