Search in sources :

Example 36 with PagedList

use of com.microsoft.azure.PagedList in project azure-tools-for-java by Microsoft.

the class AzureNewDockerConfigPage method updateDockerHostVMSizeComboBox.

private void updateDockerHostVMSizeComboBox(Composite mainContainer, boolean preferredSizesOnly) {
    dockerHostVMSizeComboBox.deselectAll();
    dockerHostVMSizeComboBox.removeAll();
    dockerHostVMSizeComboBox.redraw();
    if (preferredSizesOnly) {
        int index = 0;
        for (KnownDockerVirtualMachineSizes knownDockerVirtualMachineSize : KnownDockerVirtualMachineSizes.values()) {
            dockerHostVMSizeComboBox.add(knownDockerVirtualMachineSize.name());
            if (newHost.hostVM.vmSize.equals(knownDockerVirtualMachineSize.name())) {
                dockerHostVMSizeComboBox.select(index);
            }
            index++;
        }
        if (index == 0 || !newHost.hostVM.vmSize.equals((String) dockerHostVMSizeComboBox.getText())) {
            dockerHostVMSizeComboBox.add(newHost.hostVM.vmSize, 0);
            dockerHostVMSizeComboBox.select(0);
        }
        updateDockerSelectStorageComboBox(mainContainer, getCurrentSubscription());
    } else {
        dockerHostVMSizeComboBox.add("<Loading...>", 0);
        dockerHostVMSizeComboBox.select(0);
        dockerHostVMSizeComboBox.redraw();
        Azure azureClient = getCurrentSubscription().azureClient;
        DefaultLoader.getIdeHelper().runInBackground(null, "Loading VM sizes...", false, true, "", new Runnable() {

            @Override
            public void run() {
                PagedList<VirtualMachineSize> sizes = null;
                try {
                    sizes = azureClient.virtualMachines().sizes().listByRegion(preferredLocation);
                    Collections.sort(sizes, new Comparator<VirtualMachineSize>() {

                        @Override
                        public int compare(VirtualMachineSize size1, VirtualMachineSize size2) {
                            if (size1.name().contains("Basic") && size2.name().contains("Basic")) {
                                return size1.name().compareTo(size2.name());
                            } else if (size1.name().contains("Basic")) {
                                return -1;
                            } else if (size2.name().contains("Basic")) {
                                return 1;
                            }
                            int coreCompare = Integer.valueOf(size1.numberOfCores()).compareTo(size2.numberOfCores());
                            if (coreCompare == 0) {
                                return Integer.valueOf(size1.memoryInMB()).compareTo(size2.memoryInMB());
                            } else {
                                return coreCompare;
                            }
                        }
                    });
                } catch (Exception notHandled) {
                }
                PagedList<VirtualMachineSize> sortedSizes = sizes;
                DefaultLoader.getIdeHelper().invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        dockerHostVMSizeComboBox.deselectAll();
                        dockerHostVMSizeComboBox.removeAll();
                        if (sortedSizes != null) {
                            int index = 0;
                            for (VirtualMachineSize vmSize : sortedSizes) {
                                dockerHostVMSizeComboBox.add(vmSize.name());
                                if (vmSize.name().equals(newHost.hostVM.vmSize))
                                    dockerHostVMSizeComboBox.select(index);
                                index++;
                            }
                        }
                        if (sortedSizes.size() != 0 && !newHost.hostVM.vmSize.equals((String) dockerHostVMSizeComboBox.getText())) {
                            dockerHostVMSizeComboBox.add(newHost.hostVM.vmSize, 0);
                            dockerHostVMSizeComboBox.select(0);
                        }
                        updateDockerSelectStorageComboBox(mainContainer, getCurrentSubscription());
                        dockerHostVMSizeComboBox.redraw();
                    }
                });
            }
        });
    }
}
Also used : KnownDockerVirtualMachineSizes(com.microsoft.azure.docker.model.KnownDockerVirtualMachineSizes) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) Azure(com.microsoft.azure.management.Azure) PagedList(com.microsoft.azure.PagedList) Comparator(java.util.Comparator)

Aggregations

PagedList (com.microsoft.azure.PagedList)36 PageImpl (com.microsoft.azure.batch.protocol.models.PageImpl)26 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)26 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)26 ResponseBody (okhttp3.ResponseBody)26 DateTime (org.joda.time.DateTime)26 CloudJob (com.microsoft.azure.batch.protocol.models.CloudJob)4 NodeFile (com.microsoft.azure.batch.protocol.models.NodeFile)4 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)4 AccountListNodeAgentSkusHeaders (com.microsoft.azure.batch.protocol.models.AccountListNodeAgentSkusHeaders)3 ApplicationListHeaders (com.microsoft.azure.batch.protocol.models.ApplicationListHeaders)3 CertificateListHeaders (com.microsoft.azure.batch.protocol.models.CertificateListHeaders)3 FileListFromComputeNodeHeaders (com.microsoft.azure.batch.protocol.models.FileListFromComputeNodeHeaders)3 FileListFromTaskHeaders (com.microsoft.azure.batch.protocol.models.FileListFromTaskHeaders)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 AccountListNodeAgentSkusOptions (com.microsoft.azure.batch.protocol.models.AccountListNodeAgentSkusOptions)2 ApplicationListOptions (com.microsoft.azure.batch.protocol.models.ApplicationListOptions)2 ApplicationSummary (com.microsoft.azure.batch.protocol.models.ApplicationSummary)2 Certificate (com.microsoft.azure.batch.protocol.models.Certificate)2