use of io.trino.metadata.Catalog in project trino by trinodb.
the class ConnectorManager method createCatalog.
private synchronized void createCatalog(CatalogName catalogName, String connectorName, InternalConnectorFactory factory, Map<String, String> properties) {
// create all connectors before adding, so a broken connector does not leave the system half updated
CatalogClassLoaderSupplier duplicatePluginClassLoaderFactory = new CatalogClassLoaderSupplier(catalogName, factory.getDuplicatePluginClassLoaderFactory(), handleResolver);
MaterializedConnector connector = new MaterializedConnector(catalogName, createConnector(catalogName, factory.getConnectorFactory(), duplicatePluginClassLoaderFactory, properties), duplicatePluginClassLoaderFactory::destroy);
MaterializedConnector informationSchemaConnector = new MaterializedConnector(createInformationSchemaCatalogName(catalogName), new InformationSchemaConnector(catalogName.getCatalogName(), nodeManager, metadataManager, accessControlManager), () -> {
});
CatalogName systemId = createSystemTablesCatalogName(catalogName);
SystemTablesProvider systemTablesProvider;
if (nodeManager.getCurrentNode().isCoordinator()) {
systemTablesProvider = new CoordinatorSystemTablesProvider(transactionManager, metadataManager, catalogName.getCatalogName(), new StaticSystemTablesProvider(connector.getSystemTables()));
} else {
systemTablesProvider = new StaticSystemTablesProvider(connector.getSystemTables());
}
MaterializedConnector systemConnector = new MaterializedConnector(systemId, new SystemConnector(nodeManager, systemTablesProvider, transactionId -> transactionManager.getConnectorTransaction(transactionId, catalogName)), () -> {
});
SecurityManagement securityManagement = connector.getAccessControl().isPresent() ? CONNECTOR : SYSTEM;
Catalog catalog = new Catalog(catalogName.getCatalogName(), connector.getCatalogName(), connectorName, connector.getConnector(), securityManagement, informationSchemaConnector.getCatalogName(), informationSchemaConnector.getConnector(), systemConnector.getCatalogName(), systemConnector.getConnector());
try {
addConnectorInternal(connector);
addConnectorInternal(informationSchemaConnector);
addConnectorInternal(systemConnector);
catalogManager.registerCatalog(catalog);
} catch (Throwable e) {
catalogManager.removeCatalog(catalog.getCatalogName());
removeConnectorInternal(systemConnector.getCatalogName());
removeConnectorInternal(informationSchemaConnector.getCatalogName());
removeConnectorInternal(connector.getCatalogName());
throw e;
}
connector.getEventListeners().forEach(eventListenerManager::addEventListener);
}
use of io.trino.metadata.Catalog in project trino by trinodb.
the class CatalogSystemTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
Session session = ((FullConnectorSession) connectorSession).getSession();
Builder table = InMemoryRecordSet.builder(CATALOG_TABLE);
for (Map.Entry<String, Catalog> entry : getCatalogs(session, metadata, accessControl).entrySet()) {
table.addRow(entry.getKey(), entry.getValue().getConnectorCatalogName().toString(), entry.getValue().getConnectorName());
}
return table.build().cursor();
}
use of io.trino.metadata.Catalog in project trino by trinodb.
the class Server method updateConnectorIds.
private static void updateConnectorIds(Announcer announcer, CatalogManager metadata) {
// get existing announcement
ServiceAnnouncement announcement = getTrinoAnnouncement(announcer.getServiceAnnouncements());
// automatically build connectorIds if not configured
Set<String> connectorIds = metadata.getCatalogs().stream().map(Catalog::getConnectorCatalogName).map(Object::toString).collect(toImmutableSet());
// build announcement with updated sources
ServiceAnnouncementBuilder builder = serviceAnnouncement(announcement.getType());
builder.addProperties(announcement.getProperties());
builder.addProperty("connectorIds", Joiner.on(',').join(connectorIds));
// update announcement
announcer.removeServiceAnnouncement(announcement.getId());
announcer.addServiceAnnouncement(builder.build());
}
Aggregations