Search in sources :

Example 6 with AzureUIRefreshEvent

use of com.microsoft.azuretools.utils.AzureUIRefreshEvent in project azure-tools-for-java by Microsoft.

the class FunctionDeploymentState method createFunctionApp.

private IFunctionApp createFunctionApp(@NotNull RunProcessHandler processHandler) {
    IFunctionApp functionApp = Azure.az(AzureAppService.class).subscription(functionDeployConfiguration.getSubscriptionId()).functionApp(functionDeployConfiguration.getConfig().getResourceGroup().getName(), functionDeployConfiguration.getAppName());
    if (functionApp.exists()) {
        return functionApp;
    }
    processHandler.setText(message("function.create.hint.creating", functionDeployConfiguration.getAppName()));
    // Load app settings from security storage
    final FunctionAppConfig config = deployModel.getFunctionAppConfig();
    config.setAppSettings(FunctionUtils.loadAppSettingsFromSecurityStorage(functionDeployConfiguration.getAppSettingsKey()));
    // create function app
    functionApp = FunctionAppService.getInstance().createFunctionApp(config);
    // update run configuration
    functionDeployConfiguration.setFunctionId(functionApp.id());
    // Notify explorer refresh
    AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, functionApp));
    processHandler.setText(message("function.create.hint.created", functionDeployConfiguration.getAppName()));
    return functionApp;
}
Also used : FunctionAppConfig(com.microsoft.azure.toolkit.lib.function.FunctionAppConfig) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent)

Example 7 with AzureUIRefreshEvent

use of com.microsoft.azuretools.utils.AzureUIRefreshEvent in project azure-tools-for-java by microsoft.

the class AppServiceCreateDialog method okPressed.

@Override
protected void okPressed() {
    String errTitle = ERROR_DIALOG_TITLE;
    cleanError();
    collectData();
    recordUserSettings();
    final Map<String, String> properties = model.getTelemetryProperties(new HashMap<String, String>());
    if (!validated()) {
        return;
    }
    try {
        ProgressDialog.get(this.getShell(), CREATE_APP_SERVICE_PROGRESS_TITLE).run(true, true, (monitor) -> {
            monitor.beginTask(VALIDATING_FORM_FIELDS, IProgressMonitor.UNKNOWN);
            monitor.setTaskName(CREATING_APP_SERVICE);
            if (monitor.isCanceled()) {
                Display.getDefault().asyncExec(() -> AppServiceCreateDialog.super.cancelPressed());
            }
            EventUtil.executeWithLog(WEBAPP, CREATE_WEBAPP, (operation) -> {
                EventUtil.logEvent(EventType.info, operation, properties);
                webApp = AzureWebAppMvpModel.getInstance().createWebAppFromSettingModel(model);
                if (!appSettings.isEmpty()) {
                    webApp.update().withAppSettings(appSettings).commit();
                }
                monitor.setTaskName(UPDATING_AZURE_LOCAL_CACHE);
                Display.getDefault().asyncExec(() -> AppServiceCreateDialog.super.okPressed());
                if (AzureUIRefreshCore.listeners != null) {
                    AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
                }
            }, (ex) -> {
                LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@okPressed@AppServiceCreateDialog", ex));
                Display.getDefault().asyncExec(() -> ErrorWindow.go(getShell(), ex.getMessage(), errTitle));
            });
        });
    } catch (Exception ex) {
        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "okPressed@AppServiceCreateDialog", ex));
        ErrorWindow.go(getShell(), ex.getMessage(), errTitle);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException)

Example 8 with AzureUIRefreshEvent

use of com.microsoft.azuretools.utils.AzureUIRefreshEvent in project azure-tools-for-java by microsoft.

the class WebAppRunState method onSuccess.

@Override
@AzureOperation(name = "webapp.complete_starting.state", type = AzureOperation.Type.ACTION)
protected void onSuccess(IAppService result, @NotNull RunProcessHandler processHandler) {
    if (webAppSettingModel.isCreatingNew() && AzureUIRefreshCore.listeners != null) {
        AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, result));
    }
    updateConfigurationDataModel(result);
    int indexOfDot = webAppSettingModel.getTargetName().lastIndexOf(".");
    final String fileName = webAppSettingModel.getTargetName().substring(0, indexOfDot);
    final String fileType = webAppSettingModel.getTargetName().substring(indexOfDot + 1);
    final String url = getUrl(result, fileName, fileType);
    processHandler.setText(message("appService.deploy.hint.succeed"));
    processHandler.setText("URL: " + url);
    if (webAppSettingModel.isOpenBrowserAfterDeployment()) {
        openWebAppInBrowser(url, processHandler);
    }
    processHandler.notifyComplete();
}
Also used : AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 9 with AzureUIRefreshEvent

