Search in sources :

Example 1 with ByteArraySerializer

use of org.apache.helix.manager.zk.ByteArraySerializer in project helix by apache.

the class ZkCopy method main.

public static void main(String[] args) throws Exception {
    CommandLineParser cliParser = new GnuParser();
    Options cliOptions = constructCmdLineOpt();
    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(cliOptions, args);
    } catch (ParseException pe) {
        System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString());
        printUsage(cliOptions);
        System.exit(1);
    }
    URI srcUri = new URI(cmd.getOptionValue(src));
    URI dstUri = new URI(cmd.getOptionValue(dst));
    ZkCopyScheme srcScheme = ZkCopyScheme.valueOf(srcUri.getScheme());
    ZkCopyScheme dstScheme = ZkCopyScheme.valueOf(dstUri.getScheme());
    if (srcScheme == ZkCopyScheme.zk && dstScheme == ZkCopyScheme.zk) {
        String srcZkAddr = srcUri.getAuthority();
        String dstZkAddr = dstUri.getAuthority();
        ZkClient srcClient = null;
        ZkClient dstClient = null;
        try {
            if (srcZkAddr.equals(dstZkAddr)) {
                srcClient = dstClient = new ZkClient(srcZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
            } else {
                srcClient = new ZkClient(srcZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
                dstClient = new ZkClient(dstZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
            }
            String srcPath = srcUri.getPath();
            String dstPath = dstUri.getPath();
            zkCopy(srcClient, srcPath, dstClient, dstPath);
        } finally {
            if (srcClient != null) {
                srcClient.close();
            }
            if (dstClient != null) {
                dstClient.close();
            }
        }
    } else {
        System.err.println("Unsupported scheme. srcScheme: " + srcScheme + ", dstScheme: " + dstScheme);
        System.exit(1);
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) URI(java.net.URI) ByteArraySerializer(org.apache.helix.manager.zk.ByteArraySerializer)

Example 2 with ByteArraySerializer

use of org.apache.helix.manager.zk.ByteArraySerializer in project helix by apache.

the class HelixAdminWebApp method start.

public synchronized void start() throws Exception {
    LOG.info("helixAdminWebApp starting");
    if (_component == null) {
        _zkClient = new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
        _rawZkClient = new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
        _component = new Component();
        _component.getServers().add(Protocol.HTTP, _helixAdminPort);
        Context applicationContext = _component.getContext().createChildContext();
        applicationContext.getAttributes().put(RestAdminApplication.ZKSERVERADDRESS, _zkServerAddress);
        applicationContext.getAttributes().put(RestAdminApplication.PORT, "" + _helixAdminPort);
        applicationContext.getAttributes().put(RestAdminApplication.ZKCLIENT, _zkClient);
        applicationContext.getAttributes().put(ResourceUtil.ContextKey.RAW_ZKCLIENT.toString(), _rawZkClient);
        _adminApp = new RestAdminApplication(applicationContext);
        // Attach the application to the component and start it
        _component.getDefaultHost().attach(_adminApp);
        _component.start();
    }
    LOG.info("helixAdminWebApp started on port: " + _helixAdminPort);
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) Context(org.restlet.Context) Component(org.restlet.Component) ByteArraySerializer(org.apache.helix.manager.zk.ByteArraySerializer) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Aggregations

ByteArraySerializer (org.apache.helix.manager.zk.ByteArraySerializer)2 ZkClient (org.apache.helix.manager.zk.ZkClient)2 URI (java.net.URI)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 GnuParser (org.apache.commons.cli.GnuParser)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)1 Component (org.restlet.Component)1 Context (org.restlet.Context)1