[ 
https://issues.apache.org/jira/browse/NIFI-4932?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16419721#comment-16419721
 ] 

ASF GitHub Bot commented on NIFI-4932:
--------------------------------------

Github user mcgilman commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2510#discussion_r178174688
  
    --- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/main/java/org/apache/nifi/remote/PeerDescriptionModifier.java
 ---
    @@ -0,0 +1,165 @@
    +/*
    + * 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.remote;
    +
    +import org.apache.nifi.attribute.expression.language.PreparedQuery;
    +import org.apache.nifi.attribute.expression.language.Query;
    +import org.apache.nifi.remote.protocol.SiteToSiteTransportProtocol;
    +import org.apache.nifi.util.NiFiProperties;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.List;
    +import java.util.Map;
    +import java.util.stream.Collectors;
    +
    +import static java.lang.String.format;
    +import static org.apache.commons.lang3.StringUtils.isBlank;
    +
    +public class PeerDescriptionModifier {
    +
    +    private static final Logger logger = 
LoggerFactory.getLogger(PeerDescriptionModifier.class);
    +
    +    public enum RequestType {
    +        SiteToSiteDetail,
    +        Peers
    +    }
    +
    +    private static class Route {
    +        private String name;
    +        private SiteToSiteTransportProtocol protocol;
    +        private PreparedQuery predicate;
    +        private PreparedQuery hostname;
    +        private PreparedQuery port;
    +        private PreparedQuery secure;
    +
    +        private Route validate() {
    +            if (hostname == null) {
    +                throw new IllegalArgumentException(
    +                        format("Found an invalid Site-to-Site route 
definition [%s] 'hostname' is not specified.", name));
    +            }
    +            if (port == null) {
    +                throw new IllegalArgumentException(
    +                        format("Found an invalid Site-to-Site route 
definition [%s] 'port' is not specified.", name));
    +            }
    +            return this;
    +        }
    +
    +        private PeerDescription getTarget(final Map<String, String> 
variables) {
    +            final String targetHostName = 
hostname.evaluateExpressions(variables, null);
    +            if (isBlank(targetHostName)) {
    +                throw new IllegalStateException("Target hostname was not 
resolved for the route definition " + name);
    +            }
    +
    +            final String targetPortStr = 
port.evaluateExpressions(variables, null);
    +            if (isBlank(targetPortStr)) {
    +                throw new IllegalStateException("Target port was not 
resolved for the route definition " + name);
    +            }
    +
    +            final String targetIsSecure = secure == null ? null : 
secure.evaluateExpressions(variables, null);
    +            return new PeerDescription(targetHostName, 
Integer.valueOf(targetPortStr), Boolean.valueOf(targetIsSecure));
    +        }
    +    }
    +
    +    private Map<SiteToSiteTransportProtocol, List<Route>> routes;
    +
    +
    +    private static final String PROPERTY_PREFIX = "nifi.remote.route.";
    +
    +    public PeerDescriptionModifier(final NiFiProperties properties) {
    +        final Map<String, List<String>> routeDefinitions = 
properties.getPropertyKeys().stream()
    +                .filter(propertyKey -> 
propertyKey.startsWith(PROPERTY_PREFIX))
    +                .collect(Collectors.groupingBy(propertyKey -> 
propertyKey.substring(PROPERTY_PREFIX.length(), propertyKey.lastIndexOf('.'))));
    +
    +        routes = routeDefinitions.entrySet().stream().map(routeDefinition 
-> {
    +            final Route route = new Route();
    +            // E.g. raw.example1, http.example2
    +            final String[] protocolAndRoutingName = 
routeDefinition.getKey().split("\\.");
    +            route.protocol = 
SiteToSiteTransportProtocol.valueOf(protocolAndRoutingName[0].toUpperCase());
    +            route.name = protocolAndRoutingName[1];
    +            routeDefinition.getValue().forEach(propertyKey -> {
    +                final String routingConfigName = 
propertyKey.substring(propertyKey.lastIndexOf('.') + 1);
    --- End diff --
    
    I believe we should still better handle the property parse. I indirectly 
mentioned this in the last review with my comment to IndexOutOfBoundsException. 
Sorry if that wasn't clear previously. If a user misconfigures their properties 
the error isn't helpful:
    
    
    > Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    >   at 
org.apache.nifi.remote.PeerDescriptionModifier.lambda$new$4(PeerDescriptionModifier.java:93)
    >   at 
java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    >   at 
java.util.HashMap$EntrySpliterator.forEachRemaining(HashMap.java:1683)
    
    There is another `substring` method above that is likely susceptible to the 
same issue. 


> Enable S2S work behind a Reverse Proxy
> --------------------------------------
>
>                 Key: NIFI-4932
>                 URL: https://issues.apache.org/jira/browse/NIFI-4932
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Core Framework
>            Reporter: Koji Kawamura
>            Assignee: Koji Kawamura
>            Priority: Major
>
> Currently, NiFi UI and REST API work through a reverse proxy, but NiFi 
> Site-to-Site does not. The core issue is how a NiFi node introduce remote 
> peers to Site-to-Site clients. NiFi should provide more flexible 
> configuration so that user can define remote Site-to-Site endpoints those can 
> work for both routes, through a reverse proxy, and directly.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to