Skip to content

Commit

Permalink
first pass alphabetising/ categorising
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Aug 16, 2024
1 parent ff1fc09 commit d4771e2
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.neo4j.gds.metrics.MetricsFacade;
import org.neo4j.gds.procedures.ExporterBuildersProviderService;
import org.neo4j.gds.procedures.integration.ExportLocation;
import org.neo4j.gds.procedures.integration.GraphDataScienceExtensionBuilder;
import org.neo4j.gds.procedures.integration.OpenGraphDataScienceExtensionBuilder;
import org.neo4j.gds.procedures.integration.LogAccessor;
import org.neo4j.kernel.api.procedure.GlobalProcedures;
import org.neo4j.kernel.extension.ExtensionFactory;
Expand All @@ -51,30 +51,28 @@ public OpenGraphDataScienceExtension() {
@Override
public Lifecycle newInstance(ExtensionContext extensionContext, Dependencies dependencies) {
var log = new LogAccessor().getLog(dependencies.logService(), getClass());
var globalProcedures = dependencies.globalProcedures();
var neo4jConfiguration = dependencies.config();

// OpenGDS edition customisations go here
ExporterBuildersProviderService exporterBuildersProviderService = (__, ___) -> new NativeExportBuildersProvider(); // we always just offer native writes in OpenGDS
var exportLocation = ExportLocation.create(neo4jConfiguration);
var metricsFacade = MetricsFacade.PASSTHROUGH_METRICS_FACADE; // no metrics in OpenGDS
var modelCatalog = new OpenModelCatalogProvider().get(null);

var graphSageModelRepository = new DisableModelRepository(); // no model storing in OpenGDS

var neo4jConfiguration = dependencies.config();

var exportLocation = ExportLocation.create(neo4jConfiguration);

var graphDataScienceExtensionBuilderAndAssociatedProducts = GraphDataScienceExtensionBuilder.create(
var graphDataScienceExtensionBuilderAndAssociatedProducts = OpenGraphDataScienceExtensionBuilder.create(
log,
globalProcedures,
neo4jConfiguration,
dependencies.globalProcedures(),
exportLocation,
Optional.empty(), // no extra checks in OpenGDS
Optional.empty(), // no extra checks in OpenGDS
Optional.empty(), // no extra checks in OpenGDS
exporterBuildersProviderService,
exportLocation,
metricsFacade,
modelCatalog,
graphSageModelRepository
graphSageModelRepository,
Optional.empty(), // no extra checks in OpenGDS
Optional.empty(), // no extra checks in OpenGDS
Optional.empty() // no extra checks in OpenGDS
);

var graphDataScienceExtensionBuilder = graphDataScienceExtensionBuilderAndAssociatedProducts.getLeft();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
/**
* We use this at request time to construct the facade that the procedures call.
*/
public class GraphDataScienceProvider implements ThrowingFunction<Context, GraphDataScienceProcedures, ProcedureException> {
public class GraphDataScienceProceduresProvider implements ThrowingFunction<Context, GraphDataScienceProcedures, ProcedureException> {
private final AlgorithmMetaDataSetterService algorithmMetaDataSetterService = new AlgorithmMetaDataSetterService();
private final DatabaseIdAccessor databaseIdAccessor = new DatabaseIdAccessor();
private final KernelTransactionAccessor kernelTransactionAccessor = new KernelTransactionAccessor();
Expand All @@ -71,71 +71,75 @@ public class GraphDataScienceProvider implements ThrowingFunction<Context, Graph
private final UserAccessor userAccessor = new UserAccessor();

private final Log log;
private final DefaultsConfiguration defaultsConfiguration;
private final LimitsConfiguration limitsConfiguration;
private final AlgorithmProcedureFacadeBuilderFactory algorithmProcedureFacadeBuilderFactory;
private final Configuration neo4jConfiguration;

private final AlgorithmMetricsService algorithmMetricsService;
private final Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator;
private final Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator;
private final Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator;
private final GraphCatalogProcedureFacadeFactory graphCatalogProcedureFacadeFactory;
private final AlgorithmProcedureFacadeBuilderFactory algorithmProcedureFacadeBuilderFactory;
private final DefaultsConfiguration defaultsConfiguration;
private final DeprecatedProceduresMetricService deprecatedProceduresMetricService;
private final ExporterBuildersProviderService exporterBuildersProviderService;
private final Supplier<Path> exportLocation;
private final GraphCatalogProcedureFacadeFactory graphCatalogProcedureFacadeFactory;
private final GraphStoreCatalogService graphStoreCatalogService;
private final LimitsConfiguration limitsConfiguration;
private final MemoryGuard memoryGuard;
private final ModelCatalog modelCatalog;
private final ModelRepository modelRepository;
private final ProjectionMetricsService projectionMetricsService;
private final TaskRegistryFactoryService taskRegistryFactoryService;
private final TaskStoreService taskStoreService;
private final UserLogServices userLogServices;
private final Configuration neo4jConfiguration;
private final ModelCatalog modelCatalog;
private final ModelRepository modelRepository;
private final Supplier<Path> exportLocation;

GraphDataScienceProvider(
private final Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator;
private final Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator;
private final Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator;

GraphDataScienceProceduresProvider(
Log log,
DefaultsConfiguration defaultsConfiguration,
LimitsConfiguration limitsConfiguration,
AlgorithmProcedureFacadeBuilderFactory algorithmProcedureFacadeBuilderFactory,
Configuration neo4jConfiguration,
AlgorithmMetricsService algorithmMetricsService,
Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator,
Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator,
Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator,
GraphCatalogProcedureFacadeFactory graphCatalogProcedureFacadeFactory,
AlgorithmProcedureFacadeBuilderFactory algorithmProcedureFacadeBuilderFactory,
DefaultsConfiguration defaultsConfiguration,
DeprecatedProceduresMetricService deprecatedProceduresMetricService,
ExporterBuildersProviderService exporterBuildersProviderService,
Supplier<Path> exportLocation,
GraphCatalogProcedureFacadeFactory graphCatalogProcedureFacadeFactory,
GraphStoreCatalogService graphStoreCatalogService,
LimitsConfiguration limitsConfiguration,
MemoryGuard memoryGuard,
ModelCatalog modelCatalog,
ModelRepository modelRepository,
ProjectionMetricsService projectionMetricsService,
TaskRegistryFactoryService taskRegistryFactoryService,
TaskStoreService taskStoreService,
UserLogServices userLogServices,
Configuration neo4jConfiguration,
ModelCatalog modelCatalog,
ModelRepository modelRepository,
Supplier<Path> exportLocation
Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator,
Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator,
Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator
) {
this.log = log;
this.defaultsConfiguration = defaultsConfiguration;
this.limitsConfiguration = limitsConfiguration;
this.algorithmProcedureFacadeBuilderFactory = algorithmProcedureFacadeBuilderFactory;
this.neo4jConfiguration = neo4jConfiguration;

this.algorithmMetricsService = algorithmMetricsService;
this.algorithmProcessingTemplateDecorator = algorithmProcessingTemplateDecorator;
this.graphCatalogApplicationsDecorator = graphCatalogApplicationsDecorator;
this.modelCatalogApplicationsDecorator = modelCatalogApplicationsDecorator;
this.graphCatalogProcedureFacadeFactory = graphCatalogProcedureFacadeFactory;
this.algorithmProcedureFacadeBuilderFactory = algorithmProcedureFacadeBuilderFactory;
this.defaultsConfiguration = defaultsConfiguration;
this.deprecatedProceduresMetricService = deprecatedProceduresMetricService;
this.exporterBuildersProviderService = exporterBuildersProviderService;
this.exportLocation = exportLocation;
this.graphCatalogProcedureFacadeFactory = graphCatalogProcedureFacadeFactory;
this.graphStoreCatalogService = graphStoreCatalogService;
this.limitsConfiguration = limitsConfiguration;
this.memoryGuard = memoryGuard;
this.modelCatalog = modelCatalog;
this.modelRepository = modelRepository;
this.projectionMetricsService = projectionMetricsService;
this.taskRegistryFactoryService = taskRegistryFactoryService;
this.taskStoreService = taskStoreService;
this.userLogServices = userLogServices;
this.neo4jConfiguration = neo4jConfiguration;
this.modelCatalog = modelCatalog;
this.modelRepository = modelRepository;
this.exportLocation = exportLocation;

this.algorithmProcessingTemplateDecorator = algorithmProcessingTemplateDecorator;
this.graphCatalogApplicationsDecorator = graphCatalogApplicationsDecorator;
this.modelCatalogApplicationsDecorator = modelCatalogApplicationsDecorator;
}

@Override
Expand All @@ -147,7 +151,7 @@ public GraphDataScienceProcedures apply(Context context) throws ProcedureExcepti
var graphDatabaseService = context.graphDatabaseAPI();
var databaseId = databaseIdAccessor.getDatabaseId(graphDatabaseService);

var writeContext = constructWriteContext(context, graphDatabaseService);
var writeContext = createWriteContext(context, graphDatabaseService);

var procedureReturnColumns = new ProcedureCallContextReturnColumns(procedureCallContext);
var terminationFlag = terminationFlagAccessor.createTerminationFlag(kernelTransaction);
Expand Down Expand Up @@ -207,7 +211,7 @@ public GraphDataScienceProcedures apply(Context context) throws ProcedureExcepti
);
}

private WriteContext constructWriteContext(Context context, GraphDatabaseService graphDatabaseService) {
private WriteContext createWriteContext(Context context, GraphDatabaseService graphDatabaseService) {
var exportBuildersProvider = exporterBuildersProviderService.identifyExportBuildersProvider(
graphDatabaseService,
neo4jConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,57 +48,57 @@
* This is a way to squirrel away some dull code.
* We want to keep Neo4j out from here, this could be reusable.
*/
final class GraphDataScienceProviderFactory {
final class GraphDataScienceProceduresProviderFactory {
/**
* These are currently global singletons; when they seize to be, this is the place to initialise them.
* They are similar in lifecycle to {@link org.neo4j.gds.core.loading.GraphStoreCatalogService}
*/
private final DefaultsConfiguration defaultsConfiguration = DefaultsConfiguration.Instance;
private final LimitsConfiguration limitsConfiguration = LimitsConfiguration.Instance;

private final Log log;

// Graph catalog state initialised here, currently just a front for a big shared singleton
private final GraphStoreCatalogService graphStoreCatalogService = new GraphStoreCatalogService();

private final Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator;
private final Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator;
private final Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator;
private final Log log;

private final Configuration neo4jConfiguration;
private final ExporterBuildersProviderService exporterBuildersProviderService;
private final Supplier<Path> exportLocation;
private final MemoryGauge memoryGauge;
private final MetricsFacade metricsFacade;
private final ModelCatalog modelCatalog;
private final Configuration neo4jConfiguration;
private final ModelRepository modelRepository;
private final Supplier<Path> exportLocation;
private final Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator;
private final Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator;
private final Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator;

private GraphDataScienceProviderFactory(
GraphDataScienceProceduresProviderFactory(
Log log,
Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator,
Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator,
Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator,
Configuration neo4jConfiguration,
ExporterBuildersProviderService exporterBuildersProviderService,
Supplier<Path> exportLocation,
MemoryGauge memoryGauge,
MetricsFacade metricsFacade,
ModelCatalog modelCatalog,
Configuration neo4jConfiguration,
ModelRepository modelRepository,
Supplier<Path> exportLocation
Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator,
Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator,
Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator
) {
this.log = log;
this.algorithmProcessingTemplateDecorator = algorithmProcessingTemplateDecorator;
this.graphCatalogApplicationsDecorator = graphCatalogApplicationsDecorator;
this.modelCatalogApplicationsDecorator = modelCatalogApplicationsDecorator;
this.neo4jConfiguration = neo4jConfiguration;
this.exporterBuildersProviderService = exporterBuildersProviderService;
this.exportLocation = exportLocation;
this.memoryGauge = memoryGauge;
this.metricsFacade = metricsFacade;
this.modelCatalog = modelCatalog;
this.neo4jConfiguration = neo4jConfiguration;
this.modelRepository = modelRepository;
this.exportLocation = exportLocation;
this.algorithmProcessingTemplateDecorator = algorithmProcessingTemplateDecorator;
this.graphCatalogApplicationsDecorator = graphCatalogApplicationsDecorator;
this.modelCatalogApplicationsDecorator = modelCatalogApplicationsDecorator;
}

GraphDataScienceProvider createGraphDataScienceProvider(
GraphDataScienceProceduresProvider createGraphDataScienceProvider(
TaskRegistryFactoryService taskRegistryFactoryService,
TaskStoreService taskStoreService,
boolean useMaxMemoryEstimation,
Expand All @@ -112,56 +112,28 @@ GraphDataScienceProvider createGraphDataScienceProvider(

var memoryGuard = new DefaultMemoryGuard(log, useMaxMemoryEstimation, memoryGauge);

return new GraphDataScienceProvider(
return new GraphDataScienceProceduresProvider(
log,
defaultsConfiguration,
limitsConfiguration,
algorithmFacadeBuilderFactory,
neo4jConfiguration,
metricsFacade.algorithmMetrics(),
algorithmProcessingTemplateDecorator,
graphCatalogApplicationsDecorator,
modelCatalogApplicationsDecorator,
catalogProcedureFacadeFactory,
algorithmFacadeBuilderFactory,
defaultsConfiguration,
metricsFacade.deprecatedProcedures(),
exporterBuildersProviderService,
exportLocation,
catalogProcedureFacadeFactory,
graphStoreCatalogService,
limitsConfiguration,
memoryGuard,
modelCatalog,
modelRepository,
metricsFacade.projectionMetrics(),
taskRegistryFactoryService,
taskStoreService,
userLogServices,
neo4jConfiguration,
modelCatalog,
modelRepository,
exportLocation
);
}

static GraphDataScienceProviderFactory create(
Log log,
Supplier<Path> exportLocation,
Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator,
Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator,
Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator,
ExporterBuildersProviderService exporterBuildersProviderService,
MemoryGauge memoryGauge,
MetricsFacade metricsFacade,
ModelCatalog modelCatalog,
Configuration neo4jConfiguration,
ModelRepository modelRepository
) {
return new GraphDataScienceProviderFactory(
log,
algorithmProcessingTemplateDecorator,
graphCatalogApplicationsDecorator,
modelCatalogApplicationsDecorator,
exporterBuildersProviderService,
memoryGauge,
metricsFacade,
modelCatalog,
neo4jConfiguration,
modelRepository,
exportLocation
modelCatalogApplicationsDecorator
);
}

Expand Down
Loading

0 comments on commit d4771e2

Please sign in to comment.