use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.
the class JdbcTest method testJDBCMethods.
private void testJDBCMethods(String collection, String connectionString, Properties properties, String sql) throws Exception {
try (Connection con = DriverManager.getConnection(connectionString, properties)) {
assertTrue(con.isValid(DEFAULT_CONNECTION_TIMEOUT));
assertEquals(zkHost, con.getCatalog());
con.setCatalog(zkHost);
assertEquals(zkHost, con.getCatalog());
assertEquals(null, con.getSchema());
con.setSchema("myschema");
assertEquals(null, con.getSchema());
DatabaseMetaData databaseMetaData = con.getMetaData();
assertNotNull(databaseMetaData);
assertEquals(con, databaseMetaData.getConnection());
assertEquals(connectionString, databaseMetaData.getURL());
assertEquals(4, databaseMetaData.getJDBCMajorVersion());
assertEquals(0, databaseMetaData.getJDBCMinorVersion());
assertEquals("Apache Solr", databaseMetaData.getDatabaseProductName());
// The following tests require package information that is not available when running via Maven
// assertEquals(this.getClass().getPackage().getSpecificationVersion(), databaseMetaData.getDatabaseProductVersion());
// assertEquals(0, databaseMetaData.getDatabaseMajorVersion());
// assertEquals(0, databaseMetaData.getDatabaseMinorVersion());
// assertEquals(this.getClass().getPackage().getSpecificationTitle(), databaseMetaData.getDriverName());
// assertEquals(this.getClass().getPackage().getSpecificationVersion(), databaseMetaData.getDriverVersion());
// assertEquals(0, databaseMetaData.getDriverMajorVersion());
// assertEquals(0, databaseMetaData.getDriverMinorVersion());
List<String> tableSchemas = new ArrayList<>(Arrays.asList(zkHost, "metadata"));
try (ResultSet rs = databaseMetaData.getSchemas()) {
assertTrue(rs.next());
assertTrue(tableSchemas.contains(rs.getString("tableSchem")));
tableSchemas.remove(rs.getString("tableSchem"));
assertNull(rs.getString("tableCat"));
assertTrue(rs.next());
assertTrue(tableSchemas.contains(rs.getString("tableSchem")));
tableSchemas.remove(rs.getString("tableSchem"));
assertNull(rs.getString("tableCat"));
assertFalse(rs.next());
assertTrue(tableSchemas.isEmpty());
}
try (ResultSet rs = databaseMetaData.getCatalogs()) {
assertTrue(rs.next());
assertNull(rs.getString("tableCat"));
assertFalse(rs.next());
}
CloudSolrClient solrClient = cluster.getSolrClient();
solrClient.connect();
ZkStateReader zkStateReader = solrClient.getZkStateReader();
SortedSet<String> tables = new TreeSet<>();
Set<String> collectionsSet = zkStateReader.getClusterState().getCollectionsMap().keySet();
tables.addAll(collectionsSet);
Aliases aliases = zkStateReader.getAliases();
if (aliases != null) {
Map<String, String> collectionAliasMap = aliases.getCollectionAliasMap();
if (collectionAliasMap != null) {
Set<String> aliasesSet = collectionAliasMap.keySet();
tables.addAll(aliasesSet);
}
}
try (ResultSet rs = databaseMetaData.getTables(null, zkHost, "%", null)) {
for (String table : tables) {
assertTrue(rs.next());
assertNull(rs.getString("tableCat"));
assertEquals(zkHost, rs.getString("tableSchem"));
assertEquals(table, rs.getString("tableName"));
assertEquals("TABLE", rs.getString("tableType"));
assertNull(rs.getString("remarks"));
}
assertFalse(rs.next());
}
assertTrue(con.isReadOnly());
con.setReadOnly(true);
assertTrue(con.isReadOnly());
assertNull(con.getWarnings());
con.clearWarnings();
assertNull(con.getWarnings());
try (Statement statement = con.createStatement()) {
checkStatement(con, statement);
try (ResultSet rs = statement.executeQuery(sql)) {
assertEquals(statement, rs.getStatement());
checkResultSetMetadata(rs);
checkResultSet(rs);
}
assertTrue(statement.execute(sql));
assertEquals(-1, statement.getUpdateCount());
try (ResultSet rs = statement.getResultSet()) {
assertEquals(statement, rs.getStatement());
checkResultSetMetadata(rs);
checkResultSet(rs);
}
assertFalse(statement.getMoreResults());
}
try (PreparedStatement statement = con.prepareStatement(sql)) {
checkStatement(con, statement);
try (ResultSet rs = statement.executeQuery()) {
assertEquals(statement, rs.getStatement());
checkResultSetMetadata(rs);
checkResultSet(rs);
}
assertTrue(statement.execute());
assertEquals(-1, statement.getUpdateCount());
try (ResultSet rs = statement.getResultSet()) {
assertEquals(statement, rs.getStatement());
checkResultSetMetadata(rs);
checkResultSet(rs);
}
assertFalse(statement.getMoreResults());
}
}
}
use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.
the class TupleStream method getSlices.
public static Collection<Slice> getSlices(String collectionName, ZkStateReader zkStateReader, boolean checkAlias) throws IOException {
ClusterState clusterState = zkStateReader.getClusterState();
Map<String, DocCollection> collectionsMap = clusterState.getCollectionsMap();
// Check collection case sensitive
if (collectionsMap.containsKey(collectionName)) {
return collectionsMap.get(collectionName).getActiveSlices();
}
// Check collection case insensitive
for (String collectionMapKey : collectionsMap.keySet()) {
if (collectionMapKey.equalsIgnoreCase(collectionName)) {
return collectionsMap.get(collectionMapKey).getActiveSlices();
}
}
if (checkAlias) {
// check for collection alias
Aliases aliases = zkStateReader.getAliases();
String alias = aliases.getCollectionAlias(collectionName);
if (alias != null) {
Collection<Slice> slices = new ArrayList<>();
List<String> aliasList = StrUtils.splitSmart(alias, ",", true);
for (String aliasCollectionName : aliasList) {
// Add all active slices for this alias collection
slices.addAll(collectionsMap.get(aliasCollectionName).getActiveSlices());
}
return slices;
}
}
throw new IOException("Slices not found for " + collectionName);
}
use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.
the class CloudSolrStream method getSlices.
public static Collection<Slice> getSlices(String collectionName, ZkStateReader zkStateReader, boolean checkAlias) throws IOException {
ClusterState clusterState = zkStateReader.getClusterState();
Map<String, DocCollection> collectionsMap = clusterState.getCollectionsMap();
// Check collection case sensitive
if (collectionsMap.containsKey(collectionName)) {
return collectionsMap.get(collectionName).getActiveSlices();
}
// Check collection case insensitive
for (String collectionMapKey : collectionsMap.keySet()) {
if (collectionMapKey.equalsIgnoreCase(collectionName)) {
return collectionsMap.get(collectionMapKey).getActiveSlices();
}
}
if (checkAlias) {
// check for collection alias
Aliases aliases = zkStateReader.getAliases();
String alias = aliases.getCollectionAlias(collectionName);
if (alias != null) {
Collection<Slice> slices = new ArrayList<>();
List<String> aliasList = StrUtils.splitSmart(alias, ",", true);
for (String aliasCollectionName : aliasList) {
// Add all active slices for this alias collection
slices.addAll(collectionsMap.get(aliasCollectionName).getActiveSlices());
}
return slices;
}
}
throw new IOException("Slices not found for " + collectionName);
}
use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.
the class DeleteAliasCmd method checkForAliasAbsence.
private void checkForAliasAbsence(String name) {
TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS);
boolean success = false;
Aliases aliases = null;
while (!timeout.hasTimedOut()) {
aliases = ocmh.zkStateReader.getAliases();
String collections = aliases.getCollectionAlias(name);
if (collections == null) {
success = true;
break;
}
}
if (!success) {
log.warn("Timeout waiting to be notified of Alias change...");
}
}
use of org.apache.solr.common.cloud.Aliases in project lucene-solr by apache.
the class DeleteAliasCmd method call.
@Override
public void call(ClusterState state, ZkNodeProps message, NamedList results) throws Exception {
String aliasName = message.getStr(NAME);
Map<String, Map<String, String>> newAliasesMap = new HashMap<>();
Map<String, String> newCollectionAliasesMap = new HashMap<>();
ZkStateReader zkStateReader = ocmh.zkStateReader;
newCollectionAliasesMap.putAll(zkStateReader.getAliases().getCollectionAliasMap());
newCollectionAliasesMap.remove(aliasName);
newAliasesMap.put("collection", newCollectionAliasesMap);
Aliases newAliases = new Aliases(newAliasesMap);
byte[] jsonBytes = null;
if (newAliases.collectionAliasSize() > 0) {
// only sub map right now
jsonBytes = Utils.toJSON(newAliases.getAliasMap());
}
try {
zkStateReader.getZkClient().setData(ZkStateReader.ALIASES, jsonBytes, true);
checkForAliasAbsence(aliasName);
// some fudge for other nodes
Thread.sleep(100);
} catch (KeeperException e) {
log.error("", e);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
} catch (InterruptedException e) {
log.warn("", e);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
}
Aggregations