use of com.microsoft.azure.docker.AzureDockerHostsManager in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method deleteDockerHost.
public static void deleteDockerHost(Project project, Azure azureClient, DockerHost dockerHost, int option, Runnable runnable) {
String progressMsg = (option == 2) ? String.format("Deleting Virtual Machine %s and Its Resources...", dockerHost.name) : String.format("Deleting Docker Host %s...", dockerHost.name);
DefaultLoader.getIdeHelper().runInBackground(project, "Deleting Docker Host", false, true, progressMsg, new Runnable() {
@Override
public void run() {
try {
if (option == 2) {
AzureDockerVMOps.deleteDockerHostAll(azureClient, dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
} else {
AzureDockerVMOps.deleteDockerHost(azureClient, dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
}
DefaultLoader.getIdeHelper().runInBackground(project, "Updating Docker Hosts Details ", false, true, "Updating Docker hosts details...", new Runnable() {
@Override
public void run() {
try {
AzureDockerHostsManager dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(null);
dockerManager.refreshDockerHostDetails();
if (runnable != null) {
runnable.run();
}
} catch (Exception ee) {
if (AzureDockerUtils.DEBUG)
ee.printStackTrace();
LOGGER.error("onRemoveDockerHostAction", ee);
}
}
});
} catch (Exception e) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (AzureDockerUtils.DEBUG)
e.printStackTrace();
LOGGER.error("onRemoveDockerHostAction", e);
PluginUtil.displayErrorDialog("Delete Docker Host Error", String.format("Unexpected error detected while deleting Docker host %s:\n\n%s", dockerHost.name, e.getMessage()));
}
});
}
}
});
}
use of com.microsoft.azure.docker.AzureDockerHostsManager 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.AzureDockerHostsManager 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.AzureDockerHostsManager 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.AzureDockerHostsManager 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();
}
}
Aggregations