blob: ccafdc2d59b419ae0496778bb286a5749e30ec82 [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
22#include <fmt/format.h>
23
24#include <nlohmann/json.hpp>
25#include <phosphor-logging/log.hpp>
26
27#include <algorithm>
28
29namespace phosphor::fan::control::json
30{
31
32using json = nlohmann::json;
33using namespace phosphor::logging;
34
Matthew Barth19c77492021-04-08 10:06:06 -050035MissingOwnerTarget::MissingOwnerTarget(const json& jsonObj,
36 const std::vector<Group>& groups) :
37 ActionBase(jsonObj, groups)
Matthew Barth070ee3c2021-01-29 09:58:16 -060038{
39 setTarget(jsonObj);
40}
41
Matthew Barth6d2476c2021-04-08 10:48:57 -050042void MissingOwnerTarget::run(Zone& zone)
Matthew Barth070ee3c2021-01-29 09:58:16 -060043{
Matthew Barth6d2476c2021-04-08 10:48:57 -050044 for (const auto& group : _groups)
Matthew Barth070ee3c2021-01-29 09:58:16 -060045 {
Matthew Barth6d2476c2021-04-08 10:48:57 -050046 const auto& members = group.getMembers();
47 auto isMissingOwner =
48 std::any_of(members.begin(), members.end(),
49 [&intf = group.getInterface()](const auto& member) {
50 return !Manager::hasOwner(member, intf);
51 });
Matthew Barth53680112021-09-23 11:20:41 -050052 // Update zone's target hold based on action results
53 zone.setTargetHold(group.getName(), _target, isMissingOwner);
Matthew Barth070ee3c2021-01-29 09:58:16 -060054 }
Matthew Barth070ee3c2021-01-29 09:58:16 -060055}
56
57void MissingOwnerTarget::setTarget(const json& jsonObj)
58{
Matthew Barth55ed9012021-10-21 11:48:18 -050059 if (!jsonObj.contains("target"))
Matthew Barth070ee3c2021-01-29 09:58:16 -060060 {
Matthew Barthbfd7e1b2021-02-04 14:25:47 -060061 throw ActionParseError{ActionBase::getName(),
Matthew Barth55ed9012021-10-21 11:48:18 -050062 "Missing required target value"};
Matthew Barth070ee3c2021-01-29 09:58:16 -060063 }
Matthew Barth55ed9012021-10-21 11:48:18 -050064 _target = jsonObj["target"].get<uint64_t>();
Matthew Barth070ee3c2021-01-29 09:58:16 -060065}
66
67} // namespace phosphor::fan::control::json