markap14 commented on a change in pull request #3351: NIFI-2933 Remote input/output ports at any PG URL: https://github.com/apache/nifi/pull/3351#discussion_r263587424
########## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/main/java/org/apache/nifi/remote/StandardPublicPort.java ########## @@ -0,0 +1,544 @@ +/* + * 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.authorization.AuthorizationResult; +import org.apache.nifi.authorization.AuthorizationResult.Result; +import org.apache.nifi.authorization.Authorizer; +import org.apache.nifi.authorization.RequestAction; +import org.apache.nifi.authorization.resource.Authorizable; +import org.apache.nifi.authorization.resource.DataTransferAuthorizable; +import org.apache.nifi.authorization.user.NiFiUser; +import org.apache.nifi.authorization.user.StandardNiFiUser.Builder; +import org.apache.nifi.authorization.util.IdentityMapping; +import org.apache.nifi.authorization.util.IdentityMappingUtil; +import org.apache.nifi.authorization.util.UserGroupUtil; +import org.apache.nifi.connectable.ConnectableType; +import org.apache.nifi.connectable.Port; +import org.apache.nifi.controller.ProcessScheduler; +import org.apache.nifi.events.BulletinFactory; +import org.apache.nifi.events.EventReporter; +import org.apache.nifi.groups.ProcessGroup; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.ProcessSessionFactory; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.remote.codec.FlowFileCodec; +import org.apache.nifi.remote.exception.BadRequestException; +import org.apache.nifi.remote.exception.NotAuthorizedException; +import org.apache.nifi.remote.exception.ProtocolException; +import org.apache.nifi.remote.exception.RequestExpiredException; +import org.apache.nifi.remote.exception.TransmissionDisabledException; +import org.apache.nifi.remote.protocol.CommunicationsSession; +import org.apache.nifi.remote.protocol.ServerProtocol; +import org.apache.nifi.reporting.BulletinRepository; +import org.apache.nifi.reporting.ComponentType; +import org.apache.nifi.reporting.Severity; +import org.apache.nifi.util.NiFiProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.SocketTimeoutException; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import static java.util.Objects.requireNonNull; + +public class StandardPublicPort implements PublicPort { + + private static final String CATEGORY = "Site to Site"; + + private static final Logger logger = LoggerFactory.getLogger(StandardPublicPort.class); + + private final Port port; + private final AtomicReference<Set<String>> groupAccessControl = new AtomicReference<>(new HashSet<>()); + private final AtomicReference<Set<String>> userAccessControl = new AtomicReference<>(new HashSet<>()); + private final boolean secure; + private final Authorizer authorizer; + private final List<IdentityMapping> identityMappings; + + private final EventReporter eventReporter; + private final ProcessScheduler scheduler; + + private final BlockingQueue<FlowFileRequest> requestQueue = new ArrayBlockingQueue<>(1000); + + private final Set<FlowFileRequest> activeRequests = new HashSet<>(); + private final Lock requestLock = new ReentrantLock(); + private boolean shutdown = false; // guarded by requestLock + + public StandardPublicPort(final Port port, final TransferDirection direction, final Authorizer authorizer, + final BulletinRepository bulletinRepository, final ProcessScheduler scheduler, final boolean secure, + final NiFiProperties nifiProperties) { + + this.port = port; + this.authorizer = authorizer; + this.secure = secure; + this.identityMappings = IdentityMappingUtil.getIdentityMappings(nifiProperties); Review comment: It looks like this is the only place that `NiFiProperties` is used. I would recommend passing in a `List<IdentityMapping>` instead of passing in `NiFiProperties`. This improves testability and narrows the scope where we pass around NiFiProperties, which I personally think already is overly used. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
