blob: 205002a3a79bb74ffd8315ad68574911087c5026 [file] [log] [blame]
Matthew Barth070ee3c2021-01-29 09:58:16 -06001/**
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 Barth070ee3c2021-01-29 09:58:16 -060022#include <nlohmann/json.hpp>
Matthew Barth070ee3c2021-01-29 09:58:16 -060023
24#include <algorithm>
Patrick Williamsfbf47032023-07-17 12:27:34 -050025#include <format>
Matthew Barth070ee3c2021-01-29 09:58:16 -060026
27namespace phosphor::fan::control::json
28{
29
30using json = nlohmann::json;
Matthew Barth070ee3c2021-01-29 09:58:16 -060031
Matthew Barth19c77492021-04-08 10:06:06 -050032MissingOwnerTarget::MissingOwnerTarget(const json& jsonObj,
33 const std::vector<Group>& groups) :
34 ActionBase(jsonObj, groups)
Matthew Barth070ee3c2021-01-29 09:58:16 -060035{
36 setTarget(jsonObj);
37}
38
Matthew Barth6d2476c2021-04-08 10:48:57 -050039void MissingOwnerTarget::run(Zone& zone)
Matthew Barth070ee3c2021-01-29 09:58:16 -060040{
Matthew Barth6d2476c2021-04-08 10:48:57 -050041 for (const auto& group : _groups)
Matthew Barth070ee3c2021-01-29 09:58:16 -060042 {
Matthew Barth6d2476c2021-04-08 10:48:57 -050043 const auto& members = group.getMembers();
44 auto isMissingOwner =
45 std::any_of(members.begin(), members.end(),
46 [&intf = group.getInterface()](const auto& member) {
Patrick Williamsdfddd642024-08-16 15:21:51 -040047 return !Manager::hasOwner(member, intf);
48 });
Matthew Barth53680112021-09-23 11:20:41 -050049 // Update zone's target hold based on action results
50 zone.setTargetHold(group.getName(), _target, isMissingOwner);
Matthew Barth070ee3c2021-01-29 09:58:16 -060051 }
Matthew Barth070ee3c2021-01-29 09:58:16 -060052}
53
54void MissingOwnerTarget::setTarget(const json& jsonObj)
55{
Matthew Barth55ed9012021-10-21 11:48:18 -050056 if (!jsonObj.contains("target"))
Matthew Barth070ee3c2021-01-29 09:58:16 -060057 {
Matthew Barthbfd7e1b2021-02-04 14:25:47 -060058 throw ActionParseError{ActionBase::getName(),
Matthew Barth55ed9012021-10-21 11:48:18 -050059 "Missing required target value"};
Matthew Barth070ee3c2021-01-29 09:58:16 -060060 }
Matthew Barth55ed9012021-10-21 11:48:18 -050061 _target = jsonObj["target"].get<uint64_t>();
Matthew Barth070ee3c2021-01-29 09:58:16 -060062}
63
64} // namespace phosphor::fan::control::json