Skip to content

Commit

Permalink
Migrate OSRM settings from preferences to server.config
Browse files Browse the repository at this point in the history
The settings for the OSRM modes are moved from preferences to config, and use a new format that is more similar to the trRouting modes.

Instead of all the modes that use OSRM being placed in the same `defaultPreferences.osrmRouting.modes` object, they are all placed in the server configuration's `routing` object.
There, all modes no matter the engine are at the same level, have a `defaultEngine` field, and an `engines` field that allows for each mode to have configs for multiple routing engines.
For exemple, at the moment, 'driving' has osrmRouting as its `defaultEngine` and only configured engine, but we could add a new config that uses a different engine without having to create a new `driving` object elsewhere.
We also change the `osrmPath` field to `host`, as it was not used anywhere in the code, and we can now use `host` to use remote OSRM instances.

At the moment, we still allow the old format to be used so that the instances aren't broken, but it will be fully deprecated in the future.
Fix: #1084
  • Loading branch information
GabrielBruno24 committed Dec 9, 2024
1 parent 5ced7f9 commit 3dd71b0
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 219 deletions.
145 changes: 73 additions & 72 deletions examples/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,79 @@ module.exports = {
// }
// }
// }
// }
// },
// // Configuration for simple routing modes, using OSRM-like engines
// driving: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: {
// port: 7000, // Port used to access OSRM, either locally or remotely
// host: null, // If set to null, localhost will be used. Ignored if autoStart set to true
// autoStart: true, // If true, a local instance of OSRM will be started
// enabled: true // If true, this mode will be configured, otherwise will be left out
// }
// }
// },
// cycling: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 8000, host: null, autoStart: true, enabled: true }
// }
// },
// walking: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 5001, host: null, autoStart: true, enabled: true }
// }
// },
// bus_suburb: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 7110, host: null, autoStart: true, enabled: true }
// }
// },
// bus_urban: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 7120, host: null, autoStart: true, enabled: true }
// }
// },
// rail: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9000, host: null, autoStart: false, enabled: false }
// }
// },
// tram: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9100, host: null, autoStart: false, enabled: false }
// }
// },
// tram_train: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9200, host: null, autoStart: false, enabled: false }
// }
// },
// metro: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9300, host: null, autoStart: false, enabled: false }
// }
// },
// monorail: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9400, host: null, autoStart: false, enabled: false }
// }
// },
// cable_car: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9500, host: null, autoStart: false, enabled: false }
// }
// },
// },

mapDefaultCenter: {
Expand Down Expand Up @@ -78,77 +150,6 @@ module.exports = {
},

defaultPreferences: {
osrmRouting: {
modes: {
driving: {
// !!! Be careful: use your own server, since you may be blocked on the osrm demo server after too many queries
port : 7000, // Port used to access OSRM, either locally or remotely
host : null, // If set to null, localhost will be used. Ignored if autoStart set to true
autoStart: true, // If true, a local instance of OSRM will be started
enabled : true // If true, this mode will be configured, otherwise will be left out
},
cycling: {
port : 8000,
host : null,
autoStart: true,
enabled : true
},
walking: {
port : 5001,
host : null,
autoStart: true,
enabled : true
},
bus_suburb: {
port : 7110,
host : null,
autoStart: true,
enabled : true
},
bus_urban: {
port : 7120,
host : null,
autoStart: true,
enabled : true
},
rail: {
port : 9000,
host : null,
autoStart: false,
enabled : false
},
tram: {
port : 9100,
host : null,
autoStart: false,
enabled : false
},
tram_train: {
port : 9200,
host : null,
autoStart: false,
enabled : false
},
metro: {
port : 9300,
host : null,
autoStart: false,
enabled : false
},
monorail: {
port : 9400,
host : null,
autoStart: false,
enabled : false
},
cable_car: {
port : 9500,
host : null,
autoStart: false,
enabled : false
}
}
},
transit: {
routing: {
batch: {
Expand Down
11 changes: 11 additions & 0 deletions packages/chaire-lib-backend/src/config/ServerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ class ServerConfig {
}
return engineConfiguration[instance] || { port: 4000, cacheAllScenarios: false };
};

getAllModesForEngine = (engine: string): string[] => {
const modesForEngine: string[] = [];
for (const modeName in config.routing) {
if (config.routing[modeName].engines[engine] !== undefined) {
modesForEngine.push(modeName);
}
}

return modesForEngine;
};
}

const instance = new ServerConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('get routing mode and engine configs', () => {
});

test('getRoutingModeConfig, mode does not exist', () => {
expect(ServerConfig.getRoutingModeConfig('walking')).toBeUndefined();
expect(ServerConfig.getRoutingModeConfig('walking_way_data_as_name')).toBeUndefined();
});

test('getRoutingEngineConfigForMode, mode and engine exist', () => {
Expand All @@ -52,7 +52,29 @@ describe('get routing mode and engine configs', () => {
});

test('getRoutingEngineConfigForMode, mode does not exist', () => {
expect(ServerConfig.getRoutingEngineConfigForMode('walking', 'osrm')).toBeUndefined();
expect(ServerConfig.getRoutingEngineConfigForMode('walking_way_data_as_name', 'osrmRouting')).toBeUndefined();
});

test('getAllModesForEngine, at least one mode uses engine', () => {
expect(ServerConfig.getAllModesForEngine('trRouting')).toEqual(['transit']);
expect(ServerConfig.getAllModesForEngine('osrmRouting')).toEqual([
'driving',
'driving_congestion',
'cycling',
'walking',
'bus_suburb',
'bus_urban',
'bus_congestion',
'rail',
'tram',
'tram_train',
'metro',
'monorail',
'cable_car'
]);
});

test('getAllModesForEngine, no mode uses engine', () => {
expect(ServerConfig.getAllModesForEngine('valhalla')).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test('Expected default with env', () => {
expect(config.projectDirectory).toEqual(path.normalize(`${__dirname}/../../../../../tests/dir`));
expect(config.routing.transit.engines.trRouting!.single).toEqual({ port: 4000, cacheAllScenarios: false, debug: false, logs: { nbFiles: 3, maxFileSizeKB: 5120 } });
expect(config.routing.transit.engines.trRouting!.batch).toEqual({ port: 14000, cacheAllScenarios: false, debug: false, logs: { nbFiles: 3, maxFileSizeKB: 5120 }});
expect(config.routing.driving!.engines.osrmRouting).toEqual({ port: 7000, host: null, autoStart: true, enabled: true });
});

test('setProjectConfiguration', () => {
Expand All @@ -28,6 +29,12 @@ test('setProjectConfiguration', () => {
engines: {
trRouting: { single: { port: 5000 }, batch: { logs: { maxFileSizeKB: 10000 } } } as any
}
},
driving: {
defaultEngine: 'osrmRouting',
engines: {
osrmRouting: { port: 1234, enabled: false } as any
}
}
}
});
Expand All @@ -37,4 +44,5 @@ test('setProjectConfiguration', () => {
// Make sure the deep merge works for object configs
expect(config.routing.transit.engines.trRouting!.single).toEqual({ port: 5000, cacheAllScenarios: false, debug: false, logs: { nbFiles: 3, maxFileSizeKB: 5120 } });
expect(config.routing.transit.engines.trRouting!.batch).toEqual({ port: 14000, cacheAllScenarios: false, debug: false, logs: { nbFiles: 3, maxFileSizeKB: 10000 } });
expect(config.routing.driving!.engines.osrmRouting).toEqual({ port: 1234, host: null, autoStart: true, enabled: false });
});
Loading

0 comments on commit 3dd71b0

Please sign in to comment.