Skip to content

Commit

Permalink
move algorithms facade scaffolding from into procedure facade factory…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
lassewesth committed May 27, 2024
1 parent 16819e8 commit fdbe655
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import org.neo4j.gds.BaseTest;
import org.neo4j.gds.GdsCypher;
import org.neo4j.gds.NodeProjections;
import org.neo4j.gds.ProcedureCallContextReturnColumns;
import org.neo4j.gds.RelationshipProjections;
import org.neo4j.gds.api.AlgorithmMetaDataSetter;
import org.neo4j.gds.api.CloseableResourceRegistry;
import org.neo4j.gds.api.DatabaseId;
import org.neo4j.gds.api.NodeLookup;
import org.neo4j.gds.api.ProcedureReturnColumns;
import org.neo4j.gds.catalog.GraphProjectProc;
import org.neo4j.gds.compat.GraphDatabaseApiProxy;
import org.neo4j.gds.compat.Neo4jProxy;
Expand Down Expand Up @@ -75,7 +75,7 @@ void setup() throws Exception {
.builder()
.databaseId(DatabaseId.of(db.databaseName()))
.dependencyResolver(GraphDatabaseApiProxy.dependencyResolver(db))
.returnColumns(ProcedureCallContextReturnColumns.EMPTY)
.returnColumns(ProcedureReturnColumns.EMPTY)
.log(Neo4jProxy.testLog())
.taskRegistryFactory(EmptyTaskRegistryFactory.INSTANCE)
.userLogRegistryFactory(EmptyUserLogRegistryFactory.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.neo4j.gds.ProcedureCallContextReturnColumns;
import org.neo4j.gds.api.AlgorithmMetaDataSetter;
import org.neo4j.gds.api.CloseableResourceRegistry;
import org.neo4j.gds.api.GraphStore;
import org.neo4j.gds.api.NodeLookup;
import org.neo4j.gds.api.ProcedureReturnColumns;
import org.neo4j.gds.compat.Neo4jProxy;
import org.neo4j.gds.config.GraphProjectConfig;
import org.neo4j.gds.core.loading.GraphStoreCatalog;
Expand Down Expand Up @@ -133,7 +133,7 @@ private ExecutionContext executionContext(TaskStore taskStore) {
.builder()
.databaseId(graphStore.databaseInfo().databaseId())
.log(Neo4jProxy.testLog())
.returnColumns(ProcedureCallContextReturnColumns.EMPTY)
.returnColumns(ProcedureReturnColumns.EMPTY)
.taskRegistryFactory(jobId -> new TaskRegistry("", taskStore, jobId))
.username("")
.terminationMonitor(TerminationMonitor.EMPTY)
Expand Down
1 change: 1 addition & 0 deletions proc/common/src/main/java/org/neo4j/gds/BaseProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.neo4j.gds.procedures.GraphDataScienceProcedures;
import org.neo4j.gds.procedures.ProcedureCallContextReturnColumns;
import org.neo4j.gds.procedures.TransactionCloseableResourceRegistry;
import org.neo4j.gds.procedures.TransactionNodeLookup;
import org.neo4j.gds.procedures.integration.TransactionTerminationMonitor;
import org.neo4j.gds.transaction.DatabaseTransactionContext;
import org.neo4j.gds.transaction.EmptyTransactionContext;
Expand Down
1 change: 1 addition & 0 deletions proc/test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
implementation project(':neo4j-api')
implementation project(':opengds-procedure-facade')
implementation project(':open-licensing')
implementation project(':open-model-catalog')
implementation project(':pregel')
implementation project(':procedure-integration')
implementation project(':progress-tracking')
Expand Down
118 changes: 0 additions & 118 deletions proc/test/src/main/java/org/neo4j/gds/FakeSecurityContext.java

This file was deleted.

39 changes: 37 additions & 2 deletions proc/test/src/main/java/org/neo4j/gds/ProcedureRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@
import org.neo4j.gds.configuration.LimitsConfiguration;
import org.neo4j.gds.core.Username;
import org.neo4j.gds.core.loading.GraphStoreCatalogService;
import org.neo4j.gds.core.model.OpenModelCatalog;
import org.neo4j.gds.core.utils.progress.TaskRegistryFactory;
import org.neo4j.gds.core.utils.warnings.EmptyUserLogRegistryFactory;
import org.neo4j.gds.core.utils.warnings.UserLogRegistryFactory;
import org.neo4j.gds.core.write.ExporterContext;
import org.neo4j.gds.core.write.NativeExportBuildersProvider;
import org.neo4j.gds.metrics.MetricsFacade;
import org.neo4j.gds.metrics.PassthroughExecutionMetricRegistrar;
import org.neo4j.gds.metrics.algorithms.AlgorithmMetricsService;
import org.neo4j.gds.metrics.procedures.DeprecatedProceduresMetricService;
import org.neo4j.gds.modelcatalogservices.ModelCatalogServiceProvider;
import org.neo4j.gds.procedures.AlgorithmFacadeBuilderFactory;
import org.neo4j.gds.procedures.CatalogProcedureFacadeFactory;
import org.neo4j.gds.procedures.GraphDataScienceProcedures;
import org.neo4j.gds.procedures.TaskRegistryFactoryService;
Expand All @@ -47,6 +53,8 @@
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.internal.kernel.api.procs.ProcedureCallContext;
import org.neo4j.internal.kernel.api.security.AuthSubject;
import org.neo4j.internal.kernel.api.security.AuthenticationResult;
import org.neo4j.internal.kernel.api.security.SecurityContext;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.impl.coreapi.InternalTransaction;
Expand Down Expand Up @@ -184,7 +192,22 @@ public TaskRegistryFactory getTaskRegistryFactory(DatabaseId databaseId, User us
new UserLogServices()
);

var securityContext = new FakeSecurityContext();
var securityContext = new SecurityContext(new AuthSubject() {
@Override
public AuthenticationResult getAuthenticationResult() {
throw new UnsupportedOperationException("TODO");
}

@Override
public boolean hasUsername(String username) {
throw new UnsupportedOperationException("TODO");
}

@Override
public String executingUser() {
return username.username();
}
}, null, null, null);

var exporterContext = new ExporterContext() {
@Override
Expand All @@ -203,6 +226,16 @@ public SecurityContext securityContext() {
}
};

var modelCatalog = new OpenModelCatalog();

var algorithmFacadeBuilderFactory = new AlgorithmFacadeBuilderFactory(
gdsLog,
graphStoreCatalogService,
false,
new AlgorithmMetricsService(new PassthroughExecutionMetricRegistrar()),
new ModelCatalogServiceProvider(modelCatalog)
);

return GraphDataScienceProcedures.create(
gdsLog,
DefaultsConfiguration.Instance,
Expand All @@ -220,7 +253,9 @@ public SecurityContext securityContext() {
securityContext,
exporterContext,
graphDatabaseService,
procedureTransaction
procedureTransaction,
algorithmFacadeBuilderFactory,
DeprecatedProceduresMetricService.PASSTHROUGH
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.gds.procedures.integration;
package org.neo4j.gds.procedures;

import org.neo4j.gds.algorithms.centrality.CentralityAlgorithmsEstimateBusinessFacade;
import org.neo4j.gds.algorithms.centrality.CentralityAlgorithmsFacade;
Expand Down Expand Up @@ -65,7 +65,7 @@
import org.neo4j.gds.procedures.embeddings.NodeEmbeddingsProcedureFacade;
import org.neo4j.gds.procedures.misc.MiscAlgorithmsProcedureFacade;

class AlgorithmFacadeFactory {
class AlgorithmFacadeBuilder {
// Request scoped parameters
private final ConfigurationCreator configurationCreator;
private final NodeLookup nodeLookup;
Expand All @@ -82,7 +82,7 @@ class AlgorithmFacadeFactory {
private final StatsModeAlgorithmRunner statsModeAlgorithmRunner;
private final WriteModeAlgorithmRunner writeModeAlgorithmRunner;

AlgorithmFacadeFactory(
AlgorithmFacadeBuilder(
ConfigurationCreator configurationCreator,
NodeLookup nodeLookup,
ProcedureReturnColumns procedureReturnColumns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.gds.procedures.integration;
package org.neo4j.gds.procedures;

import org.neo4j.gds.procedures.ProcedureCallContextReturnColumns;
import org.neo4j.gds.procedures.TransactionCloseableResourceRegistry;
import org.neo4j.gds.TransactionNodeLookup;
import org.neo4j.gds.algorithms.AlgorithmMemoryValidationService;
import org.neo4j.gds.algorithms.estimation.AlgorithmEstimator;
import org.neo4j.gds.algorithms.mutateservices.MutateNodePropertyService;
Expand All @@ -42,10 +39,10 @@
import org.neo4j.gds.procedures.algorithms.runners.WriteModeAlgorithmRunner;
import org.neo4j.gds.procedures.algorithms.stubs.GenericStub;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.internal.kernel.api.procs.ProcedureCallContext;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.procedure.Context;

class AlgorithmFacadeFactoryProvider {
public class AlgorithmFacadeBuilderFactory {
// dull utilities
private final FictitiousGraphStoreEstimationService fictitiousGraphStoreEstimationService = new FictitiousGraphStoreEstimationService();

Expand All @@ -58,7 +55,7 @@ class AlgorithmFacadeFactoryProvider {
private final AlgorithmMetricsService algorithmMetricsService;
private final ModelCatalogServiceProvider modelCatalogServiceProvider;

AlgorithmFacadeFactoryProvider(
public AlgorithmFacadeBuilderFactory(
Log log,
GraphStoreCatalogService graphStoreCatalogService,
boolean useMaxMemoryEstimation,
Expand All @@ -73,15 +70,15 @@ class AlgorithmFacadeFactoryProvider {
this.modelCatalogServiceProvider = modelCatalogServiceProvider;
}

AlgorithmFacadeFactory createAlgorithmFacadeFactory(
Context context,
AlgorithmFacadeBuilder create(
ConfigurationCreator configurationCreator,
RequestScopedDependencies requestScopedDependencies,
KernelTransaction kernelTransaction,
GraphDatabaseService graphDatabaseService,
DatabaseGraphStoreEstimationService databaseGraphStoreEstimationService,
ApplicationsFacade applicationsFacade,
GenericStub genericStub
GenericStub genericStub,
ProcedureCallContext procedureCallContext
) {
/*
* GDS services derived from Procedure Context.
Expand All @@ -92,7 +89,7 @@ AlgorithmFacadeFactory createAlgorithmFacadeFactory(
var algorithmMemoryValidationService = new AlgorithmMemoryValidationService(log, useMaxMemoryEstimation);
var mutateNodePropertyService = new MutateNodePropertyService(log);
var nodeLookup = new TransactionNodeLookup(kernelTransaction);
var procedureReturnColumns = new ProcedureCallContextReturnColumns(context.procedureCallContext());
var procedureReturnColumns = new ProcedureCallContextReturnColumns(procedureCallContext);

// Second layer
var writeNodePropertyService = new WriteNodePropertyService(log, requestScopedDependencies);
Expand All @@ -119,7 +116,7 @@ AlgorithmFacadeFactory createAlgorithmFacadeFactory(
var writeModeAlgorithmRunner = new WriteModeAlgorithmRunner(configurationCreator);

// procedure facade
return new AlgorithmFacadeFactory(
return new AlgorithmFacadeBuilder(
configurationCreator,
nodeLookup,
procedureReturnColumns,
Expand Down
Loading

0 comments on commit fdbe655

Please sign in to comment.