Java Code Examples for com.thinkaurelius.titan.diskstorage.configuration.ConfigOption

The following are top voted examples for showing how to use com.thinkaurelius.titan.diskstorage.configuration.ConfigOption. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: titan1withtp3.1   File: BerkeleyJEStoreManager.java   View source code 6 votes vote down vote up
@Override
public BerkeleyJETx beginTransaction(final BaseTransactionConfig txCfg) throws BackendException {
    try {
        Transaction tx = null;

        Configuration effectiveCfg =
                new MergedConfiguration(txCfg.getCustomOptions(), getStorageConfig());

        if (transactional) {
            TransactionConfig txnConfig = new TransactionConfig();
            ConfigOption.getEnumValue(effectiveCfg.get(ISOLATION_LEVEL),IsolationLevel.class).configure(txnConfig);
            tx = environment.beginTransaction(null, txnConfig);
        }
        BerkeleyJETx btx = new BerkeleyJETx(tx, ConfigOption.getEnumValue(effectiveCfg.get(LOCK_MODE),LockMode.class), txCfg);

        if (log.isTraceEnabled()) {
            log.trace("Berkeley tx created", new TransactionBegin(btx.toString()));
        }

        return btx;
    } catch (DatabaseException e) {
        throw new PermanentBackendException("Could not start BerkeleyJE transaction", e);
    }
}
 
Example 2
Project: titan1withtp3.1   File: ConfigurationPrinter.java   View source code 6 votes vote down vote up
private void printNamespace(ConfigNamespace n, String prefix) {
    String newPrefix = prefix + n.getName() + ".";
    if (n.isUmbrella()) newPrefix += "[X].";

    if (n.isRoot()) newPrefix = ""; //Override for root namespace

    //Only print namespace if it contains (visible) options
    if (!Iterables.isEmpty(getSortedChildOptions(n))) {
        stream.println(getNamespaceSectionHeader(n, prefix));
        stream.println(getTableHeader());
        for (ConfigOption<?> o : getSortedChildOptions(n)) {
            stream.println(getTableLineForOption(o, newPrefix));
        }
        stream.println(TABLE_FOOTER_LINES);
    }

    for (ConfigNamespace cn : getSortedChildNamespaces(n)) {
        printNamespace(cn, newPrefix);
    }
}
 
Example 3
Project: titan1.0.1.kafka   File: BerkeleyJEStoreManager.java   View source code 6 votes vote down vote up
@Override
public BerkeleyJETx beginTransaction(final BaseTransactionConfig txCfg) throws BackendException {
    try {
        Transaction tx = null;

        Configuration effectiveCfg =
                new MergedConfiguration(txCfg.getCustomOptions(), getStorageConfig());

        if (transactional) {
            TransactionConfig txnConfig = new TransactionConfig();
            ConfigOption.getEnumValue(effectiveCfg.get(ISOLATION_LEVEL),IsolationLevel.class).configure(txnConfig);
            tx = environment.beginTransaction(null, txnConfig);
        }
        BerkeleyJETx btx = new BerkeleyJETx(tx, ConfigOption.getEnumValue(effectiveCfg.get(LOCK_MODE),LockMode.class), txCfg);

        if (log.isTraceEnabled()) {
            log.trace("Berkeley tx created", new TransactionBegin(btx.toString()));
        }

        return btx;
    } catch (DatabaseException e) {
        throw new PermanentBackendException("Could not start BerkeleyJE transaction", e);
    }
}
 
Example 4
Project: titan1.0.1.kafka   File: ConfigurationPrinter.java   View source code 6 votes vote down vote up
private void printNamespace(ConfigNamespace n, String prefix) {
    String newPrefix = prefix + n.getName() + ".";
    if (n.isUmbrella()) newPrefix += "[X].";

    if (n.isRoot()) newPrefix = ""; //Override for root namespace

    //Only print namespace if it contains (visible) options
    if (!Iterables.isEmpty(getSortedChildOptions(n))) {
        stream.println(getNamespaceSectionHeader(n, prefix));
        stream.println(getTableHeader());
        for (ConfigOption<?> o : getSortedChildOptions(n)) {
            stream.println(getTableLineForOption(o, newPrefix));
        }
        stream.println(TABLE_FOOTER_LINES);
    }

    for (ConfigNamespace cn : getSortedChildNamespaces(n)) {
        printNamespace(cn, newPrefix);
    }
}
 
