use of org.springframework.cache.annotation.Cacheable in project cloudbreak by hortonworks.
the class GcpPlatformResources method regions.
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
String defaultRegion = gcpZoneParameterDefault;
RegionList regionList = compute.regions().list(projectId).execute();
for (com.google.api.services.compute.model.Region gcpRegion : regionList.getItems()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || gcpRegion.getName().equals(region.value())) {
List<AvailabilityZone> availabilityZones = new ArrayList<>();
for (String s : gcpRegion.getZones()) {
String[] split = s.split("/");
if (split.length > 0) {
availabilityZones.add(AvailabilityZone.availabilityZone(split[split.length - 1]));
}
}
regionListMap.put(region(gcpRegion.getName()), availabilityZones);
displayNames.put(region(gcpRegion.getName()), displayName(gcpRegion.getName()));
}
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(regionListMap, displayNames, defaultRegion);
}
use of org.springframework.cache.annotation.Cacheable in project cloudbreak by hortonworks.
the class CachedImageCatalogProvider method getImageCatalogV2.
@Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl")
public CloudbreakImageCatalogV2 getImageCatalogV2(String catalogUrl) throws CloudbreakImageCatalogException {
CloudbreakImageCatalogV2 catalog = null;
if (catalogUrl == null) {
LOGGER.warn("No image catalog was defined!");
return catalog;
}
try {
long started = System.currentTimeMillis();
if (catalogUrl.startsWith("http")) {
Client client = RestClientUtil.get();
WebTarget target = client.target(catalogUrl);
Response response = target.request().get();
catalog = checkResponse(target, response);
} else {
String content = readCatalogFromFile(catalogUrl);
catalog = JsonUtil.readValue(content, CloudbreakImageCatalogV2.class);
}
validateImageCatalogUuids(catalog);
validateCloudBreakVersions(catalog);
cleanAndValidateMaps(catalog);
long timeOfParse = System.currentTimeMillis() - started;
LOGGER.info("ImageCatalog has been get and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse);
} catch (RuntimeException e) {
throw new CloudbreakImageCatalogException("Failed to get image catalog", e);
} catch (JsonMappingException e) {
throw new CloudbreakImageCatalogException(e.getMessage(), e);
} catch (IOException e) {
throw new CloudbreakImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl), e);
}
return catalog;
}
use of org.springframework.cache.annotation.Cacheable in project cloudbreak by hortonworks.
the class AzurePlatformResources method regions.
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AzureClient client = azureClientService.getClient(cloudCredential);
Map<Region, List<AvailabilityZone>> cloudRegions = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
String defaultRegion = armZoneParameterDefault;
for (com.microsoft.azure.management.resources.fluentcore.arm.Region azureRegion : client.getRegion(region)) {
cloudRegions.put(region(azureRegion.label()), new ArrayList<>());
displayNames.put(region(azureRegion.label()), azureRegion.label());
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(cloudRegions, displayNames, defaultRegion);
}
use of org.springframework.cache.annotation.Cacheable in project pinpoint by naver.
the class HbaseApiMetaDataDao method getApiMetaData.
@Override
@Cacheable(cacheNames = "apiMetaData", key = SPEL_KEY, cacheManager = CacheConfiguration.API_METADATA_CACHE_NAME)
public List<ApiMetaDataBo> getApiMetaData(String agentId, long time, int apiId) {
Objects.requireNonNull(agentId, "agentId");
MetaDataRowKey metaDataRowKey = new DefaultMetaDataRowKey(agentId, time, apiId);
byte[] sqlId = getDistributedKey(rowKeyEncoder.encodeRowKey(metaDataRowKey));
Get get = new Get(sqlId);
get.addFamily(DESCRIPTOR.getName());
TableName apiMetaDataTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable());
return hbaseOperations2.get(apiMetaDataTableName, get, apiMetaDataMapper);
}
Aggregations