- Résolution problème empêchant l'utilisation de deux SBE différents lors la la sauvegarde d'un fichier et donc emêchant le parallélisme

This commit is contained in:
Benjamin 2022-03-19 13:11:08 +01:00
parent 6823c41825
commit 6a002327db
12 changed files with 79 additions and 28 deletions

View File

@ -42,6 +42,7 @@ public class Task {
* @return TRUE si le client doit recevoir cette réponse.
*/
public boolean isResponseOfClient(String storeDomain) {
System.out.println(status + " - " + context.getDomain() + " | " + storeDomain);
return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain));
}

View File

@ -110,30 +110,33 @@ public class ClientHandler implements Runnable, AutoCloseable {
ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand();
// TODO : Vérifier que le StorBackEnd demandé (Pas toujours demandé) est disponible
if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND && !fileFrontEnd.canExecuteCommand(ruleResult.getRequestDomain())) {
System.out.println("[1] 1");
writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client
writer.flush();
} else if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) {
System.out.println("[1] 2");
fileFrontEnd.newCommand(context, writerCommand); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd
// Attend la fin de la réalisation de la tâche
waitTaskResponse();
System.out.println("[1] 4");
if (response != null) {
System.out.println("[1] 5");
writer.write(response.getCommand()); // Renvoie au client
writer.flush();
response.write(this.client.getOutputStream()); // Ecrit au client si nécessaire
} else {
System.out.println("[1] 6");
writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client
writer.flush();
}
} else {
System.out.println("[1] 3");
writer.print(writerCommand.getCommand()); // Renvoie au client
writer.flush();
}
} else {
System.out.println(4);
accessDenied();
}
} catch (IOException e) {

View File

@ -92,6 +92,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
protocolResult.write(this.store.getOutputStream());
} catch (IOException writeException) { // Si SBE fermé
System.out.println("STOPPER");
writeException.printStackTrace();
// Envoie au client que la requête n'a pu être traitée
alertAvailable(null);
break;
@ -103,7 +104,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
responseCommand += "\r\n";
ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(context, responseCommand);
if (responseResult != null) {
System.out.println("StoreBackEnd response to client: " + responseResult.getResultCommand());
System.out.println("StoreBackEnd (" + domain + ") response to client: " + responseResult.getResultCommand());
responseResult.read(
this.store.getInputStream()
);
@ -207,7 +208,8 @@ public class StoreProcessor extends Thread implements AutoCloseable {
return Objects.hash(domain);
}
public boolean canProcessTask(Task task) {
public boolean canProcessTask() {
System.out.println("[OK 2] " + protocolResult + " - " + domain);
return this.protocolResult == null; // Vérifier si tâche veut ce SBE
}

View File

@ -23,7 +23,7 @@ public interface MulticastSPR {
*/
boolean addStore(StoreProcessor store);
String findDomain(Task task);
String findDomain();
void assignTask(String stor, Task task);

View File

@ -19,7 +19,7 @@ import java.io.InputStream;
*/
public class SavefileRule extends ProtocolReader {
// Constants
private static final String PATTERN = "^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$";
private static final String PATTERN = "^SAVEFILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$";
private static final String NAME = "SAVEFILE";

View File

@ -12,7 +12,7 @@ public class SendErrorRule extends ProtocolReader {
// Constants
private static final String PATTERN = "^SEND_ERROR\r\n$";
private static final String NAME = "SEND_ERROR";
private static final String NAME = "SENDERROR";
private final ProtocolRepository protocolRep;

View File

@ -28,16 +28,22 @@ public class SaveFileErrorRule extends ProtocolWriter {
@Override
protected ProtocolResult onExecuted(Context context, String... data) {
ProtocolResult result = new ProtocolResult(context);
String fileName = context.getDataString("fileName");
String fileNameSalt = context.getDataString("fileNameSalt");
// Suppression du fichier temporaire dans le stockage du FFE
ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + context.getDataString("fileName"));
try {
Files.deleteIfExists(Path.of(
String.format("%s/%s", this.storagePath,
hasher.fromSalt(hasher.saltToByte(context.getDataString("fileNameSalt")))
)
));
} catch (IOException e) {}
if (fileName != null && fileNameSalt != null) {
// Suppression du fichier temporaire dans le stockage du FFE
ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + fileName);
try {
Files.deleteIfExists(Path.of(
String.format("%s/%s", this.storagePath,
hasher.fromSalt(hasher.saltToByte(fileNameSalt))
)
));
} catch (IOException e) {
}
}
return result;
}

View File

@ -27,6 +27,7 @@ public class SaveFileOkRule extends ProtocolWriter {
protected ProtocolWriter.ProtocolResult onExecuted(Context context, String... data) {
ProtocolWriter.ProtocolResult result = new ProtocolWriter.ProtocolResult(context);
System.out.println("===> Save en json " + context.getDomain() + " - " + context.getLogin());
// Sauvegarder dans JSON
context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataInt("size"), context.getDataString("iv"), context.getDomain());

View File

@ -32,7 +32,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
*/
public void alertStoreProcessors(Task task) {
// On avertit les stor processors d'une nouvelle tâche
String stor = storeRepository.findDomain(task);
String stor = storeRepository.findDomain();
if (stor != null) {
storeRepository.assignTask(stor, task);
task.setDomain(stor);
@ -51,9 +51,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
Iterator<Task> it = tasks.iterator();
while (it.hasNext()) {
Task task = it.next();
System.out.println("Cherche");
if (task.isResponseOfClient(store.getDomain())) {
System.out.println("Task trouvée");
clientRepository.respondToClient(task.getClient(), response);
it.remove(); // Suppression de la tâche
break;
@ -73,7 +71,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
while (it.hasNext()) {
Task task = it.next();
if (store.canProcessTask(task)) {
if (task.getDomain() == null && store.canProcessTask()) {
storeRepository.assignTask(store.getDomain(), task);
task.setDomain(store.getDomain());
return;

View File

@ -31,7 +31,6 @@ public class ProtocolRepositoryImpl implements ProtocolRepository {
return command;
}
}
System.out.println("COMMANDE NULL");
return null;
}

View File

@ -60,14 +60,14 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
}
@Override
public String findDomain(Task task) {
StoreProcessor handler = findSBE(task);
public String findDomain() {
StoreProcessor handler = findSBE();
return handler == null ? null : handler.getDomain();
}
private StoreProcessor findSBE(Task task) {
private StoreProcessor findSBE() {
for (StoreProcessor handler : handlers) {
if (handler.canProcessTask(task)) {
if (handler.canProcessTask()) {
return handler;
}
}
@ -77,7 +77,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
@Override
public void assignTask(String stor, Task task) {
StoreProcessor handler = findSBE(task);
StoreProcessor handler = findSBE();
System.out.println("Find stor : " + handler);
handler.executeCommand(task.getContext(), task.getCommand());
}

View File

@ -1 +1,42 @@
{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"wlp1s0","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"main.py","fileNameSalt":"PLQB1QjPaKdfdM+zjywxcQ==","size":854,"iv":"UnkiNxFMYsRcw5fsEkr+5w==","storage":["lightcontainerSB01"]}]}]}
{
"unicast_port": 8000,
"multicast_ip": "224.66.66.1",
"multicast_port": 15502,
"network_interface": "wlp1s0",
"tls": true,
"storagePath": "/home/benjamin/ffe",
"users": [
{
"name": "benjamin",
"password": "$2a$10$I4vHt83CTYuQCP7xvZ04Ne7Vb0cswBiVZhV0n23k9FCxoH0ny9fZG",
"aes_key": "mAP6izUBUhBxIkakH2yB/TplhRz1OQV5Fp6HQmhywns=",
"files": [
{
"name": "README.md",
"fileNameSalt": "5k8bd3/hn5ehdkCRJ0MGRQ==",
"size": 17,
"iv": "/sEVBG7kKnMaJcg5Wpz2bQ==",
"storage": [
"lightcontainerSB02"
]
}
]
},
{
"name": "aaaaa",
"password": "$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W",
"aes_key": "kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=",
"files": [
{
"name": "ca.crt",
"fileNameSalt": "JmISh065QAtDIePgl8IG2A==",
"size": 4207,
"iv": "Tg3aeOm1U0hQI1VqSZbAJw==",
"storage": [
"lightcontainerSB01"
]
}
]
}
]
}