-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fsck display tree #92
Open
yichen88
wants to merge
7
commits into
main
Choose a base branch
from
fsck_display_tree
base: main
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.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
155edac
Add orphan node check
yichen88 b666a70
Fix
yichen88 45e0fca
Add orphan data check
yichen88 d584abb
Add show afs content in tree
yichen88 8cf09b6
Merge branch 'master' into fsck_display_tree
sylvlecl fd5a3d2
Fix
yichen88 93a88f3
Merge branch 'master' into fsck_display_tree
sylvlecl 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
This file contains 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
121 changes: 121 additions & 0 deletions
121
afs-cassandra/src/main/java/com/powsybl/afs/cassandra/DisplayTreeIssueBuilder.java
This file contains 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,121 @@ | ||
/** | ||
* Copyright (c) 2021, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package com.powsybl.afs.cassandra; | ||
|
||
import com.datastax.driver.core.ResultSet; | ||
import com.datastax.driver.core.Row; | ||
import com.powsybl.afs.storage.check.FileSystemCheckIssue; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Yichen TANG <yichen.tang at rte-france.com> | ||
*/ | ||
class DisplayTreeIssueBuilder { | ||
|
||
private final TreeNode root = new TreeNode("display tree"); | ||
private final Map<String, TreeNode> nodes = new HashMap<>(); | ||
private final Map<String, NodeInfo> infos = new HashMap<>(); | ||
|
||
DisplayTreeIssueBuilder(ResultSet resultSet) { | ||
for (Row row : resultSet) { | ||
RowBean rowBean = new RowBean(row.getUUID(0).toString(), | ||
row.getString(1), | ||
row.getString(2), | ||
row.getUUID(3) == null ? null : row.getUUID(3).toString()); | ||
cacheNodeInfo(rowBean); | ||
nodes.computeIfAbsent(rowBean.id, TreeNode::new); | ||
if (rowBean.cId != null) { | ||
nodes.computeIfAbsent(rowBean.cId, TreeNode::new); | ||
nodes.get(rowBean.id).children.add(rowBean.cId); | ||
} | ||
if (row.getUUID(4) == null) { | ||
root.children.add(rowBean.id); | ||
} | ||
} | ||
} | ||
|
||
private void cacheNodeInfo(RowBean bean) { | ||
if (!infos.containsKey(bean.id)) { | ||
infos.put(bean.id, new NodeInfo(bean.name, bean.pseudoClass)); | ||
} | ||
} | ||
|
||
static class NodeInfo { | ||
|
||
private final String name; | ||
private final String pseudoClass; | ||
|
||
NodeInfo(String name, String pseudoClass) { | ||
this.name = name; | ||
this.pseudoClass = pseudoClass; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name + "(" + pseudoClass + ")"; | ||
} | ||
} | ||
|
||
static class RowBean { | ||
|
||
private final String id; | ||
private final String name; | ||
private final String pseudoClass; | ||
private final String cId; | ||
|
||
RowBean(String id, String name, String pseudoClass, String cId) { | ||
this.id = id; | ||
this.name = name; | ||
this.pseudoClass = pseudoClass; | ||
this.cId = cId; | ||
} | ||
} | ||
|
||
static class TreeNode { | ||
String id; | ||
String name; | ||
Set<String> children = new HashSet<>(); | ||
|
||
TreeNode(String id) { | ||
this.id = id; | ||
} | ||
|
||
TreeNode(String id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return id + "_" + name; | ||
} | ||
} | ||
|
||
FileSystemCheckIssue build() { | ||
StringBuilder sb = new StringBuilder(); | ||
printNode(sb, root, 0); | ||
return new FileSystemCheckIssue().setDescription(sb.toString()); | ||
} | ||
|
||
void printNode(StringBuilder sb, TreeNode node, int level) { | ||
for (int i = 0; i < level - 1; i++) { | ||
sb.append(" "); | ||
} | ||
if (level != 0) { | ||
sb.append(infos.get(node.id)) | ||
.append(" ") | ||
.append(node.id) | ||
.append("\n"); | ||
} | ||
int nextLevel = level + 1; | ||
node.children.forEach(e -> printNode(sb, nodes.get(e), nextLevel)); | ||
} | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the tree is displayed multiple times because we don't check here if the node has already been added:
if the root node of the filesystem has multiple children, it will appear multiple times in the table (once for itself, once for each children), so we will go through that code multiple times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by 'Set'