- 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:
parent
6823c41825
commit
6a002327db
@ -42,6 +42,7 @@ public class Task {
|
|||||||
* @return TRUE si le client doit recevoir cette réponse.
|
* @return TRUE si le client doit recevoir cette réponse.
|
||||||
*/
|
*/
|
||||||
public boolean isResponseOfClient(String storeDomain) {
|
public boolean isResponseOfClient(String storeDomain) {
|
||||||
|
System.out.println(status + " - " + context.getDomain() + " | " + storeDomain);
|
||||||
return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain));
|
return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,30 +110,33 @@ 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); // 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println(4);
|
|
||||||
accessDenied();
|
accessDenied();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -92,6 +92,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
|
|||||||
protocolResult.write(this.store.getOutputStream());
|
protocolResult.write(this.store.getOutputStream());
|
||||||
} catch (IOException writeException) { // Si SBE fermé
|
} catch (IOException writeException) { // Si SBE fermé
|
||||||
System.out.println("STOPPER");
|
System.out.println("STOPPER");
|
||||||
|
writeException.printStackTrace();
|
||||||
// Envoie au client que la requête n'a pu être traitée
|
// Envoie au client que la requête n'a pu être traitée
|
||||||
alertAvailable(null);
|
alertAvailable(null);
|
||||||
break;
|
break;
|
||||||
@ -103,7 +104,7 @@ public class StoreProcessor extends Thread implements AutoCloseable {
|
|||||||
responseCommand += "\r\n";
|
responseCommand += "\r\n";
|
||||||
ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(context, responseCommand);
|
ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(context, responseCommand);
|
||||||
if (responseResult != null) {
|
if (responseResult != null) {
|
||||||
System.out.println("StoreBackEnd response to client: " + responseResult.getResultCommand());
|
System.out.println("StoreBackEnd (" + domain + ") response to client: " + responseResult.getResultCommand());
|
||||||
responseResult.read(
|
responseResult.read(
|
||||||
this.store.getInputStream()
|
this.store.getInputStream()
|
||||||
);
|
);
|
||||||
@ -207,7 +208,8 @@ public class StoreProcessor extends Thread implements AutoCloseable {
|
|||||||
return Objects.hash(domain);
|
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
|
return this.protocolResult == null; // Vérifier si tâche veut ce SBE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public interface MulticastSPR {
|
|||||||
*/
|
*/
|
||||||
boolean addStore(StoreProcessor store);
|
boolean addStore(StoreProcessor store);
|
||||||
|
|
||||||
String findDomain(Task task);
|
String findDomain();
|
||||||
|
|
||||||
void assignTask(String stor, Task task);
|
void assignTask(String stor, Task task);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import java.io.InputStream;
|
|||||||
*/
|
*/
|
||||||
public class SavefileRule extends ProtocolReader {
|
public class SavefileRule extends ProtocolReader {
|
||||||
// Constants
|
// 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";
|
private static final String NAME = "SAVEFILE";
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ public class SendErrorRule extends ProtocolReader {
|
|||||||
// Constants
|
// Constants
|
||||||
private static final String PATTERN = "^SEND_ERROR\r\n$";
|
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;
|
private final ProtocolRepository protocolRep;
|
||||||
|
|
||||||
|
@ -28,16 +28,22 @@ public class SaveFileErrorRule extends ProtocolWriter {
|
|||||||
@Override
|
@Override
|
||||||
protected ProtocolResult onExecuted(Context context, String... data) {
|
protected ProtocolResult onExecuted(Context context, String... data) {
|
||||||
ProtocolResult result = new ProtocolResult(context);
|
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"));
|
if (fileName != null && fileNameSalt != null) {
|
||||||
try {
|
// Suppression du fichier temporaire dans le stockage du FFE
|
||||||
Files.deleteIfExists(Path.of(
|
ShaHasher hasher = new ShaHasher(context.getLogin() + "_" + fileName);
|
||||||
String.format("%s/%s", this.storagePath,
|
try {
|
||||||
hasher.fromSalt(hasher.saltToByte(context.getDataString("fileNameSalt")))
|
Files.deleteIfExists(Path.of(
|
||||||
)
|
String.format("%s/%s", this.storagePath,
|
||||||
));
|
hasher.fromSalt(hasher.saltToByte(fileNameSalt))
|
||||||
} catch (IOException e) {}
|
)
|
||||||
|
));
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ public class SaveFileOkRule extends ProtocolWriter {
|
|||||||
protected ProtocolWriter.ProtocolResult onExecuted(Context context, String... data) {
|
protected ProtocolWriter.ProtocolResult onExecuted(Context context, String... data) {
|
||||||
ProtocolWriter.ProtocolResult result = new ProtocolWriter.ProtocolResult(context);
|
ProtocolWriter.ProtocolResult result = new ProtocolWriter.ProtocolResult(context);
|
||||||
|
|
||||||
|
System.out.println("===> Save en json " + context.getDomain() + " - " + context.getLogin());
|
||||||
// Sauvegarder dans JSON
|
// Sauvegarder dans JSON
|
||||||
context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataInt("size"), context.getDataString("iv"), context.getDomain());
|
context.addFile(context.getDataString("fileName"), context.getDataString("fileNameSalt"), context.getDataInt("size"), context.getDataString("iv"), context.getDomain());
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
|||||||
*/
|
*/
|
||||||
public void alertStoreProcessors(Task task) {
|
public void alertStoreProcessors(Task task) {
|
||||||
// On avertit les stor processors d'une nouvelle tâche
|
// On avertit les stor processors d'une nouvelle tâche
|
||||||
String stor = storeRepository.findDomain(task);
|
String stor = storeRepository.findDomain();
|
||||||
if (stor != null) {
|
if (stor != null) {
|
||||||
storeRepository.assignTask(stor, task);
|
storeRepository.assignTask(stor, task);
|
||||||
task.setDomain(stor);
|
task.setDomain(stor);
|
||||||
@ -51,9 +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();
|
||||||
System.out.println("Cherche");
|
|
||||||
if (task.isResponseOfClient(store.getDomain())) {
|
if (task.isResponseOfClient(store.getDomain())) {
|
||||||
System.out.println("Task trouvée");
|
|
||||||
clientRepository.respondToClient(task.getClient(), response);
|
clientRepository.respondToClient(task.getClient(), response);
|
||||||
it.remove(); // Suppression de la tâche
|
it.remove(); // Suppression de la tâche
|
||||||
break;
|
break;
|
||||||
@ -73,7 +71,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
|||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Task task = it.next();
|
Task task = it.next();
|
||||||
if (store.canProcessTask(task)) {
|
if (task.getDomain() == null && store.canProcessTask()) {
|
||||||
storeRepository.assignTask(store.getDomain(), task);
|
storeRepository.assignTask(store.getDomain(), task);
|
||||||
task.setDomain(store.getDomain());
|
task.setDomain(store.getDomain());
|
||||||
return;
|
return;
|
||||||
|
@ -31,7 +31,6 @@ public class ProtocolRepositoryImpl implements ProtocolRepository {
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("COMMANDE NULL");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,14 +60,14 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String findDomain(Task task) {
|
public String findDomain() {
|
||||||
StoreProcessor handler = findSBE(task);
|
StoreProcessor handler = findSBE();
|
||||||
return handler == null ? null : handler.getDomain();
|
return handler == null ? null : handler.getDomain();
|
||||||
}
|
}
|
||||||
|
|
||||||
private StoreProcessor findSBE(Task task) {
|
private StoreProcessor findSBE() {
|
||||||
for (StoreProcessor handler : handlers) {
|
for (StoreProcessor handler : handlers) {
|
||||||
if (handler.canProcessTask(task)) {
|
if (handler.canProcessTask()) {
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void assignTask(String stor, Task task) {
|
public void assignTask(String stor, Task task) {
|
||||||
StoreProcessor handler = findSBE(task);
|
StoreProcessor handler = findSBE();
|
||||||
System.out.println("Find stor : " + handler);
|
System.out.println("Find stor : " + handler);
|
||||||
handler.executeCommand(task.getContext(), task.getCommand());
|
handler.executeCommand(task.getContext(), task.getCommand());
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user