use of com.microsoft.azure.docker.model.DockerHost 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.DockerHost in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method publish2DockerHostContainer.
public static void publish2DockerHostContainer(Shell shell, IProject project, DockerHost host) {
try {
AzureDockerUIResources.createArtifact(shell, project);
AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureAuthManager == null) {
return;
}
AzureDockerHostsManager dockerManager = AzureDockerHostsManager.getAzureDockerHostsManager(azureAuthManager);
if (!dockerManager.isInitialized()) {
AzureDockerUIResources.updateAzureResourcesWithProgressDialog(shell, project);
if (AzureDockerUIResources.CANCELED) {
return;
}
dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(null);
}
if (dockerManager.getSubscriptionsMap().isEmpty()) {
PluginUtil.displayErrorDialog(shell, "Create Docker Host", "Must select an Azure subscription first");
return;
}
DockerHost dockerHost = (host != null) ? host : (dockerManager.getDockerPreferredSettings() != null) ? dockerManager.getDockerHostForURL(dockerManager.getDockerPreferredSettings().dockerApiName) : null;
AzureDockerImageInstance dockerImageDescription = dockerManager.getDefaultDockerImageDescription(project.getName(), dockerHost);
AzureSelectDockerWizard selectDockerWizard = new AzureSelectDockerWizard(project, dockerManager, dockerImageDescription);
WizardDialog selectDockerHostDialog = new AzureWizardDialog(shell, selectDockerWizard);
if (dockerHost != null) {
selectDockerWizard.selectDefaultDockerHost(dockerHost, true);
}
if (selectDockerHostDialog.open() == Window.OK) {
try {
String url = selectDockerWizard.deploy();
if (AzureDockerUtils.DEBUG)
System.out.println("Web app published at: " + url);
} catch (Exception ex) {
PluginUtil.displayErrorDialogAndLog(shell, "Unexpected error detected while publishing to a Docker container", ex.getMessage(), ex);
log.log(Level.SEVERE, "publish2DockerHostContainer: " + ex.getMessage(), ex);
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "publish2DockerHostContainer: " + e.getMessage(), e);
e.printStackTrace();
}
}
use of com.microsoft.azure.docker.model.DockerHost in project azure-tools-for-java by Microsoft.
the class AzureNewDockerWizard method createHost.
public void createHost() {
AzureDockerPreferredSettings dockerPreferredSettings = dockerManager.getDockerPreferredSettings();
if (dockerPreferredSettings == null) {
dockerPreferredSettings = new AzureDockerPreferredSettings();
}
dockerPreferredSettings.dockerApiName = newHost.apiUrl;
dockerPreferredSettings.region = newHost.hostVM.region;
dockerPreferredSettings.vmSize = newHost.hostVM.vmSize;
dockerPreferredSettings.vmOS = newHost.hostOSType.name();
dockerManager.setDockerPreferredSettings(dockerPreferredSettings);
Job createDockerHostJob = new Job("Creating Docker virtual machine " + newHost.name) {
@Override
protected IStatus run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask("start task", 100);
try {
DockerHost dockerHost = newHost;
progressMonitor.subTask(String.format("Reading subscription details for Docker host %s ...", dockerHost.apiUrl));
progressMonitor.worked(5);
Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient;
if (progressMonitor.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 0) {
progressMonitor.done();
return Status.CANCEL_STATUS;
}
}
progressMonitor.subTask(String.format("Creating new virtual machine %s ...", dockerHost.name));
progressMonitor.worked(10);
if (AzureDockerUtils.DEBUG)
System.out.println("Creating new virtual machine: " + new Date().toString());
AzureDockerVMOps.createDockerHostVM(azureClient, dockerHost);
if (AzureDockerUtils.DEBUG)
System.out.println("Done creating new virtual machine: " + new Date().toString());
if (progressMonitor.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 0) {
progressMonitor.done();
return Status.CANCEL_STATUS;
}
}
progressMonitor.subTask("Getting the new Docker virtual machines details...");
progressMonitor.worked(5);
if (AzureDockerUtils.DEBUG)
System.out.println("Getting the new Docker hosts details: " + new Date().toString());
VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
if (vm != null) {
DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
if (updatedHost != null) {
dockerHost.hostVM = updatedHost.hostVM;
dockerHost.apiUrl = updatedHost.apiUrl;
}
}
if (AzureDockerUtils.DEBUG)
System.out.println("Done getting the new Docker hosts details: " + new Date().toString());
if (progressMonitor.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 0) {
progressMonitor.done();
return Status.CANCEL_STATUS;
}
}
progressMonitor.subTask(String.format("Waiting for virtual machine %s to be up...", dockerHost.name));
progressMonitor.worked(55);
if (AzureDockerUtils.DEBUG)
System.out.println("Waiting for virtual machine to be up: " + new Date().toString());
AzureDockerVMOps.waitForVirtualMachineStartup(azureClient, dockerHost);
if (AzureDockerUtils.DEBUG)
System.out.println("Done Waiting for virtual machine to be up: " + new Date().toString());
if (progressMonitor.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 0) {
progressMonitor.done();
return Status.CANCEL_STATUS;
}
}
progressMonitor.subTask(String.format("Configuring Docker service for %s ...", dockerHost.apiUrl));
progressMonitor.worked(15);
if (AzureDockerUtils.DEBUG)
System.out.println("Configuring Docker host: " + new Date().toString());
AzureDockerVMOps.installDocker(dockerHost);
if (AzureDockerUtils.DEBUG)
System.out.println("Done configuring Docker host: " + new Date().toString());
if (AzureDockerUtils.DEBUG)
System.out.println("Finished setting up Docker host");
if (progressMonitor.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 0) {
progressMonitor.done();
return Status.CANCEL_STATUS;
}
}
if (dockerHost.certVault != null && dockerHost.certVault.hostName != null) {
AzureDockerUIResources.createDockerKeyVault(dockerHost, dockerManager);
}
progressMonitor.subTask("Refreshing the Docker virtual machines details...");
progressMonitor.worked(5);
if (AzureDockerUtils.DEBUG)
System.out.println("Refreshing Docker hosts details: " + new Date().toString());
vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
if (vm != null) {
DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
if (updatedHost != null) {
updatedHost.sid = dockerHost.sid;
updatedHost.hostVM.sid = dockerHost.hostVM.sid;
if (updatedHost.certVault == null) {
updatedHost.certVault = dockerHost.certVault;
updatedHost.hasPwdLogIn = dockerHost.hasPwdLogIn;
updatedHost.hasSSHLogIn = dockerHost.hasSSHLogIn;
updatedHost.isTLSSecured = dockerHost.isTLSSecured;
}
dockerManager.addDockerHostDetails(updatedHost);
if (AzureUIRefreshCore.listeners != null) {
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.ADD, updatedHost));
}
}
}
if (AzureDockerUtils.DEBUG)
System.out.println("Done refreshing Docker hosts details: " + new Date().toString());
if (progressMonitor.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 0) {
progressMonitor.done();
return Status.CANCEL_STATUS;
}
}
progressMonitor.done();
return Status.OK_STATUS;
} catch (Exception e) {
String msg = "An error occurred while attempting to create Docker host." + "\n" + e.getMessage();
log.log(Level.SEVERE, "createHost: " + msg, e);
e.printStackTrace();
return Status.CANCEL_STATUS;
}
// progressMonitor.subTask("");
// progressMonitor.worked(1);
// if (progressMonitor.isCanceled()) {
// if (displayWarningOnCreateHostCancelAction() == 0) {
// progressMonitor.done();
// return Status.CANCEL_STATUS;
// }
// }
//
// for (int i = 0; i < 10; i++) {
// try {
// Thread.sleep(3000);
// progressMonitor.subTask("doing " + i);
// // Report that 10 units are done
// progressMonitor.worked(10);
// } catch (InterruptedException e1) {
// e1.printStackTrace();
// }
// }
}
};
createDockerHostJob.schedule();
// DefaultLoader.getIdeHelper().runInBackground(null, "Creating Docker virtual machine " + newHost.name + "...", false, true, "Creating Docker virtual machine " + newHost.name + "...", new Runnable() {
// @Override
// public void run() {
// DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
// @Override
// public void run() {
//
// }
// });
// }
// });
}
use of com.microsoft.azure.docker.model.DockerHost in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerHostPage method selectDefaultDockerHost.
public void selectDefaultDockerHost(DockerHost dockerHost, boolean selectOtherHosts) {
if (dockerHost != null) {
int idx = 0;
DockerHost selected = null;
for (DockerHost host : dockerHostsList) {
if (dockerHost.apiUrl.equals(host.apiUrl)) {
selected = host;
break;
}
idx++;
}
if (selected != null) {
if (dockerHostsTableSelection == null) {
dockerHostsTableSelection = new DockerHostsTableSelection();
}
dockerHostsTableSelection.row = idx;
dockerHostsTableSelection.host = selected;
} else {
dockerHostsTableSelection = null;
}
}
}
use of com.microsoft.azure.docker.model.DockerHost 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);
}
});
}
Aggregations