Example 5
Project: titan0.5.4-hbase1.1.1-custom   File: ConfigurationPrinter.java   View source code 6 votes vote down vote up
private void printNamespace(ConfigNamespace n, String prefix) {
    String newPrefix = prefix + n.getName() + ".";
    if (n.isUmbrella()) newPrefix += "[X].";

    if (n.isRoot()) newPrefix = ""; //Override for root namespace

    //Only print namespace if it contains (visible) options
    if (!Iterables.isEmpty(getSortedChildOptions(n))) {
        stream.println(getNamespaceSectionHeader(n, prefix));
        stream.println(getTableHeader());
        for (ConfigOption<?> o : getSortedChildOptions(n)) {
            stream.println(getTableLineForOption(o, newPrefix));
        }
        stream.println(TABLE_FOOTER_LINES);
    }

    for (ConfigNamespace cn : getSortedChildNamespaces(n)) {
        printNamespace(cn, newPrefix);
    }
}
 
Example 6
Project: titan1withtp3.1   File: BerkeleyGraphTest.java   View source code 5 votes vote down vote up
@Override
public void testConsistencyEnforcement() {
    // Check that getConfiguration() explicitly set serializable isolation
    // This could be enforced with a JUnit assertion instead of a Precondition,
    // but a failure here indicates a problem in the test itself rather than the
    // system-under-test, so a Precondition seems more appropriate
    IsolationLevel effective = ConfigOption.getEnumValue(config.get(ConfigElement.getPath(BerkeleyJEStoreManager.ISOLATION_LEVEL), String.class),IsolationLevel.class);
    Preconditions.checkState(IsolationLevel.SERIALIZABLE.equals(effective));
    super.testConsistencyEnforcement();
}
 
Example 7
Project: titan1withtp3.1   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private String getFullPath(ConfigOption<?> opt) {
    StringBuilder sb = new StringBuilder(64);
    sb.insert(0, opt.getName());
    for (ConfigNamespace parent = opt.getNamespace();
         null != parent && !parent.isRoot();
         parent = parent.getNamespace()) {
        if (parent.isUmbrella())
            sb.insert(0, "[X].");
        sb.insert(0, ".");
        sb.insert(0, parent.getName());
    }
    return sb.toString();
}
 
Example 8
Project: titan1withtp3.1   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private List<ConfigOption<?>> getSortedChildOptions(ConfigNamespace n) {
    return getSortedChildren(n, new Function<ConfigElement, Boolean>() {
        @Override
        public Boolean apply(ConfigElement arg0) {
            return arg0.isOption() && !((ConfigOption)arg0).isHidden();
        }
    });
}
 
Example 9
Project: titan1withtp3.1   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private String getTableLineForOption(ConfigOption o, String prefix) {

        List<String> colData = new ArrayList<String>(10);
        String name = prefix + o.getName();
        if (o.isDeprecated()) {
            ConfigOption<?> successor = o.getDeprecationReplacement();
            if (null == successor) {
                name = "[deprecation-warning]*Deprecated* [line-through]#" + name + "#";
            } else {
                name = "[deprecation-warning]*Deprecated.  See " + getFullPath(successor) + "* [line-through]#" + name + "#";
            }

        }
        colData.add(name);
        colData.add(removeDelim(o.getDescription()));
        colData.add(o.getDatatype().getSimpleName());
        colData.add(removeDelim(getStringForDefaultValue(o)));

        if (showMutability)
            colData.add(o.getType().toString());

        String line = Joiner.on(DELIM_PADDING + DELIM + DELIM_PADDING).join(colData);

        if (DELIM_AT_LINE_START) {
            line = DELIM + DELIM_PADDING + line;
        }

        if (DELIM_AT_LINE_END) {
            line = line + DELIM_PADDING + DELIM;
        }

        return line;
    }
 
