use of org.codelibs.core.exception.ResourceNotFoundRuntimeException in project fess by codelibs.
the class UpgradeUtil method createAlias.
public static boolean createAlias(final IndicesAdminClient indicesClient, final String indexConfigPath, final String indexName, final String aliasName) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String aliasConfigPath = indexConfigPath + "/" + indexName + "/alias/" + aliasName + ".json";
try {
final File aliasConfigFile = org.codelibs.core.io.ResourceUtil.getResourceAsFile(aliasConfigPath);
if (aliasConfigFile.exists()) {
final String source = FileUtil.readUTF8(aliasConfigFile);
final AcknowledgedResponse response = indicesClient.prepareAliases().addAlias(indexName, aliasName, source).execute().actionGet(fessConfig.getIndexIndicesTimeout());
if (response.isAcknowledged()) {
logger.info("Created {} alias for {}", aliasName, indexName);
return true;
}
if (logger.isDebugEnabled()) {
logger.debug("Failed to create {} alias for {}", aliasName, indexName);
}
}
} catch (final ResourceNotFoundRuntimeException e) {
// ignore
} catch (final Exception e) {
logger.warn("{} is not found.", aliasConfigPath, e);
}
return false;
}
use of org.codelibs.core.exception.ResourceNotFoundRuntimeException in project fess by codelibs.
the class FessEsClient method createAlias.
protected void createAlias(final String index, final String createdIndexName) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
// alias
final String aliasConfigDirPath = indexConfigPath + "/" + index + "/alias";
try {
final File aliasConfigDir = ResourceUtil.getResourceAsFile(aliasConfigDirPath);
if (aliasConfigDir.isDirectory()) {
stream(aliasConfigDir.listFiles((dir, name) -> name.endsWith(".json"))).of(stream -> stream.forEach(f -> {
final String aliasName = f.getName().replaceFirst(".json$", "");
String source = FileUtil.readUTF8(f);
if (source.trim().equals("{}")) {
source = null;
}
final IndicesAliasesResponse response = client.admin().indices().prepareAliases().addAlias(createdIndexName, aliasName, source).execute().actionGet(fessConfig.getIndexIndicesTimeout());
if (response.isAcknowledged()) {
logger.info("Created " + aliasName + " alias for " + createdIndexName);
} else if (logger.isDebugEnabled()) {
logger.debug("Failed to create " + aliasName + " alias for " + createdIndexName);
}
}));
}
} catch (final ResourceNotFoundRuntimeException e) {
// ignore
} catch (final Exception e) {
logger.warn(aliasConfigDirPath + " is not found.", e);
}
}
Aggregations