| // 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 <memory> | |
| #include <string> | |
| #include <utility> | |
| #include <vector> | |
| #include "OPCCommon.h" | |
| #include "BaseOPCProcessor.h" | |
| #include "minifi-cpp/FlowFileRecord.h" | |
| #include "core/ProcessSession.h" | |
| #include "minifi-cpp/core/Property.h" | |
| #include "core/PropertyDefinitionBuilder.h" | |
| #include "minifi-cpp/core/PropertyValidator.h" | |
| #include "minifi-cpp/controllers/SSLContextServiceInterface.h" | |
| #include "core/logging/LoggerFactory.h" | |
| #include "utils/ArrayUtils.h" | |
| #include "utils/Id.h" | |
| #include "utils/expected.h" | |
| namespace org::apache::nifi::minifi::processors { | |
| class PutOPCProcessor final : public BaseOPCProcessor { | |
| public: | |
| EXTENSIONAPI static constexpr const char* Description = "Creates/updates OPC nodes"; | |
| EXTENSIONAPI static constexpr auto ParentNodeIDType = core::PropertyDefinitionBuilder<magic_enum::enum_count<opc::OPCNodeIDType>()>::createProperty("Parent node ID type") | |
| .withDescription("Specifies the type of the provided node ID. Only required when a new node is created.") | |
| .withAllowedValues(magic_enum::enum_names<opc::OPCNodeIDType>()) | |
| .build(); | |
| EXTENSIONAPI static constexpr auto ParentNodeID = core::PropertyDefinitionBuilder<>::createProperty("Parent node ID") | |
| .withDescription("Specifies the ID of the root node to traverse. Only required when a new node is created.") | |
| .build(); | |
| EXTENSIONAPI static constexpr auto ParentNameSpaceIndex = core::PropertyDefinitionBuilder<>::createProperty("Parent node namespace index") | |
| .withDescription("The index of the namespace of the parent node. Only used when a new node is created.") | |
| .withValidator(core::StandardPropertyValidators::UNSIGNED_INTEGER_VALIDATOR) | |
| .withDefaultValue("0") | |
| .build(); | |
| EXTENSIONAPI static constexpr auto ValueType = core::PropertyDefinitionBuilder<magic_enum::enum_count<opc::OPCNodeDataType>()>::createProperty("Value type") | |
| .withDescription("Set the OPC value type of the created nodes") | |
| .withAllowedValues(magic_enum::enum_names<opc::OPCNodeDataType>()) | |
| .isRequired(true) | |
| .build(); | |
| EXTENSIONAPI static constexpr auto PathReferenceTypes = core::PropertyDefinitionBuilder<>::createProperty("Path reference types") | |
| .withDescription("Specify the reference types between nodes in the parent node path if Parent node ID type is Path. If not provided, all reference types are assumed to be Organizes. " | |
| "The format is 'referenceType1/referenceType2/.../referenceTypeN' and the supported reference types are Organizes, HasComponent, HasProperty, and HasSubtype. " | |
| "Subtypes of the specified reference types are also matched.") | |
| .build(); | |
| EXTENSIONAPI static constexpr auto TargetNodeIDType = core::PropertyDefinitionBuilder<>::createProperty("Target node ID type") | |
| .withDescription("ID type of target node. Allowed values are: Int, String, Guid, Path. Path can only be used to update an existing node: " | |
| "if the path does not resolve to exactly one existing node, the flow file is routed to failure.") | |
| .supportsExpressionLanguage(true) | |
| .isRequired(true) | |
| .build(); | |
| EXTENSIONAPI static constexpr auto TargetNodeID = core::PropertyDefinitionBuilder<>::createProperty("Target node ID") | |
| .withDescription("ID of target node.") | |
| .supportsExpressionLanguage(true) | |
| .isRequired(true) | |
| .build(); | |
| EXTENSIONAPI static constexpr auto TargetNodePathReferenceTypes = core::PropertyDefinitionBuilder<>::createProperty("Target node path reference types") | |
| .withDescription("Specify the reference types between nodes in the target node path if Target node ID type is Path. If not provided, all reference types are assumed to be Organizes. " | |
| "The format is 'referenceType1/referenceType2/.../referenceTypeN' and the supported reference types are Organizes, HasComponent, HasProperty, and HasSubtype. " | |
| "Subtypes of the specified reference types are also matched.") | |
| .supportsExpressionLanguage(true) | |
| .build(); | |
| EXTENSIONAPI static constexpr auto TargetNodeBrowseName = core::PropertyDefinitionBuilder<>::createProperty("Target node browse name") | |
| .withDescription("Browse name of target node. Only used when new node is created.") | |
| .supportsExpressionLanguage(true) | |
| .build(); | |
| EXTENSIONAPI static constexpr auto TargetNodeNameSpaceIndex = core::PropertyDefinitionBuilder<>::createProperty("Target node namespace index") | |
| .withDescription("The index of the namespace of the target node.") | |
| .supportsExpressionLanguage(true) | |
| .withDefaultValue("0") | |
| .isRequired(true) | |
| .build(); | |
| EXTENSIONAPI static constexpr auto CreateNodeReferenceType = core::PropertyDefinitionBuilder<4>::createProperty("Create node reference type") | |
| .withDescription("Reference type used when a new node is created.") | |
| .withAllowedValues({"Organizes", "HasComponent", "HasProperty", "HasSubtype"}) | |
| .withDefaultValue("HasComponent") | |
| .build(); | |
| EXTENSIONAPI static constexpr auto Properties = utils::array_cat(BaseOPCProcessor::Properties, std::to_array<core::PropertyReference>({ | |
| PathReferenceTypes, | |
| ParentNodeIDType, | |
| ParentNodeID, | |
| ParentNameSpaceIndex, | |
| ValueType, | |
| TargetNodeIDType, | |
| TargetNodeID, | |
| TargetNodePathReferenceTypes, | |
| TargetNodeBrowseName, | |
| TargetNodeNameSpaceIndex, | |
| CreateNodeReferenceType | |
| })); | |
| EXTENSIONAPI static constexpr auto Success = core::RelationshipDefinition{"success", "Successfully put OPC-UA node"}; | |
| EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure", "Failed to put OPC-UA node"}; | |
| EXTENSIONAPI static constexpr auto Relationships = std::array{Success, Failure}; | |
| EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false; | |
| EXTENSIONAPI static constexpr bool SupportsDynamicRelationships = false; | |
| EXTENSIONAPI static constexpr core::annotation::Input InputRequirement = core::annotation::Input::INPUT_REQUIRED; | |
| EXTENSIONAPI static constexpr bool IsSingleThreaded = true; | |
| ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS | |
| using BaseOPCProcessor::BaseOPCProcessor; | |
| void onSchedule(core::ProcessContext& context, core::ProcessSessionFactory& session_factory) override; | |
| void onTrigger(core::ProcessContext& context, core::ProcessSession& session) override; | |
| void initialize() override; | |
| private: | |
| std::expected<std::pair<bool, opc::NodeId>, std::string> configureTargetNode(core::ProcessContext& context, core::FlowFile& flow_file) const; | |
| std::expected<std::pair<bool, opc::NodeId>, std::string> resolveTargetNodePath(core::ProcessContext& context, core::FlowFile& flow_file, | |
| const std::string& target_path, UA_UInt16 namespace_idx) const; | |
| void updateNode(const UA_NodeId& target_node, const std::string& contentstr, core::ProcessSession& session, const std::shared_ptr<core::FlowFile>& flow_file) const; | |
| void createNode(const UA_NodeId& parent_node, const UA_NodeId& target_node, const std::string& contentstr, core::ProcessContext& context, core::ProcessSession& session, | |
| const std::shared_ptr<core::FlowFile>& flow_file) const; | |
| opc::OPCNodeDataType node_data_type_{}; | |
| UA_UInt32 create_node_reference_type_ = UA_NS0ID_HASCOMPONENT; | |
| bool parent_node_defined_ = false; | |
| }; | |
| } // namespace org::apache::nifi::minifi::processors |