Skip to content

Commit

Permalink
Merge pull request #9455 from lassewesth/modgra1
Browse files Browse the repository at this point in the history
add modules for graph catalog and model catalog, and populate them
  • Loading branch information
lassewesth authored Aug 7, 2024
2 parents 6feafa0 + b91afec commit ec4e9f4
Show file tree
Hide file tree
Showing 85 changed files with 1,139 additions and 393 deletions.
2 changes: 2 additions & 0 deletions alpha/alpha-proc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ dependencies {
implementation project(':core-utils')
implementation project(':core-write')
implementation project(':executor')
implementation project(':graph-catalog-procedure-facade')
implementation project(':legacy-cypher-projection')
implementation project(':memory-usage')
implementation project(':neo4j-api')
implementation project(':operations-procedure-facade')
implementation project(':opengds-procedure-facade')
implementation project(':pregel')
implementation project(':proc-catalog')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public UserLogProc() {}
@Procedure("gds.userLog")
@Description("Log warnings and hints for currently running tasks.")
public Stream<UserLogEntry> queryUserLog(@Name(value = "jobId", defaultValue = "") String jobId) {
return facade.catalog().queryUserLog(jobId);
return facade.operations().queryUserLog(jobId);
}

@Procedure(value = "gds.alpha.userLog", deprecatedBy = "gds.userLog")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.neo4j.gds.core.utils.progress.tasks.LeafTask;
import org.neo4j.gds.core.utils.warnings.UserLogEntry;
import org.neo4j.gds.procedures.GraphDataScienceProcedures;
import org.neo4j.gds.procedures.catalog.CatalogProcedureFacade;
import org.neo4j.gds.procedures.operations.OperationsProcedureFacade;

import java.util.stream.Stream;

Expand All @@ -43,9 +43,9 @@ void shouldLogUserWarnings() {
new UserLogEntry(new LeafTask("lt", 87), "going twice..."),
new UserLogEntry(new LeafTask("lt", 23), "gone!")
);
var catalogFacade = mock(CatalogProcedureFacade.class);
when(facade.catalog()).thenReturn(catalogFacade);
when(catalogFacade.queryUserLog("unused")).thenReturn(expectedWarnings);
var operationsProcedureFacade = mock(OperationsProcedureFacade.class);
when(facade.operations()).thenReturn(operationsProcedureFacade);
when(operationsProcedureFacade.queryUserLog("unused")).thenReturn(expectedWarnings);
var actualWarnings = userLogProc.queryUserLog("unused");

assertThat(actualWarnings).isSameAs(expectedWarnings);
Expand Down
2 changes: 2 additions & 0 deletions applications/facade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ dependencies {
implementation project(":memory-estimation")
implementation project(":metrics-api")
implementation project(":model-catalog-api")
implementation project(":model-catalog-applications")
implementation project(":miscellaneous-algorithms")
implementation project(":node-embedding-algorithms")
implementation project(":operations-applications")
implementation project(":path-finding-algorithms")
implementation project(":progress-tracking")
implementation project(":similarity-algorithms")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
import org.neo4j.gds.applications.algorithms.miscellaneous.MiscellaneousApplications;
import org.neo4j.gds.applications.algorithms.pathfinding.PathFindingApplications;
import org.neo4j.gds.applications.algorithms.similarity.SimilarityApplications;
import org.neo4j.gds.applications.graphstorecatalog.CatalogBusinessFacade;
import org.neo4j.gds.applications.graphstorecatalog.DefaultCatalogBusinessFacade;
import org.neo4j.gds.applications.graphstorecatalog.DefaultGraphCatalogApplications;
import org.neo4j.gds.applications.graphstorecatalog.GraphCatalogApplications;
import org.neo4j.gds.applications.modelcatalog.DefaultModelCatalogApplications;
import org.neo4j.gds.applications.modelcatalog.ModelCatalogApplications;
import org.neo4j.gds.applications.operations.OperationsApplications;
import org.neo4j.gds.core.loading.GraphStoreCatalogService;
import org.neo4j.gds.core.model.ModelCatalog;
import org.neo4j.gds.logging.Log;
Expand All @@ -56,28 +59,34 @@
* and we apply a breakdown into sub-facades to keep things smaller and more manageable.
*/
public final class ApplicationsFacade {
private final CatalogBusinessFacade catalogBusinessFacade;
private final CentralityApplications centralityApplications;
private final CommunityApplications communityApplications;
private final GraphCatalogApplications graphCatalogApplications;
private final MiscellaneousApplications miscellaneousApplications;
private final ModelCatalogApplications modelCatalogApplications;
private final NodeEmbeddingApplications nodeEmbeddingApplications;
private final OperationsApplications operationsApplications;
private final PathFindingApplications pathFindingApplications;
private final SimilarityApplications similarityApplications;

ApplicationsFacade(
CatalogBusinessFacade catalogBusinessFacade,
CentralityApplications centralityApplications,
CommunityApplications communityApplications,
GraphCatalogApplications graphCatalogApplications,
MiscellaneousApplications miscellaneousApplications,
ModelCatalogApplications modelCatalogApplications,
NodeEmbeddingApplications nodeEmbeddingApplications,
OperationsApplications operationsApplications,
PathFindingApplications pathFindingApplications,
SimilarityApplications similarityApplications
) {
this.catalogBusinessFacade = catalogBusinessFacade;
this.centralityApplications = centralityApplications;
this.communityApplications = communityApplications;
this.graphCatalogApplications = graphCatalogApplications;
this.miscellaneousApplications = miscellaneousApplications;
this.modelCatalogApplications = modelCatalogApplications;
this.nodeEmbeddingApplications = nodeEmbeddingApplications;
this.operationsApplications = operationsApplications;
this.pathFindingApplications = pathFindingApplications;
this.similarityApplications = similarityApplications;
}
Expand All @@ -88,7 +97,8 @@ public final class ApplicationsFacade {
public static ApplicationsFacade create(
Log log,
Optional<Function<AlgorithmProcessingTemplate, AlgorithmProcessingTemplate>> algorithmProcessingTemplateDecorator,
Optional<Function<CatalogBusinessFacade, CatalogBusinessFacade>> catalogBusinessFacadeDecorator,
Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator,
Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator,
GraphStoreCatalogService graphStoreCatalogService,
MemoryGuard memoryGuard,
AlgorithmMetricsService algorithmMetricsService,
Expand All @@ -98,13 +108,6 @@ public static ApplicationsFacade create(
ModelCatalog modelCatalog,
GraphSageModelRepository graphSageModelRepository
) {
var catalogBusinessFacade = createCatalogBusinessFacade(
log,
catalogBusinessFacadeDecorator,
graphStoreCatalogService,
projectionMetricsService
);

var databaseGraphStoreEstimationService = new DatabaseGraphStoreEstimationService(
requestScopedDependencies.getGraphLoaderContext(),
requestScopedDependencies.getUser()
Expand Down Expand Up @@ -149,13 +152,29 @@ public static ApplicationsFacade create(
mutateNodeProperty
);

var graphCatalogApplications = createGraphCatalogApplications(
log,
graphCatalogApplicationsDecorator,
graphStoreCatalogService,
projectionMetricsService
);

var miscellaneousApplications = MiscellaneousApplications.create(
log, requestScopedDependencies, writeContext, algorithmEstimationTemplate,
log,
requestScopedDependencies,
writeContext,
algorithmEstimationTemplate,
algorithmProcessingTemplateConvenience,
progressTrackerCreator,
mutateNodeProperty
);

var modelCatalogApplications = createModelCatalogApplications(
requestScopedDependencies,
modelCatalog,
modelCatalogApplicationsDecorator
);

var nodeEmbeddingApplications = NodeEmbeddingApplications.create(
log,
requestScopedDependencies,
Expand All @@ -168,6 +187,8 @@ public static ApplicationsFacade create(
graphSageModelRepository
);

var operationsApplications = OperationsApplications.create(requestScopedDependencies);

var pathFindingApplications = PathFindingApplications.create(
log,
requestScopedDependencies,
Expand All @@ -189,11 +210,13 @@ public static ApplicationsFacade create(
);

return new ApplicationsFacadeBuilder()
.with(catalogBusinessFacade)
.with(centralityApplications)
.with(communityApplications)
.with(graphCatalogApplications)
.with(miscellaneousApplications)
.with(modelCatalogApplications)
.with(nodeEmbeddingApplications)
.with(operationsApplications)
.with(pathFindingApplications)
.with(similarityApplications)
.build();
Expand All @@ -220,25 +243,36 @@ private static AlgorithmProcessingTemplate createAlgorithmProcessingTemplate(
return algorithmProcessingTemplateDecorator.get().apply(algorithmProcessingTemplate);
}

private static CatalogBusinessFacade createCatalogBusinessFacade(
private static GraphCatalogApplications createGraphCatalogApplications(
Log log,
Optional<Function<CatalogBusinessFacade, CatalogBusinessFacade>> catalogBusinessFacadeDecorator,
Optional<Function<GraphCatalogApplications, GraphCatalogApplications>> graphCatalogApplicationsDecorator,
GraphStoreCatalogService graphStoreCatalogService,
ProjectionMetricsService projectionMetricsService
) {
var catalogBusinessFacade = DefaultCatalogBusinessFacade.create(
var graphCatalogApplications = DefaultGraphCatalogApplications.create(
log,
graphStoreCatalogService,
projectionMetricsService
);

if (catalogBusinessFacadeDecorator.isEmpty()) return catalogBusinessFacade;
if (graphCatalogApplicationsDecorator.isEmpty()) return graphCatalogApplications;

return catalogBusinessFacadeDecorator.get().apply(catalogBusinessFacade);
return graphCatalogApplicationsDecorator.get().apply(graphCatalogApplications);
}

public CatalogBusinessFacade catalog() {
return catalogBusinessFacade;
private static ModelCatalogApplications createModelCatalogApplications(
RequestScopedDependencies requestScopedDependencies,
ModelCatalog modelCatalog,
Optional<Function<ModelCatalogApplications, ModelCatalogApplications>> modelCatalogApplicationsDecorator
) {
var modelCatalogApplications = DefaultModelCatalogApplications.create(
modelCatalog,
requestScopedDependencies.getUser()
);

if (modelCatalogApplicationsDecorator.isEmpty()) return modelCatalogApplications;

return modelCatalogApplicationsDecorator.get().apply(modelCatalogApplications);
}

public CentralityApplications centrality() {
Expand All @@ -249,14 +283,26 @@ public CommunityApplications community() {
return communityApplications;
}

public GraphCatalogApplications graphCatalog() {
return graphCatalogApplications;
}

public MiscellaneousApplications miscellaneous() {
return miscellaneousApplications;
}

public ModelCatalogApplications modelCatalog() {
return modelCatalogApplications;
}

public NodeEmbeddingApplications nodeEmbeddings() {
return nodeEmbeddingApplications;
}

public OperationsApplications operations() {
return operationsApplications;
}

public PathFindingApplications pathFinding() {
return pathFindingApplications;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,24 @@
import org.neo4j.gds.applications.algorithms.miscellaneous.MiscellaneousApplications;
import org.neo4j.gds.applications.algorithms.pathfinding.PathFindingApplications;
import org.neo4j.gds.applications.algorithms.similarity.SimilarityApplications;
import org.neo4j.gds.applications.graphstorecatalog.CatalogBusinessFacade;
import org.neo4j.gds.applications.graphstorecatalog.GraphCatalogApplications;
import org.neo4j.gds.applications.modelcatalog.ModelCatalogApplications;
import org.neo4j.gds.applications.operations.OperationsApplications;

/**
* This is a helper that makes it easy to inject constituents, and to not have to inject all of them.
*/
public class ApplicationsFacadeBuilder {
private CatalogBusinessFacade catalogBusinessFacade;
private CentralityApplications centralityApplications;
private CommunityApplications communityApplications;
private GraphCatalogApplications graphCatalogApplications;
private MiscellaneousApplications miscellaneousApplications;
private ModelCatalogApplications modelCatalogApplications;
private NodeEmbeddingApplications nodeEmbeddingApplications;
private OperationsApplications operationsApplications;
private PathFindingApplications pathFindingApplications;
private SimilarityApplications similarityApplications;

public ApplicationsFacadeBuilder with(CatalogBusinessFacade catalogBusinessFacade) {
this.catalogBusinessFacade = catalogBusinessFacade;
return this;
}

public ApplicationsFacadeBuilder with(CentralityApplications centralityApplications) {
this.centralityApplications = centralityApplications;
return this;
Expand All @@ -54,16 +53,31 @@ public ApplicationsFacadeBuilder with(CommunityApplications communityApplication
return this;
}

public ApplicationsFacadeBuilder with(GraphCatalogApplications graphCatalogApplications) {
this.graphCatalogApplications = graphCatalogApplications;
return this;
}

public ApplicationsFacadeBuilder with(MiscellaneousApplications miscellaneousApplications) {
this.miscellaneousApplications = miscellaneousApplications;
return this;
}

public ApplicationsFacadeBuilder with(ModelCatalogApplications modelCatalogApplications) {
this.modelCatalogApplications = modelCatalogApplications;
return this;
}

public ApplicationsFacadeBuilder with(NodeEmbeddingApplications nodeEmbeddingApplications) {
this.nodeEmbeddingApplications = nodeEmbeddingApplications;
return this;
}

public ApplicationsFacadeBuilder with(OperationsApplications operationsApplications) {
this.operationsApplications = operationsApplications;
return this;
}

public ApplicationsFacadeBuilder with(PathFindingApplications pathFindingApplications) {
this.pathFindingApplications = pathFindingApplications;
return this;
Expand All @@ -76,11 +90,13 @@ public ApplicationsFacadeBuilder with(SimilarityApplications similarityApplicati

public ApplicationsFacade build() {
return new ApplicationsFacade(
catalogBusinessFacade,
centralityApplications,
communityApplications,
graphCatalogApplications,
miscellaneousApplications,
modelCatalogApplications,
nodeEmbeddingApplications,
operationsApplications,
pathFindingApplications,
similarityApplications
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
* Here we have just business logic: no Neo4j bits or other integration bits, just Java POJO things.
* <p>
* By nature business logic is going to be bespoke, so one method per logical thing.
* Take {@link DefaultCatalogBusinessFacade#graphExists(User, DatabaseId, String)} for example:
* Take {@link DefaultGraphCatalogApplications#graphExists(User, DatabaseId, String)} for example:
* pure expressed business logic that layers above will use in multiple places, but!
* Any marshalling happens in those layers, not here.
* <p>
Expand All @@ -72,7 +72,7 @@
* Ideally though this is a facade over many individual pieces of business logic in separate classes,
* or behind other facades (oh gosh turtles, turtles everywhere :scream:).
*/
public class DefaultCatalogBusinessFacade implements CatalogBusinessFacade {
public class DefaultGraphCatalogApplications implements GraphCatalogApplications {
private final CatalogConfigurationService catalogConfigurationService = new CatalogConfigurationService();
private final GraphStoreValidationService graphStoreValidationService = new GraphStoreValidationService();

Expand Down Expand Up @@ -105,7 +105,7 @@ public class DefaultCatalogBusinessFacade implements CatalogBusinessFacade {
private final EstimateCommonNeighbourAwareRandomWalkApplication estimateCommonNeighbourAwareRandomWalkApplication;
private final GenerateGraphApplication generateGraphApplication;

DefaultCatalogBusinessFacade(
DefaultGraphCatalogApplications(
Log log,
GraphStoreCatalogService graphStoreCatalogService,
ProjectionMetricsService projectionMetricsService,
Expand Down Expand Up @@ -157,7 +157,7 @@ public class DefaultCatalogBusinessFacade implements CatalogBusinessFacade {
this.generateGraphApplication = generateGraphApplication;
}

public static CatalogBusinessFacade create(
public static GraphCatalogApplications create(
Log log,
GraphStoreCatalogService graphStoreCatalogService,
ProjectionMetricsService projectionMetricsService
Expand Down Expand Up @@ -199,7 +199,7 @@ public static CatalogBusinessFacade create(
var writeRelationshipPropertiesApplication = new WriteRelationshipPropertiesApplication(log);
var writeRelationshipsApplication = new WriteRelationshipsApplication(log);

var catalogFacade = new DefaultCatalogBusinessFacadeBuilder()
return new DefaultGraphCatalogApplicationsBuilder()
.withLog(log)
.withGraphStoreCatalogService(graphStoreCatalogService)
.withProjectionMetricsService(projectionMetricsService)
Expand All @@ -224,8 +224,6 @@ public static CatalogBusinessFacade create(
.withWriteRelationshipPropertiesApplication(writeRelationshipPropertiesApplication)
.withWriteRelationshipsApplication(writeRelationshipsApplication)
.build();

return catalogFacade;
}

@Override
Expand Down
Loading

0 comments on commit ec4e9f4

Please sign in to comment.