diff --git a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/AlgorithmFacadeFactory.java b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/AlgorithmFacadeFactory.java index 17eea95128..1bb33ee4f2 100644 --- a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/AlgorithmFacadeFactory.java +++ b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/AlgorithmFacadeFactory.java @@ -61,16 +61,8 @@ import org.neo4j.gds.api.NodeLookup; import org.neo4j.gds.api.User; import org.neo4j.gds.applications.ApplicationsFacade; -import org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmEstimationTemplate; -import org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmProcessingTemplate; import org.neo4j.gds.configuration.DefaultsConfiguration; import org.neo4j.gds.configuration.LimitsConfiguration; -import org.neo4j.gds.core.utils.progress.TaskRegistryFactory; -import org.neo4j.gds.core.utils.warnings.UserLogRegistryFactory; -import org.neo4j.gds.core.write.NodePropertyExporterBuilder; -import org.neo4j.gds.core.write.RelationshipExporterBuilder; -import org.neo4j.gds.core.write.RelationshipStreamExporterBuilder; -import org.neo4j.gds.logging.Log; import org.neo4j.gds.modelcatalogservices.ModelCatalogService; import org.neo4j.gds.procedures.algorithms.configuration.ConfigurationCreator; import org.neo4j.gds.procedures.algorithms.configuration.ConfigurationParser; @@ -80,11 +72,9 @@ import org.neo4j.gds.procedures.embeddings.NodeEmbeddingsProcedureFacade; import org.neo4j.gds.procedures.misc.MiscAlgorithmsProcedureFacade; import org.neo4j.gds.procedures.similarity.SimilarityProcedureFacade; -import org.neo4j.gds.termination.TerminationFlag; class AlgorithmFacadeFactory { // Global scoped dependencies - private final Log log; private final DefaultsConfiguration defaultsConfiguration; private final LimitsConfiguration limitsConfiguration; @@ -100,19 +90,10 @@ class AlgorithmFacadeFactory { private final WriteRelationshipService writeRelationshipService; private final AlgorithmEstimator algorithmEstimator; private final AlgorithmRunner algorithmRunner; - private final AlgorithmProcessingTemplate algorithmProcessingTemplate; - private final AlgorithmEstimationTemplate algorithmEstimationTemplate; - private final NodePropertyExporterBuilder nodePropertyExporterBuilder; - private final RelationshipExporterBuilder relationshipExporterBuilder; - private final RelationshipStreamExporterBuilder relationshipStreamExporterBuilder; - private final TaskRegistryFactory taskRegistryFactory; - private final TerminationFlag terminationFlag; private final User user; - private final UserLogRegistryFactory userLogRegistryFactory; private final ModelCatalogService modelCatalogService; AlgorithmFacadeFactory( - Log log, DefaultsConfiguration defaultsConfiguration, LimitsConfiguration limitsConfiguration, CloseableResourceRegistry closeableResourceRegistry, @@ -126,18 +107,9 @@ class AlgorithmFacadeFactory { WriteRelationshipService writeRelationshipService, AlgorithmRunner algorithmRunner, AlgorithmEstimator algorithmEstimator, - AlgorithmProcessingTemplate algorithmProcessingTemplate, - AlgorithmEstimationTemplate algorithmEstimationTemplate, - NodePropertyExporterBuilder nodePropertyExporterBuilder, - RelationshipExporterBuilder relationshipExporterBuilder, - RelationshipStreamExporterBuilder relationshipStreamExporterBuilder, - TaskRegistryFactory taskRegistryFactory, - TerminationFlag terminationFlag, User user, - UserLogRegistryFactory userLogRegistryFactory, ModelCatalogService modelCatalogService ) { - this.log = log; this.defaultsConfiguration = defaultsConfiguration; this.limitsConfiguration = limitsConfiguration; @@ -154,15 +126,6 @@ class AlgorithmFacadeFactory { this.algorithmRunner = algorithmRunner; this.algorithmEstimator = algorithmEstimator; this.modelCatalogService = modelCatalogService; - - this.algorithmProcessingTemplate = algorithmProcessingTemplate; - this.algorithmEstimationTemplate = algorithmEstimationTemplate; - this.nodePropertyExporterBuilder = nodePropertyExporterBuilder; - this.relationshipExporterBuilder = relationshipExporterBuilder; - this.relationshipStreamExporterBuilder = relationshipStreamExporterBuilder; - this.taskRegistryFactory = taskRegistryFactory; - this.terminationFlag = terminationFlag; - this.userLogRegistryFactory = userLogRegistryFactory; } CentralityProcedureFacade createCentralityProcedureFacade() { @@ -285,20 +248,7 @@ MiscAlgorithmsProcedureFacade createMiscellaneousProcedureFacade() { ); } - PathFindingProcedureFacade createPathFindingProcedureFacade() { - // eventually this moves up and is shared - var applicationsFacade = ApplicationsFacade.create( - log, - nodePropertyExporterBuilder, - relationshipExporterBuilder, - relationshipStreamExporterBuilder, - taskRegistryFactory, - terminationFlag, - userLogRegistryFactory, - algorithmProcessingTemplate, - algorithmEstimationTemplate - ); - + PathFindingProcedureFacade createPathFindingProcedureFacade(ApplicationsFacade applicationsFacade) { return PathFindingProcedureFacade.create( defaultsConfiguration, limitsConfiguration, diff --git a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/AlgorithmFacadeFactoryProvider.java b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/AlgorithmFacadeFactoryProvider.java index 145bb82e47..bf59b3632c 100644 --- a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/AlgorithmFacadeFactoryProvider.java +++ b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/AlgorithmFacadeFactoryProvider.java @@ -30,42 +30,31 @@ import org.neo4j.gds.algorithms.similarity.MutateRelationshipService; import org.neo4j.gds.algorithms.similarity.WriteRelationshipService; import org.neo4j.gds.algorithms.writeservices.WriteNodePropertyService; -import org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmEstimationTemplate; -import org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmProcessingTemplate; -import org.neo4j.gds.applications.algorithms.pathfinding.DefaultAlgorithmProcessingTemplate; -import org.neo4j.gds.applications.algorithms.pathfinding.DefaultMemoryGuard; +import org.neo4j.gds.api.DatabaseId; +import org.neo4j.gds.api.User; import org.neo4j.gds.configuration.DefaultsConfiguration; import org.neo4j.gds.configuration.LimitsConfiguration; import org.neo4j.gds.core.loading.GraphStoreCatalogService; -import org.neo4j.gds.core.write.ExporterContext; +import org.neo4j.gds.core.utils.progress.TaskRegistryFactory; +import org.neo4j.gds.core.utils.warnings.UserLogRegistryFactory; +import org.neo4j.gds.core.write.NodePropertyExporterBuilder; +import org.neo4j.gds.core.write.RelationshipExporterBuilder; import org.neo4j.gds.logging.Log; -import org.neo4j.gds.mem.MemoryGauge; import org.neo4j.gds.memest.DatabaseGraphStoreEstimationService; import org.neo4j.gds.memest.FictitiousGraphStoreEstimationService; import org.neo4j.gds.metrics.algorithms.AlgorithmMetricsService; import org.neo4j.gds.modelcatalogservices.ModelCatalogServiceProvider; -import org.neo4j.gds.procedures.KernelTransactionAccessor; -import org.neo4j.gds.procedures.TaskRegistryFactoryService; -import org.neo4j.gds.procedures.TerminationFlagAccessor; import org.neo4j.gds.procedures.algorithms.configuration.ConfigurationCreator; import org.neo4j.gds.procedures.algorithms.configuration.ConfigurationParser; -import org.neo4j.gds.services.DatabaseIdAccessor; -import org.neo4j.gds.services.UserAccessor; -import org.neo4j.gds.services.UserLogServices; -import org.neo4j.internal.kernel.api.exceptions.ProcedureException; +import org.neo4j.gds.termination.TerminationFlag; +import org.neo4j.graphdb.GraphDatabaseService; +import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.procedure.Context; -import java.util.Optional; -import java.util.function.Function; - class AlgorithmFacadeFactoryProvider { // dull utilities private final AlgorithmMetaDataSetterService algorithmMetaDataSetterService = new AlgorithmMetaDataSetterService(); - private final DatabaseIdAccessor databaseIdAccessor = new DatabaseIdAccessor(); private final FictitiousGraphStoreEstimationService fictitiousGraphStoreEstimationService = new FictitiousGraphStoreEstimationService(); - private final KernelTransactionAccessor kernelTransactionAccessor = new KernelTransactionAccessor(); - private final TerminationFlagAccessor terminationFlagAccessor = new TerminationFlagAccessor(); - private final UserAccessor userAccessor = new UserAccessor(); // Global state and services private final Log log; @@ -73,17 +62,11 @@ class AlgorithmFacadeFactoryProvider { private final DefaultsConfiguration defaultsConfiguration; private final GraphStoreCatalogService graphStoreCatalogService; private final LimitsConfiguration limitsConfiguration; - private final MemoryGauge memoryGauge; private final boolean useMaxMemoryEstimation; // Request scoped state and services private final AlgorithmMetricsService algorithmMetricsService; - private final ExporterBuildersProviderService exporterBuildersProviderService; - private final TaskRegistryFactoryService taskRegistryFactoryService; - private final UserLogServices userLogServices; private final ModelCatalogServiceProvider modelCatalogServiceProvider; - private final Optional> algorithmProcessingTemplateDecorator; - //algorithm facade parameters AlgorithmFacadeFactoryProvider( Log log, @@ -91,37 +74,34 @@ class AlgorithmFacadeFactoryProvider { DefaultsConfiguration defaultsConfiguration, GraphStoreCatalogService graphStoreCatalogService, LimitsConfiguration limitsConfiguration, - MemoryGauge memoryGauge, boolean useMaxMemoryEstimation, AlgorithmMetricsService algorithmMetricsService, - ExporterBuildersProviderService exporterBuildersProviderService, - ModelCatalogServiceProvider modelCatalogServiceProvider, - TaskRegistryFactoryService taskRegistryFactoryService, - UserLogServices userLogServices, - Optional> algorithmProcessingTemplateDecorator + ModelCatalogServiceProvider modelCatalogServiceProvider ) { this.log = log; this.configurationParser = configurationParser; this.defaultsConfiguration = defaultsConfiguration; this.graphStoreCatalogService = graphStoreCatalogService; this.limitsConfiguration = limitsConfiguration; - this.memoryGauge = memoryGauge; this.useMaxMemoryEstimation = useMaxMemoryEstimation; - this.exporterBuildersProviderService = exporterBuildersProviderService; - this.taskRegistryFactoryService = taskRegistryFactoryService; this.algorithmMetricsService = algorithmMetricsService; - this.userLogServices = userLogServices; - this.algorithmProcessingTemplateDecorator = algorithmProcessingTemplateDecorator; this.modelCatalogServiceProvider = modelCatalogServiceProvider; } - - AlgorithmFacadeFactory createAlgorithmFacadeFactory(Context context) throws ProcedureException { - // Neo4j's services - var graphDatabaseService = context.graphDatabaseAPI(); - var kernelTransaction = kernelTransactionAccessor.getKernelTransaction(context); - + AlgorithmFacadeFactory createAlgorithmFacadeFactory( + Context context, + NodePropertyExporterBuilder nodePropertyExporterBuilder, + RelationshipExporterBuilder relationshipExporterBuilder, + TaskRegistryFactory taskRegistryFactory, + UserLogRegistryFactory userLogRegistryFactory, + TerminationFlag terminationFlag, + DatabaseId databaseId, + User user, + KernelTransaction kernelTransaction, + GraphDatabaseService graphDatabaseService, + DatabaseGraphStoreEstimationService databaseGraphStoreEstimationService + ) { /* * GDS services derived from Procedure Context. * These come in layers, we can create some services readily, @@ -131,32 +111,14 @@ AlgorithmFacadeFactory createAlgorithmFacadeFactory(Context context) throws Proc var algorithmMetaDataSetter = algorithmMetaDataSetterService.getAlgorithmMetaDataSetter(kernelTransaction); var algorithmMemoryValidationService = new AlgorithmMemoryValidationService(log, useMaxMemoryEstimation); var closeableResourceRegistry = new TransactionCloseableResourceRegistry(kernelTransaction); - var databaseId = databaseIdAccessor.getDatabaseId(context.graphDatabaseAPI()); - var exportBuildersProvider = exporterBuildersProviderService.identifyExportBuildersProvider(graphDatabaseService); - var exporterContext = new ExporterContext.ProcedureContextWrapper(context); - var memoryGuard = new DefaultMemoryGuard(log, useMaxMemoryEstimation, memoryGauge); var mutateNodePropertyService = new MutateNodePropertyService(log); var mutateRelationshipService = new MutateRelationshipService(log); var nodeLookup = new TransactionNodeLookup(kernelTransaction); var returnColumns = new ProcedureCallContextReturnColumns(context.procedureCallContext()); - var terminationFlag = terminationFlagAccessor.createTerminationFlag(kernelTransaction); - var user = userAccessor.getUser(context.securityContext()); - var taskRegistryFactory = taskRegistryFactoryService.getTaskRegistryFactory(databaseId, user); - var userLogRegistryFactory = userLogServices.getUserLogRegistryFactory(databaseId, user); // Second layer var configurationCreator = new ConfigurationCreator(configurationParser, algorithmMetaDataSetter, user); - var graphLoaderContext = GraphLoaderContextProvider.buildGraphLoaderContext( - context, - databaseId, - taskRegistryFactory, - terminationFlag, - userLogRegistryFactory, - log - ); - var nodePropertyExporterBuilder = exportBuildersProvider.nodePropertyExporterBuilder(exporterContext); - var relationshipExporterBuilder = exportBuildersProvider.relationshipExporterBuilder(exporterContext); - var relationshipStreamExporterBuilder = exportBuildersProvider.relationshipStreamExporterBuilder(exporterContext); + var requestScopedDependencies = RequestScopedDependencies.builder() .with(databaseId) .with(user) @@ -176,7 +138,6 @@ AlgorithmFacadeFactory createAlgorithmFacadeFactory(Context context) throws Proc taskRegistryFactory, terminationFlag ); - var databaseGraphStoreEstimationService = new DatabaseGraphStoreEstimationService(graphLoaderContext, user); // Fourth layer var algorithmEstimator = new AlgorithmEstimator( @@ -196,30 +157,8 @@ AlgorithmFacadeFactory createAlgorithmFacadeFactory(Context context) throws Proc userLogRegistryFactory ); - // business facades - AlgorithmProcessingTemplate algorithmProcessingTemplate = new DefaultAlgorithmProcessingTemplate( - log, - algorithmMetricsService, - graphStoreCatalogService, - memoryGuard, - databaseId, - user - ); - - if (this.algorithmProcessingTemplateDecorator.isPresent()) - algorithmProcessingTemplate = this.algorithmProcessingTemplateDecorator.get().apply( - algorithmProcessingTemplate); - - var algorithmEstimationTemplate = new AlgorithmEstimationTemplate( - graphStoreCatalogService, - databaseId, - databaseGraphStoreEstimationService, - user - ); - // procedure facade return new AlgorithmFacadeFactory( - log, defaultsConfiguration, limitsConfiguration, closeableResourceRegistry, @@ -233,15 +172,7 @@ AlgorithmFacadeFactory createAlgorithmFacadeFactory(Context context) throws Proc writeRelationshipService, algorithmRunner, algorithmEstimator, - algorithmProcessingTemplate, - algorithmEstimationTemplate, - nodePropertyExporterBuilder, - relationshipExporterBuilder, - relationshipStreamExporterBuilder, - taskRegistryFactory, - terminationFlag, user, - userLogRegistryFactory, modelCatalogServiceProvider.createService(graphDatabaseService, log) ); } diff --git a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/GraphDataScienceProvider.java b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/GraphDataScienceProvider.java index 2f376468ce..0ef0718a98 100644 --- a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/GraphDataScienceProvider.java +++ b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/GraphDataScienceProvider.java @@ -20,45 +20,164 @@ package org.neo4j.gds.procedures.integration; import org.neo4j.function.ThrowingFunction; +import org.neo4j.gds.api.DatabaseId; +import org.neo4j.gds.api.User; +import org.neo4j.gds.applications.ApplicationsFacade; +import org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmEstimationTemplate; +import org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmProcessingTemplate; +import org.neo4j.gds.applications.algorithms.pathfinding.DefaultAlgorithmProcessingTemplate; +import org.neo4j.gds.applications.algorithms.pathfinding.DefaultMemoryGuard; +import org.neo4j.gds.core.loading.GraphStoreCatalogService; +import org.neo4j.gds.core.utils.progress.TaskRegistryFactory; +import org.neo4j.gds.core.utils.warnings.UserLogRegistryFactory; +import org.neo4j.gds.core.write.ExporterContext; +import org.neo4j.gds.core.write.NodePropertyExporterBuilder; +import org.neo4j.gds.core.write.RelationshipExporterBuilder; +import org.neo4j.gds.core.write.RelationshipStreamExporterBuilder; import org.neo4j.gds.logging.Log; +import org.neo4j.gds.mem.MemoryGauge; +import org.neo4j.gds.memest.DatabaseGraphStoreEstimationService; +import org.neo4j.gds.metrics.algorithms.AlgorithmMetricsService; import org.neo4j.gds.metrics.procedures.DeprecatedProceduresMetricService; import org.neo4j.gds.procedures.GraphDataScienceProcedures; import org.neo4j.gds.procedures.GraphDataScienceProceduresBuilder; +import org.neo4j.gds.procedures.KernelTransactionAccessor; +import org.neo4j.gds.procedures.TaskRegistryFactoryService; +import org.neo4j.gds.procedures.TerminationFlagAccessor; +import org.neo4j.gds.services.DatabaseIdAccessor; +import org.neo4j.gds.services.UserAccessor; +import org.neo4j.gds.services.UserLogServices; +import org.neo4j.gds.termination.TerminationFlag; import org.neo4j.internal.kernel.api.exceptions.ProcedureException; import org.neo4j.kernel.api.procedure.Context; +import java.util.Optional; +import java.util.function.Function; + /** * We use this at request time to construct the facade that the procedures call. */ public class GraphDataScienceProvider implements ThrowingFunction { + private final DatabaseIdAccessor databaseIdAccessor = new DatabaseIdAccessor(); + private final KernelTransactionAccessor kernelTransactionAccessor = new KernelTransactionAccessor(); + private final TerminationFlagAccessor terminationFlagAccessor = new TerminationFlagAccessor(); + private final UserAccessor userAccessor = new UserAccessor(); + private final Log log; private final CatalogFacadeProvider catalogFacadeProvider; private final AlgorithmFacadeFactoryProvider algorithmFacadeFactoryProvider; private final DeprecatedProceduresMetricService deprecatedProceduresMetricService; private final PipelinesProcedureFacadeProvider pipelinesProcedureFacadeProvider = new PipelinesProcedureFacadeProvider(); + private final ExporterBuildersProviderService exporterBuildersProviderService; + private final TaskRegistryFactoryService taskRegistryFactoryService; + private final UserLogServices userLogServices; + private final GraphStoreCatalogService graphStoreCatalogService; + private final Optional> algorithmProcessingTemplateDecorator; + private final MemoryGauge memoryGauge; + private final boolean useMaxMemoryEstimation; + private final AlgorithmMetricsService algorithmMetricsService; GraphDataScienceProvider( Log log, CatalogFacadeProvider catalogFacadeProvider, AlgorithmFacadeFactoryProvider algorithmFacadeFactoryProvider, - DeprecatedProceduresMetricService deprecatedProceduresMetricService + DeprecatedProceduresMetricService deprecatedProceduresMetricService, + ExporterBuildersProviderService exporterBuildersProviderService, + TaskRegistryFactoryService taskRegistryFactoryService, + UserLogServices userLogServices, GraphStoreCatalogService graphStoreCatalogService, + Optional> algorithmProcessingTemplateDecorator, + MemoryGauge memoryGauge, boolean useMaxMemoryEstimation, AlgorithmMetricsService algorithmMetricsService ) { this.log = log; this.catalogFacadeProvider = catalogFacadeProvider; this.algorithmFacadeFactoryProvider = algorithmFacadeFactoryProvider; this.deprecatedProceduresMetricService = deprecatedProceduresMetricService; + this.exporterBuildersProviderService = exporterBuildersProviderService; + this.taskRegistryFactoryService = taskRegistryFactoryService; + this.userLogServices = userLogServices; + this.graphStoreCatalogService = graphStoreCatalogService; + this.algorithmProcessingTemplateDecorator = algorithmProcessingTemplateDecorator; + this.memoryGauge = memoryGauge; + this.useMaxMemoryEstimation = useMaxMemoryEstimation; + this.algorithmMetricsService = algorithmMetricsService; } @Override public GraphDataScienceProcedures apply(Context context) throws ProcedureException { + // with the context we can build the application layer before any of the procedure stuff + var graphDatabaseService = context.graphDatabaseAPI(); + var kernelTransaction = kernelTransactionAccessor.getKernelTransaction(context); + + var databaseId = databaseIdAccessor.getDatabaseId(graphDatabaseService); + var terminationFlag = terminationFlagAccessor.createTerminationFlag(kernelTransaction); + var user = userAccessor.getUser(context.securityContext()); + + var taskRegistryFactory = taskRegistryFactoryService.getTaskRegistryFactory(databaseId, user); + var userLogRegistryFactory = userLogServices.getUserLogRegistryFactory(databaseId, user); + + var exportBuildersProvider = exporterBuildersProviderService.identifyExportBuildersProvider(graphDatabaseService); + var exporterContext = new ExporterContext.ProcedureContextWrapper(context); + var nodePropertyExporterBuilder = exportBuildersProvider.nodePropertyExporterBuilder(exporterContext); + var relationshipExporterBuilder = exportBuildersProvider.relationshipExporterBuilder(exporterContext); + var relationshipStreamExporterBuilder = exportBuildersProvider.relationshipStreamExporterBuilder(exporterContext); + + var graphLoaderContext = GraphLoaderContextProvider.buildGraphLoaderContext( + context, + databaseId, + taskRegistryFactory, + terminationFlag, + userLogRegistryFactory, + log + ); + var databaseGraphStoreEstimationService = new DatabaseGraphStoreEstimationService( + graphLoaderContext, + user + ); + + // this eventually goes below the fold, inside the application layer + var algorithmEstimationTemplate = new AlgorithmEstimationTemplate( + graphStoreCatalogService, + databaseId, + databaseGraphStoreEstimationService, + user + ); + + var algorithmProcessingTemplate = buildAlgorithmProcessingTemplate( + databaseId, + user + ); + + var applicationsFacade = buildApplicationLayer( + nodePropertyExporterBuilder, + relationshipExporterBuilder, + relationshipStreamExporterBuilder, + taskRegistryFactory, + terminationFlag, + userLogRegistryFactory, + algorithmProcessingTemplate, + algorithmEstimationTemplate + ); + var catalogFacade = catalogFacadeProvider.createCatalogFacade(context); - var algorithmFacadeFactory = algorithmFacadeFactoryProvider.createAlgorithmFacadeFactory(context); + var algorithmFacadeFactory = algorithmFacadeFactoryProvider.createAlgorithmFacadeFactory( + context, + nodePropertyExporterBuilder, + relationshipExporterBuilder, + taskRegistryFactory, + userLogRegistryFactory, + terminationFlag, + databaseId, + user, + kernelTransaction, + graphDatabaseService, + databaseGraphStoreEstimationService + ); var centralityProcedureFacade = algorithmFacadeFactory.createCentralityProcedureFacade(); var communityProcedureFacade = algorithmFacadeFactory.createCommunityProcedureFacade(); var miscAlgorithmsProcedureFacade = algorithmFacadeFactory.createMiscellaneousProcedureFacade(); var nodeEmbeddingsProcedureFacade = algorithmFacadeFactory.createNodeEmbeddingsProcedureFacade(); - var pathFindingProcedureFacade = algorithmFacadeFactory.createPathFindingProcedureFacade(); + var pathFindingProcedureFacade = algorithmFacadeFactory.createPathFindingProcedureFacade(applicationsFacade); var similarityProcedureFacade = algorithmFacadeFactory.createSimilarityProcedureFacade(); var pipelinesProcedureFacade = pipelinesProcedureFacadeProvider.createPipelinesProcedureFacade(context); @@ -75,4 +194,47 @@ public GraphDataScienceProcedures apply(Context context) throws ProcedureExcepti .with(deprecatedProceduresMetricService) .build(); } + + private AlgorithmProcessingTemplate buildAlgorithmProcessingTemplate( + DatabaseId databaseId, + User user + ) { + var memoryGuard = new DefaultMemoryGuard(log, useMaxMemoryEstimation, memoryGauge); + + var algorithmProcessingTemplate = new DefaultAlgorithmProcessingTemplate( + log, + algorithmMetricsService, + graphStoreCatalogService, + memoryGuard, + databaseId, + user + ); + + if (algorithmProcessingTemplateDecorator.isEmpty()) return algorithmProcessingTemplate; + + return algorithmProcessingTemplateDecorator.get().apply(algorithmProcessingTemplate); + } + + private ApplicationsFacade buildApplicationLayer( + NodePropertyExporterBuilder nodePropertyExporterBuilder, + RelationshipExporterBuilder relationshipExporterBuilder, + RelationshipStreamExporterBuilder relationshipStreamExporterBuilder, + TaskRegistryFactory taskRegistryFactory, + TerminationFlag terminationFlag, + UserLogRegistryFactory userLogRegistryFactory, + AlgorithmProcessingTemplate algorithmProcessingTemplate, + AlgorithmEstimationTemplate algorithmEstimationTemplate + ) { + return ApplicationsFacade.create( + log, + nodePropertyExporterBuilder, + relationshipExporterBuilder, + relationshipStreamExporterBuilder, + taskRegistryFactory, + terminationFlag, + userLogRegistryFactory, + algorithmProcessingTemplate, + algorithmEstimationTemplate + ); + } } diff --git a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/GraphDataScienceProviderFactory.java b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/GraphDataScienceProviderFactory.java index 8567f6838b..3d6df80449 100644 --- a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/GraphDataScienceProviderFactory.java +++ b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/GraphDataScienceProviderFactory.java @@ -94,16 +94,22 @@ GraphDataScienceProvider createGraphDataScienceProvider( defaultsConfiguration, graphStoreCatalogService, limitsConfiguration, - taskRegistryFactoryService, - useMaxMemoryEstimation, - userLogServices + useMaxMemoryEstimation ); return new GraphDataScienceProvider( log, catalogFacadeProvider, algorithmFacadeService, - metricsFacade.deprecatedProcedures() + metricsFacade.deprecatedProcedures(), + exporterBuildersProviderService, + taskRegistryFactoryService, + userLogServices, + graphStoreCatalogService, + algorithmProcessingTemplateDecorator, + memoryGauge, + useMaxMemoryEstimation, + metricsFacade.algorithmMetrics() ); } @@ -138,9 +144,7 @@ private AlgorithmFacadeFactoryProvider createAlgorithmService( DefaultsConfiguration defaultsConfiguration, GraphStoreCatalogService graphStoreCatalogService, LimitsConfiguration limitsConfiguration, - TaskRegistryFactoryService taskRegistryFactoryService, - boolean useMaxMemoryEstimation, - UserLogServices userLogServices + boolean useMaxMemoryEstimation ) { // Defaults and limits is a big shared thing (or, will be) var configurationParser = new ConfigurationParser(defaultsConfiguration, limitsConfiguration); @@ -152,14 +156,9 @@ private AlgorithmFacadeFactoryProvider createAlgorithmService( defaultsConfiguration, graphStoreCatalogService, limitsConfiguration, - memoryGauge, useMaxMemoryEstimation, metricsFacade.algorithmMetrics(), - exporterBuildersProviderService, - modelCatalogServiceProvider, - taskRegistryFactoryService, - userLogServices, - algorithmProcessingTemplateDecorator + modelCatalogServiceProvider ); } }