org.apache.blur.console.RunMiniCluster.java Source code

Java tutorial

Introduction

Here is the source code for org.apache.blur.console.RunMiniCluster.java

Source

/**
 * 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.blur.console;

import java.io.File;
import java.io.IOException;

import org.apache.blur.MiniCluster;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocalFileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission;

public class RunMiniCluster {

    private static final File TMPDIR = new File(System.getProperty("blur.tmp.dir", "./target/mini-cluster"));

    public static void main(String[] args) throws IOException {
        // GCWatcher.init(0.60);
        LocalFileSystem localFS = FileSystem.getLocal(new Configuration());
        File testDirectory = new File(TMPDIR, "blur-cluster-test").getAbsoluteFile();
        testDirectory.mkdirs();

        Path directory = new Path(testDirectory.getPath());
        FsPermission dirPermissions = localFS.getFileStatus(directory).getPermission();
        FsAction userAction = dirPermissions.getUserAction();
        FsAction groupAction = dirPermissions.getGroupAction();
        FsAction otherAction = dirPermissions.getOtherAction();

        StringBuilder builder = new StringBuilder();
        builder.append(userAction.ordinal());
        builder.append(groupAction.ordinal());
        builder.append(otherAction.ordinal());
        String dirPermissionNum = builder.toString();
        System.setProperty("dfs.datanode.data.dir.perm", dirPermissionNum);
        testDirectory.delete();
        MiniCluster miniCluster = new MiniCluster();
        miniCluster.startBlurCluster(new File(testDirectory, "cluster").getAbsolutePath(), 2, 3, true, false);

        System.out.println("ZK Connection String = [" + miniCluster.getZkConnectionString() + "]");
        System.out.println("Controller Connection String = [" + miniCluster.getControllerConnectionStr() + "]");
        System.out.println("HDFS URI = [" + miniCluster.getFileSystemUri() + "]");

    }

}