mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4474 Add command for getting runtime info (i.e. console/gui)
* Also fixed up some tests when running in console
This commit is contained in:
parent
eec5569eca
commit
1a337ea0f8
@ -7,6 +7,7 @@ import "Empty.proto";
|
||||
service App {
|
||||
rpc GetVersion(Empty) returns (Version) {}
|
||||
rpc Exit(Empty) returns (Empty) {}
|
||||
rpc GetRuntimeInfo(Empty) returns (RuntimeInfo) {}
|
||||
}
|
||||
|
||||
message Version {
|
||||
@ -14,3 +15,14 @@ message Version {
|
||||
int32 minor_version = 2;
|
||||
int32 patch_version = 3;
|
||||
}
|
||||
|
||||
enum ApplicationTypeEnum
|
||||
{
|
||||
GUI_APPLICATION = 0;
|
||||
CONSOLE_APPLICATION = 1;
|
||||
}
|
||||
|
||||
message RuntimeInfo
|
||||
{
|
||||
ApplicationTypeEnum app_type = 1;
|
||||
}
|
@ -23,4 +23,11 @@ class App:
|
||||
def versionString(self):
|
||||
return str(self.majorVersion()) + "." + str(self.minorVersion()) + "." + str(self.patchVersion())
|
||||
def exit(self):
|
||||
print("Telling ResInsight to Exit")
|
||||
return self.app.Exit(Empty())
|
||||
def isConsole(self):
|
||||
print("RunTimeInfo stuff: ", self.app.GetRuntimeInfo(Empty()).app_type)
|
||||
return self.app.GetRuntimeInfo(Empty()).app_type == App_pb2.ApplicationTypeEnum.Value('CONSOLE_APPLICATION')
|
||||
def isGui(self):
|
||||
print("RunTimeInfo stuff: ", self.app.GetRuntimeInfo(Empty()).app_type)
|
||||
return self.app.GetRuntimeInfo(Empty()).app_type == App_pb2.ApplicationTypeEnum.Value('GUI_APPLICATION')
|
||||
|
@ -13,6 +13,8 @@ from .Commands import Commands
|
||||
from .Project import Project
|
||||
|
||||
class Instance:
|
||||
launched = False
|
||||
|
||||
@staticmethod
|
||||
def is_port_in_use(port):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
@ -20,7 +22,7 @@ class Instance:
|
||||
return s.connect_ex(('localhost', port)) == 0
|
||||
|
||||
@staticmethod
|
||||
def launch(resInsightExecutable = ''):
|
||||
def launch(resInsightExecutable = '', console = False):
|
||||
port = 50051
|
||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||
if portEnv:
|
||||
@ -38,9 +40,11 @@ class Instance:
|
||||
|
||||
print('Port ' + str(port))
|
||||
print('Trying to launch', resInsightExecutable)
|
||||
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, " --grpcserver " + str(port))
|
||||
print(pid)
|
||||
return Instance(port)
|
||||
parameters = " --grpcserver " + str(port)
|
||||
if console:
|
||||
parameters += " --console"
|
||||
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, parameters)
|
||||
return Instance(port=port, launched=True)
|
||||
|
||||
@staticmethod
|
||||
def find(startPort = 50051, endPort = 50071):
|
||||
@ -56,10 +60,11 @@ class Instance:
|
||||
print('Error: Could not find any ResInsight instances responding between ports ' + str(startPort) + ' and ' + str(endPort))
|
||||
return None
|
||||
|
||||
def __init__(self, port = 50051):
|
||||
def __init__(self, port = 50051, launched = False):
|
||||
logging.basicConfig()
|
||||
location = "localhost:" + str(port)
|
||||
self.channel = grpc.insecure_channel(location)
|
||||
self.launched = launched
|
||||
|
||||
# Main version check package
|
||||
self.app = App(self.channel)
|
||||
@ -78,3 +83,9 @@ class Instance:
|
||||
self.commands = Commands(self.channel)
|
||||
self.project = Project(self.channel)
|
||||
|
||||
path = os.getcwd()
|
||||
self.commands.setStartDir(path=path)
|
||||
|
||||
def __del__(self):
|
||||
if self.launched:
|
||||
self.app.exit()
|
@ -1,24 +1,28 @@
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
instance = rips.Instance.launch()
|
||||
|
||||
if (not instance):
|
||||
print("A ResInsight instance is required for running the tests")
|
||||
exit(1)
|
||||
_rips_instance = None
|
||||
|
||||
@pytest.fixture
|
||||
def rips_instance():
|
||||
return instance
|
||||
return _rips_instance
|
||||
|
||||
@pytest.fixture
|
||||
def initializeTest():
|
||||
instance.project.close()
|
||||
_rips_instance.project.close()
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
print("Telling ResInsight to Exit")
|
||||
instance.app.exit()
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--console", action="store_true", default=False, help="Run as console application")
|
||||
|
||||
def pytest_configure(config):
|
||||
global _rips_instance
|
||||
console = False
|
||||
if config.getoption('--console'):
|
||||
print("Should run as console app")
|
||||
console = True
|
||||
_rips_instance = rips.Instance.launch(console=console)
|
||||
|
@ -1,6 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
import pytest
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
@ -8,6 +9,9 @@ import rips
|
||||
import dataroot
|
||||
|
||||
def test_exportSnapshots(rips_instance, initializeTest):
|
||||
if not rips_instance.app.isGui():
|
||||
pytest.skip("Cannot run test without a GUI")
|
||||
|
||||
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
rips_instance.project.loadCase(casePath)
|
||||
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
|
||||
|
@ -17,6 +17,7 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
#include "RiaGrpcAppService.h"
|
||||
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaVersionInfo.h"
|
||||
#include "RiaGrpcCallbacks.h"
|
||||
#include "RiaGrpcServer.h"
|
||||
@ -41,14 +42,32 @@ grpc::Status RiaGrpcAppService::Exit(grpc::ServerContext* context, const rips::E
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcAppService::GetRuntimeInfo(grpc::ServerContext* context, const rips::Empty* request, rips::RuntimeInfo* reply)
|
||||
{
|
||||
rips::ApplicationTypeEnum appType = rips::CONSOLE_APPLICATION;
|
||||
if (RiaGuiApplication::isRunning())
|
||||
{
|
||||
appType = rips::GUI_APPLICATION;
|
||||
}
|
||||
reply->set_app_type(appType);
|
||||
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RiaGrpcCallbackInterface*> RiaGrpcAppService::createCallbacks()
|
||||
{
|
||||
typedef RiaGrpcAppService Self;
|
||||
return { new RiaGrpcUnaryCallback<Self, rips::Empty, rips::Version>(this, &Self::GetVersion, &Self::RequestGetVersion),
|
||||
new RiaGrpcUnaryCallback<Self, rips::Empty, rips::Empty>(this, &Self::Exit, &Self::RequestExit) };
|
||||
return {
|
||||
new RiaGrpcUnaryCallback<Self, rips::Empty, rips::Version>(this, &Self::GetVersion, &Self::RequestGetVersion),
|
||||
new RiaGrpcUnaryCallback<Self, rips::Empty, rips::Empty>(this, &Self::Exit, &Self::RequestExit),
|
||||
new RiaGrpcUnaryCallback<Self, rips::Empty, rips::RuntimeInfo>(this, &Self::GetRuntimeInfo, &Self::RequestGetRuntimeInfo)
|
||||
};
|
||||
}
|
||||
|
||||
static bool RiaGrpcAppInfoService_init =
|
||||
|
@ -44,6 +44,7 @@ class RiaGrpcAppService : public rips::App::AsyncService, public RiaGrpcServiceI
|
||||
public:
|
||||
grpc::Status GetVersion(grpc::ServerContext* context, const rips::Empty* request, rips::Version* reply) override;
|
||||
grpc::Status Exit(grpc::ServerContext* context, const rips::Empty* request, rips::Empty* reply) override;
|
||||
grpc::Status GetRuntimeInfo(grpc::ServerContext* context, const rips::Empty* request, rips::RuntimeInfo* reply) override;
|
||||
std::vector<RiaGrpcCallbackInterface*> createCallbacks() override;
|
||||
|
||||
};
|
||||
|
@ -17,8 +17,6 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
#include "RiaGrpcCommandService.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RiaGrpcCallbacks.h"
|
||||
|
||||
#include "RicfSetTimeStep.h"
|
||||
@ -45,7 +43,6 @@ using namespace google::protobuf;
|
||||
grpc::Status RiaGrpcCommandService::Execute(grpc::ServerContext* context, const CommandParams* request, CommandReply* reply)
|
||||
{
|
||||
auto requestDescriptor = request->GetDescriptor();
|
||||
RiaLogging::info(QString::fromStdString(requestDescriptor->name()));
|
||||
|
||||
CommandParams::ParamsCase paramsCase = request->params_case();
|
||||
if (paramsCase != CommandParams::PARAMS_NOT_SET)
|
||||
@ -55,7 +52,6 @@ grpc::Status RiaGrpcCommandService::Execute(grpc::ServerContext* context, const
|
||||
|
||||
const Message& params = request->GetReflection()->GetMessage(*request, grpcOneOfMessage);
|
||||
QString grpcOneOfMessageName = QString::fromStdString(grpcOneOfMessage->name());
|
||||
RiaLogging::info(QString("Found Command: %1").arg(grpcOneOfMessageName));
|
||||
auto pdmObjectHandle = caf::PdmDefaultObjectFactory::instance()->create(grpcOneOfMessageName);
|
||||
auto commandHandle = dynamic_cast<RicfCommandObject*>(pdmObjectHandle);
|
||||
if (commandHandle)
|
||||
@ -71,7 +67,6 @@ grpc::Status RiaGrpcCommandService::Execute(grpc::ServerContext* context, const
|
||||
auto pdmValueFieldHandle = dynamic_cast<caf::PdmValueField*>(pdmObjectHandle->findField(parameterName));
|
||||
if (pdmValueFieldHandle)
|
||||
{
|
||||
RiaLogging::info(QString("Found Matching Parameter: %1").arg(parameterName));
|
||||
assignPdmFieldValue(pdmValueFieldHandle, params, parameter);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user