Example 10
Project: titan1withtp3.1   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private String getStringForDefaultValue(ConfigOption<?> c) {
    Object o = c.getDefaultValue();

    if (null == o) {
        return "(no default value)";
    } else if (o instanceof Duration) {
        Duration d = (Duration)o;
        return d.toMillis() + " ms";
    } else if (o instanceof String[]) {
        return Joiner.on(",").join((String[])o);
    }

    return o.toString();
}
 
Example 11
Project: titan1.0.1.kafka   File: BerkeleyGraphTest.java   View source code 5 votes vote down vote up
@Override
public void testConsistencyEnforcement() {
    // Check that getConfiguration() explicitly set serializable isolation
    // This could be enforced with a JUnit assertion instead of a Precondition,
    // but a failure here indicates a problem in the test itself rather than the
    // system-under-test, so a Precondition seems more appropriate
    IsolationLevel effective = ConfigOption.getEnumValue(config.get(ConfigElement.getPath(BerkeleyJEStoreManager.ISOLATION_LEVEL), String.class),IsolationLevel.class);
    Preconditions.checkState(IsolationLevel.SERIALIZABLE.equals(effective));
    super.testConsistencyEnforcement();
}
 
Example 12
Project: titan1.0.1.kafka   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private String getFullPath(ConfigOption<?> opt) {
    StringBuilder sb = new StringBuilder(64);
    sb.insert(0, opt.getName());
    for (ConfigNamespace parent = opt.getNamespace();
         null != parent && !parent.isRoot();
         parent = parent.getNamespace()) {
        if (parent.isUmbrella())
            sb.insert(0, "[X].");
        sb.insert(0, ".");
        sb.insert(0, parent.getName());
    }
    return sb.toString();
}
 
Example 13
Project: titan1.0.1.kafka   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private List<ConfigOption<?>> getSortedChildOptions(ConfigNamespace n) {
    return getSortedChildren(n, new Function<ConfigElement, Boolean>() {
        @Override
        public Boolean apply(ConfigElement arg0) {
            return arg0.isOption() && !((ConfigOption)arg0).isHidden();
        }
    });
}
 
Example 14
Project: titan1.0.1.kafka   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private String getTableLineForOption(ConfigOption o, String prefix) {

        List<String> colData = new ArrayList<String>(10);
        String name = prefix + o.getName();
        if (o.isDeprecated()) {
            ConfigOption<?> successor = o.getDeprecationReplacement();
            if (null == successor) {
                name = "[deprecation-warning]*Deprecated* [line-through]#" + name + "#";
            } else {
                name = "[deprecation-warning]*Deprecated.  See " + getFullPath(successor) + "* [line-through]#" + name + "#";
            }

        }
        colData.add(name);
        colData.add(removeDelim(o.getDescription()));
        colData.add(o.getDatatype().getSimpleName());
        colData.add(removeDelim(getStringForDefaultValue(o)));

        if (showMutability)
            colData.add(o.getType().toString());

        String line = Joiner.on(DELIM_PADDING + DELIM + DELIM_PADDING).join(colData);

        if (DELIM_AT_LINE_START) {
            line = DELIM + DELIM_PADDING + line;
        }

        if (DELIM_AT_LINE_END) {
            line = line + DELIM_PADDING + DELIM;
        }

        return line;
    }
 
Example 15
Project: titan1.0.1.kafka   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private String getStringForDefaultValue(ConfigOption<?> c) {
    Object o = c.getDefaultValue();

    if (null == o) {
        return "(no default value)";
    } else if (o instanceof Duration) {
        Duration d = (Duration)o;
        return d.toMillis() + " ms";
    } else if (o instanceof String[]) {
        return Joiner.on(",").join((String[])o);
    }

    return o.toString();
}
 
