org.apache.blur.BlurConfiguration - java examples

Here are the examples of the java api org.apache.blur.BlurConfiguration taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

85 Examples 7

19 View Complete Implementation : SequentialReadControl.java
Copyright Apache License 2.0
Author : apache
public clreplaced SequentialReadControl implements Cloneable {

    private final BlurConfiguration _configuration;

    private final boolean _sequentialReadAllowed = true;

    private long _sequentialReadThreshold;

    private long _sequentialReadSkipThreshold;

    private int _sequentialReadDetectorCounter = 0;

    private boolean _sequentialRead;

    public SequentialReadControl(BlurConfiguration configuration) {
        _configuration = configuration;
        setup(_configuration, this);
    }

    @Override
    public SequentialReadControl clone() {
        try {
            SequentialReadControl control = (SequentialReadControl) super.clone();
            // Setup too heavy for clones
            // setup(_configuration, control);
            return control;
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    public static void setup(BlurConfiguration configuration, SequentialReadControl control) {
        if (Thread.currentThread().getName().startsWith(BlurConstants.SHARED_MERGE_SCHEDULER_PREFIX)) {
            control._sequentialReadThreshold = configuration.getLong(BLUR_SHARD_MERGE_READ_SEQUENTIAL_THRESHOLD, 5L);
            control._sequentialReadSkipThreshold = configuration.getLong(BLUR_SHARD_MERGE_READ_SEQUENTIAL_SKIP_THRESHOLD, 128L * 1024L);
        } else {
            control._sequentialReadThreshold = configuration.getLong(BLUR_SHARD_DEFAULT_READ_SEQUENTIAL_THRESHOLD, 25L);
            control._sequentialReadSkipThreshold = configuration.getLong(BLUR_SHARD_DEFAULT_READ_SEQUENTIAL_SKIP_THRESHOLD, 32L * 1024L);
        }
    }

    public boolean isSequentialReadAllowed() {
        return _sequentialReadAllowed;
    }

    public void incrReadDetector() {
        _sequentialReadDetectorCounter++;
    }

    public boolean switchToSequentialRead() {
        if (_sequentialReadDetectorCounter > _sequentialReadThreshold && !_sequentialRead) {
            return true;
        }
        return false;
    }

    public boolean shouldSkipInput(long filePointer, long prevFilePointer) {
        return filePointer - prevFilePointer <= _sequentialReadSkipThreshold;
    }

    public boolean isEnabled() {
        return _sequentialRead;
    }

    public void setEnabled(boolean sequentialRead) {
        _sequentialRead = sequentialRead;
    }

    public void reset() {
        _sequentialRead = false;
        _sequentialReadDetectorCounter = 0;
    }
}

19 View Complete Implementation : BlurClient.java
Copyright Apache License 2.0
Author : apache
public static Iface getClient(BlurConfiguration conf) {
    return getClient(getOnlineControllers(conf));
}

19 View Complete Implementation : ThriftServer.java
Copyright Apache License 2.0
Author : apache
public void setConfiguration(BlurConfiguration configuration) {
    this._configuration = configuration;
}

19 View Complete Implementation : TableAdmin.java
Copyright Apache License 2.0
Author : apache
public void setConfiguration(BlurConfiguration config) {
    _configuration = config;
}

19 View Complete Implementation : ClientPool.java
Copyright Apache License 2.0
Author : apache
public void setBlurConfiguration(BlurConfiguration configuration) {
    _configuration = configuration;
}

19 View Complete Implementation : BlurUtil.java
Copyright Apache License 2.0
Author : apache
public static Configuration newHadoopConfiguration(BlurConfiguration blurConfiguration) {
    return addHdfsConfig(new Configuration(), blurConfiguration);
}

19 View Complete Implementation : BlurClient.java
Copyright Apache License 2.0
Author : apache
public static void init(BlurConfiguration configuration) {
    _defaultBlurConfiguration = configuration;
    ClientPool clientPool = BlurClientManager.getClientPool();
    clientPool.setBlurConfiguration(_defaultBlurConfiguration);
}

19 View Complete Implementation : ThriftServer.java
Copyright Apache License 2.0
Author : apache
public static File getTmpPath(BlurConfiguration configuration) throws IOException {
    File defaultTmpPath = getDefaultTmpPath(BLUR_TMP_PATH);
    String configTmpPath = configuration.get(BLUR_TMP_PATH);
    File tmpPath;
    if (!(configTmpPath == null || configTmpPath.isEmpty())) {
        tmpPath = new File(configTmpPath);
    } else {
        tmpPath = defaultTmpPath;
    }
    return tmpPath;
}

19 View Complete Implementation : BlurClient.java
Copyright Apache License 2.0
Author : apache
private static String getZooKeeperConnectionStr(BlurConfiguration conf) {
    return conf.getExpected(BLUR_ZOOKEEPER_CONNECTION);
}

19 View Complete Implementation : ThriftCacheServerTest.java
Copyright Apache License 2.0
Author : apache
public clreplaced ThriftCacheServerTest {

    private BlurConfiguration _configuration;

    private ThriftCache _thriftCache;

    private ThriftCacheServer _thriftCacheServer;

    private String _table;

    @Before
    public void setup() throws IOException {
        _configuration = new BlurConfiguration();
        _thriftCache = new ThriftCache(10000);
        _thriftCacheServer = new ThriftCacheServer(_configuration, getMock(), getMockIndexServer(), _thriftCache);
        _table = "t";
    }

    @Test
    public void testQuery() throws IOException, BlurException, TException {
        _thriftCache.clear();
        replacedertEquals(0, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        BlurQuery blurQuery1 = new BlurQuery();
        blurQuery1.setUserContext("user1");
        BlurResults blurResults1 = _thriftCacheServer.query(_table, blurQuery1);
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        BlurQuery blurQuery2 = new BlurQuery();
        blurQuery1.setUserContext("user2");
        BlurResults blurResults2 = _thriftCacheServer.query(_table, blurQuery2);
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(1, _thriftCache.getHits());
        replacedertFalse(blurResults1 == blurResults2);
        replacedertEquals(blurResults1, blurResults2);
    }

    @Test
    public void testTableStats() throws IOException, BlurException, TException {
        _thriftCache.clear();
        replacedertEquals(0, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        TableStats tableStats1 = _thriftCacheServer.tableStats(_table);
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        TableStats tableStats2 = _thriftCacheServer.tableStats(_table);
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(1, _thriftCache.getHits());
        replacedertFalse(tableStats1 == tableStats2);
        replacedertEquals(tableStats1, tableStats2);
    }

    @Test
    public void testFetchRow() throws BlurException, TException {
        _thriftCache.clear();
        replacedertEquals(0, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        Selector selector1 = new Selector();
        selector1.setLocationId("1");
        FetchResult fetchRow1 = _thriftCacheServer.fetchRow(_table, selector1);
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        Selector selector2 = new Selector();
        selector2.setLocationId("1");
        FetchResult fetchRow2 = _thriftCacheServer.fetchRow(_table, selector2);
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(1, _thriftCache.getHits());
        replacedertFalse(fetchRow1 == fetchRow2);
        replacedertEquals(fetchRow1, fetchRow2);
    }

    @Test
    public void testFetchRowBatch1() throws BlurException, TException {
        _thriftCache.clear();
        replacedertEquals(0, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        Selector selector1 = new Selector();
        selector1.setLocationId("1");
        List<FetchResult> fetchRowBatch1 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector1));
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        Selector selector2 = new Selector();
        selector2.setLocationId("1");
        List<FetchResult> fetchRowBatch2 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector2));
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(1, _thriftCache.getHits());
        replacedertFalse(fetchRowBatch1 == fetchRowBatch2);
        replacedertEquals(fetchRowBatch1, fetchRowBatch2);
    }

    @Test
    public void testFetchRowBatch2() throws BlurException, TException {
        _thriftCache.clear();
        replacedertEquals(0, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        Selector selector1 = new Selector();
        selector1.setLocationId("1");
        List<FetchResult> fetchRowBatch1 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector1));
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(0, _thriftCache.getHits());
        Selector selector2 = new Selector();
        selector2.setLocationId("1");
        List<FetchResult> fetchRowBatch2 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector2));
        replacedertEquals(1, _thriftCache.getMisses());
        replacedertEquals(1, _thriftCache.getHits());
        replacedertFalse(fetchRowBatch1 == fetchRowBatch2);
        replacedertEquals(fetchRowBatch1, fetchRowBatch2);
        Selector selector3 = new Selector();
        selector3.setLocationId("2");
        List<FetchResult> fetchRowBatch3 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector1, selector3));
        // one miss for the non cached selector
        replacedertEquals(2, _thriftCache.getMisses());
        // one hit for the cached selector
        replacedertEquals(2, _thriftCache.getHits());
        Selector selector4 = new Selector();
        selector4.setLocationId("2");
        List<FetchResult> fetchRowBatch4 = _thriftCacheServer.fetchRowBatch(_table, Arrays.asList(selector2, selector4));
        replacedertEquals(2, _thriftCache.getMisses());
        // two hits for the cached selectors
        replacedertEquals(4, _thriftCache.getHits());
        replacedertFalse(fetchRowBatch3 == fetchRowBatch4);
        replacedertEquals(fetchRowBatch3, fetchRowBatch4);
    }

    private Iface getMock() {
        return new Iface() {

            @Override
            public List<String> traceRequestList(String traceId) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public String traceRequestFetch(String traceId, String requestId) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void traceRemove(String traceId) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<String> traceList() throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<String> terms(String table, String columnFamily, String columnName, String startWith, short size) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public TableStats tableStats(String table) throws BlurException, TException {
                return new TableStats();
            }

            @Override
            public List<String> tableListByCluster(String cluster) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<String> tableList() throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void startTrace(String traceId, String requestId) throws TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<String> shardServerList(String cluster) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public Map<String, Map<String, ShardState>> shardServerLayoutState(String table) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public Map<String, String> shardServerLayout(String table) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<String> shardClusterList() throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void setUser(User user) throws TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public Schema schema(String table) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void resetLogging() throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void removeTable(String table, boolean deleteIndexFiles) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void removeSnapshot(String table, String name) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void refresh() throws TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public long recordFrequency(String table, String columnFamily, String columnName, String value) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public Response reconnect(long instanceExecutionId) throws BlurException, TimeoutException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<String> queryStatusIdList(String table) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public BlurQueryStatus queryStatusById(String table, String uuid) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public BlurResults query(String table, BlurQuery blurQuery) throws BlurException, TException {
                BlurResults blurResults = new BlurResults();
                return blurResults;
            }

            @Override
            public void ping() throws TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public String parseQuery(String table, Query query) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void optimize(String table, int numberOfSegmentsPerShard) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void mutateBatch(List<RowMutation> mutations) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void mutate(RowMutation mutation) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public Map<String, Metric> metrics(Set<String> metrics) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void logging(String clreplacedNameOrLoggerName, Level level) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void loadData(String table, String location) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public Map<String, List<String>> listSnapshots(String table) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<CommandDescriptor> listInstalledCommands() throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public boolean isInSafeMode(String cluster) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<FetchResult> fetchRowBatch(String table, List<Selector> selectors) throws BlurException, TException {
                List<FetchResult> list = new ArrayList<FetchResult>();
                for (Selector selector : selectors) {
                    list.add(fetchRow(table, selector));
                }
                return list;
            }

            @Override
            public FetchResult fetchRow(String table, Selector selector) throws BlurException, TException {
                FetchResult fetchResult = new FetchResult();
                return fetchResult;
            }

            @Override
            public Response execute(String commandName, Arguments arguments) throws BlurException, TimeoutException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void enqueueMutateBatch(List<RowMutation> mutations) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void enqueueMutate(RowMutation mutation) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void enableTable(String table) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void disableTable(String table) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public TableDescriptor describe(String table) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void createTable(TableDescriptor tableDescriptor) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void createSnapshot(String table, String name) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<String> controllerServerList() throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public Map<String, String> configuration() throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public List<String> commandStatusList(int startingAt, short fetch) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public CommandStatus commandStatus(String commandExecutionId) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void commandCancel(String commandExecutionId) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void cancelQuery(String table, String uuid) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void bulkMutateStart(String bulkId) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void bulkMutateFinish(String bulkId, boolean apply, boolean blockUntilComplete) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void bulkMutateAddMultiple(String bulkId, List<RowMutation> rowMutations) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void bulkMutateAdd(String bulkId, RowMutation rowMutation) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public boolean addColumnDefinition(String table, ColumnDefinition columnDefinition) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public String configurationPerServer(String thriftServerPlusPort, String configName) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void validateIndex(String table, List<String> externalIndexPaths) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public void loadIndex(String table, List<String> externalIndexPaths) throws BlurException, TException {
                throw new RuntimeException("Not implemented.");
            }
        };
    }

    private IndexServer getMockIndexServer() {
        return new IndexServer() {

            @Override
            public long getTableSize(String table) throws IOException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public Map<String, ShardState> getShardState(String table) {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public SortedSet<String> getShardListCurrentServerOnly(String table) throws IOException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public long getRowCount(String table) throws IOException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public long getRecordCount(String table) throws IOException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public String getNodeName() {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public Map<String, BlurIndex> getIndexes(String table) throws IOException {
                Map<String, BlurIndex> map = new HashMap<String, BlurIndex>();
                map.put("shard-000000", null);
                map.put("shard-000001", null);
                return map;
            }

            @Override
            public void close() throws IOException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public long getSegmentImportInProgressCount(String table) throws IOException {
                throw new RuntimeException("Not implemented.");
            }

            @Override
            public long getSegmentImportPendingCount(String table) throws IOException {
                throw new RuntimeException("Not implemented.");
            }
        };
    }
}

19 View Complete Implementation : BlurFilterCache.java
Copyright Apache License 2.0
Author : apache
/**
 * The {@link BlurFilterCache} clreplaced provides the ability to cache pre and post
 * filters on a per table basis. The closing and opening methods should be used
 * as hooks to for when tables are being enabled and disabled.
 */
public abstract clreplaced BlurFilterCache {

    public interface FilterParser {

        Query parse(String query) throws ParseException;
    }

    protected final BlurConfiguration _configuration;

    public BlurFilterCache(BlurConfiguration configuration) {
        _configuration = configuration;
    }

    /**
     * The fetchPreFilter method fetches the cache pre-filter (or {@link Record}
     * Filter) before attempting to execute the filter provided by the user.
     *
     * @param table
     *          the table name.
     * @param filterStr
     *          the filter query string, should be used as a key.
     * @return the {@link Filter} to execute or not is missing.
     */
    public abstract Filter fetchPreFilter(String table, String filterStr);

    /**
     * The fetchPostFilter method fetches the cache post-filter (or {@link Row}
     * Filter) before attempting to execute the filter provided by the user.
     *
     * @param table
     *          the table name.
     * @param filterStr
     *          the filter query string, should be used as a key.
     * @return the {@link Filter} to execute or not is missing.
     */
    public abstract Filter fetchPostFilter(String table, String filterStr);

    /**
     * The storePreFilter method stores the parsed pre {@link Filter} (or
     * {@link Record} Filter) for caching, and should return the {@link Filter} to
     * be executed.
     *
     * @param table
     *          the table name.
     * @param filterStr
     *          the filter query string, should be used as a key.
     * @return the {@link Filter} that was parsed by the {@link SuperParser}.
     * @throws ParseException
     */
    public abstract Filter storePreFilter(String table, String filterStr, Filter filter, FilterParser filterParser) throws ParseException;

    /**
     * The storePreFilter method stores the parsed post {@link Filter} (or
     * {@link Row} Filter) for caching, and should return the {@link Filter} to be
     * executed.
     *
     * @param table
     *          the table name.
     * @param filterStr
     *          the filter query string, should be used as a key.
     * @return the {@link Filter} that was parsed by the {@link SuperParser}.
     * @throws ParseException
     */
    public abstract Filter storePostFilter(String table, String filterStr, Filter filter, FilterParser filterParser) throws ParseException;

    /**
     * Notifies the cache that the index is closing on this shard server.
     *
     * @param table
     *          the table name.
     * @param shard
     *          the shard name.
     * @param index
     *          the {@link BlurIndex}.
     */
    public abstract void closing(String table, String shard, BlurIndex index);

    /**
     * Notifies the cache that the index is opening on this shard server.
     *
     * @param table
     *          the table name.
     * @param shard
     *          the shard name.
     * @param index
     *          the {@link BlurIndex}.
     */
    public abstract void opening(String table, String shard, BlurIndex index);
}

19 View Complete Implementation : ReporterSetup.java
Copyright Apache License 2.0
Author : apache
public abstract void setup(BlurConfiguration configuration);

19 View Complete Implementation : ServerSecurityFilterFactory.java
Copyright Apache License 2.0
Author : apache
public abstract ServerSecurityFilter getServerSecurity(ServerType server, BlurConfiguration configuration);

19 View Complete Implementation : TableContext.java
Copyright Apache License 2.0
Author : apache
public static void setSystemBlurConfiguration(BlurConfiguration systemBlurConfiguration) {
    TableContext._systemBlurConfiguration = systemBlurConfiguration;
}

19 View Complete Implementation : TraceStorage.java
Copyright Apache License 2.0
Author : apache
public abstract clreplaced TraceStorage implements Closeable {

    protected final BlurConfiguration _configuration;

    public TraceStorage(BlurConfiguration configuration) {
        _configuration = configuration;
    }

    public abstract void store(TraceCollector collector);

    public abstract List<String> getTraceIds() throws IOException;

    public abstract List<String> getRequestIds(String traceId) throws IOException;

    public abstract String getRequestContentsJson(String traceId, String requestId) throws IOException;

    public abstract void removeTrace(String traceId) throws IOException;
}

18 View Complete Implementation : SaslHelper.java
Copyright Apache License 2.0
Author : apache
public static boolean isSaslEnabled(BlurConfiguration configuration) {
    return configuration.getBoolean(BLUR_SECURITY_SASL_ENABLED, false);
}

18 View Complete Implementation : AuthenticationDenied.java
Copyright Apache License 2.0
Author : apache
@Override
public final void setupProvider(BlurConfiguration config) {
}

18 View Complete Implementation : SaslHelper.java
Copyright Apache License 2.0
Author : apache
public static void setPlainPreplacedword(BlurConfiguration configuration, String preplacedword) {
    configuration.set(BLUR_SECURITY_SASL_PLAIN_PreplacedWORD, preplacedword);
}

18 View Complete Implementation : ReporterSetup.java
Copyright Apache License 2.0
Author : apache
public static void setupReporters(BlurConfiguration configuration) {
    String reportersStr = configuration.get(BLUR_SHARD_METRICS_REPORTERS);
    if (reportersStr == null || reportersStr.trim().isEmpty()) {
        return;
    }
    String[] reporters = reportersStr.split(",");
    for (String reporter : reporters) {
        setupReporter(configuration, reporter);
    }
}

18 View Complete Implementation : ReporterSetup.java
Copyright Apache License 2.0
Author : apache
private static void reflectiveSetup(Clreplaced<?> reporterClazz, BlurConfiguration configuration, String reporter) {
    try {
        Object o = reporterClazz.newInstance();
        if (o instanceof ReporterSetup) {
            ReporterSetup reporterSetup = (ReporterSetup) o;
            reporterSetup.setup(configuration);
        } else {
            LOG.error("Could not setup [{0}] because it does not extends [{1}]", reporter, ReporterSetup.clreplaced.getName());
        }
    } catch (InstantiationException e) {
        LOG.error("Could not instantiate [{0}]", e, reporter);
    } catch (IllegalAccessException e) {
        LOG.error("Could not instantiate [{0}]", e, reporter);
    }
}

18 View Complete Implementation : ConfigTest.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetBlurConfig() {
    BlurConfiguration blurConfig = Config.getBlurConfig();
    replacedertNotNull(blurConfig);
}

18 View Complete Implementation : DistributedLayoutFactoryImpl.java
Copyright Apache License 2.0
Author : apache
public static DistributedLayoutFactory getDistributedLayoutFactory(BlurConfiguration configuration, String cluster, ZooKeeper zooKeeper) {
    return new MasterBasedDistributedLayoutFactory(zooKeeper, cluster);
}

18 View Complete Implementation : BlurIndexSimpleWriter.java
Copyright Apache License 2.0
Author : apache
private String getDefaultReadMaskMessage(TableContext tableContext) {
    BlurConfiguration blurConfiguration = tableContext.getBlurConfiguration();
    String message = blurConfiguration.get(BLUR_RECORD_SECURITY_DEFAULT_READMASK_MESSAGE);
    if (message == null || message.trim().isEmpty()) {
        return null;
    }
    return message.trim();
}

18 View Complete Implementation : SimpleExampleServerSecurity.java
Copyright Apache License 2.0
Author : apache
@Override
public ServerSecurityFilter getServerSecurity(ServerType server, BlurConfiguration configuration) {
    return new ServerSecurityFilter() {

        @Override
        public boolean canAccess(Method method, Object[] args, User user, InetAddress address, int port) throws BlurException {
            if (method.getName().equals("createTable")) {
                if (user != null && user.getUsername().equals("admin")) {
                    return true;
                }
                return false;
            }
            return true;
        }
    };
}

18 View Complete Implementation : FilteredBlurServer.java
Copyright Apache License 2.0
Author : apache
public clreplaced FilteredBlurServer implements Iface {

    protected final Iface _iface;

    public void startTrace(String rootId, String requestId) throws TException {
        _iface.startTrace(rootId, requestId);
    }

    protected final boolean _shard;

    protected final BlurConfiguration _configuration;

    public FilteredBlurServer(BlurConfiguration configuration, Iface iface, boolean shard) {
        _iface = iface;
        _shard = shard;
        _configuration = configuration;
    }

    public void setUser(User user) throws TException {
        _iface.setUser(user);
    }

    public final BlurServerContext getServerContext() {
        if (_shard) {
            return ShardServerContext.getShardServerContext();
        } else {
            return ControllerServerContext.getControllerServerContext();
        }
    }

    public void createTable(TableDescriptor tableDescriptor) throws BlurException, TException {
        _iface.createTable(tableDescriptor);
    }

    public void enableTable(String table) throws BlurException, TException {
        _iface.enableTable(table);
    }

    public void disableTable(String table) throws BlurException, TException {
        _iface.disableTable(table);
    }

    public void removeTable(String table, boolean deleteIndexFiles) throws BlurException, TException {
        _iface.removeTable(table, deleteIndexFiles);
    }

    public boolean addColumnDefinition(String table, ColumnDefinition columnDefinition) throws BlurException, TException {
        return _iface.addColumnDefinition(table, columnDefinition);
    }

    public List<String> tableList() throws BlurException, TException {
        return _iface.tableList();
    }

    public List<String> tableListByCluster(String cluster) throws BlurException, TException {
        return _iface.tableListByCluster(cluster);
    }

    public TableDescriptor describe(String table) throws BlurException, TException {
        return _iface.describe(table);
    }

    public Schema schema(String table) throws BlurException, TException {
        return _iface.schema(table);
    }

    public String parseQuery(String table, Query query) throws BlurException, TException {
        return _iface.parseQuery(table, query);
    }

    public TableStats tableStats(String table) throws BlurException, TException {
        return _iface.tableStats(table);
    }

    public void optimize(String table, int numberOfSegmentsPerShard) throws BlurException, TException {
        _iface.optimize(table, numberOfSegmentsPerShard);
    }

    public void createSnapshot(String table, String name) throws BlurException, TException {
        _iface.createSnapshot(table, name);
    }

    public void removeSnapshot(String table, String name) throws BlurException, TException {
        _iface.removeSnapshot(table, name);
    }

    public Map<String, List<String>> listSnapshots(String table) throws BlurException, TException {
        return _iface.listSnapshots(table);
    }

    public BlurResults query(String table, BlurQuery blurQuery) throws BlurException, TException {
        return _iface.query(table, blurQuery);
    }

    public FetchResult fetchRow(String table, Selector selector) throws BlurException, TException {
        return _iface.fetchRow(table, selector);
    }

    public List<FetchResult> fetchRowBatch(String table, List<Selector> selectors) throws BlurException, TException {
        return _iface.fetchRowBatch(table, selectors);
    }

    public void mutate(RowMutation mutation) throws BlurException, TException {
        _iface.mutate(mutation);
    }

    public void mutateBatch(List<RowMutation> mutations) throws BlurException, TException {
        _iface.mutateBatch(mutations);
    }

    public void cancelQuery(String table, String uuid) throws BlurException, TException {
        _iface.cancelQuery(table, uuid);
    }

    public List<String> queryStatusIdList(String table) throws BlurException, TException {
        return _iface.queryStatusIdList(table);
    }

    public BlurQueryStatus queryStatusById(String table, String uuid) throws BlurException, TException {
        return _iface.queryStatusById(table, uuid);
    }

    public List<String> terms(String table, String columnFamily, String columnName, String startWith, short size) throws BlurException, TException {
        return _iface.terms(table, columnFamily, columnName, startWith, size);
    }

    public long recordFrequency(String table, String columnFamily, String columnName, String value) throws BlurException, TException {
        return _iface.recordFrequency(table, columnFamily, columnName, value);
    }

    public List<String> shardClusterList() throws BlurException, TException {
        return _iface.shardClusterList();
    }

    public List<String> shardServerList(String cluster) throws BlurException, TException {
        return _iface.shardServerList(cluster);
    }

    public List<String> controllerServerList() throws BlurException, TException {
        return _iface.controllerServerList();
    }

    public Map<String, String> shardServerLayout(String table) throws BlurException, TException {
        return _iface.shardServerLayout(table);
    }

    public Map<String, Map<String, ShardState>> shardServerLayoutState(String table) throws BlurException, TException {
        return _iface.shardServerLayoutState(table);
    }

    public boolean isInSafeMode(String cluster) throws BlurException, TException {
        return _iface.isInSafeMode(cluster);
    }

    public Map<String, String> configuration() throws BlurException, TException {
        return _iface.configuration();
    }

    public Map<String, Metric> metrics(Set<String> metrics) throws BlurException, TException {
        return _iface.metrics(metrics);
    }

    public List<String> traceList() throws BlurException, TException {
        return _iface.traceList();
    }

    public List<String> traceRequestList(String traceId) throws BlurException, TException {
        return _iface.traceRequestList(traceId);
    }

    public String traceRequestFetch(String traceId, String requestId) throws BlurException, TException {
        return _iface.traceRequestFetch(traceId, requestId);
    }

    public void traceRemove(String traceId) throws BlurException, TException {
        _iface.traceRemove(traceId);
    }

    @Override
    public void ping() throws TException {
        _iface.ping();
    }

    @Override
    public void logging(String clreplacedNameOrLoggerName, Level level) throws BlurException, TException {
        _iface.logging(clreplacedNameOrLoggerName, level);
    }

    @Override
    public void resetLogging() throws BlurException, TException {
        _iface.resetLogging();
    }

    @Override
    public void enqueueMutate(RowMutation mutation) throws BlurException, TException {
        _iface.enqueueMutate(mutation);
    }

    @Override
    public void enqueueMutateBatch(List<RowMutation> mutations) throws BlurException, TException {
        _iface.enqueueMutateBatch(mutations);
    }

    @Override
    public Response execute(String commandName, Arguments arguments) throws BlurException, TException {
        return _iface.execute(commandName, arguments);
    }

    @Override
    public void refresh() throws TException {
        _iface.refresh();
    }

    @Override
    public List<String> commandStatusList(int startingAt, short fetch) throws BlurException, TException {
        return _iface.commandStatusList(startingAt, fetch);
    }

    @Override
    public List<CommandDescriptor> listInstalledCommands() throws BlurException, TException {
        return _iface.listInstalledCommands();
    }

    @Override
    public Response reconnect(long instanceExecutionId) throws BlurException, TimeoutException, TException {
        return _iface.reconnect(instanceExecutionId);
    }

    @Override
    public CommandStatus commandStatus(String commandExecutionId) throws BlurException, TException {
        return _iface.commandStatus(commandExecutionId);
    }

    @Override
    public void commandCancel(String commandExecutionId) throws BlurException, TException {
        _iface.commandCancel(commandExecutionId);
    }

    @Override
    public void loadData(String table, String location) throws BlurException, TException {
        _iface.loadData(table, location);
    }

    @Override
    public void bulkMutateStart(String bulkId) throws BlurException, TException {
        _iface.bulkMutateStart(bulkId);
    }

    @Override
    public void bulkMutateAdd(String bulkId, RowMutation rowMutation) throws BlurException, TException {
        _iface.bulkMutateAdd(bulkId, rowMutation);
    }

    @Override
    public void bulkMutateFinish(String bulkId, boolean apply, boolean blockUntilComplete) throws BlurException, TException {
        _iface.bulkMutateFinish(bulkId, apply, blockUntilComplete);
    }

    @Override
    public void bulkMutateAddMultiple(String bulkId, List<RowMutation> rowMutations) throws BlurException, TException {
        _iface.bulkMutateAddMultiple(bulkId, rowMutations);
    }

    @Override
    public String configurationPerServer(String thriftServerPlusPort, String configName) throws BlurException, TException {
        return _iface.configurationPerServer(thriftServerPlusPort, configName);
    }

    @Override
    public void validateIndex(String table, List<String> externalIndexPaths) throws BlurException, TException {
        _iface.validateIndex(table, externalIndexPaths);
    }

    @Override
    public void loadIndex(String table, List<String> externalIndexPaths) throws BlurException, TException {
        _iface.loadIndex(table, externalIndexPaths);
    }
}

18 View Complete Implementation : ThriftServer.java
Copyright Apache License 2.0
Author : apache
public static TraceStorage setupTraceStorage(BlurConfiguration configuration, Configuration conf) throws IOException {
    String hdfsPath = configuration.get(BLUR_HDFS_TRACE_PATH);
    if (hdfsPath != null) {
        HdfsTraceStorage hdfsTraceStorage = new HdfsTraceStorage(configuration);
        hdfsTraceStorage.init(conf);
        return hdfsTraceStorage;
    } else {
        return new LogTraceStorage(configuration);
    }
}

18 View Complete Implementation : ThriftServer.java
Copyright Apache License 2.0
Author : apache
public static TServerTransport getTServerTransport(String bindAddress, int bindPort, BlurConfiguration configuration) throws TTransportException {
    InetSocketAddress bindInetSocketAddress = getBindInetSocketAddress(bindAddress, bindPort);
    if (SaslHelper.isSaslEnabled(configuration)) {
        return new TServerSocket(bindInetSocketAddress);
    } else {
        return new TNonblockingServerSocket(bindInetSocketAddress);
    }
}

18 View Complete Implementation : BlurClient.java
Copyright Apache License 2.0
Author : apache
public clreplaced BlurClient {

    private static final Log LOG = LogFactory.getLog(BlurClient.clreplaced);

    public static clreplaced BlurClientInvocationHandler implements InvocationHandler {

        private final List<Connection> _connections;

        private final int _maxRetries;

        private final long _backOffTime;

        private final long _maxBackOffTime;

        public BlurClientInvocationHandler(List<Connection> connections, int maxRetries, long backOffTime, long maxBackOffTime) {
            _connections = connections;
            _maxRetries = maxRetries;
            _backOffTime = backOffTime;
            _maxBackOffTime = maxBackOffTime;
        }

        public BlurClientInvocationHandler(List<Connection> connections) {
            this(connections, BlurClientManager.MAX_RETRIES, BlurClientManager.BACK_OFF_TIME, BlurClientManager.MAX_BACK_OFF_TIME);
        }

        public List<Connection> getConnections() {
            return _connections;
        }

        @Override
        public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable {
            return BlurClientManager.execute(_connections, new BlurCommand<Object>() {

                @Override
                public Object call(Client client) throws BlurException, TException {
                    try {
                        return method.invoke(client, args);
                    } catch (IllegalArgumentException e) {
                        throw new RuntimeException(e);
                    } catch (IllegalAccessException e) {
                        throw new RuntimeException(e);
                    } catch (InvocationTargetException e) {
                        Throwable targetException = e.getTargetException();
                        if (targetException instanceof BlurException) {
                            throw (BlurException) targetException;
                        }
                        if (targetException instanceof TException) {
                            throw (TException) targetException;
                        }
                        throw new RuntimeException(targetException);
                    }
                }
            }, _maxRetries, _backOffTime, _maxBackOffTime);
        }
    }

    private static clreplaced ZooKeeperConntrollerWatchInfo implements Closeable {

        final List<Connection> _connections = new CopyOnWriteArrayList<Connection>();

        final ZooKeeper _zooKeeper;

        final WatchChildren _watchConntrollers;

        final String _zooKeeperConnectionStr;

        final int _zkSessionTimeout;

        ZooKeeperConntrollerWatchInfo(BlurConfiguration conf) throws IOException, KeeperException, InterruptedException {
            _zooKeeperConnectionStr = conf.getExpected(BLUR_ZOOKEEPER_CONNECTION);
            _zkSessionTimeout = conf.getInt(BLUR_ZOOKEEPER_TIMEOUT, BLUR_ZOOKEEPER_TIMEOUT_DEFAULT);
            _zooKeeper = new ZooKeeperClient(_zooKeeperConnectionStr, _zkSessionTimeout, new Watcher() {

                @Override
                public void process(WatchedEvent event) {
                }
            });
            setConnections(_zooKeeper.getChildren(ZookeeperPathConstants.getOnlineControllersPath(), false));
            _watchConntrollers = new WatchChildren(_zooKeeper, ZookeeperPathConstants.getOnlineControllersPath());
            _watchConntrollers.watch(new OnChange() {

                @Override
                public void action(List<String> children) {
                    setConnections(children);
                }
            });
        }

        void setConnections(List<String> children) {
            Set<Connection> goodConnections = new HashSet<Connection>();
            for (String s : children) {
                Connection connection = new Connection(s);
                goodConnections.add(connection);
                if (!_connections.contains(connection)) {
                    _connections.add(connection);
                }
            }
            Set<Connection> badConnections = new HashSet<Connection>();
            for (Connection c : _connections) {
                if (!goodConnections.contains(c)) {
                    badConnections.add(c);
                }
            }
            _connections.removeAll(badConnections);
        }

        @Override
        public void close() throws IOException {
            closeQuietly(_watchConntrollers);
            closeQuietly(new Closeable() {

                @Override
                public void close() throws IOException {
                    try {
                        _zooKeeper.close();
                    } catch (InterruptedException e) {
                        throw new IOException(e);
                    }
                }
            });
        }
    }

    private static ConcurrentMap<String, ZooKeeperConntrollerWatchInfo> _zkConnectionInfo = new ConcurrentHashMap<String, ZooKeeperConntrollerWatchInfo>();

    private static BlurConfiguration _defaultBlurConfiguration;

    public static Iface getClient() {
        try {
            return getClient(getBlurConfiguration());
        } catch (IOException e) {
            throw new RuntimeException("Unable to load configurations.", e);
        }
    }

    private static synchronized BlurConfiguration getBlurConfiguration() throws IOException {
        if (_defaultBlurConfiguration == null) {
            _defaultBlurConfiguration = new BlurConfiguration();
        }
        return _defaultBlurConfiguration;
    }

    public static Iface getClient(BlurConfiguration conf) {
        return getClient(getOnlineControllers(conf));
    }

    /**
     * Returns a client interface to Blur based on the connectionStr.
     *
     * <pre>
     * Blur.Iface client = Blur.getClient("controller1:40010,controller2:40010");
     * </pre>
     *
     * The connectionStr also supports preplaceding a proxy host/port (e.g. a SOCKS
     * proxy configuration):
     *
     * <pre>
     * Blur.Iface client = Blur.getClient("host1:port/proxyhost1:proxyport");
     * </pre>
     *
     * @param connectionStr
     *          - a comma-delimited list of host:port of Shard Controllers.
     * @return
     */
    public static Iface getClient(String connectionStr) {
        List<Connection> connections = BlurClientManager.getConnections(connectionStr);
        return getClient(connections);
    }

    public static Iface getClient(String connectionStr, int maxRetries, long backOffTime, long maxBackOffTime) {
        List<Connection> connections = BlurClientManager.getConnections(connectionStr);
        return getClient(connections, maxRetries, backOffTime, maxBackOffTime);
    }

    public static Iface getClient(Connection connection) {
        return getClient(Arrays.asList(connection));
    }

    public static Iface getClient(List<Connection> connections) {
        return (Iface) Proxy.newProxyInstance(Iface.clreplaced.getClreplacedLoader(), new Clreplaced[] { Iface.clreplaced }, new BlurClientInvocationHandler(connections));
    }

    public static Iface getClient(Connection connection, int maxRetries, long backOffTime, long maxBackOffTime) {
        return getClient(Arrays.asList(connection), maxRetries, backOffTime, maxBackOffTime);
    }

    public static Iface getClient(List<Connection> connections, int maxRetries, long backOffTime, long maxBackOffTime) {
        return (Iface) Proxy.newProxyInstance(Iface.clreplaced.getClreplacedLoader(), new Clreplaced[] { Iface.clreplaced }, new BlurClientInvocationHandler(connections, maxRetries, backOffTime, maxBackOffTime));
    }

    private static List<Connection> getOnlineControllers(BlurConfiguration conf) {
        String zooKeeperConnectionStr = getZooKeeperConnectionStr(conf);
        ZooKeeperConntrollerWatchInfo zooKeeperConntrollerWatchInfo = _zkConnectionInfo.get(zooKeeperConnectionStr);
        if (zooKeeperConntrollerWatchInfo != null) {
            return zooKeeperConntrollerWatchInfo._connections;
        }
        setupZooKeeper(conf);
        zooKeeperConntrollerWatchInfo = _zkConnectionInfo.get(zooKeeperConnectionStr);
        return zooKeeperConntrollerWatchInfo._connections;
    }

    private static String getZooKeeperConnectionStr(BlurConfiguration conf) {
        return conf.getExpected(BLUR_ZOOKEEPER_CONNECTION);
    }

    private static synchronized void setupZooKeeper(BlurConfiguration conf) {
        String zooKeeperConnectionStr = getZooKeeperConnectionStr(conf);
        ZooKeeperConntrollerWatchInfo zooKeeperConntrollerWatchInfo = _zkConnectionInfo.get(zooKeeperConnectionStr);
        if (zooKeeperConntrollerWatchInfo == null) {
            try {
                final ZooKeeperConntrollerWatchInfo zkcwi = new ZooKeeperConntrollerWatchInfo(conf);
                _zkConnectionInfo.put(zooKeeperConnectionStr, zkcwi);
                Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

                    @Override
                    public void run() {
                        closeQuietly(zkcwi);
                    }
                }));
            } catch (Exception e) {
                throw new RuntimeException("Unknown error while trying to connect to ZooKeeper and fetch controllers.", e);
            }
        }
    }

    public static void closeQuietly(Closeable closeable) {
        try {
            closeable.close();
        } catch (IOException e) {
            LOG.error("Unknown error while trying to close [{0}]", e);
        }
    }

    public static void closeZooKeeper() {
        Collection<ZooKeeperConntrollerWatchInfo> values = _zkConnectionInfo.values();
        for (ZooKeeperConntrollerWatchInfo zooKeeperConntrollerWatchInfo : values) {
            closeQuietly(zooKeeperConntrollerWatchInfo);
        }
    }

    public static Iface getClientFromZooKeeperConnectionStr(String zkConnectionString) {
        BlurConfiguration blurConfiguration;
        try {
            blurConfiguration = new BlurConfiguration();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        blurConfiguration.set(BLUR_ZOOKEEPER_CONNECTION, zkConnectionString);
        return getClient(blurConfiguration);
    }

    public static void init(BlurConfiguration configuration) {
        _defaultBlurConfiguration = configuration;
        ClientPool clientPool = BlurClientManager.getClientPool();
        clientPool.setBlurConfiguration(_defaultBlurConfiguration);
    }
}

