Search in sources :

Example 21 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class SubscriptionsDialog method refreshSubscriptions.

private void refreshSubscriptions() {
    try {
        AzureManager manager = AuthMethodManager.getInstance().getAzureManager();
        if (manager == null) {
            return;
        }
        final SubscriptionManager subscriptionManager = manager.getSubscriptionManager();
        subscriptionManager.cleanSubscriptions();
        DefaultTableModel dm = (DefaultTableModel) table.getModel();
        dm.getDataVector().removeAllElements();
        dm.fireTableDataChanged();
        SelectSubscriptionsAction.updateSubscriptionWithProgressDialog(subscriptionManager, project);
        //System.out.println("refreshSubscriptions: calling getSubscriptionDetails()");
        sdl = subscriptionManager.getSubscriptionDetails();
        setSubscriptions();
        // to notify subscribers
        subscriptionManager.setSubscriptionDetails(sdl);
    } catch (Exception ex) {
        ex.printStackTrace();
        //LOGGER.error("refreshSubscriptions", ex);
        ErrorWindow.show(project, ex.getMessage(), "Refresh Subscriptions Error");
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) DefaultTableModel(javax.swing.table.DefaultTableModel) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager)

Example 22 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class SelectSubsriptionsCommandHandler method onSelectSubscriptions.

public static void onSelectSubscriptions(Shell parentShell) {
    try {
        AzureManager manager = AuthMethodManager.getInstance().getAzureManager();
        if (manager == null) {
            return;
        }
        SubscriptionManager sm = manager.getSubscriptionManager();
        SubscriptionsDialog.go(parentShell, sm);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 23 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager 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 24 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager 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 25 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class AzureDeploymentProgressNotification method deployToDockerContainer.

public void deployToDockerContainer(AzureDockerImageInstance dockerImageInstance, String url) {
    Date startDate = new Date();
    Map<String, String> postEventProperties = new HashMap<String, String>();
    postEventProperties.put("DockerFileOption", dockerImageInstance.predefinedDockerfile);
    String descriptionTask = String.format("Publishing %s into Docker host %s at port(s) %s", new File(dockerImageInstance.artifactPath).getName(), dockerImageInstance.host.name, dockerImageInstance.dockerPortSettings);
    try {
        String msg = String.format("Publishing %s to Docker host %s ...", new File(dockerImageInstance.artifactPath).getName(), dockerImageInstance.host.name);
        notifyProgress(descriptionTask, startDate, null, 5, msg);
        AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureAuthManager == null) {
            throw new RuntimeException("User not signed in");
        }
        AzureDockerHostsManager dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(azureAuthManager);
        Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerImageInstance.sid).azureClient;
        KeyVaultClient keyVaultClient = dockerManager.getSubscriptionsMap().get(dockerImageInstance.sid).keyVaultClient;
        if (dockerImageInstance.hasNewDockerHost) {
            msg = String.format("Creating new virtual machine %s ...", dockerImageInstance.host.name);
            notifyProgress(descriptionTask, startDate, null, 10, msg);
            if (AzureDockerUtils.DEBUG)
                System.out.println("Creating new virtual machine: " + new Date().toString());
            AzureDockerVMOps.createDockerHostVM(azureClient, dockerImageInstance.host);
            if (AzureDockerUtils.DEBUG)
                System.out.println("Done creating new virtual machine: " + new Date().toString());
            msg = String.format("Get new VM details...");
            notifyProgress(descriptionTask, startDate, null, 30, msg);
            if (AzureDockerUtils.DEBUG)
                System.out.println("Getting the new Docker host details: " + new Date().toString());
            VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerImageInstance.host.hostVM.resourceGroupName, dockerImageInstance.host.hostVM.name);
            if (vm != null) {
                DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
                if (updatedHost != null) {
                    dockerImageInstance.host.hostVM = updatedHost.hostVM;
                    dockerImageInstance.host.apiUrl = updatedHost.apiUrl;
                }
            }
            if (AzureDockerUtils.DEBUG)
                System.out.println("Done getting the new Docker host details: " + new Date().toString());
            msg = String.format("Waiting for virtual machine to be up %s ...", dockerImageInstance.host.name);
            notifyProgress(descriptionTask, startDate, null, 35, msg);
            if (AzureDockerUtils.DEBUG)
                System.out.println("Waiting for virtual machine to be up: " + new Date().toString());
            AzureDockerVMOps.waitForVirtualMachineStartup(azureClient, dockerImageInstance.host);
            if (AzureDockerUtils.DEBUG)
                System.out.println("Done Waiting for virtual machine to be up: " + new Date().toString());
            msg = String.format("Configuring Docker service for %s ...", dockerImageInstance.host.name);
            notifyProgress(descriptionTask, startDate, null, 45, msg);
            if (AzureDockerUtils.DEBUG)
                System.out.println("Configuring Docker host: " + new Date().toString());
            AzureDockerVMOps.installDocker(dockerImageInstance.host);
            if (AzureDockerUtils.DEBUG)
                System.out.println("Done configuring Docker host: " + new Date().toString());
            msg = String.format("Updating Docker hosts ...");
            notifyProgress(descriptionTask, startDate, null, 50, msg);
            if (AzureDockerUtils.DEBUG)
                System.out.println("Refreshing docker hosts: " + new Date().toString());
            //            dockerManager.refreshDockerHostDetails();
            vm = azureClient.virtualMachines().getByResourceGroup(dockerImageInstance.host.hostVM.resourceGroupName, dockerImageInstance.host.hostVM.name);
            if (vm != null) {
                DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
                if (updatedHost != null) {
                    updatedHost.sid = dockerImageInstance.host.sid;
                    updatedHost.hostVM.sid = dockerImageInstance.host.hostVM.sid;
                    if (updatedHost.certVault == null) {
                        updatedHost.certVault = dockerImageInstance.host.certVault;
                        updatedHost.hasPwdLogIn = dockerImageInstance.host.hasPwdLogIn;
                        updatedHost.hasSSHLogIn = dockerImageInstance.host.hasSSHLogIn;
                        updatedHost.isTLSSecured = dockerImageInstance.host.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: " + new Date().toString());
            if (AzureDockerUtils.DEBUG)
                System.out.println("Finished setting up Docker host");
        } else {
            msg = String.format("Using virtual machine %s ...", dockerImageInstance.host.name);
            notifyProgress(descriptionTask, startDate, null, 50, msg);
        }
        if (dockerImageInstance.host.session == null) {
            if (AzureDockerUtils.DEBUG)
                System.out.println("Opening a remote connection to the Docker host: " + new Date().toString());
            dockerImageInstance.host.session = AzureDockerSSHOps.createLoginInstance(dockerImageInstance.host);
            if (AzureDockerUtils.DEBUG)
                System.out.println("Done opening a remote connection to the Docker host: " + new Date().toString());
        }
        if (dockerImageInstance.hasNewDockerHost) {
            if (dockerImageInstance.host.certVault != null && dockerImageInstance.host.certVault.hostName != null) {
                AzureDockerUIResources.createDockerKeyVault(null, dockerImageInstance.host, dockerManager);
            }
        }
        msg = String.format("Uploading Dockerfile and artifact %s on %s ...", dockerImageInstance.artifactName, dockerImageInstance.host.name);
        notifyProgress(descriptionTask, startDate, null, 60, msg);
        if (AzureDockerUtils.DEBUG)
            System.out.println("Uploading Dockerfile and artifact: " + new Date().toString());
        AzureDockerVMOps.uploadDockerfileAndArtifact(dockerImageInstance, dockerImageInstance.host.session);
        if (AzureDockerUtils.DEBUG)
            System.out.println("Uploading Dockerfile and artifact: " + new Date().toString());
        msg = String.format("Creating Docker image %s on %s ...", dockerImageInstance.dockerImageName, dockerImageInstance.host.name);
        notifyProgress(descriptionTask, startDate, null, 80, msg);
        if (AzureDockerUtils.DEBUG)
            System.out.println("Creating a Docker image to the Docker host: " + new Date().toString());
        AzureDockerImageOps.create(dockerImageInstance, dockerImageInstance.host.session);
        if (AzureDockerUtils.DEBUG)
            System.out.println("Done creating a Docker image to the Docker host: " + new Date().toString());
        msg = String.format("Creating Docker container %s for image %s on %s ...", dockerImageInstance.dockerContainerName, dockerImageInstance.dockerImageName, dockerImageInstance.host.name);
        notifyProgress(descriptionTask, startDate, null, 90, msg);
        if (AzureDockerUtils.DEBUG)
            System.out.println("Creating a Docker container to the Docker host: " + new Date().toString());
        AzureDockerContainerOps.create(dockerImageInstance, dockerImageInstance.host.session);
        if (AzureDockerUtils.DEBUG)
            System.out.println("Done creating a Docker container to the Docker host: " + new Date().toString());
        msg = String.format("Starting Docker container %s for image %s on %s ...", dockerImageInstance.dockerContainerName, dockerImageInstance.dockerImageName, dockerImageInstance.host.name);
        notifyProgress(descriptionTask, startDate, null, 95, msg);
        if (AzureDockerUtils.DEBUG)
            System.out.println("Starting a Docker container to the Docker host: " + new Date().toString());
        AzureDockerContainerOps.start(dockerImageInstance, dockerImageInstance.host.session);
        if (AzureDockerUtils.DEBUG)
            System.out.println("Done starting a Docker container to the Docker host: " + new Date().toString());
        notifyProgress(descriptionTask, startDate, url, 100, message("runStatus"), dockerImageInstance.host.name);
    } catch (InterruptedException e) {
        postEventProperties.put("PublishInterruptedError", e.getMessage());
        notifyProgress(descriptionTask, startDate, url, 100, message("runStatus"), dockerImageInstance.host.name);
    } catch (Exception ee) {
        postEventProperties.put("PublishError", ee.getMessage());
        notifyProgress(descriptionTask, startDate, url, 100, "Error: %s", ee.getMessage());
    }
    AppInsightsClient.createByType(AppInsightsClient.EventType.DockerContainer, null, "Deploy", postEventProperties);
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) HashMap(java.util.HashMap) KeyVaultClient(com.microsoft.azure.keyvault.KeyVaultClient) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) Date(java.util.Date) MalformedURLException(java.net.MalformedURLException) DockerHost(com.microsoft.azure.docker.model.DockerHost) AzureDockerHostsManager(com.microsoft.azure.docker.AzureDockerHostsManager) File(java.io.File) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Aggregations

AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)48 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)17 Azure (com.microsoft.azure.management.Azure)15 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)15 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)12 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)8 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)8 DockerHost (com.microsoft.azure.docker.model.DockerHost)6 Location (com.microsoft.azure.management.resources.Location)4 AzureDockerImageInstance (com.microsoft.azure.docker.model.AzureDockerImageInstance)3 EditableDockerHost (com.microsoft.azure.docker.model.EditableDockerHost)3 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)3 Subscription (com.microsoft.azure.management.resources.Subscription)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)3 KeyVaultClient (com.microsoft.azure.keyvault.KeyVaultClient)2 Network (com.microsoft.azure.management.network.Network)2 Kind (com.microsoft.azure.management.storage.Kind)2