Skip to content

Conversation

TheKorpos
Copy link
Contributor

@TheKorpos TheKorpos commented Apr 30, 2025

Previously, the REST API base path could be set in the Jupyter kernel only as part of the deployment process: either during the kernel installation by using --api-base-path or by using an environmental variable.

This PR adds a new %repo command that allows users to change the API base path in the running kernel. The usage of this command is:

%repo [<BASE PATH>]

Set the API base path for the repository accessed by the %projects, %publish and %load commands.
<BASE PATH> is a URL (possibly including port number), such as: https://my.domain.com/sysml_repo:9000.
If <BASE PATH> is not given, the current repository base path is printed.
If <BASE PATH> is given, the repository base path is set to this.

@TheKorpos TheKorpos requested a review from seidewitz April 30, 2025 16:39
@seidewitz seidewitz changed the title ST6RI-836 Added option that allows changing the API basePath in a running Jupyter kernel ST6RI-836 Add option that allows changing the API basePath in a running Jupyter kernel Apr 30, 2025
@seidewitz seidewitz self-assigned this Apr 30, 2025
@seidewitz seidewitz added this to the 2025-04 milestone Apr 30, 2025
Copy link
Member

@seidewitz seidewitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%api-base-path is an awkward name for a command. How about something like %repo instead. The help text should then say:

Usage: %repo [<BASE PATH>]

If <BASE PATH> is not given, print the current repository base path.
If <BASE PATH> is given, set the repository base path.

<BASE PATH> is a URL giving the API base path for the repository access by the %projects, %publish and %load commands. 
For example: https://my.domain.com/sysml_repo

- updated help string
- fixed '-h' flag
@TheKorpos
Copy link
Contributor Author

%api-base-path is an awkward name for a command. How about something like %repo instead. The help text should then say:

Usage: %repo [<BASE PATH>]

If <BASE PATH> is not given, print the current repository base path.
If <BASE PATH> is given, set the repository base path.

<BASE PATH> is a URL giving the API base path for the repository access by the %projects, %publish and %load commands. 
For example: https://my.domain.com/sysml_repo

Hi @seidewitz,
I've udpated the magic command name and help strings.

For the example URL I used the default value (http://sysml2-dev.intercax.com:9000), it's more consistent with the new help strings, and default values we used in ST6RI-178.

Also, I removed the part 'The api base path is:' from the output of this command so now it simply prints the current base path.

@seidewitz
Copy link
Member

For the example URL I used the default value (http://sysml2-dev.intercax.com:9000), it's more consistent with the new help strings, and default values we used in ST6RI-178.

I specifically do not want to put a real domain in the help text. The Intercax deployment will not be the default forever, and may even change in the near future. And the default should particularly not be the sysml2-dev server. This is for internal development use, and the URL is not supposed to be public.

@TheKorpos
Copy link
Contributor Author

I specifically do not want to put a real domain in the help text. The Intercax deployment will not be the default forever, and may even change in the near future. And the default should particularly not be the sysml2-dev server. This is for internal development use, and the URL is not supposed to be public.

I see. I changed it to the one you wrote.

@TheKorpos TheKorpos requested a review from seidewitz May 6, 2025 13:51
@ujhelyiz ujhelyiz changed the base branch from master to ST6RI-178 May 15, 2025 09:24
@seidewitz
Copy link
Member

This probably has more to do with ST6RI-682 than ST6RI-836, but I didn't notice it until I changed repositories.

After doing %repo "http://sysml2-sst.intercax.com:9000", I got an exception when I tried reading a crtain project that was already in that repository:

%load "Spacecraft project with Element CRUD - 2025-05-07 11:54:28.544540"

API base path: http://sysml2-sst.intercax.com:9000/

Selected branch main (7824e4cc-c649-405b-9871-44ad2ff07e9b)
Downloading model...

---------------------------------------------------------------------------
java.lang.UnsupportedOperationException: Revision has no remote!
	at org.omg.sysml.util.repository.Revision.fetchRemote(Revision.java:84)
	at org.omg.sysml.interactive.SysMLInteractive.load(SysMLInteractive.java:555)
	at org.omg.sysml.interactive.SysMLInteractive.load(SysMLInteractive.java:529)
	at org.omg.sysml.jupyter.kernel.magic.Load.load(Load.java:69)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at io.github.spencerpark.jupyter.kernel.magic.registry.Magics.invoke(Magics.java:89)
	at io.github.spencerpark.jupyter.kernel.magic.registry.Magics.access$000(Magics.java:8)
	at io.github.spencerpark.jupyter.kernel.magic.registry.Magics$LineReflectionMagicFunction.execute(Magics.java:149)
	at io.github.spencerpark.jupyter.kernel.magic.registry.Magics.applyLineMagic(Magics.java:26)
	at org.omg.sysml.jupyter.kernel.SysMLKernel.eval(SysMLKernel.java:95)
	at io.github.spencerpark.jupyter.kernel.BaseKernel.handleExecuteRequest(BaseKernel.java:334)
	at io.github.spencerpark.jupyter.channels.ShellChannel.lambda$bind$0(ShellChannel.java:64)
	at io.github.spencerpark.jupyter.channels.Loop.lambda$new$0(Loop.java:21)
	at io.github.spencerpark.jupyter.channels.Loop.run(Loop.java:78)

Other projects seem to load OK. The name of this particular project is not consistent with the old format for publishing from Jupyter, so I suspect it was added by someone using the API directly and may be ill-formed in some way. However, if that is the case, it would be better if we generated some sort of error message, rather than an exception, if possible

TheKorpos added 2 commits May 21, 2025 14:26
- when trying to query a project by id instead of throwing an exception
getProjectById return null. This matches with the logic used in by
getProjectByName
@TheKorpos
Copy link
Contributor Author

TheKorpos commented May 21, 2025

java.lang.UnsupportedOperationException: Revision has no remote!

When a branch has no head commit the logic creates and returns a local (no remote state) revision. The future head commit of the branch. Once this commit is published (delta between empty remote state and local state) it becomes 'remote'.
The UnsupportedOperation exception happens when fetch is called on a revision that has no remote.

In this case a project is empty (no commits) but %load still tires to fetch the non-existing remote state.

I added a check to prevent this from happening and show the following error for empty branches:

ERROR:Branch has no head commit

I've made another cosmetic change. When %load --id=<PROJECT ID> is used and the project is not found an exception was thrown (informing about error code: 404). I changed that to the message ERROR:Project doesn't exist to match the output with %load --name=<PROJECT NAME>.

Additionally, it might be a good idea to move the printing of repository URL to an earlier stage in %load. Currently it happens after the error messages, so there is no information in case of a Project doesn't exist error about which repository is being used.

@seidewitz
Copy link
Member

Additionally, it might be a good idea to move the printing of repository URL to an earlier stage in %load.

Done.

@seidewitz seidewitz merged commit 7808b57 into master May 22, 2025
2 checks passed
@seidewitz
Copy link
Member

Note: PR description has been updated per help text changes made in PR #649.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants