Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add refresh button for storage container in job upload storage panel #2242

Merged
merged 2 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ class SparkSubmitJobUploadStorageModel {

@get:Transient @set:Transient var errorMsg: String? = null

@get:Transient @set:Transient var refreshContainersEnabled = true

fun getCredentialAzureBlobAccount(): String? = storageAccount?.let{ SERVICE_NAME_PREFIX + storageAccount }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,27 @@

package com.microsoft.azure.hdinsight.spark.ui

import com.intellij.openapi.ui.ComboBox
import com.intellij.ui.ComboboxWithBrowseButton
import com.intellij.uiDesigner.core.GridConstraints.*
import com.microsoft.azure.hdinsight.common.StreamUtil
import com.microsoft.intellij.forms.dsl.panel
import javax.swing.JLabel
import javax.swing.JTextArea
import javax.swing.JTextField

class SparkSubmissionJobUploadStorageAzureBlobCard: SparkSubmissionJobUploadStorageBasicCard() {
private val refreshButtonIconPath = "/icons/refresh.png"
private val storageAccountTip = "The default storage account of the HDInsight cluster, which can be found from HDInsight cluster properties of Azure portal."
private val storageKeyTip = "The storage key of the default storage account, which can be found from HDInsight cluster storage accounts of Azure portal."
private val storageAccountLabel = JLabel("Storage Account").apply { toolTipText = storageAccountTip }
val storageAccountField = JTextField().apply { toolTipText = storageAccountTip }
private val storageKeyLabel = JLabel("Storage Key").apply { toolTipText = storageKeyTip }
val storageKeyField = JTextArea().apply { toolTipText = storageKeyTip }
private val storageContainerLabel = JLabel("Storage Container")
val storageContainerComboBox = ComboBox<String>()
val storageContainerComboBox = ComboboxWithBrowseButton().apply {
Copy link
Member

@wezhang wezhang Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May we can remove the type ComboBox from the value storageContainerComboBox, just name it storageContainerUI may be enough. #Resolved

button.toolTipText = "Refresh"
button.icon = StreamUtil.getImageResourceFile(refreshButtonIconPath)
}

init {
val formBuilder = panel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,14 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU
// check storage info when cluster selection changes
registerStorageInfoCheck()

// refresh containers after account and key focus lost
arrayOf(view.storagePanel.azureBlobCard.storageAccountField, view.storagePanel.azureBlobCard.storageKeyField).forEach {
it.addFocusListener(object : FocusAdapter() {
override fun focusLost(e: FocusEvent?) {
refreshContainers().subscribe(
{ },
{ err -> log().warn(ExceptionUtils.getStackTrace(err)) })
}
})
// refresh containers after refresh button is clicked
view.storagePanel.azureBlobCard.storageContainerComboBox.button.addActionListener { _ ->
Copy link
Member

@wezhang wezhang Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can _ -> be removed? #Resolved

refreshContainers().subscribe(
{ },
{ err -> log().warn(ExceptionUtils.getStackTrace(err)) })
}
// after container is selected, update upload path
view.storagePanel.azureBlobCard.storageContainerComboBox.addItemListener { itemEvent ->
view.storagePanel.azureBlobCard.storageContainerComboBox.comboBox.addItemListener { itemEvent ->
if (itemEvent?.stateChange == ItemEvent.SELECTED) {
updateStorageAfterContainerSelected().subscribe(
{ },
Expand Down Expand Up @@ -172,6 +168,8 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU
fun refreshContainers(): Observable<SparkSubmitJobUploadStorageModel> {
return Observable.just(SparkSubmitJobUploadStorageModel())
.doOnNext(view::getData)
.map { toUpdate -> toUpdate.apply { refreshContainersEnabled = false } }
.doOnNext(view::setData)
.observeOn(Schedulers.io())
.map { toUpdate ->
toUpdate.apply {
Expand Down Expand Up @@ -203,6 +201,7 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU
errorMsg = "Can't get storage containers, check if the key matches"
}
}
refreshContainersEnabled = true
Copy link
Member

@wezhang wezhang Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enable operation needs to be put into .doOnEach #Resolved

}
}
.doOnNext { data ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ class SparkSubmissionJobUploadStorageWithUploadPathPanel : JPanel(), SettableCon
data.storageAccountType = SparkSubmitStorageType.BLOB
data.storageAccount = storagePanel.azureBlobCard.storageAccountField.text.trim()
data.storageKey = storagePanel.azureBlobCard.storageKeyField.text.trim()
data.containersModel = storagePanel.azureBlobCard.storageContainerComboBox.model as DefaultComboBoxModel
data.selectedContainer = storagePanel.azureBlobCard.storageContainerComboBox.selectedItem as? String
data.containersModel = storagePanel.azureBlobCard.storageContainerComboBox.comboBox.model as DefaultComboBoxModel<String>
data.selectedContainer = storagePanel.azureBlobCard.storageContainerComboBox.comboBox.selectedItem as? String
data.refreshContainersEnabled = storagePanel.azureBlobCard.storageContainerComboBox.button.isEnabled
}
storagePanel.clusterDefaultStorageCard.title -> {
data.storageAccountType = SparkSubmitStorageType.DEFAULT_STORAGE_ACCOUNT
Expand Down Expand Up @@ -117,10 +118,11 @@ class SparkSubmissionJobUploadStorageWithUploadPathPanel : JPanel(), SettableCon
data.storageKey
}
if (data.containersModel.size == 0 && StringUtils.isEmpty(storagePanel.errorMessage) && StringUtils.isNotEmpty(data.selectedContainer)) {
storagePanel.azureBlobCard.storageContainerComboBox.model = DefaultComboBoxModel(arrayOf(data.selectedContainer))
storagePanel.azureBlobCard.storageContainerComboBox.comboBox.model = DefaultComboBoxModel(arrayOf(data.selectedContainer))
} else {
storagePanel.azureBlobCard.storageContainerComboBox.model = data.containersModel
storagePanel.azureBlobCard.storageContainerComboBox.comboBox.model = data.containersModel as DefaultComboBoxModel<Any>
}
storagePanel.azureBlobCard.storageContainerComboBox.button.isEnabled = data.refreshContainersEnabled
}
}
ApplicationManager.getApplication().invokeLater(applyData, ModalityState.any())
Expand Down