Skip to content

Commit 8bf59e3

Browse files
Merge pull request #1 from mateuszkalinowski/BackupWersjiZeZmianaNazwy
Poprawa dzialania zmiany nazwy
2 parents 926e552 + 991877e commit 8bf59e3

File tree

11 files changed

+385
-85
lines changed

11 files changed

+385
-85
lines changed

src/main/java/pl/dfs/distributedfilesystem/configuration/OnFinishLoading.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.context.event.ContextRefreshedEvent;
66
import org.springframework.stereotype.Component;
77
import pl.dfs.distributedfilesystem.files.FilesRepository;
8+
import pl.dfs.distributedfilesystem.models.ToChangeRepository;
89

910

1011
@Component
@@ -14,11 +15,14 @@ public class OnFinishLoading
1415
@Autowired
1516
FilesRepository filesRepository;
1617

18+
@Autowired
19+
ToChangeRepository toChangeRepository;
20+
1721
public void onApplicationEvent(ContextRefreshedEvent event) {
1822
filesRepository.initializeDataNodesSizes();
19-
2023
filesRepository.checkCohesion();
21-
2224
filesRepository.tryToDelete();
25+
26+
toChangeRepository.tryToExecuteCommands();
2327
}
2428
}

src/main/java/pl/dfs/distributedfilesystem/controllers/FilesAccessController.java

Lines changed: 137 additions & 54 deletions
Large diffs are not rendered by default.

src/main/java/pl/dfs/distributedfilesystem/files/FilesRepository.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,9 @@ public void tryToDelete() {
240240

241241
}
242242

243-
244243
private ArrayList<SingleFile> fileArrayList;
245244

246245
String rootPath = System.getProperty("user.home") + File.separator + "dsfNameNode";
247246

248247
public ArrayList<Pair<String,String>> toDelete = new ArrayList<>();
249-
}
248+
}

src/main/java/pl/dfs/distributedfilesystem/folders/FoldersRepository.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ public void removeFolder(String path,String folder) {
101101
rewriteFolders();
102102
}
103103