18 View Complete Implementation : AllAuthenticated.java
Copyright Apache License 2.0
Author : apache
@Override
public void setupProvider(BlurConfiguration config) {
}

18 View Complete Implementation : SaslHelper.java
Copyright Apache License 2.0
Author : apache
public static PreplacedwordAuthenticationProvider getAuthenticationProvider(AuthenticationType type, BlurConfiguration configuration) throws IOException {
    LOG.info("Setting SASL Server with preplacedword authentication provider [{0}]", type);
    switch(type) {
        case ANONYMOUS:
            return new AnonymousAuthenticationProviderImpl(configuration);
        case CUSTOM:
            return new CustomAuthenticationProviderImpl(configuration);
        case LDAP:
            return new LdapAuthenticationProviderImpl(configuration);
        default:
            throw new IOException("Unsupported authentication method [" + type + "]");
    }
}

18 View Complete Implementation : ThriftServer.java
Copyright Apache License 2.0
Author : apache
public static String getNodeName(BlurConfiguration configuration, String hostNameProperty) throws UnknownHostException {
    String hostName = configuration.get(hostNameProperty);
    if (hostName == null) {
        hostName = "";
    }
    hostName = hostName.trim();
    if (hostName.isEmpty()) {
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            String message = e.getMessage();
            int index = message.indexOf(':');
            if (index < 0) {
                throw new RuntimeException("Nodename cannot be determined.");
            }
            String nodeName = message.substring(0, index);
            LOG.warn("Hack to get nodename from exception [" + nodeName + "]");
            return nodeName;
        }
    }
    return hostName;
}

