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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 4 votes vote down vote up
@Override
public <V> V getCustomOption(ConfigOption<V> opt) {
    return customOptions.get(opt);
}
 
Example 41
Project: titan0.5.4-hbase1.1.1-custom   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testLocalGraphConfiguration() {
    setIllegalGraphOption(STORAGE_READONLY, ConfigOption.Type.LOCAL, true);
}
 
Example 42
Project: titan0.5.4-hbase1.1.1-custom   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testMaskableGraphConfig() {
    setAndCheckGraphOption(DB_CACHE, ConfigOption.Type.MASKABLE, true, false);
}
 
Example 43
Project: titan0.5.4-hbase1.1.1-custom   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testGlobalGraphConfig() {
    setAndCheckGraphOption(SYSTEM_LOG_TRANSACTIONS, ConfigOption.Type.GLOBAL, true, false);
}
 
Example 44
Project: titan0.5.4-hbase1.1.1-custom   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testGlobalOfflineGraphConfig() {
    setAndCheckGraphOption(DB_CACHE_TIME, ConfigOption.Type.GLOBAL_OFFLINE, 500L, 777L);
}
 
Example 45
Project: titan0.5.4-hbase1.1.1-custom   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testFixedGraphConfig() {
    setIllegalGraphOption(INITIAL_TITAN_VERSION, ConfigOption.Type.FIXED, "foo");
}
 
Example 46
Project: titan0.5.4-hbase1.1.1-custom   File: TitanGraphTest.java   Source Code and License 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.getManagementSystem();
    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.shutdown();
}
 
Example 47
Project: titan0.5.4-hbase1.1.1-custom   File: ModifiableHadoopConfiguration.java   Source Code and License 4 votes vote down vote up
public Class<?> getClass(ConfigOption<String> opt, Class<?> cls) {
    return conf.getClass(ConfigElement.getPath(opt), cls);
}
 
Example 48
Project: titan0.5.4-hbase1.1.1-custom   File: ModifiableHadoopConfiguration.java   Source Code and License 4 votes vote down vote up
public <T> Class<? extends T> getClass(ConfigOption<String> opt,  Class<? extends T> defaultValue, Class<T> iface) {
    return conf.getClass(ConfigElement.getPath(opt), defaultValue, iface);
}
 
Example 49
Project: titan0.5.4-hbase1.1.1-custom   File: ModifiableHadoopConfiguration.java   Source Code and License 4 votes vote down vote up
public void setClass(ConfigOption<String> opt, Class<?> cls, Class<?> iface) {
    conf.setClass(ConfigElement.getPath(opt), cls, iface);
}
 
Example 50
Project: titan0.5.4-hbase1.1.1-custom   File: StandardBaseTransactionConfig.java   Source Code and License 4 votes vote down vote up
@Override
public <V> V getCustomOption(ConfigOption<V> opt) {
    return customOptions.get(opt);
}
 
Example 51
Project: titan1withtp3.1   File: ElasticSearchIndex.java   Source Code and License 3 votes vote down vote up
/**
 * Configure ElasticSearchIndex's ES client according to semantics introduced in
 * 0.5.1.  Allows greater flexibility than the previous config semantics.  See
 * {@link com.thinkaurelius.titan.diskstorage.es.ElasticSearchSetup} for more
 * information.
 * <p>
 * This is activated by setting an explicit value for {@link #INTERFACE} in
 * the Titan configuration.
 *
 * @see #legacyConfiguration(com.thinkaurelius.titan.diskstorage.configuration.Configuration)
 * @param config a config passed to ElasticSearchIndex's constructor
 * @return a node and client object open and ready for use
 */
private ElasticSearchSetup.Connection interfaceConfiguration(Configuration config) {
    ElasticSearchSetup clientMode = ConfigOption.getEnumValue(config.get(INTERFACE), ElasticSearchSetup.class);

    try {
        return clientMode.connect(config);
    } catch (IOException e) {
        throw new TitanException(e);
    }
}
 
Example 52
Project: titan1.0.1.kafka   File: ElasticSearchIndex.java   Source Code and License 3 votes vote down vote up
/**
 * Configure ElasticSearchIndex's ES client according to semantics introduced in
 * 0.5.1.  Allows greater flexibility than the previous config semantics.  See
 * {@link com.thinkaurelius.titan.diskstorage.es.ElasticSearchSetup} for more
 * information.
 * <p>
 * This is activated by setting an explicit value for {@link #INTERFACE} in
 * the Titan configuration.
 *
 * @see #legacyConfiguration(com.thinkaurelius.titan.diskstorage.configuration.Configuration)
 * @param config a config passed to ElasticSearchIndex's constructor
 * @return a node and client object open and ready for use
 */
private ElasticSearchSetup.Connection interfaceConfiguration(Configuration config) {
    ElasticSearchSetup clientMode = ConfigOption.getEnumValue(config.get(INTERFACE), ElasticSearchSetup.class);

    try {
        return clientMode.connect(config);
    } catch (IOException e) {
        throw new TitanException(e);
    }
}
 
Example 53
Project: titan1withtp3.1   File: BaseTransactionConfig.java   Source Code and License 2 votes vote down vote up
/**
 * Get an arbitrary transaction-specific option.
 *
 * @param opt option for which to return a value
 * @return value of the option
 */
public <V> V getCustomOption(ConfigOption<V> opt);
 
Example 54
Project: titan1.0.1.kafka   File: BaseTransactionConfig.java   Source Code and License 2 votes vote down vote up
/**
 * Get an arbitrary transaction-specific option.
 *
 * @param opt option for which to return a value
 * @return value of the option
 */
public <V> V getCustomOption(ConfigOption<V> opt);
 
Example 55
Project: titan0.5.4-hbase1.1.1-custom   File: BaseTransactionConfig.java   Source Code and License 2 votes vote down vote up
/**
 * Get an arbitrary transaction-specific option.
 *
 * @param opt option for which to return a value
 * @return value of the option
 */
public <V> V getCustomOption(ConfigOption<V> opt);