use of com.microsoft.azuretools.utils.AzureUIRefreshEvent 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)

Example 10 with AzureUIRefreshEvent

use of com.microsoft.azuretools.utils.AzureUIRefreshEvent in project azure-tools-for-java by Microsoft.

the class AzureSelectDockerWizard method createDockerContainerDeployTask.

public void createDockerContainerDeployTask(IProject project, AzureDockerImageInstance dockerImageInstance, AzureDockerHostsManager dockerManager) {
    String url = AzureDockerUtils.getUrl(dockerImageInstance);
    String deploymentName = url;
    String jobDescription = String.format("Publishing %s as Docker Container", new File(dockerImageInstance.artifactPath).getName());
    AzureDeploymentProgressNotification.createAzureDeploymentProgressNotification(deploymentName, jobDescription);
    Map<String, String> postEventProperties = new HashMap<String, String>();
    postEventProperties.put("DockerFileOption", dockerImageInstance.predefinedDockerfile);
    Job createDockerHostJob = new Job(jobDescription) {

        @Override
        protected IStatus run(IProgressMonitor progressMonitor) {
            try {
                // Setup Azure Console and Azure Activity Log Window notifications
                MessageConsole console = com.microsoft.azuretools.core.Activator.findConsole(com.microsoft.azuretools.core.Activator.CONSOLE_NAME);
                console.activate();
                final MessageConsoleStream azureConsoleOut = console.newMessageStream();
                progressMonitor.beginTask("start task", 100);
                //		            com.microsoft.azuretools.core.Activator.removeUnNecessaryListener();
                DeploymentEventListener undeployListnr = new DeploymentEventListener() {

                    @Override
                    public void onDeploymentStep(DeploymentEventArgs args) {
                        progressMonitor.subTask(args.getDeployMessage());
                        progressMonitor.worked(args.getDeployCompleteness());
                        azureConsoleOut.println(String.format("%s: %s", deploymentName, args.getDeployMessage()));
                    }
                };
                com.microsoft.azuretools.core.Activator.getDefault().addDeploymentEventListener(undeployListnr);
                com.microsoft.azuretools.core.Activator.depEveList.add(undeployListnr);
                // Start the real job here
                String msg = String.format("Publishing %s to Docker host %s ...", new File(dockerImageInstance.artifactPath).getName(), dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 0, msg);
                msg = "Connecting to Azure...";
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 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.host.sid).azureClient;
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                if (dockerImageInstance.hasNewDockerHost) {
                    msg = String.format("Creating new virtual machine %s ...", dockerImageInstance.host.name);
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 20, msg);
                    AzureDockerUIResources.printDebugMessage(this, "Creating new virtual machine: " + new Date().toString());
                    AzureDockerVMOps.createDockerHostVM(azureClient, dockerImageInstance.host);
                    AzureDockerUIResources.printDebugMessage(this, "Done creating new virtual machine: " + new Date().toString());
                    if (progressMonitor.isCanceled()) {
                        displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                        return Status.CANCEL_STATUS;
                    }
                    msg = String.format("Updating Docker hosts ...");
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 5, msg);
                    AzureDockerUIResources.printDebugMessage(this, "Getting the new docker host details: " + new Date().toString());
                    //			            dockerManager.refreshDockerHostDetails();
                    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;
                        }
                    }
                    AzureDockerUIResources.printDebugMessage(this, "Done getting new Docker host details: " + new Date().toString());
                    msg = String.format("Waiting for virtual machine to be up %s ...", dockerImageInstance.host.name);
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 10, msg);
                    AzureDockerUIResources.printDebugMessage(this, "Waiting for virtual machine to be up: " + new Date().toString());
                    AzureDockerVMOps.waitForVirtualMachineStartup(azureClient, dockerImageInstance.host);
                    AzureDockerUIResources.printDebugMessage(this, "Done Waiting for virtual machine to be up: " + new Date().toString());
                    if (progressMonitor.isCanceled()) {
                        displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                        return Status.CANCEL_STATUS;
                    }
                    msg = String.format("Configuring Docker service for %s ...", dockerImageInstance.host.name);
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 10, msg);
                    AzureDockerUIResources.printDebugMessage(this, "Configuring Docker host: " + new Date().toString());
                    AzureDockerVMOps.installDocker(dockerImageInstance.host);
                    AzureDockerUIResources.printDebugMessage(this, "Done configuring Docker host: " + new Date().toString());
                    msg = String.format("Updating Docker hosts ...");
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 5, msg);
                    AzureDockerUIResources.printDebugMessage(this, "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));
                            }
                        }
                    }
                    AzureDockerUIResources.printDebugMessage(this, "Done refreshing Docker hosts: " + new Date().toString());
                    AzureDockerUIResources.printDebugMessage(this, "Finished setting up Docker host");
                } else {
                    msg = String.format("Using virtual machine %s ...", dockerImageInstance.host.name);
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 55, msg);
                }
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                if (dockerImageInstance.host.session == null) {
                    AzureDockerUIResources.printDebugMessage(this, "Opening a remote connection to the Docker host: " + new Date().toString());
                    dockerImageInstance.host.session = AzureDockerSSHOps.createLoginInstance(dockerImageInstance.host);
                    AzureDockerUIResources.printDebugMessage(this, "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(dockerImageInstance.host, dockerManager);
                    }
                }
                msg = String.format("Uploading Dockerfile and artifact %s on %s ...", dockerImageInstance.artifactName, dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 15, msg);
                AzureDockerUIResources.printDebugMessage(this, "Uploading Dockerfile and artifact: " + new Date().toString());
                AzureDockerVMOps.uploadDockerfileAndArtifact(dockerImageInstance, dockerImageInstance.host.session);
                AzureDockerUIResources.printDebugMessage(this, "Uploading Dockerfile and artifact: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                msg = String.format("Creating Docker image %s on %s ...", dockerImageInstance.dockerImageName, dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 15, msg);
                AzureDockerUIResources.printDebugMessage(this, "Creating a Docker image to the Docker host: " + new Date().toString());
                AzureDockerImageOps.create(dockerImageInstance, dockerImageInstance.host.session);
                AzureDockerUIResources.printDebugMessage(this, "Done creating a Docker image to the Docker host: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                msg = String.format("Creating Docker container %s for image %s on %s ...", dockerImageInstance.dockerContainerName, dockerImageInstance.dockerImageName, dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 5, msg);
                AzureDockerUIResources.printDebugMessage(this, "Creating a Docker container to the Docker host: " + new Date().toString());
                AzureDockerContainerOps.create(dockerImageInstance, dockerImageInstance.host.session);
                AzureDockerUIResources.printDebugMessage(this, "Done creating a Docker container to the Docker host: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                msg = String.format("Starting Docker container %s for image %s on %s ...", dockerImageInstance.dockerContainerName, dockerImageInstance.dockerImageName, dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 5, msg);
                AzureDockerUIResources.printDebugMessage(this, "Starting a Docker container to the Docker host: " + new Date().toString());
                AzureDockerContainerOps.start(dockerImageInstance, dockerImageInstance.host.session);
                AzureDockerUIResources.printDebugMessage(this, "Done starting a Docker container to the Docker host: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 100, "");
                try {
                    com.microsoft.azuretools.core.Activator.depEveList.remove(undeployListnr);
                    com.microsoft.azuretools.core.Activator.removeDeploymentEventListener(undeployListnr);
                } catch (Exception ignored) {
                }
                progressMonitor.done();
                AppInsightsClient.create("Deploy as DockerContainer", "", postEventProperties);
                return Status.OK_STATUS;
            } catch (Exception e) {
                String msg = "An error occurred while attempting to publish a Docker container!" + "\n" + e.getMessage();
                log.log(Level.SEVERE, "createDockerContainerDeployTask: " + msg, e);
                e.printStackTrace();
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, null, -1, "Error: " + e.getMessage());
                return Status.CANCEL_STATUS;
            }
        }
    };
    createDockerHostJob.schedule();
}
Also used : Azure(com.microsoft.azure.management.Azure) MessageConsole(org.eclipse.ui.console.MessageConsole) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) HashMap(java.util.HashMap) DeploymentEventArgs(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventArgs) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) Date(java.util.Date) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerHost(com.microsoft.azure.docker.model.DockerHost) DeploymentEventListener(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventListener) Job(org.eclipse.core.runtime.jobs.Job) AzureDockerHostsManager(com.microsoft.azure.docker.AzureDockerHostsManager) File(java.io.File) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Aggregations

AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)14 DockerHost (com.microsoft.azure.docker.model.DockerHost)4 Azure (com.microsoft.azure.management.Azure)4 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)4 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)4 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)4 PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)4 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)4 DockerClient (com.spotify.docker.client.DockerClient)4 FileNotFoundException (java.io.FileNotFoundException)4 Path (java.nio.file.Path)4 Date (java.util.Date)4 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)3 MalformedURLException (java.net.MalformedURLException)3 AzureDockerPreferredSettings (com.microsoft.azure.docker.model.AzureDockerPreferredSettings)2 DockerProgressHandler (com.microsoft.azure.toolkit.intellij.webapp.docker.utils.DockerProgressHandler)2 IFunctionApp (com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp)2 FunctionAppConfig (com.microsoft.azure.toolkit.lib.function.FunctionAppConfig)2 InvalidFormDataException (com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException)2 DockerProgressHandler (com.microsoft.azuretools.container.DockerProgressHandler)2