Example 16
Project: titan0.5.4-hbase1.1.1-custom   File: ModifiableHadoopConfiguration.java   View source code 5 votes vote down vote up
@Override
public<O> ModifiableConfiguration set(ConfigOption<O> option, O value, String... umbrellaElements) {
    if (TitanHadoopConfiguration.PIPELINE_TRACK_PATHS == option) {
        trackPaths = null;
    } else if (TitanHadoopConfiguration.PIPELINE_TRACK_STATE == option) {
        trackState = null;
    }
    return super.set(option, value, umbrellaElements);
}
 
Example 17
Project: titan0.5.4-hbase1.1.1-custom   File: ModifiableHadoopConfiguration.java   View source code 5 votes vote down vote up
public void setAllOutput(Map<ConfigElement.PathIdentifier, Object> entries) {
    ModifiableConfiguration out = getOutputConf();
    for (Map.Entry<ConfigElement.PathIdentifier,Object> entry : entries.entrySet()) {
        Preconditions.checkArgument(entry.getKey().element.isOption());
        out.set((ConfigOption) entry.getKey().element, entry.getValue(), entry.getKey().umbrellaElements);
    }
}
 
Example 18
Project: titan0.5.4-hbase1.1.1-custom   File: ModifiableHadoopConfiguration.java   View source code 5 votes vote down vote up
public void setAllInput(Map<ConfigElement.PathIdentifier, Object> entries) {
    ModifiableConfiguration in = getInputConf();
    for (Map.Entry<ConfigElement.PathIdentifier,Object> entry : entries.entrySet()) {
        Preconditions.checkArgument(entry.getKey().element.isOption());
        in.set((ConfigOption) entry.getKey().element, entry.getValue(), entry.getKey().umbrellaElements);
    }
}
 
Example 19
Project: titan0.5.4-hbase1.1.1-custom   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private String getFullPath(ConfigOption<?> opt) {
    StringBuilder sb = new StringBuilder(64);
    sb.insert(0, opt.getName());
    for (ConfigNamespace parent = opt.getNamespace();
         null != parent && !parent.isRoot();
         parent = parent.getNamespace()) {
        if (parent.isUmbrella())
            sb.insert(0, "[X].");
        sb.insert(0, ".");
        sb.insert(0, parent.getName());
    }
    return sb.toString();
}
 
Example 20
Project: titan0.5.4-hbase1.1.1-custom   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private List<ConfigOption<?>> getSortedChildOptions(ConfigNamespace n) {
    return getSortedChildren(n, new Function<ConfigElement, Boolean>() {
        @Override
        public Boolean apply(ConfigElement arg0) {
            return arg0.isOption() && !((ConfigOption)arg0).isHidden();
        }
    });
}
 
Example 21
Project: titan0.5.4-hbase1.1.1-custom   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private String getTableLineForOption(ConfigOption o, String prefix) {

        List<String> colData = new ArrayList<String>(10);
        String name = prefix + o.getName();
        if (o.isDeprecated()) {
            ConfigOption<?> successor = o.getDeprecationReplacement();
            if (null == successor) {
                name = "[deprecation-warning]*Deprecated* [line-through]#" + name + "#";
            } else {
                name = "[deprecation-warning]*Deprecated.  See " + getFullPath(successor) + "* [line-through]#" + name + "#";
            }

        }
        colData.add(name);
        colData.add(removeDelim(o.getDescription()));
        colData.add(o.getDatatype().getSimpleName());
        colData.add(removeDelim(getStringForDefaultValue(o)));

        if (showMutability)
            colData.add(o.getType().toString());

        String line = Joiner.on(DELIM_PADDING + DELIM + DELIM_PADDING).join(colData);

        if (DELIM_AT_LINE_START) {
            line = DELIM + DELIM_PADDING + line;
        }

        if (DELIM_AT_LINE_END) {
            line = line + DELIM_PADDING + DELIM;
        }

        return line;
    }
 
