symious commented on code in PR #3874:
URL: https://github.com/apache/ozone/pull/3874#discussion_r1103821791


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerYaml.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.container.diskbalancer;
+
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * Class for creating diskbalancer.info file in yaml format.
+ */
+
+public final class DiskBalancerYaml {
+
+  private DiskBalancerYaml() {
+    // static helper methods only, no state.
+  }
+
+  /**
+   * Creates a yaml file to store DiskBalancer info.
+   *
+   * @param diskBalancerInfo {@link DiskBalancerInfo}
+   * @param path            Path to diskBalancer.info file
+   */
+  public static void createDiskBalancerInfoFile(
+      DiskBalancerInfo diskBalancerInfo, File path)
+      throws IOException {
+    DumperOptions options = new DumperOptions();
+    options.setPrettyFlow(true);
+    options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
+    Yaml yaml = new Yaml(options);
+
+    try (Writer writer = new OutputStreamWriter(
+        new FileOutputStream(path), StandardCharsets.UTF_8)) {
+      yaml.dump(getDiskBalancerInfoYaml(diskBalancerInfo), writer);
+    }
+  }
+
+  /**
+   * Read DiskBalancerConfiguration from file.
+   */
+  public static DiskBalancerInfo readDiskBalancerInfoFile(File path)
+      throws IOException {
+    DiskBalancerInfo diskBalancerInfo;
+
+    try (FileInputStream inputFileStream = new FileInputStream(path)) {
+      Yaml yaml = new Yaml();
+      DiskBalancerInfoYaml diskBalancerInfoYaml;
+      try {
+        diskBalancerInfoYaml =
+            yaml.loadAs(inputFileStream, DiskBalancerInfoYaml.class);
+      } catch (Exception e) {
+        throw new IOException("Unable to parse yaml file.", e);
+      }
+
+      diskBalancerInfo = new DiskBalancerInfo(
+          diskBalancerInfoYaml.isShouldRun(),
+          diskBalancerInfoYaml.getThreshold(),
+          diskBalancerInfoYaml.getBandwidthInMB(),
+          diskBalancerInfoYaml.getParallelThread());
+    }
+
+    return diskBalancerInfo;
+  }
+
+  /**
+   * Datanode DiskBalancer Info to be written to the yaml file.
+   */
+  public static class DiskBalancerInfoYaml {
+    private boolean shouldRun;
+    private double threshold;
+    private long bandwidthInMB;
+    private int parallelThread;
+
+    public DiskBalancerInfoYaml() {
+      // Needed for snake-yaml introspection.
+    }
+
+    @SuppressWarnings({"parameternumber", "java:S107"}) // required for yaml

Review Comment:
   Removed annotion.
   Will mark as resolved.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to