use of com.microsoft.azure.docker.model.EditableDockerHost in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerHostPage method initUIMainContainer.
private void initUIMainContainer(Composite mainContainer) {
dockerImageNameTextField.setText(dockerImageDescription.dockerImageName);
dockerImageNameTextField.setToolTipText(AzureDockerValidationUtils.getDockerImageNameTip());
dockerImageNameTextField.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent event) {
if (AzureDockerValidationUtils.validateDockerImageName(((Text) event.getSource()).getText())) {
errDispatcher.removeMessage("dockerImageNameTextField", dockerImageNameTextField);
setErrorMessage(null);
setPageComplete(doValidate());
} else {
errDispatcher.addMessage("dockerImageNameTextField", AzureDockerValidationUtils.getDockerImageNameTip(), null, IMessageProvider.ERROR, dockerImageNameTextField);
setErrorMessage("Invalid Docker image name");
setPageComplete(false);
}
}
});
String artifactPath;
if (project != null) {
try {
String projectName = project.getName();
artifactPath = project.getLocation() + "/" + projectName + ".war";
} catch (Exception ignored) {
artifactPath = "";
}
} else {
artifactPath = "";
}
if (artifactPath == null || artifactPath.isEmpty() || !Files.isRegularFile(Paths.get(artifactPath))) {
errDispatcher.addMessage("dockerArtifactPathTextField", AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR, dockerArtifactPathTextField);
setErrorMessage("Invalid artifact path");
} else {
dockerArtifactPathTextField.setText(artifactPath);
}
dockerArtifactPathTextField.setToolTipText(AzureDockerValidationUtils.getDockerArtifactPathTip());
dockerArtifactPathTextField.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent event) {
if (AzureDockerValidationUtils.validateDockerArtifactPath(((Text) event.getSource()).getText())) {
errDispatcher.removeMessage("dockerArtifactPathTextField", dockerArtifactPathTextField);
String artifactFileName = new File(((Text) event.getSource()).getText()).getName();
wizard.setPredefinedDockerfileOptions(artifactFileName);
setErrorMessage(null);
setPageComplete(doValidate());
} else {
errDispatcher.addMessage("dockerArtifactPathTextField", AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR, dockerArtifactPathTextField);
setErrorMessage("Invalid artifact path");
setPageComplete(false);
}
}
});
dockerArtifactPathBrowseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog fileDialog = new FileDialog(dockerArtifactPathBrowseButton.getShell(), SWT.OPEN);
fileDialog.setText("Select Artifact .WAR or .JAR");
fileDialog.setFilterPath(System.getProperty("user.home"));
fileDialog.setFilterExtensions(new String[] { "*.war;*.jar", "*.jar", "*.*" });
String path = fileDialog.open();
if (path == null || (!path.toLowerCase().contains(".war") && !path.toLowerCase().contains(".jar"))) {
return;
}
dockerArtifactPathTextField.setText(path);
String artifactFileName = new File(path).getName();
wizard.setPredefinedDockerfileOptions(artifactFileName);
setPageComplete(doValidate());
}
});
TableViewerColumn colHostName = createTableViewerColumn(dockerHostsTableViewer, "Name", 150, 1);
colHostName.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DockerHost) element).name;
}
});
TableViewerColumn colHostState = createTableViewerColumn(dockerHostsTableViewer, "State", 80, 2);
colHostState.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
DockerHost dockerHost = (DockerHost) element;
return dockerHost.hostVM.state != null ? dockerHost.hostVM.state.toString() : "TO_BE_CREATED";
}
});
TableViewerColumn colHostOS = createTableViewerColumn(dockerHostsTableViewer, "OS", 200, 3);
colHostOS.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DockerHost) element).hostOSType.toString();
}
});
TableViewerColumn colHostApiUrl = createTableViewerColumn(dockerHostsTableViewer, "API URL", 250, 4);
colHostApiUrl.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DockerHost) element).apiUrl.toString();
}
});
dockerHostsTableViewer.setContentProvider(new ArrayContentProvider());
dockerHostsList = new ArrayList<>();
dockerHostsTableViewer.setInput(dockerHostsList);
refreshDockerHostsTable(mainContainer);
if (!dockerHostsList.isEmpty()) {
if (dockerHostsTableSelection == null) {
dockerHostsTable.select(0);
dockerHostsTable.getItem(0).setChecked(true);
dockerHostsTableSelection = new DockerHostsTableSelection();
dockerHostsTableSelection.row = 0;
dockerHostsTableSelection.host = (DockerHost) dockerHostsTable.getItem(0).getData();
} else {
dockerHostsTable.select(dockerHostsTableSelection.row);
dockerHostsTable.getItem(dockerHostsTableSelection.row).setChecked(true);
}
} else {
dockerHostsTableSelection = null;
setPageComplete(false);
}
dockerHostsTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.CHECK) {
DockerHost dockerHost = (DockerHost) ((TableItem) e.item).getData();
if (dockerHostsTableSelection == null || dockerHostsTableSelection.host != dockerHost) {
dockerHostsTableSelection = new DockerHostsTableSelection();
dockerHostsTableSelection.row = dockerHostsTable.indexOf((TableItem) e.item);
dockerHostsTableSelection.host = dockerHost;
for (TableItem tableItem : dockerHostsTable.getItems()) {
if (tableItem != ((TableItem) e.item) && tableItem.getChecked()) {
tableItem.setChecked(false);
}
}
dockerHostsTable.redraw();
} else {
dockerHostsTableSelection = null;
}
setPageComplete(doValidate());
}
}
});
dockerHostsRefreshButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AzureDockerUIResources.updateAzureResourcesWithProgressDialog(mainContainer.getShell(), project);
refreshDockerHostsTable(mainContainer);
setPageComplete(doValidate());
sendButtonClickedTelemetry(REFRESH);
}
});
dockerHostsViewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int idx = dockerHostsTable.getSelectionIndex();
if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
DockerHost dockerHost = (DockerHost) dockerHostsTable.getItem(dockerHostsTable.getSelectionIndex()).getData();
if (dockerHost != null) {
AzureViewDockerDialog viewDockerDialog = new AzureViewDockerDialog(mainContainer.getShell(), project, dockerHost, dockerManager);
viewDockerDialog.open();
if (viewDockerDialog.getInternalExitCode() == AzureViewDockerDialog.UPDATE_EXIT_CODE) {
if (dockerHost != null && !dockerHost.isUpdating) {
AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project, new EditableDockerHost(dockerHost), dockerManager, true);
} else {
PluginUtil.displayErrorDialog(mainContainer.getShell(), "Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
}
}
setPageComplete(doValidate());
}
}
sendButtonClickedTelemetry(VIEW);
}
});
dockerHostsAddButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AzureNewDockerWizard newDockerWizard = new AzureNewDockerWizard(project, dockerManager);
WizardDialog createNewDockerHostDialog = new AzureWizardDialog(mainContainer.getShell(), newDockerWizard);
if (createNewDockerHostDialog.open() == Window.OK) {
DockerHost host = newDockerWizard.getDockerHost();
dockerImageDescription.host = host;
dockerImageDescription.hasNewDockerHost = true;
dockerImageDescription.sid = host.sid;
AzureDockerPreferredSettings dockerPrefferedSettings = dockerManager.getDockerPreferredSettings();
if (dockerPrefferedSettings == null) {
dockerPrefferedSettings = new AzureDockerPreferredSettings();
}
dockerPrefferedSettings.region = host.hostVM.region;
dockerPrefferedSettings.vmSize = host.hostVM.vmSize;
dockerPrefferedSettings.vmOS = host.hostOSType.name();
dockerManager.setDockerPreferredSettings(dockerPrefferedSettings);
dockerHostsList.add(0, host);
dockerHostsTable.setEnabled(false);
dockerHostsRefreshButton.setEnabled(false);
dockerHostsAddButton.setEnabled(false);
dockerHostsDeleteButton.setEnabled(false);
dockerHostsEditButton.setEnabled(false);
dockerHostsTableViewer.refresh();
dockerHostsTable.getItem(0).setChecked(true);
dockerHostsTable.select(0);
}
setPageComplete(doValidate());
sendButtonClickedTelemetry(ADD);
}
});
dockerHostsDeleteButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
//dockerHostsList
int idx = dockerHostsTable.getSelectionIndex();
if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
DockerHost deleteHost = (DockerHost) dockerHostsTable.getItem(idx).getData();
if (deleteHost != null) {
Azure azureClient = dockerManager.getSubscriptionsMap().get(deleteHost.sid).azureClient;
int option = AzureDockerUIResources.deleteAzureDockerHostConfirmationDialog(mainContainer.getShell(), azureClient, deleteHost);
if (option != 1 && option != 2) {
if (AzureDockerUtils.DEBUG)
System.out.format("User canceled delete Docker host op: %d\n", option);
return;
}
dockerHostsList.remove(deleteHost);
if (dockerHostsTableSelection != null && dockerHostsTableSelection.row == idx) {
dockerHostsTableSelection = null;
}
dockerHostsTableViewer.refresh();
AzureDockerUIResources.deleteDockerHost(mainContainer.getShell(), project, azureClient, deleteHost, option, new Runnable() {
@Override
public void run() {
dockerManager.getDockerHostsList().remove(deleteHost);
dockerManager.refreshDockerHostDetails();
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
refreshDockerHostsTable(mainContainer);
}
});
}
});
}
setPageComplete(doValidate());
}
sendButtonClickedTelemetry(DELETE);
}
});
dockerHostsEditButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int idx = dockerHostsTable.getSelectionIndex();
if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
DockerHost updateHost = (DockerHost) dockerHostsTable.getItem(idx).getData();
if (updateHost != null && !updateHost.isUpdating) {
AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project, new EditableDockerHost(updateHost), dockerManager, true);
} else {
PluginUtil.displayErrorDialog(mainContainer.getShell(), "Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
}
}
setPageComplete(doValidate());
sendButtonClickedTelemetry(EDIT);
}
});
}
use of com.microsoft.azure.docker.model.EditableDockerHost in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerWizard method deploy.
public String deploy() {
AzureDockerPreferredSettings dockerPreferredSettings = dockerManager.getDockerPreferredSettings();
if (dockerPreferredSettings == null) {
dockerPreferredSettings = new AzureDockerPreferredSettings();
}
dockerPreferredSettings.dockerApiName = dockerImageDescription.host.apiUrl;
dockerPreferredSettings.dockerfileOption = dockerImageDescription.predefinedDockerfile;
dockerPreferredSettings.region = dockerImageDescription.host.hostVM.region;
dockerPreferredSettings.vmSize = dockerImageDescription.host.hostVM.vmSize;
dockerPreferredSettings.vmOS = dockerImageDescription.host.hostOSType.name();
dockerManager.setDockerPreferredSettings(dockerPreferredSettings);
DefaultLoader.getIdeHelper().runInBackground(project, "Deploying Docker Container on Azure", false, true, "Deploying Web app to a Docker host on Azure...", new Runnable() {
@Override
public void run() {
try {
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
if (!dockerImageDescription.hasNewDockerHost) {
Session session = null;
do {
try {
// check if the Docker host is accessible
session = AzureDockerSSHOps.createLoginInstance(dockerImageDescription.host);
} catch (Exception e) {
session = null;
}
if (session == null) {
EditableDockerHost editableDockerHost = new EditableDockerHost(dockerImageDescription.host);
AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(PluginUtil.getParentShell(), project, editableDockerHost, dockerManager, false);
if (loginCredsDialog.open() == Window.OK) {
// Update Docker host log in credentials
dockerImageDescription.host.certVault = editableDockerHost.updatedDockerHost.certVault;
dockerImageDescription.host.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
dockerImageDescription.host.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
// AzureDockerVMOps.updateDockerHostVM(dockerManager.getSubscriptionsMap().get(dockerImageDescription.sid).azureClient, editableDockerHost.updatedDockerHost);
} else {
return;
}
}
} while (session == null);
}
// Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerImageDescription.sid).azureClient;
// DockerContainerDeployTask task = new DockerContainerDeployTask(project, azureClient, dockerImageDescription);
// task.queue();
createDockerContainerDeployTask(project, dockerImageDescription, dockerManager);
}
});
} catch (Exception e) {
String msg = "An error occurred while attempting to deploy to the selected Docker host." + "\n" + e.getMessage();
PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), "Failed to Deploy Web App as Docker Container", msg, e);
}
}
});
return AzureDockerUtils.getUrl(dockerImageDescription);
}
use of com.microsoft.azure.docker.model.EditableDockerHost in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method updateDockerHost.
public static void updateDockerHost(Shell shell, IProject project, EditableDockerHost editableDockerHost, AzureDockerHostsManager dockerManager, boolean doReset) {
DockerHost updateHost = editableDockerHost.originalDockerHost;
AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(PluginUtil.getParentShell(), project, editableDockerHost, dockerManager, doReset);
if (loginCredsDialog.open() == Window.OK) {
// Update Docker host log in credentials
updateHost.isUpdating = true;
DefaultLoader.getIdeHelper().runInBackground(project, String.format("Updating %s Log In Credentials", updateHost.name), false, true, String.format("Updating log in credentials for %s...", updateHost.name), new Runnable() {
@Override
public void run() {
try {
AzureDockerVMOps.updateDockerHostVM(dockerManager.getSubscriptionsMap().get(updateHost.sid).azureClient, editableDockerHost.updatedDockerHost);
updateHost.certVault = editableDockerHost.updatedDockerHost.certVault;
updateHost.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
updateHost.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
updateHost.hasKeyVault = false;
updateHost.certVault.uri = "";
updateHost.certVault.name = "";
Session session = AzureDockerSSHOps.createLoginInstance(updateHost);
AzureDockerVMOps.UpdateCurrentDockerUser(session);
updateHost.session = session;
} catch (Exception ee) {
if (AzureDockerUtils.DEBUG)
ee.printStackTrace();
log.log(Level.SEVERE, "dockerHostsEditButton.addSelectionListener", ee);
}
updateHost.isUpdating = false;
}
});
}
}
use of com.microsoft.azure.docker.model.EditableDockerHost in project azure-tools-for-java by Microsoft.
the class ViewDockerHostAction method actionPerformed.
@Override
public void actionPerformed(NodeActionEvent e) {
IProject project;
try {
project = AzureDockerUIResources.getCurrentSelectedProject();
} catch (Exception Ignored) {
project = null;
}
if (project == null) {
project = (IProject) dockerHostNode.getProject();
}
AzureViewDockerDialog viewDockerDialog = new AzureViewDockerDialog(PluginUtil.getParentShell(), project, dockerHost, dockerManager);
viewDockerDialog.open();
if (viewDockerDialog.getInternalExitCode() == AzureViewDockerDialog.UPDATE_EXIT_CODE) {
if (dockerHost != null && !dockerHost.isUpdating) {
AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project, new EditableDockerHost(dockerHost), dockerManager, true);
} else {
PluginUtil.displayErrorDialog(PluginUtil.getParentShell(), "Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
}
}
}
use of com.microsoft.azure.docker.model.EditableDockerHost in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method updateDockerHost.
public static void updateDockerHost(Project project, EditableDockerHost editableDockerHost, AzureDockerHostsManager dockerManager, boolean doReset) {
AppInsightsClient.createByType(AppInsightsClient.EventType.DockerHost, "", "Update");
AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(project, editableDockerHost, dockerManager, doReset);
loginCredsDialog.show();
if (loginCredsDialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
// Update Docker host log in credentials
DockerHost updateHost = editableDockerHost.originalDockerHost;
updateHost.isUpdating = true;
DefaultLoader.getIdeHelper().runInBackground(project, String.format("Updating %s Log In Credentials", updateHost.name), false, true, String.format("Updating log in credentials for %s...", updateHost.name), new Runnable() {
@Override
public void run() {
try {
AzureDockerVMOps.updateDockerHostVM(dockerManager.getSubscriptionsMap().get(updateHost.sid).azureClient, editableDockerHost.updatedDockerHost);
updateHost.certVault = editableDockerHost.updatedDockerHost.certVault;
updateHost.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
updateHost.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
updateHost.hasKeyVault = false;
updateHost.certVault.uri = "";
updateHost.certVault.name = "";
Session session = AzureDockerSSHOps.createLoginInstance(updateHost);
AzureDockerVMOps.UpdateCurrentDockerUser(session);
updateHost.session = session;
} catch (Exception ee) {
if (AzureDockerUtils.DEBUG)
ee.printStackTrace();
LOGGER.error("onEditDockerHostAction", ee);
}
updateHost.isUpdating = false;
}
});
}
}
Aggregations