Example 22
Project: titan0.5.4-hbase1.1.1-custom   File: ConfigurationPrinter.java   View source code 5 votes vote down vote up
private String getStringForDefaultValue(ConfigOption<?> c) {
    Object o = c.getDefaultValue();

    if (null == o) {
        return "(no default value)";
    } else if (o instanceof Duration) {
        Duration d = (Duration)o;
        return d.getLength(TimeUnit.MILLISECONDS) + " ms";
    } else if (o instanceof String[]) {
        return Joiner.on(",").join((String[])o);
    }

    return o.toString();
}
 
Example 23
Project: titan1withtp3.1   File: CassandraThriftStoreManager.java   View source code 4 votes vote down vote up
public CassandraThriftStoreManager(Configuration config) throws BackendException {
    super(config);

    /*
     * This is eventually passed to Thrift's TSocket constructor. The
     * constructor parameter is of type int.
     */
    int thriftTimeoutMS = (int)config.get(GraphDatabaseConfiguration.CONNECTION_TIMEOUT).toMillis();

    CTConnectionFactory.Config factoryConfig = new CTConnectionFactory.Config(hostnames, port, username, password)
                                                                        .setTimeoutMS(thriftTimeoutMS)
                                                                        .setFrameSize(thriftFrameSizeBytes);

    if (config.get(SSL_ENABLED)) {
        factoryConfig.setSSLTruststoreLocation(config.get(SSL_TRUSTSTORE_LOCATION));
        factoryConfig.setSSLTruststorePassword(config.get(SSL_TRUSTSTORE_PASSWORD));
    }

    final PoolExhaustedAction poolExhaustedAction = ConfigOption.getEnumValue(
            config.get(CPOOL_WHEN_EXHAUSTED), PoolExhaustedAction.class);

    CTConnectionPool p = new CTConnectionPool(factoryConfig.build());
    p.setTestOnBorrow(true);
    p.setTestOnReturn(true);
    p.setTestWhileIdle(config.get(CPOOL_IDLE_TESTS));
    p.setNumTestsPerEvictionRun(config.get(CPOOL_IDLE_TESTS_PER_EVICTION_RUN));
    p.setWhenExhaustedAction(poolExhaustedAction.getByte());
    p.setMaxActive(config.get(CPOOL_MAX_ACTIVE));
    p.setMaxTotal(config.get(CPOOL_MAX_TOTAL)); // maxTotal limits active + idle
    p.setMaxIdle(config.get(CPOOL_MAX_IDLE));
    p.setMinIdle(config.get(CPOOL_MIN_IDLE));
    p.setMaxWait(config.get(CPOOL_MAX_WAIT));
    p.setTimeBetweenEvictionRunsMillis(config.get(CPOOL_EVICTOR_PERIOD));
    p.setMinEvictableIdleTimeMillis(config.get(CPOOL_MIN_EVICTABLE_IDLE_TIME));
    this.pool = p;

    this.openStores = new HashMap<String, CassandraThriftKeyColumnValueStore>();

    // Only watch the ring and change endpoints with BOP
    if (getCassandraPartitioner() instanceof ByteOrderedPartitioner) {
        deployment = (hostnames.length == 1)// mark deployment as local only in case we have byte ordered partitioner and local connection
                      ? (NetworkUtil.isLocalConnection(hostnames[0])) ? Deployment.LOCAL : Deployment.REMOTE
                      : Deployment.REMOTE;
    } else {
        deployment = Deployment.REMOTE;
    }
}
 
Example 24
Project: titan1withtp3.1   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testLocalGraphConfiguration() {
    setIllegalGraphOption(STORAGE_READONLY, ConfigOption.Type.LOCAL, true);
}
 
