Skip to content

Commit 036e90c

Browse files
committed
Revert "feat: Add effective map location to metadata events (#2321)"
This reverts commit 71f89e1
1 parent 33de170 commit 036e90c

13 files changed

Lines changed: 12 additions & 220 deletions

File tree

service/definition/src/main/java/ai/timefold/solver/service/definition/api/domain/Metadata.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ public final class Metadata<Score_> implements Status<Score_> {
7070
@JsonInclude(JsonInclude.Include.NON_EMPTY)
7171
private String failureMessage;
7272

73-
@Schema(nullable = true,
74-
description = "The map-service region resolved when location is auto-select.")
75-
@JsonInclude(JsonInclude.Include.NON_EMPTY)
76-
private String resolvedMapLocation;
77-
7873
public Metadata() {
7974
this((String) null);
8075
}
@@ -107,7 +102,6 @@ public Metadata(Metadata<Score_> metadata) {
107102
this.parentId = metadata.parentId;
108103
this.originId = metadata.originId;
109104
this.failureMessage = metadata.failureMessage;
110-
this.resolvedMapLocation = metadata.resolvedMapLocation;
111105
}
112106

113107
public String getId() {
@@ -266,14 +260,6 @@ public void setFailureMessage(String failureMessage) {
266260
this.failureMessage = failureMessage;
267261
}
268262

269-
public String getResolvedMapLocation() {
270-
return resolvedMapLocation;
271-
}
272-
273-
public void setResolvedMapLocation(String resolvedMapLocation) {
274-
this.resolvedMapLocation = resolvedMapLocation;
275-
}
276-
277263
@Override
278264
public void solvingStarted() {
279265
if (solverStatus != SolvingStatus.DATASET_COMPUTED

service/definition/src/main/java/ai/timefold/solver/service/definition/internal/Headers.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ public class Headers {
66

77
public static final String X_MAPS_PROVIDER_HEADER = "X-TF-MAPS-PROVIDER";
88

9-
public static final String X_MAPS_LOCATION_HEADER = "X-TF-MAPS-LOCATION";
10-
119
public static final String X_MAPS_CACHE_ID = "X-TF-MAPS-CACHE-ID";
1210

1311
public static final String X_MAPS_RESPONSE_CHUNK_BYTES = "X-TF-MAPS-CHUNK-BYTES";
Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
package ai.timefold.solver.service.definition.internal;
2-
3-
import jakarta.enterprise.context.ApplicationScoped;
4-
5-
/**
6-
* Side-channel used by the maps enricher to publish the resolved map-service location to the
7-
* SolverWorker, which then writes it onto the dataset's {@code Metadata} so it propagates through
8-
* insight events.
9-
*/
10-
@ApplicationScoped
11-
public class MapEnrichmentContext {
12-
13-
private String resolvedMapLocation;
14-
15-
public void setResolvedMapLocation(String location) {
16-
this.resolvedMapLocation = location;
17-
}
18-
19-
public String getResolvedMapLocation() {
20-
return this.resolvedMapLocation;
21-
}
22-
}

service/definition/src/main/java/ai/timefold/solver/service/definition/internal/platform/EnvironmentVars.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ public class EnvironmentVars {
3232
*/
3333
public static final String ENV_TIMEFOLD_TENANT_NAME = "AI_TIMEFOLD_TENANT_NAME";
3434

35-
/**
36-
* Configured map-service location: either a concrete region (e.g. {@code us-georgia}) or the
37-
* sentinel {@link #MAP_SERVICE_LOCATION_AUTO_SELECT} for runtime region resolution.
38-
*/
39-
public static final String ENV_TIMEFOLD_PLATFORM_MAP_SERVICE_LOCATION = "AI_TIMEFOLD_PLATFORM_MAP_SERVICE_LOCATION";
40-
41-
/**
42-
* Sentinel value for {@link #ENV_TIMEFOLD_PLATFORM_MAP_SERVICE_LOCATION}: tells the maps-service
43-
* to auto-select the region at request time based on the locations being routed.
44-
*/
45-
public static final String MAP_SERVICE_LOCATION_AUTO_SELECT = "auto-select";
46-
4735
/**
4836
* Kubernetes API specific environment variables that are set based on execution information like pod and node
4937
*/

service/maps/service-client/src/main/java/ai/timefold/solver/service/maps/service/client/api/TravelTimeMatrixEnricher.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import jakarta.inject.Inject;
99

1010
import ai.timefold.solver.service.definition.api.enrichment.SolverModelEnricher;
11-
import ai.timefold.solver.service.definition.internal.MapEnrichmentContext;
1211
import ai.timefold.solver.service.definition.internal.error.ErrorCodes;
1312
import ai.timefold.solver.service.definition.internal.error.TimefoldRuntimeException;
1413
import ai.timefold.solver.service.maps.api.model.Location;
@@ -31,14 +30,10 @@ public class TravelTimeMatrixEnricher implements SolverModelEnricher<LocationsAw
3130

3231
private final MapServiceOptionsSupplier optionsSupplier;
3332

34-
private final MapEnrichmentContext mapEnrichmentContext;
35-
3633
@Inject
37-
public TravelTimeMatrixEnricher(MapService mapService, MapServiceOptionsSupplier optionsSupplier,
38-
MapEnrichmentContext mapEnrichmentContext) {
34+
public TravelTimeMatrixEnricher(MapService mapService, MapServiceOptionsSupplier optionsSupplier) {
3935
this.mapService = mapService;
4036
this.optionsSupplier = optionsSupplier;
41-
this.mapEnrichmentContext = mapEnrichmentContext;
4237
}
4338

4439
@Retry(maxRetries = 5, delay = 1, delayUnit = ChronoUnit.SECONDS, abortOn = {
@@ -66,7 +61,6 @@ public LocationsAwareSolverModel<?> enrich(LocationsAwareSolverModel<?> solverMo
6661
location.setDistanceMatrix(travelTimeAndDistance.travelTimeAndDistance().distance());
6762
});
6863
solverModel.setLocationsNotInMap(convertIdxToLocations(travelTimeAndDistance.locationsNotInMapIdx(), locations));
69-
mapEnrichmentContext.setResolvedMapLocation(travelTimeAndDistance.resolvedMapLocation());
7064
return solverModel;
7165
}
7266

service/maps/service-client/src/main/java/ai/timefold/solver/service/maps/service/client/impl/CacheItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
import ai.timefold.solver.service.maps.service.integration.internal.model.TravelTimeAndDistance;
77

88
public record CacheItem(TravelTimeAndDistance travelTimeAndDistance, List<Location> locations, String hash,
9-
List<Integer> locationsOutOfMap, String resolvedMapLocation) {
9+
List<Integer> locationsOutOfMap) {
1010

1111
}

service/maps/service-client/src/main/java/ai/timefold/solver/service/maps/service/client/impl/MapServiceClientImpl.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static ai.timefold.solver.service.definition.internal.Headers.X_MAPS_INVALIDATE_MATRIX_HEADER;
55
import static ai.timefold.solver.service.definition.internal.Headers.X_MAPS_LOCATIONS_CHUNK_BYTES;
66
import static ai.timefold.solver.service.definition.internal.Headers.X_MAPS_LOCATIONS_NOT_IN_MAP;
7-
import static ai.timefold.solver.service.definition.internal.Headers.X_MAPS_LOCATION_HEADER;
87
import static ai.timefold.solver.service.definition.internal.Headers.X_MAPS_MATRIX_HASH_HEADER;
98
import static ai.timefold.solver.service.definition.internal.Headers.X_MAPS_PROVIDER_HEADER;
109
import static ai.timefold.solver.service.definition.internal.Headers.X_MAPS_RESPONSE_CHUNK_BYTES;
@@ -136,9 +135,8 @@ public TravelTimeAndDistanceWithMetadata getTravelTimeAndDistance(List<Location>
136135
// If there are no updates, return from cache
137136
LOGGER.info("Distance matrix in cache is up-to-date, returning from cache");
138137
assertLocationsAreInCache(locations);
139-
CacheItem cached = travelTimeAndDistanceSingleItemCache.get();
140-
return new TravelTimeAndDistanceWithMetadata(cached.travelTimeAndDistance(),
141-
cached.locationsOutOfMap(), cached.resolvedMapLocation());
138+
return new TravelTimeAndDistanceWithMetadata(travelTimeAndDistanceSingleItemCache.get().travelTimeAndDistance(),
139+
travelTimeAndDistanceSingleItemCache.get().locationsOutOfMap());
142140
} else {
143141
// If there are updates, process them and update cache
144142
LOGGER.info("Distance matrix in cache is not up-to-date, processing updates");
@@ -207,8 +205,7 @@ private TravelTimeAndDistanceWithMetadata getFromCacheOrRequest(List<Location> l
207205
if (travelTimeAndDistanceSingleItemCache.isInCache(id)) {
208206
LOGGER.info("Distance matrix without location set name in cache, returning from cache");
209207
CacheItem cacheItem = travelTimeAndDistanceSingleItemCache.get();
210-
return new TravelTimeAndDistanceWithMetadata(cacheItem.travelTimeAndDistance(), cacheItem.locationsOutOfMap(),
211-
cacheItem.resolvedMapLocation());
208+
return new TravelTimeAndDistanceWithMetadata(cacheItem.travelTimeAndDistance(), cacheItem.locationsOutOfMap());
212209
}
213210

214211
// If it does not exist, request from maps-service and store by hash of locations
@@ -240,7 +237,6 @@ private TravelTimeAndDistanceWithMetadata getAndStoreInCache(List<Location> loca
240237
private TravelTimeAndDistanceWithMetadata processResponseAndStoreInCache(Response response, String localCacheId) {
241238
String matrixHash = response.getHeaderString(X_MAPS_MATRIX_HASH_HEADER);
242239
String provider = response.getHeaderString(X_MAPS_PROVIDER_HEADER);
243-
String resolvedMapLocation = response.getHeaderString(X_MAPS_LOCATION_HEADER);
244240
String tenant = response.getHeaderString(X_TENANT_ID_HEADER);
245241
String cacheId = response.getHeaderString(X_MAPS_CACHE_ID);
246242
String locationsNotInMapString = response.getHeaderString(X_MAPS_LOCATIONS_NOT_IN_MAP);
@@ -260,13 +256,11 @@ private TravelTimeAndDistanceWithMetadata processResponseAndStoreInCache(Respons
260256
throw new IllegalArgumentException("No provider found to convert travel time and distance response.");
261257
}
262258

263-
TravelTimeAndDistanceWithMetadata raw =
259+
TravelTimeAndDistanceWithMetadata travelTimeAndDistance =
264260
convertResponse(provider, chunkBytes, responseLocations, data, locationsNotInMap);
265-
TravelTimeAndDistanceWithMetadata travelTimeAndDistance = new TravelTimeAndDistanceWithMetadata(
266-
raw.travelTimeAndDistance(), raw.locationsNotInMapIdx(), resolvedMapLocation);
267261
travelTimeAndDistanceSingleItemCache.put(localCacheId,
268262
new CacheItem(travelTimeAndDistance.travelTimeAndDistance(), responseLocations, matrixHash,
269-
locationsNotInMap, resolvedMapLocation));
263+
locationsNotInMap));
270264
return travelTimeAndDistance;
271265

272266
} catch (IllegalDistanceResponseException e) {
@@ -281,7 +275,6 @@ private TravelTimeAndDistanceWithMetadata processResponseAndStoreInCache(Respons
281275
private TravelTimeAndDistanceWithMetadata processUpdateAndStoreInCache(Response response, String locationSetName) {
282276
String matrixHash = response.getHeaderString(X_MAPS_MATRIX_HASH_HEADER);
283277
String provider = response.getHeaderString(X_MAPS_PROVIDER_HEADER);
284-
String resolvedMapLocation = response.getHeaderString(X_MAPS_LOCATION_HEADER);
285278
String tenant = response.getHeaderString(X_TENANT_ID_HEADER);
286279
String cacheId = response.getHeaderString(X_MAPS_CACHE_ID);
287280
String locationsNotInMapString = response.getHeaderString(X_MAPS_LOCATIONS_NOT_IN_MAP);
@@ -301,18 +294,15 @@ private TravelTimeAndDistanceWithMetadata processUpdateAndStoreInCache(Response
301294
throw new IllegalArgumentException("No provider found to convert travel time and distance update.");
302295
}
303296

304-
TravelTimeAndDistanceWithMetadata raw =
297+
TravelTimeAndDistanceWithMetadata travelTimeAndDistance =
305298
convertUpdate(provider, chunkBytes, responseLocations, data, cacheItem.locationsOutOfMap(),
306299
locationsNotInMap);
307-
String effectiveMapLocation = resolvedMapLocation != null ? resolvedMapLocation : cacheItem.resolvedMapLocation();
308-
TravelTimeAndDistanceWithMetadata travelTimeAndDistance = new TravelTimeAndDistanceWithMetadata(
309-
raw.travelTimeAndDistance(), raw.locationsNotInMapIdx(), effectiveMapLocation);
310300

311301
List<Location> newLocations = Stream.concat(cacheItem.locations().stream(), responseLocations.stream()).toList();
312302
if (locationSetName != null && matrixHash != null) {
313303
travelTimeAndDistanceSingleItemCache.put(locationSetName,
314304
new CacheItem(travelTimeAndDistance.travelTimeAndDistance(), newLocations, matrixHash,
315-
locationsNotInMap, effectiveMapLocation));
305+
locationsNotInMap));
316306
}
317307
return travelTimeAndDistance;
318308

service/maps/service-client/src/test/java/ai/timefold/solver/service/maps/service/client/api/TravelTimeMatrixEnricherTest.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package ai.timefold.solver.service.maps.service.client.api;
22

3-
import java.util.ArrayList;
43
import java.util.List;
54
import java.util.Optional;
65

76
import jakarta.inject.Inject;
87

9-
import ai.timefold.solver.service.definition.internal.MapEnrichmentContext;
108
import ai.timefold.solver.service.maps.api.model.Location;
119
import ai.timefold.solver.service.maps.api.model.travel.TravelDistance;
1210
import ai.timefold.solver.service.maps.api.model.travel.TravelTime;
1311
import ai.timefold.solver.service.maps.service.client.util.RemoteMapServiceConfigurationProfile;
1412
import ai.timefold.solver.service.maps.service.client.util.SampleModel;
1513
import ai.timefold.solver.service.maps.service.integration.api.LocationsAwareSolverModel;
1614
import ai.timefold.solver.service.maps.service.test.api.MapServiceApiWiremockExtensions;
17-
import ai.timefold.solver.service.maps.service.test.impl.DistanceGetUpdateResponseTransformer;
18-
import ai.timefold.solver.service.maps.service.test.impl.HaversineDistanceResponseTransformer;
1915

2016
import org.assertj.core.api.Assertions;
2117
import org.junit.jupiter.api.Test;
@@ -32,9 +28,6 @@ public class TravelTimeMatrixEnricherTest {
3228
@Inject
3329
TravelTimeMatrixEnricher enricher;
3430

35-
@Inject
36-
MapEnrichmentContext mapEnrichmentContext;
37-
3831
@Test
3932
void testRemoteConnectionWithMapServer() {
4033
Location l1 = new Location(0, 0);
@@ -48,8 +41,6 @@ void testRemoteConnectionWithMapServer() {
4841
Assertions.assertThat(enrich.getLocations().getFirst().getTravelTimeTo(l2)).isEqualTo(TravelTime.of(11322L));
4942
Assertions.assertThat(enrich.getLocations().getFirst().getDistanceTo(l2)).isEqualTo(TravelDistance.of(157249L));
5043
Assertions.assertThat(enrich.getLocationsNotInMap()).isEmpty();
51-
Assertions.assertThat(mapEnrichmentContext.getResolvedMapLocation())
52-
.isEqualTo(HaversineDistanceResponseTransformer.RESOLVED_MAP_LOCATION);
5344
}
5445

5546
@Test
@@ -106,8 +97,6 @@ void testDistanceMatrixWithUpdates() {
10697
Assertions.assertThat(enrich.getLocations().get(1).getDistanceTo(l1)).isEqualTo(TravelDistance.of(157249L));
10798
Assertions.assertThat(enrich.getLocations().get(2).getDistanceTo(l4)).isEqualTo(TravelDistance.of(157178L));
10899
Assertions.assertThat(enrich.getLocationsNotInMap()).isEmpty();
109-
Assertions.assertThat(mapEnrichmentContext.getResolvedMapLocation())
110-
.isEqualTo(HaversineDistanceResponseTransformer.RESOLVED_MAP_LOCATION);
111100
}
112101

113102
@Test
@@ -164,27 +153,4 @@ void testDistanceMatrixWithLocationsOutOfMap() {
164153
Assertions.assertThat(enrich.getLocations().get(2).getDistanceTo(l4)).isEqualTo(TravelDistance.ZERO);
165154
}
166155

167-
@Test
168-
void updatePathFallsBackToCachedMapLocationWhenHeaderIsMissing() {
169-
// First enrich populates the cache for "with-updates" via the POST full-matrix path,
170-
// which emits X_MAPS_LOCATION_HEADER and cache stores resolvedMapLocation="us-georgia".
171-
SampleModel seed = new SampleModel(DistanceGetUpdateResponseTransformer.UPDATE_AWARE_LOCATION_SET_NAME,
172-
DistanceGetUpdateResponseTransformer.UPDATE_OLD_LOCATIONS);
173-
enricher.enrich(seed);
174-
Assertions.assertThat(mapEnrichmentContext.getResolvedMapLocation())
175-
.isEqualTo(HaversineDistanceResponseTransformer.RESOLVED_MAP_LOCATION);
176-
177-
// Second enrich adds a new location and cache hit triggers the GET-update path.
178-
// The transformer returns a 200 update WITHOUT X_MAPS_LOCATION_HEADER, so
179-
// processUpdateAndStoreInCache must fall back to the value stored in the CacheItem.
180-
List<Location> withNewLocation = new ArrayList<>(DistanceGetUpdateResponseTransformer.UPDATE_OLD_LOCATIONS);
181-
withNewLocation.addAll(DistanceGetUpdateResponseTransformer.UPDATE_NEW_LOCATIONS);
182-
SampleModel updated = new SampleModel(DistanceGetUpdateResponseTransformer.UPDATE_AWARE_LOCATION_SET_NAME,
183-
withNewLocation);
184-
enricher.enrich(updated);
185-
186-
Assertions.assertThat(mapEnrichmentContext.getResolvedMapLocation())
187-
.isEqualTo(HaversineDistanceResponseTransformer.RESOLVED_MAP_LOCATION);
188-
}
189-
190156
}

service/maps/service-integration/src/main/java/ai/timefold/solver/service/maps/service/integration/internal/model/TravelTimeAndDistanceWithMetadata.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
import java.util.List;
44

55
public record TravelTimeAndDistanceWithMetadata(TravelTimeAndDistance travelTimeAndDistance,
6-
List<Integer> locationsNotInMapIdx, String resolvedMapLocation) {
7-
8-
public TravelTimeAndDistanceWithMetadata(TravelTimeAndDistance travelTimeAndDistance,
9-
List<Integer> locationsNotInMapIdx) {
10-
this(travelTimeAndDistance, locationsNotInMapIdx, null);
11-
}
6+
List<Integer> locationsNotInMapIdx) {
127
}

service/maps/service-integration/src/main/java/ai/timefold/solver/service/maps/service/integration/internal/provider/TravelTimeAndDistanceMatrixResponse.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
import java.io.InputStream;
44
import java.util.List;
55

6-
public record TravelTimeAndDistanceMatrixResponse(InputStream response, List<Integer> locationsOutOfMapIndexes,
7-
String resolvedMapLocation) {
8-
9-
public TravelTimeAndDistanceMatrixResponse(InputStream response, List<Integer> locationsOutOfMapIndexes) {
10-
this(response, locationsOutOfMapIndexes, null);
11-
}
6+
public record TravelTimeAndDistanceMatrixResponse(InputStream response, List<Integer> locationsOutOfMapIndexes) {
127
}

0 commit comments

Comments
 (0)