8#include <boost/uuid/uuid_io.hpp>
10#include <Ice/Exception.h>
11#include <Ice/OutputStream.h>
12#include <IceUtil/Exception.h>
13#include <IceUtil/Optional.h>
18#include <ArmarXCore/interface/core/time.h>
27#include <RobotAPI/interface/aron/Aron.h>
28#include <RobotAPI/interface/skills/SkillManagerInterface.h>
29#include <RobotAPI/libraries/skills/core/aron/FluxioProfile.aron.generated.h>
30#include <RobotAPI/libraries/skills/core/aron/FluxioSkill.aron.generated.h>
44 this->plugin->addProvider(i);
45 std::string providerId = boost::uuids::to_string(
46 armarx::plugins::SkillManagerComponentPlugin::createUuidWithString(
47 info.providerId.providerName));
48 std::optional<std::vector<skills::manager::arondto::FluxioSkill>> opt =
53 ARMARX_ERROR <<
"Failed to load composite skills for provider "
54 << info.providerId.providerName;
58 for (
const auto& skill : opt.value())
66 const skills::manager::dto::ProviderID& provider,
70 this->plugin->removeProvider(i);
73 skills::manager::dto::SkillStatusUpdate
75 const skills::manager::dto::SkillExecutionRequest& info,
79 return this->plugin->executeSkill(e).toManagerIce();
82 skills::manager::dto::SkillExecutionID
84 const skills::manager::dto::SkillExecutionRequest& info,
85 const Ice::Current& current)
88 return this->plugin->executeSkillAsync(e).toManagerIce();
91 skills::provider::dto::ParameterUpdateResult
93 const skills::manager::dto::SkillExecutionID& info,
95 const Ice::Current& current)
97 skills::provider::dto::ParameterUpdateResult ret;
100 ret.success = this->plugin->updateSkillParameters(e, a);
104 skills::provider::dto::AbortSkillResult
106 const Ice::Current& current)
108 skills::provider::dto::AbortSkillResult ret;
110 ret.success = this->plugin->abortSkill(i);
114 skills::provider::dto::AbortSkillResult
116 const skills::manager::dto::SkillExecutionID&
id,
117 const Ice::Current& )
119 skills::provider::dto::AbortSkillResult ret;
121 ret.success = this->plugin->abortSkillAsync(i);
125 std::vector<skills::provider::dto::AbortSkillResult>
130 std::vector<skills::provider::dto::AbortSkillResult> results;
132 skills::manager::dto::SkillStatusUpdateMap executions;
147 for (
auto& [executionId,
status] : executions)
150 if (
status.status != armarx::skills::core::dto::Execution::Aborted and
151 status.status != armarx::skills::core::dto::Execution::Failed)
154 results.push_back(this->
abortSkill(executionId, current));
160 std::vector<skills::provider::dto::AbortSkillResult>
164 std::vector<skills::provider::dto::AbortSkillResult> results;
166 skills::manager::dto::SkillStatusUpdateMap executions;
181 for (
auto& [executionId,
status] : executions)
184 if (
status.status != armarx::skills::core::dto::Execution::Aborted and
185 status.status != armarx::skills::core::dto::Execution::Failed)
196 const skills::provider::dto::SkillStatusUpdate& statusUpdate,
197 const skills::callback::dto::ProviderID& pid,
205 skills::manager::dto::SkillDescriptionMap
208 skills::manager::dto::SkillDescriptionMap ret;
210 auto m = this->plugin->getSkillDescriptions();
212 for (
const auto& [k, v] : m)
214 ret.insert({k.toManagerIce(), v.toManagerIce()});
220 IceUtil::Optional<skills::manager::dto::SkillDescription>
222 const Ice::Current& current)
225 auto o = this->plugin->getSkillDescription(e);
228 return o->toManagerIce();
233 IceUtil::Optional<skills::manager::dto::SkillStatusUpdate>
235 const skills::manager::dto::SkillExecutionID& executionId,
236 const Ice::Current& current)
239 auto o = this->plugin->getSkillExecutionStatus(e);
242 return o->toManagerIce();
247 skills::manager::dto::SkillStatusUpdateMap
250 skills::manager::dto::SkillStatusUpdateMap ret;
252 auto m = this->plugin->getSkillExecutionStatuses();
254 for (
const auto& [k, v] : m)
256 ret.insert({k.toManagerIce(), v.toManagerIce()});
266 aron::type::dto::AronObjectPtr
269 const auto& res = this->plugin->getTypes();
270 return res->toAronObjectDTO();
273 IceUtil::Optional<std::string>
275 const std::string& profileId,
276 const Ice::Current& current)
278 const auto& res = this->plugin->executeFluxioSkill(skillId, profileId,
"Fluxio");
279 if (!res.isSuccess())
281 auto e = res.getError();
282 e.addToContext(std::nullopt,
"SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
283 throw e.toManagerIce();
285 if (res.getResult() ==
nullptr)
287 auto e = res.getError();
288 e.addToContext(std::nullopt,
"SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
289 throw e.toManagerIce();
292 return res.getResult()->id;
297 const Ice::Current& current)
299 this->plugin->abortFluxioSkill(executionId);
302 IceUtil::Optional<skills::manager::dto::FluxioSkillStatusUpdateList>
304 const Ice::Current& current)
306 auto l = this->plugin->getFluxioSkillExecutionStatus(executionId);
311 auto e = l.getError();
312 e.addToContext(std::nullopt,
"SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
313 throw e.toManagerIce();
316 skills::manager::dto::FluxioSkillStatusUpdateList ret;
318 for (
const auto& s : l.getResult())
320 ret.push_back(s.toManagerIce());
326 skills::manager::dto::FluxioSkillList
329 skills::manager::dto::FluxioSkillList ret;
331 auto l = this->plugin->getSkillList();
335 auto e = l.getError();
336 e.addToContext(std::nullopt,
"SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
337 throw e.toManagerIce();
340 for (
const auto& s : l.getResult())
348 const auto& skill = s->toManagerIce();
350 if (!skill.has_value())
352 ARMARX_WARNING <<
"Skill with id " << s->id <<
" could not be converted";
356 ret.push_back(skill.value());
362 IceUtil::Optional<skills::manager::dto::FluxioSkill>
365 auto result = this->plugin->getSkill(
id);
367 if (!result.isSuccess())
369 auto e = result.getError();
370 e.addToContext(std::nullopt,
"SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
371 throw e.toManagerIce();
373 const auto& skill = result.getResult();
374 if (skill ==
nullptr)
379 const auto& s = skill->toManagerIce();
391 const skills::manager::dto::FluxioSkill& skill,
392 const Ice::Current& current)
394 std::scoped_lock l(this->plugin->fluxioDC.skillsMutex,
395 this->plugin->fluxioDC.profilesMutex,
396 this->plugin->fluxioDC.providersMutex,
397 this->plugin->fluxioDC.typesMutex);
398 auto& skillsMap = this->plugin->fluxioDC.skills;
399 auto& providersMap = this->plugin->fluxioDC.providers;
400 auto& profilesMap = this->plugin->fluxioDC.profiles;
401 auto& typesMap = this->plugin->fluxioDC.types;
402 const auto& s = skillsMap.find(skill.id);
405 if (s == skillsMap.end())
412 auto res = this->plugin->getSkillMutex(skill.id, userId);
413 if (!res.isSuccess())
415 ARMARX_WARNING <<
"User " << userId <<
"User does not have Mutex for this Skill"
418 auto error = res.getError();
421 "SkillManagerComponentPluginUser",
424 throw error.toManagerIce();
428 s->second.updateFromIce(skill, providersMap, profilesMap, skillsMap, typesMap);
430 std::optional<skills::manager::arondto::FluxioSkill> opt = s->second.toAronXml();
432 if (!opt.has_value())
434 ARMARX_WARNING <<
"Skill with id " << skill.id <<
" could not be converted";
445 const std::string& userId,
446 const std::string& skillId,
447 const skills::manager::dto::FluxioParameterList& parameters,
448 const Ice::Current& current)
451 for (
const auto& param : parameters)
457 ARMARX_WARNING <<
"Parameter value of param " << param.id <<
" and skill "
458 << skillId <<
" could not be converted";
469 const std::string& userId,
470 const std::string& skillId,
471 const std::string& parameterId,
472 const skills::manager::dto::FluxioValueList& values,
473 const Ice::Current& current)
475 std::scoped_lock l(this->plugin->fluxioDC.skillsMutex,
476 this->plugin->fluxioDC.profilesMutex);
477 auto& skillsMap = this->plugin->fluxioDC.skills;
478 auto& profilesMap = this->plugin->fluxioDC.profiles;
481 const auto& skill = skillsMap.find(skillId);
483 if (skill == skillsMap.end())
490 auto res = this->plugin->getSkillMutex(skillId, userId);
491 if (!res.isSuccess())
493 ARMARX_WARNING <<
"User " << userId <<
"User does not have Mutex for this Skill"
496 auto error = res.getError();
499 "SkillManagerComponentPluginUser",
502 throw error.toManagerIce();
506 const auto& p = skill->second.parameters.find(parameterId);
507 if (p == skill->second.parameters.end())
509 ARMARX_WARNING <<
"Parameter with id " << parameterId <<
" not found in skill with id "
515 p->second.updateValuesFromIce(values, profilesMap);
519 IceUtil::Optional<skills::manager::dto::FluxioIdentificatorList>
521 const std::string& userId,
523 const Ice::Current& current)
525 skills::manager::dto::FluxioIdentificatorList ret;
528 res = this->plugin->getSkill(skillId);
536 std::optional<skills::manager::arondto::FluxioSkill> opt = skillptr->toAronXml();
537 if (!opt.has_value())
539 ARMARX_WARNING <<
"Skill with id " << skillId <<
" could not be converted";
542 skills::manager::arondto::FluxioSkill skill = opt.value();
544 auto l = this->plugin->deleteSkill(skillId, userId, dryRun);
551 for (
const auto& s : l.value())
558 ret.push_back(s->toFluxioIdentificatorIce());
563 skill.deleted =
true;
572 const std::string& userId,
573 const Ice::Current& current)
575 return this->plugin->getSkillMutex(skillId, userId).getResult();
580 const std::string& userId,
581 const Ice::Current& current)
583 this->plugin->deleteSkillMutex(skillId, userId);
586 IceUtil::Optional<skills::manager::dto::FluxioIdentificatorList>
588 const std::string& parameterId,
589 const std::string& userId,
591 const Ice::Current& current)
593 skills::manager::dto::FluxioIdentificatorList ret;
594 auto res = this->plugin->deleteSkillParameter(skillId, parameterId, userId, dryRun);
596 if (!res.isSuccess())
598 throw res.getError().toManagerIce();
601 for (
const auto& s : res.getResult())
608 ret.push_back(s->toFluxioIdentificatorIce());
614 IceUtil::Optional<skills::manager::dto::FluxioIdentificatorList>
616 const std::string& skillId,
617 const skills::manager::dto::FluxioParameter& parameter,
618 const std::string& userId,
620 const Ice::Current& current)
622 skills::manager::dto::FluxioIdentificatorList ret;
623 auto res = this->plugin->updateSkillParameter(skillId, parameter, userId, dryRun);
625 if (!res.isSuccess())
627 throw res.getError().toManagerIce();
630 for (
const auto& s : res.getResult())
637 ret.push_back(s->toFluxioIdentificatorIce());
643 skills::manager::dto::FluxioProfileList
646 skills::manager::dto::FluxioProfileList ret;
648 auto l = this->plugin->getProfileList();
650 for (
const auto& p : l.getResult())
657 ret.push_back(p->toManagerIce());
663 IceUtil::Optional<skills::manager::dto::FluxioProfile>
666 auto profile = this->plugin->getProfile(
id);
668 if (!profile.isSuccess())
670 auto e = profile.getError();
671 e.addToContext(std::nullopt,
"SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
672 throw e.toManagerIce();
674 return profile.getResult().toManagerIce();
677 skills::manager::dto::FluxioProfile
679 const skills::manager::dto::FluxioProfile& profile,
680 const Ice::Current& current)
682 std::unique_lock l(this->plugin->fluxioDC.profilesMutex);
683 auto& profilesMap = this->plugin->fluxioDC.profiles;
697 const skills::manager::dto::FluxioProfile& profile,
698 const Ice::Current& current)
700 std::unique_lock l(this->plugin->fluxioDC.profilesMutex);
701 auto& profilesMap = this->plugin->fluxioDC.profiles;
707 skills::manager::dto::FluxioProviderList
710 skills::manager::dto::FluxioProviderList ret;
712 auto l = this->plugin->getProviderList();
715 auto e = l.getError();
716 e.addToContext(std::nullopt,
"SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
717 throw e.toManagerIce();
720 for (
const auto& p : l.getResult())
727 ret.push_back(p->toManagerIce());
733 IceUtil::Optional<skills::manager::dto::FluxioProvider>
736 auto provider = this->plugin->getProvider(
id);
738 if (provider.isSuccess())
740 auto e = provider.getError();
741 e.addToContext(std::nullopt,
"SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
742 throw e.toManagerIce();
744 return provider.getResult().toManagerIce();
747 IceUtil::Optional<skills::manager::dto::FluxioSkillList>
749 const Ice::Current& current)
751 skills::manager::dto::FluxioSkillList ret;
753 auto l = this->plugin->getSkillsOfProvider(
id);
757 auto error = l.getError();
759 std::nullopt,
"SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
760 throw error.toManagerIce();
763 for (
const auto& s : l.getResult())
771 const auto& skill = s->toManagerIce();
773 if (!skill.has_value())
776 <<
"SkillManagerComponentPluginUser::getSkillsOfProvider: Skill with id "
777 << s->id <<
" could not be converted";
781 ret.push_back(skill.value());
787 IceUtil::Optional<skills::manager::dto::FluxioSkill>
789 const std::string& userId,
790 const std::string& providerId,
791 const skills::manager::dto::FluxioSkill& skill,
792 const Ice::Current& current)
794 std::unique_lock skillsLock(this->plugin->fluxioDC.skillsMutex, std::defer_lock);
795 std::unique_lock profilesLock(this->plugin->fluxioDC.profilesMutex, std::defer_lock);
796 std::unique_lock providersLock(this->plugin->fluxioDC.providersMutex, std::defer_lock);
797 std::unique_lock typesLock(this->plugin->fluxioDC.typesMutex, std::defer_lock);
798 std::lock(skillsLock, profilesLock, providersLock, typesLock);
800 auto& skillsMap = this->plugin->fluxioDC.skills;
801 auto& providersMap = this->plugin->fluxioDC.providers;
802 auto& profilesMap = this->plugin->fluxioDC.profiles;
803 auto& typesMap = this->plugin->fluxioDC.types;
807 if (skillBO ==
nullptr)
809 ARMARX_WARNING <<
"Skill with id " << skill.id <<
" could not be converted";
815 "SkillManagerComponentPluginUser",
822 profilesLock.unlock();
823 providersLock.unlock();
826 auto& skillReleased = *skillBO.release();
828 this->plugin->addSkillToProvider(userId, providerId, std::move(skillReleased));
829 if (!res.isSuccess())
832 <<
" could not be added to provider with id " << providerId;
834 auto error = res.getError();
837 {skill.id, providerId})),
838 "SkillManagerComponentPluginUser",
841 throw error.toManagerIce();
844 const auto& s = res.getResult();
849 <<
" could not be added to provider with id " << providerId;
853 const auto& ret = s->toManagerIce();
854 if (!ret.has_value())
856 ARMARX_WARNING <<
"Skill with id " << skill.id <<
" could not be converted";
860 const std::optional<skills::manager::arondto::FluxioSkill> aronSkill = s->toAronXml();
862 if (!aronSkill.has_value())
864 ARMARX_WARNING <<
"Skill with id " << skill.id <<
" could not be converted to Aron";
879 std::optional<std::vector<skills::manager::arondto::FluxioSkill>>
886 std::optional<std::vector<skills::manager::arondto::FluxioSkill>>
895 const skills::manager::arondto::FluxioProfile& profile)
900 std::optional<std::vector<skills::manager::arondto::FluxioProfile>>
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
bool getSkillMutex(const std::string &skillId, const std::string &userId, const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::FluxioProvider > getProvider(const std::string &id, const Ice::Current ¤t) override
virtual std::optional< std::vector< skills::manager::arondto::FluxioSkill > > loadCompositeSkillsOfProvider(const std::string &providerId)
void removeProvider(const skills::manager::dto::ProviderID &provider, const Ice::Current ¤t) override
void updateProfile(const skills::manager::dto::FluxioProfile &profile, const Ice::Current ¤t) override
void addProvider(const skills::manager::dto::ProviderInfo &providerInfo, const Ice::Current ¤t) override
virtual void addProfile(const skills::manager::arondto::FluxioProfile &profile)
aron::type::dto::AronObjectPtr getTypes(const Ice::Current ¤t) override
skills::manager::dto::SkillStatusUpdateMap getSkillExecutionStatuses(const Ice::Current ¤t) override
skills::manager::dto::SkillExecutionID executeSkillAsync(const skills::manager::dto::SkillExecutionRequest &skillExecutionRequest, const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::SkillDescription > getSkillDescription(const skills::manager::dto::SkillID &id, const Ice::Current ¤t) override
virtual void saveSkill(const skills::manager::arondto::FluxioSkill &skill)
virtual std::optional< std::vector< skills::manager::arondto::FluxioSkill > > loadCompositeSkills()
bool updateSkillParameterValues(const std::string &userId, const std::string &skillId, const std::string ¶meterId, const skills::manager::dto::FluxioValueList &values, const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::FluxioSkill > getSkill(const std::string &id, const Ice::Current ¤t) override
skills::manager::dto::FluxioProfileList getProfileList(const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::FluxioIdentificatorList > updateSkillParameter(const std::string &skillId, const skills::manager::dto::FluxioParameter ¶meter, const std::string &userId, bool dryRun, const Ice::Current ¤t) override
bool updateSkillValues(const std::string &userId, const std::string &skillId, const skills::manager::dto::FluxioParameterList ¶meters, const Ice::Current ¤t) override
SkillManagerComponentPluginUser()
IceUtil::Optional< std::string > executeFluxioSkill(const std::string &skillId, const std::string &profileId, const Ice::Current ¤t) override
void updateStatusForSkill(const skills::provider::dto::SkillStatusUpdate &update, const skills::callback::dto::ProviderID &id, const Ice::Current ¤t) override
skills::manager::dto::SkillDescriptionMap getSkillDescriptions(const Ice::Current ¤t) override
void deleteSkillMutex(const std::string &skillId, const std::string &userId, const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::FluxioIdentificatorList > deleteSkillParameter(const std::string &skillId, const std::string ¶meterId, const std::string &userId, bool dryRun, const Ice::Current ¤t) override
skills::manager::dto::SkillStatusUpdate executeSkill(const skills::manager::dto::SkillExecutionRequest &info, const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::FluxioProfile > getProfile(const std::string &id, const Ice::Current ¤t) override
void abortFluxioSkill(const std::string &executionId, const Ice::Current ¤t) override
bool updateSkill(const std::string &userId, const skills::manager::dto::FluxioSkill &skill, const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::SkillStatusUpdate > getSkillExecutionStatus(const skills::manager::dto::SkillExecutionID &executionId, const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::FluxioSkillStatusUpdateList > getFluxioSkillExecutionStatus(const std::string &executionId, const Ice::Current ¤t) override
skills::provider::dto::AbortSkillResult abortSkill(const skills::manager::dto::SkillExecutionID &id, const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::FluxioIdentificatorList > deleteSkill(const std::string &skillId, const std::string &userId, bool dryRun, const Ice::Current ¤t) override
skills::manager::dto::FluxioProfile createProfile(const skills::manager::dto::FluxioProfile &profile, const Ice::Current ¤t) override
skills::manager::dto::FluxioProviderList getProviderList(const Ice::Current ¤t) override
skills::provider::dto::AbortSkillResult abortSkillAsync(const skills::manager::dto::SkillExecutionID &id, const Ice::Current ¤t) override
std::vector< skills::provider::dto::AbortSkillResult > abortAllSkills(const Ice::Current ¤t) override
skills::provider::dto::ParameterUpdateResult updateSkillParameters(const skills::manager::dto::SkillExecutionID &executionId, const aron::data::dto::DictPtr ¶ms, const Ice::Current ¤t) override
std::vector< skills::provider::dto::AbortSkillResult > abortAllSkillsAsync(const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::FluxioSkillList > getSkillsOfProvider(const std::string &id, const Ice::Current ¤t) override
virtual std::optional< std::vector< skills::manager::arondto::FluxioProfile > > loadProfiles()
skills::manager::dto::FluxioSkillList getSkillList(const Ice::Current ¤t) override
IceUtil::Optional< skills::manager::dto::FluxioSkill > addSkillToProvider(const std::string &userId, const std::string &providerId, const skills::manager::dto::FluxioSkill &skill, const Ice::Current ¤t) override
static PointerType FromAronDictDTO(const data::dto::DictPtr &aron)
static ProviderID FromIce(const manager::dto::ProviderID &)
static ProviderInfo FromIce(const manager::dto::ProviderInfo &)
static SkillExecutionRequest FromIce(const manager::dto::SkillExecutionRequest &)
static SkillID FromIce(const manager::dto::SkillID &)
A base class for skill exceptions.
static FluxioException create(const std::string &message, const FluxioExceptionType &type, const std::string &className, const char *function, int line)
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
::IceInternal::Handle< Dict > DictPtr
std::string createErrorMessage(ErrorCode code, const std::vector< std::string > &args)
This file offers overloads of toIce() and fromIce() functions for STL container types.
manager::dto::FluxioProfile toManagerIce() const
manager::arondto::FluxioProfile toManagerAron() const
static FluxioProfile FromIce(const manager::dto::FluxioProfile &i, std::map< std::string, FluxioProfile > &profilesMap)
static std::unique_ptr< FluxioSkill > FromIce(const manager::dto::FluxioSkill &i, std::map< std::string, FluxioProvider > &providersMap, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, FluxioSkill > &skillsMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
static SkillExecutionID FromIce(const skills::manager::dto::SkillExecutionID &)