Example 25
Project: titan1withtp3.1   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testMaskableGraphConfig() {
    setAndCheckGraphOption(DB_CACHE, ConfigOption.Type.MASKABLE, true, false);
}
 
Example 26
Project: titan1withtp3.1   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testGlobalGraphConfig() {
    setAndCheckGraphOption(SYSTEM_LOG_TRANSACTIONS, ConfigOption.Type.GLOBAL, true, false);
}
 
Example 27
Project: titan1withtp3.1   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testGlobalOfflineGraphConfig() {
    setAndCheckGraphOption(DB_CACHE_TIME, ConfigOption.Type.GLOBAL_OFFLINE, 500L, 777L);
}
 
Example 28
Project: titan1withtp3.1   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testFixedGraphConfig() {
    setIllegalGraphOption(INITIAL_TITAN_VERSION, ConfigOption.Type.FIXED, "foo");
}
 
Example 29
Project: titan1withtp3.1   File: TitanGraphTest.java   View source code 4 votes vote down vote up
private <T> void setAndCheckGraphOption(ConfigOption<T> opt, ConfigOption.Type requiredType, T firstValue, T secondValue) {
    // Sanity check: make sure the Type of the configoption is what we expect
    Preconditions.checkState(opt.getType().equals(requiredType));
    final EnumSet<ConfigOption.Type> allowedTypes =
            EnumSet.of(ConfigOption.Type.GLOBAL,
                    ConfigOption.Type.GLOBAL_OFFLINE,
                    ConfigOption.Type.MASKABLE);
    Preconditions.checkState(allowedTypes.contains(opt.getType()));

    // Sanity check: it's kind of pointless for the first and second values to be identical
    Preconditions.checkArgument(!firstValue.equals(secondValue));

    // Get full string path of config option
    final String path = ConfigElement.getPath(opt);

    // Set and check initial value before and after database restart
    mgmt.set(path, firstValue);
    assertEquals(firstValue.toString(), mgmt.get(path));
    // Close open tx first.  This is specific to BDB + GLOBAL_OFFLINE.
    // Basically: the BDB store manager throws a fit if shutdown is called
    // with one or more transactions still open, and GLOBAL_OFFLINE calls
    // shutdown on our behalf when we commit this change.
    tx.rollback();
    mgmt.commit();
    clopen();
    // Close tx again following clopen
    tx.rollback();
    assertEquals(firstValue.toString(), mgmt.get(path));

    // Set and check updated value before and after database restart
    mgmt.set(path, secondValue);
    assertEquals(secondValue.toString(), mgmt.get(path));
    mgmt.commit();
    clopen();
    tx.rollback();
    assertEquals(secondValue.toString(), mgmt.get(path));

    // Open a separate graph "g2"
    TitanGraph g2 = TitanFactory.open(config);
    TitanManagement m2 = g2.openManagement();
    assertEquals(secondValue.toString(), m2.get(path));

    // GLOBAL_OFFLINE options should be unmodifiable with g2 open
    if (opt.getType().equals(ConfigOption.Type.GLOBAL_OFFLINE)) {
        try {
            mgmt.set(path, firstValue);
            mgmt.commit();
            fail("Option " + path + " with type " + ConfigOption.Type.GLOBAL_OFFLINE + " should not be modifiable with concurrent instances");
        } catch (RuntimeException e) {
            log.debug("Caught expected exception", e);
        }
        assertEquals(secondValue.toString(), mgmt.get(path));
        // GLOBAL and MASKABLE should be modifiable even with g2 open
    } else {
        mgmt.set(path, firstValue);
        assertEquals(firstValue.toString(), mgmt.get(path));
        mgmt.commit();
        clopen();
        assertEquals(firstValue.toString(), mgmt.get(path));
    }

    m2.rollback();
    g2.close();
}
 
Example 30
Project: titan1withtp3.1   File: InMemoryConfigurationTest.java   View source code 4 votes vote down vote up
public void initialize(ConfigOption option, Object value) {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    config.set(option,value);
    graph = (StandardTitanGraph) TitanFactory.open(config);
}
 
