Skip to content

Commit

Permalink
Open source companion commit for rstudio/rstudio-pro#893
Browse files Browse the repository at this point in the history
  • Loading branch information
kfeinauer committed Feb 21, 2019
1 parent f1a5181 commit a97ad3e
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/cpp/server/ServerSessionProxy.cpp
Expand Up @@ -81,8 +81,7 @@ bool proxyRequest(int requestType,
const boost::shared_ptr<const http::Request>& pRequest,
const r_util::SessionContext &context,
boost::shared_ptr<core::http::AsyncConnection> ptrConnection,
const http::ErrorHandler &errorHandler,
const http::ConnectionRetryProfile &connectionRetryProfile);
const http::ErrorHandler &errorHandler);

bool proxyLocalhostRequest(http::Request& request,
const std::string& port,
Expand Down Expand Up @@ -578,8 +577,7 @@ void proxyRequest(
invokeRequestFilter(pRequest.get());

// see if the request should be handled by the overlay
if (overlay::proxyRequest(requestType, pRequest, context, ptrConnection,
errorHandler, connectionRetryProfile))
if (overlay::proxyRequest(requestType, pRequest, context, ptrConnection, errorHandler))
{
// request handled by the overlay
return;
Expand Down Expand Up @@ -729,8 +727,9 @@ void proxyRpcRequest(
boost::shared_ptr<core::http::AsyncConnection> ptrConnection)
{
// validate the user if this is client_init
if (boost::algorithm::ends_with(ptrConnection->request().uri(),
"client_init"))
bool isClientInit = boost::algorithm::ends_with(ptrConnection->request().uri(),
"client_init");
if (isClientInit)
{
if (!validateUser(ptrConnection, username))
return;
Expand All @@ -741,7 +740,7 @@ void proxyRpcRequest(
if (!sessionContextForRequest(ptrConnection, username, &context))
return;

proxyRequest(RequestType::Rpc,
proxyRequest(isClientInit ? RequestType::ClientInit : RequestType::Rpc,
context,
ptrConnection,
boost::bind(handleRpcError, ptrConnection, context, _1),
Expand Down
3 changes: 1 addition & 2 deletions src/cpp/server/ServerSessionProxyOverlay.cpp
Expand Up @@ -31,8 +31,7 @@ bool proxyRequest(
const boost::shared_ptr<const http::Request>& pRequest,
const r_util::SessionContext& context,
boost::shared_ptr<http::AsyncConnection> ptrConnection,
const http::ErrorHandler& errorHandler,
const http::ConnectionRetryProfile& connectionRetryProfile)
const http::ErrorHandler& errorHandler)
{
// not proxying the request
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/server/include/server/ServerSessionProxy.hpp
Expand Up @@ -41,7 +41,8 @@ struct RequestType
{
Rpc,
Content,
Events
Events,
ClientInit
};
};

Expand Down
28 changes: 27 additions & 1 deletion src/gwt/src/org/rstudio/studio/client/RStudio.java
Expand Up @@ -77,6 +77,8 @@
import org.rstudio.studio.client.projects.ui.prefs.ProjectPreferencesDialogResources;
import org.rstudio.studio.client.rmarkdown.RmdOutputSatellite;
import org.rstudio.studio.client.rsconnect.ui.RSConnectDeploy;
import org.rstudio.studio.client.server.ServerError;
import org.rstudio.studio.client.server.ServerRequestCallback;
import org.rstudio.studio.client.shiny.ShinyApplicationSatellite;
import org.rstudio.studio.client.vcs.VCSApplication;
import org.rstudio.studio.client.workbench.codesearch.ui.CodeSearchResources;
Expand Down Expand Up @@ -181,6 +183,15 @@ private Command showProgress()
homeLabel.getElement().getStyle().setProperty("fontFamily", fontFamily);
homeLabel.getElement().getStyle().setProperty("fontSize", fontSize);
messagePanel.add(homeLabel);

connectionStatusLabel_ = new Label();
connectionStatusLabel_.getElement().getStyle().setWidth(100, Style.Unit.PCT);
connectionStatusLabel_.getElement().getStyle().setProperty("textAlign", "center");
connectionStatusLabel_.getElement().getStyle().setProperty("fontFamily", fontFamily);
connectionStatusLabel_.getElement().getStyle().setProperty("fontSize", "font-size: 6px;");
connectionStatusLabel_.getElement().getStyle().setMarginTop(8, Style.Unit.PX);
connectionStatusLabel_.getElement().getStyle().setMarginBottom(8, Style.Unit.PX);
messagePanel.add(connectionStatusLabel_);

statusPanel.add(messagePanel);
messagePanel.setVisible(false);
Expand Down Expand Up @@ -377,9 +388,23 @@ else if (PlumberAPISatellite.NAME.equals(view))
}
else
{
final ServerRequestCallback<String> connectionStatusCallback =
new ServerRequestCallback<String>() {
@Override
public void onResponseReceived(String message)
{
connectionStatusLabel_.setText(message);
}
@Override
public void onError(ServerError error)
{
}
};

RStudioGinjector.INSTANCE.getApplication().go(
RootLayoutPanel.get(),
dismissProgressAnimation_);
dismissProgressAnimation_,
connectionStatusCallback);
}
}

Expand Down Expand Up @@ -452,4 +477,5 @@ private void ensureStylesInjected()

private Command dismissProgressAnimation_;
private Timer showStatusTimer_;
private Label connectionStatusLabel_;
}
Expand Up @@ -155,7 +155,8 @@ public Application(ApplicationView view,
}

public void go(final RootLayoutPanel rootPanel,
final Command dismissLoadingProgress)
final Command dismissLoadingProgress,
final ServerRequestCallback<String> connectionStatusCallback)
{
rootPanel_ = rootPanel;

Expand Down Expand Up @@ -218,6 +219,8 @@ public void onError(ServerError error)
error.getUserMessage());
}
}) ;

sessionOpener_.getJobConnectionStatus(connectionStatusCallback);
}

@Handler
Expand Down
Expand Up @@ -30,6 +30,9 @@ public interface ApplicationServerOperations extends PrefsServerOperations
void clientInit(String baseURL,
ServerRequestCallback<SessionInfo> requestCallback);

// get current connection status for a session job
void getJobConnectionStatus(ServerRequestCallback<String> requestCallback);

// interrupt the current session
void interrupt(ServerRequestCallback<Void> requestCallback);

Expand Down
Expand Up @@ -322,10 +322,17 @@ public void logException(ClientException e,

public void clientInit(String baseURL,
final ServerRequestCallback<SessionInfo> requestCallback)
{
{
// generate a unique id to represent this client init request
// this allows us to request the current status of routing for this request
// for launcher jobs
if (clientInitId_.isEmpty())
clientInitId_ = StringUtil.makeRandomId(32);

// send init request (record clientId and version contained in response)
JSONArray params = new JSONArray();
params.set(0, new JSONString(baseURL));
params.set(1, new JSONString(clientInitId_));
sendRequest(RPC_SCOPE,
CLIENT_INIT,
params,
Expand All @@ -345,6 +352,11 @@ public void onError(ServerError error)
}
});
}

@Override
public void getJobConnectionStatus(final ServerRequestCallback<String> requestCallback)
{
}

private void setArrayString(JSONArray params, int index, List<String> what) {
JSONArray array = new JSONArray();
Expand Down Expand Up @@ -5875,6 +5887,7 @@ public void replaceCommentHeader(String command,
sendRequest(RPC_SCOPE, REPLACE_COMMENT_HEADER, params, callback);
}

protected String clientInitId_ = "";
private String clientId_;
private String clientVersion_ = "";
private JsObject launchParameters_;
Expand Down
Expand Up @@ -195,6 +195,13 @@ protected void onFailure()
}
});
}

/**
* Streams the session job's current connection details
*/
public void getJobConnectionStatus(final ServerRequestCallback<String> connectionStatusCallback)
{
}

protected void waitForSessionJobExit(final String afterRestartCommand,
Command onClosed, Command onFailure)
Expand Down

0 comments on commit a97ad3e

Please sign in to comment.