Ejemplo n.º 1
0
        public ClientProto.StatusResponse MoveFile(ClientProto.DoublePath doublePath)
        {
            try
            {
                string path      = doublePath.Fullpath;
                string newPath   = doublePath.Newpath;
                string oldName   = TraverseFileSystem(path);
                Folder oldFolder = CurrentDirectory;

                string newName = TraverseFileSystem(newPath);

                FileSystem.File toBeMoved = oldFolder.files[oldName];

                oldFolder.files.Remove(oldName);
                toBeMoved.name = newName;
                toBeMoved.path = $"{CurrentDirectory.path}/{newName}";
                CurrentDirectory.files.Add(newName, toBeMoved);
                SaveFileDirectory();
                return(new ClientProto.StatusResponse {
                    Type = ClientProto.StatusResponse.Types.StatusType.Success
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(new ClientProto.StatusResponse {
                    Type = ClientProto.StatusResponse.Types.StatusType.Fail, Message = "Internal Server Failure"
                });
            }
        }
Ejemplo n.º 2
0
        public ClientProto.StatusResponse CreateFile(ClientProto.Path fullPath)
        {
            // Wrap in try block, if fails then returns false
            try
            {
                // If a file exists, fail the execution
                if (FileExists(fullPath.FullPath))
                {
                    return(new ClientProto.StatusResponse {
                        Type = ClientProto.StatusResponse.Types.StatusType.FileExists
                    });
                }

                // Creates the file
                FileSystem.File file = new FileSystem.File();
                file.name = TraverseFileSystem(fullPath.FullPath);
                file.path = fullPath.FullPath;

                // Saves to file system
                CurrentDirectory.files.Add(file.name, file);
                SaveFileDirectory();
                //It done did it
                return(new ClientProto.StatusResponse {
                    Type = ClientProto.StatusResponse.Types.StatusType.Ok
                });
            }
            catch (Exception e)
            {
                // Logs the error to console
                Console.WriteLine(e.Message);
                return(new ClientProto.StatusResponse {
                    Type = ClientProto.StatusResponse.Types.StatusType.Fail
                });
            }
        }
Ejemplo n.º 3
0
        public ClientProto.BlockMessage ReadFile(ClientProto.Path wrappedPath)
        {
            try
            {
                string path = wrappedPath.FullPath;
                // Breaks up the path variable into the path's segments
                string name = TraverseFileSystem(path);

                // Grabs the parent directory
                FileSystem.File toBeRead = CurrentDirectory.files[name];

                List <ClientProto.BlockInfo> blockInfos = new List <ClientProto.BlockInfo>();

                List <string> ipAddresses;

                //checks block ids based on the file requested
                foreach (Guid blockID in toBeRead.data)
                {
                    //cross references those against the list of ids to ips
                    //choose ips for each block of the file
                    ipAddresses = BlockID_To_ip[blockID];

                    blockInfos.Add(new ClientProto.BlockInfo {
                        BlockId = new ClientProto.UUID {
                            Value = blockID.ToString()
                        },
                        BlockSize = Constants.MaxBlockSize,
                        IpAddress = { ipAddresses }
                    });
                }

                //send back to client the ips and what to search for on the datanode
                return(new ClientProto.BlockMessage {
                    BlockInfo = { blockInfos },
                    FileSize = toBeRead.fileSize,
                    Type = ClientProto.BlockMessage.Types.StatusType.Success
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(new ClientProto.BlockMessage {
                    BlockInfo = { new List <ClientProto.BlockInfo>() },
                    FileSize = 0,
                    Type = ClientProto.BlockMessage.Types.StatusType.Fail
                });
            }
        }
Ejemplo n.º 4
0
 public ClientProto.StatusResponse DeleteFile(ClientProto.Path wrappedPath)
 {
     try
     {
         string          path        = wrappedPath.FullPath;
         string          name        = TraverseFileSystem(path);
         FileSystem.File toBeDeleted = CurrentDirectory.files[name];
         //queue up requests for each of the datanodes that have blocks
         //      to delete as soon as they send in heartbeat/block report
         foreach (Guid blockID in toBeDeleted.data)
         {
             foreach (string ipAddress in BlockID_To_ip[blockID])
             {
                 DataNodeManager.Instance.AddRequestToNode(ipAddress, new DataNodeProto.BlockCommand
                 {
                     Action    = DataNodeProto.BlockCommand.Types.Action.Delete,
                     BlockList = new DataNodeProto.BlockList
                     {
                         BlockId = { new DataNodeProto.UUID {
                                         Value = blockID.ToString()
                                     } }
                     }
                 });
             }
             BlockID_To_ip.Remove(blockID);
         }
         //remove file from directory system
         CurrentDirectory.files.Remove(name);
         SaveFileDirectory();
         return(new ClientProto.StatusResponse {
             Type = ClientProto.StatusResponse.Types.StatusType.Success
         });
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(new ClientProto.StatusResponse {
             Type = ClientProto.StatusResponse.Types.StatusType.Fail
         });
     }
 }
Ejemplo n.º 5
0
        public ClientProto.ListOfNodesList ListDataNodesStoringReplicas(ClientProto.Path wrappedPath)
        {
            try
            {
                string path = wrappedPath.FullPath;
                //cross reference file name to block ids and locations
                string name = TraverseFileSystem(path);

                List <string>   responseLocations = new List <string>();
                FileSystem.File requestedFile     = CurrentDirectory.files[name];

                List <ClientProto.ListOfNodes> responseList = new List <ClientProto.ListOfNodes>();


                //queue up requests for each of the datanodes that have blocks
                //      to delete as soon as they send in heartbeat/block report
                foreach (Guid blockID in requestedFile.data)
                {
                    List <string> ips = new List <string>();
                    foreach (string ipAddress in BlockID_To_ip[blockID])
                    {
                        ips.Add(ipAddress);
                    }
                    responseList.Add(new ClientProto.ListOfNodes {
                        BlockId = blockID.ToString(), NodeId = { ips }
                    });
                }
                return(new ClientProto.ListOfNodesList {
                    ListOfNodes = { responseList }, Type = ClientProto.ListOfNodesList.Types.StatusType.Success
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(new ClientProto.ListOfNodesList {
                    ListOfNodes = { new List <ClientProto.ListOfNodes>() },
                    Type = ClientProto.ListOfNodesList.Types.StatusType.FileDoesNotExist, Message = "Specified File Not Found."
                });
            }
        }
Ejemplo n.º 6
0
        public ClientProto.BlockInfo AddBlockToFile(ClientProto.BlockInfo addedBlock)
        {
            try
            {
                string          path = addedBlock.FullPath;
                string          name = TraverseFileSystem(path);
                FileSystem.File file = CurrentDirectory.files[name];
                file.fileSize += addedBlock.BlockSize;

                // to be used to send back a write request to the client
                List <string> responseRequests = new List <string>();

                // stores blockID and adds it to the file.
                Guid id = Guid.Parse(addedBlock.BlockId.Value);
                if (!file.data.Contains(id))
                {
                    file.data.Add(id);
                }

                List <string> ipAddresses = DataNodeManager.Instance.GetDataNodesForReplication();

                // add it to the BlockID to DataNode Dictionary
                BlockID_To_ip.TryAdd(id, new List <string>());
                SaveFileDirectory();
                return(new ClientProto.BlockInfo {
                    BlockId = new ClientProto.UUID {
                        Value = id.ToString()
                    }, FullPath = path, BlockSize = addedBlock.BlockSize, IpAddress = { ipAddresses }
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }