public void Post(UnShareFileWithUser request) { logger.Info("****Request received for un-sharing file owned by user : "******" by user : "******" for file name : " + request.filename ); if (!filesystem.AuthenticateUser(request.clientId, request.password)) { throw new AuthenticationException("Authentication failed"); } FileServerComm serverComm = FileServerComm.getInstance(); Address [] memberAdresses = serverComm.getFileServerGroup().getLiveMembers(); List <Address> where = new List <Address> (); where.AddRange(memberAdresses); try { if (true == serverComm.getFileHandler().sendSynchUnShareRequest(request, serverComm.getOOBHandler(), serverComm.getFileServerGroup())) { filesystem.unShareFileWithUser(request.clientId, request.filename, request.sharedWithUser); } else { throw new Exception("Internal Server Error"); } } catch (Exception e) { logger.Warn(e); throw e; } }
public void handleAddUser(object arg) { try { Logger.Debug("Update addUser To Memory Synchronized - Begin"); OOBTransaction request = (OOBTransaction)arg; UserFileSystem fileSystem = null; Group group = FileServerComm.getInstance().getFileServerGroup(); OOBHandler oobhandle = FileServerComm.getInstance().getOOBHandler(); MemoryMappedFile transferredFile = group.OOBFetch(request.transactionID); if (null != transferredFile) { Logger.Debug("AddUser for OOB Fetch Success :)"); int index = 0; fileSystem = oobhandle.deserializeFromMemoryMappedFile(transferredFile, ref index, request.fileLength) as UserFileSystem; Logger.Debug("Received User is " + fileSystem.ToString()); } else { Logger.Debug("AddUser for OOB Fetch Success :("); } group.OOBDelete(request.transactionID); TryReleaseLock(request.initiatedSystemId, request.transactionID); Logger.Debug("Update addUser To Memory Synchronized - End"); } catch (Exception e) { Logger.Debug("Update addUser To Memory Synchronized encountered exception " + e.ToString()); } }
public void Post(DeleteFile request) { logger.Info("****Request received for deleting file : " + request.filepath + " owned by user : "******"Authentication failed"); } FileMetaData metadata = filesystem.getFileMetaDataCloneSynchronized(request.clientId, request.password, request.filepath); FileServerComm serverComm = FileServerComm.getInstance(); Address [] memberAdresses = serverComm.getFileServerGroup().getLiveMembers(); List <Address> where = new List <Address> (); where.AddRange(memberAdresses); if (true == serverComm.getFileHandler().sendsynchdeleteFile(metadata, serverComm.getOOBHandler(), serverComm.getFileServerGroup())) { bool delete = filesystem.deleteFileSynchronized(request.clientId, request.filepath); if (!delete) { logger.Debug("The file : " + request.filepath + " was already marked for deletion, skipping"); } } } catch (Exception e) { logger.Warn(e); throw e; } }
public static FileServerComm getInstance() { if (null == instance) { instance = new FileServerComm(fileServerGroupName); } return(instance); }
public void handleBootStrappingRequestPlaceHolder(object arg) { Logger.Debug("Begin handleBootStrappingRequestPlaceHolder ()"); BootStrappingRequest request = (BootStrappingRequest)arg; handleBootStrappingRequest(FileServerComm.getInstance().getFileServerGroup(), FileServerComm.getInstance().getOOBHandler(), FileServerComm.getInstance().getFileHandler().filesystem, request.RequestName, request.requestNodeAddress); }
public void TryReleaseLock(Address addr, string transactionID) { if (addr.Equals(IsisSystem.GetMyAddress())) { Transaction trans = FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionID); if (null != trans) { trans.signalTransactionEnd(); } } }
public void sendOOBData(Group group, MemoryMappedFile mmf, string FileName, List <Address> where) { group.OOBRegister(FileName, mmf); group.OOBReReplicate(FileName, where, (Action <string, MemoryMappedFile>) delegate(string oobfname, MemoryMappedFile m) { Logger.Debug("Send OOB Finished finished for " + FileName); //Transfer is Complete Now do a Ordered Send, so that the File may be processed //This needs to be ordered, since the all Groups need to see this event in the same wat Transaction trn = FileServerComm.getInstance().transManager.getTransaction(oobfname); trn.signalTransactionEnd(); }); }
/* * This Function is called when a New File Needs to be Added into the memory */ public bool sendsynchaddFileToMemory(string UserName, UserFile file, OOBHandler oobhandle, Group group, List <Address> where) { try { Logger.Debug("File Operations Synch - sendsynchaddFileToMemory >> BEGIN"); bool operationResult = false; MemoryMappedFile transferFile = null; string fileName = FileServerComm.getInstance().transManager.generateTransactionId(UserName + "_" + file.filemetadata.filepath); Transaction trans = new Transaction(fileName); if (true == FileServerComm.getInstance().transManager.insertTransaction(trans)) { try { int writtenBytesLength = 0; transferFile = oobhandle.serializeIntoMemoryMappedFile(fileName, file, ref writtenBytesLength); oobhandle.sendOOBData(group, transferFile, fileName, where); trans.waitTillSignalled(); Logger.Debug("File Operations Synch - sendsynchaddFileToMemory >> OOB Transfer of Data Complete for : " + file.filemetadata.filepath); operationResult = !trans.isTimedOut; OOBTransaction oobtrabs = new OOBTransaction(fileName, IsisSystem.GetMyAddress(), writtenBytesLength); if (operationResult) { group.OrderedSend(FileServerComm.SaveFileToMemory, oobtrabs); trans.waitTillSignalled(); Logger.Debug("File Operations Synch - sendsynchaddFileToMemory >> Ordered Send Complete Complete for : " + file.filemetadata.filepath); operationResult = !trans.isTimedOut; } FileServerComm.getInstance().transManager.removeAndGetTransaction(fileName); operationResult = !trans.isTimedOut; } catch (Exception e) { Logger.Debug("Exception during File Operations Synch - sendsynchaddFileToMemory" + e.ToString()); FileServerComm.getInstance().transManager.removeAndGetTransaction(fileName); operationResult = false; } } else { Logger.Debug("File Operations Synch - sendsynchaddFileToMemory >> Generation of Transaction ID Failed: " + fileName); } return(operationResult); } catch (Exception e) { Logger.Debug("Caught Exception " + e.ToString()); } return(false); }
public void sendBootStrappingRequest(Group group, Address lastSelectedNode) { Address [] liveMembers = group.getLiveMembers(); Address myAddress = IsisSystem.GetMyAddress(); if (liveMembers.Length > 1) { Random rnd = new Random(); int sendNodeIndex = 0; int numTries = 0; do { sendNodeIndex = rnd.Next(0, liveMembers.Length); if (liveMembers [sendNodeIndex].Equals(myAddress)) { continue; } Logger.Debug("Stuck in a Infinite Loop : Length: " + liveMembers.Length); numTries = numTries + 1; break; } while(true); if (numTries != liveMembers.Length) { Logger.Debug("sendBootStrappingRequest Succeeded :). Sending to Address " + liveMembers [sendNodeIndex].ToStringVerboseFormat()); Logger.Debug("My Address is :) " + IsisSystem.GetMyAddress().ToStringVerboseFormat()); BootStrappingRequest request = new BootStrappingRequest(IsisSystem.GetMyAddress(), FileServerComm.getInstance().transManager.generateTransactionId()); state.selectedNode = liveMembers [sendNodeIndex]; state.currState = eBootStrapState.SentBootStrappingBeginRequest; group.RawP2PSend(liveMembers [sendNodeIndex], FileServerComm.BootStrapRequest, request); } else { Logger.Debug("sendBootStrappingRequest Failed :) Try After Backup"); state.selectedNode = lastSelectedNode; state.currState = eBootStrapState.Initialized; state.setBootStrappingTimer(group, this); } } else { Logger.Debug("There are No Live Members Available, Just Continue : " + liveMembers.Length); state.currState = eBootStrapState.BootStrappingComplete; waitBootStrap.Release(); } }
void handleBootStrappingEnd(BootStrappingCheckPoint request) { Logger.Debug("handleBootStrappingEnd , Response received from " + request.nodeAddress.ToStringVerboseFormat()); if (null != state.selectedNode && request.nodeAddress.Equals(state.selectedNode)) { Logger.Debug("handleBootStrappingEnd :)"); state.currState = eBootStrapState.BootStrappingComplete; FileServerComm fileSrvComm = FileServerComm.getInstance(); doDiff(fileSrvComm.getFileHandler().filesystem); state.cancelBootStrappingTimer(); waitBootStrap.Release(); Logger.Debug("handleBootStrappingEnd :) Finally Done"); } else { Logger.Debug("handleBootStrappingEnd, Receieved from Another Node, Some Problem. Ignore this Plz :)"); } }
public bool sendSynchShareRequest(ShareFileWithUser request, OOBHandler handler, Group group, bool waitToFinish = true) { try { Logger.Debug("File Operations Synch - sendSynchShareRequest >> BEGIN"); bool operationResult = false; if (waitToFinish) { string transactionId = FileServerComm.getInstance().transManager.generateTransactionId(request.filename); Transaction trans = new Transaction(transactionId); if (true == FileServerComm.getInstance().transManager.insertTransaction(trans)) { SyncSharedUser sync = new SyncSharedUser(transactionId, IsisSystem.GetMyAddress(), request.clientId, request.password, request.filename, request.sharedWithUser); group.OrderedSend(FileServerComm.ShareWithUser, sync); trans.waitTillSignalled(); FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionId); operationResult = !trans.isTimedOut; } else { Logger.Debug("File Operations Synch - sendsynchdeleteFile >> Generation of Transaction ID Failed: " + transactionId); } } else { SyncSharedUser sync = new SyncSharedUser("", IsisSystem.GetMyAddress(), request.clientId, request.password, request.filename, request.sharedWithUser); group.OrderedSend(FileServerComm.ShareWithUser, sync); operationResult = true; } Logger.Debug("File Operations Synch - sendsynchdeleteFileFromMemory >> END Operation Status " + operationResult); return(operationResult); } catch (Exception e) { Logger.Debug("File Server Creation Failed"); return(false); } }
public void Post(AddUser request) { logger.Info("****Request received for adding user with client id :" + request.clientId + " and password : "******"User is already present in inmemory map, throwing back exception"); throw new Exception("User is already present in memory"); } else { logger.Debug("User added succesfully"); } } catch (Exception e) { logger.Debug(e); throw e; } } else { throw new Exception("User Add Exception"); } }
/* * This Function is to be Called when a Entire User Needs to be Moved */ public bool sendsynchUser(UserFileSystem file, OOBHandler oobhandle, Group group, List <Address> where) { try { Logger.Debug("File Operations Synch - sendsynchUser >> BEGIN"); bool operationResult = false; string fileName = FileServerComm.getInstance().transManager.generateTransactionId(file.metadata.clientId); Transaction trans = new Transaction(fileName); if (true == FileServerComm.getInstance().transManager.insertTransaction(trans)) { try { MemoryMappedFile transferFile = null; int writtenBytesLength = 0; transferFile = oobhandle.serializeIntoMemoryMappedFile(fileName, file, ref writtenBytesLength); OOBTransaction oobtrabs = new OOBTransaction(fileName, IsisSystem.GetMyAddress(), writtenBytesLength); oobhandle.sendOOBData(group, transferFile, fileName, where); trans.waitTillSignalled(); operationResult = !trans.isTimedOut; if (operationResult) { group.OrderedSend(FileServerComm.UpdateUser, oobtrabs); trans.waitTillSignalled(); operationResult = !trans.isTimedOut; } FileServerComm.getInstance().transManager.removeAndGetTransaction(fileName); operationResult = !trans.isTimedOut; } catch (Exception e) { Logger.Debug("Exception during File Operations Synch - sendsynchUser" + e.ToString()); } } return(operationResult); } catch (Exception e) { Logger.Debug("File Operations Synch - sendsynchUser >> Encountered Exception : " + e.ToString()); return(false); } }
public override void Configure(Funq.Container container) { Plugins.Add(new RequestLogsFeature()); this.Config.DefaultContentType = "Json"; //container.RegisterAutoWired<InMemoryFileSystem>(); InMemoryFileSystem fileSystem = new InMemoryFileSystem(); container.Register <InMemoryFileSystem> (fileSystem); Console.WriteLine("Application_Start ---->. Begin"); //Start the ISIS System IsisSystem.Start(); Console.WriteLine("ISIS Started :)"); FileServerComm.fileServerGroupName = "FileServer"; FileServerComm fileSrvComm = FileServerComm.getInstance(); fileSrvComm.getFileHandler().filesystem = fileSystem; System.IO.StreamReader file = new System.IO.StreamReader("bootstrap.txt"); string line = file.ReadLine(); Console.WriteLine(line); bool isBootStrap = false; if (line.Equals("1")) { isBootStrap = true; } fileSrvComm.ApplicationStartup(isBootStrap, FileServerComm.fileServerGroupName); Console.WriteLine("Application_Start. End"); }
/* * This Function is to be called when the File is Deleted from the Users List */ public bool sendsynchdeleteFile(FileMetaData filemetadata, OOBHandler handler, Group group, bool waitToFinish = true) { try { Logger.Debug("File Operations Synch - sendsynchdeleteFile >> BEGIN"); bool operationResult = false; if (waitToFinish) { string transactionId = FileServerComm.getInstance().transManager.generateTransactionId(filemetadata.filepath); Transaction trans = new Transaction(transactionId); if (true == FileServerComm.getInstance().transManager.insertTransaction(trans)) { FileMetaDataSync sync = new FileMetaDataSync(transactionId, IsisSystem.GetMyAddress(), filemetadata); group.OrderedSend(FileServerComm.DeleteFile, sync); trans.waitTillSignalled(); FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionId); operationResult = !trans.isTimedOut; } else { Logger.Debug("File Operations Synch - sendsynchdeleteFile >> Generation of Transaction ID Failed: " + transactionId); } } else { FileMetaDataSync sync = new FileMetaDataSync("", IsisSystem.GetMyAddress(), filemetadata); group.OrderedSend(FileServerComm.DeleteFile, sync); operationResult = true; } Logger.Debug("File Operations Synch - sendsynchdeleteFileFromMemory >> END Operation Status " + operationResult); return(operationResult); } catch (Exception e) { Logger.Debug("File Operations Synch - sendsynchdeleteFile encountered a Excetpion: " + e.ToString()); return(false); } }
/* * This Function is called when a New User Is Added or the Meta Data of the User Needs to be Changed and Synched */ public bool sendsynchUserMetaData(UserMetaData data, OOBHandler handler, Group group, bool waitToFinish = true) { try { Logger.Debug("File Operations Synch - sendsynchUserMetaData >> BEGIN"); bool operationResult = false; if (waitToFinish) { string transactionId = FileServerComm.getInstance().transManager.generateTransactionId(data.clientId); Transaction trans = new Transaction(transactionId); if (true == FileServerComm.getInstance().transManager.insertTransaction(trans)) { UserMetaDataSync sync = new UserMetaDataSync(transactionId, IsisSystem.GetMyAddress(), data); group.OrderedSend(FileServerComm.UpdateUserMetaData, sync); Logger.Debug("File Operations Synch - Making a Ordered Send"); trans.waitTillSignalled(); FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionId); operationResult = !trans.isTimedOut; } else { Logger.Debug("File Operations Synch - sendsynchUserMetaData >> Generation of Transaction ID Failed: " + transactionId); } } else { UserMetaDataSync sync = new UserMetaDataSync("", IsisSystem.GetMyAddress(), data); group.OrderedSend(FileServerComm.UpdateUserMetaData, sync); operationResult = true; } Logger.Debug("File Operations Synch - sendsynchUserMetaData >> END Operation Status " + operationResult); return(operationResult); } catch (Exception e) { Logger.Debug("File Operations Synch - sendsynchUserMetaData threw an Exception " + e.ToString()); return(false); } }
public void Post(UpdateFile request) { logger.Info("****Request received for updating user file for client id : " + request.clientId + " and file name : " + request.file.filemetadata.filepath ); if (!filesystem.AuthenticateUser(request.clientId, request.password)) { throw new AuthenticationException("Authentication failed"); } // Send the File to the All other Nodes in a Ordered Way FileServerComm serverComm = FileServerComm.getInstance(); Address [] memberAdresses = serverComm.getFileServerGroup().getLiveMembers(); List <Address> where = new List <Address>(); where.AddRange(memberAdresses); if (true == serverComm.getFileHandler().sendsynchaddFileToMemory(request.clientId, request.file, serverComm.getOOBHandler(), serverComm.getFileServerGroup(), where)) { try { filesystem.addFileSynchronized(request.clientId, request.file); } catch (Exception e) { logger.Debug("Exception occured while updating user file for client id : " + request.clientId + " and file name : " + request.file.filemetadata.filepath, e); throw e; } } else { throw new Exception("File Cannot be Added, Some Internal error"); } }
/* * Handler Function which Adds a File into Memory */ public void handleAddFileToMemory(object arg) { try { OOBTransaction request = (OOBTransaction)arg; UserFile userfilesys = null; Logger.Debug("Update addFileToMemory Data Synchronized - Begin"); Group group = FileServerComm.getInstance().getFileServerGroup(); OOBHandler oobhandle = FileServerComm.getInstance().getOOBHandler(); MemoryMappedFile transferredFile = group.OOBFetch(request.transactionID); if (null != transferredFile) { Logger.Debug("getUserFileInfo OOB Fetch Success :)"); int index = 0; userfilesys = oobhandle.deserializeFromMemoryMappedFile(transferredFile, ref index, request.fileLength) as UserFile; } else { Logger.Debug("getUserFileInfo Failed Reason: OOB Fetch Failed:)"); } if (!request.initiatedSystemId.Equals(IsisSystem.GetMyAddress()) && null != userfilesys) { filesystem.addFileSynchronized(userfilesys.filemetadata.owner, userfilesys); } group.OOBDelete(request.transactionID); TryReleaseLock(request.initiatedSystemId, request.transactionID); Logger.Debug("Update addFileToMemory Data Synchronized - End"); } catch (Exception e) { Logger.Debug("Update addFileToMemory Data Synchronized encountered an exception " + e.ToString()); } }
public static FileServerComm getInstance() { if (null == instance) { instance = new FileServerComm(fileServerGroupName); } return instance; }
public void handleBootStarppingResponse(BootStrappingResponse response) { FileServerComm.getInstance().getFileHandler().TryReleaseLock(IsisSystem.GetMyAddress(), response.fileName); }
void handleBootStrappingRequest(Group group, OOBHandler oobhandle, InMemoryFileSystem fileSystem, string requestName, Address recvdFrom) { if (state.currState == eBootStrapState.BootStrappingComplete) { Logger.Debug("handleBootStrappingRequest , Received from " + recvdFrom.ToStringVerboseFormat()); BootStrappingCheckPoint initialStage = null; initialStage = new BootStrappingCheckPoint("Boot Strapping Begin", FileServerComm.BootStrapBegin, IsisSystem.GetMyAddress(), SUCCESS, 0); Logger.Debug("Sending a BootStrapping Begin , Response to " + recvdFrom.ToStringVerboseFormat()); group.RawP2PSend(recvdFrom, FileServerComm.BootStrapBegin, initialStage); MemoryMappedFile transferFile = null; int currentUserIndex = 0; int numberOfUsersCurrentBatch = 0; List <string> users = fileSystem.GetInMemoryUserList(); InMemoryFileSystem tempFileSystem = new InMemoryFileSystem(false); //Yayy Lets Begin Doing Some Boot Strapping try { Logger.Debug("Number of Users to BootStrap and Send " + users.Count); while (currentUserIndex < users.Count) { UserFileSystem userfilesys = fileSystem.GetClonedInMemoryUserFileSystem(users [currentUserIndex]); numberOfUsersCurrentBatch++; Logger.Debug("Adding User to the BootStrap : " + users[currentUserIndex]); tempFileSystem.addFSToMapSynchronized(userfilesys, users [currentUserIndex]); currentUserIndex++; if (numberOfUsersCurrentBatch == BatchSize) { //Let's Make a OOB File and Transfer the Data string currentFileName = FileServerComm.getInstance().transManager.generateTransactionId(); bool operationResult = false; numberOfUsersCurrentBatch = 0; Transaction trans = new Transaction(currentFileName); FileServerComm.getInstance().transManager.insertTransaction(trans); int writtenBytesLength = 0; transferFile = oobhandle.serializeIntoMemoryMappedFile(currentFileName, tempFileSystem, ref writtenBytesLength); BootStrappingCheckPoint continueBootStrap = null; continueBootStrap = new BootStrappingCheckPoint(currentFileName, FileServerComm.BootStrapContinue, IsisSystem.GetMyAddress(), SUCCESS, writtenBytesLength); List <Address> where = new List <Address>(); where.Add(recvdFrom); where.Add(IsisSystem.GetMyAddress()); oobhandle.sendOOBData(group, transferFile, currentFileName, where); trans.waitTillSignalled(); operationResult = !trans.isTimedOut; if (operationResult) { group.RawP2PSend(recvdFrom, FileServerComm.BootStrapContinue, continueBootStrap); trans.waitTillSignalled(); operationResult = !trans.isTimedOut; } else { Logger.Debug("Sending BootStraping Request Timed Out, Quit Out of BootStrapping partcicipation"); return; } tempFileSystem = new InMemoryFileSystem(); } } //Lets Throw out the Remaining Users if (numberOfUsersCurrentBatch != 0) { string currentFileName = FileServerComm.getInstance().transManager.generateTransactionId(); Transaction trans = new Transaction(currentFileName); FileServerComm.getInstance().transManager.insertTransaction(trans); bool currentOperationResult = false; int writtenBytesLength = 0; transferFile = oobhandle.serializeIntoMemoryMappedFile(currentFileName, tempFileSystem, ref writtenBytesLength); BootStrappingCheckPoint _continue = null; _continue = new BootStrappingCheckPoint(currentFileName, FileServerComm.BootStrapContinue, IsisSystem.GetMyAddress(), SUCCESS, writtenBytesLength); List <Address> where = new List <Address>(); where.Add(recvdFrom); where.Add(IsisSystem.GetMyAddress()); oobhandle.sendOOBData(group, transferFile, currentFileName, where); trans.waitTillSignalled(); currentOperationResult = !trans.isTimedOut; if (currentOperationResult) { group.RawP2PSend(recvdFrom, FileServerComm.BootStrapContinue, _continue); trans.waitTillSignalled(); currentOperationResult = !trans.isTimedOut; } else { Logger.Debug("Sending BootStraping Request Timed Out, Quit Out of BootStrapping partcicipation"); return; } tempFileSystem = new InMemoryFileSystem(); numberOfUsersCurrentBatch = 0; } Logger.Debug("Sending a Boot Strap End Response to " + recvdFrom.ToString()); BootStrappingCheckPoint finalStage = null; finalStage = new BootStrappingCheckPoint("Yayyy Finally Done", FileServerComm.BootStrapEnd, IsisSystem.GetMyAddress(), SUCCESS, 0); group.RawP2PSend(recvdFrom, FileServerComm.BootStrapEnd, finalStage); return; } catch (Exception e) { Logger.Debug("Caught an Exception : " + e.ToString()); BootStrappingCheckPoint _exception = null; _exception = new BootStrappingCheckPoint(e.ToString(), FileServerComm.BootStrapException, IsisSystem.GetMyAddress(), FAILURE, 0); group.P2PSend(recvdFrom, FileServerComm.BootStrapException, _exception); return; } } else { Logger.Debug("Node is Not in the State of Boot Strapping, Ignore this Request and Keep Calm"); } }