che icon indicating copy to clipboard operation
che copied to clipboard

How to know workspace Id

Open mstavares opened this issue 8 years ago • 6 comments

Hi,

I would like to know if there is a way to know in a plugin the current workspace id. There is a listener that I can use for that?

Thanks

mstavares avatar Jul 23 '18 11:07 mstavares

I don't know scope of your question... If you ask about current GWT IDE, so you can inject and use: https://github.com/eclipse/che/blob/master/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/context/AppContextImpl.java#L140

To indicate that workspace is ready or running we have workspace ready event and workspace running event

AndrienkoAleksandr avatar Jul 23 '18 11:07 AndrienkoAleksandr

Hi @AndreyChizhikov,

Thanks :) Is it possible to retrieve this information by workspace id?

"dev-machine": { "attributes": { "memoryLimitBytes": "2147483648" }, "servers": { "5000/tcp": { "url": "http://172.17.0.1:32771", "attributes": {}, "status": "UNKNOWN" }, "wsagent/ws": { "url": "ws://172.17.0.1:32775/wsagent", "attributes": {}, "status": "UNKNOWN" },

I can fetch it through the webservice, but I would like to have it through Java code like I did for workspace Id.

mstavares avatar Jul 24 '18 09:07 mstavares

@mstavares In the GWT code you can use WorkspaceServiceClient: Get workspace config by Id

AndrienkoAleksandr avatar Jul 24 '18 09:07 AndrienkoAleksandr

You can use also https://github.com/eclipse/che/blob/master/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/context/AppContextImpl.java#L130

AndrienkoAleksandr avatar Jul 24 '18 09:07 AndrienkoAleksandr

Hi @AndrienkoAleksandr I'm trying to use AppContext but I have some issues.

"runtime": { "machines": { "frontend": { "attributes": { "memoryLimitBytes": "1073741824" }, "servers": { "exec-agent/ws": { "url": "ws://172.17.0.1:32943/connect", "attributes": {}, "status": "UNKNOWN" }, "8081/tcp": { "url": "http://172.17.0.1:32942", "attributes": { "type": "frontend" },

I need to discover this URL dynamically in order to load it in an iFrame.

"url": "http://172.17.0.1:32942", <<

`
@Singleton public class FrontendAction extends BaseAction {

...

@Override public void actionPerformed(ActionEvent e) {

Map<String, ServerImpl> servers = appContext.getWorkspace().getRuntime().getMachines().get("frontend").getServers();
for (Map.Entry<String, ServerImpl> entry : servers.entrySet()) {
  if(entry.getValue().getAttributes().get("type").equalsIgnoreCase("frontend")) {
    frontEndViewPresenter.setUrl(entry.getValue().getUrl());
  }
}

workspaceAgent.openPart(frontEndViewPresenter, PartStackType.TOOLING);
workspaceAgent.setActivePart(frontEndViewPresenter);

}`

I don't know why but right now my button is not working, and to get worse I can't debug this class and I don't know why. I set the break point there but isn't working.

Could you help me again please?

mstavares avatar Jul 26 '18 16:07 mstavares

Hi @AndrienkoAleksandr ,

I have already found a way to solve it. I have subscribed for an event which is triggered when my workspace is up, then I use the AppContext in order to fetch the information that I need.

Thanks for your help.

mstavares avatar Jul 31 '18 07:07 mstavares