18 View Complete Implementation : AliasBlurFilterCacheTest.java
Copyright Apache License 2.0
Author : apache
@Test
public void testFetchPreFilterEmpty() throws IOException {
    BlurConfiguration configuration = new BlurConfiguration();
    AliasBlurFilterCache defaultBlurFilterCache = new AliasBlurFilterCache(configuration);
    Filter fetchPreFilter = defaultBlurFilterCache.fetchPreFilter(TABLE, TEST_FILTER);
    replacedertNull(fetchPreFilter);
}

18 View Complete Implementation : SaslHelper.java
Copyright Apache License 2.0
Author : apache
public static void setPlainUsername(BlurConfiguration configuration, String username) {
    configuration.set(BLUR_SECURITY_SASL_PLAIN_USERNAME, username);
}

18 View Complete Implementation : EmptyAuthorization.java
Copyright Apache License 2.0
Author : apache
@Override
public void setupProvider(BlurConfiguration config) throws Exception {
// do nothing
}

18 View Complete Implementation : HdfsTraceStorageTest.java
Copyright Apache License 2.0
Author : apache
public clreplaced HdfsTraceStorageTest {

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

    private HdfsTraceStorage _storage;

    private BlurConfiguration configuration;

    @Before
    public void setUp() throws IOException, InterruptedException {
        rmr(TMPDIR);
        LocalFileSystem localFS = FileSystem.getLocal(new Configuration());
        File testDirectory = new File(TMPDIR, "HdfsTraceStorageTest").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);
        configuration = new BlurConfiguration();
        configuration.set(BLUR_HDFS_TRACE_PATH, directory.makeQualified(localFS).toString());
        _storage = new HdfsTraceStorage(configuration);
        _storage.init(new Configuration());
    }

    @After
    public void tearDown() throws Exception {
        _storage.close();
        rmr(new File("./target/HdfsTraceStorageTest"));
    }

    private void rmr(File file) {
        if (file.exists()) {
            if (file.isDirectory()) {
                for (File f : file.listFiles()) {
                    rmr(f);
                }
            }
            file.delete();
        }
    }

    @Test
    public void testStorage() throws IOException, JSONException {
        Random random = new Random();
        createTraceData(random);
        createTraceData(random);
        createTraceData(random);
        List<String> traceIds = _storage.getTraceIds();
        replacedertEquals(3, traceIds.size());
        for (String traceId : traceIds) {
            List<String> requestIds = _storage.getRequestIds(traceId);
            replacedertEquals(4, requestIds.size());
            for (String requestId : requestIds) {
                String contents = _storage.getRequestContentsJson(traceId, requestId);
                replacedertEquals("{\"id\":" + requestId + "}", contents);
            }
        }
        _storage.removeTrace(traceIds.get(0));
        replacedertEquals(2, _storage.getTraceIds().size());
    }

    private void createTraceData(Random random) throws IOException, JSONException {
        String traceId = Long.toString(Math.abs(random.nextLong()));
        Path path = new Path(configuration.get(BLUR_HDFS_TRACE_PATH));
        Path tracePath = new Path(path, traceId);
        Path storePath = new Path(tracePath, traceId + "_" + Long.toString(Math.abs(random.nextLong())));
        _storage.storeJson(storePath, new JSONObject("{\"id\":" + traceId + "}"));
        writeRequest(random, tracePath);
        writeRequest(random, tracePath);
        writeRequest(random, tracePath);
    }

    private void writeRequest(Random random, Path tracePath) throws IOException, JSONException {
        String requestId = Long.toString(random.nextLong());
        Path storePath = new Path(tracePath, requestId + "_" + Long.toString(Math.abs(random.nextLong())));
        System.out.println(storePath);
        _storage.storeJson(storePath, new JSONObject("{\"id\":" + requestId + "}"));
    }
}

