Search in sources :

Example 1 with JsonSerializableExecutor

use of pipelite.executor.JsonSerializableExecutor in project pipelite by enasequence.

the class StageService method prepareSaveStage.

public static void prepareSaveStage(Stage stage) {
    StageExecutor stageExecutor = stage.getExecutor();
    StageEntity stageEntity = stage.getStageEntity();
    stageEntity.setExecutorName(stageExecutor.getClass().getName());
    if (stageExecutor instanceof JsonSerializableExecutor) {
        stageEntity.setExecutorData(((JsonSerializableExecutor) stageExecutor).serialize());
    }
    if (stageExecutor.getExecutorParams() != null) {
        stageEntity.setExecutorParams(stageExecutor.getExecutorParams().serialize());
    }
}
Also used : JsonSerializableExecutor(pipelite.executor.JsonSerializableExecutor) StageEntity(pipelite.entity.StageEntity) StageExecutor(pipelite.stage.executor.StageExecutor)

Example 2 with JsonSerializableExecutor

use of pipelite.executor.JsonSerializableExecutor in project pipelite by enasequence.

the class StageExecutorSerializer method deserializeExecution.

/**
 * Deserialize active stage executor and stage executor parameters. An asynchronous executor must
 * be in the POLL state to be deserialized.
 *
 * @oaran stage the stage being executed
 * @return true if the executor was deserialized
 */
public static <T extends ExecutorParameters> Boolean deserializeExecution(Stage stage, Deserialize deserialize) {
    if (!(stage.getExecutor() instanceof JsonSerializableExecutor)) {
        return false;
    }
    if (stage.getStageEntity().getStageState() != StageState.ACTIVE) {
        return false;
    }
    StageEntity stageEntity = stage.getStageEntity();
    if (stageEntity.getExecutorName() == null || stageEntity.getExecutorData() == null || stageEntity.getExecutorParams() == null) {
        return false;
    }
    StageExecutor deserializedExecutor = deserializeExecutor(stage, deserialize);
    if (deserializedExecutor == null) {
        logContext(log.atSevere(), stage).log("Failed to deserialize executor");
        return false;
    }
    if (deserialize == Deserialize.ASYNC_EXECUTOR) {
        AbstractAsyncExecutor deserializedAsyncExecutor = (AbstractAsyncExecutor) deserializedExecutor;
        if (deserializedAsyncExecutor.getJobId() == null) {
            return false;
        }
    }
    ExecutorParameters deserializedExecutorParams = deserializeExecutorParameters(stage, deserializedExecutor.getExecutorParamsType());
    if (deserializedExecutorParams == null) {
        return false;
    }
    logContext(log.atInfo(), stage).log("Using deserialized executor");
    stage.setExecutor(deserializedExecutor);
    deserializedExecutor.setExecutorParams(deserializedExecutorParams);
    return true;
}
Also used : JsonSerializableExecutor(pipelite.executor.JsonSerializableExecutor) ExecutorParameters(pipelite.stage.parameters.ExecutorParameters) StageEntity(pipelite.entity.StageEntity) AbstractAsyncExecutor(pipelite.executor.AbstractAsyncExecutor)

Aggregations

StageEntity (pipelite.entity.StageEntity)2 JsonSerializableExecutor (pipelite.executor.JsonSerializableExecutor)2 AbstractAsyncExecutor (pipelite.executor.AbstractAsyncExecutor)1 StageExecutor (pipelite.stage.executor.StageExecutor)1 ExecutorParameters (pipelite.stage.parameters.ExecutorParameters)1