Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2021 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include "missing_owner_target.hpp" |
| 17 | |
| 18 | #include "../manager.hpp" |
| 19 | #include "../zone.hpp" |
| 20 | #include "group.hpp" |
| 21 | |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 22 | #include <nlohmann/json.hpp> |
| 23 | #include <phosphor-logging/log.hpp> |
| 24 | |
| 25 | #include <algorithm> |
Patrick Williams | fbf4703 | 2023-07-17 12:27:34 -0500 | [diff] [blame] | 26 | #include <format> |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 27 | |
| 28 | namespace phosphor::fan::control::json |
| 29 | { |
| 30 | |
| 31 | using json = nlohmann::json; |
| 32 | using namespace phosphor::logging; |
| 33 | |
Matthew Barth | 19c7749 | 2021-04-08 10:06:06 -0500 | [diff] [blame] | 34 | MissingOwnerTarget::MissingOwnerTarget(const json& jsonObj, |
| 35 | const std::vector<Group>& groups) : |
| 36 | ActionBase(jsonObj, groups) |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 37 | { |
| 38 | setTarget(jsonObj); |
| 39 | } |
| 40 | |
Matthew Barth | 6d2476c | 2021-04-08 10:48:57 -0500 | [diff] [blame] | 41 | void MissingOwnerTarget::run(Zone& zone) |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 42 | { |
Matthew Barth | 6d2476c | 2021-04-08 10:48:57 -0500 | [diff] [blame] | 43 | for (const auto& group : _groups) |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 44 | { |
Matthew Barth | 6d2476c | 2021-04-08 10:48:57 -0500 | [diff] [blame] | 45 | const auto& members = group.getMembers(); |
| 46 | auto isMissingOwner = |
| 47 | std::any_of(members.begin(), members.end(), |
| 48 | [&intf = group.getInterface()](const auto& member) { |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame^] | 49 | return !Manager::hasOwner(member, intf); |
| 50 | }); |
Matthew Barth | 5368011 | 2021-09-23 11:20:41 -0500 | [diff] [blame] | 51 | // Update zone's target hold based on action results |
| 52 | zone.setTargetHold(group.getName(), _target, isMissingOwner); |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 53 | } |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void MissingOwnerTarget::setTarget(const json& jsonObj) |
| 57 | { |
Matthew Barth | 55ed901 | 2021-10-21 11:48:18 -0500 | [diff] [blame] | 58 | if (!jsonObj.contains("target")) |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 59 | { |
Matthew Barth | bfd7e1b | 2021-02-04 14:25:47 -0600 | [diff] [blame] | 60 | throw ActionParseError{ActionBase::getName(), |
Matthew Barth | 55ed901 | 2021-10-21 11:48:18 -0500 | [diff] [blame] | 61 | "Missing required target value"}; |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 62 | } |
Matthew Barth | 55ed901 | 2021-10-21 11:48:18 -0500 | [diff] [blame] | 63 | _target = jsonObj["target"].get<uint64_t>(); |
Matthew Barth | 070ee3c | 2021-01-29 09:58:16 -0600 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace phosphor::fan::control::json |