Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging #40

Merged
merged 21 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bb5eed3
added NX_PRINT outputs for all error returns
Dabnsky Aug 2, 2024
18ddd3b
added NX_PRINT lines for general info
Dabnsky Aug 2, 2024
1924124
added another error NX_PRINT line before return
Dabnsky Aug 2, 2024
01765ca
Removed "generated passphrase" print
Dabnsky Aug 13, 2024
460197b
dropped checking mountDir has correct permissions print
Dabnsky Aug 13, 2024
0f82967
added "the mount directory does not exist" to print
Dabnsky Aug 13, 2024
d7177ab
moved print to else block and modified it to "creating file cache sin…
Dabnsky Aug 13, 2024
5dcbc85
moved spawn prococess prints out of platform specific conditional cod…
Dabnsky Aug 13, 2024
3b703ea
added print for error on active settings
Dabnsky Aug 13, 2024
fc666b0
adjusted mount directory error print
Dabnsky Aug 14, 2024
d7a1bfc
added error logging for mounting dir
Dabnsky Aug 16, 2024
4f9c63a
moved Print into if code block
Dabnsky Aug 16, 2024
a5f551a
corrected print location above if condtion and in function scope
Dabnsky Aug 16, 2024
9ccf165
pulled print out from platform flags
Dabnsky Aug 16, 2024
1c25782
pulled print out of platform flags for dryRun
Dabnsky Aug 16, 2024
ad13038
Merge commit 'e235b2c1156439804653c0957d5a223de30f434d' into add-logging
Dabnsky Aug 16, 2024
20f938d
ran clang-format on file
Dabnsky Aug 16, 2024
458089d
ran clang-format on file in question for github action
Dabnsky Aug 16, 2024
a160f05
removed std:endl on all NX_PRINT lines
Dabnsky Aug 16, 2024
989c758
removed remaining std::endl of NX_PRINT lines
Dabnsky Aug 16, 2024
dbdbb4c
removed empty line
Dabnsky Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/cloudfuse/child_process_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CloudfuseMngr::CloudfuseMngr()
{
std::string systemName = getSystemName();
// NOTE: increment the version number when the config template changes
templateVersionString= "template-version: 0.1";
templateVersionString = "template-version: 0.1";
std::string config_template = templateVersionString + R"(
allow-other: true
logging:
Expand Down
54 changes: 39 additions & 15 deletions src/plugin/settings/engine.cpp
foodprocessor marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using namespace nx::kit;
Engine::Engine(Plugin *plugin)
: nx::sdk::analytics::Engine(NX_DEBUG_ENABLE_OUTPUT, plugin->instanceId()), m_plugin(plugin), cfManager()
{
NX_PRINT << "cloudfuse Engine::Engine" << std::endl;
NX_PRINT << "cloudfuse Engine::Engine";
for (const auto &entry : kActiveSettingsRules)
{
const ActiveSettingsBuilder::ActiveSettingKey key = entry.first;
Expand All @@ -61,18 +61,17 @@ Engine::Engine(Plugin *plugin)

Engine::~Engine()
{
NX_PRINT << "cloudfuse Engine::~Engine unmount cloudfuse" << std::endl;
NX_PRINT << "cloudfuse Engine::~Engine unmount cloudfuse";
const processReturn unmountRet = cfManager.unmount();
if (unmountRet.errCode != 0)
{
NX_PRINT << "cloudfuse Engine::~Engine failed to unmount cloudfuse with error: " + unmountRet.output
<< std::endl;
NX_PRINT << "cloudfuse Engine::~Engine failed to unmount cloudfuse with error: " + unmountRet.output;
}
}

void Engine::doObtainDeviceAgent(Result<IDeviceAgent *> *outResult, const IDeviceInfo *deviceInfo)
{
NX_PRINT << "cloudfuse Engine::doObtainDeviceAgent" << std::endl;
NX_PRINT << "cloudfuse Engine::doObtainDeviceAgent";
*outResult = new DeviceAgent(this, deviceInfo);
}

Expand All @@ -92,7 +91,7 @@ static std::string buildCapabilities()

std::string Engine::manifestString() const
{
NX_PRINT << "cloudfuse Engine::manifestString" << std::endl;
NX_PRINT << "cloudfuse Engine::manifestString";
std::string result = /*suppress newline*/ 1 + (const char *)R"json(
{
"capabilities": ")json" +
Expand All @@ -109,7 +108,7 @@ std::string Engine::manifestString() const
bool Engine::processActiveSettings(Json::object *model, std::map<std::string, std::string> *values,
const std::vector<std::string> &settingIdsToUpdate) const
{
NX_PRINT << "cloudfuse Engine::processActiveSettings" << std::endl;
NX_PRINT << "cloudfuse Engine::processActiveSettings";
Json::array items = (*model)[kItems].array_items();

auto activeSettingsGroupBoxIt = std::find_if(items.begin(), items.end(), [](Json &item) {
Expand Down Expand Up @@ -196,7 +195,7 @@ bool Engine::settingsChanged()

Result<const ISettingsResponse *> Engine::settingsReceived()
{
NX_PRINT << "cloudfuse Engine::settingsReceived" << std::endl;
NX_PRINT << "cloudfuse Engine::settingsReceived";
std::string parseError;
Json::object model = Json::parse(kEngineSettingsModel, parseError).object_items();

Expand All @@ -208,7 +207,7 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
updatePrevSettings(values);
if (mountRequired)
{
NX_PRINT << "Values changed" << std::endl;
NX_PRINT << "Values changed";
const std::string keyId = values[kKeyIdTextFieldId];
const std::string secretKey = values[kSecretKeyPasswordFieldId];
const std::string endpointUrl = values[kEndpointUrlTextFieldId];
Expand Down Expand Up @@ -238,12 +237,14 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
}
else
{
NX_PRINT << "OpenSSL Error: Unable to generate secure passphrase";
return error(ErrorCode::internalError, "OpenSSL Error: Unable to generate secure passphrase");
}

std::error_code errCode;

// Create mount directory if it does not exist
NX_PRINT << "Creating mount directory if it does not exist";
if (fs::exists(mountDir))
{
// Unmount before mounting
Expand All @@ -261,6 +262,7 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
fs::permissions(mountDir, fs::perms::all, fs::perm_options::add, errCode);
if (errCode)
{
NX_PRINT << "Unable to set mount directory permission with error: " + errCode.message();
return error(ErrorCode::internalError,
"Unable to set mount directory permission with error: " + errCode.message());
}
Expand All @@ -271,14 +273,17 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
{
#if defined(__linux__)
// On Linux we need to create the folder if it does not yet exist
NX_PRINT << "creating the folder since it does not yet exist";
if (!fs::create_directory(mountDir, errCode))
{
NX_PRINT << "Unable to create mount directory with error: " + errCode.message();
return error(ErrorCode::internalError,
foodprocessor marked this conversation as resolved.
Show resolved Hide resolved
"Unable to create mount directory with error: " + errCode.message());
}
fs::permissions(mountDir, fs::perms::all, fs::perm_options::add, errCode);
if (errCode)
{
NX_PRINT << "Unable to set mount directory permissions with error: " + errCode.message();
return error(ErrorCode::internalError,
"Unable to set mount directory permissions with error: " + errCode.message());
}
Expand All @@ -294,31 +299,37 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
fs::permissions(fileCacheDir, fs::perms::all, fs::perm_options::add, errCode);
if (errCode)
{
NX_PRINT << "Unable to set mount directory permission with error: " + errCode.message();
return error(ErrorCode::internalError,
"Unable to set mount directory permission with error: " + errCode.message());
}
}
}
else
{
NX_PRINT << "creating file cache since it does not exist";
if (!fs::create_directories(fileCacheDir, errCode))
{
NX_PRINT << "Unable to create file cache directory " + fileCacheDir +
" with error: " + errCode.message();
return error(ErrorCode::internalError, "Unable to create file cache directory " + fileCacheDir +
" with error: " + errCode.message());
}
fs::permissions(fileCacheDir, fs::perms::all, fs::perm_options::add, errCode);
if (errCode)
{
NX_PRINT << "Unable to set file cache directory permissions with error: " + errCode.message();
return error(ErrorCode::internalError,
"Unable to set file cache directory permissions with error: " + errCode.message());
}
}

if (!cfManager.isInstalled())
{
NX_PRINT << "Cloudfuse is not installed";
return error(ErrorCode::internalError, "Cloudfuse is not installed");
}

NX_PRINT << "spawning process from genS3Config";
#if defined(__linux__)
const processReturn dryGenConfig = cfManager.genS3Config(endpointRegion, endpointUrl, bucketName, passphrase);
#elif defined(_WIN32)
Expand All @@ -328,9 +339,10 @@ Result<const ISettingsResponse *> Engine::settingsReceived()

if (dryGenConfig.errCode != 0)
{
NX_PRINT << "Unable to generate config file with error: " + dryGenConfig.output;
return error(ErrorCode::internalError, "Unable to generate config file with error: " + dryGenConfig.output);
}

NX_PRINT << "spawning process from dryRun";
#if defined(__linux__)
const processReturn dryRunRet = cfManager.dryRun(keyId, secretKey, passphrase);
#elif defined(_WIN32)
Expand All @@ -344,6 +356,7 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
Engine::pushPluginDiagnosticEvent(IPluginDiagnosticEvent::Level::error, "Plugin Bucket Error",
"Error with provided cloud bucket: " +
parseCloudfuseError(dryRunRet.output));
NX_PRINT << "Unable to authenticate with bucket: " + parseCloudfuseError(dryRunRet.output);
return error(ErrorCode::otherError,
"Unable to authenticate with bucket: " + parseCloudfuseError(dryRunRet.output));
}
Expand All @@ -352,6 +365,8 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
Engine::pushPluginDiagnosticEvent(
IPluginDiagnosticEvent::Level::error, "Plugin Credential or Endpoint Error",
"Error with cloud credentials or incorrect endpoint: " + parseCloudfuseError(dryRunRet.output));
NX_PRINT << "Error with cloud credentials or incorrect endpoint: " +
parseCloudfuseError(dryRunRet.output);
return error(ErrorCode::otherError, "Error with cloud credentials or incorrect endpoint: " +
parseCloudfuseError(dryRunRet.output));
}
Expand All @@ -360,6 +375,7 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
Engine::pushPluginDiagnosticEvent(IPluginDiagnosticEvent::Level::error, "Plugin Endpoint Error",
"Error with provided endpoint: " +
parseCloudfuseError(dryRunRet.output));
NX_PRINT << "Error with provided endpoint: " + parseCloudfuseError(dryRunRet.output);
return error(ErrorCode::otherError,
"Error with provided endpoint: " + parseCloudfuseError(dryRunRet.output));
}
Expand All @@ -368,6 +384,7 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
Engine::pushPluginDiagnosticEvent(IPluginDiagnosticEvent::Level::error, "Plugin Secret Error",
"Secret key provided is incorrect: " +
parseCloudfuseError(dryRunRet.output));
NX_PRINT << "Error with provided endpoint: " + parseCloudfuseError(dryRunRet.output);
return error(ErrorCode::otherError,
"Secret key provided is incorrect: " + parseCloudfuseError(dryRunRet.output));
}
Expand All @@ -376,10 +393,11 @@ Result<const ISettingsResponse *> Engine::settingsReceived()
Engine::pushPluginDiagnosticEvent(IPluginDiagnosticEvent::Level::error, "Plugin Error",
"Unable to validate credentials with error: " +
parseCloudfuseError(dryRunRet.output));
NX_PRINT << "Unable to validate credentials with error: " + parseCloudfuseError(dryRunRet.output);
return error(ErrorCode::otherError,
"Unable to validate credentials with error: " + parseCloudfuseError(dryRunRet.output));
}

NX_PRINT << "spawning process from mount";
#if defined(__linux__)
const processReturn mountRet = cfManager.mount(keyId, secretKey, passphrase);
#elif defined(_WIN32)
Expand All @@ -388,6 +406,7 @@ Result<const ISettingsResponse *> Engine::settingsReceived()

if (mountRet.errCode != 0)
{
NX_PRINT << "Unable to launch mount with error: " + mountRet.output;
return error(ErrorCode::internalError, "Unable to launch mount with error: " + mountRet.output);
}

Expand All @@ -401,16 +420,20 @@ Result<const ISettingsResponse *> Engine::settingsReceived()

if (retryCount == 10)
{
NX_PRINT << "Cloudfuse was not able to successfully mount";
return error(ErrorCode::internalError, "Cloudfuse was not able to successfully mount");
}
}
else
{
NX_PRINT << "Settings have not changed." << std::endl;
NX_PRINT << "Settings have not changed.";
}

if (!processActiveSettings(&model, &values))
{
NX_PRINT << "Unable to process the active settings section";
return error(ErrorCode::internalError, "Unable to process the active settings section");
}

auto settingsResponse = new SettingsResponse();
settingsResponse->setModel(makePtr<String>(Json(model).dump()));
Expand All @@ -421,7 +444,7 @@ Result<const ISettingsResponse *> Engine::settingsReceived()

void Engine::getPluginSideSettings(Result<const ISettingsResponse *> *outResult) const
{
NX_PRINT << "cloudfuse Engine::getPluginSideSettings" << std::endl;
NX_PRINT << "cloudfuse Engine::getPluginSideSettings";
auto settingsResponse = new SettingsResponse();
settingsResponse->setValue(kEnginePluginSideSetting, kEnginePluginSideSettingValue);

Expand All @@ -431,7 +454,7 @@ void Engine::getPluginSideSettings(Result<const ISettingsResponse *> *outResult)
void Engine::doGetSettingsOnActiveSettingChange(Result<const IActiveSettingChangedResponse *> *outResult,
const IActiveSettingChangedAction *activeSettingChangedAction)
{
NX_PRINT << "cloudfuse Engine::doGetSettingsOnActiveSettingChange" << std::endl;
NX_PRINT << "cloudfuse Engine::doGetSettingsOnActiveSettingChange";
std::string parseError;
Json::object model = Json::parse(activeSettingChangedAction->settingsModel(), parseError).object_items();

Expand All @@ -441,6 +464,7 @@ void Engine::doGetSettingsOnActiveSettingChange(Result<const IActiveSettingChang

if (!processActiveSettings(&model, &values, {settingId}))
{
NX_PRINT << "Unable to process the active settings section";
*outResult = error(ErrorCode::internalError, "Unable to process the active settings section");

return;
Expand Down
Loading