use of org.neo4j.graphdb.factory.module.GlobalModule in project neo4j by neo4j.
the class DefaultDatabaseManagerTest method shouldThrowIfUpgradingNonExistingDatabase.
@Test
void shouldThrowIfUpgradingNonExistingDatabase() {
// Given
NamedDatabaseId namedDatabaseId = DatabaseIdFactory.from("foo", UUID.randomUUID());
GlobalModule mock = mock(GlobalModule.class, RETURNS_MOCKS);
DefaultDatabaseManager databaseManager = new DefaultDatabaseManager(mock, mock(AbstractEditionModule.class));
// Then
DatabaseManagementException e = assertThrows(DatabaseManagementException.class, () -> databaseManager.upgradeDatabase(namedDatabaseId));
assertThat(e).hasMessage("Database not found: " + namedDatabaseId);
}
use of org.neo4j.graphdb.factory.module.GlobalModule in project neo4j by neo4j.
the class DatabaseManagementServiceFactoryTest method newFaultyGraphDatabaseFacadeFactory.
private static DatabaseManagementServiceFactory newFaultyGraphDatabaseFacadeFactory(final RuntimeException startupError, RuntimeException shutdownError) {
return new DatabaseManagementServiceFactory(DbmsInfo.UNKNOWN, CommunityEditionModule::new) {
@Override
protected GlobalModule createGlobalModule(Config config, ExternalDependencies dependencies) {
final LifeSupport lifeMock = mock(LifeSupport.class);
doThrow(startupError).when(lifeMock).start();
if (shutdownError != null) {
doThrow(shutdownError).when(lifeMock).shutdown();
}
doAnswer(invocation -> invocation.getArgument(0)).when(lifeMock).add(any(Lifecycle.class));
return new GlobalModule(config, dbmsInfo, dependencies) {
@Override
public LifeSupport createLife() {
return lifeMock;
}
};
}
};
}
use of org.neo4j.graphdb.factory.module.GlobalModule in project neo4j by neo4j.
the class DatabaseManagementServiceFactory method build.
/**
* Instantiate a graph database given configuration, dependencies, and a custom implementation of {@link org
* .neo4j.kernel.impl.factory.GraphDatabaseFacade}.
*
* @param config configuration
* @param dependencies the dependencies required to construct the {@link GraphDatabaseFacade}
* @return the initialised {@link GraphDatabaseFacade}
*/
public DatabaseManagementService build(Config config, final ExternalDependencies dependencies) {
GlobalModule globalModule = createGlobalModule(config, dependencies);
AbstractEditionModule edition = editionFactory.apply(globalModule);
Dependencies globalDependencies = globalModule.getGlobalDependencies();
LifeSupport globalLife = globalModule.getGlobalLife();
LogService logService = globalModule.getLogService();
Log internalLog = logService.getInternalLog(getClass());
DatabaseManager<?> databaseManager = edition.createDatabaseManager(globalModule);
DatabaseManagementService managementService = createManagementService(globalModule, globalLife, internalLog, databaseManager);
globalDependencies.satisfyDependencies(managementService);
edition.bootstrapFabricServices();
setupProcedures(globalModule, edition, databaseManager);
edition.registerSystemGraphComponents(globalModule.getSystemGraphComponents(), globalModule);
globalLife.add(edition.createSystemGraphInitializer(globalModule));
var dbmsRuntimeSystemGraphComponent = new DbmsRuntimeSystemGraphComponent(globalModule.getGlobalConfig());
globalModule.getSystemGraphComponents().register(dbmsRuntimeSystemGraphComponent);
edition.createDefaultDatabaseResolver(globalModule);
globalDependencies.satisfyDependency(edition.getDefaultDatabaseResolver());
edition.createSecurityModule(globalModule);
SecurityProvider securityProvider = edition.getSecurityProvider();
globalDependencies.satisfyDependencies(securityProvider.authManager());
var dbmsRuntimeRepository = edition.createAndRegisterDbmsRuntimeRepository(globalModule, databaseManager, globalDependencies, dbmsRuntimeSystemGraphComponent);
globalDependencies.satisfyDependency(dbmsRuntimeRepository);
globalLife.add(new DefaultDatabaseInitializer(databaseManager));
globalLife.add(globalModule.getGlobalExtensions());
BoltGraphDatabaseManagementServiceSPI boltGraphDatabaseManagementServiceSPI = edition.createBoltDatabaseManagementServiceProvider(globalDependencies, managementService, globalModule.getGlobalMonitors(), globalModule.getGlobalClock(), logService);
globalLife.add(createBoltServer(globalModule, edition, boltGraphDatabaseManagementServiceSPI, databaseManager.databaseIdRepository()));
var webServer = createWebServer(edition, managementService, globalDependencies, config, globalModule.getLogService().getUserLogProvider());
globalDependencies.satisfyDependency(webServer);
globalLife.add(webServer);
globalLife.add(globalModule.getCapabilitiesService());
startDatabaseServer(globalModule, globalLife, internalLog, databaseManager, managementService);
return managementService;
}
use of org.neo4j.graphdb.factory.module.GlobalModule in project neo4j by neo4j.
the class DatabaseManagementServiceFactory method setupProcedures.
/**
* Creates and registers the systems procedures, including those which belong to a particular edition.
* N.B. This method takes a {@link DatabaseManager} as an unused parameter *intentionally*, in
* order to enforce that the databaseManager must be constructed first.
*/
@SuppressWarnings("unused")
private static void setupProcedures(GlobalModule globalModule, AbstractEditionModule editionModule, DatabaseManager<?> databaseManager) {
Supplier<GlobalProcedures> procedureInitializer = () -> {
Config globalConfig = globalModule.getGlobalConfig();
Path proceduresDirectory = globalConfig.get(GraphDatabaseSettings.plugin_dir);
LogService logService = globalModule.getLogService();
Log internalLog = logService.getInternalLog(GlobalProcedures.class);
Log proceduresLog = logService.getUserLog(GlobalProcedures.class);
ProcedureConfig procedureConfig = new ProcedureConfig(globalConfig);
Edition neo4jEdition = globalModule.getDbmsInfo().edition;
SpecialBuiltInProcedures builtInProcedures = new SpecialBuiltInProcedures(Version.getNeo4jVersion(), neo4jEdition.toString());
GlobalProceduresRegistry globalProcedures = new GlobalProceduresRegistry(builtInProcedures, proceduresDirectory, internalLog, procedureConfig);
globalProcedures.registerType(Node.class, NTNode);
globalProcedures.registerType(NodeValue.class, NTNode);
globalProcedures.registerType(Relationship.class, NTRelationship);
globalProcedures.registerType(RelationshipValue.class, NTRelationship);
globalProcedures.registerType(org.neo4j.graphdb.Path.class, NTPath);
globalProcedures.registerType(PathValue.class, NTPath);
globalProcedures.registerType(Geometry.class, NTGeometry);
globalProcedures.registerType(Point.class, NTPoint);
globalProcedures.registerType(PointValue.class, NTPoint);
// Below components are not public API, but are made available for internal
// procedures to call, and to provide temporary workarounds for the following
// patterns:
// - Batch-transaction imports (GDAPI, needs to be real and passed to background processing threads)
// - Group-transaction writes (same pattern as above, but rather than splitting large transactions,
// combine lots of small ones)
// - Bleeding-edge performance (KernelTransaction, to bypass overhead of working with Core API)
globalProcedures.registerComponent(DependencyResolver.class, Context::dependencyResolver, false);
globalProcedures.registerComponent(KernelTransaction.class, ctx -> ctx.internalTransaction().kernelTransaction(), false);
globalProcedures.registerComponent(GraphDatabaseAPI.class, Context::graphDatabaseAPI, false);
globalProcedures.registerComponent(SystemGraphComponents.class, ctx -> globalModule.getSystemGraphComponents(), false);
globalProcedures.registerComponent(ValueMapper.class, Context::valueMapper, true);
// Register injected public API components
globalProcedures.registerComponent(Log.class, ctx -> proceduresLog, true);
globalProcedures.registerComponent(Transaction.class, new ProcedureTransactionProvider(), true);
globalProcedures.registerComponent(org.neo4j.procedure.TerminationGuard.class, new TerminationGuardProvider(), true);
globalProcedures.registerComponent(SecurityContext.class, Context::securityContext, true);
globalProcedures.registerComponent(ProcedureCallContext.class, Context::procedureCallContext, true);
globalProcedures.registerComponent(FulltextAdapter.class, ctx -> ctx.dependencyResolver().resolveDependency(FulltextAdapter.class), true);
globalProcedures.registerComponent(GraphDatabaseService.class, ctx -> new GraphDatabaseFacade((GraphDatabaseFacade) ctx.graphDatabaseAPI(), new ProcedureLoginContextTransformer(ctx)), true);
globalProcedures.registerComponent(DataCollector.class, ctx -> ctx.dependencyResolver().resolveDependency(DataCollector.class), false);
// Edition procedures
try {
editionModule.registerProcedures(globalProcedures, procedureConfig, globalModule, databaseManager);
} catch (KernelException e) {
internalLog.error("Failed to register built-in edition procedures at start up: " + e.getMessage());
}
globalModule.getGlobalLife().add(globalProcedures);
return globalProcedures;
};
GlobalProcedures procedures = tryResolveOrCreate(GlobalProcedures.class, globalModule.getExternalDependencyResolver(), procedureInitializer);
if (procedures instanceof Consumer) {
((Consumer) procedures).accept(procedureInitializer);
}
globalModule.getGlobalDependencies().satisfyDependency(procedures);
}
Aggregations