use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class ElasticSearchConfigTest method testExternalMappingsViaTemplate.
@Test
public void testExternalMappingsViaTemplate() throws Exception {
final Duration maxWrite = Duration.ofMillis(2000L);
final String storeName = "test_mapping";
final Configuration indexConfig = GraphDatabaseConfiguration.buildGraphConfiguration().set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME).restrictTo(INDEX_NAME);
final IndexProvider idx = open(indexConfig);
final ElasticMajorVersion version = ((ElasticSearchIndex) idx).getVersion();
final HttpPut newTemplate = new HttpPut("_template/template_1");
final Map<String, Object> content = ImmutableMap.of("template", "janusgraph_test_mapping*", "mappings", readMapping(version, "/strict_mapping.json").getMappings());
newTemplate.setEntity(new StringEntity(objectMapper.writeValueAsString(content), Charset.forName("UTF-8")));
executeRequest(newTemplate);
final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
executeRequest(newMapping);
final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD));
final BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
final IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
// Test date property OK
idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
// Test weight property KO
try {
idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
fail("should fail");
} catch (final BackendException ignored) {
}
itx.rollback();
idx.close();
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class AstyanaxStoreManager method getRetryPolicy.
private static RetryPolicy getRetryPolicy(String serializedRetryPolicy) throws BackendException {
String[] tokens = serializedRetryPolicy.split(",");
String policyClassName = tokens[0];
int argCount = tokens.length - 1;
Integer[] args = new Integer[argCount];
for (int i = 1; i < tokens.length; i++) {
args[i - 1] = Integer.valueOf(tokens[i]);
}
try {
RetryPolicy rp = instantiate(policyClassName, args, serializedRetryPolicy);
log.debug("Instantiated RetryPolicy object {} from config string \"{}\"", rp, serializedRetryPolicy);
return rp;
} catch (Exception e) {
throw new PermanentBackendException("Failed to instantiate Astyanax Retry Policy class", e);
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class CassandraThriftStoreManager method ensureColumnFamilyExists.
private void ensureColumnFamilyExists(String ksName, String cfName) throws BackendException {
CTConnection conn = null;
try {
KsDef keyspaceDef = ensureKeyspaceExists(ksName);
conn = pool.borrowObject(ksName);
Cassandra.Client client = conn.getClient();
log.debug("Looking up metadata on keyspace {}...", ksName);
boolean foundColumnFamily = false;
for (CfDef cfDef : keyspaceDef.getCf_defs()) {
String curCfName = cfDef.getName();
if (curCfName.equals(cfName))
foundColumnFamily = true;
}
if (!foundColumnFamily) {
createColumnFamily(client, ksName, cfName, "org.apache.cassandra.db.marshal.BytesType");
} else {
log.debug("Keyspace {} and ColumnFamily {} were found.", ksName, cfName);
}
} catch (SchemaDisagreementException e) {
throw new TemporaryBackendException(e);
} catch (Exception e) {
throw new PermanentBackendException(e);
} finally {
pool.returnObjectUnsafe(ksName, conn);
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class CassandraThriftStoreManager method getCompressionOptions.
@Override
public Map<String, String> getCompressionOptions(String cf) throws BackendException {
CTConnection conn = null;
Map<String, String> result = null;
try {
conn = pool.borrowObject(keySpaceName);
Cassandra.Client client = conn.getClient();
KsDef ksDef = client.describe_keyspace(keySpaceName);
for (CfDef cfDef : ksDef.getCf_defs()) {
if (null != cfDef && cfDef.getName().equals(cf)) {
result = cfDef.getCompression_options();
break;
}
}
return result;
} catch (InvalidRequestException e) {
log.debug("Keyspace {} does not exist", keySpaceName);
return null;
} catch (Exception e) {
throw new TemporaryBackendException(e);
} finally {
pool.returnObjectUnsafe(keySpaceName, conn);
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class CassandraThriftStoreManager method getLocalKeyPartition.
@Override
public List<KeyRange> getLocalKeyPartition() throws BackendException {
CTConnection conn = null;
IPartitioner partitioner = getCassandraPartitioner();
if (!(partitioner instanceof AbstractByteOrderedPartitioner))
throw new UnsupportedOperationException("getLocalKeyPartition() only supported by byte ordered partitioner.");
Token.TokenFactory tokenFactory = partitioner.getTokenFactory();
try {
// Resist the temptation to describe SYSTEM_KS. It has no ring.
// Instead, we'll create our own keyspace (or check that it exists), then describe it.
ensureKeyspaceExists(keySpaceName);
conn = pool.borrowObject(keySpaceName);
final List<TokenRange> ranges = conn.getClient().describe_ring(keySpaceName);
final List<KeyRange> keyRanges = new ArrayList<>(ranges.size());
for (TokenRange range : ranges) {
if (!NetworkUtil.hasLocalAddress(range.endpoints))
continue;
keyRanges.add(CassandraHelper.transformRange(tokenFactory.fromString(range.start_token), tokenFactory.fromString(range.end_token)));
}
return keyRanges;
} catch (Exception e) {
throw CassandraThriftKeyColumnValueStore.convertException(e);
} finally {
pool.returnObjectUnsafe(keySpaceName, conn);
}
}
Aggregations