Skip to content
Snippets Groups Projects
Commit b089fbba authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

run test sites

parent aef3bb71
No related branches found
No related tags found
1 merge request!809Lambda Priming
package gov.usgs.earthquake.nshmp.www;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import org.crac.Context;
import org.crac.Resource;
......@@ -12,8 +14,13 @@ import software.amazon.awssdk.services.ssm.model.SsmException;
import com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.MultiValuedTreeMap;
import gov.usgs.earthquake.nshmp.NamedLocation;
import gov.usgs.earthquake.nshmp.geo.Regions;
import gov.usgs.earthquake.nshmp.gmm.Gmm;
import gov.usgs.earthquake.nshmp.gmm.Imt;
import gov.usgs.earthquake.nshmp.site.NshmpSite;
import io.micronaut.context.annotation.Value;
import io.micronaut.crac.OrderedResource;
......@@ -26,18 +33,60 @@ import jakarta.inject.Singleton;
@Singleton
public class PrimingResource implements OrderedResource {
/* Test sites */
private static final List<NamedLocation> LOCATIONS = List.of(
NshmpSite.LOS_ANGELES_CA,
NshmpSite.SAN_FRANCISCO_CA,
NshmpSite.SEATTLE_WA,
NshmpSite.SALT_LAKE_CITY_UT,
NshmpSite.RENO_NV,
NshmpSite.NEW_MADRID_MO,
NshmpSite.BOSTON_MA,
NshmpSite.NEW_YORK_NY,
NshmpSite.CHICAGO_IL,
NshmpSite.ANCHORAGE_AK,
NshmpSite.FAIRBANKS_AK,
NshmpSite.JUNEAU_AK,
NshmpSite.KODIAK_AK,
NshmpSite.VALDEZ_AK,
NshmpSite.HILO_HI,
NshmpSite.HONOLULU_HI,
NshmpSite.KAILUA_KONA_HI,
NshmpSite.SAN_JUAN_PR);
@Value("${nshmp-haz.model-path}")
private Path modelPath;
@Override
public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {
ServletUtil.model(ServletUtil.loadModel(modelPath));
var model = ServletUtil.loadModel(modelPath);
ServletUtil.model(model);
updateParameter();
var region = Regions.createRectangular("Bounds", model.bounds().min, model.bounds().max);
try (MicronautLambdaHandler handler = new MicronautLambdaHandler()) {
handler.handleRequest(
getAwsProxyRequest("/hazard"),
new MockLambdaContext());
var paths = List.of("/hazard", "/disagg");
paths.forEach(path -> {
handler.handleRequest(
getAwsProxyRequest(path, Optional.empty()),
new MockLambdaContext());
});
paths.forEach(path -> {
LOCATIONS.forEach(namedLocation -> {
var location = namedLocation.location();
if (region.contains(location)) {
handler.handleRequest(
getAwsProxyRequest(
String.format("%s/%f/%f/760", path, location.longitude, location.latitude),
Optional.of(Imt.PGA)),
new MockLambdaContext());
}
});
});
}
}
......@@ -47,10 +96,19 @@ public class PrimingResource implements OrderedResource {
ServletUtil.resetExecutors();
}
private static AwsProxyRequest getAwsProxyRequest(String path) {
private static AwsProxyRequest getAwsProxyRequest(String path, Optional<Imt> imt) {
final AwsProxyRequest awsProxyRequest = new AwsProxyRequest();
awsProxyRequest.setHttpMethod("GET");
awsProxyRequest.setPath(path);
if (imt.isPresent()) {
var parameters = new MultiValuedTreeMap<String, String>();
parameters.add("imt", imt.get().name());
awsProxyRequest.setMultiValueQueryStringParameters(
parameters);
}
return awsProxyRequest;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment