This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bayesian compatibility and workspace cleaning with multi-tenancy (#417)
* Adapt to the last upstream changes * Make Bayesian plugin work with multi-tenancy (issue #376) by: - creating a service endpoint started on wsmaster along with the Bayesian Agent, to provide the required up-to-date token (from the user that started the workspace) from the machine token of the workspace agent - retrieving this token endpoint when starting the language server on the workspace agent. Signed-off-by: David Festal <dfestal@redhat.com>
- Loading branch information
1 parent
d344377
commit dcbb673
Showing
6 changed files
with
194 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
plugins/ls-bayesian-agent/src/main/java/com/redhat/bayesian/agent/BayesianAgentModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2016-2017 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package com.redhat.bayesian.agent; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.multibindings.Multibinder; | ||
import org.eclipse.che.api.agent.shared.model.Agent; | ||
import org.eclipse.che.inject.DynaModule; | ||
|
||
/** @author David Festal */ | ||
@DynaModule | ||
public class BayesianAgentModule extends AbstractModule { | ||
@Override | ||
protected void configure() { | ||
Multibinder<Agent> agents = Multibinder.newSetBinder(binder(), Agent.class); | ||
agents.addBinding().to(BayesianAgent.class); | ||
bind(BayesianTokenProvider.class); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
plugins/ls-bayesian-agent/src/main/java/com/redhat/bayesian/agent/BayesianTokenProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2016-2017 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package com.redhat.bayesian.agent; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.HeaderParam; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import org.eclipse.che.api.core.NotFoundException; | ||
import org.eclipse.che.api.workspace.server.WorkspaceSubjectRegistry; | ||
import org.eclipse.che.commons.subject.Subject; | ||
import org.eclipse.che.multiuser.machine.authentication.server.MachineTokenRegistry; | ||
import org.slf4j.Logger; | ||
|
||
@Path("/bayesian") | ||
@Singleton | ||
public class BayesianTokenProvider { | ||
private static final Logger LOG = getLogger(BayesianTokenProvider.class); | ||
|
||
@Inject private MachineTokenRegistry machineTokenRegistry; | ||
@Inject private WorkspaceSubjectRegistry workspaceSubjectRegistry; | ||
|
||
@GET | ||
@Path("/token") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getBayesianToken(@HeaderParam(HttpHeaders.AUTHORIZATION) String machineToken) | ||
throws NotFoundException { | ||
String workspaceId = machineTokenRegistry.getWorkspaceId(machineToken); | ||
LOG.debug("workspaceId for Bayesian recommender token retrieval: {}", workspaceId); | ||
Subject workspaceStarter = workspaceSubjectRegistry.getWorkspaceStarter(workspaceId); | ||
if (workspaceStarter == null) { | ||
LOG.error( | ||
"Subject that started workspace '{}' was not found during Bayesian recommender token retrieval.", | ||
workspaceId); | ||
throw new NotFoundException("Bayesian token not found"); | ||
} | ||
String keycloakToken = workspaceStarter.getToken(); | ||
if (keycloakToken == null) { | ||
LOG.error( | ||
"Keycloak token of the subject that started workspace '{}' (user name = '{}' )was not found during Bayesian recommender token retrieval.", | ||
workspaceId, | ||
workspaceStarter.getUserName()); | ||
throw new NotFoundException("Bayesian token not found"); | ||
} | ||
return Response.ok("\"" + keycloakToken + '"').build(); | ||
} | ||
} |