Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #114 from burmanm/remote_agent
Browse files Browse the repository at this point in the history
Modify remote agent install UI and make userfriendlier error messages(cherry picked from commit 66effaa)
Signed-off-by: Jay Shaughnessy <jshaughn@redhat.com>
  • Loading branch information
jmazzitelli authored and jshaughn committed Aug 29, 2014
1 parent 298bb22 commit 83f133d
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 124 deletions.
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2010 Red Hat, Inc.
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -35,6 +35,7 @@
import com.smartgwt.client.util.BooleanCallback;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Dialog;
import com.smartgwt.client.widgets.HTMLFlow;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
Expand Down Expand Up @@ -101,6 +102,8 @@ public class RemoteAgentInstallView extends EnhancedVLayout {
private CheckboxItem rememberMeCheckbox;
private VLayout agentInfoLayout;

private Dialog dialog;

private final boolean showInstallButton;
private final boolean showUninstallButton;
private final boolean showStartButton;
Expand Down Expand Up @@ -267,11 +270,7 @@ protected void doActualWork() {
}
});

agentStatusText = new StaticTextItem("agentStatus", MSG.view_remoteAgentInstall_agentStatus());
agentStatusText.setDefaultValue(MSG.view_remoteAgentInstall_agentStatusDefault());
agentStatusText.setRedrawOnChange(true);
agentStatusText.setStartRow(true);
agentStatusText.setEndRow(false);
createAgentStatusTextItem();

statusCheckButton = new ButtonItem("updateStatus", MSG.view_remoteAgentInstall_updateStatus());
statusCheckButton.setStartRow(false);
Expand Down Expand Up @@ -327,6 +326,15 @@ protected void doActualWork() {
return connectionForm;
}

private void createAgentStatusTextItem() {
agentStatusText = new StaticTextItem("agentStatus", MSG.view_remoteAgentInstall_agentStatus());
agentStatusText.setDefaultValue(MSG.view_remoteAgentInstall_agentStatusDefault());
agentStatusText.setRedrawOnChange(true);
agentStatusText.setStartRow(true);
agentStatusText.setEndRow(false);
}


private Layout getButtons() {
buttonsForm = new HLayout();

Expand Down Expand Up @@ -429,6 +437,8 @@ protected void doActualWork() {
private void doneProcessing() {
disableButtons(false);
hostAuthorized = false; // if the ssh fingerprint changes under us this forces the user to re-authorize again
dialog.hide();
dialog.destroy();
}

private void displayError(String msg) {
Expand All @@ -438,7 +448,27 @@ private void displayError(String msg) {
private void displayError(String msg, Throwable caught) {
CoreGUI.getErrorHandler().handleError(msg, caught);
String rootCause = ErrorHandler.getRootCauseMessage(caught);
String fullMsg = (rootCause == null) ? msg : msg + ": " + rootCause;

// JSch returns very bad error messages, transform them here before returning to the customer
String fullMsg = null;
if(rootCause != null && msg != null) {
String runtimeException = "java.lang.RuntimeException";
if("com.jcraft.jsch.JSchException:Auth cancel".equals(rootCause)) {
fullMsg = MSG.view_remoteAgentInstall_error_authFailed();
} else if(rootCause.indexOf("java.net.UnknownHostException") != -1) {
fullMsg = MSG.view_remoteAgentInstall_error_unknownHost();
} else if("java.net.ConnectException:Connection refused".equals(rootCause)) {
fullMsg = MSG.view_remoteAgentInstall_error_connRefused();
} else if(rootCause.indexOf(runtimeException) != -1) {
int exceptionEnd = rootCause.indexOf(runtimeException) + runtimeException.length() + 1; // remove : also
fullMsg = rootCause.substring(exceptionEnd);
}
}

// Fallback
if(fullMsg == null) {
fullMsg = (rootCause == null) ? msg : msg + ": " + rootCause;
}
SC.warn(fullMsg);
}

Expand All @@ -448,7 +478,7 @@ private void displayMessage(String msg) {
}

private void setAgentStatusText(String msg) {
if (agentStatusText != null && agentStatusText.isDrawn()) {
if (agentStatusText != null) {
agentStatusText.setValue(msg);
}
}
Expand Down Expand Up @@ -501,6 +531,8 @@ private void findAgentInstallPath() {

final String parentPath = getAgentInstallPath();

createWaitingWindow(MSG.view_remoteAgentInstall_findAgentWait(), true);

remoteInstallService.findAgentInstallPath(getRemoteAccessInfo(), parentPath, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
displayError(MSG.view_remoteAgentInstall_error_1(), caught);
Expand Down Expand Up @@ -541,6 +573,15 @@ public void onSuccess(String result) {
});
}

private void createWaitingWindow(String text, boolean show) {
dialog = new Dialog();
dialog.setMessage(text);
dialog.setIcon("[SKIN]notify.png");
dialog.draw();
dialog.setTitle(MSG.view_remoteAgentInstall_dialogTitle());
dialog.setShowCloseButton(false);
}

private void installAgent() {
disableButtons(true);

Expand Down Expand Up @@ -584,7 +625,7 @@ private void installAgent() {
return;
}

SC.showPrompt(MSG.view_remoteAgentInstall_waitForUpload());
createWaitingWindow(MSG.view_remoteAgentInstall_waitForUpload(), true);

Scheduler.get().scheduleEntry(new RepeatingCommand() {
@Override
Expand All @@ -601,7 +642,7 @@ public boolean execute() {
return true; // keep waiting, call us back later
}

SC.clearPrompt();
dialog.destroy();
reallyInstallAgent();
return false; // upload is done, we can stop calling ourselves
}
Expand All @@ -611,6 +652,9 @@ public boolean execute() {
private void reallyInstallAgent() {
disableButtons(true);
setAgentStatusText(MSG.view_remoteAgentInstall_installingPleaseWait());

createWaitingWindow(MSG.view_remoteAgentInstall_installingPleaseWait(), true);

SC.ask(MSG.view_remoteAgentInstall_overwriteAgentTitle(), MSG.view_remoteAgentInstall_overwriteAgentQuestion(),
new BooleanCallback() {
@Override
Expand Down Expand Up @@ -645,7 +689,7 @@ public void onSuccess(AgentInstallInfo result) {
result.getAgentAddress(), String.valueOf(result.getAgentPort())));
}

buildInstallInfoCanvas(agentInfoLayout, result);
buildInstallInfoCanvas(result);
agentInfoLayout.markForRedraw();
agentStatusCheck(); // we are relying on this to call doneProcessing(), we shouldn't do it here
}
Expand All @@ -661,6 +705,8 @@ public void onSuccess(AgentInstallInfo result) {
private void uninstallAgent() {
disableButtons(true);

createWaitingWindow(MSG.view_remoteAgentInstall_uninstallingPleaseWait(), true);

remoteInstallService.uninstallAgent(getRemoteAccessInfo(), new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
displayError(MSG.view_remoteAgentInstall_error_7(), caught);
Expand All @@ -686,6 +732,7 @@ public void onSuccess(String result) {

private void startAgent() {
disableButtons(true);
createWaitingWindow(MSG.view_remoteAgentInstall_startAgentPleaseWait(), true);
remoteInstallService.startAgent(getRemoteAccessInfo(), getAgentInstallPath(), new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
displayError(MSG.view_remoteAgentInstall_error_5(), caught);
Expand All @@ -704,6 +751,7 @@ public void onSuccess(String result) {

private void stopAgent() {
disableButtons(true);
createWaitingWindow(MSG.view_remoteAgentInstall_stopAgentPleaseWait(), true);
remoteInstallService.stopAgent(getRemoteAccessInfo(), getAgentInstallPath(), new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
displayError(MSG.view_remoteAgentInstall_error_6(), caught);
Expand All @@ -720,7 +768,7 @@ public void onSuccess(String result) {
});
}

private void buildInstallInfoCanvas(VLayout installInfo, AgentInstallInfo info) {
private void buildInstallInfoCanvas(AgentInstallInfo info) {
DynamicForm infoForm = new DynamicForm();
infoForm.setMargin(20);
infoForm.setWidth100();
Expand Down Expand Up @@ -772,10 +820,18 @@ protected Canvas getExpansionComponent(ListGridRecord record) {
listLayout.addMember(listGrid);
listCanvas.setCanvas(listLayout);

infoForm.setFields(infoHeader, version, path, owner, config, listCanvas);
installInfo.addMember(infoForm);
// Replace the current info with just the install steps
for (Canvas canvas : this.getChildren()) {
canvas.markForDestroy();
}

createAgentStatusTextItem();
infoForm.setFields(infoHeader, version, path, owner, config, agentStatusText, listCanvas);

addMember(infoForm);

return;
this.setMembersMargin(1);
this.markForRedraw();
}

private ListGridRecord[] getStepRecords(AgentInstallInfo info) {
Expand Down
Expand Up @@ -183,5 +183,4 @@ private static void getStackTraceAsCause(Throwable t, StringBuilder s, Throwable
getStackTraceAsCause(t, s, nextCause, newline);
}
}

}
Expand Up @@ -2164,17 +2164,22 @@ view_portlet_results_empty = No results found using specified criteria.
view_remoteAgentInstall_agentStatus = Agent Status
view_remoteAgentInstall_agentStatusDefault = -Click Update Status Button-
view_remoteAgentInstall_buttonFindAgent = Find Agent
view_remoteAgentInstall_findAgentWait = Searching, this may take a while...
view_remoteAgentInstall_connInfo = Connection Information
view_remoteAgentInstall_dialogTitle = Processing
view_remoteAgentInstall_error_1 = Error occurred while trying to find agent install path
view_remoteAgentInstall_error_2 = Could not find an agent installed when looking in common locations
view_remoteAgentInstall_error_3 = Could not find an agent installed at or under [{0}]
view_remoteAgentInstall_error_4 = Failed to install agent
view_remoteAgentInstall_error_5 = Failed to start agent
view_remoteAgentInstall_error_6 = Failed to stop agent
view_remoteAgentInstall_error_7 = Failed to uninstall agent.
view_remoteAgentInstall_error_authFailed = Authentication failed.
view_remoteAgentInstall_error_cannotPingAgent = Agent was installed on host [{0}] but it failed to be pinged on port [{1}] . Please make sure it has been fully configured and ensure there is no firewall blocking traffic to its endpoint.
view_remoteAgentInstall_error_connError = An SSH connection error occurred.
view_remoteAgentInstall_error_connRefused = Connection refused.
view_remoteAgentInstall_error_needAbsPath = You must provide an absolute path (i.e. a path starting with "/") when performing this operation.
view_remoteAgentInstall_error_unknownHost = Unknown hostname.
view_remoteAgentInstall_installAgent = Install Agent
view_remoteAgentInstall_installInfo = Agent Installation Information
view_remoteAgentInstall_installPath = Agent Install Path
Expand All @@ -2194,13 +2199,16 @@ view_remoteAgentInstall_rememberMe = Remember Me
view_remoteAgentInstall_result = Result
view_remoteAgentInstall_resultCode = ResultCode
view_remoteAgentInstall_startAgent = Start Agent
view_remoteAgentInstall_startAgentPleaseWait = Starting agent, please wait...
view_remoteAgentInstall_startAgentResults = Agent start results: [{0}]
view_remoteAgentInstall_step = Step
view_remoteAgentInstall_stopAgent = Stop Agent
view_remoteAgentInstall_stopAgentPleaseWait = Stopping agent, please wait...
view_remoteAgentInstall_stopAgentResults = Agent stop results: [{0}]
view_remoteAgentInstall_success = Agent installation complete
view_remoteAgentInstall_uninstallAgent = Uninstall Agent
view_remoteAgentInstall_uninstallAgentResults = Agent uninstall results: [{0}]
view_remoteAgentInstall_uninstallingPleaseWait = Uninstalling, this may take a few minutes...
view_remoteAgentInstall_uninstallSuccess = Uninstalled agent.
view_remoteAgentInstall_updateStatus = Update Status
view_remoteAgentInstall_waitForUpload = Please wait for the file uploads to complete...
Expand Down
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2010 Red Hat, Inc.
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -24,6 +24,7 @@

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;
Expand All @@ -36,6 +37,7 @@
import org.rhq.core.domain.common.composite.SystemSettings;
import org.rhq.core.domain.install.remote.AgentInstall;
import org.rhq.core.domain.install.remote.AgentInstallInfo;
import org.rhq.core.domain.install.remote.AgentInstallStep;
import org.rhq.core.domain.install.remote.CustomAgentInstallData;
import org.rhq.core.domain.install.remote.RemoteAccessInfo;
import org.rhq.core.domain.install.remote.SSHSecurityException;
Expand Down Expand Up @@ -206,6 +208,15 @@ public AgentInstallInfo installAgent(Subject subject, RemoteAccessInfo remoteAcc
SSHInstallUtility sshUtil = getSSHConnection(remoteAccessInfo);
try {
AgentInstallInfo info = sshUtil.installAgent(customData, String.valueOf(ai.getId()));

List<AgentInstallStep> steps = info.getSteps();
AgentInstallStep lastInstallStep = steps.get(steps.size() - 1);

// At the moment, SSHInstallUtility might throw RuntimeException as well if it fails. Lets unify this for now.
if(lastInstallStep.getResultCode() != 0) {
throw new RuntimeException(lastInstallStep.getDescription() + " failed, " + lastInstallStep.getResult());
}

return info;
} finally {
sshUtil.disconnect();
Expand Down

0 comments on commit 83f133d

Please sign in to comment.