18 View Complete Implementation : SequentialReadControl.java
Copyright Apache License 2.0
Author : apache
public static void setup(BlurConfiguration configuration, SequentialReadControl control) {
    if (Thread.currentThread().getName().startsWith(BlurConstants.SHARED_MERGE_SCHEDULER_PREFIX)) {
        control._sequentialReadThreshold = configuration.getLong(BLUR_SHARD_MERGE_READ_SEQUENTIAL_THRESHOLD, 5L);
        control._sequentialReadSkipThreshold = configuration.getLong(BLUR_SHARD_MERGE_READ_SEQUENTIAL_SKIP_THRESHOLD, 128L * 1024L);
    } else {
        control._sequentialReadThreshold = configuration.getLong(BLUR_SHARD_DEFAULT_READ_SEQUENTIAL_THRESHOLD, 25L);
        control._sequentialReadSkipThreshold = configuration.getLong(BLUR_SHARD_DEFAULT_READ_SEQUENTIAL_SKIP_THRESHOLD, 32L * 1024L);
    }
}

18 View Complete Implementation : BlurClient.java
Copyright Apache License 2.0
Author : apache
public static Iface getClientFromZooKeeperConnectionStr(String zkConnectionString) {
    BlurConfiguration blurConfiguration;
    try {
        blurConfiguration = new BlurConfiguration();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    blurConfiguration.set(BLUR_ZOOKEEPER_CONNECTION, zkConnectionString);
    return getClient(blurConfiguration);
}

18 View Complete Implementation : BlurClient.java
Copyright Apache License 2.0
Author : apache
private static List<Connection> getOnlineControllers(BlurConfiguration conf) {
    String zooKeeperConnectionStr = getZooKeeperConnectionStr(conf);
    ZooKeeperConntrollerWatchInfo zooKeeperConntrollerWatchInfo = _zkConnectionInfo.get(zooKeeperConnectionStr);
    if (zooKeeperConntrollerWatchInfo != null) {
        return zooKeeperConntrollerWatchInfo._connections;
    }
    setupZooKeeper(conf);
    zooKeeperConntrollerWatchInfo = _zkConnectionInfo.get(zooKeeperConnectionStr);
    return zooKeeperConntrollerWatchInfo._connections;
}

17 View Complete Implementation : BlurUtil.java
Copyright Apache License 2.0
Author : apache
@SuppressWarnings("unchecked")
public static Iface wrapFilteredBlurServer(BlurConfiguration configuration, Iface iface, boolean shard) {
    String clreplacedName;
    if (!shard) {
        clreplacedName = configuration.get(BLUR_CONTROLLER_FILTERED_SERVER_CLreplaced);
    } else {
        clreplacedName = configuration.get(BLUR_SHARD_FILTERED_SERVER_CLreplaced);
    }
    if (clreplacedName != null && !clreplacedName.isEmpty()) {
        try {
            Clreplaced<? extends FilteredBlurServer> clazz = (Clreplaced<? extends FilteredBlurServer>) Clreplaced.forName(clreplacedName);
            Constructor<? extends FilteredBlurServer> constructor = clazz.getConstructor(new Clreplaced[] { BlurConfiguration.clreplaced, Iface.clreplaced, Boolean.TYPE });
            return constructor.newInstance(new Object[] { configuration, iface, shard });
        } catch (ClreplacedNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (SecurityException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
    return iface;
}

17 View Complete Implementation : SuiteCluster.java
Copyright Apache License 2.0
Author : apache
public static Iface getClient() throws IOException {
    String zkConnectionString = cluster.getZkConnectionString();
    BlurConfiguration blurConfiguration = new BlurConfiguration();
    blurConfiguration.set(BlurConstants.BLUR_ZOOKEEPER_CONNECTION, zkConnectionString);
    return BlurClient.getClient(blurConfiguration);
}

17 View Complete Implementation : BlurClient.java
Copyright Apache License 2.0
Author : apache
private static synchronized void setupZooKeeper(BlurConfiguration conf) {
    String zooKeeperConnectionStr = getZooKeeperConnectionStr(conf);
    ZooKeeperConntrollerWatchInfo zooKeeperConntrollerWatchInfo = _zkConnectionInfo.get(zooKeeperConnectionStr);
    if (zooKeeperConntrollerWatchInfo == null) {
        try {
            final ZooKeeperConntrollerWatchInfo zkcwi = new ZooKeeperConntrollerWatchInfo(conf);
            _zkConnectionInfo.put(zooKeeperConnectionStr, zkcwi);
            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

                @Override
                public void run() {
                    closeQuietly(zkcwi);
                }
            }));
        } catch (Exception e) {
            throw new RuntimeException("Unknown error while trying to connect to ZooKeeper and fetch controllers.", e);
        }
    }
}

17 View Complete Implementation : LdapAuthenticationProviderImpl.java
Copyright Apache License 2.0
Author : apache
public static void main(String[] args) throws IOException {
    if (args.length < 2) {
        System.err.println("<ldap uri> <username>");
        System.exit(1);
    }
    String ldap = args[0];
    StringBuilder builder = new StringBuilder();
    for (int i = 1; i < args.length; i++) {
        if (builder.length() != 0) {
            builder.append(' ');
        }
        builder.append(args[i]);
    }
    String user = builder.toString();
    Console cons;
    if ((cons = System.console()) != null) {
        char[] preplacedwd = cons.readPreplacedword("%s", "Type Preplacedword:\n");
        BlurConfiguration blurConfiguration = new BlurConfiguration();
        blurConfiguration.set(BLUR_SECURITY_SASL_LDAP_URL, ldap);
        LdapAuthenticationProviderImpl ldapAuthenticationProviderImpl = new LdapAuthenticationProviderImpl(blurConfiguration);
        ldapAuthenticationProviderImpl.authenticate(user, new String(preplacedwd), null);
        System.out.println("Valid");
    } else {
        System.err.println("No Console.");
        System.exit(1);
    }
}

17 View Complete Implementation : SaslHelper.java
Copyright Apache License 2.0
Author : apache
public static TTransport getTSaslClientTransport(BlurConfiguration configuration, TTransport transport) throws IOException {
    AuthenticationType type = getValueOf(configuration.get(BLUR_SECURITY_SASL_TYPE));
    switch(type) {
        case ANONYMOUS:
        case LDAP:
        case CUSTOM:
            return getPlainTSaslClientTransport(type, configuration, transport);
        default:
            throw new IOException("Type [" + type + "] not supported.");
    }
}

17 View Complete Implementation : SaslHelper.java
Copyright Apache License 2.0
Author : apache
private static TSaslServerTransport.Factory getPlainTSaslServerTransportFactory(final AuthenticationType type, final BlurConfiguration configuration) throws IOException {
    TSaslServerTransport.Factory saslTransportFactory = new TSaslServerTransport.Factory();
    final String serverName = null;
    final Map<String, String> props = new HashMap<String, String>();
    final PreplacedwordAuthenticationProvider provider = getAuthenticationProvider(type, configuration);
    CallbackHandler cbh = new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            String username = null;
            String preplacedword = null;
            AuthorizeCallback ac = null;
            for (int i = 0; i < callbacks.length; i++) {
                if (callbacks[i] instanceof NameCallback) {
                    NameCallback nc = (NameCallback) callbacks[i];
                    username = nc.getName();
                } else if (callbacks[i] instanceof PreplacedwordCallback) {
                    PreplacedwordCallback pc = (PreplacedwordCallback) callbacks[i];
                    preplacedword = new String(pc.getPreplacedword());
                } else if (callbacks[i] instanceof AuthorizeCallback) {
                    ac = (AuthorizeCallback) callbacks[i];
                } else {
                    throw new UnsupportedCallbackException(callbacks[i]);
                }
            }
            InetSocketAddress address = TSaslTransport._currentConnection.get();
            provider.authenticate(username, preplacedword, address);
            if (ac != null) {
                ac.setAuthorized(true);
            }
        }
    };
    saslTransportFactory.addServerDefinition(PLAIN, CUSTOM, serverName, props, cbh);
    return saslTransportFactory;
}

