markobean commented on code in PR #9685: URL: https://github.com/apache/nifi/pull/9685#discussion_r1943254652
########## nifi-extension-bundles/nifi-standard-bundle/nifi-standard-rules/src/main/java/org/apache/nifi/flowanalysis/rules/RestrictLoadBalancing.java: ########## @@ -0,0 +1,266 @@ +/* + * 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. + */ +package org.apache.nifi.flowanalysis.rules; + +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.controller.queue.LoadBalanceCompression; +import org.apache.nifi.controller.queue.LoadBalanceStrategy; +import org.apache.nifi.flow.VersionedProcessGroup; +import org.apache.nifi.flowanalysis.AbstractFlowAnalysisRule; +import org.apache.nifi.flowanalysis.FlowAnalysisRuleContext; +import org.apache.nifi.flowanalysis.GroupAnalysisResult; +import org.apache.nifi.flowanalysis.rules.util.ConnectionViolation; +import org.apache.nifi.flowanalysis.rules.util.FlowAnalysisRuleUtils; +import org.apache.nifi.flowanalysis.rules.util.ViolationType; +import org.apache.nifi.processor.util.StandardValidators; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@Tags({"connection", "load", "balance", "strategy", "compression"}) +@CapabilityDescription("This rule generates a violation when the Load Balance Strategy setting of a connection is set to a strategy which is not allowed. " + + "This rule may be useful for preventing certain strategy types or load-balancing compression. It may be implemented to assist in locating " + + "all connections which have load balancing enabled.") +public class RestrictLoadBalancing extends AbstractFlowAnalysisRule { + + static final String CONFIGURE_STRATEGY_ERROR_MESSAGE = "at least one load balance strategy property must be set to 'true'"; + static final String COMPRESSION_CONFIGURATION_ERROR_MESSAGE = + "there is no compression configuration for content only without including attributes. If content compression is allowed, attribute compression must also be allowed."; + + public static final PropertyDescriptor ALLOW_DO_NOT_LOAD_BALANCE = new PropertyDescriptor.Builder() + .name("Allow 'Do not load balance' Strategy") + .description("If set to true, connections may be configured with the load balancing strategy of 'Do not load balance'. This is the default " + + "setting for new connections.") + .required(true) + .allowableValues("true", "false") + .defaultValue("true") + .addValidator(StandardValidators.BOOLEAN_VALIDATOR) + .build(); + + public static final PropertyDescriptor ALLOW_PARTITION = new PropertyDescriptor.Builder() + .name("Allow 'Partition by attribute' Strategy") + .description("If set to true, connections may be configured with the load balancing strategy of 'Partition by attribute'.") + .required(true) + .allowableValues("true", "false") + .defaultValue("false") + .addValidator(StandardValidators.BOOLEAN_VALIDATOR) + .build(); + + public static final PropertyDescriptor ALLOW_ROUND_ROBIN = new PropertyDescriptor.Builder() + .name("Allow 'Round robin' Strategy") + .description("If set to true, connections may be configured with the load balancing strategy of 'Round robin'.") + .required(true) + .allowableValues("true", "false") + .defaultValue("false") + .addValidator(StandardValidators.BOOLEAN_VALIDATOR) + .build(); + + public static final PropertyDescriptor ALLOW_SINGLE_NODE = new PropertyDescriptor.Builder() + .name("Allow 'Single node' Strategy") + .description("If set to true, connections may be configured with the load balancing strategy of 'Single node'.") + .required(true) + .allowableValues("true", "false") + .defaultValue("false") + .addValidator(StandardValidators.BOOLEAN_VALIDATOR) + .build(); Review Comment: Refactor created a property `Load Balancing Policy`. It is the only property for the rule if set for `Disallowed`. If set for `Allowed`, additional properties for load balancing strategies and compression are available. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
