Skip to content

Commit 131f6e4

Browse files
adamdebreceniszaszm
authored andcommitted
MINIFICPP-2669 - Reduce controller service api
Closes #2065 Signed-off-by: Marton Szasz <szaszm@apache.org>
1 parent a89a27c commit 131f6e4

File tree

124 files changed

+1038
-1291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1038
-1291
lines changed

CONTROLLERS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ In the list below, the names of required properties appear in bold. Any other pr
209209
| **Max Throughput** | 1 MB | | Max throughput ( per second ) for these network controllers |
210210
| **Max Payload** | 1 GB | | Maximum payload for these network controllers |
211211
| **Verify Interfaces** | true | true<br/>false | Verify that interfaces are operational |
212-
| Default Prioritizer | false | true<br/>false | Sets this controller service as the default prioritizer for all comms |
212+
| Default Prioritizer | false | true<br/>false | DEPRECATED, does not do anything |
213213

214214

215215
## ODBCService

controller/MiNiFiController.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "c2/ControllerSocketProtocol.h"
3131
#include "controllers/SSLContextService.h"
3232
#include "core/ConfigurationFactory.h"
33-
#include "minifi-cpp/core/controller/ControllerService.h"
3433
#include "core/extension/ExtensionManager.h"
3534
#include "properties/Configure.h"
3635
#include "range/v3/algorithm/contains.hpp"
@@ -42,8 +41,7 @@ std::shared_ptr<minifi::controllers::SSLContextServiceInterface> getSSLContextSe
4241
std::shared_ptr<minifi::controllers::SSLContextServiceInterface> secure_context;
4342
std::string secure_str;
4443
if (configuration->get(minifi::Configure::nifi_remote_input_secure, secure_str) && minifi::utils::string::toBool(secure_str).value_or(false)) {
45-
secure_context = std::make_shared<minifi::controllers::SSLContextService>("ControllerSocketProtocolSSL", configuration);
46-
secure_context->onEnable();
44+
secure_context = minifi::controllers::SSLContextService::createAndEnable("ControllerSocketProtocolSSL", configuration);
4745
}
4846

4947
return secure_context;

controller/tests/ControllerTests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ class ControllerTestFixture {
228228
configuration_->set(minifi::Configure::nifi_security_client_private_key, (minifi::utils::file::FileUtils::get_executable_dir() / "resources" / "minifi-cpp-flow.key").string());
229229
configuration_->set(minifi::Configure::nifi_security_client_pass_phrase, "abcdefgh");
230230
configuration_->set(minifi::Configure::nifi_security_client_ca_certificate, (minifi::utils::file::FileUtils::get_executable_dir() / "resources" / "root-ca.pem").string());
231-
ssl_context_service_ = std::make_shared<controllers::SSLContextService>("SSLContextService", configuration_);
232-
ssl_context_service_->onEnable();
231+
ssl_context_service_ = controllers::SSLContextService::createAndEnable("SSLContextService", configuration_);
233232
controller_socket_data_.host = "localhost";
234233
controller_socket_data_.port = 9997;
235234
}

core-framework/include/core/Resource.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "utils/OptionalUtils.h"
3131
#include "utils/Macro.h"
3232
#include "core/ProcessorFactoryImpl.h"
33+
#include "core/controller/ControllerServiceFactoryImpl.h"
3334
#include "core/ObjectFactory.h"
3435
#include "minifi-cpp/agent/agent_version.h"
3536

