/** * Obtain the existing keyspaces in cassandra. * * @param session The cassandra session. * @return A list of {@link com.stratio.crossdata.common.metadata.CatalogMetadata} . */ public static List<CatalogMetadata> getKeyspaces(Session session, String cluster) { List<CatalogMetadata> catalogMetadataList = new ArrayList<>(); List<KeyspaceMetadata> keyspaceMetadataList = session.getCluster().getMetadata().getKeyspaces(); for (KeyspaceMetadata keyspaceMetadata : keyspaceMetadataList) { //Catalogs CatalogName name = new CatalogName(keyspaceMetadata.getName()); Map<Selector, Selector> options = new HashMap<>(); Map<String, String> replicationOptions = new HashMap<>(); for (Map.Entry<String, String> entry : replicationOptions.entrySet()) { options.put(new StringSelector(entry.getKey()), new StringSelector(entry.getValue())); } //Tables Map<TableName, TableMetadata> tables = getTablesFromKeyspace(session, keyspaceMetadata, cluster); CatalogMetadata catalogMetadata = new CatalogMetadata(name, options, tables); catalogMetadataList.add(catalogMetadata); } return catalogMetadataList; }
/** * Get the specified Catalog from the cassandra keyspace. * * @param session The cassandra session. * @param catalogName The catalog name of the cassandra keyspace. * @return A {@link com.stratio.crossdata.common.metadata.CatalogMetadata} . */ public static CatalogMetadata getKeyspacesByName(Session session, CatalogName catalogName, String cluster) { KeyspaceMetadata keyspace = session.getCluster().getMetadata().getKeyspace(Utils.toCaseSensitive(catalogName .getName())); CatalogName name = new CatalogName(keyspace.getName()); Map<Selector, Selector> options = new HashMap<>(); Map<String, String> replicationOptions = new HashMap<>(); for (Map.Entry<String, String> entry : replicationOptions.entrySet()) { options.put(new StringSelector(entry.getKey()), new StringSelector(entry.getValue())); } Map<TableName, TableMetadata> tables = getTablesFromKeyspace(session, keyspace, cluster); CatalogMetadata catalogMetadata = new CatalogMetadata(name, options, tables); return catalogMetadata; }