Example 31
Project: titan1withtp3.1   File: StandardBaseTransactionConfig.java   View source code 4 votes vote down vote up
@Override
public <V> V getCustomOption(ConfigOption<V> opt) {
    return customOptions.get(opt);
}
 
Example 32
Project: titan1.0.1.kafka   File: CassandraThriftStoreManager.java   View source code 4 votes vote down vote up
public CassandraThriftStoreManager(Configuration config) throws BackendException {
    super(config);

    /*
     * This is eventually passed to Thrift's TSocket constructor. The
     * constructor parameter is of type int.
     */
    int thriftTimeoutMS = (int)config.get(GraphDatabaseConfiguration.CONNECTION_TIMEOUT).toMillis();

    CTConnectionFactory.Config factoryConfig = new CTConnectionFactory.Config(hostnames, port, username, password)
                                                                        .setTimeoutMS(thriftTimeoutMS)
                                                                        .setFrameSize(thriftFrameSizeBytes);

    if (config.get(SSL_ENABLED)) {
        factoryConfig.setSSLTruststoreLocation(config.get(SSL_TRUSTSTORE_LOCATION));
        factoryConfig.setSSLTruststorePassword(config.get(SSL_TRUSTSTORE_PASSWORD));
    }

    final PoolExhaustedAction poolExhaustedAction = ConfigOption.getEnumValue(
            config.get(CPOOL_WHEN_EXHAUSTED), PoolExhaustedAction.class);

    CTConnectionPool p = new CTConnectionPool(factoryConfig.build());
    p.setTestOnBorrow(true);
    p.setTestOnReturn(true);
    p.setTestWhileIdle(config.get(CPOOL_IDLE_TESTS));
    p.setNumTestsPerEvictionRun(config.get(CPOOL_IDLE_TESTS_PER_EVICTION_RUN));
    p.setWhenExhaustedAction(poolExhaustedAction.getByte());
    p.setMaxActive(config.get(CPOOL_MAX_ACTIVE));
    p.setMaxTotal(config.get(CPOOL_MAX_TOTAL)); // maxTotal limits active + idle
    p.setMaxIdle(config.get(CPOOL_MAX_IDLE));
    p.setMinIdle(config.get(CPOOL_MIN_IDLE));
    p.setMaxWait(config.get(CPOOL_MAX_WAIT));
    p.setTimeBetweenEvictionRunsMillis(config.get(CPOOL_EVICTOR_PERIOD));
    p.setMinEvictableIdleTimeMillis(config.get(CPOOL_MIN_EVICTABLE_IDLE_TIME));
    this.pool = p;

    this.openStores = new HashMap<String, CassandraThriftKeyColumnValueStore>();

    // Only watch the ring and change endpoints with BOP
    if (getCassandraPartitioner() instanceof ByteOrderedPartitioner) {
        deployment = (hostnames.length == 1)// mark deployment as local only in case we have byte ordered partitioner and local connection
                      ? (NetworkUtil.isLocalConnection(hostnames[0])) ? Deployment.LOCAL : Deployment.REMOTE
                      : Deployment.REMOTE;
    } else {
        deployment = Deployment.REMOTE;
    }
}
 
Example 33
Project: titan1.0.1.kafka   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testLocalGraphConfiguration() {
    setIllegalGraphOption(STORAGE_READONLY, ConfigOption.Type.LOCAL, true);
}
 
Example 34
Project: titan1.0.1.kafka   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testMaskableGraphConfig() {
    setAndCheckGraphOption(DB_CACHE, ConfigOption.Type.MASKABLE, true, false);
}
 
Example 35
Project: titan1.0.1.kafka   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testGlobalGraphConfig() {
    setAndCheckGraphOption(SYSTEM_LOG_TRANSACTIONS, ConfigOption.Type.GLOBAL, true, false);
}
 
