packages feed

Holumbus-Storage 0.0.1 → 0.1.0

raw patch · 21 files changed

+1071/−90 lines, 21 filesdep +randomdep ~Holumbus-Distributiondep ~basenew-component:exe:StorageControllerDaemonnew-component:exe:StorageNodeDaemonPVP ok

version bump matches the API change (PVP)

Dependencies added: random

Dependency ranges changed: Holumbus-Distribution, base

API changes (from Hackage documentation)

+ Holumbus.FileSystem.Controller: createFiles :: (ControllerClass c) => [(FileId, IdType)] -> c -> IO ()
+ Holumbus.FileSystem.Controller: getNearestNodePortForFiles :: (ControllerClass c) => [(FileId, Integer)] -> SiteId -> c -> IO ClientPortMap
+ Holumbus.FileSystem.Controller: getNearestNodePortWithFiles :: (ControllerClass c) => [FileId] -> SiteId -> c -> IO ClientPortMap
+ Holumbus.FileSystem.FileSystem: createFiles :: [(FileId, FileContent)] -> FileSystem -> IO ()
+ Holumbus.FileSystem.FileSystem: getMultiFileContent :: [FileId] -> FileSystem -> IO [(FileId, FileContent)]
+ Holumbus.FileSystem.Messages: CReqCreateS :: [(FileId, NodeId)] -> ControllerRequestMessage
+ Holumbus.FileSystem.Messages: CReqGetNearestNodePortForFiles :: [(FileId, Integer)] -> SiteId -> ControllerRequestMessage
+ Holumbus.FileSystem.Messages: CReqGetNearestNodePortWithFiles :: [FileId] -> SiteId -> ControllerRequestMessage
+ Holumbus.FileSystem.Messages: CRspGetNearestNodePortForFiles :: ClientPortMap -> ControllerResponseMessage
+ Holumbus.FileSystem.Messages: CRspGetNearestNodePortWithFiles :: ClientPortMap -> ControllerResponseMessage
+ Holumbus.FileSystem.Messages: NReqCreateS :: [(FileId, FileContent)] -> NodeRequestMessage
+ Holumbus.FileSystem.Messages: NReqGetMultiFileContent :: [FileId] -> NodeRequestMessage
+ Holumbus.FileSystem.Messages: NRspGetMultiFileContent :: [(FileId, FileContent)] -> NodeResponseMessage
+ Holumbus.FileSystem.Messages: performPortAction :: (Show a, Binary a, Show b, Binary b, RspMsg b) => Port a -> Stream b -> Int -> a -> (b -> IO (Maybe c)) -> IO c
+ Holumbus.FileSystem.Messages: type ClientPortMap = [(ClientPort, [FileId])]
+ Holumbus.FileSystem.Node: createFiles :: (NodeClass n) => [(FileId, FileContent)] -> n -> IO ()
+ Holumbus.FileSystem.Node: getMultiFileContent :: (NodeClass n) => [FileId] -> n -> IO [(FileId, FileContent)]
+ Holumbus.FileSystem.Storage: createFiles :: (Storage s) => s -> [(FileId, FileContent)] -> IO (s)

Files

