blob: 471e4b9d381d2cd40038ca1e3f594c940272c7b2 [file]
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
#pragma once
#include <iostream>
#include <limits>
#include <memory>
#include <string>
#include <utility>
#include "utils/StringUtils.h"
#include "io/validation.h"
#include "core/controller/ControllerServiceBase.h"
#include "core/logging/LoggerFactory.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
#include "minifi-cpp/core/PropertyValidator.h"
#include "core/state/UpdatePolicy.h"
#include "minifi-cpp/utils/Export.h"
namespace org::apache::nifi::minifi::controllers {
/**
* Purpose: UpdatePolicyControllerService allows a flow specific policy on allowing or disallowing updates.
* Since the flow dictates the purpose of a device it will also be used to dictate updates to specific components.
*/
class UpdatePolicyControllerService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceHandle {
public:
using ControllerServiceBase::ControllerServiceBase;
MINIFIAPI static constexpr const char* Description = "UpdatePolicyControllerService allows a flow specific policy on allowing or disallowing updates. "
"Since the flow dictates the purpose of a device it will also be used to dictate updates to specific components.";
MINIFIAPI static constexpr auto AllowAllProperties = core::PropertyDefinitionBuilder<>::createProperty("Allow All Properties")
.withDescription("Allows all properties, which are also not disallowed, to be updated")
.withValidator(core::StandardPropertyValidators::BOOLEAN_VALIDATOR)
.withDefaultValue("false")
.build();
MINIFIAPI static constexpr auto PersistUpdates = core::PropertyDefinitionBuilder<>::createProperty("Persist Updates")
.withDescription("Property that dictates whether updates should persist after a restart")
.isRequired(false)
.withValidator(core::StandardPropertyValidators::BOOLEAN_VALIDATOR)
.withDefaultValue("false")
.build();
MINIFIAPI static constexpr auto AllowedProperties = core::PropertyDefinitionBuilder<>::createProperty("Allowed Properties")
.withDescription("Properties for which we will allow updates")
.isRequired(false)
.build();
MINIFIAPI static constexpr auto DisallowedProperties = core::PropertyDefinitionBuilder<>::createProperty("Disallowed Properties")
.withDescription("Properties for which we will not allow updates")
.isRequired(false)
.build();
MINIFIAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({
AllowAllProperties,
PersistUpdates,
AllowedProperties,
DisallowedProperties
});
MINIFIAPI static constexpr bool SupportsDynamicProperties = false;
ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override;
void onEnable() override;
[[nodiscard]] ControllerServiceHandle* getControllerServiceHandle() override {return this;}
bool canUpdate(const std::string &property) const {
return policy_->canUpdate(property);
}
bool persistUpdates() const {
return persist_updates_;
}
private:
bool persist_updates_ = false;
std::unique_ptr<state::UpdatePolicy> policy_ = std::make_unique<state::UpdatePolicy>(false);
};
} // namespace org::apache::nifi::minifi::controllers