Skip to content

Commit

Permalink
[install] Check dependency duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
MakarenkoAI committed Jun 14, 2024
1 parent 5918965 commit ea670f9
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace keynodes
{
ScAddr ScComponentManagerKeynodes::myself;
ScAddr ScComponentManagerKeynodes::concept_reusable_component;
ScAddr ScComponentManagerKeynodes::current_components_to_install;
ScAddr ScComponentManagerKeynodes::concept_reusable_kb_component;
ScAddr ScComponentManagerKeynodes::concept_reusable_ps_component;
ScAddr ScComponentManagerKeynodes::concept_reusable_ui_component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class ScComponentManagerKeynodes : public ScObject
SC_PROPERTY(Keynode("concept_reusable_component"), ForceCreate(ScType::NodeConstClass))
static ScAddr concept_reusable_component;

SC_PROPERTY(Keynode("concept_current_components_to_install"), ForceCreate(ScType::NodeConst))
static ScAddr current_components_to_install;

SC_PROPERTY(Keynode("concept_reusable_kb_component"), ForceCreate(ScType::NodeConstClass))
static ScAddr concept_reusable_kb_component;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ SC_AGENT_IMPLEMENTATION(ScComponentManagerInstallAgent)
configManager[PathKeysOfConfigPath::UI_PATH]});

ScComponentManagerCommandInstall command = ScComponentManagerCommandInstall(componentWithConfigPath);
ScAddrUnorderedSet const & identifiersNodes = command.Execute(&m_memoryCtx, actionAddr);
ScAddrVector result(identifiersNodes.begin(), identifiersNodes.end());
utils::AgentUtils::finishAgentWork(&m_memoryCtx, actionAddr, result, true);
ScAddrUnorderedSet const & identifiersNodesSet = command.Execute(&m_memoryCtx, actionAddr);
bool result = !identifiersNodesSet.empty();
ScAddrVector identifiersNodesVector(identifiersNodesSet.begin(), identifiersNodesSet.end());

utils::AgentUtils::finishAgentWork(&m_memoryCtx, actionAddr, identifiersNodesVector, result);
SC_LOG_DEBUG("ScComponentManagerInstallAgent finished");
return SC_RESULT_OK;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,28 @@ bool ScComponentManagerCommandInstall::InstallComponent(ScMemoryContext * contex
return true;
}

bool ScComponentManagerCommandInstall::EraseTempOutputEdges(ScMemoryContext * context, ScAddr const & node)
{
bool result = context->IsElement(node);
if (result)
{
ScIterator3Ptr const & edgesIterator = context->Iterator3(
node, // set of components
ScType::EdgeAccessConstPosTemp,
ScType::NodeConst); // component
while (edgesIterator->Next())
{
context->EraseElement(edgesIterator->Get(1));
}
}
return result;
}

