Désormais, lorsque le SBE crash, celui-ci répond négativement à son client et ceux qui sont dans la fils en attente d'être traité par ce SBE
This commit is contained in:
parent
6afc3dbd0a
commit
1e821cf4ef
@ -18,10 +18,11 @@ public class Task {
|
|||||||
*/
|
*/
|
||||||
private final Context context;
|
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.context = context;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.command = command;
|
this.command = command;
|
||||||
|
context.setDomain(requestDomain); // Domaine requis
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,8 +32,8 @@ public class Task {
|
|||||||
* @param command Commande à exécuter
|
* @param command Commande à exécuter
|
||||||
* @return L'instance de la tâche créée
|
* @return L'instance de la tâche créée
|
||||||
*/
|
*/
|
||||||
public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command) {
|
public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command, String requestDomain) {
|
||||||
return new Task(context, TaskStatus.PENDING, command);
|
return new Task(context, TaskStatus.PENDING, command, requestDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,6 +84,10 @@ public class Task {
|
|||||||
return this.context;
|
return this.context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Le domaine actuellement utilisé OU requis, null si aucune domaine requis/associé
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public String getDomain() {
|
public String getDomain() {
|
||||||
return context.getDomain();
|
return context.getDomain();
|
||||||
}
|
}
|
||||||
|
@ -110,28 +110,22 @@ public class ClientHandler implements Runnable, AutoCloseable {
|
|||||||
ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand();
|
ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand();
|
||||||
// TODO : Vérifier que le StorBackEnd demandé (Pas toujours demandé) est disponible
|
// TODO : Vérifier que le StorBackEnd demandé (Pas toujours demandé) est disponible
|
||||||
if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND && !fileFrontEnd.canExecuteCommand(ruleResult.getRequestDomain())) {
|
if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND && !fileFrontEnd.canExecuteCommand(ruleResult.getRequestDomain())) {
|
||||||
System.out.println("[1] 1");
|
|
||||||
writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client
|
writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client
|
||||||
writer.flush();
|
writer.flush();
|
||||||
} else if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) {
|
} else if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) {
|
||||||
System.out.println("[1] 2");
|
fileFrontEnd.newCommand(context, writerCommand, ruleResult.getRequestDomain()); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd
|
||||||
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
|
// Attend la fin de la réalisation de la tâche
|
||||||
waitTaskResponse();
|
waitTaskResponse();
|
||||||
System.out.println("[1] 4");
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
System.out.println("[1] 5");
|
|
||||||
writer.write(response.getCommand()); // Renvoie au client
|
writer.write(response.getCommand()); // Renvoie au client
|
||||||
writer.flush();
|
writer.flush();
|
||||||
response.write(this.client.getOutputStream()); // Ecrit au client si nécessaire
|
response.write(this.client.getOutputStream()); // Ecrit au client si nécessaire
|
||||||
} else {
|
} else {
|
||||||
System.out.println("[1] 6");
|
|
||||||
writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client
|
writer.print(ruleResult.onNotExecutable(context)); // Renvoie au client
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("[1] 3");
|
|
||||||
writer.print(writerCommand.getCommand()); // Renvoie au client
|
writer.print(writerCommand.getCommand()); // Renvoie au client
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public interface ClientHandlerFFE {
|
|||||||
* @param context Context de la requête
|
* @param context Context de la requête
|
||||||
* @param command Commande à traiter
|
* @param command Commande à traiter
|
||||||
*/
|
*/
|
||||||
void newCommand(Context context, ProtocolWriter.ProtocolResult command);
|
void newCommand(Context context, ProtocolWriter.ProtocolResult command, String requestDomain);
|
||||||
|
|
||||||
boolean canExecuteCommand(String domain);
|
boolean canExecuteCommand(String domain);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class RetrieveOkRule extends ProtocolReader {
|
|||||||
if (!fileReceiver.receiveFile(reader, this.filename, this.filesize)) {
|
if (!fileReceiver.receiveFile(reader, this.filename, this.filesize)) {
|
||||||
throw new IllegalStateException("Bad file reception");
|
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");
|
throw new IllegalStateException("File hash content are not equals");
|
||||||
}
|
}
|
||||||
} catch (IllegalStateException|SHA.ShaException e) {
|
} catch (IllegalStateException|SHA.ShaException e) {
|
||||||
|
@ -51,7 +51,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
|||||||
Iterator<Task> it = tasks.iterator();
|
Iterator<Task> it = tasks.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Task task = it.next();
|
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);
|
task.setDomain(storeDomain);
|
||||||
storeRepository.assignTask(storeDomain, task);
|
storeRepository.assignTask(storeDomain, task);
|
||||||
return;
|
return;
|
||||||
@ -62,6 +62,14 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
|||||||
@Override
|
@Override
|
||||||
public void onStoreDisconnect(String domain) {
|
public void onStoreDisconnect(String domain) {
|
||||||
responseToClient(domain, null);
|
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);
|
this.storeRepository.closeStore(domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,8 +87,8 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newCommand(Context context, ProtocolWriter.ProtocolResult command) {
|
public void newCommand(Context context, ProtocolWriter.ProtocolResult command, String requestDomain) {
|
||||||
Task task = Task.newInstance(context, command);
|
Task task = Task.newInstance(context, command, requestDomain);
|
||||||
tasks.add(task);
|
tasks.add(task);
|
||||||
alertStoreProcessors(task);
|
alertStoreProcessors(task);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public class JsonAdapter implements Adapter {
|
|||||||
* @return A Json String containing AppData properties
|
* @return A Json String containing AppData properties
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized String toString(AppData appData) {
|
public String toString(AppData appData) {
|
||||||
return addData(appData);
|
return addData(appData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public class Repository {
|
|||||||
/**
|
/**
|
||||||
* Saves configuration file
|
* Saves configuration file
|
||||||
*/
|
*/
|
||||||
public void save() {
|
public synchronized void save() {
|
||||||
if (filePath != null) {
|
if (filePath != null) {
|
||||||
String jsonAppData = adapter.toString(appData);
|
String jsonAppData = adapter.toString(appData);
|
||||||
try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
|
try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
|
||||||
|
@ -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"]}]}]}
|
Loading…
Reference in New Issue
Block a user