+ Examples/StoragePerformance/Makefile view
@@ -0,0 +1,19 @@+GHC_FLAGS = -threaded -O2 -hidir $(OUTPUT) -odir $(OUTPUT) -XScopedTypeVariables+GHC       = ghc $(GHC_FLAGS)++RM_FLAGS = -rf+RM       = rm $(RM_FLAGS)++PROG   = NetFile_1  ReadFile_1 NetFile_2 ReadFile_2 +OUTPUT = output++all : $(PROG)++% : %.hs+	[ -d $(OUTPUT) ] || mkdir -p $(OUTPUT)+	$(RM) $(OUTPUT)/*+	$(GHC) --make -o $@ $<++clean :+	$(RM) $(PROG) $(OUTPUT)+	
+ Examples/StoragePerformance/NetFile_1.hs view
@@ -0,0 +1,43 @@+module Main where++import Data.Time.Clock.POSIX+import GHC.Int+import Data.Binary++import Holumbus.FileSystem.FileSystem+import Holumbus.Network.PortRegistry.PortRegistryPort+++import qualified Data.ByteString.Lazy as B++main :: IO ()+main = do+  -- get time+  t0 <- getPOSIXTime+  t0 `seq` putStrLn . show $ t0++  p <- newPortRegistryFromXmlFile "/tmp/registry.xml"+  setPortRegistry p      ++  -- make filesystem+  fs <- mkFileSystemClient defaultFSClientConfig+  +  -- get time+  t <- getPOSIXTime+  t `seq` putStrLn . show $ t++  -- copy to fs+  mapM_ (\(i,bin) -> createFile ("File"++show i) bin fs) $ zip [1..1000] binLists++  -- get time 2+  t' <- getPOSIXTime+  t' `seq` putStrLn . show $ t'++  let duration = t' - t;+  putStrLn $ "Duration    : " ++ show duration++binLists ::[B.ByteString]+binLists = (map encode . repeat) empty++empty :: [Int32]+empty = []
+ Examples/StoragePerformance/NetFile_2.hs view
@@ -0,0 +1,45 @@+module Main where++import Data.Time.Clock.POSIX+import GHC.Int+import Data.Binary++import Holumbus.FileSystem.FileSystem+import Holumbus.Network.PortRegistry.PortRegistryPort+++import qualified Data.ByteString.Lazy as B++main :: IO ()+main = do+  -- get time+  t0 <- getPOSIXTime+  t0 `seq` putStrLn . show $ t0++  p <- newPortRegistryFromXmlFile "/tmp/registry.xml"+  setPortRegistry p      ++  -- make filesystem+  fs <- mkFileSystemClient defaultFSClientConfig+  +  -- get time+  t <- getPOSIXTime+  putStrLn . show $ t++  -- copy to fs+  let filenames = map (\i -> "File_" ++ show i) [1..1000];+      files     = zip filenames binLists+  createFiles files fs++  -- get time 2+  t' <- getPOSIXTime+  putStrLn . show $ t'++  let duration = t' - t+  putStrLn $ "Duration    : " ++ show duration++binLists ::[B.ByteString]+binLists = map encode empty++empty :: [[Int32]]+empty = replicate 1000 []
+ Examples/StoragePerformance/ReadFile_1.hs view
@@ -0,0 +1,45 @@+module Main where++import Data.Time.Clock.POSIX+import GHC.Int+import Data.Binary+import Data.Maybe++import Holumbus.FileSystem.FileSystem+import Holumbus.Network.PortRegistry.PortRegistryPort+++import qualified Data.ByteString.Lazy as B++main :: IO ()+main = do+  p <- newPortRegistryFromXmlFile "/tmp/registry.xml"+  setPortRegistry p      ++  -- make filesystem+  fs <- mkFileSystemClient defaultFSClientConfig+  +  -- get time+  t <- getPOSIXTime+  t `seq` putStrLn . show $ t++  -- copy to fs+  binList <- getFileContent "File" fs++  -- get time 2+  t' <- getPOSIXTime+  t' `seq` putStrLn . show $ t'++  let duration = t' - t;+      bytes = fromIntegral . B.length . fromMaybe B.empty $ binList;+      kbytes = bytes / 1024;+      mbytes = kbytes / 1024;+      bytesPerSecond  = bytes / duration+      kbytesPerSecond = kbytes / duration+      mbytesPerSecond = mbytes / duration++  putStrLn $ "Duration    : " ++ show duration+  putStrLn $ "Bytes copied: " ++ show bytes+  putStrLn $ "Bytes / s   : " ++ show bytesPerSecond+  putStrLn $ "KBytes / s  : " ++ show kbytesPerSecond+  putStrLn $ "MBytes / s  : " ++ show mbytesPerSecond
+ Examples/StoragePerformance/ReadFile_2.hs view
@@ -0,0 +1,45 @@+module Main where++import Data.Time.Clock.POSIX+import GHC.Int+import Data.Binary+import Data.Maybe++import Holumbus.FileSystem.FileSystem+import Holumbus.Network.PortRegistry.PortRegistryPort+++import qualified Data.ByteString.Lazy as B++main :: IO ()+main = do+  p <- newPortRegistryFromXmlFile "/tmp/registry.xml"+  setPortRegistry p      ++  -- make filesystem+  fs <- mkFileSystemClient defaultFSClientConfig+  +  -- get time+  t <- getPOSIXTime+  t `seq` putStrLn . show $ t++  -- copy to fs+  binList <- getMultiFileContent ( map (\i -> "File_" ++show i) [1..100] ) fs++  -- get time 2+  t' <- getPOSIXTime+  t' `seq` putStrLn . show $ t'++  let duration = t' - t;+      bytes = fromIntegral . B.length .  encode $ binList;+      kbytes = bytes / 1024;+      mbytes = kbytes / 1024;+      bytesPerSecond  = bytes / duration+      kbytesPerSecond = kbytes / duration+      mbytesPerSecond = mbytes / duration++  putStrLn $ "Duration    : " ++ show duration+  putStrLn $ "Bytes copied: " ++ show bytes+  putStrLn $ "Bytes / s   : " ++ show bytesPerSecond+  putStrLn $ "KBytes / s  : " ++ show kbytesPerSecond+  putStrLn $ "MBytes / s  : " ++ show mbytesPerSecond
Examples/Utils/Filehandling/FileHandlingTest.hs view
@@ -15,8 +15,8 @@  module Main(main) where - import           Data.Binary+--import           Holumbus.Common.MRBinary import qualified Data.ByteString.Lazy as B  import           Holumbus.Common.FileHandling
Holumbus-Storage.cabal view
@@ -1,9 +1,9 @@ name:          Holumbus-Storage-version:       0.0.1+version:       0.1.0 license:       OtherLicense license-file:  LICENSE author:        Uwe Schmidt, Stefan Schmidt-copyright:     Copyright (c) 2008 Uwe Schmidt, Stefan Schmidt+copyright:     Copyright (c) 2010 Stefan Schmidt, Uwe Schmidt, Sebastian Reese maintainer:    Stefan Schmidt <sts@holumbus.org> stability:     experimental category:      Distributed Computing@@ -21,11 +21,16 @@     Examples/FileSystem/ControllerMain.hs     Examples/FileSystem/NodeMain.hs     Examples/Makefile+    Examples/StoragePerformance/Makefile+    Examples/StoragePerformance/NetFile_1.hs+    Examples/StoragePerformance/NetFile_2.hs+    Examples/StoragePerformance/ReadFile_1.hs+    Examples/StoragePerformance/ReadFile_2.hs     Examples/Utils/Filehandling/FileHandlingTest.hs     Examples/Utils/Filehandling/Makefile  library-  build-depends:  base >= 3+  build-depends:  base >= 4 && < 5                 , binary     >= 0.4                 , bytestring >= 0.9                 , containers >= 0.1@@ -36,7 +41,8 @@                 , network    >= 2.1                 , time       >= 1.1                 , unix       >= 2.3-                , Holumbus-Distribution >= 0.0.1+                , Holumbus-Distribution >= 0.0.1 && < 0.2+                , random     >= 1.0    hs-source-dirs:                    source@@ -52,5 +58,16 @@                 , Holumbus.FileSystem.Controller                 , Holumbus.FileSystem.Controller.ControllerData                 , Holumbus.FileSystem.Controller.ControllerPort-  ghc-options: -Wall -threaded+  ghc-options: -Wall   extensions: Arrows DeriveDataTypeable ExistentialQuantification++executable StorageControllerDaemon+  main-is: StorageControllerDaemon.hs+  hs-source-dirs: Programs/StorageControllerDaemon source+  ghc-options: -Wall -threaded -O2++executable StorageNodeDaemon+  main-is: StorageNodeDaemon.hs+  hs-source-dirs: Programs/StorageNodeDaemon source+  ghc-options: -Wall -threaded -O2+
+ Programs/StorageControllerDaemon/StorageControllerDaemon.hs view
@@ -0,0 +1,219 @@+module Main(main) where++import           Holumbus.Common.Logging+import           Holumbus.Network.PortRegistry.PortRegistryPort+import qualified Holumbus.Common.Debug                  as DEBUG+import           Holumbus.Common.Utils                  ( handleAll )+import Data.Binary+import Data.List+import qualified Holumbus.Console.ServerConsole                       as Console+import qualified Holumbus.FileSystem.FileSystem         as FS+import qualified Holumbus.FileSystem.Storage            as S+import           System.Environment (getArgs)+import           System.Log.Logger+import           System.Exit++version :: String+version = "Holumbus-StorageControllerDaemon 0.1"++prompt :: String+prompt = "# StorageControllerDaemon > "++localLogger :: String+localLogger = "Holumbus.StorageControllerDaemon"++pUsage :: IO ()+pUsage = do+  putStrLn "Usage: StorageControllerDaemon ConsolePort Logfile"++params :: IO [String]+params = do+  args <- getArgs+  if length args /= 2 then do+    errorM localLogger "Wrong argument count"+    pUsage+    exitFailure+    else+      return args++main :: IO ()+main+  = handleAll (\e -> errorM localLogger $ "EXCEPTION: " ++ show e) $ do+    putStrLn ("Starting " ++ version)+    (s_cport:logfile:[]) <- params+    initializeFileLogging logfile [(localLogger, INFO),("Holumbus.Network.DoWithServer",INFO),("measure",ERROR),("Holumbus",ERROR),("Holumbus.Network",ERROR)]+    fs <- initialize+    +    Console.startServerConsole createConsole fs (read s_cport) prompt+    +initialize :: IO (FS.FileSystem)+initialize = do+  p <- newPortRegistryFromXmlFile "/tmp/registry.xml"      +  setPortRegistry p+  fs <- FS.mkFileSystemController FS.defaultFSControllerConfig+  return fs++createConsole :: Console.ConsoleData (FS.FileSystem)+createConsole =+  Console.addConsoleCommand "id"        getMySiteId     "get my siteId" $+  Console.addConsoleCommand "sites"     getFileSites    "get all sites with the given file name" $+  Console.addConsoleCommand "with"      getNearestNodePortWithFile      "gets the nearest node-port with a file (DEBUG)" $+  Console.addConsoleCommand "for"       getNearestNodePortForFile       "gets the nearest node-port for a (new) file (DEBUG)" $  +  Console.addConsoleCommand "contains"  containsFile    "is file in filesystem or not" $+  Console.addConsoleCommand "create"    createFile      "adds a file" $+  Console.addConsoleCommand "createS"   createFiles     "adds a list of files [(Filename,FileContent)]" $+  Console.addConsoleCommand "append"    append          "appends to a file" $+  Console.addConsoleCommand "delete"    deleteFile      "deletes a file" $+  Console.addConsoleCommand "content"   getFileContent  "gets the content of a file" $+  Console.addConsoleCommand "data"      getFileData     "gets the metadata of a file" $+  Console.addConsoleCommand "local"     isFileLocal     "test, if the file is on the local node" $+  Console.addConsoleCommand "debug"     printDebug      "prints internal state of the filesystem (DEBUG)" $ +  Console.addConsoleCommand "version"   (printVersion version)          "prints the version" $ +  Console.initializeConsole+  ++getFileNameAndContent :: [String] -> (S.FileId, S.FileContent)+getFileNameAndContent []   = error "no filename given"+getFileNameAndContent (x:xs) = (x, encode $ intercalate " " xs)+-- getFileNameAndContent (x:xs) = (x, S.TextFile $ intercalate " " xs)++getFileNamesAndContent :: [String] -> [(S.FileId, S.FileContent)]+getFileNamesAndContent [] = []+getFileNamesAndContent (_:[]) = error "no content given"+getFileNamesAndContent (fid:c:xs) = ((fid, encode c):getFileNamesAndContent xs)+++getFileNameAndContentSize :: [String] -> (S.FileId, Integer)+getFileNameAndContentSize []   = error "no filename given"+getFileNameAndContentSize (x1:[]) = (x1, 0)+getFileNameAndContentSize (x1:x2:_) = (x1, read x2)+++getMySiteId :: FS.FileSystem -> [String] -> IO String+getMySiteId fs _+  = do+    handleAll (\e -> return $ show e) $+      do+      i <- FS.getMySiteId fs+      return $ show i+     ++getFileSites :: FS.FileSystem -> [String] -> IO String+getFileSites fs opts+  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, _) = getFileNameAndContent opts+      s <- FS.getFileSites n fs+      return $ show s+++getNearestNodePortWithFile :: FS.FileSystem -> [String] -> IO String+getNearestNodePortWithFile fs opts+  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, _) = getFileNameAndContent opts+      p <- FS.getNearestNodePortWithFile n fs+      return $ show p+++getNearestNodePortForFile :: FS.FileSystem -> [String] -> IO String+getNearestNodePortForFile fs opts+  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, s) = getFileNameAndContentSize opts+      p <- FS.getNearestNodePortForFile n s fs+      return $ show p+++containsFile :: FS.FileSystem -> [String] -> IO String+containsFile fs opts +  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, _) = getFileNameAndContent opts+      b <- FS.containsFile n fs+      return $ show b+++createFile :: FS.FileSystem -> [String] -> IO String+createFile fs opts +  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, c) = getFileNameAndContent opts+      FS.createFile n c fs +      return ""++createFiles :: FS.FileSystem -> [String] -> IO String+createFiles fs opts+  = do+    handleAll (\e -> return $ show e) $+      do+      let l = getFileNamesAndContent opts+      FS.createFiles l fs+      return ""++append :: FS.FileSystem -> [String] -> IO String+append fs opts+  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, c) = getFileNameAndContent opts+      FS.appendFile n c fs+      return ""+  ++deleteFile :: FS.FileSystem -> [String] -> IO String+deleteFile fs opts+  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, _) = getFileNameAndContent opts+      FS.deleteFile n fs+      return ""+++getFileContent :: FS.FileSystem -> [String] -> IO String+getFileContent fs opts+  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, _) = getFileNameAndContent opts+      c <- FS.getFileContent n fs+      return $ show c+++getFileData :: FS.FileSystem -> [String] -> IO String+getFileData fs opts+  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, _) = getFileNameAndContent opts+      d <- FS.getFileData n fs+      return $ show d+      ++isFileLocal :: FS.FileSystem -> [String] -> IO String+isFileLocal fs opts +  = do+    handleAll (\e -> return $ show e) $+      do+      let (n, _) = getFileNameAndContent opts+      b <- FS.isFileLocal n fs+      return $ show b+    +      +printDebug :: FS.FileSystem -> [String] -> IO String+printDebug fs _+  = do+    handleAll (\e -> return . show $ e) $ DEBUG.getDebug  fs+  +  +printVersion :: String -> FS.FileSystem -> [String] -> IO String+printVersion ver _ _+  = return ver++-- ------------------------------------------------------------
+ Programs/StorageNodeDaemon/StorageNodeDaemon.hs view
@@ -0,0 +1,104 @@+module Main(main) where++import           Holumbus.Common.Logging+import           Holumbus.Common.Utils+import           Holumbus.Network.PortRegistry.PortRegistryPort+import Holumbus.FileSystem.FileSystem+import qualified Holumbus.Console.ServerConsole as Console+import           System.Environment (getArgs)+import           System.Log.Logger+import           System.Exit++version :: String+version = "Holumbus-StorageNodeDaemon 0.1"++prompt :: String+prompt = "# StorageNodeDaemon > "++localLogger :: String+localLogger = "Holumbus.StorageNodeDaemon"++pUsage :: IO ()+pUsage = do+  putStrLn "Usage: StorageNodeDaemon ConsolePort Logfile"++params :: IO [String]+params = do+  args <- getArgs+  if length args /= 2 then do+    errorM localLogger "Wrong argument count"+    pUsage+    exitFailure+    else+      return args++main :: IO ()+main+  = handleAll (\e -> errorM localLogger $ "EXCEPTION: " ++ show e) $ do+    putStrLn ("Starting " ++ version)+    (s_cport:logfile:[]) <- params+    initializeFileLogging logfile [(localLogger, INFO),("Holumbus.Network.DoWithServer",INFO),("measure",ERROR),("Holumbus",ERROR),("Holumbus.Network",ERROR)]+    fs <- initialize+    +    Console.startServerConsole createConsole fs (read s_cport) prompt+    +initialize :: IO (FileSystem)+initialize = do+  p <- newPortRegistryFromXmlFile "/tmp/registry.xml"      +  setPortRegistry p+  fs <- mkFileSystemNode defaultFSNodeConfig+  return fs++    +createConsole :: Console.ConsoleData FileSystem+createConsole = Console.initializeConsole+{-  Console.addConsoleCommand "register"   hdlRegister   "registers a port manually" $+  Console.addConsoleCommand "unregister" hdlUnregister "unregisters a port manually" $+  Console.addConsoleCommand "lookup"   hdlLookup     "gets the socket id for a port" $+  Console.addConsoleCommand "ports"    hdlGetPorts   "lists all ports" $ +  Console.addConsoleCommand "version"    hdlVersion    "prints the version" $+  Console.initializeConsole -}+      ++{- hdlRegister :: FileSystem -> [String] -> IO String+hdlRegister prd opts+  = do+    handleAll (\_ -> return "usage: register <streamname> <hostname> <socketId>") $+      do+      let sn = head opts+      let hn = head $ tail opts+      let po = fromInteger . read . head . tail . tail $ opts+      registerPort sn (SocketId hn po) prd+      return "Register succesfull"+++hdlUnregister :: FileSystem -> [String] -> IO String+hdlUnregister prd opts+  = handleAll (\_ -> return "usage: unregister <streamname>") $+      do+      let sn = head opts+      unregisterPort sn prd+      return "Unregister succesfull"+++hdlLookup :: FileSystem -> [String] -> IO String+hdlLookup prd opts+  = handleAll (\_ -> return "usage: lookup <streamname>") $+      do+      let sn = head opts+      soid <- lookupPort sn prd+      return . show $ soid+++hdlGetPorts :: FileSystem -> [String] -> IO String+hdlGetPorts prd _+  = do+    ls <- getPorts prd+    return . show $ ls+++hdlVersion :: FileSystem -> [String] -> IO String+hdlVersion _ _+  = return version -}++-- ------------------------------------------------------------
README view
@@ -1,6 +1,6 @@ This is the Holumbus-Storage library -Version 0.0.1+Version 0.1.0  Stefan Schmidt sts@holumbus.org 
source/Holumbus/FileSystem/Controller.hs view
@@ -29,8 +29,7 @@ import           Holumbus.Network.Site import           Holumbus.Network.Communication import qualified Holumbus.FileSystem.Storage as S--+import           Holumbus.FileSystem.Messages ( ClientPortMap )  -- ---------------------------------------------------------------------------- -- Typeclass@@ -47,13 +46,20 @@      getNearestNodePortWithFile :: S.FileId -> SiteId -> c -> IO (Maybe ClientPort)   +  getNearestNodePortWithFiles :: [S.FileId] -> SiteId -> c -> IO ClientPortMap+     getNearestNodePortForFile :: S.FileId -> Integer -> SiteId -> c -> IO (Maybe ClientPort)   +  getNearestNodePortForFiles :: [(S.FileId,Integer)] -> SiteId -> c -> IO ClientPortMap+   +     -- only to be used by the nodes      createFile :: S.FileId -> IdType -> c -> IO ()-+  +  createFiles :: [(S.FileId,IdType)] -> c -> IO ()+     deleteFile :: S.FileId -> IdType -> c -> IO ()    appendFile :: S.FileId -> IdType -> c -> IO ()
source/Holumbus/FileSystem/Controller/ControllerData.hs view
@@ -49,6 +49,10 @@ import           Holumbus.Network.Communication  +import Control.Monad (foldM)+import System.Random++ localLogger :: String localLogger = "Holumbus.FileSystem.Controller" @@ -70,7 +74,6 @@   , cd_FileController :: FileController   } - -- ---------------------------------------------------------------------------- -- -- ----------------------------------------------------------------------------@@ -114,14 +117,26 @@         do         p <- C.getNearestNodePortWithFile f sid cd         return $ Just $ M.CRspGetNearestNodePortWithFile p+      (M.CReqGetNearestNodePortWithFiles l sid) ->+        do+        portmap <- C.getNearestNodePortWithFiles l sid cd+        return $ Just $ M.CRspGetNearestNodePortWithFiles portmap       (M.CReqGetNearestNodePortForFile f l sid) ->         do         p <- C.getNearestNodePortForFile f l sid cd         return $ Just $ M.CRspGetNearestNodePortForFile p+      (M.CReqGetNearestNodePortForFiles l sid) ->+        do+        p <- C.getNearestNodePortForFiles l sid cd+        return $ Just $ M.CRspGetNearestNodePortForFiles p       (M.CReqCreate f n) ->         do         C.createFile f n cd         return $ Just $ M.CRspSuccess+      (M.CReqCreateS l) ->+        do+        C.createFiles l cd+        return $ Just $ M.CRspSuccess       (M.CReqAppend f n) ->          do         C.appendFile f n cd@@ -229,7 +244,12 @@   addFileToController :: S.FileId -> M.NodeId -> FileControllerData -> FileControllerData-addFileToController fid nid cm = addFilesToController [fid] nid cm+--addFileToController fid nid cm = addFilesToController [fid] nid cm+addFileToController fid nid cm = cm { cm_FileToNodeMap = fnm' }+  where+    fnm = cm_FileToNodeMap cm+    fnm' = Map.insert fid nid' fnm +    nid' = Set.singleton nid   deleteFileFromController :: S.FileId -> FileControllerData -> FileControllerData@@ -238,8 +258,8 @@   where      fnm = cm_FileToNodeMap cm      fnm' = Map.delete fid fnm-     + -- | gets the List of all sites the file is located on... getFileClientInfoList :: S.FileId -> Server -> FileControllerData -> IO [ClientInfo] getFileClientInfoList f s cm@@ -249,22 +269,82 @@     mbDats <- mapM (\i -> getClientInfo i s) is     return $ catMaybes mbDats   -+shuffle :: [a] -> IO [a]+shuffle l' = shuffle' l' []+  where+    shuffle' [] acc = return acc+    shuffle' l acc = do+      k <- randomRIO (0, length l - 1)+      let (lead, x:xs) = splitAt k l+      shuffle' (lead ++ xs) (x:acc)  lookupNearestPortWithFile :: S.FileId -> SiteId -> Server -> FileControllerData -> IO (Maybe ClientPort) lookupNearestPortWithFile f sid s cm   = do     dats <- getFileClientInfoList f s cm-    let sids  = map (\ci -> ci_Site ci) dats-        mbns  = nearestId sid sids+    let sids'  = map (\ci -> ci_Site ci) dats+    sids <- shuffle sids'+    let mbns  = nearestId sid sids         mbdat = maybe Nothing (\ns -> List.find (\ci -> (ci_Site ci) == ns) dats) mbns         mbnp  = maybe Nothing (\ci -> Just $ ci_Port ci) mbdat      return mbnp +-- | gets the List of all sites the files are located on...+{-+trude :: SiteId -> [S.FileId] -> Server -> FileControllerData -> IO (Maybe SiteId)+trude currentSite files s cm+  = do+    let file2node       = cm_FileToNodeMap cm;+        nodeIdsWithFiles = concatMap (\file -> Set.toList $ maybe Set.empty id (Map.lookup file file2node)) files+    sitesIdsWithFiles <- foldM f ([],[],[]) nodeIdsWithFiles+    nearestId' sitesIdsWithFiles+    where -lookupNearestPortWithFileAndSpace :: S.FileId -> Integer -> SiteId -> Server -> FileControllerData -> IO (Maybe ClientPort)-lookupNearestPortWithFileAndSpace f _size sid s cm-  = lookupNearestPortWithFile f sid s cm+    nearestId' :: ([SiteId],[SiteId],[SiteId]) -> IO (Maybe SiteId)+    nearestId' ([],  [],  [])  = return Nothing                      -- no site id found+    nearestId' ([],  [],  xs)  = do +      xs' <- shuffle xs+      return . Just . head $ xs' -- only others ids, shuffle and return the first+    nearestId' ([],  x:_, _)   = return $ Just x                     -- return the hosts stie+    nearestId' (x:_, _,   _)   = return $ Just x                     -- return the procs site++    f :: ([SiteId],[SiteId],[SiteId]) -> M.NodeId -> IO ([SiteId],[SiteId],[SiteId])+    f (procs,hosts,others) i = do+      cli <- getClientInfo i s+      case cli of+        Nothing -> return (procs,hosts,others)+        (Just clientInfo) -> insert (procs,hosts,others) (ci_Site clientInfo)+    +    insert :: ([SiteId],[SiteId],[SiteId]) -> SiteId -> IO ([SiteId],[SiteId],[SiteId])+    insert (procs,hosts,others) thisSite = if isSameProcess thisSite currentSite+                       then return (thisSite:procs,hosts,others)+                       else if isSameHost thisSite currentSite+                              then return (procs,thisSite:hosts,others)+                              else return (procs,hosts,thisSite:others)+-}++lookupNearestPortWithFiles :: [S.FileId] -> SiteId -> Server -> FileControllerData -> IO M.ClientPortMap+lookupNearestPortWithFiles l sid s cm = do+  infoM localLogger $  "Getting nearest ports with: " ++ show l+  res <- foldM f [] l+  infoM localLogger $  "Clientportmap is: " ++ show res+  return res+  where++  f :: M.ClientPortMap -> S.FileId -> IO M.ClientPortMap+  f theMap fid = do++    infoM localLogger $  "Getting nearest ports with: " ++ fid+    maybeport <- lookupNearestPortWithFile fid sid s cm++    debugM localLogger $  "Nearest ports: " ++ show maybeport+    case maybeport of+      (Just port) -> return (ins port fid theMap)+      Nothing -> return theMap++-- lookupNearestPortWithFileAndSpace :: S.FileId -> Integer -> SiteId -> Server -> FileControllerData -> IO (Maybe ClientPort)+-- lookupNearestPortWithFileAndSpace f _size sid s cm+--   = lookupNearestPortWithFile f sid s cm {-    dats <- getFileClientInfoList f s cm     -- TODO add Capacity     let sids  = map (\ci -> ci_Site ci) $ filter (...) dats@@ -279,8 +359,9 @@ lookupNearestPortWithSpace _size sid s _cm   = do     dats <- getAllClientInfos s -    let sids  = map (\ci -> ci_Site ci) dats-        mbns  = nearestId sid sids+    let sids'  = map (\ci -> ci_Site ci) dats+    sids <- shuffle sids'+    let mbns  = nearestId sid sids         mbdat = maybe Nothing (\ns -> List.find (\ci -> (ci_Site ci) == ns) dats) mbns         mbnp  = maybe Nothing (\ci -> Just $ ci_Port ci) mbdat      return mbnp@@ -307,12 +388,12 @@   lookupNearestPortForFile :: S.FileId -> Integer -> SiteId -> Server -> FileControllerData -> IO (Maybe ClientPort)-lookupNearestPortForFile f size sid s cm+lookupNearestPortForFile _ size sid s cm   -- if file exists, get nearest node, else the closest with space   = do-    nodeWithFile    <- lookupNearestPortWithFileAndSpace f size sid s cm-    nodeWithoutFile <- lookupNearestPortWithSpace size sid s cm -    let mbnp = maybe nodeWithoutFile (\np -> Just np) nodeWithFile+--    nodeWithFile    <- lookupNearestPortWithFileAndSpace f size sid s cm+    nodeWithoutFile <- lookupNearestPortWithSpace size sid s cm   +    let mbnp = maybe Nothing (\np -> Just np) nodeWithoutFile {-  debugM localLogger $ "lookupNearestPortForFile: file:            " ++ show f         debugM localLogger $ "lookupNearestPortForFile: size:            " ++ show size     debugM localLogger $ "lookupNearestPortForFile: site:            " ++ show sid    @@ -322,6 +403,47 @@ -}  return mbnp      +{-  = do+    dats <- getAllClientInfos s :: [ClientInfo]+    let sids'  = map (\ci -> ci_Site ci) dats+    sids <- shuffle sids'+    let mbns  = nearestId sid sids+        mbdat = maybe Nothing (\ns -> List.find (\ci -> (ci_Site ci) == ns) dats) mbns+        mbnp  = maybe Nothing (\ci -> Just $ ci_Port ci) mbdat+    return mbnp-}++lookupNearestPortForFiles :: [(S.FileId,Integer)] -> SiteId -> Server -> FileControllerData -> IO M.ClientPortMap+lookupNearestPortForFiles l sid s cm = do+  nearestPortWithSpace <- lookupNearestPortWithSpace 0 sid s cm+  case nearestPortWithSpace of+    Nothing -> return []+    (Just p) -> return [(p,map fst l)]+--  infoM localLogger $  "Getting nearest ports for: " ++ show l  +--  res <- foldM f [] l+--  infoM localLogger $  "Clientportmap is: " ++ show res+--  return res+--  where+--+--  f :: M.ClientPortMap -> (S.FileId,Integer) -> IO M.ClientPortMap+--  f theMap (fid,len) = do+--    infoM localLogger $  "Getting nearest ports for: " ++ fid+--    mp <- lookupNearestPortForFile fid len sid s cm+--    debugM localLogger $  "Nearest ports: " ++ show mp+--    cpm <- case mp of+--      (Just port) -> return (ins port fid theMap)+--      Nothing -> return theMap+--    return cpm++ins  :: ClientPort -> S.FileId -> M.ClientPortMap -> M.ClientPortMap+ins port fid []            = [(port,[fid])]+ins port fid ((p,fids):[]) = if (p==port)+                               then [(p,(fid:fids))]+                               else [(port,[fid]),(p,fids)]+ins port fid ((p,fids):ps) = if (p==port)+                               then ((p,fid:fids):ps) +                               else (p,fids):(ins port fid ps)+  --   + getOtherFilePorts :: S.FileId -> IdType -> Server -> FileControllerData -> IO [ClientInfo] getOtherFilePorts f nid s cm   = do@@ -379,13 +501,20 @@     = withMVar (cd_FileController cd) $         \fc -> lookupNearestPortWithFile f sid (cd_Server cd) fc  - +  -- getNearestNodePortWithFiles :: [S.FileId] -> SiteId -> c -> IO (Maybe M.NodeRequestPort)+  getNearestNodePortWithFiles l sid cd+    = withMVar (cd_FileController cd) $+        \fc -> lookupNearestPortWithFiles l sid (cd_Server cd) fc +   -- getNearestNodePortForFile :: S.FileId -> Integer -> SiteId -> c -> IO (Maybe M.NodeRequestPort)   getNearestNodePortForFile f c sid cd     = withMVar (cd_FileController cd) $         \fc -> lookupNearestPortForFile f c sid (cd_Server cd) fc -+  -- getNearestNodePortForFiles :: [(S.FileId,Integer)] -> SiteId -> c -> IO (ClientPortMap)+  getNearestNodePortForFiles l sid cd+    = withMVar (cd_FileController cd) $+        \fc -> lookupNearestPortForFiles l sid (cd_Server cd) fc -- ---------------------------------------------------------------------------- -- used by the nodes -- ----------------------------------------------------------------------------@@ -398,13 +527,13 @@         do         mbCi <- getClientInfo nid (cd_Server cd)         case mbCi of-          (Just ci) ->+          (Just _) ->             do             let fc' = addFileToController f nid fc             -- copy file to one other node             mpCp <- lookupPortWithoutFile f (cd_Server cd) fc             case mpCp of-              (Just cp) -> +              (Just _) ->                  do                  return ()                 -- let np = NP.newNodePort cp@@ -413,7 +542,34 @@             return (fc', ())           (Nothing) -> return (fc,()) +--createFiles :: [(S.FileId,M.NodeId)] -> ControllerData -> IO ControllerData+  createFiles l cd+    = modifyMVar (cd_FileController cd) $+        \fc ->+        do+        fc'' <- foldM f fc l+        return  (fc'',())+        where+        f :: FileControllerData -> (S.FileId,M.NodeId) -> IO FileControllerData+        f filecontroller (fid,nid) = do+          mbCi <- getClientInfo nid (cd_Server cd)+          case mbCi of+            (Just _) ->+              do+              let fc' = addFileToController fid nid filecontroller+            -- copy file to one other node+--            mpCp <- lookupPortWithoutFile f (cd_Server cd) fc+--            case mpCp of+--              (Just _) ->+--                do+--                return ()+                -- let np = NP.newNodePort cp+                -- N.copyFile f (ci_Port ci) np+--              (Nothing) -> return ()+              return fc'+            (Nothing) -> return filecontroller + --appendFile :: S.FileId -> M.NodeId -> ControllerData -> IO ControllerData   appendFile f nid cd     = modifyMVar (cd_FileController cd) $@@ -429,7 +585,7 @@             cps <- getOtherFilePorts f nid (cd_Server cd) fc             let nps = map (\i -> NP.newNodePort (ci_Port i)) cps             -- order them to copy the file from the first node-            mapM (N.copyFile f (ci_Port ci)) nps+            _ <- mapM (N.copyFile f (ci_Port ci)) nps             return (fc', ())           (Nothing) -> return (fc,()) @@ -460,5 +616,19 @@       putStrLn "FileToNodeMap:"       withMVar (cd_FileController cd) $         \fc -> do-        putStrLn $ show (cm_FileToNodeMap $ fc) +        putStrLn $ show (cm_FileToNodeMap $ fc)+  getDebug cd+    = do+      let line = "--------------------------------------------------------"+      tmp <- getDebug (cd_Server cd)+      tmp2 <- withMVar (cd_FileController cd) $+          \fc -> do+          return $ show (cm_FileToNodeMap $ fc)+      return ( "Controller-Object (full)"+        ++"\n"++ line+        ++"\n"++ "Server"+        ++"\n"++ tmp+        ++"\n"++ line+        ++"\n"++ "FileToNodeMap:"+        ++"\n"++tmp2++"\n")         
source/Holumbus/FileSystem/Controller/ControllerPort.hs view
@@ -93,6 +93,14 @@           (CRspGetNearestNodePortWithFile po) -> return (Just po)           _ -> return Nothing +  getNearestNodePortWithFiles l sid (ControllerPort p)+    = do+      sendRequestToServer p time30 (CReqGetNearestNodePortWithFiles l sid) $+        \rsp ->+        do+        case rsp of+          (CRspGetNearestNodePortWithFiles portmap) -> return (Just portmap)+          _ -> return Nothing      getNearestNodePortForFile f l sid (ControllerPort p)     = do@@ -103,6 +111,14 @@           (CRspGetNearestNodePortForFile po) -> return (Just po)           _ -> return Nothing             +  getNearestNodePortForFiles l sid (ControllerPort p)+    = do+      sendRequestToServer p time30 (CReqGetNearestNodePortForFiles l sid) $+        \rsp ->+        do+        case rsp of+          (CRspGetNearestNodePortForFiles portlist) -> return (Just portlist)+          _ -> return Nothing                createFile f nid (ControllerPort p)     = do@@ -113,7 +129,16 @@           (CRspSuccess) -> return (Just $ ())           _ -> return Nothing +  createFiles l (ControllerPort p)+    = do+      sendRequestToServer p time30 (CReqCreateS l) $+        \rsp ->+        do+        case rsp of+          (CRspSuccess) -> return (Just $ ())+          _ -> return Nothing +   appendFile f nid (ControllerPort p)     = do       sendRequestToServer p time30 (CReqAppend f nid) $@@ -140,3 +165,5 @@     = do       putStrLn "ControllerPort:"       putStrLn $ show p+  getDebug (ControllerPort p)+    = return ("ControllerPort:\n"++show p++"\n")
source/Holumbus/FileSystem/FileSystem.hs view
@@ -50,10 +50,12 @@ , containsFile  , createFile+, createFiles , appendFile , deleteFile  , getFileContent+, getMultiFileContent , getFileData , isFileLocal @@ -65,8 +67,10 @@ import           Control.Concurrent import           Control.Monad -import qualified Data.Set as Set +import qualified Data.List as L+import qualified Data.Set as Set+import qualified Data.Map as Map import           System.Log.Logger  import           Holumbus.Common.Debug@@ -85,6 +89,7 @@ import           Holumbus.Network.Site import           Holumbus.Network.Communication +import Holumbus.FileSystem.Messages (ClientPortMap)  localLogger :: String localLogger = "Holumbus.FileSystem.FileSystem"@@ -276,16 +281,45 @@       \(FileSystemData sid c _) ->        (liftM createNodePort) $ C.getNearestNodePortWithFile f sid c     +-- | gets the nearest NodePorts with list of fileId+getNearestNodePortWithFiles :: [S.FileId] -> FileSystem -> IO [(NP.NodePort,[S.FileId])]+getNearestNodePortWithFiles l (FileSystem fs)+  = withMVar fs $+      \(FileSystemData sid c _) -> do+        infoM localLogger $ "Searching for nearest ports with files"+        ports <- C.getNearestNodePortWithFiles l sid c+        infoM localLogger $ ">>>>>>>>>>>>>>> " ++ show ports+        let result = createPortList ports+        debugM localLogger $ "Found ports" ++ show ports+        return result + -- | gets the nearest NodePort on which we can create our fileId. we need the --   content-size to get a node with enough space. getNearestNodePortForFile :: S.FileId -> Integer -> FileSystem -> IO (Maybe NP.NodePort) getNearestNodePortForFile f l (FileSystem fs)   = withMVar fs $-      \(FileSystemData sid c _) -> +      \(FileSystemData sid c _) ->       (liftM createNodePort) $ C.getNearestNodePortForFile f l sid c +-- | gets the nearest NodePort on which we can create our files. Iterate through the list and give back a result, where each nodeport is assosiated with the list of files it can handle. If we have an empty Storage system, one pair is returned. If there are existing files in the list, the files are stored on the node, they exists on.+getNearestNodePortForFiles :: [(S.FileId,Integer)] -> FileSystem -> IO [(NP.NodePort,[S.FileId])]+getNearestNodePortForFiles l (FileSystem fs)+  = withMVar fs $+      \(FileSystemData sid c _) -> do+      infoM localLogger $ "Searching for nearest ports"+      ports <- C.getNearestNodePortForFiles l sid c+      let result = createPortList ports+      debugM localLogger $ "Found ports" ++ show ports+      return result +createPortList :: ClientPortMap -> [(NP.NodePort,[S.FileId])]+createPortList [] = []+createPortList ((p,fids):ps) = case createNodePort (Just p) of+                        (Just p') -> ( (p',fids) : (createPortList ps) )+                        Nothing -> createPortList ps++ -- | Checks if a file is in the filesystem containsFile :: S.FileId -> FileSystem -> IO Bool containsFile f (FileSystem fs)@@ -308,7 +342,25 @@         N.createFile f c np'         return () +-- | Creates a list of files in the filesystem.+createFiles :: [(S.FileId,S.FileContent)] -> FileSystem -> IO ()+createFiles l fs = do+  infoM localLogger $ "creating files: " ++ (show . map fst $ l)+  nps <- getNearestNodePortForFiles (map (\(fid,c) -> (fid,S.getContentLength c)) l) fs+  debugM localLogger $ "Nodes to files map:" ++ show nps+  mapM_ (\(node,fids) -> N.createFiles (filesToStore fids) node) nps+    where+    asMap :: Map.Map S.FileId S.FileContent+    asMap = Map.fromList l +    filesToStore :: [S.FileId] -> [(S.FileId,S.FileContent)]+    filesToStore = L.foldl' addFile [] ++    addFile :: [(S.FileId,S.FileContent)] -> S.FileId -> [(S.FileId,S.FileContent)]+    addFile l' fid = case Map.lookup fid asMap of+                      Nothing -> l'+                      (Just c) -> ((fid,c):l')+ -- | Appends a file in the fileSystem. appendFile :: S.FileId -> S.FileContent -> FileSystem -> IO () appendFile f c fs@@ -351,6 +403,18 @@         do         N.getFileContent f np'  +-- | Gets the file content from the nearest site whitch holds the file+getMultiFileContent :: [S.FileId] -> FileSystem -> IO [(S.FileId,S.FileContent)]+getMultiFileContent l fs+  = do+    infoM localLogger $ "getting files: " ++ (show l)+    portmap <- getNearestNodePortWithFiles l fs+    infoM localLogger $ "ports with files: " ++ show portmap+    res <- mapM f portmap+    return . concat $ res+    where+    f :: (NP.NodePort,[S.FileId]) -> IO [(S.FileId,S.FileContent)]+    f (np,files) = N.getMultiFileContent files np  -- | Gets the file data from the nearest site whitch holds the file getFileData :: S.FileId -> FileSystem -> IO (Maybe S.FileData)@@ -391,3 +455,24 @@         putStrLn "Node:"         maybe (putStrLn "NOTHING") (\n' -> printDebug n') n         putStrLn "--------------------------------------------------------"+  getDebug (FileSystem fs)+    = do+      tmp <- withMVar fs $+        \(FileSystemData s c n) ->+        do+        tmp <-  getDebug c+        tmp2 <- maybe (return "NOTHING") (\n' -> getDebug n') n+        let line = "--------------------------------------------------------"+        return (line+          ++"\n"++ "FileSystem - internal data\n"+          ++"\n"++ line+          ++"\n"++ "SiteId:"+          ++"\n"++ show s+          ++"\n"++ line+          ++"\n"++ "Controller:"+          ++"\n"++ tmp+          ++"\n"++ line+          ++"\n"++ "Node:"+          ++"\n"++ tmp2+          ++"\n"++ line ++"\n")+      return tmp   
source/Holumbus/FileSystem/Messages.hs view
@@ -32,12 +32,14 @@  -- * request an response handling , performPortAction -- reexport from Holumbus.Network.Messages+, ClientPortMap ) where  import           Prelude hiding (appendFile)  import           Data.Binary+--import           Holumbus.Common.MRBinary import           Data.Set  import           Holumbus.Network.Communication@@ -46,7 +48,9 @@ import           Holumbus.Network.Messages  +type ClientPortMap = [(ClientPort,[S.FileId])] + -- ---------------------------------------------------------------------------- -- Datatypes -- ---------------------------------------------------------------------------- @@ -62,13 +66,16 @@  -- | Requests datatype, which is send to a filesystem Controller. data ControllerRequestMessage-  = CReqContains                   S.FileId-  | CReqGetFileSites               S.FileId-  | CReqGetNearestNodePortWithFile S.FileId Site.SiteId -  | CReqGetNearestNodePortForFile  S.FileId Integer Site.SiteId-  | CReqCreate                     S.FileId NodeId-  | CReqAppend                     S.FileId NodeId-  | CReqDelete                     S.FileId NodeId+  = CReqContains                    S.FileId+  | CReqGetFileSites                S.FileId+  | CReqGetNearestNodePortWithFile  S.FileId Site.SiteId +  | CReqGetNearestNodePortWithFiles [S.FileId] Site.SiteId +  | CReqGetNearestNodePortForFile   S.FileId Integer Site.SiteId+  | CReqGetNearestNodePortForFiles  [(S.FileId,Integer)] Site.SiteId+  | CReqCreate                      S.FileId NodeId+  | CReqCreateS                     [(S.FileId,NodeId)]+  | CReqAppend                      S.FileId NodeId+  | CReqDelete                      S.FileId NodeId   | CReqUnknown   deriving (Show) @@ -77,8 +84,11 @@   put (CReqContains f)                      = putWord8 1  >> put f   put (CReqGetFileSites f)                  = putWord8 2  >> put f   put (CReqGetNearestNodePortWithFile f s)  = putWord8 3  >> put f >> put s+  put (CReqGetNearestNodePortWithFiles l s) = putWord8 11 >> put s >> put l   put (CReqGetNearestNodePortForFile f l s) = putWord8 4  >> put f >> put l >> put s+  put (CReqGetNearestNodePortForFiles l s)  = putWord8 9  >> put s >> put l   put (CReqCreate f n)                      = putWord8 5  >> put f >> put n+  put (CReqCreateS l)                       = putWord8 10 >> put l   put (CReqAppend f n)                      = putWord8 6  >> put f >> put n   put (CReqDelete f n)                      = putWord8 7  >> put f >> put n   put (CReqUnknown)                         = putWord8 0@@ -89,8 +99,11 @@         1  -> get >>= \f -> return (CReqContains f)         2  -> get >>= \f -> return (CReqGetFileSites f)         3  -> get >>= \f -> get >>= \s -> return (CReqGetNearestNodePortWithFile f s)+        11 -> get >>= \s -> get >>= \l -> return (CReqGetNearestNodePortWithFiles l s)         4  -> get >>= \f -> get >>= \l -> get >>= \s -> return (CReqGetNearestNodePortForFile  f l s)+        9  -> get >>= \s -> get >>= \l -> return (CReqGetNearestNodePortForFiles l s)         5  -> get >>= \f -> get >>= \n -> return (CReqCreate f n)+        10 -> get >>= \l -> return (CReqCreateS l)         6  -> get >>= \f -> get >>= \n -> return (CReqAppend f n)         7  -> get >>= \f -> get >>= \n -> return (CReqDelete f n)         _  -> return (CReqUnknown)@@ -102,7 +115,9 @@   | CRspGetFileSites (Set Site.SiteId)   | CRspContains Bool   | CRspGetNearestNodePortWithFile (Maybe ClientPort)+  | CRspGetNearestNodePortWithFiles ClientPortMap   | CRspGetNearestNodePortForFile (Maybe ClientPort)+  | CRspGetNearestNodePortForFiles ClientPortMap   | CRspError String   | CRspUnknown   deriving (Show)@@ -126,7 +141,9 @@   put (CRspGetFileSites s)                = putWord8 2 >> put s    put (CRspContains b)                    = putWord8 3 >> put b   put (CRspGetNearestNodePortWithFile p)  = putWord8 4 >> put p+  put (CRspGetNearestNodePortWithFiles p) = putWord8 8 >> put p   put (CRspGetNearestNodePortForFile p)   = putWord8 5 >> put p+  put (CRspGetNearestNodePortForFiles p)  = putWord8 7 >> put p   put (CRspError e)                       = putWord8 6 >> put e   put (CRspUnknown)                       = putWord8 0   get@@ -137,7 +154,9 @@         2 -> get >>= \s -> return (CRspGetFileSites s)          3 -> get >>= \b -> return (CRspContains b)         4 -> get >>= \p -> return (CRspGetNearestNodePortWithFile p)+        8 -> get >>= \p -> return (CRspGetNearestNodePortWithFiles p)         5 -> get >>= \p -> return (CRspGetNearestNodePortForFile p)+        7 -> get >>= \p -> return (CRspGetNearestNodePortForFiles p)         6 -> get >>= \e -> return (CRspError e)         _ -> return (CRspUnknown) @@ -151,11 +170,13 @@ -- | Requests datatype, which is send to a filesystem node. data NodeRequestMessage    = NReqCreate          S.FileId S.FileContent+  | NReqCreateS         [(S.FileId,S.FileContent)]   | NReqAppend          S.FileId S.FileContent   | NReqDelete          S.FileId Bool   | NReqCopy            S.FileId ClientPort   | NReqContains        S.FileId   | NReqGetFileContent  S.FileId+  | NReqGetMultiFileContent  [S.FileId]   | NReqGetFileData     S.FileId   | NReqGetFileIds         | NReqUnknown         @@ -163,28 +184,32 @@   instance Binary NodeRequestMessage where-  put (NReqCreate i c)       = putWord8 1 >> put i >> put c-  put (NReqAppend i c)       = putWord8 2 >> put i >> put c-  put (NReqDelete i b)       = putWord8 3 >> put i >> put b-  put (NReqCopy i cp)        = putWord8 4 >> put i >> put cp-  put (NReqContains i)       = putWord8 5 >> put i-  put (NReqGetFileContent i) = putWord8 6 >> put i-  put (NReqGetFileData i)    = putWord8 7 >> put i+  put (NReqCreate i c)       = putWord8 1  >> put i >> put c+  put (NReqCreateS l)        = putWord8 9  >> put l+  put (NReqAppend i c)       = putWord8 2  >> put i >> put c+  put (NReqDelete i b)       = putWord8 3  >> put i >> put b+  put (NReqCopy i cp)        = putWord8 4  >> put i >> put cp+  put (NReqContains i)       = putWord8 5  >> put i+  put (NReqGetFileContent i) = putWord8 6  >> put i+  put (NReqGetMultiFileContent l) = putWord8 10 >> put l+  put (NReqGetFileData i)    = putWord8 7  >> put i   put (NReqGetFileIds)       = putWord8 8   put (NReqUnknown)          = putWord8 0   get     = do       t <- getWord8       case t of-        1 -> get >>= \i -> get >>= \c -> return (NReqCreate i c) -        2 -> get >>= \i -> get >>= \c -> return (NReqAppend i c) -        3 -> get >>= \i -> get >>= \b -> return (NReqDelete i b)-        4 -> get >>= \i -> get >>= \cp -> return (NReqCopy i cp)-        5 -> get >>= \i -> return (NReqContains i)-        6 -> get >>= \i -> return (NReqGetFileContent i)-        7 -> get >>= \i -> return (NReqGetFileData i)-        8 -> return (NReqGetFileIds)-        _ -> return (NReqUnknown)+        1  -> get >>= \i -> get >>= \c -> return (NReqCreate i c) +        2  -> get >>= \i -> get >>= \c -> return (NReqAppend i c) +        3  -> get >>= \i -> get >>= \b -> return (NReqDelete i b)+        4  -> get >>= \i -> get >>= \cp -> return (NReqCopy i cp)+        5  -> get >>= \i -> return (NReqContains i)+        6  -> get >>= \i -> return (NReqGetFileContent i)+        10 -> get >>= \l -> return (NReqGetMultiFileContent l)+        7  -> get >>= \i -> return (NReqGetFileData i)+        8  -> return (NReqGetFileIds)+        9  -> get >>= \l -> return (NReqCreateS l)+        _  -> return (NReqUnknown)   -- | Response datatype from a filesystem node.@@ -192,6 +217,7 @@   = NRspSuccess   | NRspContains Bool   | NRspGetFileContent (Maybe S.FileContent)+  | NRspGetMultiFileContent [(S.FileId,S.FileContent)]   | NRspGetFileData (Maybe S.FileData)   | NRspGetFileIds [S.FileId]   | NRspError String@@ -213,13 +239,14 @@           instance Binary NodeResponseMessage where-  put (NRspSuccess)          = putWord8 1-  put (NRspContains b)       = putWord8 2 >> put b-  put (NRspGetFileContent c) = putWord8 3 >> put c-  put (NRspGetFileData d)    = putWord8 4 >> put d-  put (NRspGetFileIds ls)    = putWord8 5 >> put ls-  put (NRspError e)          = putWord8 6 >> put e-  put (NRspUnknown)          = putWord8 0+  put (NRspSuccess)                = putWord8 1+  put (NRspContains b)             = putWord8 2 >> put b+  put (NRspGetFileContent c)       = putWord8 3 >> put c+  put (NRspGetMultiFileContent lc) = putWord8 7 >> put lc+  put (NRspGetFileData d)          = putWord8 4 >> put d+  put (NRspGetFileIds ls)          = putWord8 5 >> put ls+  put (NRspError e)                = putWord8 6 >> put e+  put (NRspUnknown)                = putWord8 0   get     = do       t <- getWord8@@ -227,6 +254,7 @@         1 -> return (NRspSuccess)         2 -> get >>= \b  -> return (NRspContains b)         3 -> get >>= \c  -> return (NRspGetFileContent c)+        7 -> get >>= \lc -> return (NRspGetMultiFileContent lc)         4 -> get >>= \d  -> return (NRspGetFileData d)         5 -> get >>= \ls -> return (NRspGetFileIds ls)         6 -> get >>= \e  -> return (NRspError e)
source/Holumbus/FileSystem/Node.hs view
@@ -36,6 +36,8 @@   closeNode :: n -> IO ()    createFile :: S.FileId -> S.FileContent -> n -> IO ()+  +  createFiles :: [(S.FileId,S.FileContent)] -> n -> IO ()    appendFile :: S.FileId -> S.FileContent -> n -> IO () @@ -46,6 +48,8 @@   containsFile :: S.FileId -> n -> IO Bool    getFileContent :: S.FileId -> n -> IO (Maybe S.FileContent)+  +  getMultiFileContent :: [S.FileId] -> n -> IO [(S.FileId,S.FileContent)]    getFileData :: S.FileId -> n -> IO (Maybe S.FileData) 
source/Holumbus/FileSystem/Node/NodeData.hs view
@@ -30,7 +30,6 @@ import           Control.Concurrent import           Control.Monad import           Data.Maybe-import           System.IO hiding (appendFile) import           System.Log.Logger  import           Holumbus.Common.Debug@@ -70,12 +69,12 @@ newNode sn soid stor   = do     -- initialise the client-    node <- newEmptyMVar-    client <- newClient sn soid (dispatch (Node node))+    nodedata <- newEmptyMVar+    client <- newClient sn soid (dispatch (Node nodedata))     -- open storage     stor' <- S.openStorage stor             -    putMVar node (NodeData client stor')-    return (Node node)+    putMVar nodedata (NodeData client stor')+    return (Node nodedata)   dispatch @@ -89,6 +88,10 @@         do         createFile i c nd         return $ Just M.NRspSuccess        +      (M.NReqCreateS l) ->+        do+        createFiles l nd+        return $ Just M.NRspSuccess       (M.NReqAppend i c) ->          do         appendFile i c nd@@ -109,6 +112,13 @@         do         c <- getFileContent i nd         return $ Just $ M.NRspGetFileContent c+      (M.NReqGetMultiFileContent l) ->+        do+--        mvar <- newEmptyMVar+--        _ <- forkIO $ multiThread l nd mvar+--        lc <- takeMVar mvar+        lc <- getMultiFileContent l nd+        return $ Just $ M.NRspGetMultiFileContent lc       (M.NReqGetFileData i) ->         do         d <- getFileData i nd@@ -137,10 +147,24 @@  readStorage :: (FS.FileStorage-> IO a) -> Node -> IO a readStorage f (Node node)-  = withMVar node $ \nd -> f (nd_Storage nd)+  = do+    a <- withMVar node $ \nd -> f (nd_Storage nd)    +    return a +logStorage :: Node -> IO ()+logStorage (Node node) = withMVar node $ \nd ->  logStorage2 (nd_Client nd) +  where+  logStorage2 (Client client) = withMVar client $ \cd -> debugM "measure.readStorage" ((show . cd_SiteId) cd)  +{-+multiThread :: [S.FileId] -> Node -> MVar [(S.FileId,S.FileContent)] -> IO ()+multiThread l' nd mvar = do+  l <- getMultiFileContent l' nd+  putMVar mvar l+  return ()+-}+ -- ---------------------------------------------------------------------------- -- Typeclass instanciation (NodeClass) -- ----------------------------------------------------------------------------@@ -177,7 +201,28 @@           C.createFile i nid' cp           return ()           +--  createFiles l n = mapM_ (\(fid,c) -> createFile fid c n) l+  --createFiles :: [(S.FileId,S.FileContent)] -> Node -> IO ()+  createFiles l n@(Node node)+    = do+      client <- withMVar node $ \nd -> return (nd_Client nd)+      nid <- getClientId client+      case nid of+        (Nothing) ->+          do+          --TODO better exception-handling+          errorM localLogger $ "createFiles - no nid"+          return ()+        (Just nid') ->+          do+          mapM_ (\(i,c) -> changeStorage (\stor -> S.createFile stor i c) n) l+          server <- getServerPort client+          let cp = CP.newControllerPortFromServerPort server+          let fns = map (\(i,_) -> (i,nid')) l+          C.createFiles fns  cp+          return () +   --appendFile :: S.FileId -> S.FileContent -> Node -> IO ()   appendFile i c n@(Node node)     = do@@ -248,9 +293,25 @@     = do       c <- readStorage (\stor -> S.getFileContent stor i) n       debugM localLogger $ "getFileContent: " ++ show c+      logStorage n        return c-     +  --getMultiFileContent :: [S.FileId] -> Node -> IO [(S.FileId,S.FileContent)]+  getMultiFileContent l n+    = do+      result <- foldM f [] l+      debugM localLogger $ "getFileContents: " ++ show result+      logStorage n+      return result+      where+      f :: [(S.FileId,S.FileContent)] -> S.FileId -> IO [(S.FileId,S.FileContent)]+      f res filename = do+        maybecontent <- readStorage (\stor -> S.getFileContent stor filename) n+        case maybecontent of+          (Just c) -> return ((filename,c):res)+          Nothing   -> return res++   --getFileData :: S.FileId -> Node -> IO (Maybe S.FileData)   getFileData i nd     = do@@ -276,3 +337,13 @@         putStrLn $ prettyRecordLine gap "Storage:" (nd_Storage nd)         where         gap = 20+  getDebug (Node node)+    = do      +      tmp <- withMVar node $+        \nd ->+        do+        tmp <- getDebug (nd_Client nd)+        return (tmp++"\n"++ (prettyRecordLine gap "Storage:" (nd_Storage nd)) ++"\n")+      return ("Node-Object (full)"++"\n"++tmp++"\n")+        where+        gap = 20        
source/Holumbus/FileSystem/Node/NodePort.hs view
@@ -66,6 +66,14 @@             (NRspSuccess) -> return (Just ())             _ -> return Nothing +  createFiles l (NodePort p)+    = do+      sendRequestToClient p time60 (NReqCreateS l) $+        \rsp ->+        do+        case rsp of+            (NRspSuccess) -> return (Just ())+            _ -> return Nothing    appendFile i c (NodePort p)     = do@@ -116,6 +124,15 @@           (NRspGetFileContent c) -> return (Just c)           _ -> return Nothing +  getMultiFileContent l (NodePort p) +      = do+      sendRequestToClient p time30 (NReqGetMultiFileContent l) $+        \rsp ->+        do+        case rsp of+          (NRspGetMultiFileContent lc) -> return (Just lc)+          _ -> return Nothing+        getFileData i (NodePort p)     = do@@ -142,3 +159,5 @@     = do       putStrLn "NodePort:"       putStrLn $ show p+  getDebug (NodePort p)+    = return ("NodePort:\n"++show p++"\n")
source/Holumbus/FileSystem/Storage.hs view
@@ -38,6 +38,7 @@  import           Prelude hiding (appendFile) import           Data.Binary+--import           Holumbus.Common.MRBinary import           Data.Time import qualified Data.ByteString.Lazy as B @@ -192,6 +193,8 @@   -- | Create a new file in the storage.   --   Overwrite the file if it already exists.   createFile :: s -> FileId -> FileContent -> IO (s)+  +  createFiles :: s ->[(FileId, FileContent)] -> IO (s)    -- | Delete a file in the storage.   --   Nothing happens if the file doesn't exist
source/Holumbus/FileSystem/Storage/FileStorage.hs view
@@ -28,12 +28,7 @@     ) where -import           Control.Monad-import           Control.Exception-import qualified Data.ByteString.Lazy as B import           Data.Binary-import           Data.Maybe-import           System.IO import           System.Directory import           System.Log.Logger import qualified Data.Map as Map@@ -105,8 +100,12 @@ readDirectory :: FileStorage -> IO (FileStorage) readDirectory stor   = do-    handleAll (\_ -> writeDirectory stor) $-      bracket+    handleAll (\_ -> writeDirectory stor) $ do+      infoM localLogger ("opening filestorage directory: " ++ (fs_DirfilePath stor))+      file <- decodeFile (fs_DirfilePath stor)+      file `seq` return (stor {fs_Directory = file})++{-      bracket         (do          infoM localLogger ("opening filestorage directory: " ++ (fs_DirfilePath stor))          openFile (fs_DirfilePath stor) ReadMode@@ -118,28 +117,52 @@           raw <- B.hGet hdl (read $ head pkg)           dir <- return (decode raw)           return (stor {fs_Directory = dir})-        )+        )-}   -- | Saves the filestorage on disk   writeDirectory :: FileStorage -> IO (FileStorage) writeDirectory stor   = do-    bracket +    infoM localLogger ("writing filestorage directory: " ++ (fs_DirfilePath stor))+    createDirectoryIfMissing True (fs_Path stor)+    encodeFile (fs_DirfilePath stor) (fs_Directory stor)+    return stor++{-    bracket        (do        infoM localLogger ("writing filestorage directory: " ++ (fs_DirfilePath stor))        createDirectoryIfMissing True (fs_Path stor)+       debugM localLogger "directory created .. "        openFile (fs_DirfilePath stor) WriteMode)       (hClose)        (\hdl ->         do +        debugM localLogger "encode store.. "         enc <- return (encode $ fs_Directory stor)++        debugM localLogger "calc length .. "         hPutStrLn hdl ((show $ B.length enc) ++ " ")++        debugM localLogger "put store .. "         B.hPut hdl enc    ++        debugM localLogger "return .. "         return stor-      )+      )-} +writeSingleFile :: FileStorage -> S.FileId -> S.FileContent -> IO FileStorage+writeSingleFile stor fn c = do+  debugM localLogger "write to bin file .. "+  writeToBinFile path c+  debugM localLogger "create file metadata"+  dat <- S.createFileData fn c+  return $ stor {fs_Directory = newdir dat}  +  where+    path = (fs_Path stor) ++ fn+    newdir d = addFileData (fs_Directory stor) d + -- | deriving FileStorage from the class Storage instance S.Storage FileStorage where @@ -151,17 +174,23 @@    createFile stor fn c      = do-      writeToBinFile path c-      -- case c of-      --  (S.TextFile t) -> writeToTextFile path t-      --  (S.ListFile l) -> writeToListFile path l-      --  (S.BinFile  b) -> writeToBinFile path b-      dat <- S.createFileData fn c-      writeDirectory $ stor {fs_Directory = newdir dat} -      where-        path = (fs_Path stor) ++ fn-        newdir d = addFileData (fs_Directory stor) d +      stor' <- writeSingleFile stor fn c+      debugM localLogger "write directory"+      writeDirectory stor' +  createFiles stor l+    = do+      debugM localLogger "write to bin file .. "+      stor' <- writeFiles stor l+      debugM localLogger "write directory"+      writeDirectory stor'+      where+        writeFiles :: FileStorage -> [(S.FileId,S.FileContent)] -> IO FileStorage+        writeFiles stor'' [] = return stor''+        writeFiles stor'' ((fn,c):xs) = do+          stor''' <- writeSingleFile stor'' fn c+          writeFiles stor''' xs+     deleteFile stor i     = do@@ -229,6 +258,7 @@                  return $ S.BinFile b             -}             debugM localLogger $ "getFileContent: content: " ++ show c+            infoM localLogger $ "getFileContent: finished "             return (Just c)         else do return Nothing       where
source/Holumbus/FileSystem/UserInterface.hs view
@@ -24,6 +24,7 @@ where  import           Data.Binary+--import           Holumbus.Common.MRBinary import           Data.List  import qualified Holumbus.Common.Debug                  as DEBUG