diff --git a/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java b/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java index 03183ac3009e..b508a9dc0d85 100644 --- a/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java +++ b/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java @@ -1547,17 +1547,16 @@ public BootstrapStateHandler.Lock getBootstrapStateLock() { return lock; } - public String pngPrintMutableGraph(String fileName, GraphType graphType) + public void pngPrintMutableGraph(String filePath, GraphType graphType) throws IOException { - Objects.requireNonNull(fileName, "Image file name is required."); + Objects.requireNonNull(filePath, "Image file path is required."); Objects.requireNonNull(graphType, "Graph type is required."); PrintableGraph graph; synchronized (this) { - graph = new PrintableGraph(forwardCompactionDAG, graphType); + graph = new PrintableGraph(backwardCompactionDAG, graphType); } - graph.generateImage(fileName); - return fileName; + graph.generateImage(filePath); } } diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java index 6453b2b88afe..cceb8a9040e7 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java @@ -595,14 +595,14 @@ public Iterator listSnapshot( /** * Create an image of the current compaction log DAG in the OM. - * @param fileName name of the image file. - * @param graphType type of node name to use in the graph image. - * @return path of the image file. - * @throws IOException + * @param fileNamePrefix file name prefix of the image file. + * @param graphType type of node name to use in the graph image. + * @return message which tells the image name, parent dir and OM leader + * node information. */ - public String printCompactionLogDag(String fileName, + public String printCompactionLogDag(String fileNamePrefix, String graphType) throws IOException { - return proxy.printCompactionLogDag(fileName, graphType); + return proxy.printCompactionLogDag(fileNamePrefix, graphType); } /** diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/protocol/ClientProtocol.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/protocol/ClientProtocol.java index f721eba5e4bc..16d75f131778 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/protocol/ClientProtocol.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/protocol/ClientProtocol.java @@ -1047,12 +1047,12 @@ void deleteSnapshot(String volumeName, /** * Create an image of the current compaction log DAG in the OM. - * @param fileName name of the image file. - * @param graphType type of node name to use in the graph image. - * @return path of the image file. - * @throws IOException + * @param fileNamePrefix file name prefix of the image file. + * @param graphType type of node name to use in the graph image. + * @return message which tells the image name, parent dir and OM leader + * node information. */ - String printCompactionLogDag(String fileName, String graphType) + String printCompactionLogDag(String fileNamePrefix, String graphType) throws IOException; /** diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java index 5b18f4727514..b2038c1a16ae 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java @@ -989,15 +989,15 @@ public void deleteSnapshot(String volumeName, /** * Create an image of the current compaction log DAG in the OM. - * @param fileName name of the image file. - * @param graphType type of node name to use in the graph image. - * @return path of the image file. - * @throws IOException + * @param fileNamePrefix file name prefix of the image file. + * @param graphType type of node name to use in the graph image. + * @return message which tells the image name, parent dir and OM leader + * node information. */ @Override - public String printCompactionLogDag(String fileName, + public String printCompactionLogDag(String fileNamePrefix, String graphType) throws IOException { - return ozoneManagerClient.printCompactionLogDag(fileName, graphType); + return ozoneManagerClient.printCompactionLogDag(fileNamePrefix, graphType); } @Override diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerProtocol.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerProtocol.java index b9a9f1e7b28c..ca25dd80e8d6 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerProtocol.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerProtocol.java @@ -693,12 +693,12 @@ default void deleteSnapshot(String volumeName, /** * Create an image of the current compaction log DAG in the OM. - * @param fileName name of the image file. - * @param graphType type of node name to use in the graph image. - * @return path of the image file. - * @throws IOException + * @param fileNamePrefix file name prefix of the image file. + * @param graphType type of node name to use in the graph image. + * @return message which tells the image name, parent dir and OM leader + * node information. */ - default String printCompactionLogDag(String fileName, String graphType) + default String printCompactionLogDag(String fileNamePrefix, String graphType) throws IOException { throw new UnsupportedOperationException("OzoneManager does not require " + "this to be implemented"); diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java index a6bb29859ebf..0b5c1f44055d 100644 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java +++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java @@ -1194,13 +1194,13 @@ public void deleteSnapshot(String volumeName, * {@inheritDoc} */ @Override - public String printCompactionLogDag(String fileName, String graphType) + public String printCompactionLogDag(String fileNamePrefix, String graphType) throws IOException { final PrintCompactionLogDagRequest.Builder request = PrintCompactionLogDagRequest.newBuilder(); - if (fileName != null) { - request.setFileName(fileName); + if (fileNamePrefix != null) { + request.setFileNamePrefix(fileNamePrefix); } if (graphType != null) { request.setGraphType(graphType); @@ -1211,7 +1211,7 @@ public String printCompactionLogDag(String fileName, String graphType) .build(); final OMResponse omResponse = submitRequest(omRequest); handleError(omResponse); - return omResponse.getPrintCompactionLogDagResponse().getImagePath(); + return omResponse.getPrintCompactionLogDagResponse().getMessage(); } /** diff --git a/hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto b/hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto index ece9b2637c77..d63f8583105d 100644 --- a/hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto +++ b/hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto @@ -1783,7 +1783,7 @@ message DeleteSnapshotRequest { } message PrintCompactionLogDagRequest { - optional string fileName = 1; + optional string fileNamePrefix = 1; optional string graphType = 2; } @@ -1879,7 +1879,7 @@ message DeleteSnapshotResponse { } message PrintCompactionLogDagResponse { - optional string imagePath = 1; + optional string message = 1; } message SnapshotMoveDeletedKeysResponse { diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java index f50d0c8c5fce..cc55d6e48479 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java @@ -256,7 +256,6 @@ import static org.apache.hadoop.ozone.OzoneConsts.OM_METRICS_FILE; import static org.apache.hadoop.ozone.OzoneConsts.OM_METRICS_TEMP_FILE; import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_DIR; -import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER; import static org.apache.hadoop.ozone.OzoneConsts.PREPARE_MARKER_KEY; import static org.apache.hadoop.ozone.OzoneConsts.OM_RATIS_SNAPSHOT_DIR; import static org.apache.hadoop.ozone.OzoneConsts.RPC_PORT; @@ -4646,16 +4645,23 @@ public List listSnapshotDiffJobs(String volume, bucket, jobStatus, listAll); } - public String printCompactionLogDag(String fileName, + public String printCompactionLogDag(String fileNamePrefix, String graphType) throws IOException { - if (StringUtils.isBlank(fileName)) { - fileName = "dag-" + System.currentTimeMillis(); + final UserGroupInformation ugi = getRemoteUser(); + if (!isAdmin(ugi)) { + throw new OMException( + "Only Ozone admins are allowed to print compaction DAG.", + PERMISSION_DENIED); } - // Append the tmp file prefix and image file suffix. - fileName = "/tmp" + OZONE_URI_DELIMITER + fileName + ".png"; + if (StringUtils.isBlank(fileNamePrefix)) { + fileNamePrefix = "dag-"; + } else { + fileNamePrefix = fileNamePrefix + "-"; + } + File tempFile = File.createTempFile(fileNamePrefix, ".png"); PrintableGraph.GraphType type; @@ -4665,10 +4671,13 @@ public String printCompactionLogDag(String fileName, type = FILE_NAME; } - return getMetadataManager() + getMetadataManager() .getStore() .getRocksDBCheckpointDiffer() - .pngPrintMutableGraph(fileName, type); + .pngPrintMutableGraph(tempFile.getAbsolutePath(), type); + + return String.format("Graph was generated at '\\tmp\\%s' on OM " + + "node '%s'.", tempFile.getName(), getOMNodeId()); } private String reconfOzoneAdmins(String newVal) { diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerRequestHandler.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerRequestHandler.java index b1dbcf7a5e17..b196e2173551 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerRequestHandler.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerRequestHandler.java @@ -1335,11 +1335,11 @@ private ListSnapshotDiffJobResponse listSnapshotDiffJobs( private PrintCompactionLogDagResponse printCompactionLogDag( PrintCompactionLogDagRequest printCompactionLogDagRequest) throws IOException { - String imagePath = impl.printCompactionLogDag( - printCompactionLogDagRequest.getFileName(), + String message = impl.printCompactionLogDag( + printCompactionLogDagRequest.getFileNamePrefix(), printCompactionLogDagRequest.getGraphType()); return PrintCompactionLogDagResponse.newBuilder() - .setImagePath(imagePath) + .setMessage(message) .build(); } diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/ClientProtocolStub.java b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/ClientProtocolStub.java index 66f823459b88..f5fc4f17fe1e 100644 --- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/ClientProtocolStub.java +++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/ClientProtocolStub.java @@ -631,7 +631,7 @@ public void deleteSnapshot(String volumeName, } - public String printCompactionLogDag(String fileName, + public String printCompactionLogDag(String fileNamePrefix, String graphType) throws IOException { return null; } diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/CompactionLogDagPrinter.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/CompactionLogDagPrinter.java index f8a4d885845c..18c13d67cf27 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/CompactionLogDagPrinter.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/CompactionLogDagPrinter.java @@ -29,7 +29,7 @@ import java.io.IOException; /** - * Handler to generate image for current compaction DAG in the OM. + * Handler to generate image for current compaction DAG in the OM leader node. * ozone sh snapshot print-log-dag. */ @CommandLine.Command( @@ -40,15 +40,15 @@ public class CompactionLogDagPrinter extends Handler implements SubcommandWithParent { - @CommandLine.Option(names = {"-f", "--file-name"}, - description = "Name of the image file. (optional)") - private String fileName; + @CommandLine.Option(names = {"-f", "--file-name-prefix"}, + description = "Prefix to be use in image file name. (optional)") + private String fileNamePrefix; // TODO: Change graphType to enum. @CommandLine.Option(names = {"-t", "--graph-type"}, - description = "Type of node name to use in the graph image.\n" + - "Accepted values are: \n" + - " file_name: to use file name as node name in DAG,\n" + + description = "Type of node name to use in the graph image. " + + "(optional)\n Accepted values are: \n" + + " file_name (default) : to use file name as node name in DAG,\n" + " key_size: to show the no. of keys in the file along with file " + "name in the DAG node name,\n" + " cumulative_size: to show the cumulative size along with file " + @@ -64,8 +64,8 @@ public Class getParentType() { @Override protected void execute(OzoneClient client, OzoneAddress address) throws IOException, OzoneClientException { - String imagePath = client.getObjectStore() - .printCompactionLogDag(fileName, graphType); - System.out.println("DAG image is created on path: " + imagePath); + String message = client.getObjectStore() + .printCompactionLogDag(fileNamePrefix, graphType); + System.out.println(message); } }