Search in sources :

Example 1 with AzureDockerImageInstance

use of com.microsoft.azure.docker.model.AzureDockerImageInstance 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();
    }
}
Also used : AzureDockerImageInstance(com.microsoft.azure.docker.model.AzureDockerImageInstance) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) DockerHost(com.microsoft.azure.docker.model.DockerHost) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) AzureSelectDockerWizardDialog(com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardDialog) AzureSelectDockerWizardModel(com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardModel) AzureDockerHostsManager(com.microsoft.azure.docker.AzureDockerHostsManager)

Example 2 with AzureDockerImageInstance

use of com.microsoft.azure.docker.model.AzureDockerImageInstance 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();
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProjectImportBuilder.getCurrentProject(com.intellij.projectImport.ProjectImportBuilder.getCurrentProject) AzureDockerImageInstance(com.microsoft.azure.docker.model.AzureDockerImageInstance) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) DockerHost(com.microsoft.azure.docker.model.DockerHost) AzureSelectDockerWizardDialog(com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardDialog) AzureSelectDockerWizardModel(com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardModel) Module(com.intellij.openapi.module.Module) AzureDockerHostsManager(com.microsoft.azure.docker.AzureDockerHostsManager)

Example 3 with AzureDockerImageInstance

use of com.microsoft.azure.docker.model.AzureDockerImageInstance 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();
    }
}
Also used : AzureDockerImageInstance(com.microsoft.azure.docker.model.AzureDockerImageInstance) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) AzureSelectDockerWizard(com.microsoft.azuretools.docker.ui.wizards.publish.AzureSelectDockerWizard) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerHost(com.microsoft.azure.docker.model.DockerHost) AzureDockerHostsManager(com.microsoft.azure.docker.AzureDockerHostsManager) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog)

Example 4 with AzureDockerImageInstance

use of com.microsoft.azure.docker.model.AzureDockerImageInstance in project azure-tools-for-java by Microsoft.

the class AzureSelectDockerWizardDialog method deploy.

public String deploy() {
    AzureDockerImageInstance dockerImageInstance = model.getDockerImageDescription();
    AzureDockerPreferredSettings dockerPreferredSettings = model.getDockerHostsManager().getDockerPreferredSettings();
    if (dockerPreferredSettings == null) {
        dockerPreferredSettings = new AzureDockerPreferredSettings();
    }
    dockerPreferredSettings.dockerApiName = dockerImageInstance.host.apiUrl;
    dockerPreferredSettings.dockerfileOption = dockerImageInstance.predefinedDockerfile;
    dockerPreferredSettings.region = dockerImageInstance.host.hostVM.region;
    dockerPreferredSettings.vmSize = dockerImageInstance.host.hostVM.vmSize;
    dockerPreferredSettings.vmOS = dockerImageInstance.host.hostOSType.name();
    model.getDockerHostsManager().setDockerPreferredSettings(dockerPreferredSettings);
    DefaultLoader.getIdeHelper().runInBackground(model.getProject(), "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() {
                        AzureDockerImageInstance dockerImageInstance = model.getDockerImageDescription();
                        if (!dockerImageInstance.hasNewDockerHost) {
                            Session session = null;
                            do {
                                try {
                                    // check if the Docker host is accessible
                                    session = AzureDockerSSHOps.createLoginInstance(dockerImageInstance.host);
                                } catch (Exception e) {
                                    session = null;
                                }
                                if (session == null) {
                                    EditableDockerHost editableDockerHost = new EditableDockerHost(dockerImageInstance.host);
                                    AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(model.getProject(), editableDockerHost, model.getDockerHostsManager(), false);
                                    loginCredsDialog.show();
                                    if (loginCredsDialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
                                        // Update Docker host log in credentials
                                        DockerHost dockerHost = model.getDockerHostsManager().getDockerHostForURL(dockerImageInstance.host.apiUrl);
                                        dockerHost.certVault = editableDockerHost.updatedDockerHost.certVault;
                                        dockerHost.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
                                        dockerHost.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
                                        dockerImageInstance.host = dockerHost;
                                    //                    AzureDockerVMOps.updateDockerHostVM(model.getDockerHostsManager().getSubscriptionsMap().get(model.getDockerImageDescription().sid).azureClient, editableDockerHost.updatedDockerHost);
                                    } else {
                                        return;
                                    }
                                }
                            } while (session == null);
                        }
                        Azure azureClient = model.getDockerHostsManager().getSubscriptionsMap().get(model.getDockerImageDescription().sid).azureClient;
                        DockerContainerDeployTask task = new DockerContainerDeployTask(model.getProject(), azureClient, model.getDockerImageDescription());
                        task.queue();
                        // Update caches here
                        if (onCreate != null) {
                            onCreate.run();
                        }
                    }
                });
            } catch (Exception e) {
                String msg = "An error occurred while attempting to deploy to the selected Docker host." + "\n" + e.getMessage();
                PluginUtil.displayErrorDialogInAWTAndLog("Failed to Deploy Web App as Docker Container", msg, e);
            }
        }
    });
    return AzureDockerUtils.getUrl(dockerImageInstance);
}
Also used : AzureInputDockerLoginCredsDialog(com.microsoft.intellij.docker.dialogs.AzureInputDockerLoginCredsDialog) AzureDockerImageInstance(com.microsoft.azure.docker.model.AzureDockerImageInstance) Azure(com.microsoft.azure.management.Azure) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerHost(com.microsoft.azure.docker.model.DockerHost) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerContainerDeployTask(com.microsoft.tasks.DockerContainerDeployTask) AzureDockerPreferredSettings(com.microsoft.azure.docker.model.AzureDockerPreferredSettings) Session(com.jcraft.jsch.Session)

