use of com.azure.resourcemanager.resources.models.ProviderResourceType in project azure-maven-plugins by microsoft.
the class AzureService method listSupportedRegions.
default List<Region> listSupportedRegions(String subscriptionId) {
String[] names = StringUtils.split(name(), "/");
if (names.length != 2) {
throw new AzureToolkitRuntimeException(String.format("It is illegal to list regions for service '%s'.", name()));
}
final String provider = names[0];
final String resourceType = names[1];
List<Region> allRegionList = az(IAzureAccount.class).listRegions(subscriptionId);
List<Region> result = new ArrayList<>();
final ResourceManager resourceManager = getResourceManager(subscriptionId);
resourceManager.providers().getByName(provider).resourceTypes().stream().filter(type -> StringUtils.equalsIgnoreCase(type.resourceType(), resourceType)).findAny().map(ProviderResourceType::locations).ifPresent(list -> result.addAll(list.stream().map(Region::fromName).filter(allRegionList::contains).collect(Collectors.toList())));
return result.isEmpty() ? allRegionList : result;
}
use of com.azure.resourcemanager.resources.models.ProviderResourceType 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;
}
}
}
}
Aggregations