use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class ElasticSearchIndex method runCommonQuery.
private ElasticSearchResponse runCommonQuery(RawQuery query, BaseTransaction tx, int size, boolean useScroll) throws BackendException {
final ElasticSearchRequest sr = new ElasticSearchRequest();
sr.setQuery(compat.queryString(query.getQuery()));
sr.setFrom(0);
sr.setSize(size);
try {
return client.search(getIndexStoreName(query.getStore()), useMultitypeIndex ? query.getStore() : null, compat.createRequestBody(sr, query.getParameters()), useScroll);
} catch (final IOException | UncheckedIOException e) {
throw new PermanentBackendException(e);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class ElasticSearchIndex method register.
@Override
public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException {
final Class<?> dataType = information.getDataType();
final Mapping map = Mapping.getMapping(information);
Preconditions.checkArgument(map == Mapping.DEFAULT || AttributeUtil.isString(dataType) || (map == Mapping.PREFIX_TREE && AttributeUtil.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]", map, dataType);
final String indexStoreName = getIndexStoreName(store);
if (useExternalMappings) {
try {
// We check if the externalMapping have the property 'key'
final IndexMapping mappings = client.getMapping(indexStoreName, store);
if (mappings == null || (!mappings.isDynamic() && !mappings.getProperties().containsKey(key))) {
// Error if it is not dynamic and have not the property 'key'
throw new PermanentBackendException("The external mapping for index '" + indexStoreName + "' and type '" + store + "' do not have property '" + key + "'");
} else if (mappings.isDynamic()) {
// If it is dynamic, we push the unknown property 'key'
this.pushMapping(store, key, information);
}
} catch (final IOException e) {
throw new PermanentBackendException(e);
}
} else {
try {
checkForOrCreateIndex(indexStoreName);
} catch (final IOException e) {
throw new PermanentBackendException(e);
}
this.pushMapping(store, key, information);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class ElasticSearchConfigTest method testExternalMappingsViaMapping.
@Test
public void testExternalMappingsViaMapping() 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();
// Test create index KO mapping is not push
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);
try {
idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
fail("should fail");
} catch (final PermanentBackendException ignored) {
}
final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
newMapping.setEntity(new StringEntity(objectMapper.writeValueAsString(readMapping(version, "/strict_mapping.json")), Charset.forName("UTF-8")));
executeRequest(newMapping);
// 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.PermanentBackendException in project janusgraph by JanusGraph.
the class HBaseSnapshotBinaryInputFormat method setConf.
@Override
public void setConf(final Configuration config) {
HBaseConfiguration.addHbaseResources(config);
super.setConf(config);
// Pass the extra pass-through properties directly to HBase/Hadoop config.
final Map<String, Object> configSub = janusgraphConf.getSubset(HBaseStoreManager.HBASE_CONFIGURATION_NAMESPACE);
for (Map.Entry<String, Object> entry : configSub.entrySet()) {
log.info("HBase configuration: setting {}={}", entry.getKey(), entry.getValue());
if (entry.getValue() == null)
continue;
config.set(entry.getKey(), entry.getValue().toString());
}
config.set("autotype", "none");
final Scan scanner = new Scan();
String cfName = mrConf.get(JanusGraphHadoopConfiguration.COLUMN_FAMILY_NAME);
// TODO the space-saving short name mapping leaks from HBaseStoreManager here
if (janusgraphConf.get(HBaseStoreManager.SHORT_CF_NAMES)) {
try {
final BiMap<String, String> shortCfMap = HBaseStoreManager.createShortCfMap(janusgraphConf);
cfName = HBaseStoreManager.shortenCfName(shortCfMap, cfName);
} catch (PermanentBackendException e) {
throw new RuntimeException(e);
}
}
edgeStoreFamily = Bytes.toBytes(cfName);
scanner.addFamily(edgeStoreFamily);
// This is a workaround, to be removed when convertScanToString becomes public in hbase package.
Method converter;
try {
converter = TableMapReduceUtil.class.getDeclaredMethod("convertScanToString", Scan.class);
converter.setAccessible(true);
config.set(TableInputFormat.SCAN, (String) converter.invoke(null, scanner));
} catch (Exception e) {
throw new RuntimeException(e);
}
final String snapshotName = janusgraphConf.get(HBaseStoreManager.HBASE_SNAPSHOT);
final String restoreDirString = janusgraphConf.get(HBaseStoreManager.HBASE_SNAPSHOT_RESTORE_DIR);
final Path restoreDir = new Path(restoreDirString);
try {
// This is a workaround. TableSnapshotInputFormat.setInput accepts a Job as parameter.
// And the Job.getInstance(config) create clone of the config, not setting on the
// passed in config.
Job job = Job.getInstance(config);
TableSnapshotInputFormat.setInput(job, snapshotName, restoreDir);
config.set(SNAPSHOT_NAME_KEY, job.getConfiguration().get(SNAPSHOT_NAME_KEY));
config.set(RESTORE_DIR_KEY, job.getConfiguration().get(RESTORE_DIR_KEY));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class SolrIndex method clearStorage.
@Override
public void clearStorage() throws BackendException {
try {
if (mode != Mode.CLOUD) {
logger.error("Operation only supported for SolrCloud. Cores must be deleted manually through the Solr API when using HTTP mode.");
return;
}
logger.debug("Clearing storage from Solr: {}", solrClient);
final ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader();
zkStateReader.forciblyRefreshAllClusterStateSlow();
final ClusterState clusterState = zkStateReader.getClusterState();
for (final String collection : clusterState.getCollectionsMap().keySet()) {
logger.debug("Clearing collection [{}] in Solr", collection);
// Collection is not dropped because it may have been created externally
final UpdateRequest deleteAll = newUpdateRequest();
deleteAll.deleteByQuery("*:*");
solrClient.request(deleteAll, collection);
}
} catch (final SolrServerException e) {
logger.error("Unable to clear storage from index due to server error on Solr.", e);
throw new PermanentBackendException(e);
} catch (final IOException e) {
logger.error("Unable to clear storage from index due to low-level I/O error.", e);
throw new PermanentBackendException(e);
} catch (final Exception e) {
logger.error("Unable to clear storage from index due to general error.", e);
throw new PermanentBackendException(e);
}
}
Aggregations