Skip to content

Commit

Permalink
refactor: Rename graph repo manager classes to graph repo client clas…
Browse files Browse the repository at this point in the history
…ses (#1912)
  • Loading branch information
MichaelsJP authored Nov 26, 2024
2 parents 235586e + 534de87 commit 4acd9a1
Show file tree
Hide file tree
Showing 28 changed files with 336 additions and 335 deletions.
5 changes: 3 additions & 2 deletions docs/run-instance/configuration/how-to-configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,14 @@ The internal value for the specific profile wins over the user's `profile_defaul

The configured profile properties in `ors.engine.profiles.<profile>.build` (and `ors.engine.profile_default.build`)
are used to _build_ a graph.
openrouteservice stores these build properties in the file `graphs/<profile>/graph_info.yml` when a graph is computed.
openrouteservice stores these build properties in the file `graphs/<profile>/graph_build_info.yml` when a graph is
computed.

When openrouteservice is _loading_ an existing graph instead of building it,
the persisted build parameters are again loaded from this file,
locally configured build parameters for the affected routing profile are overridden.

Therefore, the file `graph_info.yml` must not be edited!
Therefore, the file `graph_build_info.yml` must not be edited!
The content of this file is also used for repository lookups by
the ([Graph Repo Client](/technical-details/graph-repo-client/index.md)).

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
public class GraphService {

// get this value from ors.engine.graph_management.enabled
@Value("${ors.engine.graph_management.enabled:false}")
private Boolean enabled = false;
private final Boolean enabled;

private final EngineProperties engineProperties;

Expand All @@ -34,8 +33,9 @@ public class GraphService {
private final AtomicBoolean isActivatingGraphs = new AtomicBoolean(true);

@Autowired
public GraphService(EngineProperties engineProperties) {
public GraphService(EngineProperties engineProperties, @Value("${ors.engine.graph_management.enabled:false}") Boolean enabled) {
this.engineProperties = engineProperties;
this.enabled = enabled;
}

public void addGraphManagerInstance(ORSGraphManager orsGraphManager) {
Expand Down
28 changes: 14 additions & 14 deletions ors-api/src/test/java/org/heigit/ors/apitests/ORSStartupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.heigit.ors.exceptions.ORSGraphFileManagerException;
import org.heigit.ors.routing.RoutingProfile;
import org.heigit.ors.routing.RoutingProfileManager;
import org.heigit.ors.routing.graphhopper.extensions.manage.GraphInfo;
import org.heigit.ors.routing.graphhopper.extensions.manage.GraphBuildInfo;
import org.junit.jupiter.api.Test;

import java.text.ParseException;
Expand All @@ -18,22 +18,22 @@ class ORSStartupTest extends ServiceTest {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

@Test
void testGraphInfoFilesWrittenCorrectly() throws ParseException, ORSGraphFileManagerException {
void testGraphBuildInfoFilesWrittenCorrectly() throws ParseException, ORSGraphFileManagerException {
RoutingProfileManager rpm = RoutingProfileManager.getInstance();
RoutingProfile profile = rpm.getRoutingProfile(EncoderNameEnum.DRIVING_CAR.getEncoderName());
GraphInfo graphInfo = profile.getGraphhopper().getOrsGraphManager().getActiveGraphInfo();
ProfileProperties profileProperties = graphInfo.getPersistedGraphInfo().getProfileProperties();
assertEquals(dateFormat.parse("2024-09-08T20:21:00+0000"), graphInfo.getPersistedGraphInfo().getOsmDate(), "graph_info should contain OSM data timestamp");
assertEquals(EncoderNameEnum.DRIVING_CAR, profileProperties.getEncoderName(), "Encoder name should be set in the graph_info");
assertTrue(profileProperties.getBuild().getElevation(), "Elevation should be set in the graph_info");
assertNull(profileProperties.getService().getMaximumDistance(), "Maximum distance should not be set in the graph_info");
assertNull(profileProperties.getBuild().getGtfsFile(), "GTFS file path settings should not be set in the graph_info");
assertTrue(profileProperties.getRepo().isEmpty(), "Repo settings should not be set in the graph_info");
assertTrue(profileProperties.getService().getExecution().isEmpty(), "Execution settings should not be set in the graph_info");
assertEquals("turn_costs=true|block_fords=false|use_acceleration=true|maximum_grade_level=1|conditional_access=true|conditional_speed=true", profileProperties.getBuild().getEncoderOptions().toString(), "Encoder options should be set in the graph_info");
assertFalse(profileProperties.getBuild().getPreparation().isEmpty(), "Preparation settings should be set in the graph_info");
GraphBuildInfo graphBuildInfo = profile.getGraphhopper().getOrsGraphManager().getActiveGraphBuildInfo();
ProfileProperties profileProperties = graphBuildInfo.getPersistedGraphBuildInfo().getProfileProperties();
assertEquals(dateFormat.parse("2024-09-08T20:21:00+0000"), graphBuildInfo.getPersistedGraphBuildInfo().getOsmDate(), "graph_build_info should contain OSM data timestamp");
assertEquals(EncoderNameEnum.DRIVING_CAR, profileProperties.getEncoderName(), "Encoder name should be set in the graph_build_info");
assertTrue(profileProperties.getBuild().getElevation(), "Elevation should be set in the graph_build_info");
assertNull(profileProperties.getService().getMaximumDistance(), "Maximum distance should not be set in the graph_build_info");
assertNull(profileProperties.getBuild().getGtfsFile(), "GTFS file path settings should not be set in the graph_build_info");
assertTrue(profileProperties.getRepo().isEmpty(), "Repo settings should not be set in the graph_build_info");
assertTrue(profileProperties.getService().getExecution().isEmpty(), "Execution settings should not be set in the graph_build_info");
assertEquals("turn_costs=true|block_fords=false|use_acceleration=true|maximum_grade_level=1|conditional_access=true|conditional_speed=true", profileProperties.getBuild().getEncoderOptions().toString(), "Encoder options should be set in the graph_build_info");
assertFalse(profileProperties.getBuild().getPreparation().isEmpty(), "Preparation settings should be set in the graph_build_info");
assertTrue(profileProperties.getBuild().getPreparation().getMethods().getCore().getEnabled(), "Preparation settings should contain enabled core method");
assertFalse(profileProperties.getBuild().getExtStorages().isEmpty(), "ExtStorages settings should be set in the graph_info");
assertFalse(profileProperties.getBuild().getExtStorages().isEmpty(), "ExtStorages settings should be set in the graph_build_info");
assertTrue(profileProperties.getBuild().getExtStorages().get("WayCategory").getEnabled(), "ExtStorages settings should contain enabled WayCategory storage");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public GraphHopper importOrLoad() {

ORSGraphHopper gh = (ORSGraphHopper) super.importOrLoad();

writeOrsGraphInfoFileIfNotExists(gh);
writeOrsGraphBuildInfoFileIfNotExists(gh);

if ((tmcEdges != null) && (osmId2EdgeIds != null)) {
java.nio.file.Path path = Paths.get(gh.getGraphHopperLocation(), "edges_ors_traffic");
Expand Down Expand Up @@ -211,8 +211,8 @@ public GraphHopper importOrLoad() {
return gh;
}

private void writeOrsGraphInfoFileIfNotExists(ORSGraphHopper gh) {
orsGraphManager.writeOrsGraphInfoFileIfNotExists(gh);
private void writeOrsGraphBuildInfoFileIfNotExists(ORSGraphHopper gh) {
orsGraphManager.writeOrsGraphBuildInfoFileIfNotExists(gh);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
@AllArgsConstructor
@Setter
@Accessors(chain = true)
public class GraphInfo {
public class GraphBuildInfo {

private URI remoteUri;
@Getter
private File localDirectory = null;
Logger logger = Logger.getLogger(GraphInfo.class.getName());
Logger logger = Logger.getLogger(GraphBuildInfo.class.getName());

@Getter
private PersistedGraphInfo persistedGraphInfo;
private PersistedGraphBuildInfo persistedGraphBuildInfo;

public GraphInfo withRemoteUrl(URL url) {
public GraphBuildInfo withRemoteUrl(URL url) {
try {
this.remoteUri = url.toURI();
} catch (URISyntaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ORSGraphManager {

private GraphManagementRuntimeProperties managementRuntimeProperties;
private ORSGraphFileManager orsGraphFileManager;
private ORSGraphRepoManager orsGraphRepoManager;
private ORSGraphRepoClient orsGraphRepoClient;

public static ORSGraphManager initializeGraphManagement(String graphVersion, EngineProperties engineProperties, ProfileProperties profileProperties) {
GraphManagementRuntimeProperties managementProps = GraphManagementRuntimeProperties.Builder.from(engineProperties, profileProperties, graphVersion).build();
Expand All @@ -40,32 +40,32 @@ public static ORSGraphManager initializeGraphManagement(GraphManagementRuntimePr
ORSGraphFileManager orsGraphFileManager = new ORSGraphFileManager(managementProps, orsGraphFolderStrategy);
orsGraphFileManager.initialize();

ORSGraphRepoManager orsGraphRepoManager = getOrsGraphRepoManager(managementProps, orsGraphRepoStrategy, orsGraphFileManager);
ORSGraphRepoClient orsGraphRepoClient = getOrsGraphRepoClient(managementProps, orsGraphRepoStrategy, orsGraphFileManager);

ORSGraphManager orsGraphManager = new ORSGraphManager(managementProps, orsGraphFileManager, orsGraphRepoManager);
ORSGraphManager orsGraphManager = new ORSGraphManager(managementProps, orsGraphFileManager, orsGraphRepoClient);
orsGraphManager.manageStartup();
return orsGraphManager;
}

public static ORSGraphRepoManager getOrsGraphRepoManager(GraphManagementRuntimeProperties managementProps, ORSGraphRepoStrategy orsGraphRepoStrategy, ORSGraphFileManager orsGraphFileManager) {
ORSGraphRepoManager orsGraphRepoManager = new NullRepoManager();
public static ORSGraphRepoClient getOrsGraphRepoClient(GraphManagementRuntimeProperties managementProps, ORSGraphRepoStrategy orsGraphRepoStrategy, ORSGraphFileManager orsGraphFileManager) {
ORSGraphRepoClient orsGraphRepoClient = new NullGraphRepoClient();

switch (managementProps.getDerivedRepoType()) {
case HTTP -> {
LOGGER.debug("Using HttpRepoManager for repoUrl %s".formatted(managementProps.getDerivedRepoBaseUrl()));
orsGraphRepoManager = new HttpRepoManager(managementProps, orsGraphRepoStrategy, orsGraphFileManager);
LOGGER.debug("Using HttpGraphRepoClient for repoUrl %s".formatted(managementProps.getDerivedRepoBaseUrl()));
orsGraphRepoClient = new HttpGraphRepoClient(managementProps, orsGraphRepoStrategy, orsGraphFileManager);
}
case FILESYSTEM -> {
LOGGER.debug("Using FileSystemRepoManager for repoUri %s".formatted(managementProps.getDerivedRepoPath()));
orsGraphRepoManager = new FileSystemRepoManager(managementProps, orsGraphRepoStrategy, orsGraphFileManager);
LOGGER.debug("Using FileSystemGraphRepoClient for repoUri %s".formatted(managementProps.getDerivedRepoPath()));
orsGraphRepoClient = new FileSystemGraphRepoClient(managementProps, orsGraphRepoStrategy, orsGraphFileManager);
}
case NULL -> {
LOGGER.debug("No valid repositoryUri configured, using NullRepoManager.");
orsGraphRepoManager = new NullRepoManager();
LOGGER.debug("No valid repositoryUri configured, using NullGraphRepoClient.");
orsGraphRepoClient = new NullGraphRepoClient();
}
}

return orsGraphRepoManager;
return orsGraphRepoClient;
}

public ProfileProperties loadProfilePropertiesFromActiveGraph(ORSGraphManager orsGraphManager, ProfileProperties profileProperties) throws ORSGraphFileManagerException {
Expand Down Expand Up @@ -138,7 +138,7 @@ public void downloadAndExtractLatestGraphIfNecessary() {
LOGGER.debug("[%s] ORSGraphManager is busy - skipping download".formatted(getQualifiedProfileName()));
return;
}
orsGraphRepoManager.downloadGraphIfNecessary();
orsGraphRepoClient.downloadGraphIfNecessary();
orsGraphFileManager.extractDownloadedGraph();
}

Expand All @@ -152,18 +152,18 @@ public boolean hasActivationLock() {
return restartLockFile.exists();
}

public void writeOrsGraphInfoFileIfNotExists(ORSGraphHopper gh) {
orsGraphFileManager.writeOrsGraphInfoFileIfNotExists(gh);
public void writeOrsGraphBuildInfoFileIfNotExists(ORSGraphHopper gh) {
orsGraphFileManager.writeOrsGraphBuildInfoFileIfNotExists(gh);
}

public GraphInfo getActiveGraphInfo() throws ORSGraphFileManagerException {
return orsGraphFileManager.getActiveGraphInfo();
public GraphBuildInfo getActiveGraphBuildInfo() throws ORSGraphFileManagerException {
return orsGraphFileManager.getActiveGraphBuildInfo();
}

public ProfileProperties getActiveGraphProfileProperties() throws ORSGraphFileManagerException {
return ofNullable(getActiveGraphInfo())
.map(GraphInfo::getPersistedGraphInfo)
.map(PersistedGraphInfo::getProfileProperties)
return ofNullable(getActiveGraphBuildInfo())
.map(GraphBuildInfo::getPersistedGraphBuildInfo)
.map(PersistedGraphBuildInfo::getProfileProperties)
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Getter
@Setter
@NoArgsConstructor
public class PersistedGraphInfo {
public class PersistedGraphBuildInfo {

@JsonProperty("graph_build_date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssZ")
Expand All @@ -25,16 +25,16 @@ public class PersistedGraphInfo {
@JsonProperty("profile_properties")
private ProfileProperties profileProperties;

public static PersistedGraphInfo withOsmDate(Date osmDate) {
PersistedGraphInfo graphInfo = new PersistedGraphInfo();
graphInfo.setOsmDate(osmDate);
return graphInfo;
public static PersistedGraphBuildInfo withOsmDate(Date osmDate) {
PersistedGraphBuildInfo graphBuildInfo = new PersistedGraphBuildInfo();
graphBuildInfo.setOsmDate(osmDate);
return graphBuildInfo;
}

public static PersistedGraphInfo withGraphBuildDate(Date importDate) {
PersistedGraphInfo graphInfo = new PersistedGraphInfo();
graphInfo.setGraphBuildDate(importDate);
return graphInfo;
public static PersistedGraphBuildInfo withGraphBuildDate(Date importDate) {
PersistedGraphBuildInfo graphBuildInfo = new PersistedGraphBuildInfo();
graphBuildInfo.setGraphBuildDate(importDate);
return graphBuildInfo;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public String getProfileDescriptiveName() {
}

@Override
public String getGraphInfoFileNameInRepository() {
return managementProperties.getLocalProfileName() + "." + GRAPH_INFO_FILE_EXTENSION;
public String getGraphBuildInfoFileNameInRepository() {
return managementProperties.getLocalProfileName() + "." + GRAPH_BUILD_INFO_FILE_EXTENSION;
}

@Override
Expand Down Expand Up @@ -68,18 +68,18 @@ public String getActiveGraphDirAbsPath() {
}

@Override
public String getActiveGraphInfoFileName() {
return "graph_info." + GRAPH_INFO_FILE_EXTENSION;
public String getActiveGraphBuildInfoFileName() {
return "graph_build_info." + GRAPH_BUILD_INFO_FILE_EXTENSION;
}

@Override
public String getDownloadedGraphInfoFileName() {
return getConcatenatedLocalFileName(GRAPH_INFO_FILE_EXTENSION);
public String getDownloadedGraphBuildInfoFileName() {
return getConcatenatedLocalFileName(GRAPH_BUILD_INFO_FILE_EXTENSION);
}

@Override
public String getDownloadedGraphInfoFileAbsPath() {
return managementProperties.getLocalGraphsRootAbsPath() + File.separator + getDownloadedGraphInfoFileName();
public String getDownloadedGraphBuildInfoFileAbsPath() {
return managementProperties.getLocalGraphsRootAbsPath() + File.separator + getDownloadedGraphBuildInfoFileName();
}

@Override
Expand Down
Loading

0 comments on commit 4acd9a1

Please sign in to comment.