Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
-DENABLE_SFTP=ON
-DENABLE_SPLUNK=ON
-DENABLE_SQL=ON
-DENABLE_TEST_PROCESSORS=OFF
-DENABLE_TEST_PROCESSORS=ON
-DFORCE_COLORED_OUTPUT=OFF
-DLIBC_STATIC=OFF
-DMINIFI_ADVANCED_ASAN_BUILD=OFF
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
-DENABLE_SMB=ON
-DENABLE_SPLUNK=ON
-DENABLE_SQL=ON
-DENABLE_TEST_PROCESSORS=OFF
-DENABLE_TEST_PROCESSORS=ON
-DENABLE_WEL=ON
-DFORCE_COLORED_OUTPUT=ON
-DINSTALLER_MERGE_MODULES=OFF
Expand Down
6 changes: 3 additions & 3 deletions core-framework/include/core/ObjectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ObjectFactoryImpl : public ObjectFactory {

ObjectFactoryImpl() = default;

std::string getGroupName() const override {
std::string getModuleName() const override {
return group_;
}

Expand All @@ -50,8 +50,8 @@ class DefaultObjectFactory : public ObjectFactoryImpl {
: className(core::className<T>()) {
}

explicit DefaultObjectFactory(std::string group_name)
: ObjectFactoryImpl(std::move(group_name)),
explicit DefaultObjectFactory(std::string module_name)
: ObjectFactoryImpl(std::move(module_name)),
className(core::className<T>()) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class ControllerServiceFactoryImpl : public ControllerServiceFactory {
: class_name_(core::className<T>()) {
}

explicit ControllerServiceFactoryImpl(std::string group_name)
: group_name_(std::move(group_name)),
explicit ControllerServiceFactoryImpl(std::string module_name)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ive renamed it from group_name to module_name, because this groupname was not the groupname in C2 but rather the artifact name

: module_name_(std::move(module_name)),
class_name_(core::className<T>()) {
}

std::string getGroupName() const override {
return group_name_;
std::string getModuleName() const override {
return module_name_;
}

std::unique_ptr<ControllerServiceApi> create(ControllerServiceMetadata metadata) override {
Expand All @@ -52,7 +52,7 @@ class ControllerServiceFactoryImpl : public ControllerServiceFactory {
}

protected:
std::string group_name_;
std::string module_name_;
std::string_view class_name_;
};

Expand Down
24 changes: 24 additions & 0 deletions extension-framework/cpp-extension-lib/include/api/core/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,22 @@ void useControllerServiceClassDefinition(Fn&& fn) {
const auto full_name = minifi::core::className<Class>();

std::vector<MinifiPropertyDefinition> class_properties = utils::toProperties(Class::Properties, string_vector_cache);
std::vector<MinifiStringView> provided_interfaces;
if constexpr (requires { Class::ProvidedInterfaces; }) {
provided_interfaces.reserve(Class::ProvidedInterfaces.size());
for (const auto& iface : Class::ProvidedInterfaces) {
provided_interfaces.push_back(utils::minifiStringView(iface.name));
}
}

MinifiControllerServiceClassDefinition definition{.full_name = utils::minifiStringView(full_name),
.description = utils::minifiStringView(Class::Description),
.class_properties_count = gsl::narrow<uint32_t>(class_properties.size()),
.class_properties_ptr = class_properties.data(),

.provided_interfaces_count = gsl::narrow<uint32_t>(provided_interfaces.size()),
.provided_interfaces_ptr = provided_interfaces.data(),

.callbacks = MinifiControllerServiceCallbacks{
.create = [](MinifiControllerServiceMetadata metadata) -> MINIFI_OWNED void* {
try {
Expand All @@ -181,6 +191,20 @@ void useControllerServiceClassDefinition(Fn&& fn) {
static_cast<Class*>(self)->disable();
} catch (...) {}
},
.get_interface = [](void* self, MinifiStringView interface_name) -> void* {
try {
const std::string_view name_view{interface_name.data, interface_name.length};

if constexpr (requires { Class::ProvidedInterfaces; }) {
for (const auto& iface : Class::ProvidedInterfaces) {
if (iface.name == name_view) {
return iface.cast(self);
}
}
}
return nullptr;
} catch (...) { return nullptr; }
}
}};

fn(definition);
Expand Down
35 changes: 35 additions & 0 deletions extensions/stable-api-sandbox/AnimalControllerServiceApis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <cinttypes>

namespace org::apache::nifi::minifi::api_sandbox {
class NumberOfLegsControllerApi {
public:
virtual ~NumberOfLegsControllerApi() = default;
virtual uint8_t numberOfLegs() const = 0;
};

class CanFlyControllerApi {
public:
Comment thread
martinzink marked this conversation as resolved.
virtual ~CanFlyControllerApi() = default;
virtual bool canFly() const = 0;
};

} // namespace org::apache::nifi::minifi::api_sandbox
30 changes: 30 additions & 0 deletions extensions/stable-api-sandbox/AnimalControllerServices.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "AnimalControllerServices.h"

#include "api/utils/ProcessorConfigUtils.h"
namespace org::apache::nifi::minifi::api_sandbox {

MinifiStatus DogController::enableImpl(api::core::ControllerServiceContext& ctx) {
this->has_jetpack_ = ctx.getProperty(HasJetpack) | minifi::utils::andThen(parsing::parseBool) |
minifi::utils::orThrow(fmt::format("Expected parsable bool from \"{}\"", HasJetpack.name));

return MINIFI_STATUS_SUCCESS;
}

} // namespace org::apache::nifi::minifi::api_sandbox
67 changes: 67 additions & 0 deletions extensions/stable-api-sandbox/AnimalControllerServices.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "AnimalControllerServiceApis.h"
#include "api/core/ControllerServiceImpl.h"
#include "api/utils/Export.h"
#include "core/PropertyDefinitionBuilder.h"
#include "minifi-cpp/core/ProvidedControllerServiceInterface.h"

namespace org::apache::nifi::minifi::api_sandbox {
class DogController : public api::core::ControllerServiceImpl, public CanFlyControllerApi, public NumberOfLegsControllerApi {
public:
EXTENSIONAPI static constexpr const char* Description = "Test DogController";
EXTENSIONAPI static constexpr auto HasJetpack = core::PropertyDefinitionBuilder<>::createProperty("Has Jetpack")
.withDescription("Whether or not the dog has a jetpack")
.withDefaultValue("false")
.withValidator(core::StandardPropertyValidators::BOOLEAN_VALIDATOR)
.build();

EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({
HasJetpack,
});
EXTENSIONAPI static constexpr auto ProvidedInterfaces =
std::to_array<core::ProvidedInterface>({core::createProvidedInterface<CanFlyControllerApi, DogController>(),
core::createProvidedInterface<NumberOfLegsControllerApi, DogController>()});

using ControllerServiceImpl::ControllerServiceImpl;
MinifiStatus enableImpl(api::core::ControllerServiceContext& ctx) override;

uint8_t numberOfLegs() const override { return 4; }
bool canFly() const override { return has_jetpack_; }

private:
bool has_jetpack_ = false;
};

class DuckController : public api::core::ControllerServiceImpl, public CanFlyControllerApi, public NumberOfLegsControllerApi {
public:
EXTENSIONAPI static constexpr const char* Description = "Test DuckController";

EXTENSIONAPI static constexpr std::array<core::PropertyReference, 0> Properties = {};
EXTENSIONAPI static constexpr auto ProvidedInterfaces =
std::to_array<core::ProvidedInterface>({core::createProvidedInterface<CanFlyControllerApi, DuckController>(),
core::createProvidedInterface<NumberOfLegsControllerApi, DuckController>()});
using ControllerServiceImpl::ControllerServiceImpl;
MinifiStatus enableImpl(api::core::ControllerServiceContext&) override { return MINIFI_STATUS_SUCCESS; }

uint8_t numberOfLegs() const override { return 2; }
bool canFly() const override { return true; }
};
} // namespace org::apache::nifi::minifi::api_sandbox
31 changes: 31 additions & 0 deletions extensions/stable-api-sandbox/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

if (NOT ENABLE_TEST_PROCESSORS)
return()
endif ()

include(${CMAKE_SOURCE_DIR}/extensions/ExtensionHeader.txt)
file(GLOB SOURCES "*.cpp")

add_minifi_library(minifi-stable-api-sandbox SHARED ${SOURCES})

target_link_libraries(minifi-stable-api-sandbox minifi-cpp-extension-lib)

register_c_api_extension(minifi-stable-api-sandbox "Stable API Sandbox" SANDBOX-EXTENSION "Stable API Sandbox" "extensions/stable-api-sandbox/tests")
38 changes: 38 additions & 0 deletions extensions/stable-api-sandbox/ExtensionInitializer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "AnimalControllerServices.h"
#include "ZooProcessor.h"
#include "api/core/Resource.h"
#include "api/utils/minifi-c-utils.h"

#define MKSOC(x) #x
#define MAKESTRING(x) MKSOC(x) // NOLINT(cppcoreguidelines-macro-usage)

namespace minifi = org::apache::nifi::minifi;

CEXTENSIONAPI const uint32_t MinifiApiVersion = MINIFI_API_VERSION;

CEXTENSIONAPI void MinifiInitExtension(MinifiExtensionContext* extension_context) {
const MinifiExtensionDefinition extension_definition{.name = minifi::api::utils::minifiStringView(MAKESTRING(EXTENSION_NAME)),
.version = minifi::api::utils::minifiStringView(MAKESTRING(EXTENSION_VERSION)),
.deinit = nullptr,
.user_data = nullptr};
auto* extension = MinifiRegisterExtension(extension_context, &extension_definition);
minifi::api::core::registerProcessors<minifi::api_sandbox::ZooProcessor>(extension);
minifi::api::core::registerControllerServices<minifi::api_sandbox::DogController, minifi::api_sandbox::DuckController>(extension);
}
46 changes: 46 additions & 0 deletions extensions/stable-api-sandbox/ZooProcessor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ZooProcessor.h"

#include "AnimalControllerServices.h"
#include "api/core/ProcessContext.h"

namespace org::apache::nifi::minifi::api_sandbox {

MinifiStatus ZooProcessor::onTriggerImpl(api::core::ProcessContext& process_context, api::core::ProcessSession& process_session) {
if (const auto can_fly_opaque = process_context.getControllerService(CanFlyService)) {
if (*can_fly_opaque) {
const auto can_fly_controller_name = process_context.getProperty(CanFlyService, nullptr) | utils::orThrow("Should be here");
const CanFlyControllerApi* can_fly = reinterpret_cast<CanFlyControllerApi*>(*can_fly_opaque);
logger_->log_critical("Can {} fly? {}", can_fly_controller_name, can_fly->canFly());
}
}
if (const auto num_of_legs_opaque = process_context.getControllerService(NumberOfLegsService)) {
if (*num_of_legs_opaque) {
const auto num_of_legs_name = process_context.getProperty(NumberOfLegsService, nullptr) | utils::orThrow("Should be here");
const NumberOfLegsControllerApi* num_legs = reinterpret_cast<NumberOfLegsControllerApi*>(*num_of_legs_opaque);
logger_->log_critical("{} has {} legs", num_of_legs_name, num_legs->numberOfLegs());
}
}
return ProcessorImpl::onTriggerImpl(process_context, process_session);
}

MinifiStatus ZooProcessor::onScheduleImpl(api::core::ProcessContext& process_context) {
return ProcessorImpl::onScheduleImpl(process_context);
}
} // namespace org::apache::nifi::minifi::api_sandbox
Loading
Loading