MINIFICPP-31 Added UpdateAttribute processor
[nifi-minifi-cpp.git] / libminifi / include / core / ProcessorNode.h
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
18 #ifndef LIBMINIFI_INCLUDE_PROCESSOR_PROCESSORNODE_H_
19 #define LIBMINIFI_INCLUDE_PROCESSOR_PROCESSORNODE_H_
20
21 #include "ConfigurableComponent.h"
22 #include "Connectable.h"
23 #include "Property.h"
24
25 namespace org {
26 namespace apache {
27 namespace nifi {
28 namespace minifi {
29 namespace core {
30
31 /**
32 * Processor node functions as a pass through to the implementing Connectables
33 * ProcessorNode can be used by itself or with a pass through object, in which case
34 * we need to function as a passthrough or not.
35 */
36 class ProcessorNode : public ConfigurableComponent, public Connectable {
37 public:
38 explicit ProcessorNode(const std::shared_ptr<Connectable> &processor);
39
40 explicit ProcessorNode(const ProcessorNode &other);
41
42 explicit ProcessorNode(const ProcessorNode &&other);
43
44 /**
45 * Get property using the provided name.
46 * @param name property name.
47 * @param value value passed in by reference
48 * @return result of getting property.
49 */
50 std::shared_ptr<Connectable> getProcessor() const {
51 return processor_;
52 }
53
54 void yield() {
55 processor_->yield();
56 }
57
58 /**
59 * Get property using the provided name.
60 * @param name property name.
61 * @param value value passed in by reference
62 * @return result of getting property.
63 */
64 bool getProperty(const std::string &name, std::string &value) {
65 const std::shared_ptr<ConfigurableComponent> processor_cast = std::dynamic_pointer_cast<ConfigurableComponent>(processor_);
66 if (nullptr != processor_cast)
67 return processor_cast->getProperty(name, value);
68 else {
69 return ConfigurableComponent::getProperty(name, value);
70 }
71 }
72 /**
73 * Sets the property using the provided name
74 * @param property name
75 * @param value property value.
76 * @return result of setting property.
77 */
78 bool setProperty(const std::string &name, std::string value) {
79 const std::shared_ptr<ConfigurableComponent> processor_cast = std::dynamic_pointer_cast<ConfigurableComponent>(processor_);
80 bool ret = ConfigurableComponent::setProperty(name, value);
81 if (nullptr != processor_cast)
82 ret = processor_cast->setProperty(name, value);
83
84 return ret;
85
86 }
87
88 /**
89 * Get dynamic property using the provided name.
90 * @param name property name.
91 * @param value value passed in by reference
92 * @return result of getting property.
93 */
94 bool getDynamicProperty(const std::string name, std::string &value) {
95 const auto &processor_cast = std::dynamic_pointer_cast<ConfigurableComponent>(processor_);
96 if (processor_cast) {
97 return processor_cast->getDynamicProperty(name, value);
98 } else {
99 return ConfigurableComponent::getDynamicProperty(name, value);
100 }
101 }
102
103 /**
104 * Sets the dynamic property using the provided name
105 * @param property name
106 * @param value property value.
107 * @return result of setting property.
108 */
109 bool setDynamicProperty(const std::string name, std::string value) {
110 const auto &processor_cast = std::dynamic_pointer_cast<ConfigurableComponent>(processor_);
111 auto ret = ConfigurableComponent::setDynamicProperty(name, value);
112
113 if (processor_cast) {
114 ret = processor_cast->setDynamicProperty(name, value);
115 }
116
117 return ret;
118 }
119
120 /**
121 * Gets list of dynamic property keys
122 * @param name property name.
123 * @param value value passed in by reference
124 * @return result of getting property.
125 */
126 std::vector<std::string> getDynamicPropertyKeys() {
127 const auto &processor_cast = std::dynamic_pointer_cast<ConfigurableComponent>(processor_);
128 if (processor_cast) {
129 return processor_cast->getDynamicPropertyKeys();
130 } else {
131 return ConfigurableComponent::getDynamicPropertyKeys();
132 }
133 }
134
135 /**
136 * Sets the property using the provided name
137 * @param property name
138 * @param value property value.
139 * @return whether property was set or not
140 */
141 bool setProperty(Property &prop, std::string value) {
142 const std::shared_ptr<ConfigurableComponent> processor_cast = std::dynamic_pointer_cast<ConfigurableComponent>(processor_);
143 bool ret = ConfigurableComponent::setProperty(prop, value);
144 if (nullptr != processor_cast)
145 ret = processor_cast->setProperty(prop, value);
146
147 return ret;
148 }
149
150 /**
151 * Sets supported properties for the ConfigurableComponent
152 * @param supported properties
153 * @return result of set operation.
154 */
155 bool setSupportedProperties(std::set<Property> properties) {
156 const std::shared_ptr<ConfigurableComponent> processor_cast = std::dynamic_pointer_cast<ConfigurableComponent>(processor_);
157 bool ret = ConfigurableComponent::setSupportedProperties(properties);
158 if (nullptr != processor_cast)
159 ret = processor_cast->setSupportedProperties(properties);
160
161 return ret;
162 }
163 /**
164 * Sets supported properties for the ConfigurableComponent
165 * @param supported properties
166 * @return result of set operation.
167 */
168
169 bool setAutoTerminatedRelationships(std::set<Relationship> relationships) {
170 return processor_->setAutoTerminatedRelationships(relationships);
171 }
172
173 bool isAutoTerminated(Relationship relationship) {
174 return processor_->isAutoTerminated(relationship);
175 }
176
177 bool setSupportedRelationships(std::set<Relationship> relationships) {
178 return processor_->setSupportedRelationships(relationships);
179 }
180
181 bool isSupportedRelationship(Relationship relationship) {
182 return processor_->isSupportedRelationship(relationship);
183 }
184
185 /**
186 * Set name.
187 * @param name
188 */
189 void setName(const std::string &name) {
190 Connectable::setName(name);
191 processor_->setName(name);
192 }
193
194 /**
195 * Set UUID in this instance
196 * @param uuid uuid to apply to the internal representation.
197 */
198 void setUUID(uuid_t uuid) {
199 Connectable::setUUID(uuid);
200 processor_->setUUID(uuid);
201 }
202
203 // Get Processor penalization period in MilliSecond
204 uint64_t getPenalizationPeriodMsec(void) {
205 return processor_->getPenalizationPeriodMsec();
206 }
207
208 /**
209 * Get outgoing connection based on relationship
210 * @return set of outgoing connections.
211 */
212 std::set<std::shared_ptr<Connectable>> getOutGoingConnections(std::string relationship) {
213 return processor_->getOutGoingConnections(relationship);
214 }
215
216 /**
217 * Get next incoming connection
218 * @return next incoming connection
219 */
220 std::shared_ptr<Connectable> getNextIncomingConnection() {
221 return processor_->getNextIncomingConnection();
222 }
223
224 /**
225 * @return true if incoming connections > 0
226 */
227 bool hasIncomingConnections() {
228 return processor_->hasIncomingConnections();
229 }
230
231 /**
232 * Returns the UUID through the provided object.
233 * @param uuid uuid struct to which we will copy the memory
234 * @return success of request
235 */
236 bool getUUID(uuid_t uuid) {
237 return processor_->getUUID(uuid);
238 }
239
240 unsigned const char *getUUID() {
241 return processor_->getUUID();
242 }
243 /**
244 * Return the UUID string
245 * @param constant reference to the UUID str
246 */
247 const std::string & getUUIDStr() const {
248 return processor_->getUUIDStr();
249 }
250
251 // Get Process Name
252 std::string getName() const {
253 return processor_->getName();
254 }
255
256 uint8_t getMaxConcurrentTasks() {
257 return processor_->getMaxConcurrentTasks();
258 }
259
260 void setMaxConcurrentTasks(const uint8_t tasks) {
261 processor_->setMaxConcurrentTasks(tasks);
262 }
263
264 virtual bool supportsDynamicProperties() {
265 return false;
266 }
267
268 virtual bool isRunning();
269
270 virtual bool isWorkAvailable();
271
272 virtual ~ProcessorNode();
273
274 protected:
275
276 virtual bool canEdit() {
277 return !processor_->isRunning();
278 }
279
280 /**
281 * internal connectable.
282 */
283 std::shared_ptr<Connectable> processor_;
284
285 }
286 ;
287
288 } /* namespace core */
289 } /* namespace minifi */
290 } /* namespace nifi */
291 } /* namespace apache */
292 } /* namespace org */
293
294 #endif /* LIBMINIFI_INCLUDE_PROCESSOR_PROCESSORNODE_H_ */