#1665 Add error handling and logging to command file execution

This commit is contained in:
Bjørnar Grip Fjær 2017-07-27 14:26:59 +02:00
parent ab1322c5d7
commit d0564c4d2a
9 changed files with 113 additions and 22 deletions

View File

@ -21,6 +21,8 @@
#include "RifcCommandFileReader.h"
#include "RicfCommandObject.h"
#include "RiaLogging.h"
namespace caf {
template<>
void RicfCommandFileExecutor::ExportTypeEnum::setUp()
@ -55,7 +57,14 @@ void RicfCommandFileExecutor::executeCommands(QTextStream& stream)
std::vector<RicfCommandObject*> commands = RicfCommandFileReader::readCommands(stream, caf::PdmDefaultObjectFactory::instance(), &m_messages);
for (auto message : m_messages.m_messages)
{
std::cout << message.second.toUtf8().constData();
if (message.first == RicfMessages::MESSAGE_WARNING)
{
RiaLogging::warning(message.second);
}
else
{
RiaLogging::error(message.second);
}
}
for (RicfCommandObject* command : commands)
{

View File

@ -1,4 +1,3 @@
#include "RicfComputeCaseGroupStatistics.h"
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
@ -29,6 +28,7 @@
#include "RimView.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
CAF_PDM_SOURCE_INIT(RicfComputeCaseGroupStatistics, "computeCaseGroupStatistics");
@ -47,6 +47,7 @@ void RicfComputeCaseGroupStatistics::execute()
{
for (int caseId : m_caseIds())
{
bool foundCase = false;
for (RimIdenticalGridCaseGroup* group : RiaApplication::instance()->project()->activeOilField()->analysisModels()->caseGroups)
{
for (RimEclipseCase* c : group->statisticsCaseCollection->reservoirs)
@ -58,8 +59,21 @@ void RicfComputeCaseGroupStatistics::execute()
{
statsCase->computeStatisticsAndUpdateViews();
}
else
{
RiaLogging::warning(QString("computeCaseGroupStatistics: Found case with ID %1, but it is not a statistics case, cannot compute statistics.").arg(caseId));
}
foundCase = true;
break;
}
}
if (foundCase) break;
}
if (!foundCase)
{
RiaLogging::warning(QString("computeCaseGroupStatistics: Could not find statistics case with ID %1.").arg(caseId));
}
}
}

View File

@ -21,6 +21,7 @@
#include "RicfCommandFileExecutor.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RimProject.h"
#include "RimOilField.h"
@ -51,12 +52,22 @@ void RicfExportMsw::execute()
{
RicCaseAndFileExportSettingsUi exportSettings;
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels->cases())
{
if (c->caseId() == m_caseId())
bool foundCase = false;
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels->cases())
{
exportSettings.caseToApply = c;
break;
if (c->caseId() == m_caseId())
{
exportSettings.caseToApply = c;
foundCase = true;
break;
}
}
if (!foundCase)
{
RiaLogging::error(QString("exportMsw: Could not find case with ID %1.").arg(m_caseId()));
return;
}
}
@ -68,6 +79,11 @@ void RicfExportMsw::execute()
exportSettings.folder = exportFolder;
RimWellPath* wellPath = RiaApplication::instance()->project()->activeOilField()->wellPathCollection->wellPathByName(m_wellPathName);
if (!wellPath)
{
RiaLogging::error(QString("exportMsw: Could not find well path with name %1").arg(m_wellPathName()));
return;
}
std::vector<RimFishbonesMultipleSubs*> fishbonesSubs;

View File

