Search in sources :

Example 21 with InvalidConfigException

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];
}
Also used : Matcher(java.util.regex.Matcher) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException)

Example 22 with InvalidConfigException

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);
    }
}
Also used : Options(org.apache.commons.cli.Options) GnuParser(org.apache.commons.cli.GnuParser) ArrayList(java.util.ArrayList) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) CommandLine(org.apache.commons.cli.CommandLine) Checkpoint(com.linkedin.databus.core.Checkpoint) DatabusClientNode(com.linkedin.databus.client.pub.DatabusClientNode) DatabusClientGroupMember(com.linkedin.databus.client.pub.DatabusClientGroupMember) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(org.apache.commons.cli.ParseException)

Example 23 with InvalidConfigException

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());
}
Also used : InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) ChunkingType(com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig.ChunkingType)

Example 24 with InvalidConfigException

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);
}
Also used : SourceType(com.linkedin.databus2.relay.config.ReplicationBitSetterStaticConfig.SourceType) MissingValueBehavior(com.linkedin.databus2.relay.config.ReplicationBitSetterStaticConfig.MissingValueBehavior) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException)

Example 25 with InvalidConfigException

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());
}
Also used : InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) Properties(java.util.Properties) ServerContainer(com.linkedin.databus2.core.container.netty.ServerContainer)

Aggregations

InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)29 DatabusException (com.linkedin.databus2.core.DatabusException)7 IOException (java.io.IOException)7 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)6 NoSuchSchemaException (com.linkedin.databus2.schemas.NoSuchSchemaException)6 ArrayList (java.util.ArrayList)6 DbusEventV2Factory (com.linkedin.databus.core.DbusEventV2Factory)5 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)5 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)5 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)5 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)5 HttpServerCodec (org.jboss.netty.handler.codec.http.HttpServerCodec)5 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)5 Log4JLoggerFactory (org.jboss.netty.logging.Log4JLoggerFactory)5 BeforeClass (org.testng.annotations.BeforeClass)5 DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)4 UnsupportedKeyException (com.linkedin.databus.core.UnsupportedKeyException)4 OracleTriggerMonitoredSourceInfo (com.linkedin.databus2.producers.db.OracleTriggerMonitoredSourceInfo)4 Test (org.testng.annotations.Test)4 Checkpoint (com.linkedin.databus.core.Checkpoint)3