Esempio n. 1
0
        /*
         * The Handler Function which handles the User Meta Data Change
         */
        public bool handleUserMetaData(UserMetaDataSync request)
        {
            try {
                Logger.Debug("handleFileUserMetaData - Begin");

                if (request.initiatedSystemId.Equals(IsisSystem.GetMyAddress()))
                {
                    TryReleaseLock(request.initiatedSystemId, request.transactionID);
                    Logger.Debug("handleFileUserMetaData - End");
                    return(true);
                }

                UserMetaData userdata = new UserMetaData(request.clientId, request.password, request.versionNumber, 0);

                try {
                    filesystem.updateMetadataSynchronized(userdata);
                    TryReleaseLock(request.initiatedSystemId, request.transactionID);
                    Logger.Debug("handleFileUserMetaData - End");
                } catch (UserNotLoadedInMemoryException e) {
                    Logger.Debug("Exception: " + e.ToString());
                    filesystem.addUserSynchronized(request.clientId, request.password);
                    TryReleaseLock(request.initiatedSystemId, request.transactionID);
                    Logger.Debug("handleFileUserMetaData - End");
                }
                return(true);
            } catch (Exception e) {
                Logger.Debug("handleUserMetaData Encountered an exception " + e.ToString());
                return(false);
            }
        }
