in PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/azure/hdinsight/common/SparkSubmissionToolWindowProcessor.java [65:232]
public void initialize() {
ApplicationManager.getApplication().assertIsDispatchThread();
// TODO: Fix deprecated API "addUISettingsListener"
UISettings.getInstance().addUISettingsListener(new UISettingsListener() {
@Override
public void uiSettingsChanged(final UISettings uiSettings) {
synchronized (this) {
for (final IHtmlElement htmlElement : cachedInfo) {
htmlElement.changeTheme();
}
setToolWindowText(parserHtmlElementList(cachedInfo));
}
}
}, ApplicationManager.getApplication());
fontFace = jEditorPanel.getFont().getFamily();
final JPanel jPanel = new JPanel();
jPanel.setLayout(new GridBagLayout());
jEditorPanel.setMargin(JBUI.insetsLeft(10));
final JBScrollPane scrollPane = new JBScrollPane(jEditorPanel);
stopButton = new JButton(PluginUtil.getIcon(CommonConst.StopIconPath));
stopButton.setDisabledIcon(PluginUtil.getIcon(CommonConst.StopDisableIconPath));
stopButton.setEnabled(false);
stopButton.setToolTipText("stop execution of current application");
stopButton.addActionListener(e -> DefaultLoader.getIdeHelper().executeOnPooledThread(() -> {
if (clusterDetail != null) {
AppInsightsClient.create(HDInsightBundle.message("SparkSubmissionStopButtionClickEvent"),
null);
EventUtil.logEvent(EventType.info, HDINSIGHT,
HDInsightBundle.message("SparkSubmissionStopButtionClickEvent"), null);
try {
final String livyUrl = clusterDetail instanceof LivyCluster
? ((LivyCluster) clusterDetail).getLivyBatchUrl()
: null;
final HttpResponse deleteResponse =
SparkBatchSubmission.getInstance().killBatchJob(livyUrl, batchId);
if (deleteResponse.getCode() == 201 || deleteResponse.getCode() == 200) {
jobStatusManager.setJobKilled();
setInfo("========================Stop application successfully"
+ "=======================");
} else {
setError(String.format(
"Error : Failed to stop spark application. error code : %d, reason : %s.",
deleteResponse.getCode(),
deleteResponse.getContent()));
}
} catch (final IOException exception) {
setError("Error : Failed to stop spark application. exception : "
+ exception.toString());
}
}
}));
openSparkUIButton = new JButton(
PluginUtil.getIcon(IconPathBuilder
.custom(CommonConst.OpenSparkUIIconName)
.build()));
openSparkUIButton.setDisabledIcon(PluginUtil.getIcon(CommonConst.OpenSparkUIDisableIconPath));
openSparkUIButton.setEnabled(false);
openSparkUIButton.setToolTipText("open the corresponding Spark UI page");
openSparkUIButton.addActionListener(e -> {
if (Desktop.isDesktopSupported()) {
try {
if (jobStatusManager.isApplicationGenerated()) {
final String connectionURL = clusterDetail.getConnectionUrl();
final String sparkApplicationUrl =
clusterDetail.isEmulator()
? String.format(yarnRunningUIEmulatorUrlFormat,
((EmulatorClusterDetail) clusterDetail).getSparkHistoryEndpoint(),
jobStatusManager.getApplicationId())
: String.format(yarnRunningUIUrlFormat,
connectionURL,
jobStatusManager.getApplicationId());
Desktop.getDesktop().browse(new URI(sparkApplicationUrl));
}
} catch (final Exception browseException) {
DefaultLoader.getUIHelper().showError("Failed to browse spark application yarn url",
"Spark Submission");
}
}
});
final JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
buttonPanel.add(stopButton);
buttonPanel.add(openSparkUIButton);
final GridBagConstraints c00 = new GridBagConstraints();
c00.fill = GridBagConstraints.VERTICAL;
c00.weighty = 1;
c00.gridx = 0;
c00.gridy = 0;
jPanel.add(buttonPanel, c00);
final GridBagConstraints c10 = new GridBagConstraints();
c10.fill = GridBagConstraints.BOTH;
c10.weightx = 1;
c10.weighty = 1;
c10.gridx = 1;
c10.gridy = 0;
jPanel.add(scrollPane, c10);
toolWindow.getComponent().add(jPanel);
jEditorPanel.setEditable(false);
jEditorPanel.setOpaque(false);
jEditorPanel.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
jEditorPanel.addHyperlinkListener(e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (Desktop.isDesktopSupported()) {
try {
final String protocol = e.getURL().getProtocol();
if ("https".equals(protocol) || "http".equals(protocol)) {
Desktop.getDesktop().browse(e.getURL().toURI());
} else if ("file".equals(protocol)) {
final String path = e.getURL().getFile();
final File localFile = new File(path);
final File parentFile = localFile.getParentFile();
if (parentFile.exists() && parentFile.isDirectory()) {
Desktop.getDesktop().open(parentFile);
}
}
} catch (final Exception exception) {
DefaultLoader.getUIHelper().showError(exception.getMessage(), "Open Local Folder Error");
}
}
}
});
final PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent evt) {
if (ApplicationManager.getApplication().isDispatchThread()) {
changeSupportHandler(evt);
} else {
try {
SwingUtilities.invokeAndWait(() -> changeSupportHandler(evt));
} catch (final InterruptedException ignore) {
} catch (final InvocationTargetException e) {
e.printStackTrace();
}
}
}
private void changeSupportHandler(final PropertyChangeEvent evt) {
if ("toolWindowText".equals(evt.getPropertyName())) {
jEditorPanel.setText(evt.getNewValue().toString());
} else if ("isStopButtonEnable".equals(evt.getPropertyName())) {
stopButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
} else if ("isBrowserButtonEnable".equals(evt.getPropertyName())) {
openSparkUIButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
}
}
};
jEditorPanel.addPropertyChangeListener(propertyChangeListener);
changeSupport = new PropertyChangeSupport(jEditorPanel);
changeSupport.addPropertyChangeListener(propertyChangeListener);
}