Example 36
Project: titan1.0.1.kafka   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testGlobalOfflineGraphConfig() {
    setAndCheckGraphOption(DB_CACHE_TIME, ConfigOption.Type.GLOBAL_OFFLINE, 500L, 777L);
}
 
Example 37
Project: titan1.0.1.kafka   File: TitanGraphTest.java   View source code 4 votes vote down vote up
@Test
public void testFixedGraphConfig() {
    setIllegalGraphOption(INITIAL_TITAN_VERSION, ConfigOption.Type.FIXED, "foo");
}
 
Example 38
Project: titan1.0.1.kafka   File: TitanGraphTest.java   View source code 4 votes vote down vote up
private <T> void setAndCheckGraphOption(ConfigOption<T> opt, ConfigOption.Type requiredType, T firstValue, T secondValue) {
    // Sanity check: make sure the Type of the configoption is what we expect
    Preconditions.checkState(opt.getType().equals(requiredType));
    final EnumSet<ConfigOption.Type> allowedTypes =
            EnumSet.of(ConfigOption.Type.GLOBAL,
                    ConfigOption.Type.GLOBAL_OFFLINE,
                    ConfigOption.Type.MASKABLE);
    Preconditions.checkState(allowedTypes.contains(opt.getType()));

    // Sanity check: it's kind of pointless for the first and second values to be identical
    Preconditions.checkArgument(!firstValue.equals(secondValue));

    // Get full string path of config option
    final String path = ConfigElement.getPath(opt);

    // Set and check initial value before and after database restart
    mgmt.set(path, firstValue);
    assertEquals(firstValue.toString(), mgmt.get(path));
    // Close open tx first.  This is specific to BDB + GLOBAL_OFFLINE.
    // Basically: the BDB store manager throws a fit if shutdown is called
    // with one or more transactions still open, and GLOBAL_OFFLINE calls
    // shutdown on our behalf when we commit this change.
    tx.rollback();
    mgmt.commit();
    clopen();
    // Close tx again following clopen
    tx.rollback();
    assertEquals(firstValue.toString(), mgmt.get(path));

    // Set and check updated value before and after database restart
    mgmt.set(path, secondValue);
    assertEquals(secondValue.toString(), mgmt.get(path));
    mgmt.commit();
    clopen();
    tx.rollback();
    assertEquals(secondValue.toString(), mgmt.get(path));

    // Open a separate graph "g2"
    TitanGraph g2 = TitanFactory.open(config);
    TitanManagement m2 = g2.openManagement();
    assertEquals(secondValue.toString(), m2.get(path));

    // GLOBAL_OFFLINE options should be unmodifiable with g2 open
    if (opt.getType().equals(ConfigOption.Type.GLOBAL_OFFLINE)) {
        try {
            mgmt.set(path, firstValue);
            mgmt.commit();
            fail("Option " + path + " with type " + ConfigOption.Type.GLOBAL_OFFLINE + " should not be modifiable with concurrent instances");
        } catch (RuntimeException e) {
            log.debug("Caught expected exception", e);
        }
        assertEquals(secondValue.toString(), mgmt.get(path));
        // GLOBAL and MASKABLE should be modifiable even with g2 open
    } else {
        mgmt.set(path, firstValue);
        assertEquals(firstValue.toString(), mgmt.get(path));
        mgmt.commit();
        clopen();
        assertEquals(firstValue.toString(), mgmt.get(path));
    }

    m2.rollback();
    g2.close();
}
 
Example 39
Project: titan1.0.1.kafka   File: InMemoryConfigurationTest.java   View source code 4 votes vote down vote up
public void initialize(ConfigOption option, Object value) {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    config.set(option,value);
    graph = (StandardTitanGraph) TitanFactory.open(config);
}
 
Example 40
Project: titan1.0.1.kafka   File: StandardBaseTransactionConfig.java   View source code 4 votes vote down vote up
@Override
public <V> V getCustomOption(ConfigOption<V> opt) {
    return customOptions.get(opt);
}