Skip to content

Commit

Permalink
refactor, still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorgantaylor committed Oct 3, 2024
1 parent b5753bb commit 8f5b078
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import bio.terra.common.exception.MissingRequiredFieldException;
import bio.terra.pipelines.dependencies.stairway.JobMapKeys;
import bio.terra.pipelines.generated.model.ApiErrorReport;
import bio.terra.pipelines.stairway.imputation.PipelineRunTypeFlight;
import bio.terra.stairway.FlightContext;
import bio.terra.stairway.FlightMap;
import bio.terra.stairway.FlightState;
Expand Down Expand Up @@ -160,11 +161,14 @@ public static boolean flightComplete(FlightState flightState) {
}

/** Get a class object from a string. Return null if no matching class name found. */
public static Class<?> getFlightClassFromString(String className) {
public static boolean classNameIsPipelineRunTypeFlightClass(String className) {
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
return null;
Class cls = Class.forName(className);
PipelineRunTypeFlight pipelineRunTypeFlight =
(PipelineRunTypeFlight) cls.getDeclaredConstructor().newInstance();
return true;
} catch (ReflectiveOperationException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package bio.terra.pipelines.common.utils;

import static bio.terra.pipelines.common.utils.FlightUtils.getFlightClassFromString;
import static bio.terra.pipelines.common.utils.FlightUtils.classNameIsPipelineRunTypeFlightClass;

import bio.terra.pipelines.app.common.MetricsUtils;
import bio.terra.pipelines.dependencies.stairway.JobMapKeys;
import bio.terra.pipelines.stairway.imputation.PipelineRunTypeFlight;
import bio.terra.stairway.FlightContext;
import bio.terra.stairway.FlightStatus;
import bio.terra.stairway.HookAction;
Expand All @@ -27,13 +26,7 @@ public HookAction endFlight(FlightContext context) {
return HookAction.CONTINUE;
}

Class<?> flightClass = getFlightClassFromString(context.getFlightClassName());
if (flightClass == null) {
logger.warn(
"Failed to interpret flight class {}, skipping metrics hook",
context.getFlightClassName());
return HookAction.CONTINUE;
} else if (flightClass.isInstance(PipelineRunTypeFlight.class)
if (classNameIsPipelineRunTypeFlightClass(context.getFlightClassName())
&& context.getFlightStatus() != FlightStatus.SUCCESS) {
logger.info("Flight failed, incrementing failed flight counter");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package bio.terra.pipelines.common.utils;

import static bio.terra.pipelines.common.utils.FlightUtils.getFlightClassFromString;
import static bio.terra.pipelines.common.utils.FlightUtils.classNameIsPipelineRunTypeFlightClass;

import bio.terra.pipelines.dependencies.stairway.JobMapKeys;
import bio.terra.pipelines.service.PipelineRunsService;
import bio.terra.pipelines.stairway.imputation.PipelineRunTypeFlight;
import bio.terra.stairway.FlightContext;
import bio.terra.stairway.FlightStatus;
import bio.terra.stairway.HookAction;
Expand All @@ -31,13 +30,7 @@ public HookAction endFlight(FlightContext context) {
return HookAction.CONTINUE;
}

Class<?> flightClass = getFlightClassFromString(context.getFlightClassName());
if (flightClass == null) {
logger.warn(
"Failed to interpret flight class {}, skipping update status hook",
context.getFlightClassName());
return HookAction.CONTINUE;
} else if (flightClass.isInstance(PipelineRunTypeFlight.class)
if (classNameIsPipelineRunTypeFlightClass(context.getFlightClassName())
&& context.getFlightStatus() != FlightStatus.SUCCESS) {
logger.info(
"Flight has status {}, setting PipelineRun status to FAILED", context.getFlightStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,11 @@ void flightComplete_running_isNotComplete() {
// flightComplete returns True if flight is SUCCESS, ERROR, or FATAL
assertFalse(FlightUtils.flightComplete(flightState));
}

@Test
void classNameIsPipelineRunTypeFlightClass_true() {
assertTrue(
FlightUtils.classNameIsPipelineRunTypeFlightClass(
"bio.terra.pipelines.stairway.imputation.RunImputationGcpJobFlight"));
}
}

0 comments on commit 8f5b078

Please sign in to comment.