Esempio n. 1
0
 public void GetResourceLinkForOneRunningInstance()
 {
     System.Console.WriteLine("Start Test : GetResourceLinkForOneRunningInstance");
     StartSingleInstance();
     Assert.Contains("/jnb1/notebooks/HelloWorld.ipynb", JupyterNotebookTool.GetResourceLink(JNBFirstFile));
     StopSingleInstance();
     System.Console.WriteLine("End Test : GetResourceLinkForOneRunningInstance");
 }
Esempio n. 2
0
        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 }));
            }
        }