Example 5 with AzureDockerImageInstance

use of com.microsoft.azure.docker.model.AzureDockerImageInstance in project azure-tools-for-java by Microsoft.

the class DeployDockerContainerAction method actionPerformed.

@Override
public void actionPerformed(NodeActionEvent e) {
    try {
        if (!AzureSignInAction.doSignIn(AuthMethodManager.getInstance(), project))
            return;
        if (dockerManager.getSubscriptionsMap().isEmpty()) {
            PluginUtil.displayErrorDialog("Publish Docker Container", "Must select an Azure subscription first");
            return;
        }
        AzureDockerImageInstance dockerImageDescription = dockerManager.getDefaultDockerImageDescription(project.getName(), dockerHost);
        AzureSelectDockerWizardModel model = new AzureSelectDockerWizardModel(project, dockerManager, dockerImageDescription);
        AzureSelectDockerWizardDialog wizard = new AzureSelectDockerWizardDialog(model);
        model.selectDefaultDockerHost(dockerHost, false);
        wizard.show();
        if (wizard.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
            try {
                String url = wizard.deploy();
                System.out.println("Container published at: " + url);
            } catch (Exception ex) {
                PluginUtil.displayErrorDialogAndLog(message("webAppDplyErr"), ex.getMessage(), ex);
            }
        }
    } catch (Exception ex1) {
        LOGGER.error("actionPerformed", ex1);
        ex1.printStackTrace();
    }
}
Also used : AzureDockerImageInstance(com.microsoft.azure.docker.model.AzureDockerImageInstance) AzureSelectDockerWizardDialog(com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardDialog) AzureSelectDockerWizardModel(com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardModel)

Aggregations

AzureDockerImageInstance (com.microsoft.azure.docker.model.AzureDockerImageInstance)5 DockerHost (com.microsoft.azure.docker.model.DockerHost)4 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)3 EditableDockerHost (com.microsoft.azure.docker.model.EditableDockerHost)3 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)3 AzureSelectDockerWizardDialog (com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardDialog)3 AzureSelectDockerWizardModel (com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardModel)3 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 ProjectImportBuilder.getCurrentProject (com.intellij.projectImport.ProjectImportBuilder.getCurrentProject)1 Session (com.jcraft.jsch.Session)1 AzureDockerPreferredSettings (com.microsoft.azure.docker.model.AzureDockerPreferredSettings)1 Azure (com.microsoft.azure.management.Azure)1 AzureWizardDialog (com.microsoft.azuretools.core.components.AzureWizardDialog)1 AzureSelectDockerWizard (com.microsoft.azuretools.docker.ui.wizards.publish.AzureSelectDockerWizard)1 AzureInputDockerLoginCredsDialog (com.microsoft.intellij.docker.dialogs.AzureInputDockerLoginCredsDialog)1 DockerContainerDeployTask (com.microsoft.tasks.DockerContainerDeployTask)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1