@@ -62,6 +63,11 @@ class StaticClassType {
6263
auto factory = std::unique_ptr<ProcessorFactory>(new ProcessorFactoryImpl<Class>(module_name));
6364
getClassLoader().registerClass(construction_name, std::move(factory));
6465
}
66+
} else if constexpr (Type == ResourceType::ControllerService) {
67+
for (const auto& construction_name : construction_names_) {
68+
auto factory = std::unique_ptr<controller::ControllerServiceFactory>(new controller::ControllerServiceFactoryImpl<Class>(module_name));
69+
getClassLoader().registerClass(construction_name, std::move(factory));
70+
}
6571
} else {
6672
for (const auto& construction_name : construction_names_) {
6773
auto factory = std::unique_ptr<ObjectFactory>(new DefaultObjectFactory<Class>(module_name));

core-framework/include/core/controller/ControllerService.h

Lines changed: 0 additions & 121 deletions
This file was deleted.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
*
3+
* Licensed to the Apache Software Foundation (ASF) under one or more
4+
* contributor license agreements. See the NOTICE file distributed with
5+
* this work for additional information regarding copyright ownership.
6+
* The ASF licenses this file to You under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#pragma once
19+
20+
#include <memory>
21+
#include <string>
22+
#include <utility>
23+
#include <vector>
24+
25+
#include "minifi-cpp/properties/Configure.h"
26+
#include "core/Core.h"
27+
#include "core/ConfigurableComponentImpl.h"
28+
#include "core/Connectable.h"
29+
#include "minifi-cpp/core/controller/ControllerServiceApi.h"
30+
#include "minifi-cpp/core/controller/ControllerServiceHandle.h"
31+
#include "minifi-cpp/core/ControllerServiceApiDefinition.h"
32+
#include "minifi-cpp/core/controller/ControllerServiceMetadata.h"
33+
34+
#define ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES \
35+
bool supportsDynamicProperties() const override { return SupportsDynamicProperties; }
36+
37+
namespace org::apache::nifi::minifi::core::controller {
38+
39+
class ControllerServiceBase : public ControllerServiceApi {
40+
public:
41+
explicit ControllerServiceBase(ControllerServiceMetadata metadata)
42+
: name_(std::move(metadata.name)),
43+
uuid_(metadata.uuid),
44+
logger_(std::move(metadata.logger)) {}
45+
46+
virtual void initialize() = 0;
47+
48+
void initialize(ControllerServiceDescriptor& descriptor) final {
49+
gsl_Expects(!descriptor_);
50+
descriptor_ = &descriptor;
51+
auto guard = gsl::finally([&] {descriptor_ = nullptr;});
52+
initialize();
53+
}
54+
55+
void setSupportedProperties(std::span<const PropertyReference> properties) {
56+
gsl_Expects(descriptor_);
57+
descriptor_->setSupportedProperties(properties);
58+
}
59+
60+
ControllerServiceBase(const ControllerServiceBase&) = delete;
61+
ControllerServiceBase(ControllerServiceBase&&) = delete;
62+
ControllerServiceBase& operator=(const ControllerServiceBase&) = delete;
63+
ControllerServiceBase& operator=(ControllerServiceBase&&) = delete;
64+
65+
~ControllerServiceBase() noexcept override = default;
66+
67+
virtual void onEnable() = 0;
68+
69+
void onEnable(ControllerServiceContext& context, const std::shared_ptr<Configure>& configuration, const std::vector<std::shared_ptr<ControllerServiceHandle>>& linked_services) final {
70+
configuration_ = configuration;
71+
linked_services_ = linked_services;
72+
gsl_Expects(!context_);
73+
context_ = &context;
74+
auto guard = gsl::finally([&] {context_ = nullptr;});
75+
onEnable();
76+
}
77+
78+
[[nodiscard]] nonstd::expected<std::string, std::error_code> getProperty(std::string_view name) const {
79+
gsl_Expects(context_);
80+
return context_->getProperty(name);
81+
}
82+
83+
[[nodiscard]] nonstd::expected<std::vector<std::string>, std::error_code> getAllPropertyValues(std::string_view name) const {
84+
gsl_Expects(context_);
85+
return context_->getAllPropertyValues(name);
86+
}
87+
88+
void notifyStop() override {}
89+
90+
std::string getName() const {
91+
return name_;
92+
}
93+
94+
utils::Identifier getUUID() const {
95+
return uuid_;
96+
}
97+
98+
99+
static constexpr auto ImplementsApis = std::array<ControllerServiceApiDefinition, 0>{};
100+
101+
protected:
102+
std::string name_;
103+
utils::Identifier uuid_;
104+
std::vector<std::shared_ptr<controller::ControllerServiceHandle> > linked_services_;
105+
std::shared_ptr<Configure> configuration_;
106+
// valid during initialize, sink for supported properties
107+
ControllerServiceDescriptor* descriptor_{nullptr};
108+
// valid during onEnable, provides property access
109+
ControllerServiceContext* context_{nullptr};
110+
111+
std::shared_ptr<core::logging::Logger> logger_;
112+
};
113+
114+
} // namespace org::apache::nifi::minifi::core::controller

minifi-api/include/minifi-cpp/core/controller/ControllerService.h renamed to core-framework/include/core/controller/ControllerServiceFactoryImpl.h

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/**
2-
*
32
* Licensed to the Apache Software Foundation (ASF) under one or more
43
* contributor license agreements. See the NOTICE file distributed with
54
* this work for additional information regarding copyright ownership.
@@ -15,40 +14,44 @@
1514
* See the License for the specific language governing permissions and
1615
* limitations under the License.
1716
*/
17+
1818
#pragma once
1919

20-
#include <memory>
2120
#include <string>
21+
#include <memory>
2222
#include <utility>
23-
#include <vector>
24-
25-
#include "minifi-cpp/properties/Configure.h"
26-
#include "minifi-cpp/core/ConfigurableComponent.h"
27-
#include "minifi-cpp/core/Connectable.h"
23+
#include "core/ClassName.h"
24+
#include "minifi-cpp/core/controller/ControllerServiceFactory.h"
2825

2926
namespace org::apache::nifi::minifi::core::controller {
3027

31-
enum ControllerServiceState {
32-
DISABLED,
33-
DISABLING,
34-
ENABLING,
35-
ENABLED
36-
};
37-
38-
/**
39-
* Controller Service base class that contains some pure virtual methods.
40-
*
41-
* Design: OnEnable is executed when the controller service is being enabled.
42-
* Note that keeping state here must be protected in this function.
43-
*/
44-
class ControllerService : public virtual ConfigurableComponent, public virtual Connectable {
28+
template<class T>
29+
class ControllerServiceFactoryImpl : public ControllerServiceFactory {
4530
public:
46-
virtual void setConfiguration(const std::shared_ptr<Configure> &configuration) = 0;
47-
virtual ControllerServiceState getState() const = 0;
48-
virtual void onEnable() = 0;
49-
virtual void notifyStop() = 0;
50-
virtual void setState(ControllerServiceState state) = 0;
51-
virtual void setLinkedControllerServices(const std::vector<std::shared_ptr<controller::ControllerService>> &services) = 0;
31+
ControllerServiceFactoryImpl()
32+
: class_name_(core::className<T>()) {
33+
}
34+
35+
explicit ControllerServiceFactoryImpl(std::string group_name)
36+
: group_name_(std::move(group_name)),
37+
class_name_(core::className<T>()) {
38+
}
39+
40+
std::string getGroupName() const override {
41+
return group_name_;
42+
}
43+
44+
std::unique_ptr<ControllerServiceApi> create(ControllerServiceMetadata metadata) override {
45+
return std::make_unique<T>(metadata);
46+
}
47+
48+
std::string getClassName() const override {
49+
return std::string{class_name_};
50+
}
51+
52+
protected:
53+
std::string group_name_;
54+
std::string_view class_name_;
5255
};
5356

5457
} // namespace org::apache::nifi::minifi::core::controller

core-framework/include/http/HTTPClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "minifi-cpp/core/logging/Logger.h"
4646
#include "core/logging/LoggerFactory.h"
4747
#include "minifi-cpp/controllers/SSLContextServiceInterface.h"
48+
#include "minifi-cpp/core/PropertyDefinition.h"
4849
#include "utils/ByteArrayCallback.h"
4950

5051
namespace org::apache::nifi::minifi::http {

0 commit comments

Comments
 (0)