104+
public void renameFolder(String path,String oldName,String newName) {
105+
ArrayList<String> folders = new ArrayList<>(Arrays.asList(foldersMap.get(path).split(",")));
106+
folders.remove(oldName);
107+
folders.add(newName);
108+
String folderList = "";
109+
for(String oneFolder : folders)
110+
folderList +=oneFolder+",";
111+
foldersMap.put(path,folderList);
112+
113+
Set<String> keys = foldersMap.keySet();
114+
Set<String> toRemove = new HashSet<>();
115+
Map<String,String> toChange = new HashMap<>();
116+
117+
for(String key : keys) {
118+
if(key.startsWith(path + oldName + "/")) {
119+
toChange.put(path + newName + "/",foldersMap.get(key));
120+
toRemove.add(key);
121+
}
122+
}
123+
124+
for(String key : toRemove)
125+
foldersMap.remove(key);
126+
127+
for(String key : toChange.keySet()) {
128+
foldersMap.put(key,toChange.get(key));
129+
}
130+
131+
132+
133+
134+
rewriteFolders();
135+
}
136+
104137
public ArrayList<String> subfoldersOfFolder(String path) {
105138
if(foldersMap.get(path).equals(""))
106139
return new ArrayList<>();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package pl.dfs.distributedfilesystem.models;
2+
3+
public class ToChange {
4+
private String address;
5+
private String command;
6+
private String from;
7+
private String to;
8+
9+
public ToChange(String address, String command, String from, String to) {
10+
this.address = address;
11+
this.command = command;
12+
this.from = from;
13+
this.to = to;
14+
}
15+
16+
public String getAddress() {
17+
return address;
18+
}
19+
20+
public void setAddress(String address) {
21+
this.address = address;
22+
}
23+
24+
public String getCommand() {
25+
return command;
26+
}
27+
28+
public void setCommand(String command) {
29+
this.command = command;
30+
}
31+
32+
public String getFrom() {
33+
return from;
34+
}
35+
36+
public void setFrom(String from) {
37+
this.from = from;
38+
}
39+
40+
public String getTo() {
41+
return to;
42+
}
43+
44+
public void setTo(String to) {
45+
this.to = to;
46+
}
47+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package pl.dfs.distributedfilesystem.models;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.stereotype.Component;
5+
import pl.dfs.distributedfilesystem.files.FilesRepository;
6+
import pl.dfs.distributedfilesystem.nodes.DataNodesRepository;
7+
8+
import java.io.File;
9+
import java.io.PrintWriter;
10+
import java.util.ArrayList;
11+
import java.util.Scanner;
12+
13+
@Component
14+
public class ToChangeRepository {
15+
16+
@Autowired
17+
DataNodesRepository dataNodesRepository;
18+
19+
public ToChangeRepository(){
20+
try {
21+
File nameNodePath = new File(rootPath);
22+
toChangeArrayList = new ArrayList<>();
23+
if (!nameNodePath.exists())
24+
nameNodePath.mkdir();
25+
26+
File nameNodeFilesInformationPath = new File(rootPath + File.separator + "files");
27+
28+
if (!nameNodeFilesInformationPath.exists())
29+
nameNodeFilesInformationPath.mkdir();
30+
31+
if (!new File(rootPath + File.separator + "files" + File.separator + "toChangeInformation").exists()) {
32+
new File(rootPath + File.separator + "files" + File.separator + "toChangeInformation").createNewFile();
33+
}
34+
Scanner in = new Scanner(new File(rootPath + File.separator +"files" + File.separator + "toChangeInformation"));
35+
while(in.hasNextLine()) {
36+
String line = in.nextLine();
37+
String divided[] = line.split(",");
38+
toChangeArrayList.add(new ToChange(divided[0],divided[1],divided[2],divided[3]));
39+
}
40+
} catch (Exception e) {
41+
42+
}
43+
}
44+
45+
public void add(ToChange toChange){
46+
toChangeArrayList.add(toChange);
47+
writeToFile();
48+
}
49+
50+
public void tryToExecuteCommands(){
51+
ArrayList<Integer> indexesToDelete = new ArrayList<>();
52+
String address;
53+
for(int i = 0;i<toChangeArrayList.size();i++) {
54+
try {
55+
address = toChangeArrayList.get(i).getAddress();
56+
dataNodesRepository.get(address).writeString(toChangeArrayList.get(i).getCommand());
57+
dataNodesRepository.get(address).writeString(toChangeArrayList.get(i).getFrom());
58+
dataNodesRepository.get(address).writeString(toChangeArrayList.get(i).getTo());
59+
dataNodesRepository.get(address).writeFlush();
60+
String response = dataNodesRepository.get(address).readResponse();
61+
if (response.equals("success")) {
62+
indexesToDelete.add(i);
63+
}
64+
} catch (Exception e){}
65+
}
66+
67+
for(int i = indexesToDelete.size()-1;i>=0;i--) {
68+
indexesToDelete.remove(indexesToDelete.get(i));
69+
}
70+
writeToFile();
71+
72+
}
73+
74+
public void writeToFile(){
75+
try {
76+
PrintWriter writer = new PrintWriter(new File(rootPath + File.separator + "files" + File.separator + "toChangeInformation"));
77+
for(int i = 0; i < toChangeArrayList.size();i++){
78+
writer.println(toChangeArrayList.get(i).getAddress() + "," + toChangeArrayList.get(i).getCommand()+","+toChangeArrayList.get(i).getFrom()+","+toChangeArrayList.get(i).getTo());
79+
}
80+
writer.close();
81+
}
82+
catch (Exception e){}
83+
}
84+
85+
86+
String rootPath = System.getProperty("user.home") + File.separator + "dsfNameNode";
87+
88+
private ArrayList<ToChange> toChangeArrayList;
89+
}
16.6 KB
Loading
11.7 KB
Loading

src/main/resources/static/js/Scripts.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,3 @@ function post(path, params, method) {
174174
document.body.appendChild(form);
175175
form.submit();
176176
}
177-
Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
<!DOCTYPE html>
22
<html xmlns:th="http://www.thymeleaf.org">
33
<head>
4-
<meta charset="UTF-8" />
4+
<meta charset="UTF-8"/>
55
<title>DFS - About</title>
66
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css"/>
77
<script src="/js/loginPage.js"></script>
88
</head>
99
<body class="bg-light">
1010
<div class="container">
11-
<nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-primary"
12-
th:include="navigationBar :: navigationBar"/>
13-
<div class="row mt-3">
14-
<div class="col-md-8 mx-auto text-center">
15-
<h4 class="my-2">Podłączone węzły danych:</h4>
11+
<nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-primary"
12+
th:include="navigationBar :: navigationBar"/>
13+
<div class="row mt-3">
14+
<div class="col-md-8 mx-auto text-center">
15+
<h4 class="my-2">Podłączone węzły danych:</h4>
1616

17-
<table class="w-100 table mx-auto table-hover table-bordered table-sm" id="filesListTable" border="1">
18-
<thead class="thead-light">
19-
<tr>
20-
<th style="width: 70%">Adres</th>
21-
<th style="width: 15%">Zajęte miejsce</th>
22-
<th style="width: 15%">Wolne miejsce</th>
23-
</tr>
24-
</thead>
25-
<tr th:each="dataNode: ${dataNodesOnTheList}" th:object="${dataNode}">
26-
<td th:text="*{address}">text</td>
27-
<td th:text="*{storage}"></td>
28-
<td th:text="*{freeStorage}"></td>
29-
</tr>
30-
</table>
17+
<table class="w-100 table mx-auto table-hover table-bordered table-sm" id="filesListTable" border="1">
18+
<thead class="thead-light">
19+
<tr>
20+
<th></th>
21+
<th style="width: 70%">Adres</th>
22+
<th style="width: 15%">Zajęte miejsce</th>
23+
<th style="width: 15%">Wolne miejsce</th>
24+
</tr>
25+
</thead>
26+
<tr th:each="dataNode: ${dataNodesOnTheList}" th:object="${dataNode}">
27+
<td><img src="/fileIcons/node.png" style="width: 20px;height: 20px"></td>
28+
<td th:text="*{address}">text</td>
29+
<td th:text="*{storage}"></td>
30+
<td th:text="*{freeStorage}"></td>
31+
</tr>
32+
</table>
3133

34+
</div>
35+
</div>
36+
<div class="fixed-bottom text-center">
37+
Icons made by <a href="https://www.flaticon.com/authors/smashicons" title="smashicons">smashicons</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> are licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
3238
</div>
33-
</div>
3439
</div>
3540
</body>
3641
</html>

0 commit comments

Comments
 (0)