arpadboda commented on a change in pull request #489: MINIFICPP-740: Add ability to run NiFi processors from Java and Python URL: https://github.com/apache/nifi-minifi-cpp/pull/489#discussion_r259895000
########## File path: extensions/jni/ExecuteJavaProcessor.cpp ########## @@ -0,0 +1,221 @@ +/** + * + * 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 "ExecuteJavaProcessor.h" + +#include <regex> +#include <uuid/uuid.h> +#include <memory> +#include <algorithm> +#include <cctype> +#include <cstdint> +#include <cstring> +#include <iostream> +#include <iterator> +#include <map> +#include <set> +#include <string> +#include <utility> +#include <vector> + +#include "core/FlowFile.h" +#include "core/logging/Logger.h" +#include "core/ProcessContext.h" +#include "core/Relationship.h" +#include "ResourceClaim.h" +#include "utils/StringUtils.h" +#include "utils/ByteArrayCallback.h" +#include "jvm/JniMethod.h" +#include "jvm/JniLogger.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace jni { +namespace processors { + +core::Property ExecuteJavaProcessor::JVMControllerService( + core::PropertyBuilder::createProperty("JVM Controller Service")->withDescription("Name of controller service defined within this flow")->isRequired(false)->withDefaultValue<std::string>("")->build()); +core::Property ExecuteJavaProcessor::NiFiProcessor( + core::PropertyBuilder::createProperty("NiFi Processor")->withDescription("Name of NiFi processor to load and run")->isRequired(true)->withDefaultValue<std::string>("")->build()); + +const char *ExecuteJavaProcessor::ProcessorName = "ExecuteJavaClass"; + +core::Relationship ExecuteJavaProcessor::Success("success", "All files are routed to success"); +void ExecuteJavaProcessor::initialize() { + logger_->log_info("Initializing ExecuteJavaClass"); + // Set the supported properties + std::set<core::Property> properties; + properties.insert(JVMControllerService); + properties.insert(NiFiProcessor); + setSupportedProperties(properties); + setAcceptAllProperties(); + // Set the supported relationships + std::set<core::Relationship> relationships; + relationships.insert(Success); + setSupportedRelationships(relationships); +} + +void ExecuteJavaProcessor::onSchedule(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSessionFactory> &sessionFactory) { + std::string controller_service_name; + if (getProperty(JVMControllerService.getName(), controller_service_name)) { + auto cs = context->getControllerService(controller_service_name); + if (cs == nullptr) { + auto serv_cs = JVMLoader::getInstance()->getBaseServicer(); + java_servicer_ = std::static_pointer_cast<controllers::JavaControllerService>(serv_cs); + if (serv_cs == nullptr) + throw std::runtime_error("Could not load controller service"); + } else { + java_servicer_ = std::static_pointer_cast<controllers::JavaControllerService>(cs); + } + + } else { + auto serv_cs = JVMLoader::getInstance()->getBaseServicer(); + java_servicer_ = std::static_pointer_cast<controllers::JavaControllerService>(serv_cs); + if (serv_cs == nullptr) + throw std::runtime_error("Could not load controller service"); + } + + if (!getProperty(NiFiProcessor.getName(), class_name_)) { + throw std::runtime_error("NiFi Processor must be defined"); + } + + nifi_logger_ = logging::LoggerFactory<ExecuteJavaProcessor>::getAliasedLogger(class_name_); + + jni_logger_ref_.logger_reference_ = nifi_logger_; + + std::string dir_name_; Review comment: This seems to be unreferenced. (Guess it's just left) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
