Search in sources :

Example 1 with Provider

use of com.azure.resourcemanager.resources.models.Provider in project azure-vm-agents-plugin by jenkinsci.

the class LocationCache method getLocation.

public static Set<String> getLocation(AzureResourceManager azureClient, String key) throws Exception {
    if (regions.containsKey(key) && !regions.get(key).isEmpty() && System.currentTimeMillis() < achieveTimeInMillis.get(key) + EXPIRE_TIME_IN_MILLIS) {
        return regions.get(key);
    } else {
        synchronized (LocationCache.class) {
            if (regions.containsKey(key) && !regions.get(key).isEmpty() && System.currentTimeMillis() < achieveTimeInMillis.get(key) + EXPIRE_TIME_IN_MILLIS) {
                return regions.get(key);
            } else {
                Provider byName = azureClient.providers().getByName("Microsoft.Compute");
                ProviderResourceType resourceType = byName.resourceTypes().stream().filter(type -> type.resourceType().equalsIgnoreCase("virtualMachines")).findFirst().orElse(null);
                if (resourceType == null) {
                    throw new RuntimeException("Virtual machines provider not registered");
                }
                Set<String> locations = new HashSet<>(resourceType.locations());
                achieveTimeInMillis.put(key, System.currentTimeMillis());
                regions.put(key, locations);
                return locations;
            }
        }
    }
}
Also used : ProviderResourceType(com.azure.resourcemanager.resources.models.ProviderResourceType) Provider(com.azure.resourcemanager.resources.models.Provider) HashSet(java.util.HashSet)

Aggregations

Provider (com.azure.resourcemanager.resources.models.Provider)1 ProviderResourceType (com.azure.resourcemanager.resources.models.ProviderResourceType)1 HashSet (java.util.HashSet)1