From issues-return-85996-archive-asf-public=cust-asf.ponee.io@nifi.apache.org Tue Oct 1 13:25:52 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id C8A13180608 for ; Tue, 1 Oct 2019 15:25:51 +0200 (CEST) Received: (qmail 62938 invoked by uid 500); 1 Oct 2019 13:25:51 -0000 Mailing-List: contact issues-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list issues@nifi.apache.org Received: (qmail 62929 invoked by uid 99); 1 Oct 2019 13:25:51 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Oct 2019 13:25:51 +0000 From: GitBox To: issues@nifi.apache.org Subject: [GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #635: MINIFICPP-819 - OPC Unified Architecture Support Message-ID: <156993635109.16540.8465352566917699713.gitbox@gitbox.apache.org> Date: Tue, 01 Oct 2019 13:25:51 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit arpadboda commented on a change in pull request #635: MINIFICPP-819 - OPC Unified Architecture Support URL: https://github.com/apache/nifi-minifi-cpp/pull/635#discussion_r330055009 ########## File path: extensions/opc/src/fetchopc.cpp ########## @@ -0,0 +1,239 @@ +/** + * FetchOPC class definition + * + * 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 +#include +#include +#include +#include +#include + +#include "opc.h" +#include "fetchopc.h" +#include "utils/ByteArrayCallback.h" +#include "FlowFileRecord.h" +#include "core/Processor.h" +#include "core/ProcessSession.h" +#include "core/Core.h" +#include "core/Property.h" +#include "core/Resource.h" +#include "controllers/SSLContextService.h" +#include "core/logging/LoggerConfiguration.h" +#include "utils/Id.h" +#include "utils/StringUtils.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace processors { + core::Property FetchOPCProcessor::NodeID( + core::PropertyBuilder::createProperty("Node ID") + ->withDescription("Specifies the ID of the root node to traverse") + ->isRequired(true)->build()); + + + core::Property FetchOPCProcessor::NodeIDType( + core::PropertyBuilder::createProperty("Node ID type") + ->withDescription("Specifies the type of the provided node ID") + ->isRequired(true) + ->withAllowableValues({"Path", "Int", "String"})->build()); + + core::Property FetchOPCProcessor::NameSpaceIndex( + core::PropertyBuilder::createProperty("Namespace index") + ->withDescription("The index of the namespace. Used only if node ID type is not path.") + ->withDefaultValue(0)->build()); + + core::Relationship FetchOPCProcessor::Success("success", "Successfully retrieved OPC-UA nodes"); + core::Relationship FetchOPCProcessor::Failure("failure", "Retrieved OPC-UA nodes where value cannot be extracted (only if enabled)"); + + + void FetchOPCProcessor::initialize() { + //BaseOPCProcessor::initialize(); + + // Set the supported properties + std::set fetchOPCProperties = {OPCServerEndPoint, NodeID, NodeIDType, NameSpaceIndex}; + std::set baseOPCProperties = BaseOPCProcessor::getSupportedProperties(); + fetchOPCProperties.insert(baseOPCProperties.begin(), baseOPCProperties.end()); + setSupportedProperties(fetchOPCProperties); + + // Set the supported relationships + setSupportedRelationships({Success, Failure}); + } + + void FetchOPCProcessor::onSchedule(const std::shared_ptr &context, const std::shared_ptr &factory) { + logger_->log_trace("FetchOPCProcessor::onSchedule"); + + translatedNodeIDs_.clear(); // Path might has changed during restart + + BaseOPCProcessor::onSchedule(context, factory); + + if(!configOK_) { + return; + } + + configOK_ = false; + + std::string value; + context->getProperty(NodeID.getName(), nodeID_); + context->getProperty(NodeIDType.getName(), value); + + if (value == "String") { + idType_ = opc::OPCNodeIDType::String; + } else if (value == "Int") { + idType_ = opc::OPCNodeIDType::Int; + } else if (value == "Path") { + idType_ = opc::OPCNodeIDType::Path; + } else { + // Where have our validators gone? + logger_->log_error("%s is not a valid node ID type!", value.c_str()); + } + + if(idType_ == opc::OPCNodeIDType::Int) { + try { + int t = std::stoi(nodeID_); + } catch(...) { + logger_->log_error("%s cannot be used as an int type node ID", nodeID_.c_str()); + return; + } + } + if(idType_ != opc::OPCNodeIDType::Path) { + if(!context->getProperty(NameSpaceIndex.getName(), nameSpaceIdx_)) { + logger_->log_error("%s is mandatory in case %s is not Path", NameSpaceIndex.getName().c_str(), NodeIDType.getName().c_str()); + return; + } + } + + configOK_ = true; + } + + void FetchOPCProcessor::onTrigger(const std::shared_ptr &context, const std::shared_ptr &session){ + if(!configOK_) { + logger_->log_error("This processor was not configured properly, yielding. Please check for previous errors in the logs!"); + yield(); + return; + } + + logger_->log_trace("FetchOPCProcessor::onTrigger"); + + std::unique_lock lock(onTriggerMutex_, std::try_to_lock); + if(!lock.owns_lock()){ + logger_->log_warn("processor was triggered before previous listing finished, configuration should be revised!"); + return; + } + + nodesFound_ = 0; + variablesFound_ = 0; + + if(!opc::isConnected(connection_)) { Review comment: Added, thanks! ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services