SkillManagerComponentPluginUser.cpp
Go to the documentation of this file.
2
3#include <mutex>
4#include <optional>
5#include <string>
6#include <vector>
7
8#include <boost/uuid/uuid_io.hpp>
9
10#include <Ice/Exception.h>
11#include <Ice/OutputStream.h>
12#include <IceUtil/Exception.h>
13#include <IceUtil/Optional.h>
14
15#include <nlohmann/json.hpp>
16
20#include <ArmarXCore/interface/core/time.h>
21
29#include <RobotAPI/interface/aron/Aron.h>
30#include <RobotAPI/interface/skills/SkillManagerInterface.h>
32#include <RobotAPI/libraries/skills/core/aron/FluxioProfile.aron.generated.h>
33#include <RobotAPI/libraries/skills/core/aron/FluxioSkill.aron.generated.h>
34
35namespace armarx
36{
41
42 void
43 SkillManagerComponentPluginUser::addProvider(const skills::manager::dto::ProviderInfo& info,
44 const Ice::Current&)
45 {
46 auto i = skills::ProviderInfo::FromIce(info);
47 this->plugin->addProvider(i);
48 std::string providerId = boost::uuids::to_string(
49 armarx::plugins::SkillManagerComponentPlugin::createUuidWithString(
50 info.providerId.providerName));
51 std::optional<std::vector<skills::manager::arondto::FluxioSkill>> opt =
53
54 if (!opt.has_value())
55 {
56 ARMARX_ERROR << "Failed to load composite skills for provider "
57 << info.providerId.providerName;
58 return;
59 }
60
61 for (const auto& skill : opt.value())
62 {
63 // TODO: Implement a proper way to load all skills from memory without breaking dependencies etc.
64 }
65 }
66
67 void
69 const skills::manager::dto::ProviderID& provider,
70 const Ice::Current&)
71 {
72 auto i = skills::ProviderID::FromIce(provider);
73 this->plugin->removeProvider(i);
74 }
75
76 skills::manager::dto::SkillStatusUpdate
78 const skills::manager::dto::SkillExecutionRequest& info,
79 const Ice::Current&)
80 {
82 return this->plugin->executeSkill(e).toManagerIce();
83 }
84
85 skills::manager::dto::SkillExecutionID
87 const skills::manager::dto::SkillExecutionRequest& info,
88 const Ice::Current& current)
89 {
91 return this->plugin->executeSkillAsync(e).toManagerIce();
92 }
93
94 skills::provider::dto::ParameterUpdateResult
96 const skills::manager::dto::SkillExecutionID& info,
97 const aron::data::dto::DictPtr& params,
98 const Ice::Current& current)
99 {
100 skills::provider::dto::ParameterUpdateResult ret;
103 ret.success = this->plugin->updateSkillParameters(e, a);
104 return ret;
105 }
106
107 skills::provider::dto::AbortSkillResult
108 SkillManagerComponentPluginUser::abortSkill(const skills::manager::dto::SkillExecutionID& id,
109 const Ice::Current& current)
110 {
111 skills::provider::dto::AbortSkillResult ret;
113 ret.success = this->plugin->abortSkill(i);
114 return ret;
115 }
116
117 skills::provider::dto::AbortSkillResult
119 const skills::manager::dto::SkillExecutionID& id,
120 const Ice::Current& /*unused*/)
121 {
122 skills::provider::dto::AbortSkillResult ret;
124 ret.success = this->plugin->abortSkillAsync(i);
125 return ret;
126 }
127
128 std::vector<skills::provider::dto::AbortSkillResult>
130 {
131 ARMARX_IMPORTANT << "Stopping all running executions.";
132
133 std::vector<skills::provider::dto::AbortSkillResult> results;
134
135 skills::manager::dto::SkillStatusUpdateMap executions;
136
137 // we ALWAYS want the newest information when stopping all!
138 // e.g. there is some new skill not known to the GUI which we explicitely want to stop too.
139 // the stop-all function is often used in an emergency, so we'll live with the extra call...
140 try
141 {
142 executions = this->getSkillExecutionStatuses(current);
143 }
144 catch (...) // if any error occurs, we use the snapshot as backup. better to miss a skill
145 // than to not do anything.
146 {
147 executions = this->getSkillExecutionStatuses(current);
148 }
149
150 for (auto& [executionId, status] : executions)
151 {
152 // select all running executions...
153 if (status.status != armarx::skills::core::dto::Execution::Aborted and
154 status.status != armarx::skills::core::dto::Execution::Failed)
155 {
156 // ... and kill them.
157 results.push_back(this->abortSkill(executionId, current));
158 }
159 }
160 return results;
161 }
162
163 std::vector<skills::provider::dto::AbortSkillResult>
165 {
166 ARMARX_IMPORTANT << "Stopping all running executions.";
167 std::vector<skills::provider::dto::AbortSkillResult> results;
168
169 skills::manager::dto::SkillStatusUpdateMap executions;
170
171 // we ALWAYS want the newest information when stopping all!
172 // e.g. there is some new skill not known to the GUI which we explicitely want to stop too.
173 // the stop-all function is often used in an emergency, so we'll live with the extra call...
174 try
175 {
176 executions = this->getSkillExecutionStatuses(current);
177 }
178 catch (...) // if any error occurs, we use the snapshot as backup. better to miss a skill
179 // than to not do anything.
180 {
181 executions = this->getSkillExecutionStatuses(current);
182 }
183
184 for (auto& [executionId, status] : executions)
185 {
186 // select all running executions...
187 if (status.status != armarx::skills::core::dto::Execution::Aborted and
188 status.status != armarx::skills::core::dto::Execution::Failed)
189 {
190 // ... and kill them.
191 results.push_back(this->abortSkillAsync(executionId, current));
192 }
193 }
194 return results;
195 }
196
197 void
199 const skills::provider::dto::SkillStatusUpdate& statusUpdate,
200 const skills::callback::dto::ProviderID& pid,
201 const Ice::Current&)
202 {
203 (void)statusUpdate;
204 (void)pid;
205 // If you want to use the status, implement this method!
206 }
207
208 skills::manager::dto::SkillDescriptionMap
210 {
211 skills::manager::dto::SkillDescriptionMap ret;
212
213 auto m = this->plugin->getSkillDescriptions();
214
215 for (const auto& [k, v] : m)
216 {
217 ret.insert({k.toManagerIce(), v.toManagerIce()});
218 }
219
220 return ret;
221 }
222
223 IceUtil::Optional<skills::manager::dto::SkillDescription>
224 SkillManagerComponentPluginUser::getSkillDescription(const skills::manager::dto::SkillID& id,
225 const Ice::Current& current)
226 {
227 auto e = skills::SkillID::FromIce(id);
228 auto o = this->plugin->getSkillDescription(e);
229 if (o.has_value())
230 {
231 return o->toManagerIce();
232 }
233 return {};
234 }
235
236 IceUtil::Optional<skills::manager::dto::SkillStatusUpdate>
238 const skills::manager::dto::SkillExecutionID& executionId,
239 const Ice::Current& current)
240 {
241 auto e = skills::SkillExecutionID::FromIce(executionId);
242 auto o = this->plugin->getSkillExecutionStatus(e);
243 if (o.has_value())
244 {
245 return o->toManagerIce();
246 }
247 return {};
248 }
249
250 skills::manager::dto::SkillStatusUpdateMap
252 {
253 skills::manager::dto::SkillStatusUpdateMap ret;
254
255 auto m = this->plugin->getSkillExecutionStatuses();
256
257 for (const auto& [k, v] : m)
258 {
259 ret.insert({k.toManagerIce(), v.toManagerIce()});
260 }
261
262 return ret;
263 }
264
265 //****************************//
266 //** Fluxio related methods **//
267 //****************************//
268
269 aron::type::dto::AronObjectPtr
270 SkillManagerComponentPluginUser::getTypes(const Ice::Current& current)
271 {
272 const auto& res = this->plugin->getTypes();
273 return res->toAronObjectDTO();
274 }
275
276 IceUtil::Optional<std::string>
278 const std::string& profileId,
279 const Ice::Current& current)
280 {
281 const auto& res = this->plugin->executeFluxioSkill(skillId, profileId, "Fluxio");
282 if (!res.isSuccess())
283 {
284 auto e = res.getError();
285 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
286 throw e.toManagerIce();
287 }
288 if (res.getResult() == nullptr)
289 {
290 auto e = res.getError();
291 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
292 throw e.toManagerIce();
293 }
294
295 return res.getResult()->id;
296 }
297
298 IceUtil::Optional<std::string>
300 const std::string& executionArgs,
301 const Ice::Current&)
302 {
303 const auto delimiterPos = skillId.find('/');
304 const auto providerName = skillId.substr(0, delimiterPos);
305 const auto skillName = skillId.substr(delimiterPos + 1);
306
307 // generate skill id (idempotent)
308 const auto& providerId =
309 armarx::plugins::SkillManagerComponentPlugin::createUuidWithString(providerName);
310
311 const auto& id = armarx::plugins::SkillManagerComponentPlugin::createUuidWithString(
312 skillName, providerId);
313
314 const auto& idStr = boost::uuids::to_string(id);
315
316 nlohmann::json json = nlohmann::json::parse(executionArgs);
317
318 aron::data::DictPtr aronData =
320
321 // change aron data keys from name string to uuid string
322 aron::data::DictPtr updatedAronData = std::make_shared<aron::data::Dict>();
323 for (const auto& key : aronData->getAllKeys())
324 {
325 const auto& seed = key + "isInput";
326 const auto& keyUuid = boost::uuids::to_string(
327 armarx::plugins::SkillManagerComponentPlugin::createUuidWithString(seed, id));
328 const auto& value = aronData->getElement(key);
329 if (value == nullptr)
330 {
331 continue;
332 }
333 updatedAronData->addElement(keyUuid, value->cloneAsVariant());
334 }
335
336 const auto& res =
337 this->plugin->executeFluxioSkill(idStr, "root", "Fluxio", updatedAronData);
338
339 if (!res.isSuccess())
340 {
341 auto e = res.getError();
342 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
343 throw e.toManagerIce();
344 }
345 if (res.getResult() == nullptr)
346 {
347 auto e = res.getError();
348 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
349 throw e.toManagerIce();
350 }
351
352 return res.getResult()->id;
353 }
354
355 void
357 const Ice::Current& current)
358 {
359 this->plugin->abortFluxioSkill(executionId);
360 }
361
362 IceUtil::Optional<skills::manager::dto::FluxioSkillStatusUpdateList>
364 const Ice::Current& current)
365 {
366 auto l = this->plugin->getFluxioSkillExecutionStatus(executionId);
367 if (!l.isSuccess())
368 {
369 ARMARX_WARNING << "Error getting FluxioSkillExecutionStatus";
370
371 auto e = l.getError();
372 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
373 throw e.toManagerIce();
374 }
375
376 skills::manager::dto::FluxioSkillStatusUpdateList ret;
377
378 for (const auto& s : l.getResult())
379 {
380 ret.push_back(s.toManagerIce());
381 }
382
383 return ret;
384 }
385
386 skills::manager::dto::FluxioSkillList
388 {
389 skills::manager::dto::FluxioSkillList ret;
390
391 auto l = this->plugin->getSkillList();
392
393 if (!l.isSuccess())
394 {
395 auto e = l.getError();
396 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
397 throw e.toManagerIce();
398 }
399
400 for (const auto& s : l.getResult())
401 {
402 if (s == nullptr)
403 {
404 ARMARX_WARNING << "Unexpected nullptr!";
405 continue;
406 }
407
408 const auto& skill = s->toManagerIce();
409
410 if (!skill.has_value())
411 {
412 ARMARX_WARNING << "Skill with id " << s->id << " could not be converted";
413 continue;
414 }
415
416 ret.push_back(skill.value());
417 }
418
419 return ret;
420 }
421
422 IceUtil::Optional<skills::manager::dto::FluxioSkill>
423 SkillManagerComponentPluginUser::getSkill(const std::string& id, const Ice::Current& current)
424 {
425 auto result = this->plugin->getSkill(id);
426
427 if (!result.isSuccess())
428 {
429 auto e = result.getError();
430 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
431 throw e.toManagerIce();
432 }
433 const auto& skill = result.getResult();
434 if (skill == nullptr)
435 {
436 return {};
437 }
438
439 const auto& s = skill->toManagerIce();
440
441 if (!s.has_value())
442 {
443 return {};
444 }
445
446 return s.value();
447 }
448
449 bool
451 const skills::manager::dto::FluxioSkill& skill,
452 const Ice::Current& current)
453 {
454 std::scoped_lock l(this->plugin->fluxioDC.skillsMutex,
455 this->plugin->fluxioDC.profilesMutex,
456 this->plugin->fluxioDC.providersMutex,
457 this->plugin->fluxioDC.typesMutex);
458 auto& skillsMap = this->plugin->fluxioDC.skills;
459 auto& providersMap = this->plugin->fluxioDC.providers;
460 auto& profilesMap = this->plugin->fluxioDC.profiles;
461 auto& typesMap = this->plugin->fluxioDC.types;
462 const auto& s = skillsMap.find(skill.id);
463
464 // Check if the skill exists
465 if (s == skillsMap.end())
466 {
467 ARMARX_WARNING << "Skill with id " << skill.id << " not found";
468 return false;
469 }
470
471 // Check if the user has the mutex for the skill
472 auto res = this->plugin->getSkillMutex(skill.id, userId);
473 if (!res.isSuccess())
474 {
475 ARMARX_WARNING << "User " << userId << "User does not have Mutex for this Skill"
476 << skill.id;
477
478 auto error = res.getError();
479 error.addToContext(skills::error::createErrorMessage(
481 "SkillManagerComponentPluginUser",
482 __FUNCTION__,
483 __LINE__);
484 throw error.toManagerIce();
485 }
486
487 const bool ret =
488 s->second.updateFromIce(skill, providersMap, profilesMap, skillsMap, typesMap);
489
490 std::optional<skills::manager::arondto::FluxioSkill> opt = s->second.toAronXml();
491
492 if (!opt.has_value())
493 {
494 ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted";
495 return false;
496 }
497
498 saveSkill(opt.value());
499
500 return ret;
501 }
502
503 bool
505 const std::string& userId,
506 const std::string& skillId,
507 const skills::manager::dto::FluxioParameterList& parameters,
508 const Ice::Current& current)
509 {
510 // updateSkillParameterValues for all params
511 for (const auto& param : parameters)
512 {
513 const auto& res =
514 this->updateSkillParameterValues(userId, skillId, param.id, param.values, current);
515 if (!res)
516 {
517 ARMARX_WARNING << "Parameter value of param " << param.id << " and skill "
518 << skillId << " could not be converted";
519 return false;
520 }
521 }
522
523
524 return true;
525 }
526
527 bool
529 const std::string& userId,
530 const std::string& skillId,
531 const std::string& parameterId,
532 const skills::manager::dto::FluxioValueList& values,
533 const Ice::Current& current)
534 {
535 std::scoped_lock l(this->plugin->fluxioDC.skillsMutex,
536 this->plugin->fluxioDC.profilesMutex);
537 auto& skillsMap = this->plugin->fluxioDC.skills;
538 auto& profilesMap = this->plugin->fluxioDC.profiles;
539
540 // check if skill exists
541 const auto& skill = skillsMap.find(skillId);
542
543 if (skill == skillsMap.end())
544 {
545 ARMARX_WARNING << "Skill with id " << skillId << " not found";
546 return false;
547 }
548
549 // Check if the user has the mutex for the skill
550 auto res = this->plugin->getSkillMutex(skillId, userId);
551 if (!res.isSuccess())
552 {
553 ARMARX_WARNING << "User " << userId << "User does not have Mutex for this Skill"
554 << skillId;
555
556 auto error = res.getError();
557 error.addToContext(skills::error::createErrorMessage(
559 "SkillManagerComponentPluginUser",
560 __FUNCTION__,
561 __LINE__);
562 throw error.toManagerIce();
563 }
564
565 // check if parameter exists in skill
566 const auto& p = skill->second.parameters.find(parameterId);
567 if (p == skill->second.parameters.end())
568 {
569 ARMARX_WARNING << "Parameter with id " << parameterId << " not found in skill with id "
570 << skillId;
571 return false;
572 }
573
574 // update values of parameter
575 p->second.updateValuesFromIce(values, profilesMap);
576 return true;
577 }
578
579 IceUtil::Optional<skills::manager::dto::FluxioIdentificatorList>
581 const std::string& userId,
582 const bool dryRun,
583 const Ice::Current& current)
584 {
585 skills::manager::dto::FluxioIdentificatorList ret;
588 res = this->plugin->getSkill(skillId);
589 if (!res.isSuccess())
590 {
591 ARMARX_WARNING << "Error getting skill with id " << skillId;
592 return {};
593 }
595 res.getResult();
596 std::optional<skills::manager::arondto::FluxioSkill> opt = skillptr->toAronXml();
597 if (!opt.has_value())
598 {
599 ARMARX_WARNING << "Skill with id " << skillId << " could not be converted";
600 return {};
601 }
602 skills::manager::arondto::FluxioSkill skill = opt.value();
603
604 auto l = this->plugin->deleteSkill(skillId, userId, dryRun);
605
606 if (!l.has_value())
607 {
608 return {};
609 }
610
611 for (const auto& s : l.value())
612 {
613 if (s == nullptr)
614 {
615 ARMARX_WARNING << "Unexpected nullptr!";
616 continue;
617 }
618 ret.push_back(s->toFluxioIdentificatorIce());
619 }
620
621 if (!dryRun)
622 {
623 skill.deleted = true;
624 saveSkill(skill);
625 }
626
627 return ret;
628 }
629
630 bool
632 const std::string& userId,
633 const Ice::Current& current)
634 {
635 return this->plugin->getSkillMutex(skillId, userId).getResult();
636 }
637
638 void
640 const std::string& userId,
641 const Ice::Current& current)
642 {
643 this->plugin->deleteSkillMutex(skillId, userId);
644 }
645
646 IceUtil::Optional<skills::manager::dto::FluxioIdentificatorList>
648 const std::string& parameterId,
649 const std::string& userId,
650 bool dryRun,
651 const Ice::Current& current)
652 {
653 skills::manager::dto::FluxioIdentificatorList ret;
654 auto res = this->plugin->deleteSkillParameter(skillId, parameterId, userId, dryRun);
655
656 if (!res.isSuccess())
657 {
658 throw res.getError().toManagerIce();
659 }
660
661 for (const auto& s : res.getResult())
662 {
663 if (s == nullptr)
664 {
665 ARMARX_WARNING << "Unexpected nullptr!";
666 continue;
667 }
668 ret.push_back(s->toFluxioIdentificatorIce());
669 }
670
671 return ret;
672 }
673
674 IceUtil::Optional<skills::manager::dto::FluxioIdentificatorList>
676 const std::string& skillId,
677 const skills::manager::dto::FluxioParameter& parameter,
678 const std::string& userId,
679 bool dryRun,
680 const Ice::Current& current)
681 {
682 skills::manager::dto::FluxioIdentificatorList ret;
683 auto res = this->plugin->updateSkillParameter(skillId, parameter, userId, dryRun);
684
685 if (!res.isSuccess())
686 {
687 throw res.getError().toManagerIce();
688 }
689
690 for (const auto& s : res.getResult())
691 {
692 if (s == nullptr)
693 {
694 ARMARX_WARNING << "Unexpected nullptr!";
695 continue;
696 }
697 ret.push_back(s->toFluxioIdentificatorIce());
698 }
699
700 return ret;
701 }
702
703 skills::manager::dto::FluxioProfileList
705 {
706 skills::manager::dto::FluxioProfileList ret;
707
708 auto l = this->plugin->getProfileList();
709
710 for (const auto& p : l.getResult())
711 {
712 if (p == nullptr)
713 {
714 ARMARX_WARNING << "Unexpected nullptr!";
715 continue;
716 }
717 ret.push_back(p->toManagerIce());
718 }
719
720 return ret;
721 }
722
723 IceUtil::Optional<skills::manager::dto::FluxioProfile>
724 SkillManagerComponentPluginUser::getProfile(const std::string& id, const Ice::Current& current)
725 {
726 auto profile = this->plugin->getProfile(id);
727
728 if (!profile.isSuccess())
729 {
730 auto e = profile.getError();
731 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
732 throw e.toManagerIce();
733 }
734 return profile.getResult().toManagerIce();
735 }
736
737 skills::manager::dto::FluxioProfile
739 const skills::manager::dto::FluxioProfile& profile,
740 const Ice::Current& current)
741 {
742 std::unique_lock l(this->plugin->fluxioDC.profilesMutex);
743 auto& profilesMap = this->plugin->fluxioDC.profiles;
744
745 const auto& converted = skills::FluxioProfile::FromIce(profile, profilesMap);
746 l.unlock();
747
748 armarx::skills::FluxioProfile ret = this->plugin->createProfile(converted).getResult();
749
751
752 return ret.toManagerIce();
753 }
754
755 void
757 const skills::manager::dto::FluxioProfile& profile,
758 const Ice::Current& current)
759 {
760 std::unique_lock l(this->plugin->fluxioDC.profilesMutex);
761 auto& profilesMap = this->plugin->fluxioDC.profiles;
762 l.unlock();
763
764 this->plugin->updateProfile(skills::FluxioProfile::FromIce(profile, profilesMap));
765 }
766
767 skills::manager::dto::FluxioProviderList
769 {
770 skills::manager::dto::FluxioProviderList ret;
771
772 auto l = this->plugin->getProviderList();
773 if (!l.isSuccess())
774 {
775 auto e = l.getError();
776 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
777 throw e.toManagerIce();
778 }
779
780 for (const auto& p : l.getResult())
781 {
782 if (p == nullptr)
783 {
784 ARMARX_WARNING << "Unexpected nullptr!";
785 continue;
786 }
787 ret.push_back(p->toManagerIce());
788 }
789
790 return ret;
791 }
792
793 IceUtil::Optional<skills::manager::dto::FluxioProvider>
794 SkillManagerComponentPluginUser::getProvider(const std::string& id, const Ice::Current& current)
795 {
796 auto provider = this->plugin->getProvider(id);
797
798 if (provider.isSuccess())
799 {
800 auto e = provider.getError();
801 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
802 throw e.toManagerIce();
803 }
804 return provider.getResult().toManagerIce();
805 }
806
807 IceUtil::Optional<skills::manager::dto::FluxioSkillList>
809 const Ice::Current& current)
810 {
811 skills::manager::dto::FluxioSkillList ret;
812
813 auto l = this->plugin->getSkillsOfProvider(id);
814
815 if (!l.isSuccess())
816 {
817 auto error = l.getError();
818 error.addToContext(
819 std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
820 throw error.toManagerIce();
821 }
822
823 for (const auto& s : l.getResult())
824 {
825 if (s == nullptr)
826 {
827 ARMARX_WARNING << "Unexpected nullptr!";
828 continue;
829 }
830
831 const auto& skill = s->toManagerIce();
832
833 if (!skill.has_value())
834 {
836 << "SkillManagerComponentPluginUser::getSkillsOfProvider: Skill with id "
837 << s->id << " could not be converted";
838 continue;
839 }
840
841 ret.push_back(skill.value());
842 }
843
844 return ret;
845 }
846
847 IceUtil::Optional<skills::manager::dto::FluxioSkill>
849 const std::string& userId,
850 const std::string& providerId,
851 const skills::manager::dto::FluxioSkill& skill,
852 const Ice::Current& current)
853 {
854 std::unique_lock skillsLock(this->plugin->fluxioDC.skillsMutex, std::defer_lock);
855 std::unique_lock profilesLock(this->plugin->fluxioDC.profilesMutex, std::defer_lock);
856 std::unique_lock providersLock(this->plugin->fluxioDC.providersMutex, std::defer_lock);
857 std::unique_lock typesLock(this->plugin->fluxioDC.typesMutex, std::defer_lock);
858 std::lock(skillsLock, profilesLock, providersLock, typesLock);
859
860 auto& skillsMap = this->plugin->fluxioDC.skills;
861 auto& providersMap = this->plugin->fluxioDC.providers;
862 auto& profilesMap = this->plugin->fluxioDC.profiles;
863 auto& typesMap = this->plugin->fluxioDC.types;
864 auto skillBO =
865 skills::FluxioSkill::FromIce(skill, providersMap, profilesMap, skillsMap, typesMap);
866
867 if (skillBO == nullptr)
868 {
869 ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted";
870
873 {skill.id}),
875 "SkillManagerComponentPluginUser",
876 __FUNCTION__,
877 __LINE__)
878 .toManagerIce();
879 }
880
881 skillsLock.unlock();
882 profilesLock.unlock();
883 providersLock.unlock();
884 typesLock.unlock();
885
886 auto& skillReleased = *skillBO.release();
887 const auto res =
888 this->plugin->addSkillToProvider(userId, providerId, std::move(skillReleased));
889 if (!res.isSuccess())
890 {
891 ARMARX_WARNING << "Skill with id " << skill.id
892 << " could not be added to provider with id " << providerId;
893
894 auto error = res.getError();
895 error.addToContext(
897 {skill.id, providerId})),
898 "SkillManagerComponentPluginUser",
899 __FUNCTION__,
900 __LINE__);
901 throw error.toManagerIce();
902 }
903
904 const auto& s = res.getResult();
905
906 if (s == nullptr)
907 {
908 ARMARX_WARNING << "Skill with id " << skill.id
909 << " could not be added to provider with id " << providerId;
910 return {};
911 }
912
913 const auto& ret = s->toManagerIce();
914 if (!ret.has_value())
915 {
916 ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted";
917 return {};
918 }
919
920 const std::optional<skills::manager::arondto::FluxioSkill> aronSkill = s->toAronXml();
921
922 if (!aronSkill.has_value())
923 {
924 ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted to Aron";
925 return {};
926 }
927
928 saveSkill(aronSkill.value());
929
930 return ret.value();
931 }
932
933 void
934 SkillManagerComponentPluginUser::saveSkill(const skills::manager::arondto::FluxioSkill& skill)
935 {
936 // Implemented in derived class
937 }
938
939 std::optional<std::vector<skills::manager::arondto::FluxioSkill>>
941 {
942 // Implemented in derived class
943 return {};
944 }
945
946 std::optional<std::vector<skills::manager::arondto::FluxioSkill>>
948 {
949 // Implemented in derived class
950 return {};
951 }
952
953 void
955 const skills::manager::arondto::FluxioProfile& profile)
956 {
957 // Implemented in derived class
958 }
959
960 std::optional<std::vector<skills::manager::arondto::FluxioProfile>>
962 {
963 // Implemented in derived class
964 return {};
965 }
966} // namespace armarx
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
bool getSkillMutex(const std::string &skillId, const std::string &userId, const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::FluxioProvider > getProvider(const std::string &id, const Ice::Current &current) 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 &current) override
void updateProfile(const skills::manager::dto::FluxioProfile &profile, const Ice::Current &current) override
void addProvider(const skills::manager::dto::ProviderInfo &providerInfo, const Ice::Current &current) override
virtual void addProfile(const skills::manager::arondto::FluxioProfile &profile)
aron::type::dto::AronObjectPtr getTypes(const Ice::Current &current) override
skills::manager::dto::SkillStatusUpdateMap getSkillExecutionStatuses(const Ice::Current &current) override
skills::manager::dto::SkillExecutionID executeSkillAsync(const skills::manager::dto::SkillExecutionRequest &skillExecutionRequest, const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::SkillDescription > getSkillDescription(const skills::manager::dto::SkillID &id, const Ice::Current &current) 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 &parameterId, const skills::manager::dto::FluxioValueList &values, const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::FluxioSkill > getSkill(const std::string &id, const Ice::Current &current) override
skills::manager::dto::FluxioProfileList getProfileList(const Ice::Current &current) override
IceUtil::Optional< std::string > executeFluxioSkillLegacy(const std::string &skillId, const std::string &executionArgs, const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::FluxioIdentificatorList > updateSkillParameter(const std::string &skillId, const skills::manager::dto::FluxioParameter &parameter, const std::string &userId, bool dryRun, const Ice::Current &current) override
bool updateSkillValues(const std::string &userId, const std::string &skillId, const skills::manager::dto::FluxioParameterList &parameters, const Ice::Current &current) override
IceUtil::Optional< std::string > executeFluxioSkill(const std::string &skillId, const std::string &profileId, const Ice::Current &current) override
void updateStatusForSkill(const skills::provider::dto::SkillStatusUpdate &update, const skills::callback::dto::ProviderID &id, const Ice::Current &current) override
skills::manager::dto::SkillDescriptionMap getSkillDescriptions(const Ice::Current &current) override
void deleteSkillMutex(const std::string &skillId, const std::string &userId, const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::FluxioIdentificatorList > deleteSkillParameter(const std::string &skillId, const std::string &parameterId, const std::string &userId, bool dryRun, const Ice::Current &current) override
skills::manager::dto::SkillStatusUpdate executeSkill(const skills::manager::dto::SkillExecutionRequest &info, const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::FluxioProfile > getProfile(const std::string &id, const Ice::Current &current) override
void abortFluxioSkill(const std::string &executionId, const Ice::Current &current) override
bool updateSkill(const std::string &userId, const skills::manager::dto::FluxioSkill &skill, const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::SkillStatusUpdate > getSkillExecutionStatus(const skills::manager::dto::SkillExecutionID &executionId, const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::FluxioSkillStatusUpdateList > getFluxioSkillExecutionStatus(const std::string &executionId, const Ice::Current &current) override
skills::provider::dto::AbortSkillResult abortSkill(const skills::manager::dto::SkillExecutionID &id, const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::FluxioIdentificatorList > deleteSkill(const std::string &skillId, const std::string &userId, bool dryRun, const Ice::Current &current) override
skills::manager::dto::FluxioProfile createProfile(const skills::manager::dto::FluxioProfile &profile, const Ice::Current &current) override
skills::manager::dto::FluxioProviderList getProviderList(const Ice::Current &current) override
skills::provider::dto::AbortSkillResult abortSkillAsync(const skills::manager::dto::SkillExecutionID &id, const Ice::Current &current) override
std::vector< skills::provider::dto::AbortSkillResult > abortAllSkills(const Ice::Current &current) override
skills::provider::dto::ParameterUpdateResult updateSkillParameters(const skills::manager::dto::SkillExecutionID &executionId, const aron::data::dto::DictPtr &params, const Ice::Current &current) override
std::vector< skills::provider::dto::AbortSkillResult > abortAllSkillsAsync(const Ice::Current &current) override
IceUtil::Optional< skills::manager::dto::FluxioSkillList > getSkillsOfProvider(const std::string &id, const Ice::Current &current) override
virtual std::optional< std::vector< skills::manager::arondto::FluxioProfile > > loadProfiles()
skills::manager::dto::FluxioSkillList getSkillList(const Ice::Current &current) 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 &current) override
static PointerType FromAronDictDTO(const data::dto::DictPtr &aron)
Definition Dict.cpp:130
static data::DictPtr ConvertFromNlohmannJSONObject(const nlohmann::json &, const armarx::aron::Path &p={})
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 &)
Definition SkillID.cpp:36
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...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
::IceInternal::Handle< Dict > DictPtr
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
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 &)