use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.
the class TestResourceManagerClusterStateProvider method testResourceGroups.
@Test(timeOut = 15_000)
public void testResourceGroups() throws Exception {
InMemoryNodeManager nodeManager = new InMemoryNodeManager();
nodeManager.addNode(new ConnectorId("x"), new InternalNode("node1", URI.create("local://127.0.0.1"), NodeVersion.UNKNOWN, true));
nodeManager.addNode(new ConnectorId("x"), new InternalNode("node2", URI.create("local://127.0.0.1"), NodeVersion.UNKNOWN, true));
nodeManager.addNode(new ConnectorId("x"), new InternalNode("node3", URI.create("local://127.0.0.1"), NodeVersion.UNKNOWN, true));
ResourceManagerClusterStateProvider provider = new ResourceManagerClusterStateProvider(nodeManager, new SessionPropertyManager(), 10, Duration.valueOf("4s"), Duration.valueOf("8s"), Duration.valueOf("50s"), Duration.valueOf("0s"), true, newSingleThreadScheduledExecutor());
provider.registerNodeHeartbeat(createCoordinatorNodeStatus("local"));
provider.registerNodeHeartbeat(createCoordinatorNodeStatus("node1"));
provider.registerNodeHeartbeat(createCoordinatorNodeStatus("node2"));
provider.registerNodeHeartbeat(createCoordinatorNodeStatus("node3"));
assertEquals(provider.getClusterQueries(), ImmutableList.of());
long query1Sequence = 0;
long query2Sequence = 0;
long query3Sequence = 0;
long query4Sequence = 0;
long query5Sequence = 0;
long query6Sequence = 0;
provider.registerQueryHeartbeat("node1", createQueryInfo("1", QUEUED, "rg1", GENERAL_POOL), query1Sequence++);
provider.registerQueryHeartbeat("node1", createQueryInfo("2", RUNNING, "rg2", GENERAL_POOL), query2Sequence++);
provider.registerQueryHeartbeat("node1", createQueryInfo("3", FINISHING, "rg3", GENERAL_POOL), query3Sequence++);
provider.registerQueryHeartbeat("node1", createQueryInfo("4", FINISHED, "rg4", GENERAL_POOL), query4Sequence++);
provider.registerQueryHeartbeat("node1", createQueryInfo("5", FAILED, "rg5", GENERAL_POOL), query5Sequence++);
assertResourceGroups(provider, "node1", 0);
assertResourceGroups(provider, "node2", 3);
// Add an existing leaf node from another node
provider.registerQueryHeartbeat("node3", createQueryInfo("6", QUEUED, "rg6", GENERAL_POOL), query6Sequence++);
assertResourceGroups(provider, "node1", 1);
assertResourceGroups(provider, "node2", 4);
assertResourceGroups(provider, "node3", 3);
// Expire running queries
Thread.sleep(SECONDS.toMillis(5));
assertResourceGroups(provider, "node1", 0);
assertResourceGroups(provider, "node2", 0);
assertResourceGroups(provider, "node3", 0);
}
use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.
the class ConnectorManager method createConnection.
private synchronized ConnectorId createConnection(String catalogName, ConnectorFactory connectorFactory, Map<String, String> properties) {
checkState(!stopped.get(), "ConnectorManager is stopped");
requireNonNull(catalogName, "catalogName is null");
requireNonNull(properties, "properties is null");
requireNonNull(connectorFactory, "connectorFactory is null");
checkArgument(!catalogManager.getCatalog(catalogName).isPresent(), "A catalog already exists for %s", catalogName);
ConnectorId connectorId = new ConnectorId(catalogName);
checkState(!connectors.containsKey(connectorId), "A connector %s already exists", connectorId);
addCatalogConnector(catalogName, connectorId, connectorFactory, properties);
return connectorId;
}
use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.
the class ConnectorManager method addCatalogConnector.
private synchronized void addCatalogConnector(String catalogName, ConnectorId connectorId, ConnectorFactory factory, Map<String, String> properties) {
// create all connectors before adding, so a broken connector does not leave the system half updated
MaterializedConnector connector = new MaterializedConnector(connectorId, createConnector(connectorId, factory, properties));
MaterializedConnector informationSchemaConnector = new MaterializedConnector(createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadataManager, accessControlManager, connector.getSessionProperties()));
ConnectorId systemId = createSystemTablesConnectorId(connectorId);
SystemTablesProvider systemTablesProvider;
if (nodeManager.getCurrentNode().isCoordinator()) {
systemTablesProvider = new DelegatingSystemTablesProvider(new StaticSystemTablesProvider(connector.getSystemTables()), new MetadataBasedSystemTablesProvider(metadataManager, catalogName));
} else {
systemTablesProvider = new StaticSystemTablesProvider(connector.getSystemTables());
}
MaterializedConnector systemConnector = new MaterializedConnector(systemId, new SystemConnector(systemId, nodeManager, systemTablesProvider, transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId), connector.getSessionProperties()));
Catalog catalog = new Catalog(catalogName, connector.getConnectorId(), connector.getConnector(), informationSchemaConnector.getConnectorId(), informationSchemaConnector.getConnector(), systemConnector.getConnectorId(), systemConnector.getConnector());
try {
addConnectorInternal(connector);
addConnectorInternal(informationSchemaConnector);
addConnectorInternal(systemConnector);
catalogManager.registerCatalog(catalog);
} catch (Throwable e) {
catalogManager.removeCatalog(catalog.getCatalogName());
removeConnectorInternal(systemConnector.getConnectorId());
removeConnectorInternal(informationSchemaConnector.getConnectorId());
removeConnectorInternal(connector.getConnectorId());
throw e;
}
}
use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.
the class CatalogSystemTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
Session session = toSession(transactionHandle, connectorSession);
Builder table = InMemoryRecordSet.builder(CATALOG_TABLE);
for (Map.Entry<String, ConnectorId> entry : listCatalogs(session, metadata, accessControl).entrySet()) {
table.addRow(entry.getKey(), entry.getValue().toString());
}
return table.build().cursor();
}
use of com.facebook.presto.spi.ConnectorId in project presto by prestodb.
the class SessionPropertyManager method getAllSessionProperties.
public List<SessionPropertyValue> getAllSessionProperties(Session session, Map<String, ConnectorId> catalogs) {
requireNonNull(session, "session is null");
ImmutableList.Builder<SessionPropertyValue> sessionPropertyValues = ImmutableList.builder();
Map<String, String> systemProperties = session.getSystemProperties();
for (PropertyMetadata<?> property : new TreeMap<>(systemSessionProperties).values()) {
String defaultValue = firstNonNull(property.getDefaultValue(), "").toString();
String value = systemProperties.getOrDefault(property.getName(), defaultValue);
sessionPropertyValues.add(new SessionPropertyValue(value, defaultValue, property.getName(), Optional.empty(), property.getName(), property.getDescription(), property.getSqlType().getDisplayName(), property.isHidden()));
}
for (Entry<String, ConnectorId> entry : new TreeMap<>(catalogs).entrySet()) {
String catalog = entry.getKey();
ConnectorId connectorId = entry.getValue();
Map<String, String> connectorProperties = session.getConnectorProperties(connectorId);
for (PropertyMetadata<?> property : new TreeMap<>(connectorSessionProperties.get(connectorId)).values()) {
String defaultValue = firstNonNull(property.getDefaultValue(), "").toString();
String value = connectorProperties.getOrDefault(property.getName(), defaultValue);
sessionPropertyValues.add(new SessionPropertyValue(value, defaultValue, catalog + "." + property.getName(), Optional.of(catalog), property.getName(), property.getDescription(), property.getSqlType().getDisplayName(), property.isHidden()));
}
}
return sessionPropertyValues.build();
}
Aggregations