17 View Complete Implementation : SaslHelper.java
Copyright Apache License 2.0
Author : apache
public static TSaslServerTransport.Factory getTSaslServerTransportFactory(BlurConfiguration configuration) throws IOException {
    AuthenticationType type = getValueOf(configuration.get(BLUR_SECURITY_SASL_TYPE));
    LOG.info("Setting SASL Server with authentication type [{0}]", type);
    switch(type) {
        case ANONYMOUS:
        case LDAP:
        case CUSTOM:
            return getPlainTSaslServerTransportFactory(type, configuration);
        default:
            throw new IOException("Type [" + type + "] not supported.");
    }
}

17 View Complete Implementation : ReporterSetup.java
Copyright Apache License 2.0
Author : apache
private static void setupConsoleReporter(BlurConfiguration configuration) {
    long period = configuration.getLong(BLUR_SHARD_METRICS_REPORTER_PREFIX + "console." + "period", 5l);
    TimeUnit unit = TimeUnit.valueOf(configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "console." + "unit", "SECONDS").toUpperCase());
    ConsoleReporter.enable(period, unit);
}

17 View Complete Implementation : ReporterSetup.java
Copyright Apache License 2.0
Author : apache
public static void setupReporter(BlurConfiguration configuration, String reporter) {
    reporter = reporter.trim();
    try {
        TYPES type = TYPES.valueOf(reporter.trim());
        switch(type) {
            case ConsoleReporter:
                setupConsoleReporter(configuration);
                return;
            case CsvReporter:
                setupCsvReporter(configuration);
                return;
            case GangliaReporter:
                setupGangliaReporter(configuration);
                return;
            case GraphiteReporter:
                setupGraphiteReporter(configuration);
                return;
            default:
                break;
        }
    } catch (IllegalArgumentException e) {
        LOG.info("Cannot resolve reporter of type [{0}] trying to find clreplaced.", reporter);
        try {
            Clreplaced<?> reporterClazz = Clreplaced.forName(reporter);
            reflectiveSetup(reporterClazz, configuration, reporter);
        } catch (ClreplacedNotFoundException ex) {
            LOG.error("Cannot find clreplaced [{0}]", reporter);
        }
    }
}

