public bool RegisterWatcher(ServiceProfile profile, string host, IServiceContext serviceContext)
 {
     lock (locker)
     {
         IRPCWatcher watcher = watchers.Find(w => w.HostInfo.Node.Equals(host, StringComparison.OrdinalIgnoreCase));
         if (watcher == null)
         {
             this.logger.LogDebug($@"setting up an Remote fs watcher for {host}...");
             var currentHostInfo = new RPCHostInfo(host, profile.GetNodeServiceNetLocation(host));
             this.logger.LogDebug($@"targeting {currentHostInfo.WatchDir} on server {host}...");
             using (var subContainer = this.factoryContainer.GetNestedContainer())
             {
                 subContainer.Inject <IRPCHostInfo>(currentHostInfo);
                 watcher = subContainer.GetInstance <IRPCWatcher>();
                 watcher.OrchWatcherErrorEventHandler += HandleWatcherFailure;
                 this.logger.LogDebug($@"{host} watchdog setup ok ");
                 var result = watcher.StartWatching();
                 if (result)
                 {
                     this.logger.LogDebug($@"{host} watchdog working...");
                     watchers.Add(watcher);
                 }
                 else
                 {
                     this.logger.LogError($@"{host} watchdog setup ok but failed to start");
                     return(false);
                 }
             }
         }
         watcher.OrchFileChangeEventHandler += serviceContext.OnProcessFinishRequest;
         return(true);
     }
 }
Exemple #2
0
 private string PutRequestOnBox(string node, string filename, string request, ServiceProfile serviceProfile, string fileInBox, int timeoutSeconds)
 {
     lock (CallLocker)
     {
         this.logger.LogDebug($@"Start checking {filename} request into {node}");
         if (!serviceProfile.VerifyServiceProfileOnNode(node))
         {
             this.logger.LogDebug($@"Put Request on {node} fail, either {node} is not up or server-client profile incorrect");
             return($"[ORCH-ERR]Put Request on {node} fail, either {node} is not up or profile incorrect.");
         }
         var outBoxFile = Path.Combine(Path.Combine(serviceProfile.GetNodeServiceNetLocation(node), "boxes", "outbox"), filename);
         WriteFileRequest(node, filename, request, serviceProfile, fileInBox);
         this.logger.LogDebug($@"Request {filename} is written to {node}, and will timeout in {timeoutSeconds} seconds");
         if (sync.WaitOne(timeoutSeconds * 1000))
         {
             this.logger.LogDebug($@"Request {filename} comes back, returning result");
             return(File.ReadAllText(outBoxFile, Encoding.UTF8));
         }
         else
         {
             this.logger.LogDebug($@"Request {filename} timeout  ({timeoutSeconds})");
             return($@"[ORCH-ERR]the operation time out ({timeoutSeconds})");
         }
     }
 }
Exemple #3
0
 public string ProcessRequestAfterReboot(string node, string filename, string request, ServiceProfile serviceProfile)
 {
     return(PutRequestOnBox(
                node,
                filename,
                request,
                serviceProfile,
                Path.Combine(Path.Combine(serviceProfile.GetNodeServiceNetLocation(node), "boxes", "rcbox"), filename)));
 }
Exemple #4
0
 public string ProcessRequest(string node, string filename, string request, ServiceProfile serviceProfile, int timeoutSeconds)
 {
     return(PutRequestOnBox(
                node,
                filename,
                request,
                serviceProfile,
                Path.Combine(Path.Combine(serviceProfile.GetNodeServiceNetLocation(node), "boxes", "inbox"), filename),
                timeoutSeconds));
 }
Exemple #5
0
 private string PutRequestOnBox(string node, string filename, string request, ServiceProfile serviceProfile, string fileInBox)
 {
     lock (CallLocker)
     {
         this.logger.LogDebug($@"Start checking {filename} request into {node}");
         if (!serviceProfile.VerifyServiceProfileOnNode(node))
         {
             this.logger.LogDebug($@"Put Request on {node} fail, either {node} is not up or server-client profile incorrect");
             return($"[ORCH-ERR]Put Request on {node} fail, either {node} is not up or profile incorrect.");
         }
         var outBoxFile = Path.Combine(Path.Combine(serviceProfile.GetNodeServiceNetLocation(node), "boxes", "outbox"), filename);
         WriteFileRequest(node, filename, request, serviceProfile, fileInBox);
         this.logger.LogDebug($@"Request {filename} is written to {node}, and will wait till the server process the request");
         sync.WaitOne();
         return(File.ReadAllText(outBoxFile, Encoding.UTF8));
     }
 }