bejancsaba commented on code in PR #6434:
URL: https://github.com/apache/nifi/pull/6434#discussion_r977564811
##########
c2/c2-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/C2HttpClient.java:
##########
@@ -124,15 +130,38 @@ public Optional<byte[]> retrieveUpdateContent(String
flowUpdateUrl) {
public void acknowledgeOperation(C2OperationAck operationAck) {
logger.info("Acknowledging Operation [{}] C2 URL [{}]",
operationAck.getOperationId(), clientConfig.getC2AckUrl());
serializer.serialize(operationAck)
- .map(operationAckBody -> RequestBody.create(operationAckBody,
MEDIA_TYPE_APPLICATION_JSON))
+ .map(operationAckBody -> create(operationAckBody,
MEDIA_TYPE_APPLICATION_JSON))
.map(requestBody -> new
Request.Builder().post(requestBody).url(clientConfig.getC2AckUrl()).build())
.ifPresent(this::sendAck);
}
+ @Override
+ public Optional<String> uploadDebugBundle(String debugCallbackUrl, byte[]
debugBundle) {
+ Request request = new Request.Builder()
+ .url(debugCallbackUrl)
+ .post(new MultipartBody.Builder()
+ .setType(FORM)
+ .addFormDataPart(MULTIPART_FORM_FILE_FIELD_NAME,
DEBUG_BUNDLE_FILE_NAME, create(debugBundle, DEBUG_BUNDLE_MIME_TYPE))
+ .build())
+ .build();
+
+ logger.info("Uploading debug bundle to url={} size={}",
debugCallbackUrl, debugBundle.length);
Review Comment:
Super minor just for the sake of consistency sometimes url is logged just as
part of the text, sometimes is in brackets [] and sometimes is behind "=". I'm
pretty sure it is inconsistent outside this change as well just I saw these 3
patterns in this change. I'm ok with whatever approach so will leave that to
you.
##########
c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/operation/DebugOperationHandler.java:
##########
@@ -0,0 +1,257 @@
+/*
+ * 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.c2.client.service.operation;
+
+import static java.nio.file.Files.copy;
+import static java.nio.file.Files.createTempDirectory;
+import static java.nio.file.Files.deleteIfExists;
+import static java.nio.file.Files.lines;
+import static java.nio.file.Files.write;
+import static java.util.Optional.empty;
+import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Stream.concat;
+import static org.apache.commons.compress.utils.IOUtils.closeQuietly;
+import static org.apache.commons.lang3.StringUtils.EMPTY;
+import static org.apache.commons.lang3.StringUtils.isBlank;
+import static
org.apache.nifi.c2.protocol.api.C2OperationState.OperationState.FULLY_APPLIED;
+import static
org.apache.nifi.c2.protocol.api.C2OperationState.OperationState.NOT_APPLIED;
+import static org.apache.nifi.c2.protocol.api.OperandType.DEBUG;
+import static org.apache.nifi.c2.protocol.api.OperationType.TRANSFER;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
+import org.apache.nifi.c2.client.api.C2Client;
+import org.apache.nifi.c2.protocol.api.C2Operation;
+import org.apache.nifi.c2.protocol.api.C2OperationAck;
+import org.apache.nifi.c2.protocol.api.C2OperationState;
+import org.apache.nifi.c2.protocol.api.C2OperationState.OperationState;
+import org.apache.nifi.c2.protocol.api.OperandType;
+import org.apache.nifi.c2.protocol.api.OperationType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DebugOperationHandler implements C2OperationHandler {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(DebugOperationHandler.class);
+
+ private static final String C2_CALLBACK_URL_NOT_FOUND = "C2 Server
callback URL was not found in request";
+ private static final String SUCCESSFUL_UPLOAD = "Debug bundle was uploaded
successfully";
+ private static final String UNABLE_TO_CREATE_BUNDLE = "Unable to create
debug bundle";
+
+ static final String TARGET_ARG = "target";
+ static final String NEW_LINE = "\n";
+
+ private final C2Client c2Client;
+ private final String configDir;
+ private final String logDir;
+ private final Predicate<String> contentFilter;
+
+ private DebugOperationHandler(C2Client c2Client, String configDir, String
logDir, Predicate<String> contentFilter) {
+ this.c2Client = c2Client;
+ this.configDir = configDir;
+ this.logDir = logDir;
+ this.contentFilter = contentFilter;
+ }
+
+ public static DebugOperationHandler create(C2Client c2Client, String
configDir, String logDir, Predicate<String> contentFilter) {
+ if (c2Client == null) {
+ throw new IllegalArgumentException("C2Client should not be null");
+ }
+ if (isBlank(configDir)) {
+ throw new IllegalArgumentException("configDir should not be not
null or empty");
+ }
+ if (isBlank(logDir)) {
+ throw new IllegalArgumentException("logDir should not be not null
or empty");
+ }
+ if (contentFilter == null) {
+ throw new IllegalArgumentException("Exclude sensitive filter
should not be null");
+ }
+
+ return new DebugOperationHandler(c2Client, configDir, logDir,
contentFilter);
+ }
+
+ @Override
+ public OperationType getOperationType() {
+ return TRANSFER;
+ }
+
+ @Override
+ public OperandType getOperandType() {
+ return DEBUG;
+ }
+
+ @Override
+ public C2OperationAck handle(C2Operation operation) {
+ Function<C2OperationState, C2OperationAck> operationAckCreate =
operationAck(operation);
Review Comment:
Is there a specific need for this function based approach? Extending the
function to get 2 parameters looks to be sufficient and simpler. What do you
think? Or maybe there is something that I'm missing?
##########
c2/c2-client-bundle/c2-client-api/src/main/java/org/apache/nifi/c2/client/api/C2Client.java:
##########
@@ -35,7 +35,7 @@ public interface C2Client {
Optional<C2HeartbeatResponse> publishHeartbeat(C2Heartbeat heartbeat);
/**
- * Retrive the content of the new flow from the C2 Server
+ * Retrieve the content of the new flow from the C2 Server
Review Comment:
Thanks
##########
c2/c2-client-bundle/c2-client-service/pom.xml:
##########
@@ -43,5 +43,10 @@ limitations under the License.
<artifactId>c2-client-http</artifactId>
<version>1.18.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ <version>1.21</version>
Review Comment:
Please externalise the version to the main nifi pom so everything is in one
place.
--
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]