Skip to content

Commit 7fb9fc6

Browse files
authored
Merge pull request opentripplanner#6996 from opentripplanner/serverinfo-validity-dates
Added transit service validity dates and CPU cores to GraphQL ServerInfo and transitInfo
2 parents b45d54d + 5469209 commit 7fb9fc6

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchemaFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.opentripplanner.apis.transmodel.model.framework.ServerInfoType;
6767
import org.opentripplanner.apis.transmodel.model.framework.StreetModeDurationInputType;
6868
import org.opentripplanner.apis.transmodel.model.framework.SystemNoticeType;
69+
import org.opentripplanner.apis.transmodel.model.framework.TransitInfoType;
6970
import org.opentripplanner.apis.transmodel.model.framework.TransmodelDirectives;
7071
import org.opentripplanner.apis.transmodel.model.framework.TransmodelScalars;
7172
import org.opentripplanner.apis.transmodel.model.framework.ValidityPeriodType;
@@ -219,6 +220,7 @@ private GraphQLSchema createDefault() {
219220
GraphQLOutputType systemNoticeType = SystemNoticeType.create();
220221
GraphQLOutputType linkGeometryType = PointsOnLinkType.create();
221222
GraphQLOutputType serverInfoType = ServerInfoType.create();
223+
GraphQLOutputType transitInfoType = TransitInfoType.create(validityPeriodType);
222224
GraphQLOutputType authorityType = authorityTypeFactory.create(
223225
LineType.REF,
224226
PtSituationElementType.REF
@@ -1533,6 +1535,14 @@ private GraphQLSchema createDefault() {
15331535
.dataFetcher(e -> projectInfo())
15341536
.build()
15351537
)
1538+
.field(
1539+
GraphQLFieldDefinition.newFieldDefinition()
1540+
.name("transitInfo")
1541+
.description("Get information about the transit data available in the system.")
1542+
.type(new GraphQLNonNull(transitInfoType))
1543+
.dataFetcher(e -> new Object())
1544+
.build()
1545+
)
15361546
.field(datedServiceJourneyQueryFactory.createGetById(datedServiceJourneyType))
15371547
.field(datedServiceJourneyQueryFactory.createQuery(datedServiceJourneyType))
15381548
.build();

application/src/main/java/org/opentripplanner/apis/transmodel/model/framework/ServerInfoType.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ public static GraphQLOutputType create() {
111111
.dataFetcher(e -> GqlUtil.getTransitService(e).getTimeZone())
112112
.build()
113113
)
114+
.field(
115+
GraphQLFieldDefinition.newFieldDefinition()
116+
.name("numberOfCores")
117+
.description("Number of CPU cores on the OTP server")
118+
.type(Scalars.GraphQLInt)
119+
.dataFetcher(e -> Runtime.getRuntime().availableProcessors())
120+
.build()
121+
)
114122
.build();
115123
}
116124
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.opentripplanner.apis.transmodel.model.framework;
2+
3+
import graphql.schema.GraphQLFieldDefinition;
4+
import graphql.schema.GraphQLObjectType;
5+
import graphql.schema.GraphQLOutputType;
6+
import org.opentripplanner.apis.transmodel.model.siri.sx.ValidityPeriod;
7+
import org.opentripplanner.apis.transmodel.support.GqlUtil;
8+
9+
public class TransitInfoType {
10+
11+
public static GraphQLOutputType create(GraphQLObjectType validityPeriodType) {
12+
return GraphQLObjectType.newObject()
13+
.name("TransitInfo")
14+
.description("Information about the transit data available in the system.")
15+
.field(
16+
GraphQLFieldDefinition.newFieldDefinition()
17+
.name("validityPeriod")
18+
.description("The validity period for the transit data currently loaded in the system.")
19+
.type(validityPeriodType)
20+
.dataFetcher(environment -> {
21+
var transitService = GqlUtil.getTransitService(environment);
22+
var startTime = transitService.getTransitServiceStarts();
23+
var endTime = transitService.getTransitServiceEnds();
24+
25+
Long startMillis = startTime != null ? startTime.toInstant().toEpochMilli() : null;
26+
Long endMillis = endTime != null ? endTime.toInstant().toEpochMilli() : null;
27+
28+
return new ValidityPeriod(startMillis, endMillis);
29+
})
30+
.build()
31+
)
32+
.build();
33+
}
34+
}

application/src/main/resources/org/opentripplanner/apis/transmodel/schema.graphql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ type QueryType {
814814
"MultiModalMode for query. To control whether multi modal parent stop places, their mono modal children or both are included in the response. Does not affect mono modal stop places that do not belong to a multi modal stop place."
815815
multiModalMode: MultiModalMode = parent
816816
): [StopPlace]! @timingData
817+
"Get information about the transit data available in the system."
818+
transitInfo: TransitInfo!
817819
"Input type for executing a travel search for a trip between two locations. Returns trip patterns describing suggested alternatives for the trip."
818820
trip(
819821
"Time and cost penalty on access/egress modes."
@@ -1184,6 +1186,8 @@ type ServerInfo {
11841186
Note: The input data can be in several time zones, but OTP internally operates on a single one.
11851187
"""
11861188
internalTransitModelTimeZone: String
1189+
"Number of CPU cores on the OTP server"
1190+
numberOfCores: Int
11871191
"The 'configVersion' of the otp-config.json file."
11881192
otpConfigVersion: String
11891193
"The otp-serialization-version-id used to check graphs for compatibility with current version of OTP."
@@ -1382,6 +1386,12 @@ type TimetabledPassingTime {
13821386
timingPoint: Boolean!
13831387
}
13841388

1389+
"Information about the transit data available in the system."
1390+
type TransitInfo {
1391+
"The validity period for the transit data currently loaded in the system."
1392+
validityPeriod: ValidityPeriod
1393+
}
1394+
13851395
"Used to specify board and alight slack for a given modes."
13861396
type TransportModeSlackType {
13871397
modes: [TransportMode!]!

0 commit comments

Comments
 (0)