exceptionfactory commented on code in PR #11587: URL: https://github.com/apache/nifi/pull/11587#discussion_r3847560537
########## nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/endpoints/ConnectorPurgeRequestEndpointMerger.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.cluster.coordination.http.endpoints; + +import org.apache.nifi.cluster.manager.NodeResponse; +import org.apache.nifi.cluster.protocol.NodeIdentifier; +import org.apache.nifi.web.api.dto.DropRequestDTO; +import org.apache.nifi.web.api.entity.DropRequestEntity; + +import java.net.URI; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +public class ConnectorPurgeRequestEndpointMerger extends AbstractSingleDTOEndpoint<DropRequestEntity, DropRequestDTO> { + private static final int TOTAL_PERCENT_COMPLETED = 100; + private static final Pattern CONNECTOR_PURGE_REQUESTS_URI = Pattern.compile("/nifi-api/connectors/[a-f0-9\\-]{36}/purge-requests"); + private static final Pattern CONNECTOR_PURGE_REQUEST_URI = Pattern.compile("/nifi-api/connectors/[a-f0-9\\-]{36}/purge-requests/[a-f0-9\\-]{36}"); + + @Override + public boolean canHandle(final URI uri, final String method) { + final String path = uri.getPath(); + if ("POST".equalsIgnoreCase(method)) { + return CONNECTOR_PURGE_REQUESTS_URI.matcher(path).matches(); + } + + return ("GET".equalsIgnoreCase(method) || "DELETE".equalsIgnoreCase(method)) + && CONNECTOR_PURGE_REQUEST_URI.matcher(path).matches(); + } + + @Override + protected Class<DropRequestEntity> getEntityClass() { + return DropRequestEntity.class; + } + + @Override + protected DropRequestDTO getDto(final DropRequestEntity entity) { + return entity.getDropRequest(); + } + + @Override + protected void mergeResponses(final DropRequestDTO clientDto, final Map<NodeIdentifier, DropRequestDTO> dtoMap, + final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) { + final Set<String> failureReasons = new LinkedHashSet<>(); + boolean allFinished = true; + int percentCompleted = TOTAL_PERCENT_COMPLETED; + + for (final DropRequestDTO nodeDto : dtoMap.values()) { + if (nodeDto.getFailureReason() != null) { + failureReasons.add(nodeDto.getFailureReason()); + } + + allFinished &= nodeDto.isFinished(); + percentCompleted = Math.min(percentCompleted, nodeDto.getPercentCompleted()); + } + + if (!failureReasons.isEmpty()) { Review Comment: For readability, I recommend flipping the conditional blocks so that it reads as `if (failureReasons.isEmpty()) { ... } else { ... }` ########## nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/StandardHttpResponseMapperTest.java: ########## @@ -0,0 +1,46 @@ +/* + * 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.cluster.coordination.http; + +import org.apache.nifi.util.NiFiProperties; +import org.junit.jupiter.api.Test; + +import java.net.URI; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class StandardHttpResponseMapperTest { Review Comment: That's a fair addition. In that case, I recommend removing the second `Unsupported` method, or limiting it to one URI, since any number of other URLs would be unsupported. -- 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]