17 View Complete Implementation : ReporterSetup.java
Copyright Apache License 2.0
Author : apache
private static void setupGraphiteReporter(BlurConfiguration configuration) {
    long period = configuration.getLong(BLUR_SHARD_METRICS_REPORTER_PREFIX + "graphite." + "period", 5l);
    TimeUnit unit = TimeUnit.valueOf(configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "graphite." + "unit", "SECONDS").toUpperCase());
    String host = configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "graphite." + "host", "localhost");
    int port = configuration.getInt(BLUR_SHARD_METRICS_REPORTER_PREFIX + "graphite." + "port", -1);
    String prefix = configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "graphite." + "prefix", "");
    GraphiteReporter.enable(period, unit, host, port, prefix);
}

17 View Complete Implementation : ReporterSetup.java
Copyright Apache License 2.0
Author : apache
private static void setupGangliaReporter(BlurConfiguration configuration) {
    long period = configuration.getLong(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "period", 5l);
    TimeUnit unit = TimeUnit.valueOf(configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "unit", "SECONDS").toUpperCase());
    String host = configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "host", "localhost");
    int port = configuration.getInt(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "port", -1);
    String prefix = configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "prefix", "");
    boolean compressPackageNames = configuration.getBoolean(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "compressPackageNames", false);
    GangliaReporter.enable(Metrics.defaultRegistry(), period, unit, host, port, prefix, MetricPredicate.ALL, compressPackageNames);
}