ScAddrUnorderedSet ScComponentManagerCommandInstall::Execute(ScMemoryContext * context, ScAddr const & actionAddr)
{
bool executionResult = true;
ScAddr const & parameterNode =
utils::IteratorUtils::getAnyByOutRelation(context, actionAddr, scAgentsCommon::CoreKeynodes::rrel_1);
ScAddrUnorderedSet componentsToInstall = CommonUtils::GetComponentsToInstall(*context, parameterNode);

if (componentsToInstall.empty())
{
SC_LOG_INFO("ScComponentManagerCommandInstall: No identifier provided, can't install");
Expand All @@ -108,27 +123,35 @@ ScAddrUnorderedSet ScComponentManagerCommandInstall::Execute(ScMemoryContext * c
componentsToInstall = GetAvailableComponents(context, componentsToInstall);

ScAddr decompositionAddr;
bool executionResult = true;
for (ScAddr const & componentAddr : componentsToInstall)
{
if (CommonUtils::CheckIfInstalled(*context, componentAddr))
{
SC_LOG_DEBUG("Component \"" << context->HelperGetSystemIdtf(componentAddr) << "\" is already installed");
continue;
}
executionResult = InstallDependencies(context, componentAddr);

if (executionResult)
context->CreateEdge(
ScType::EdgeAccessConstPosTemp,
keynodes::ScComponentManagerKeynodes::current_components_to_install,
componentAddr);
executionResult &= InstallDependencies(context, componentAddr);
executionResult &=
EraseTempOutputEdges(context, keynodes::ScComponentManagerKeynodes::current_components_to_install);
if (!executionResult)
{
executionResult &= DownloadComponent(context, componentAddr);
executionResult &= InstallComponent(context, componentAddr);
return {};
}
executionResult &= DownloadComponent(context, componentAddr);
executionResult &= InstallComponent(context, componentAddr);
// TODO: need to process installation method from component specification in kb

decompositionAddr = CommonUtils::GetSubsystemDecompositionAddr(*context, componentAddr);
if (context->IsElement(decompositionAddr))
context->CreateEdge(ScType::EdgeAccessConstPosPerm, decompositionAddr, componentAddr);
else
SC_LOG_WARNING(
"Component \"" << context->HelperGetSystemIdtf(componentAddr) << "\" can't be added in myself-decomposition");
"Component \"" << context->HelperGetSystemIdtf(componentAddr) << "\" can't be added in myself decomposition");
}

return componentsToInstall;
Expand Down Expand Up @@ -190,6 +213,31 @@ ScAddr ScComponentManagerCommandInstall::CreateSetToInstallStructure(
return mainParameter;
}

ScAddr ScComponentManagerCommandInstall::CheckDependencyDuplication(
ScMemoryContext * context,
ScAddr const & currentInstallationComponentsAddr,
ScAddr const & dependenciesSet)
{
ScAddr recursiveDependency;
if (!context->IsElement(currentInstallationComponentsAddr) && !context->IsElement(dependenciesSet))
{
return recursiveDependency;
}

ScIterator3Ptr const & componentsIterator =
context->Iterator3(dependenciesSet, ScType::EdgeAccessConstPosPerm, ScType::NodeConst);

while (componentsIterator->Next())
{
if (context->HelperCheckEdge(
currentInstallationComponentsAddr, componentsIterator->Get(2), ScType::EdgeAccessConstPosTemp))
{
return componentsIterator->Get(2);
}
}
return recursiveDependency;
}

/**
* Tries to install component dependencies.
* @return Returns {DependencyIdtf1, DependencyIdtf2, ...}
Expand All @@ -209,6 +257,24 @@ bool ScComponentManagerCommandInstall::InstallDependencies(ScMemoryContext * con
return result;
}

if (componentDependencies != GetAvailableComponents(context, componentDependencies))
{
SC_LOG_ERROR(
"ScComponentManagerCommandInstall: Can't install dependencies of the component \""
<< context->HelperGetSystemIdtf(componentAddr) << "\"");
return false;
}

ScAddr const & recursiveDependency = CheckDependencyDuplication(
context, keynodes::ScComponentManagerKeynodes::current_components_to_install, dependenciesSet);
if (context->IsElement(recursiveDependency))
{
SC_LOG_ERROR(
"ScComponentManagerCommandInstall: Found recursive dependency with component " << context->HelperGetSystemIdtf(
recursiveDependency) << ", can't install component " << context->HelperGetSystemIdtf(componentAddr));
return false;
}

// Get component dependencies and install them recursively
std::string dependencyIdtf;
ScAddr const & mainParameter = CreateSetToInstallStructure(context, dependenciesSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class ScComponentManagerCommandInstall : public ScComponentManagerCommand

static ScAddr CreateSetToInstallStructure(ScMemoryContext * context, ScAddr const & dependenciesSet);

static ScAddr CheckDependencyDuplication(
ScMemoryContext * context,
ScAddr const & currentInstallationComponentsAddr,
ScAddr const & dependenciesSet);

static bool EraseTempOutputEdges(ScMemoryContext * context, ScAddr const & node);

static ScAddrUnorderedSet GetAvailableComponents(
ScMemoryContext * context,
ScAddrUnorderedSet const & componentsToInstallIdentifiers);
Expand Down

0 comments on commit ea670f9

Please sign in to comment.