}
public synchronized RiskRun startBatchInTransaction(ViewCycleMetadata cycleMetadata, Map<String, String> batchParameters, RunCreationMode runCreationMode, SnapshotMode snapshotMode) {
s_logger.info("Starting batch ... {}", cycleMetadata);
RiskRun run;
switch (runCreationMode) {
case AUTO:
run = findRiskRunInDb(cycleMetadata.getValuationTime(), cycleMetadata.getVersionCorrection(),
cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId());
if (run != null) {
// also check parameter equality
Map<String, String> existingProperties = run.getPropertiesMap();
if (!existingProperties.equals(batchParameters)) {
Set<Map.Entry<String, String>> symmetricDiff = Sets.symmetricDifference(existingProperties.entrySet(), batchParameters.entrySet());
throw new IllegalStateException("Run parameters stored in DB differ from new parameters with respect to: " + symmetricDiff);
}
}
if (run == null) {
run = createRiskRunInTransaction(cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId(),
cycleMetadata.getVersionCorrection(), cycleMetadata.getValuationTime(), batchParameters, snapshotMode);
} else {
restartRunInTransaction(run);
}
break;
case CREATE_NEW_OVERWRITE:
run = findRiskRunInDb(cycleMetadata.getValuationTime(), cycleMetadata.getVersionCorrection(), cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId());
if (run != null) {
deleteRunInTransaction(run);
}
run = createRiskRunInTransaction(cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId(),
cycleMetadata.getVersionCorrection(), cycleMetadata.getValuationTime(), batchParameters, snapshotMode);
break;
case CREATE_NEW:
run = createRiskRunInTransaction(cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId(),
cycleMetadata.getVersionCorrection(), cycleMetadata.getValuationTime(), batchParameters, snapshotMode);
break;
case REUSE_EXISTING:
run = findRiskRunInDb(cycleMetadata.getValuationTime(), cycleMetadata.getVersionCorrection(), cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId());
if (run == null) {
throw new IllegalStateException("Cannot find run in database for " + cycleMetadata);
}
restartRunInTransaction(run);
break;
default:
throw new RuntimeException("Unexpected run creation mode " + runCreationMode);
}
populateCalculationConfigurations(run.getId(), cycleMetadata);
populateRiskValueRequirements(cycleMetadata);
Collection<ComputationTargetSpecification> computationTargets = newArrayList();
for (final String configName : cycleMetadata.getAllCalculationConfigurationNames()) {
for (com.opengamma.engine.ComputationTargetSpecification computationTarget : cycleMetadata.getComputationTargets(configName)) {
computationTargets.add(computationTarget);
}
}
populateComputationTargets(computationTargets);
_statusCacheByRunId.put(run.getId(), new ConcurrentHashMap<Pair<Long, Long>, StatusEntry>());
_computeFailureCacheByRunId.put(run.getId(), new ConcurrentHashMap<ComputeFailureKey, ComputeFailure>());
_riskRunsByIds.put(run.getId(), run);
return run;
}