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(Project project) {
try {
AzureDockerUIResources.CANCELED = false;
AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureAuthManager == null) {
System.out.println("ERROR! Not signed in!");
return;
}
AzureDockerHostsManager dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(azureAuthManager);
if (!dockerManager.isInitialized()) {
AzureDockerUIResources.updateAzureResourcesWithProgressDialog(project);
if (AzureDockerUIResources.CANCELED) {
return;
}
}
DockerHost dockerHost = (dockerManager.getDockerPreferredSettings() != null) ? dockerManager.getDockerHostForURL(dockerManager.getDockerPreferredSettings().dockerApiName) : null;
AzureDockerImageInstance dockerImageDescription = dockerManager.getDefaultDockerImageDescription(project.getName(), dockerHost);
AzureSelectDockerWizardModel model = new AzureSelectDockerWizardModel(project, dockerManager, dockerImageDescription);
AzureSelectDockerWizardDialog wizard = new AzureSelectDockerWizardDialog(model);
if (dockerHost != null) {
model.selectDefaultDockerHost(dockerHost, true);
}
wizard.show();
if (wizard.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
try {
String url = wizard.deploy();
if (AzureDockerUtils.DEBUG)
System.out.println("Web app published at: " + url);
} catch (Exception ex) {
PluginUtil.displayErrorDialogAndLog(message("webAppDplyErr"), ex.getMessage(), ex);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
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(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;
}
});
}
}
use of com.microsoft.azure.docker.model.DockerHost in project azure-tools-for-java by Microsoft.
the class AzureNewDockerWizardDialog method create.
public void create() {
DockerHost dockerHost = model.getDockerHost();
AzureDockerPreferredSettings dockerPreferredSettings = model.getDockerManager().getDockerPreferredSettings();
if (dockerPreferredSettings == null) {
dockerPreferredSettings = new AzureDockerPreferredSettings();
}
dockerPreferredSettings.dockerApiName = dockerHost.apiUrl;
dockerPreferredSettings.region = dockerHost.hostVM.region;
dockerPreferredSettings.vmSize = dockerHost.hostVM.vmSize;
dockerPreferredSettings.vmOS = dockerHost.hostOSType.name();
model.getDockerManager().setDockerPreferredSettings(dockerPreferredSettings);
ProgressManager.getInstance().run(new Task.Backgroundable(model.getProject(), "Creating Docker Host on Azure...", true) {
@Override
public void run(ProgressIndicator progressIndicator) {
try {
progressIndicator.setFraction(.05);
progressIndicator.setText2(String.format("Reading subscription details for Docker host %s ...", dockerHost.apiUrl));
AzureDockerHostsManager dockerManager = model.getDockerManager();
Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient;
if (progressIndicator.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 1) {
return;
}
}
progressIndicator.setFraction(.10);
progressIndicator.setText2(String.format("Creating new virtual machine %s ...", dockerHost.name));
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 (progressIndicator.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 1) {
return;
}
}
progressIndicator.setFraction(.60);
progressIndicator.setIndeterminate(true);
progressIndicator.setText2("Getting the new Docker virtual machines details...");
if (AzureDockerUtils.DEBUG)
System.out.println("Getting the new Docker virtual machines details: " + new Date().toString());
// dockerManager.refreshDockerHostDetails();
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 virtual machines details: " + new Date().toString());
if (progressIndicator.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 1) {
return;
}
}
progressIndicator.setFraction(.65);
progressIndicator.setText2(String.format("Waiting for virtual machine %s to be up...", dockerHost.name));
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 (progressIndicator.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 1) {
return;
}
}
progressIndicator.setFraction(.75);
progressIndicator.setText2(String.format("Configuring Docker service for %s ...", dockerHost.apiUrl));
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 (progressIndicator.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 1) {
return;
}
}
if (dockerHost.certVault != null && dockerHost.certVault.hostName != null) {
AzureDockerUIResources.createDockerKeyVault(model.getProject(), dockerHost, dockerManager);
}
progressIndicator.setFraction(.90);
progressIndicator.setIndeterminate(true);
progressIndicator.setText2("Refreshing the Docker virtual machines details...");
if (AzureDockerUtils.DEBUG)
System.out.println("Refreshing Docker hosts details: " + new Date().toString());
// dockerManager.refreshDockerHostDetails();
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 (progressIndicator.isCanceled()) {
if (displayWarningOnCreateHostCancelAction() == 1) {
return;
}
}
progressIndicator.setFraction(1);
progressIndicator.setIndeterminate(true);
} catch (Exception e) {
String msg = "An error occurred while attempting to create Docker host." + "\n" + e.getMessage();
LOGGER.error("Failed to Create Docker Host", e);
PluginUtil.displayErrorDialogInAWTAndLog("Failed to Create Docker Host", msg, e);
}
}
});
}
use of com.microsoft.azure.docker.model.DockerHost in project azure-tools-for-java by Microsoft.
the class AzureDockerHostDeployAction method onActionPerformed.
public void onActionPerformed(AnActionEvent actionEvent) {
try {
Project project = getCurrentProject();
if (!AzureSignInAction.doSignIn(AuthMethodManager.getInstance(), project))
return;
AzureDockerUIResources.CANCELED = false;
Module module = PluginUtil.getSelectedModule();
List<Module> modules = Arrays.asList(ModuleManager.getInstance(project).getModules());
if (module == null && modules.isEmpty()) {
Messages.showErrorDialog(message("noModule"), message("error"));
} else if (module == null) {
module = modules.iterator().next();
}
AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureAuthManager == null) {
System.out.println("ERROR! Not signed in!");
return;
}
AzureDockerHostsManager dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(azureAuthManager);
if (!dockerManager.isInitialized()) {
AzureDockerUIResources.updateAzureResourcesWithProgressDialog(project);
if (AzureDockerUIResources.CANCELED) {
return;
}
}
if (dockerManager.getSubscriptionsMap().isEmpty()) {
PluginUtil.displayErrorDialog("Publish Docker Container", "Please select a subscription first");
return;
}
DockerHost dockerHost = (dockerManager.getDockerPreferredSettings() != null) ? dockerManager.getDockerHostForURL(dockerManager.getDockerPreferredSettings().dockerApiName) : null;
AzureDockerImageInstance dockerImageDescription = dockerManager.getDefaultDockerImageDescription(project.getName(), dockerHost);
AzureSelectDockerWizardModel model = new AzureSelectDockerWizardModel(project, dockerManager, dockerImageDescription);
AzureSelectDockerWizardDialog wizard = new AzureSelectDockerWizardDialog(model);
if (dockerHost != null) {
model.selectDefaultDockerHost(dockerHost, true);
}
wizard.show();
if (wizard.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
try {
String url = wizard.deploy();
System.out.println("Web app published at: " + url);
} catch (Exception ex) {
PluginUtil.displayErrorDialogAndLog(message("webAppDplyErr"), ex.getMessage(), ex);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.microsoft.azure.docker.model.DockerHost in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerHostPage method refreshDockerHostsTable.
private void refreshDockerHostsTable(Composite mainContainer) {
dockerHostsList.clear();
for (DockerHost host : dockerManager.getDockerHostsList()) {
dockerHostsList.add(host);
}
dockerHostsTableViewer.refresh();
if (dockerHostsTableSelection != null) {
int idx = 0;
boolean selected = false;
for (DockerHost host : dockerHostsList) {
if (dockerHostsTableSelection.host.apiUrl.equals(host.apiUrl)) {
dockerHostsTableSelection.host = host;
dockerHostsTableSelection.row = idx;
selected = true;
break;
}
idx++;
}
if (selected) {
dockerHostsTable.getItem(idx).setChecked(true);
} else {
dockerHostsTableSelection = null;
}
}
}
Aggregations