-
Notifications
You must be signed in to change notification settings - Fork 537
HDDS-11072. Publish user-facing configs to the doc site #6916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sarvekshayr
wants to merge
17
commits into
apache:master
Choose a base branch
from
sarvekshayr:HDDS-11072
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e63b840
HDDS-11072. Publish user-facing configs to the doc site: ozone-defaul…
sarvekshayr d2b3d2e
Fixed errors
sarvekshayr 0611fe2
Fixed checkstyle errors
sarvekshayr 2fbd2d4
Added workflow file and python script to convert xml into md
sarvekshayr 0ab8cb1
Delete hadoop-hdds/common/src/main/java/com/google/protobuf/XmlToMark…
sarvekshayr 21db9fa
Delete hadoop-hdds/docs/content/tools/Configurations.md
sarvekshayr e09f2ed
Modified doc.yml
sarvekshayr 180adc2
Build - xmltomd - push the changes to ozone-site
sarvekshayr 9db5dcb
Commit to apache/ozone
sarvekshayr 9a75c2b
Creates a PR in ozone and ozone-site when the md file changes.
sarvekshayr 7f974cc
Changed Github Actions user and target path
sarvekshayr d77580f
Added secret token
sarvekshayr 3ab2148
Changed to github.sha
sarvekshayr babafff
Get short commit SHA
sarvekshayr 898afea
Get short commit SHA - 1
sarvekshayr 37ae2df
Get short commit SHA - 2
sarvekshayr 8c45500
Fetch JIRA_ID from the first commit
sarvekshayr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
176 changes: 176 additions & 0 deletions
176
hadoop-hdds/common/src/main/java/com/google/protobuf/XmlToMarkdown.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/* | ||
* 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 com.google.protobuf; | ||
|
||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
import org.xml.sax.SAXException; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.io.Writer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
/** | ||
* Represents a property in the XML file. | ||
*/ | ||
class Property { | ||
private final String name; | ||
private final String value; | ||
private final String tag; | ||
private final String description; | ||
|
||
Property(String name, String value, String tag, String description) { | ||
this.name = name; | ||
this.value = value; | ||
this.tag = tag; | ||
this.description = description; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public String getTag() { | ||
return tag; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
} | ||
|
||
/** | ||
* Utility class for converting XML properties from ozone-default.xml and | ||
* ozone-default-generated.xml into Markdown format. The converted content | ||
* is saved to Configurations.md. | ||
*/ | ||
public final class XmlToMarkdown { | ||
|
||
private XmlToMarkdown() { | ||
// Prevent instantiation | ||
} | ||
|
||
public static void main(String[] args) { | ||
try { | ||
// List of XML files to process | ||
String[] xmlFiles = { | ||
"hadoop-hdds/common/src/main/resources/ozone-default.xml", | ||
"hadoop-hdds/config/target/test-classes/ozone-default-generated.xml" | ||
sarvekshayr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
List<Property> properties = new ArrayList<>(); | ||
|
||
// Load and parse each XML file | ||
for (String xmlFile : xmlFiles) { | ||
File inputFile = new File(xmlFile); | ||
if (!inputFile.exists()) { | ||
System.out.println("File not found: " + xmlFile); | ||
continue; | ||
} | ||
|
||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); | ||
sarvekshayr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); | ||
Document doc = dBuilder.parse(inputFile); | ||
doc.getDocumentElement().normalize(); | ||
|
||
// Get all properties | ||
NodeList nList = doc.getElementsByTagName("property"); | ||
|
||
// Process each property | ||
for (int temp = 0; temp < nList.getLength(); temp++) { | ||
Node nNode = nList.item(temp); | ||
if (nNode.getNodeType() == Node.ELEMENT_NODE) { | ||
Element eElement = (Element) nNode; | ||
String name = getTextContent(eElement, "name"); | ||
String value = getTextContent(eElement, "value"); | ||
String tag = getTextContent(eElement, "tag"); | ||
String description = getTextContent(eElement, "description").replaceAll("\\s+", " ").trim(); | ||
|
||
properties.add(new Property(name, value, tag, description)); | ||
} | ||
} | ||
} | ||
|
||
// Sort properties by name | ||
properties.sort(Comparator.comparing(Property::getName)); | ||
sarvekshayr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Generate markdown content | ||
StringBuilder markdown = new StringBuilder(); | ||
// Add Apache license header | ||
markdown.append("<!--\n") | ||
.append("Licensed to the Apache Software Foundation (ASF) under one or more\n") | ||
.append("contributor license agreements. See the NOTICE file distributed with\n") | ||
.append("this work for additional information regarding copyright ownership.\n") | ||
.append("The ASF licenses this file to You under the Apache License, Version 2.0\n") | ||
.append("(the \"License\"); you may not use this file except in compliance with\n") | ||
.append("the License. You may obtain a copy of the License at\n\n") | ||
.append(" http://www.apache.org/licenses/LICENSE-2.0\n\n") | ||
.append("Unless required by applicable law or agreed to in writing, software\n") | ||
.append("distributed under the License is distributed on an \"AS IS\" BASIS,\n") | ||
.append("WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n") | ||
.append("See the License for the specific language governing permissions and\n") | ||
.append("limitations under the License.\n") | ||
.append("-->\n\n"); | ||
|
||
// Add properties | ||
for (Property prop : properties) { | ||
markdown.append("| **Name** | `").append(prop.getName()).append("` |\n"); | ||
markdown.append("|:----------------|:----------------------------|\n"); | ||
markdown.append("| **Value** | ").append(prop.getValue()).append(" |\n"); | ||
markdown.append("| **Tag** | ").append(prop.getTag()).append(" |\n"); | ||
markdown.append("| **Description** | ").append(prop.getDescription()).append(" |\n"); | ||
markdown.append("--------------------------------------------------------------------------------\n"); | ||
} | ||
|
||
// Write the markdown to a file | ||
Path outputPath = Paths.get("hadoop-hdds/docs/content/tools/Configurations.md"); | ||
try (Writer fileWriter = new OutputStreamWriter(Files.newOutputStream(outputPath), StandardCharsets.UTF_8)) { | ||
fileWriter.write(markdown.toString()); | ||
} | ||
|
||
} catch (ParserConfigurationException | SAXException | IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private static String getTextContent(Element element, String tagName) { | ||
NodeList nodeList = element.getElementsByTagName(tagName); | ||
if (nodeList.getLength() > 0 && nodeList.item(0) != null) { | ||
return nodeList.item(0).getTextContent(); | ||
} | ||
return ""; // Return an empty string if the element is missing | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.