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 ([[maybe_unused]] 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 // Iterate over each execution and asynchronously trigger abort before
151 // aborting synchronously in the next loop. This way all skills receive
152 // the request and one skill cannot block the notification to all others.
153 for (auto& [executionId, status] : executions)
154 {
155 if (status.status != armarx::skills::core::dto::Execution::Succeeded and
156 status.status != armarx::skills::core::dto::Execution::Aborted and
157 status.status != armarx::skills::core::dto::Execution::Failed)
158 {
159 this->abortSkillAsync(executionId, current);
160 }
161 }
162
163 for (auto& [executionId, status] : executions)
164 {
165 // select all running executions...
166 if (status.status != armarx::skills::core::dto::Execution::Succeeded and
167 status.status != armarx::skills::core::dto::Execution::Aborted and
168 status.status != armarx::skills::core::dto::Execution::Failed)
169 {
170 // ... and kill them.
171 results.push_back(this->abortSkill(executionId, current));
172 }
173 }
174 return results;
175 }
176
177 std::vector<skills::provider::dto::AbortSkillResult>
179 {
180 ARMARX_IMPORTANT << "Stopping all running executions.";
181 std::vector<skills::provider::dto::AbortSkillResult> results;
182
183 skills::manager::dto::SkillStatusUpdateMap executions;
184
185 // we ALWAYS want the newest information when stopping all!
186 // e.g. there is some new skill not known to the GUI which we explicitely want to stop too.
187 // the stop-all function is often used in an emergency, so we'll live with the extra call...
188 try
189 {
190 executions = this->getSkillExecutionStatuses(current);
191 }
192 catch (...) // if any error occurs, we use the snapshot as backup. better to miss a skill
193 // than to not do anything.
194 {
195 executions = this->getSkillExecutionStatuses(current);
196 }
197
198 for (auto& [executionId, status] : executions)
199 {
200 // select all running executions...
201 if (status.status != armarx::skills::core::dto::Execution::Aborted and
202 status.status != armarx::skills::core::dto::Execution::Failed)
203 {
204 // ... and kill them.
205 results.push_back(this->abortSkillAsync(executionId, current));
206 }
207 }
208 return results;
209 }
210
211 void
213 const skills::provider::dto::SkillStatusUpdate& statusUpdate,
214 const skills::callback::dto::ProviderID& pid,
215 const Ice::Current&)
216 {
217 (void)statusUpdate;
218 (void)pid;
219 // If you want to use the status, implement this method!
220 }
221
222 skills::manager::dto::SkillDescriptionMap
224 {
225 skills::manager::dto::SkillDescriptionMap ret;
226
227 auto m = this->plugin->getSkillDescriptions();
228
229 for (const auto& [k, v] : m)
230 {
231 ret.insert({k.toManagerIce(), v.toManagerIce()});
232 }
233
234 return ret;
235 }
236
237 IceUtil::Optional<skills::manager::dto::SkillDescription>
238 SkillManagerComponentPluginUser::getSkillDescription(const skills::manager::dto::SkillID& id,
239 const Ice::Current& current)
240 {
241 auto e = skills::SkillID::FromIce(id);
242 auto o = this->plugin->getSkillDescription(e);
243 if (o.has_value())
244 {
245 return o->toManagerIce();
246 }
247 return {};
248 }
249
250 IceUtil::Optional<skills::manager::dto::SkillStatusUpdate>
252 const skills::manager::dto::SkillExecutionID& executionId,
253 const Ice::Current& current)
254 {
255 auto e = skills::SkillExecutionID::FromIce(executionId);
256 auto o = this->plugin->getSkillExecutionStatus(e);
257 if (o.has_value())
258 {
259 return o->toManagerIce();
260 }
261 return {};
262 }
263
264 skills::manager::dto::SkillStatusUpdateMap
266 {
267 skills::manager::dto::SkillStatusUpdateMap ret;
268
269 auto m = this->plugin->getSkillExecutionStatuses();
270
271 for (const auto& [k, v] : m)
272 {
273 ret.insert({k.toManagerIce(), v.toManagerIce()});
274 }
275
276 return ret;
277 }
278
279 //****************************//
280 //** Fluxio related methods **//
281 //****************************//
282
283 aron::type::dto::AronObjectPtr
284 SkillManagerComponentPluginUser::getTypes(const Ice::Current& current)
285 {
286 const auto& res = this->plugin->getTypes();
287 return res->toAronObjectDTO();
288 }
289
290 IceUtil::Optional<std::string>
292 const std::string& profileId,
293 const Ice::Current& current)
294 {
295 const auto& res = this->plugin->executeFluxioSkill(skillId, profileId, "Fluxio");
296 if (!res.isSuccess())
297 {
298 auto e = res.getError();
299 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
300 throw e.toManagerIce();
301 }
302 if (res.getResult() == nullptr)
303 {
304 auto e = res.getError();
305 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
306 throw e.toManagerIce();
307 }
308
309 return res.getResult()->id;
310 }
311
312 IceUtil::Optional<std::string>
314 const std::string& executionArgs,
315 const Ice::Current&)
316 {
317 const auto delimiterPos = skillId.find('/');
318 const auto providerName = skillId.substr(0, delimiterPos);
319 const auto skillName = skillId.substr(delimiterPos + 1);
320
321 // generate skill id (idempotent)
322 const auto& providerId =
323 armarx::plugins::SkillManagerComponentPlugin::createUuidWithString(providerName);
324
325 const auto& id = armarx::plugins::SkillManagerComponentPlugin::createUuidWithString(
326 skillName, providerId);
327
328 const auto& idStr = boost::uuids::to_string(id);
329
330 nlohmann::json json = nlohmann::json::parse(executionArgs);
331
332 aron::data::DictPtr aronData =
334
335 // change aron data keys from name string to uuid string
336 aron::data::DictPtr updatedAronData = std::make_shared<aron::data::Dict>();
337 for (const auto& key : aronData->getAllKeys())
338 {
339 const auto& seed = key + "isInput";
340 const auto& keyUuid = boost::uuids::to_string(
341 armarx::plugins::SkillManagerComponentPlugin::createUuidWithString(seed, id));
342 const auto& value = aronData->getElement(key);
343 if (value == nullptr)
344 {
345 continue;
346 }
347 updatedAronData->addElement(keyUuid, value->cloneAsVariant());
348 }
349
350 const auto& res =
351 this->plugin->executeFluxioSkill(idStr, "root", "Fluxio", updatedAronData);
352
353 if (!res.isSuccess())
354 {
355 auto e = res.getError();
356 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
357 throw e.toManagerIce();
358 }
359 if (res.getResult() == nullptr)
360 {
361 auto e = res.getError();
362 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
363 throw e.toManagerIce();
364 }
365
366 return res.getResult()->id;
367 }
368
369 void
371 const Ice::Current& current)
372 {
373 this->plugin->abortFluxioSkill(executionId);
374 }
375
376 IceUtil::Optional<skills::manager::dto::FluxioSkillStatusUpdateList>
378 const Ice::Current& current)
379 {
380 auto l = this->plugin->getFluxioSkillExecutionStatus(executionId);
381 if (!l.isSuccess())
382 {
383 ARMARX_WARNING << "Error getting FluxioSkillExecutionStatus";
384
385 auto e = l.getError();
386 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
387 throw e.toManagerIce();
388 }
389
390 skills::manager::dto::FluxioSkillStatusUpdateList ret;
391
392 for (const auto& s : l.getResult())
393 {
394 ret.push_back(s.toManagerIce());
395 }
396
397 return ret;
398 }
399
400 skills::manager::dto::FluxioSkillList
402 {
403 skills::manager::dto::FluxioSkillList ret;
404
405 auto l = this->plugin->getSkillList();
406
407 if (!l.isSuccess())
408 {
409 auto e = l.getError();
410 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
411 throw e.toManagerIce();
412 }
413
414 for (const auto& s : l.getResult())
415 {
416 if (s == nullptr)
417 {
418 ARMARX_WARNING << "Unexpected nullptr!";
419 continue;
420 }
421
422 const auto& skill = s->toManagerIce();
423
424 if (!skill.has_value())
425 {
426 ARMARX_WARNING << "Skill with id " << s->id << " could not be converted";
427 continue;
428 }
429
430 ret.push_back(skill.value());
431 }
432
433 return ret;
434 }
435
436 IceUtil::Optional<skills::manager::dto::FluxioSkill>
437 SkillManagerComponentPluginUser::getSkill(const std::string& id, const Ice::Current& current)
438 {
439 auto result = this->plugin->getSkill(id);
440
441 if (!result.isSuccess())
442 {
443 auto e = result.getError();
444 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
445 throw e.toManagerIce();
446 }
447 const auto& skill = result.getResult();
448 if (skill == nullptr)
449 {
450 return {};
451 }
452
453 const auto& s = skill->toManagerIce();
454
455 if (!s.has_value())
456 {
457 return {};
458 }
459
460 return s.value();
461 }
462
463 bool
465 const skills::manager::dto::FluxioSkill& skill,
466 const Ice::Current& current)
467 {
468 std::scoped_lock l(this->plugin->fluxioDC.skillsMutex,
469 this->plugin->fluxioDC.profilesMutex,
470 this->plugin->fluxioDC.providersMutex,
471 this->plugin->fluxioDC.typesMutex);
472 auto& skillsMap = this->plugin->fluxioDC.skills;
473 auto& providersMap = this->plugin->fluxioDC.providers;
474 auto& profilesMap = this->plugin->fluxioDC.profiles;
475 auto& typesMap = this->plugin->fluxioDC.types;
476 const auto& s = skillsMap.find(skill.id);
477
478 // Check if the skill exists
479 if (s == skillsMap.end())
480 {
481 ARMARX_WARNING << "Skill with id " << skill.id << " not found";
482 return false;
483 }
484
485 // Check if the user has the mutex for the skill
486 auto res = this->plugin->getSkillMutex(skill.id, userId);
487 if (!res.isSuccess())
488 {
489 ARMARX_WARNING << "User " << userId << "User does not have Mutex for this Skill"
490 << skill.id;
491
492 auto error = res.getError();
493 error.addToContext(skills::error::createErrorMessage(
495 "SkillManagerComponentPluginUser",
496 __FUNCTION__,
497 __LINE__);
498 throw error.toManagerIce();
499 }
500
501 const bool ret =
502 s->second.updateFromIce(skill, providersMap, profilesMap, skillsMap, typesMap);
503
504 std::optional<skills::manager::arondto::FluxioSkill> opt = s->second.toAronXml();
505
506 if (!opt.has_value())
507 {
508 ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted";
509 return false;
510 }
511
512 saveSkill(opt.value());
513
514 return ret;
515 }
516
517 bool
519 const std::string& userId,
520 const std::string& skillId,
521 const skills::manager::dto::FluxioParameterList& parameters,
522 const Ice::Current& current)
523 {
524 // updateSkillParameterValues for all params
525 for (const auto& param : parameters)
526 {
527 const auto& res =
528 this->updateSkillParameterValues(userId, skillId, param.id, param.values, current);
529 if (!res)
530 {
531 ARMARX_WARNING << "Parameter value of param " << param.id << " and skill "
532 << skillId << " could not be converted";
533 return false;
534 }
535 }
536
537
538 return true;
539 }
540
541 bool
543 const std::string& userId,
544 const std::string& skillId,
545 const std::string& parameterId,
546 const skills::manager::dto::FluxioValueList& values,
547 const Ice::Current& current)
548 {
549 std::scoped_lock l(this->plugin->fluxioDC.skillsMutex,
550 this->plugin->fluxioDC.profilesMutex);
551 auto& skillsMap = this->plugin->fluxioDC.skills;
552 auto& profilesMap = this->plugin->fluxioDC.profiles;
553
554 // check if skill exists
555 const auto& skill = skillsMap.find(skillId);
556
557 if (skill == skillsMap.end())
558 {
559 ARMARX_WARNING << "Skill with id " << skillId << " not found";
560 return false;
561 }
562
563 // Check if the user has the mutex for the skill
564 auto res = this->plugin->getSkillMutex(skillId, userId);
565 if (!res.isSuccess())
566 {
567 ARMARX_WARNING << "User " << userId << "User does not have Mutex for this Skill"
568 << skillId;
569
570 auto error = res.getError();
571 error.addToContext(skills::error::createErrorMessage(
573 "SkillManagerComponentPluginUser",
574 __FUNCTION__,
575 __LINE__);
576 throw error.toManagerIce();
577 }
578
579 // check if parameter exists in skill
580 const auto& p = skill->second.parameters.find(parameterId);
581 if (p == skill->second.parameters.end())
582 {
583 ARMARX_WARNING << "Parameter with id " << parameterId << " not found in skill with id "
584 << skillId;
585 return false;
586 }
587
588 // update values of parameter
589 p->second.updateValuesFromIce(values, profilesMap);
590 return true;
591 }
592
593 IceUtil::Optional<skills::manager::dto::FluxioIdentificatorList>
595 const std::string& userId,
596 const bool dryRun,
597 const Ice::Current& current)
598 {
599 skills::manager::dto::FluxioIdentificatorList ret;
602 res = this->plugin->getSkill(skillId);
603 if (!res.isSuccess())
604 {
605 ARMARX_WARNING << "Error getting skill with id " << skillId;
606 return {};
607 }
609 res.getResult();
610 std::optional<skills::manager::arondto::FluxioSkill> opt = skillptr->toAronXml();
611 if (!opt.has_value())
612 {
613 ARMARX_WARNING << "Skill with id " << skillId << " could not be converted";
614 return {};
615 }
616 skills::manager::arondto::FluxioSkill skill = opt.value();
617
618 auto l = this->plugin->deleteSkill(skillId, userId, dryRun);
619
620 if (!l.has_value())
621 {
622 return {};
623 }
624
625 for (const auto& s : l.value())
626 {
627 if (s == nullptr)
628 {
629 ARMARX_WARNING << "Unexpected nullptr!";
630 continue;
631 }
632 ret.push_back(s->toFluxioIdentificatorIce());
633 }
634
635 if (!dryRun)
636 {
637 skill.deleted = true;
638 saveSkill(skill);
639 }
640
641 return ret;
642 }
643
644 bool
646 const std::string& userId,
647 const Ice::Current& current)
648 {
649 return this->plugin->getSkillMutex(skillId, userId).getResult();
650 }
651
652 void
654 const std::string& userId,
655 const Ice::Current& current)
656 {
657 this->plugin->deleteSkillMutex(skillId, userId);
658 }
659
660 IceUtil::Optional<skills::manager::dto::FluxioIdentificatorList>
662 const std::string& parameterId,
663 const std::string& userId,
664 bool dryRun,
665 const Ice::Current& current)
666 {
667 skills::manager::dto::FluxioIdentificatorList ret;
668 auto res = this->plugin->deleteSkillParameter(skillId, parameterId, userId, dryRun);
669
670 if (!res.isSuccess())
671 {
672 throw res.getError().toManagerIce();
673 }
674
675 for (const auto& s : res.getResult())
676 {
677 if (s == nullptr)
678 {
679 ARMARX_WARNING << "Unexpected nullptr!";
680 continue;
681 }
682 ret.push_back(s->toFluxioIdentificatorIce());
683 }
684
685 return ret;
686 }
687
688 IceUtil::Optional<skills::manager::dto::FluxioIdentificatorList>
690 const std::string& skillId,
691 const skills::manager::dto::FluxioParameter& parameter,
692 const std::string& userId,
693 bool dryRun,
694 const Ice::Current& current)
695 {
696 skills::manager::dto::FluxioIdentificatorList ret;
697 auto res = this->plugin->updateSkillParameter(skillId, parameter, userId, dryRun);
698
699 if (!res.isSuccess())
700 {
701 throw res.getError().toManagerIce();
702 }
703
704 for (const auto& s : res.getResult())
705 {
706 if (s == nullptr)
707 {
708 ARMARX_WARNING << "Unexpected nullptr!";
709 continue;
710 }
711 ret.push_back(s->toFluxioIdentificatorIce());
712 }
713
714 return ret;
715 }
716
717 skills::manager::dto::FluxioProfileList
719 {
720 skills::manager::dto::FluxioProfileList ret;
721
722 auto l = this->plugin->getProfileList();
723
724 for (const auto& p : l.getResult())
725 {
726 if (p == nullptr)
727 {
728 ARMARX_WARNING << "Unexpected nullptr!";
729 continue;
730 }
731 ret.push_back(p->toManagerIce());
732 }
733
734 return ret;
735 }
736
737 IceUtil::Optional<skills::manager::dto::FluxioProfile>
738 SkillManagerComponentPluginUser::getProfile(const std::string& id, const Ice::Current& current)
739 {
740 auto profile = this->plugin->getProfile(id);
741
742 if (!profile.isSuccess())
743 {
744 auto e = profile.getError();
745 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
746 throw e.toManagerIce();
747 }
748 return profile.getResult().toManagerIce();
749 }
750
751 skills::manager::dto::FluxioProfile
753 const skills::manager::dto::FluxioProfile& profile,
754 const Ice::Current& current)
755 {
756 std::unique_lock l(this->plugin->fluxioDC.profilesMutex);
757 auto& profilesMap = this->plugin->fluxioDC.profiles;
758
759 const auto& converted = skills::FluxioProfile::FromIce(profile, profilesMap);
760 l.unlock();
761
762 armarx::skills::FluxioProfile ret = this->plugin->createProfile(converted).getResult();
763
765
766 return ret.toManagerIce();
767 }
768
769 void
771 const skills::manager::dto::FluxioProfile& profile,
772 const Ice::Current& current)
773 {
774 std::unique_lock l(this->plugin->fluxioDC.profilesMutex);
775 auto& profilesMap = this->plugin->fluxioDC.profiles;
776 l.unlock();
777
778 this->plugin->updateProfile(skills::FluxioProfile::FromIce(profile, profilesMap));
779 }
780
781 skills::manager::dto::FluxioProviderList
783 {
784 skills::manager::dto::FluxioProviderList ret;
785
786 auto l = this->plugin->getProviderList();
787 if (!l.isSuccess())
788 {
789 auto e = l.getError();
790 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
791 throw e.toManagerIce();
792 }
793
794 for (const auto& p : l.getResult())
795 {
796 if (p == nullptr)
797 {
798 ARMARX_WARNING << "Unexpected nullptr!";
799 continue;
800 }
801 ret.push_back(p->toManagerIce());
802 }
803
804 return ret;
805 }
806
807 IceUtil::Optional<skills::manager::dto::FluxioProvider>
808 SkillManagerComponentPluginUser::getProvider(const std::string& id, const Ice::Current& current)
809 {
810 auto provider = this->plugin->getProvider(id);
811
812 if (provider.isSuccess())
813 {
814 auto e = provider.getError();
815 e.addToContext(std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
816 throw e.toManagerIce();
817 }
818 return provider.getResult().toManagerIce();
819 }
820
821 IceUtil::Optional<skills::manager::dto::FluxioSkillList>
823 const Ice::Current& current)
824 {
825 skills::manager::dto::FluxioSkillList ret;
826
827 auto l = this->plugin->getSkillsOfProvider(id);
828
829 if (!l.isSuccess())
830 {
831 auto error = l.getError();
832 error.addToContext(
833 std::nullopt, "SkillManagerComponentPluginUser", __FUNCTION__, __LINE__);
834 throw error.toManagerIce();
835 }
836
837 for (const auto& s : l.getResult())
838 {
839 if (s == nullptr)
840 {
841 ARMARX_WARNING << "Unexpected nullptr!";
842 continue;
843 }
844
845 const auto& skill = s->toManagerIce();
846
847 if (!skill.has_value())
848 {
850 << "SkillManagerComponentPluginUser::getSkillsOfProvider: Skill with id "
851 << s->id << " could not be converted";
852 continue;
853 }
854
855 ret.push_back(skill.value());
856 }
857
858 return ret;
859 }
860
861 IceUtil::Optional<skills::manager::dto::FluxioSkill>
863 const std::string& userId,
864 const std::string& providerId,
865 const skills::manager::dto::FluxioSkill& skill,
866 const Ice::Current& current)
867 {
868 std::unique_lock skillsLock(this->plugin->fluxioDC.skillsMutex, std::defer_lock);
869 std::unique_lock profilesLock(this->plugin->fluxioDC.profilesMutex, std::defer_lock);
870 std::unique_lock providersLock(this->plugin->fluxioDC.providersMutex, std::defer_lock);
871 std::unique_lock typesLock(this->plugin->fluxioDC.typesMutex, std::defer_lock);
872 std::lock(skillsLock, profilesLock, providersLock, typesLock);
873
874 auto& skillsMap = this->plugin->fluxioDC.skills;
875 auto& providersMap = this->plugin->fluxioDC.providers;
876 auto& profilesMap = this->plugin->fluxioDC.profiles;
877 auto& typesMap = this->plugin->fluxioDC.types;
878 auto skillBO =
879 skills::FluxioSkill::FromIce(skill, providersMap, profilesMap, skillsMap, typesMap);
880
881 if (skillBO == nullptr)
882 {
883 ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted";
884
887 {skill.id}),
889 "SkillManagerComponentPluginUser",
890 __FUNCTION__,
891 __LINE__)
892 .toManagerIce();
893 }
894
895 skillsLock.unlock();
896 profilesLock.unlock();
897 providersLock.unlock();
898 typesLock.unlock();
899
900 auto& skillReleased = *skillBO.release();
901 const auto res =
902 this->plugin->addSkillToProvider(userId, providerId, std::move(skillReleased));
903 if (!res.isSuccess())
904 {
905 ARMARX_WARNING << "Skill with id " << skill.id
906 << " could not be added to provider with id " << providerId;
907
908 auto error = res.getError();
909 error.addToContext(
911 {skill.id, providerId})),
912 "SkillManagerComponentPluginUser",
913 __FUNCTION__,
914 __LINE__);
915 throw error.toManagerIce();
916 }
917
918 const auto& s = res.getResult();
919
920 if (s == nullptr)
921 {
922 ARMARX_WARNING << "Skill with id " << skill.id
923 << " could not be added to provider with id " << providerId;
924 return {};
925 }
926
927 const auto& ret = s->toManagerIce();
928 if (!ret.has_value())
929 {
930 ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted";
931 return {};
932 }
933
934 const std::optional<skills::manager::arondto::FluxioSkill> aronSkill = s->toAronXml();
935
936 if (!aronSkill.has_value())
937 {
938 ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted to Aron";
939 return {};
940 }
941
942 saveSkill(aronSkill.value());
943
944 return ret.value();
945 }
946
947 void
948 SkillManagerComponentPluginUser::saveSkill(const skills::manager::arondto::FluxioSkill& skill)
949 {
950 // Implemented in derived class
951 }
952
953 std::optional<std::vector<skills::manager::arondto::FluxioSkill>>
955 {
956 // Implemented in derived class
957 return {};
958 }
959
960 std::optional<std::vector<skills::manager::arondto::FluxioSkill>>
962 {
963 // Implemented in derived class
964 return {};
965 }
966
967 void
969 const skills::manager::arondto::FluxioProfile& profile)
970 {
971 // Implemented in derived class
972 }
973
974 std::optional<std::vector<skills::manager::arondto::FluxioProfile>>
976 {
977 // Implemented in derived class
978 return {};
979 }
980} // 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:131
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:188
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:194
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:191
::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 &)