16 View Complete Implementation : Config.java
Copyright Apache License 2.0
Author : apache
public clreplaced Config {

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

    private static final Log log = LogFactory.getLog(Config.clreplaced);

    private static final int DEFAULT_PORT = 8080;

    public static final int DEFAULT_REFRESH_TIME = 5000;

    private static int port;

    private static BlurConfiguration blurConfig;

    private static Object cluster;

    private static IAuthenticationProvider authenticationProvider;

    private static IAuthorizationProvider authorizationProvider;

    private static CachingBlurClient cachingBlurClient;

    public static int getConsolePort() {
        return port;
    }

    public static BlurConfiguration getBlurConfig() {
        return blurConfig;
    }

    public static void setupConfig() throws Exception {
        if (cluster == null) {
            blurConfig = new BlurConfiguration();
        } else {
            // in dev mode
            blurConfig = new BlurConfiguration(false);
            setDevelopmentZookeeperConnection();
            setDevelopmentProperties();
        }
        port = blurConfig.getInt("blur.console.port", DEFAULT_PORT);
        cachingBlurClient = new CachingBlurClient(blurConfig.getInt("blur.console.refreshtime", DEFAULT_REFRESH_TIME));
        setupProviders();
    }

    private static void setDevelopmentZookeeperConnection() {
        String zkConnection = "";
        try {
            Method zkMethod = cluster.getClreplaced().getMethod("getZkConnectionString");
            zkConnection = (String) zkMethod.invoke(cluster);
        } catch (Exception e) {
            log.fatal("Unable get zookeeper connection string", e);
        }
        blurConfig.set("blur.zookeeper.connection", zkConnection);
    }

    private static void setDevelopmentProperties() {
        Properties properties = System.getProperties();
        for (String name : properties.stringPropertyNames()) {
            if (name.startsWith("blur.")) {
                blurConfig.set(name, properties.getProperty(name));
            }
        }
    }

    @SuppressWarnings("rawtypes")
    private static void setupProviders() throws Exception {
        String authenticationProviderClreplacedName = blurConfig.get("blur.console.authentication.provider", "org.apache.blur.console.providers.AllAuthenticated");
        String authorizationProviderClreplacedName = blurConfig.get("blur.console.authorization.provider");
        Clreplaced authenticationProviderClreplaced = Clreplaced.forName(authenticationProviderClreplacedName, false, Config.clreplaced.getClreplacedLoader());
        if (authenticationProviderClreplaced == null) {
            authenticationProvider = new AuthenticationDenied();
            log.error("Error in blur.console.authentication.provider: AuthenticationDenied");
        } else {
            authenticationProvider = (IAuthenticationProvider) authenticationProviderClreplaced.newInstance();
            log.info("Using " + authenticationProviderClreplacedName + " for authentication");
            if (authenticationProviderClreplacedName.equals(authorizationProviderClreplacedName)) {
                log.info("authentication and authorization providers are the same, reusing");
                authorizationProvider = (IAuthorizationProvider) authenticationProvider;
            }
        }
        authenticationProvider.setupProvider(blurConfig);
        if (authorizationProvider == null) {
            if (authorizationProviderClreplacedName != null) {
                Clreplaced authorizationProviderClreplaced = Clreplaced.forName(authorizationProviderClreplacedName, false, Config.clreplaced.getClreplacedLoader());
                if (authorizationProviderClreplaced == null) {
                    log.error("Error in blur.console.authorization.provider: EmptyAuthorization");
                    authorizationProvider = new EmptyAuthorization();
                } else {
                    log.info("Using " + authorizationProviderClreplacedName + " for authorization");
                    authorizationProvider = (IAuthorizationProvider) authorizationProviderClreplaced.newInstance();
                }
            } else {
                authorizationProvider = new EmptyAuthorization();
            }
            authorizationProvider.setupProvider(blurConfig);
        }
    }

    public static void shutdownMiniCluster() throws IOException {
        if (cluster != null) {
            try {
                Method method = cluster.getClreplaced().getMethod("shutdownBlurCluster");
                method.invoke(cluster);
            } catch (Exception e) {
                log.fatal("Unable to stop mini cluster through reflection.", e);
            }
            File file = new File(TMPDIR, "blur-cluster-test");
            if (file.exists()) {
                FileUtils.deleteDirectory(file);
            }
            cluster = null;
        }
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static void setupMiniCluster() throws IOException {
        File testDirectory = new File(TMPDIR, "blur-cluster-test").getAbsoluteFile();
        testDirectory.mkdirs();
        testDirectory.delete();
        try {
            Clreplaced clusterClreplaced = Clreplaced.forName("org.apache.blur.MiniCluster", false, Config.clreplaced.getClreplacedLoader());
            if (clusterClreplaced != null) {
                cluster = clusterClreplaced.newInstance();
                Method startBlurCluster = clusterClreplaced.getDeclaredMethod("startBlurCluster", String.clreplaced, int.clreplaced, int.clreplaced, boolean.clreplaced);
                startBlurCluster.invoke(cluster, new File(testDirectory, "cluster").getAbsolutePath(), 2, 3, true);
                Method getControllerConnectionStr = clusterClreplaced.getDeclaredMethod("getControllerConnectionStr");
                String controllerConnectionStr = (String) getControllerConnectionStr.invoke(cluster);
                System.out.println("MiniCluster started at " + controllerConnectionStr);
            }
        } catch (Exception e) {
            log.fatal("Unable to start in dev mode because MiniCluster isn't in clreplacedpath", e);
            cluster = null;
        }
    }

    public static Iface getClient(org.apache.blur.console.model.User user, String securityUser) throws IOException {
        Iface client = BlurClient.getClient(blurConfig);
        Map<String, String> securityAttributes = user.getSecurityAttributes(securityUser);
        if (securityAttributes != null) {
            UserContext.setUser(new User(user.getName(), securityAttributes));
        }
        return client;
    }

    public static int getInt(String name, int defaultValue) {
        return blurConfig.getInt(name, defaultValue);
    }

    public static Iface getClient() {
        return BlurClient.getClient(blurConfig);
    }

    public static CachingBlurClient getCachingBlurClient() {
        return cachingBlurClient;
    }

    public static boolean isClusterSetup() {
        return cluster != null;
    }

    public static IAuthenticationProvider getAuthenticationProvider() {
        return authenticationProvider;
    }

    public static IAuthorizationProvider getAuthorizationProvider() {
        return authorizationProvider;
    }
}