public void StartSingleInstance() { System.Console.WriteLine("Start Test : Start Single Instance"); var obj = new { base_url = "/", NotebookDir = TestDir + System.IO.Path.DirectorySeparatorChar + "HelloWorld.ipynb", ResourcePath = JNBFirstFile }; JupyterNotebookTool.StartTaskAsync((int)TaskTypes.Start, JNBFirstFile, (JObject)JObject.FromObject(obj)); System.Threading.Thread.Sleep(2000); Assert.True(JupyterNotebookTool.IsPortBusyInRange(8888, 8888, 8890)); Assert.Equal(JupyterNotebookTool.GetTasks().Count, 1); System.Console.WriteLine("End Test : Start Single Instance"); }
public async Task <IActionResult> GetJupyterNotebookUrlAsync(string id) { string response = string.Empty; string _jUrl = string.Empty; string message = "Notebook is up and running successfully"; //We needs to populate Current User from request string CURRENT_USER = string.Empty; string ResourcePath = Helpers.Common.FilePathHelper.GetFilePathById(id, codeResponse); FileInfo resourceInfo = new System.IO.FileInfo(ResourcePath); string notebookDir = resourceInfo.Directory.ToString(); string notebookLinkURL = string.Empty; var obj = new { base_url = "/", NotebookDir = $"{notebookDir}", ResourcePath = $"{ResourcePath}" }; try { var portRegex = new Regex(@"(?<![^/]/[^/]*):\d+");//to remove port number JupyterNotebook JNBTool = this.jupyterClient.GetJupyterNotebookTool(); await System.Threading.Tasks.Task.FromResult(0); ITask JupyterNoteBookTask = JNBTool.FindTask(ResourcePath); if (JupyterNoteBookTask.IsEmpty()) { JNBTool.StartTaskAsync((int)TaskTypes.Start, ResourcePath, (JObject)JObject.FromObject(obj)); } notebookLinkURL = JNBTool.GetResourceLink(ResourcePath); // notebookLinkURL = @"C:\myCode\Project\ZMOD\code\1_SVM\1_SVM.ipynb"; // // JupyterNotebook nb = JupyterNotebook.Find(ResourcePath); var objJNBInst = new InstanceResponse() { Id = id, Name = $"{id}.ipynb", Type = "JNB" // Properties = new List<InstanceProperty>(){ new InstanceProperty{ key="port", value=nb.Info.Port}} }; InstancePayload.Create(objJNBInst); notebookLinkURL = notebookLinkURL.Replace(@"//", @"/"); // return(Ok(new { user = CURRENT_USER, id = id, message = message, url = notebookLinkURL.Replace(notebookLinkURL.Substring(0, notebookLinkURL.IndexOf("jnb")), "") })); } catch (Exception ex) { message = ex.Message; return(BadRequest(new { user = CURRENT_USER, id = id, message = message })); } }
public void StartAllAllowedInstances() { JupyterNotebookTool = new JupyterNotebook("http://localhost", "/jnb", new int[] { 8888, 8890 }); System.Console.WriteLine("Start Test : StartAllAllowedInstances"); var obj = new { base_url = "/", NotebookDir = TestDir + System.IO.Path.DirectorySeparatorChar + "HelloWorld.ipynb", ResourcePath = JNBFirstFile }; JupyterNotebookTool.StartTaskAsync((int)TaskTypes.Start, JNBFirstFile, (JObject)JObject.FromObject(obj)); System.Threading.Thread.Sleep(2000); Assert.True(JupyterNotebookTool.IsPortBusyInRange(8888, 8888, 8890)); var obj2 = new { base_url = "/", NotebookDir = TestDir + System.IO.Path.DirectorySeparatorChar + "HelloWorld2.ipynb", ResourcePath = JNBSecondFile }; JupyterNotebookTool.StartTaskAsync((int)TaskTypes.Start, JNBSecondFile, (JObject)JObject.FromObject(obj2)); System.Threading.Thread.Sleep(2000); Assert.True(JupyterNotebookTool.IsPortBusyInRange(8889, 8888, 8890)); var obj3 = new { base_url = "/", NotebookDir = TestDir + System.IO.Path.DirectorySeparatorChar + "HelloWorld3.ipynb", ResourcePath = JNBThirdFile }; JupyterNotebookTool.StartTaskAsync((int)TaskTypes.Start, JNBThirdFile, (JObject)JObject.FromObject(obj3)); System.Threading.Thread.Sleep(2000); Assert.True(JupyterNotebookTool.IsPortBusyInRange(8890, 8888, 8890)); System.Console.WriteLine("End Test : StartAllAllowedInstances"); }