Esempio n. 2
0
        void handleBootStrappingContinue(BootStrappingCheckPoint request, Group group, OOBHandler oobhandle)
        {
            Logger.Debug("handleBootStrappingContinue , Response received from " + request.nodeAddress.ToStringVerboseFormat());
            int bootStrapStatus    = SUCCESS;
            int numberOfUsersAdded = 0;

            if (null != state.selectedNode && request.nodeAddress.Equals(state.selectedNode))
            {
                Logger.Debug("handleBootStrapping Continue :)");

                state.currState = eBootStrapState.ReceivingData;
                MemoryMappedFile transferredFile = group.OOBFetch(request.fileName);

                if (transferredFile != null)
                {
                    Logger.Debug("File" + request.fileName + "request Transfer Successfull!");
                    try
                    {
                        int index = 0;
                        InMemoryFileSystem tempFileSystem = null;
                        tempFileSystem = oobhandle.deserializeFromMemoryMappedFile(transferredFile, ref index, request.dataLength) as InMemoryFileSystem;

                        List <string> users = tempFileSystem.GetInMemoryUserList();
                        numberOfUsersAdded = users.Count;

                        foreach (string user in users)
                        {
                            UserFileSystem userfilesys = tempFileSystem.GetClonedInMemoryUserFileSystem(user);
                            if (null != userfilesys)
                            {
                                fileSystem.addFSToMapSynchronized(userfilesys, user);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Debug("Exception Encountered : " + e.ToString());
                        bootStrapStatus = FAILURE;
                    }
                }
                else
                {
                    Logger.Debug("File" + request.fileName + "was Deleted!");
                    bootStrapStatus = FAILURE;
                }

                Logger.Debug("handleBootStrapping Added :)" + numberOfUsersAdded + " Users");
                group.OOBDelete(request.fileName);

                BootStrappingResponse response = null;
                response = new BootStrappingResponse(request.fileName, IsisSystem.GetMyAddress(), bootStrapStatus);

                group.P2PSend(request.nodeAddress, FileServerComm.BootStrapResponse, response);
            }
            else
            {
                Logger.Debug("handleBootStrappingContinue, Receieved from Another Node, Some Problem. Ignore this Plz :)");
            }
        }
        public IsisNodeCoordinator()
        {
            IsisSystem.Start();

            _queryHandlersByMessageId.Add((uint)MessageId.ConnectionRequest, OnConnectRequest);

            _broadcastsHandlersByMessageId.Add((uint)MessageId.Empty, message => Log.Info("Received empty message"));
        }
Esempio n. 4
0
 public void TryReleaseLock(Address addr, string transactionID)
 {
     if (addr.Equals(IsisSystem.GetMyAddress()))
     {
         Transaction trans = FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionID);
         if (null != trans)
         {
             trans.signalTransactionEnd();
         }
     }
 }
Esempio n. 5
0
        /*
         *      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 string generateTransactionId()
        {
            string transactionID;

            lock (this.privateLock) {
                Address addr = IsisSystem.GetMyAddress();
                transactionID  = addr.ToString();
                transactionID += "_" + this.sequenceNumber;
                transactionID += "_" + DateTime.Now.ToFileTimeUtc();
                this.sequenceNumber++;
            }
            return(transactionID);
        }
Esempio n. 7
0
        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();
            }
        }
Esempio n. 8
0
        void ApplicationStartFileServerComm(bool isBootStrap, String fileServerGroupName)
        {
            Logger.Debug("ApplicationStartFileServerComm ---->. Begin " + isBootStrap);
            Thread fileServerCommThread = new Thread(delegate()
            {
                Logger.Debug("ApplicationStartFileServerComm. Begin");
                registerBootStrapHandlers();
                registerFileOperationHandlers();

                Msg.RegisterType(typeof(BootStrappingCheckPoint), BootStrapBegin);
                Msg.RegisterType(typeof(BootStrappingCheckPoint), BootStrapContinue);
                Msg.RegisterType(typeof(BootStrappingCheckPoint), BootStrapEnd);
                Msg.RegisterType(typeof(BootStrappingRequest), BootStrapRequest);
                Msg.RegisterType(typeof(BootStrappingResponse), BootStrapResponse);

                Msg.RegisterType(typeof(UserMetaDataSync), UpdateUserMetaData);
                Msg.RegisterType(typeof(FileMetaDataSync), UpdateFileMetaData);
                Msg.RegisterType(typeof(FileMetaDataSync), DeleteFileFromMemory);
                Msg.RegisterType(typeof(FileMetaDataSync), DeleteFile);
                Msg.RegisterType(typeof(OOBTransaction), SaveFileToMemory);
                Msg.RegisterType(typeof(OOBTransaction), UpdateUser);

                Msg.RegisterType(typeof(SyncSharedUser), ShareWithUser);
                Msg.RegisterType(typeof(SyncUnSharedUser), UnshareWithUser);


                fileServerGroup.ViewHandlers += (Isis.ViewHandler) delegate(View v)
                {
                    Logger.Debug("myGroup got a new view event: " + v);
                };

                fileServerGroup.Join();

                if (isBootStrap)
                {
                    Logger.Debug("Need to do BootStrapping :), So I'll do BootStrapping");
                    bootstrap.sendBootStrappingRequest(fileServerGroup, null);
                }
                else
                {
                    Logger.Debug("Do not Need to Do BootStrapping. Start the Application Server");
                    bootstrap.state.currState = eBootStrapState.BootStrappingComplete;
                    bootstrap.waitBootStrap.Release();
                }

                IsisSystem.WaitForever();
                Logger.Debug("ApplicationStartFileServerComm. End");
            });

            fileServerCommThread.Start();
        }
Esempio n. 9
0
 public bool handleUnshareRequest(SyncUnSharedUser request)
 {
     Logger.Debug("handleUnshareRequest - Begin");
     if (request.initiatedSystemId.Equals(IsisSystem.GetMyAddress()))
     {
         TryReleaseLock(request.initiatedSystemId, request.transactionID);
         Logger.Debug("handleUnshareRequest - End");
         return(true);
     }
     try {
         filesystem.unShareFileWithUser(request.clientId, request.filename, request.sharedWithUser);
     } catch (Exception e) {
         Logger.Debug("Exception : " + e.ToString());
     }
     Logger.Debug("handleUnshareRequest - End");
     return(true);
 }
Esempio n. 10
0
        protected void Application_Start(Object sender, EventArgs e)
        {
            Semaphore sem = new Semaphore(0, 1);
            Thread lbFileServerGroupThread = new Thread(delegate()
            {
                //Start the ISIS System
                IsisSystem.Start();

                string groupName        = "FS1";
                string logicalGroupName = "lbalancer-" + groupName;

                fileServerGroupList.TryAdd(logicalGroupName, new FileServerGroupObject());

                Group lbfsgroup = new Group(logicalGroupName);

                lbfsgroup.ViewHandlers += (ViewHandler) delegate(View v)
                {
                    Console.WriteLine("myGroup got a new view event: " + v);

                    Address [] addList = v.GetLiveMembers();
                    for (Int32 index = 0; index < addList.Length; index++)
                    {
                        Isis.WriteLine("The Add List Address " + addList[index].ToStringVerboseFormat());
                        fileServerGroupList[logicalGroupName].addToFileServerList(addList[index]);
                    }

                    Address [] removeList = v.GetFailedMembers();
                    for (Int32 index = 0; index < removeList.Length; index++)
                    {
                        fileServerGroupList[logicalGroupName].removeFromFileServerList(removeList[index]);
                    }
                };

                lbfsgroup.Join();
                sem.Release();
                IsisSystem.WaitForever();
            });

            lbFileServerGroupThread.Start();
            sem.WaitOne();
            Isis.WriteLine("Starting Web Service on the LoadBalancer");

            new AppHost().Init();
        }
Esempio n. 11
0
        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);
            }
        }
Esempio n. 12
0
        /*
         * 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);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 3)
                {
                    int setlocal  = int.Parse(args[0]);
                    int setlocal_ = int.Parse(args[1]);
                    local.Port  = setlocal;
                    local_.Port = setlocal_;
                    Console.WriteLine("Local port has been set to " + setlocal + " and " + setlocal_);
                    bootstrap = args[2];
                }
                else if (args.Length == 1)
                {
                    bootstrap = args[0];
                }

                // Set up local UDP communication with web front
                string ip = NetSetup();

                // TODO: add logic to retrieve oracle information from bootstrap server

                // Set up runtime environments
                Environment.SetEnvironmentVariable("ISIS_TCP_ONLY", "true");


                IsisSystem.Start();
                Console.WriteLine("IsisSystem started");
                smallGroup = new SmallGroup("Azure Group");
                smallGroup.Join();
                Console.WriteLine("Azure group joined");
                Thread.Sleep(15 * 1000);

                IsisSystem.WaitForever();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 14
0
        /*
         * Handler Function which Deletes a File and Marks it for Deletion if Required
         */
        public bool handleDeleteFile(FileMetaDataSync request)
        {
            try {
                Logger.Debug("handleDeleteFile - Begin");
                TryReleaseLock(request.initiatedSystemId, request.transactionID);

                if (!request.initiatedSystemId.Equals(IsisSystem.GetMyAddress()))
                {
                    bool delete = filesystem.deleteFileSynchronized(request.owner, request.filepath);

                    if (!delete)
                    {
                        Logger.Debug("The file : " + request.filepath + " was already marked for deletion, skipping");
                    }
                }
                Logger.Debug("handleDeleteFile - End");
                return(true);
            } catch (Exception e) {
                Logger.Debug("handleDeleteFile Encountered an Exception " + e.ToString());
                return(false);
            }
        }
Esempio n. 15
0
        /*
         * 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);
            }
        }
Esempio n. 16
0
            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");
            }
Esempio n. 17
0
        /*
         * 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);
            }
        }
        static void MonitorStart()
        {
            if (monitor == null)
            {
                monitor = new Thread(delegate()
                {
                    while (true)
                    {
                        if (!sending)
                        {
                            string state = IsisSystem.GetMyAddress().ToString() + " " + IsisSystem.NOW();
                            Console.WriteLine("Get time " + state);
                            Byte[] tosend = Encoding.ASCII.GetBytes(state);
                            try
                            {
                                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                                sending = true;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        }
                        Thread.Sleep(5 * 1000);
                    }
                });
                monitor.Name = "Monitor Thread";
                monitor.Start();
            }
            else
            {
                monitor.Resume();
            }

            Console.WriteLine("Monitor Thread running");
        }
Esempio n. 19
0
        /*
         * 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());
            }
        }
        private Message OnConnectRequest(Message msg)
        {
            Contract.Requires(msg is ConnectRequest);
            var connectMsg = msg as ConnectRequest;

            Log.Info("Received OnConnectRequest with {0}", connectMsg.Info);

            var isisAddr = _lastIsisView.GetLiveMembers().FirstOrDefault(x => (ulong)x.GetHashCode() == connectMsg.Info.NodeId);

            if (isisAddr != null)
            {
                if (isisAddr.Equals(IsisSystem.GetMyAddress()))
                {
                    return(new ConnectReply {
                        Info = _node.Info
                    });
                }
                else
                {
                    _nodesByIsisAddress.Add(isisAddr, connectMsg.Info);
                    _onClusterViewChanged.OnNext(new ClusterView(_lastIsisView.viewid,
                                                                 (ulong)_lastIsisView.members.First().GetHashCode(),
                                                                 _nodesByIsisAddress.Values.ToImmutableList(),
                                                                 ImmutableList <NodeRemoteInfo> .Empty.Add(connectMsg.Info),
                                                                 ImmutableList <NodeRemoteInfo> .Empty));
                    return(new ConnectReply {
                        Info = _node.Info
                    });
                }
            }
            else
            {
                Log.Warn("Received connect from non group member " + connectMsg.Info);
                return(new InvalidOperation((ushort)BasicErrorCode.NonAuthorized, "Received connect from non group member"));
            }
        }
 public ulong GenerateNodeId()
 {
     return((ulong)IsisSystem.GetMyAddress().GetHashCode());
 }
        static void Main(string[] args)
        {
            Logger Log = LogManager.GetLogger("ConsoleHost");


            Log.Info("Starting ISIS");
            var coordinator = new IsisNodeCoordinator();

            IPEndPoint externalEndpoint = null;
            IPEndPoint internalEndpoint = null;

            try
            {
                if (args.Length == 2)
                {
                    string[] addrPort = args[0].Split(':');
                    externalEndpoint = new IPEndPoint(IPAddress.Parse(addrPort[0]), int.Parse(addrPort[1]));
                    addrPort         = args[1].Split(':');
                    internalEndpoint = new IPEndPoint(IPAddress.Parse(addrPort[0]), int.Parse(addrPort[1]));
                }
                else
                {
                    externalEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5055);
                    internalEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5056);
                }
            }
            catch (Exception)
            {
                Log.Error("incorrect cmd params - expected:  externalIp:port internalIp:port");
            }

            var builder = new ContainerBuilder();

            //register core messages
            builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(EmptyMessage)))
            .Where(x => x.IsAssignableTo <Message>() && x != typeof(Message))
            .As <Message>();

            //register domain messages
            builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(IChatLogin)))
            .Where(x => x.IsAssignableTo <Message>() && x != typeof(Message))
            .As <Message>();

            //register domain service definitions and proxies
            builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(IChatLogin)))
            .Where(x => x.IsAssignableTo <NetProxy>() && x != typeof(NetProxy))
            .As <NetProxy>();

            //register domain service implementations
            builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(UserManager)))
            .Where(x => x.IsAssignableTo <Actor>() && x != typeof(Actor))
            .As <Actor>();

            builder.RegisterType <OperationDispatcher>().As <IOperationDispatcher>().SingleInstance();
            builder.RegisterType <ActorRepository>().As <IActorRepository>().SingleInstance();
            builder.RegisterType <MessageFactory>().As <IMessageFactory>().SingleInstance();

            var externalNetConf = new NetPeerConfiguration("ChatApp")
            {
                ConnectionTimeout = 30,
                Port         = externalEndpoint.Port,
                LocalAddress = externalEndpoint.Address
            };
            var internalNetConf = new NetPeerConfiguration("ChatApp")
            {
                ConnectionTimeout = 30,
                Port         = internalEndpoint.Port,
                LocalAddress = internalEndpoint.Address
            };

            builder.Register(c => new ServerNode(
                                 new LidgrenNetProvider(externalNetConf),
                                 new LidgrenNetProvider(internalNetConf),
                                 coordinator,
                                 c.Resolve <IMessageFactory>(), c.Resolve <IOperationDispatcher>(), c.Resolve <IActorRepository>(), () => new ChatClient()))
            .As <IServerNode>().SingleInstance();

            var container = builder.Build();

            var node = container.Resolve <IServerNode>();

            node.Start();

            IsisSystem.WaitForever();
        }
 public void Stop()
 {
     IsisSystem.Shutdown();
 }
Esempio n. 24
0
 public void handleBootStarppingResponse(BootStrappingResponse response)
 {
     FileServerComm.getInstance().getFileHandler().TryReleaseLock(IsisSystem.GetMyAddress(), response.fileName);
 }
Esempio n. 25
0
        public static int memPortNum = 9999;                 //memcached port number

        public static void createGroup(int nNum, int sSize, int mRank)
        {
            nodeNum   = nNum;
            shardSize = sSize;
            myRank    = mRank;

            timeout = new Isis.Timeout(15000, Isis.Timeout.TO_FAILURE);

            IsisSystem.Start();
            if (isVerbose)
            {
                Console.WriteLine("Isis system started!");
            }

//            shardSize = 1;
            shardGroup = new Isis.Group[shardSize];


            int groupNum = myRank;

//            groupNum /= sSize;

            for (int i = 0; i < shardSize; i++)
            {
                shardGroup[i] = new Isis.Group("group" + groupNum);
                groupNum--;
                if (groupNum < 0)
                {
                    groupNum += nodeNum;
                }
            }

            for (int i = 0; i < shardSize; i++)
            {
                int local = i;

                //Insert handler
                shardGroup[i].Handlers[INSERT] += (insert) delegate(string command, int rank) {
                    if (isVerbose)
                    {
                        Console.WriteLine("Got a command {0}", command);
                        Console.WriteLine("Rank is {0}", rank);
                    }

                    if (shardGroup[local].GetView().GetMyRank() == rank)
                    {
                        if (isVerbose)
                        {
                            Console.WriteLine("Got a message from myself!");
                        }
                        //shardGroup[local].Reply("Yes");
                    }
                    else
                    {
                        string ret = talkToMem(command, INSERT);
                        if (ret == "STORED")
                        {
                            //shardGroup[local].Reply("Yes");
                        }
                        else
                        {
                            //shardGroup[local].Reply("No");
                        }
                    }
                };

                //Get handler
                shardGroup[i].Handlers[GET] += (query) delegate(string command, int rank) {
                    if (isVerbose)
                    {
                        Console.WriteLine("Got a command {0}", command);
                    }
                    if (shardGroup[local].GetView().GetMyRank() == rank)
                    {
                        if (isVerbose)
                        {
                            Console.WriteLine("Got a message from myself!");
                        }
                        shardGroup[local].Reply("END\r\n");                         //Definitely not presented in local memcached!
                    }
                    else
                    {
                        string ret = talkToMem(command, GET);
                        shardGroup[local].Reply(ret);
                    }
                };

                //View handler
                shardGroup[i].ViewHandlers += (Isis.ViewHandler) delegate(View v) {
                    if (isVerbose)
                    {
                        Console.WriteLine("Got a new view {0}" + v);
                        Console.WriteLine("Group {0} has {1} members", local, shardGroup[local].GetView().GetSize());
                    }
                };
            }

            for (int i = 0; i < shardSize; i++)
            {
                shardGroup[i].Join();
            }

            is_Started = 1;
            IsisSystem.WaitForever();
        }
Esempio n. 26
0
        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");
            }
        }
        static void OnReceive(IAsyncResult ar)
        {
            Byte[] receiveBytes  = receiver.EndReceive(ar, ref web_);
            string receiveString = Encoding.ASCII.GetString(receiveBytes);

            Console.WriteLine("Received: {0}", receiveString);

            switch (receiveString.ToLower())
            {
            case "monitor":
                if (!monitoring)
                {
                    MonitorStart();
                    monitoring = true;
                }
                break;

            case "stop":
                if (monitoring)
                {
                    monitor.Suspend();
                    monitoring = false;
                }
                break;

            case "address":
            {
                string address = IsisSystem.GetMyAddress().ToStringVerboseFormat();
                Byte[] tosend  = Encoding.ASCII.GetBytes(address);
                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                sending = true;
            }
            break;

            case "members":
            {
                Address[] mems    = smallGroup.GetView().members;
                string    members = "Members: ";
                foreach (Address mem in mems)
                {
                    members += mem.ToStringVerboseFormat() + "|";
                }
                Byte[] tosend = Encoding.ASCII.GetBytes(members);
                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                sending = true;
            }
            break;

            case "query":
            {
                rankList.Clear();
                int    nr     = smallGroup.Query(Group.ALL, SmallGroup.myTO, SmallGroup.COUNT, 1, "Query", SmallGroup.myEOL, rankList);
                string result = nr.ToString() + " returns: ";
                int    total  = 0;
                foreach (int count in rankList)
                {
                    result += "| " + count;
                    total  += count;
                }
                result += "| Total processors: " + total;
                Console.WriteLine(result);
                Byte[] tosend = Encoding.ASCII.GetBytes(result);
                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                sending = true;
            }
            break;

            default:
            {
                Byte[] tosend = Encoding.ASCII.GetBytes("Wrong command, Isis cannot handle");
                sender.BeginSend(tosend, tosend.Length, web, new AsyncCallback(OnSend), ss);
                sending = true;
            }
            break;
            }

            receiver.BeginReceive(new AsyncCallback(OnReceive), rs);
        }
Esempio n. 28
0
        //public Dictionary<string, Dictionary<string, string>> entity = new Dictionary<string, Dictionary<string, string>>();

        public static void Isis_Start()
        {
            IsisSystem.Start();
            g = new Group("pb476_cs5412");
            int myRank = 0;


            g.ViewHandlers += (ViewHandler) delegate(View v)
            {
                IsisSystem.WriteLine("New View: " + v);
                myRank = v.GetMyRank();

                if (v.members.Length == 5)
                {
                    go.Release(1);
                }
            };
            g.Handlers[UPDATE] += (Action <string, string, string>) delegate(string key, string value, string attkey)
            {
                Dictionary <string, string> attr = new Dictionary <string, string>();
                if (value == "null")
                {
                    entity.Remove(key);
                }
                else if (entity.ContainsKey(key))
                {
                    entity[key] = attr;
                    attr[key]   = attkey;
                }
                else
                {
                    entity.Add(key, attr);
                }
                //collection cp = new collection();
                CS5412_Service cp = new CS5412_Service();
                cp.Set(key, value, attkey);
                IsisSystem.WriteLine("New collection: " + key + "/" + value + "/" + attkey);
            };
            g.Handlers[LOOKUP] += (Action <string>) delegate(string key)
            {
                Dictionary <string, string> attr = new Dictionary <string, string>();
                string result = null;
                //attr = entity;

                if (entity.ContainsKey(key))
                {
                    result = attr[key];
                }


                IsisSystem.WriteLine("=== Query for arg=" + key + "Result" + result);

                /*List<string> answer = new List<string>();
                 * //foreach (collection tp in database)
                 *  if (Get(key) == key)
                 *  {
                 *      IsisSystem.WriteLine("Including " + Get(key) + "/" + GetType());
                 *      answer.Add(Get(key));
                 *  }*/

                g.Reply(result);
            };
            g.Join();
            IsisSystem.WriteLine("Time elapsed is " + stopwatch.Elapsed);

            IsisSystem.WriteLine("Wait until database is full!");
            dbFull.WaitOne();
            IsisSystem.WriteLine("Database is fully populated!");
        }