Merge branch 'benjamin' into dev

This commit is contained in:
Benjamin 2022-03-19 19:03:01 +01:00
commit f676934dd4
8 changed files with 25 additions and 18 deletions

View File

@ -18,10 +18,11 @@ public class Task {
*/
private final Context context;
public Task(Context context, TaskStatus status, ProtocolWriter.ProtocolResult command) {
public Task(Context context, TaskStatus status, ProtocolWriter.ProtocolResult command, String requestDomain) {
this.context = context;
this.status = status;
this.command = command;
context.setDomain(requestDomain); // Domaine requis
}
/**
@ -31,8 +32,8 @@ public class Task {
* @param command Commande à exécuter
* @return L'instance de la tâche créée
*/
public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command) {
return new Task(context, TaskStatus.PENDING, command);
public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command, String requestDomain) {
return new Task(context, TaskStatus.PENDING, command, requestDomain);
}
/**
@ -83,6 +84,10 @@ public class Task {
return this.context;
}
/**
* Le domaine actuellement utilisé OU requis, null si aucune domaine requis/associé
* @return
*/
public String getDomain() {
return context.getDomain();
}

View File

@ -110,28 +110,22 @@ 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
fileFrontEnd.newCommand(context, writerCommand, ruleResult.getRequestDomain()); // 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();
}

View File

@ -17,7 +17,7 @@ public interface ClientHandlerFFE {
* @param context Context de la requête
* @param command Commande à traiter
*/
void newCommand(Context context, ProtocolWriter.ProtocolResult command);
void newCommand(Context context, ProtocolWriter.ProtocolResult command, String requestDomain);
boolean canExecuteCommand(String domain);
}

View File

@ -66,7 +66,7 @@ public class RetrieveOkRule extends ProtocolReader {
if (!fileReceiver.receiveFile(reader, this.filename, this.filesize)) {
throw new IllegalStateException("Bad file reception");
}
if (SHA.hashFile(storagePath, this.filename).equals(this.hashedFileContent)) {
if (!SHA.hashFile(storagePath, this.filename).equals(this.hashedFileContent)) {
throw new IllegalStateException("File hash content are not equals");
}
} catch (IllegalStateException|SHA.ShaException e) {

View File

@ -51,7 +51,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
Iterator<Task> it = tasks.iterator();
while (it.hasNext()) {
Task task = it.next();
if (task.getDomain() == null) {
if (task.getDomain() == null || task.getDomain().equals(storeDomain)) { // Si tâche sans domaine ou si domaine requis pour la tâche est le domaine
task.setDomain(storeDomain);
storeRepository.assignTask(storeDomain, task);
return;
@ -62,6 +62,14 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
@Override
public void onStoreDisconnect(String domain) {
responseToClient(domain, null);
Iterator<Task> it = tasks.iterator();
while (it.hasNext()) {
Task task = it.next();
if (storeRepository.domainCount() == 0 || (task.getDomain() != null && task.getDomain().equals(domain))) {
clientRepository.respondToClient(it.next().getClient(), null);
it.remove(); // Suppression de la tâche
}
}
this.storeRepository.closeStore(domain);
}
@ -79,8 +87,8 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
@Override
public void newCommand(Context context, ProtocolWriter.ProtocolResult command) {
Task task = Task.newInstance(context, command);
public void newCommand(Context context, ProtocolWriter.ProtocolResult command, String requestDomain) {
Task task = Task.newInstance(context, command, requestDomain);
tasks.add(task);
alertStoreProcessors(task);
}

View File

@ -13,7 +13,7 @@ public class JsonAdapter implements Adapter {
* @return A Json String containing AppData properties
*/
@Override
public synchronized String toString(AppData appData) {
public String toString(AppData appData) {
return addData(appData);
}

View File

@ -28,7 +28,7 @@ public class Repository {
/**
* Saves configuration file
*/
public void save() {
public synchronized void save() {
if (filePath != null) {
String jsonAppData = adapter.toString(appData);
try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {

View File

@ -1 +1 @@
{"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":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"README.md","fileNameSalt":"4m84wYD79s9FoFq7Tqjzow==","size":17,"iv":"8EaBv4WGO++knjUbLXSFUA==","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":"5rB5fhj09F6ukJPRoJgTGQ==","size":17,"iv":"hY2yWRgIxB0dRettv/vPJw==","storage":["lightcontainerSB01"]}]},{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[{"name":"main.py","fileNameSalt":"XKxG99LVODAXohvCwvMRww==","size":854,"iv":"G9nULidPTDRxBp+Yp+IaCQ==","storage":["lightcontainerSB01"]}]}]}