Skip to content
Snippets Groups Projects
Commit b5f6b741 authored by jakubs's avatar jakubs
Browse files

BIS-376 SP-574 Add error during prepare phase should also trigger rollback_pre_registration

SVN: 28664
parent 5f11e1f0
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,8 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec ...@@ -40,6 +40,8 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec
public static final String STORAGE_PROCESSOR_ERROR_KEY = "storage-processor-error"; public static final String STORAGE_PROCESSOR_ERROR_KEY = "storage-processor-error";
public static final String PREPARATION_ERROR_KEY = "preparation-error";
public static final String POST_REGISTRATION_ERROR_KEY = "post-registration-error"; public static final String POST_REGISTRATION_ERROR_KEY = "post-registration-error";
public static final String PRE_REGISTRATION_ERROR_KEY = "pre-registration-error"; public static final String PRE_REGISTRATION_ERROR_KEY = "pre-registration-error";
...@@ -58,6 +60,8 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec ...@@ -58,6 +60,8 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec
private final UnstoreDataAction preRegistrationError; private final UnstoreDataAction preRegistrationError;
private final UnstoreDataAction preparationError;
public ConfiguredOnErrorActionDecision(Properties properties) public ConfiguredOnErrorActionDecision(Properties properties)
{ {
invalidDataSetAction = getAction(ErrorType.INVALID_DATA_SET, properties); invalidDataSetAction = getAction(ErrorType.INVALID_DATA_SET, properties);
...@@ -65,9 +69,10 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec ...@@ -65,9 +69,10 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec
openbisRegistrationFailure = getAction(ErrorType.OPENBIS_REGISTRATION_FAILURE, properties); openbisRegistrationFailure = getAction(ErrorType.OPENBIS_REGISTRATION_FAILURE, properties);
registrationScriptError = getAction(ErrorType.REGISTRATION_SCRIPT_ERROR, properties); registrationScriptError = getAction(ErrorType.REGISTRATION_SCRIPT_ERROR, properties);
storageProcessorError = getAction(ErrorType.STORAGE_PROCESSOR_ERROR, properties); storageProcessorError = getAction(ErrorType.STORAGE_PROCESSOR_ERROR, properties);
preparationError = getAction(ErrorType.PREPARATION_ERROR, properties);
postRegistrationError = getAction(ErrorType.POST_REGISTRATION_ERROR, properties); postRegistrationError = getAction(ErrorType.POST_REGISTRATION_ERROR, properties);
preRegistrationError = getAction(ErrorType.PRE_REGISTRATION_ERROR, properties); preRegistrationError = getAction(ErrorType.PRE_REGISTRATION_ERROR, properties);
} }
@Override @Override
public UnstoreDataAction computeUndoAction(ErrorType errorType, Throwable failureOrNull) public UnstoreDataAction computeUndoAction(ErrorType errorType, Throwable failureOrNull)
...@@ -87,6 +92,9 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec ...@@ -87,6 +92,9 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec
case STORAGE_PROCESSOR_ERROR: case STORAGE_PROCESSOR_ERROR:
action = storageProcessorError; action = storageProcessorError;
break; break;
case PREPARATION_ERROR:
action = preparationError;
break;
case VALIDATION_SCRIPT_ERROR: case VALIDATION_SCRIPT_ERROR:
action = validationScriptError; action = validationScriptError;
break; break;
...@@ -127,6 +135,9 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec ...@@ -127,6 +135,9 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec
case PRE_REGISTRATION_ERROR: case PRE_REGISTRATION_ERROR:
actionStringKey = PRE_REGISTRATION_ERROR_KEY; actionStringKey = PRE_REGISTRATION_ERROR_KEY;
break; break;
case PREPARATION_ERROR:
actionStringKey = PREPARATION_ERROR_KEY;
break;
} }
String actionString = PropertyUtils.getProperty(properties, actionStringKey); String actionString = PropertyUtils.getProperty(properties, actionStringKey);
...@@ -159,7 +170,8 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec ...@@ -159,7 +170,8 @@ public class ConfiguredOnErrorActionDecision implements IDataSetOnErrorActionDec
case VALIDATION_SCRIPT_ERROR: case VALIDATION_SCRIPT_ERROR:
case POST_REGISTRATION_ERROR: case POST_REGISTRATION_ERROR:
case PRE_REGISTRATION_ERROR: case PRE_REGISTRATION_ERROR:
action = UnstoreDataAction.LEAVE_UNTOUCHED; case PREPARATION_ERROR:
action = UnstoreDataAction.LEAVE_UNTOUCHED;
break; break;
} }
......
...@@ -180,7 +180,23 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation> ...@@ -180,7 +180,23 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation>
/** /**
* Prepare registration of a data set. * Prepare registration of a data set.
*/ */
public final void prepare() public final boolean safePrepare()
{
try
{
prepare();
} catch (final Throwable throwable)
{
rollbackDuringPreparation(throwable);
return false;
}
dssRegistrationLog.log("Preparation ready");
return true;
}
private final void prepare()
{ {
// Log information about the prepare // Log information about the prepare
StringBuilder registrationSummary = new StringBuilder(); StringBuilder registrationSummary = new StringBuilder();
...@@ -300,7 +316,10 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation> ...@@ -300,7 +316,10 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation>
*/ */
public boolean prepareAndRunStorageAlgorithms() public boolean prepareAndRunStorageAlgorithms()
{ {
prepare(); if (safePrepare() == false)
{
return false;
}
// all algorithms are now in // all algorithms are now in
// PREPARED STATE // PREPARED STATE
...@@ -445,6 +464,13 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation> ...@@ -445,6 +464,13 @@ public class DataSetStorageAlgorithmRunner<T extends DataSetInformation>
ErrorType.STORAGE_PROCESSOR_ERROR); ErrorType.STORAGE_PROCESSOR_ERROR);
} }
private void rollbackDuringPreparation(Throwable ex)
{
operationLog.error("Failed to prepare");
rollbackStorageProcessors(ex);
rollbackDelegate.didRollbackStorageAlgorithmRunner(this, ex, ErrorType.PREPARATION_ERROR);
}
private void rollbackDuringPreRegistration(Throwable ex) private void rollbackDuringPreRegistration(Throwable ex)
{ {
operationLog.error("Failed to pre-register", ex); operationLog.error("Failed to pre-register", ex);
......
...@@ -29,7 +29,7 @@ public interface IDataSetOnErrorActionDecision ...@@ -29,7 +29,7 @@ public interface IDataSetOnErrorActionDecision
{ {
INVALID_DATA_SET, VALIDATION_SCRIPT_ERROR, REGISTRATION_SCRIPT_ERROR, INVALID_DATA_SET, VALIDATION_SCRIPT_ERROR, REGISTRATION_SCRIPT_ERROR,
PRE_REGISTRATION_ERROR, OPENBIS_REGISTRATION_FAILURE, STORAGE_PROCESSOR_ERROR, PRE_REGISTRATION_ERROR, OPENBIS_REGISTRATION_FAILURE, STORAGE_PROCESSOR_ERROR,
POST_REGISTRATION_ERROR; PREPARATION_ERROR, POST_REGISTRATION_ERROR;
} }
UnstoreDataAction computeUndoAction(ErrorType errorType, Throwable failureOrNull); UnstoreDataAction computeUndoAction(ErrorType errorType, Throwable failureOrNull);
......
...@@ -254,6 +254,7 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractJythonDataSetH ...@@ -254,6 +254,7 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractJythonDataSetH
ConfiguredOnErrorActionDecision.POST_REGISTRATION_ERROR_KEY, ConfiguredOnErrorActionDecision.POST_REGISTRATION_ERROR_KEY,
ConfiguredOnErrorActionDecision.REGISTRATION_SCRIPT_ERROR_KEY, ConfiguredOnErrorActionDecision.REGISTRATION_SCRIPT_ERROR_KEY,
ConfiguredOnErrorActionDecision.STORAGE_PROCESSOR_ERROR_KEY, ConfiguredOnErrorActionDecision.STORAGE_PROCESSOR_ERROR_KEY,
ConfiguredOnErrorActionDecision.PREPARATION_ERROR_KEY,
ConfiguredOnErrorActionDecision.VALIDATION_SCRIPT_ERROR_KEY, }; ConfiguredOnErrorActionDecision.VALIDATION_SCRIPT_ERROR_KEY, };
// simple test failing registration testCase // simple test failing registration testCase
......
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