Skip to content

Commit

Permalink
Shift VersionRef check into prepare.
Browse files Browse the repository at this point in the history
Extend prepare with ValidationException.

Signed-off-by: Maximilian Chrzan <[email protected]>
Signed-off-by: mchrza <[email protected]>
  • Loading branch information
mchrza committed Dec 9, 2024
1 parent 0e1361b commit 7ea6a9a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.here.xyz.models.hub.Ref;
import com.here.xyz.models.hub.Space;
import com.here.xyz.models.hub.Tag;
import com.here.xyz.util.service.BaseHttpServerVerticle;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -32,14 +33,14 @@ public void setUp() {
}

@Test
public void testResolveHeadVersion(){
public void testResolveHeadVersion() throws BaseHttpServerVerticle.ValidationException {
CompilationStepGraph graph = new ExportToFiles().compile(buildExportJobWithVersionRef(new Ref("HEAD")));
final ExportSpaceToFiles exportSpaceToFilesStep = getAndPrepareStep(graph);
//HEAD should point to version 3
Assertions.assertEquals(3, exportSpaceToFilesStep.getVersionRef().getVersion());
}

private static ExportSpaceToFiles getAndPrepareStep(CompilationStepGraph graph) {
private static ExportSpaceToFiles getAndPrepareStep(CompilationStepGraph graph) throws BaseHttpServerVerticle.ValidationException {
final ExportSpaceToFiles exportSpaceToFilesStep = (ExportSpaceToFiles) graph.getExecutions().get(0);
exportSpaceToFilesStep.prepare(null, null);
return exportSpaceToFilesStep;
Expand All @@ -53,7 +54,7 @@ public void testResolveNotExistingTag(){
}

@Test
public void testResolveExistingTag(){
public void testResolveExistingTag() throws BaseHttpServerVerticle.ValidationException {
String tagName = "TAG1";
int tagVersion = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public void deleteOutputs() {
* @param owner
* @param ownerAuth
*/
public void prepare(String owner, JobClientInfo ownerAuth) {
public void prepare(String owner, JobClientInfo ownerAuth) throws ValidationException {
//Nothing to do by default. May be overridden.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import com.here.xyz.jobs.steps.outputs.DownloadUrl;
import com.here.xyz.jobs.steps.outputs.FeatureStatistics;
import com.here.xyz.jobs.steps.outputs.FileStatistics;
import com.here.xyz.jobs.steps.outputs.ResourceHint;
import com.here.xyz.jobs.steps.resources.IOResource;
import com.here.xyz.jobs.steps.resources.Load;
import com.here.xyz.jobs.steps.resources.TooManyResourcesClaimed;
Expand All @@ -74,6 +73,8 @@ public class ExportSpaceToFiles extends SpaceBasedStep<ExportSpaceToFiles> {
public static final int PARALLELIZTATION_MIN_THRESHOLD = 10;//TODO: put back to 500k
//Defines how many export threads are getting used
public static final int PARALLELIZTATION_THREAD_COUNT = 8;
//Defines how large the area of a defined spatialFilter can be
private static final double MAX_ALLOWED_SPATALFILTER_AREA_IN_SQUARE_KM = 2500;

@JsonView({Internal.class, Static.class})
private int calculatedThreadCount = -1;
Expand Down Expand Up @@ -259,22 +260,26 @@ public ExecutionMode getExecutionMode() {
}

@Override
public void prepare(String owner, JobClientInfo ownerAuth) {
public void prepare(String owner, JobClientInfo ownerAuth) throws ValidationException {
if(versionRef == null)
throw new ValidationException("Version ref is required.");

validateSpaceExists();
//Resolve the ref to an actual version
if (versionRef.isTag()) {
try {
setVersionRef(new Ref(hubWebClient().loadTag(getSpaceId(), versionRef.getTag()).getVersion()));
}
catch (WebClientException e) {
throw new IllegalArgumentException("Unable to resolve tag \"" + versionRef.getTag() + "\" of " + getSpaceId(), e);
throw new ValidationException("Unable to resolve tag \"" + versionRef.getTag() + "\" of " + getSpaceId(), e);
}
}
else if (versionRef.isHead()) {
try {
setVersionRef(new Ref(spaceStatistics(context, true).getMaxVersion().getValue()));
}
catch (WebClientException e) {
throw new IllegalArgumentException("Unable to resolve HEAD version of " + getSpaceId(), e);
throw new ValidationException("Unable to resolve HEAD version of " + getSpaceId(), e);
}
}
}
Expand All @@ -283,9 +288,6 @@ else if (versionRef.isHead()) {
public boolean validate() throws ValidationException {
super.validate();

if(versionRef == null)
throw new ValidationException("Version ref is required.");

if (versionRef.isAllVersions())
throw new ValidationException("It is not supported to export all versions at once.");

Expand All @@ -296,8 +298,9 @@ public boolean validate() throws ValidationException {
statistics = statistics != null ? statistics : loadSpaceStatistics(getSpaceId(), context, true);

//Validate input Geometry
if (this.spatialFilter != null)
this.spatialFilter.validateSpatialFilter();
if (this.spatialFilter != null) {
spatialFilter.validateSpatialFilter();
}

//Validate versionRef
if (this.versionRef == null)
Expand Down

0 comments on commit 7ea6a9a

Please sign in to comment.