Search in sources :

Example 1 with KnownDockerVirtualMachineSizes

use of com.microsoft.azure.docker.model.KnownDockerVirtualMachineSizes 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)1 KnownDockerVirtualMachineSizes (com.microsoft.azure.docker.model.KnownDockerVirtualMachineSizes)1 Azure (com.microsoft.azure.management.Azure)1 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)1 Comparator (java.util.Comparator)1