Skip to content

Commit 7988c8b

Browse files
authored
MINIFICPP-2765 Move GCP Extension to stable C API (#2153)
1 parent 8c3152c commit 7988c8b

35 files changed

Lines changed: 691 additions & 512 deletions

behave_framework/src/minifi_behave/steps/checking_steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def verify_minifi_logs_match_regex(context, regex, duration):
119119
@step('no errors were generated on the http-proxy regarding "{url}"')
120120
def verify_no_errors_on_http_proxy(context: MinifiTestContext, url: str):
121121
http_proxy_container = next(container for container in context.containers.values() if isinstance(container, HttpProxy))
122-
assert http_proxy_container.check_http_proxy_access(url) or http_proxy_container.log_app_output()
122+
assert http_proxy_container.check_http_proxy_access(url) or log_due_to_failure(context)
123123

124124

125125
@then('in the "{container}" container no files are placed in the "{directory}" directory in {duration} of running time')

extension-framework/cpp-extension-lib/include/api/core/ProcessContext.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
#pragma once
1919

20-
#include <string>
2120
#include <expected>
21+
#include <string>
2222

2323
#include "api/core/FlowFile.h"
24+
#include "api/utils/Proxy.h"
2425
#include "api/utils/Ssl.h"
2526
#include "minifi-c.h"
2627
#include "minifi-cpp/core/PropertyDefinition.h"
@@ -39,12 +40,12 @@ class ProcessContext {
3940

4041
[[nodiscard]] virtual std::expected<std::string, std::error_code> getProperty(const minifi::core::PropertyReference& prop,
4142
const FlowFile* ff) const = 0;
42-
[[nodiscard]] virtual std::expected<MinifiControllerService*, std::error_code> getControllerService(std::string_view name,
43-
std::string_view type) const = 0;
43+
[[nodiscard]] virtual std::expected<MinifiControllerService*, std::error_code> getControllerService(const minifi::core::PropertyReference& prop) const = 0;
4444
[[nodiscard]] virtual bool hasNonEmptyProperty(std::string_view name) const = 0;
4545
[[nodiscard]] virtual std::map<std::string, std::string> getDynamicProperties(const FlowFile* flow_file) const = 0;
4646

47-
[[nodiscard]] virtual std::expected<utils::net::SslData, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const = 0;
47+
[[nodiscard]] virtual std::expected<std::optional<utils::net::SslData>, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const = 0;
48+
[[nodiscard]] virtual std::expected<std::optional<utils::ProxyData>, std::error_code> getProxyData(const minifi::core::PropertyReference& prop) const = 0;
4849
};
4950

5051
class CffiProcessContext : public ProcessContext {
@@ -53,12 +54,12 @@ class CffiProcessContext : public ProcessContext {
5354

5455
[[nodiscard]] std::expected<std::string, std::error_code> getProperty(const minifi::core::PropertyReference& property_reference,
5556
const FlowFile* flow_file) const override;
56-
[[nodiscard]] std::expected<MinifiControllerService*, std::error_code> getControllerService(std::string_view name,
57-
std::string_view type) const override;
57+
[[nodiscard]] std::expected<MinifiControllerService*, std::error_code> getControllerService(const minifi::core::PropertyReference& prop) const override;
5858
[[nodiscard]] std::map<std::string, std::string> getDynamicProperties(const FlowFile* flow_file) const override;
5959
[[nodiscard]] bool hasNonEmptyProperty(std::string_view name) const override;
6060

61-
[[nodiscard]] std::expected<utils::net::SslData, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const override;
61+
[[nodiscard]] std::expected<std::optional<utils::net::SslData>, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const override;
62+
[[nodiscard]] std::expected<std::optional<utils::ProxyData>, std::error_code> getProxyData(const minifi::core::PropertyReference& prop) const override;
6263

6364
private:
6465
[[nodiscard]] std::expected<std::string, std::error_code> getProperty(std::string_view name, const FlowFile* flow_file) const;

extension-framework/cpp-extension-lib/include/api/utils/ProcessorConfigUtils.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,8 @@ std::optional<T> parseOptionalEnumProperty(const core::ProcessContext& context,
169169

170170
template<typename ControllerServiceType>
171171
ControllerServiceType* parseOptionalControllerService(const core::ProcessContext& context, const minifi::core::PropertyReference& prop) {
172-
const auto controller_service_name = context.getProperty(prop, nullptr);
173-
if (!controller_service_name || controller_service_name->empty()) {
174-
return nullptr;
175-
}
172+
auto service = context.getControllerService(prop);
176173

177-
auto service = context.getControllerService(*controller_service_name, minifi::core::className<ControllerServiceType>());
178174
if (!service) {
179175
return nullptr;
180176
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#pragma once
18+
19+
#include <filesystem>
20+
#include <optional>
21+
#include <string>
22+
23+
namespace org::apache::nifi::minifi::api::utils {
24+
25+
enum class ProxyType {
26+
DIRECT,
27+
HTTP
28+
};
29+
30+
struct BasicAuthCredentials {
31+
std::string username;
32+
std::string password;
33+
};
34+
35+
struct ProxyData {
36+
ProxyType proxy_type;
37+
std::string host;
38+
uint16_t port;
39+
std::optional<BasicAuthCredentials> proxy_credentials;
40+
};
41+
42+
} // namespace org::apache::nifi::minifi::api::utils

extension-framework/cpp-extension-lib/include/api/utils/Ssl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717
#pragma once
1818

1919
#include <string>
20-
#include <memory>
21-
#include <optional>
2220
#include <filesystem>
2321

24-
#include "utils/Enum.h"
25-
2622
namespace org::apache::nifi::minifi::api::utils::net {
2723

2824
enum class ClientAuthOption {

extension-framework/cpp-extension-lib/mocklib/include/MockProcessContext.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class MockProcessContext : public api::core::ProcessContext {
2929

3030
[[nodiscard]] std::expected<std::string, std::error_code> getProperty(const core::PropertyReference& property_reference,
3131
const api::core::FlowFile* flow_file) const override;
32-
[[nodiscard]] std::expected<MinifiControllerService*, std::error_code> getControllerService(std::string_view controller_service_name,
33-
std::string_view controller_service_class) const override;
32+
[[nodiscard]] std::expected<MinifiControllerService*, std::error_code> getControllerService(const minifi::core::PropertyReference& prop) const override;
3433
[[nodiscard]] std::map<std::string, std::string> getDynamicProperties(const api::core::FlowFile* flow_file) const override;
3534
[[nodiscard]] bool hasNonEmptyProperty(std::string_view name) const override;
3635

37-
[[nodiscard]] std::expected<api::utils::net::SslData, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const override;
36+
[[nodiscard]] std::expected<std::optional<api::utils::net::SslData>, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const override;
37+
[[nodiscard]] std::expected<std::optional<api::utils::ProxyData>, std::error_code> getProxyData(const minifi::core::PropertyReference& prop) const override;
3838

3939
std::map<std::string, std::string, std::less<>> properties_;
4040

extension-framework/cpp-extension-lib/mocklib/src/MockProcessContext.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::expected<std::string, std::error_code> MockProcessContext::getProperty(cons
3232
return std::unexpected{make_error_code(core::PropertyErrorCode::PropertyNotSet)};
3333
}
3434

35-
std::expected<MinifiControllerService*, std::error_code> MockProcessContext::getControllerService(std::string_view, std::string_view) const {
35+
std::expected<MinifiControllerService*, std::error_code> MockProcessContext::getControllerService(const minifi::core::PropertyReference&) const {
3636
return nullptr;
3737
}
3838

@@ -44,7 +44,11 @@ bool MockProcessContext::hasNonEmptyProperty(const std::string_view name) const
4444
return properties_.contains(name);
4545
}
4646

47-
std::expected<api::utils::net::SslData, std::error_code> MockProcessContext::getSslData(const minifi::core::PropertyReference&) const {
48-
return api::utils::net::SslData{};
47+
std::expected<std::optional<api::utils::net::SslData>, std::error_code> MockProcessContext::getSslData(const minifi::core::PropertyReference&) const {
48+
return std::nullopt;
49+
}
50+
51+
[[nodiscard]] std::expected<std::optional<api::utils::ProxyData>, std::error_code> MockProcessContext::getProxyData(const minifi::core::PropertyReference&) const {
52+
return std::nullopt;
4953
}
5054
} // namespace org::apache::nifi::minifi::mock

extension-framework/cpp-extension-lib/mocklib/src/mock-minifi-c.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ MinifiBool MinifiProcessContextHasNonEmptyProperty(MinifiProcessContext*, Minifi
4444
throw std::runtime_error("Not implemented");
4545
}
4646

47-
MinifiStatus MinifiProcessContextGetControllerService(MinifiProcessContext*, MinifiStringView, MinifiStringView, MinifiControllerService**) {
47+
MinifiStatus MinifiProcessContextGetControllerServiceFromProperty(MinifiProcessContext*, MinifiStringView, MinifiStringView, MinifiControllerService**) {
4848
throw std::runtime_error("Not implemented");
4949
}
5050
void MinifiProcessContextGetDynamicProperties(MinifiProcessContext*, MinifiFlowFile*,
@@ -134,4 +134,9 @@ MinifiStatus MinifiControllerServiceContextGetProperty(MinifiControllerServiceCo
134134
void (*)(void* user_ctx, MinifiStringView property_value), void*) {
135135
throw std::runtime_error("Not implemented");
136136
}
137+
138+
MinifiStatus MinifiProcessContextGetProxyDataFromProperty(MinifiProcessContext*, MinifiStringView,
139+
void (*)(void* user_ctx, const MinifiProxyData* proxy_data), void*) {
140+
throw std::runtime_error("Not implemented");
141+
}
137142
} // extern "C"

extension-framework/cpp-extension-lib/src/core/ProcessContext.cpp

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ bool CffiProcessContext::hasNonEmptyProperty(std::string_view name) const {
4444
return MinifiProcessContextHasNonEmptyProperty(impl_, utils::minifiStringView(name));
4545
}
4646

47-
std::expected<MinifiControllerService*, std::error_code> CffiProcessContext::getControllerService(const std::string_view name,
48-
const std::string_view type) const {
47+
std::expected<MinifiControllerService*, std::error_code> CffiProcessContext::getControllerService(const minifi::core::PropertyReference& prop) const {
4948
MinifiControllerService* controller_service = nullptr;
50-
if (const MinifiStatus status = MinifiProcessContextGetControllerService(impl_,
51-
utils::minifiStringView(name),
52-
utils::minifiStringView(type),
49+
gsl_Assert(prop.allowed_types.size() == 1);
50+
const MinifiStatus status = MinifiProcessContextGetControllerServiceFromProperty(impl_,
51+
utils::minifiStringView(prop.name),
52+
utils::minifiStringView(prop.allowed_types[0]),
5353
&controller_service);
54-
status != MINIFI_STATUS_SUCCESS) {
54+
if (status == MINIFI_STATUS_PROPERTY_NOT_SET) {
55+
return nullptr;
56+
}
57+
if (status != MINIFI_STATUS_SUCCESS) {
5558
return std::unexpected{utils::make_error_code(status)};
5659
}
5760
return controller_service;
@@ -69,7 +72,10 @@ std::map<std::string, std::string> CffiProcessContext::getDynamicProperties(cons
6972
return result;
7073
}
7174

72-
std::expected<utils::net::SslData, std::error_code> CffiProcessContext::getSslData(const minifi::core::PropertyReference& prop) const {
75+
std::expected<std::optional<utils::net::SslData>, std::error_code> CffiProcessContext::getSslData(const minifi::core::PropertyReference& prop) const {
76+
const auto controller_name = getProperty(prop, nullptr);
77+
if (!controller_name) { return std::nullopt; }
78+
7379
auto ssl_data = utils::net::SslData{};
7480

7581
if (const auto status = MinifiProcessContextGetSslDataFromProperty(impl_, utils::minifiStringView(prop.name), [](void* data, const MinifiSslData* minifi_ssl_data) {
@@ -86,4 +92,31 @@ std::expected<utils::net::SslData, std::error_code> CffiProcessContext::getSslDa
8692
return ssl_data;
8793
}
8894

95+
std::expected<std::optional<utils::ProxyData>, std::error_code> CffiProcessContext::getProxyData(const minifi::core::PropertyReference& prop) const {
96+
auto proxy_data = utils::ProxyData{};
97+
const auto status = MinifiProcessContextGetProxyDataFromProperty(
98+
impl_,
99+
utils::minifiStringView(prop.name),
100+
[](void* data, const MinifiProxyData* minifi_proxy_data) {
101+
auto* proxy = static_cast<utils::ProxyData*>(data);
102+
proxy->host = utils::toString(minifi_proxy_data->hostname);
103+
proxy->port = minifi_proxy_data->port;
104+
if (minifi_proxy_data->password && minifi_proxy_data->username) {
105+
proxy->proxy_credentials = utils::BasicAuthCredentials{.username = utils::toString(*minifi_proxy_data->username),
106+
.password = utils::toString(*minifi_proxy_data->password)};
107+
} else {
108+
proxy->proxy_credentials = std::nullopt;
109+
}
110+
if (minifi_proxy_data->proxy_type == MINIFI_PROXY_TYPE_HTTP) {
111+
proxy->proxy_type = utils::ProxyType::HTTP;
112+
} else {
113+
proxy->proxy_type = utils::ProxyType::DIRECT;
114+
}
115+
},
116+
&proxy_data);
117+
if (status == MINIFI_STATUS_PROPERTY_NOT_SET) { return std::nullopt; }
118+
if (status == MINIFI_STATUS_SUCCESS) { return proxy_data; }
119+
return std::unexpected{utils::make_error_code(status)};
120+
}
121+
89122
} // namespace org::apache::nifi::minifi::api::core

extensions/gcp/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ add_minifi_library(minifi-gcp SHARED ${SOURCES})
3030
if (NOT WIN32)
3131
target_compile_options(minifi-gcp PRIVATE -Wno-error=deprecated-declarations) # Suppress deprecation warnings for std::rel_ops usage
3232
endif()
33-
target_link_libraries(minifi-gcp ${LIBMINIFI} google-cloud-cpp::storage)
34-
target_include_directories(minifi-gcp SYSTEM PUBLIC ${google-cloud-cpp_INCLUDE_DIRS})
33+
target_link_libraries(minifi-gcp minifi-cpp-extension-lib google-cloud-cpp::storage)
3534

36-
register_extension(minifi-gcp "GCP EXTENSIONS" GCP-EXTENSIONS "This enables Google Cloud Platform support" "extensions/gcp/tests")
35+
target_include_directories(minifi-gcp SYSTEM PUBLIC ${google-cloud-cpp_INCLUDE_DIRS})
3736

37+
register_c_api_extension(minifi-gcp "GCP EXTENSIONS" GCP-EXTENSIONS "This enables Google Cloud Platform support" "extensions/gcp/tests")

0 commit comments

Comments
 (0)