@ -21,6 +21,8 @@
#include "RicfCommandFileExecutor.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RimProject.h"
#include "RimOilField.h"
#include "RimEclipseCaseCollection.h"
@ -61,12 +63,21 @@ void RicfExportProperty::execute()
RimEclipseCase* eclipseCase;
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels()->cases)
{
if (c->caseId == m_caseId)
bool foundCase = false;
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels()->cases)
{
eclipseCase = c;
break;
if (c->caseId == m_caseId)
{
eclipseCase = c;
foundCase = true;
break;
}
}
if (!foundCase)
{
RiaLogging::error(QString("exportProperty: Could not find case with ID %1").arg(m_caseId()));
return;
}
}
@ -77,6 +88,11 @@ void RicfExportProperty::execute()
view = dynamic_cast<RimEclipseView*>(v);
if (view) break;
}
if (!view)
{
RiaLogging::error(QString("exportProperty: Could not find a view for case with ID %1").arg(m_caseId()));
return;
}
if (m_eclipseKeyword().isNull())
{

View File

@ -21,6 +21,7 @@
#include "RicfCommandFileExecutor.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RimProject.h"
#include "RimOilField.h"
@ -63,12 +64,21 @@ void RicfExportWellPathCompletions::execute()
exportSettings.includeFishbones = m_includeFishbones;
exportSettings.excludeMainBoreForFishbones = m_excludeMainBoreForFishbones;
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels->cases())
{
if (c->caseId() == m_caseId())
bool foundCase = false;
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels->cases())
{
exportSettings.caseToApply = c;
break;
if (c->caseId() == m_caseId())
{
exportSettings.caseToApply = c;
foundCase = true;
break;
}
}
if (!foundCase)
{
RiaLogging::error(QString("exportWellPathCompletions: Could not find case with ID %1").arg(m_caseId()));
return;
}
}

View File

@ -19,6 +19,7 @@
#include "RicfLoadCase.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
CAF_PDM_SOURCE_INIT(RicfLoadCase, "loadCase");
@ -35,5 +36,9 @@ RicfLoadCase::RicfLoadCase()
//--------------------------------------------------------------------------------------------------
void RicfLoadCase::execute()
{
RiaApplication::instance()->openEclipseCaseFromFile(m_path);
bool ok = RiaApplication::instance()->openEclipseCaseFromFile(m_path);
if (!ok)
{
RiaLogging::error(QString("loadCase: Unable to load case from %1").arg(m_path()));
}
}

View File

@ -19,6 +19,7 @@
#include "RicfOpenProject.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
CAF_PDM_SOURCE_INIT(RicfOpenProject, "openProject");
@ -35,5 +36,9 @@ RicfOpenProject::RicfOpenProject()
//--------------------------------------------------------------------------------------------------
void RicfOpenProject::execute()
{
RiaApplication::instance()->loadProject(m_path);
bool ok = RiaApplication::instance()->loadProject(m_path);
if (!ok)
{
RiaLogging::error(QString("openProject: Unable to open project at %1").arg(m_path()));
}
}

View File

@ -20,6 +20,7 @@
#include "RicfRunOctaveScript.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include <QFileInfo>
@ -46,12 +47,17 @@ void RicfRunOctaveScript::execute()
processArguments << "--path" << scriptFileInfo.absolutePath();
processArguments << scriptFileInfo.absoluteFilePath();
bool ok;
if (m_caseIds().empty())
{
RiaApplication::instance()->launchProcess(octavePath, processArguments);
ok = RiaApplication::instance()->launchProcess(octavePath, processArguments);
}
else
{
RiaApplication::instance()->launchProcessForMultipleCases(octavePath, processArguments, m_caseIds());
ok = RiaApplication::instance()->launchProcessForMultipleCases(octavePath, processArguments, m_caseIds());
}
if (!ok)
{
RiaLogging::error(QString("runOctaveScript: Could not execute script %1").arg(m_path()));
}
}

View File

@ -26,6 +26,7 @@
#include "RimView.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
CAF_PDM_SOURCE_INIT(RicfSetTimeStep, "setTimeStep");
@ -45,12 +46,21 @@ void RicfSetTimeStep::execute()
{
RimEclipseCase* eclipseCase;
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels()->cases)
{
if (c->caseId == m_caseId)
bool foundCase = false;
for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels()->cases)
{
eclipseCase = c;
break;
if (c->caseId == m_caseId)
{
eclipseCase = c;
foundCase = true;
break;
}
}
if (!foundCase)
{
RiaLogging::error(QString("setTimeStep: Could not find case with ID %1").arg(m_caseId()));
return;
}
}