Search in sources :

Example 91 with Cacheable

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Compute(com.google.api.services.compute.Compute) Region(com.sequenceiq.cloudbreak.cloud.model.Region) ArrayList(java.util.ArrayList) NetworkList(com.google.api.services.compute.model.NetworkList) RegionList(com.google.api.services.compute.model.RegionList) List(java.util.List) MachineTypeList(com.google.api.services.compute.model.MachineTypeList) FirewallList(com.google.api.services.compute.model.FirewallList) RegionList(com.google.api.services.compute.model.RegionList) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 92 with Cacheable

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;
}
Also used : Response(javax.ws.rs.core.Response) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) WebTarget(javax.ws.rs.client.WebTarget) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 93 with Cacheable

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);
}
Also used : HashMap(java.util.HashMap) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Region(com.sequenceiq.cloudbreak.cloud.model.Region) ArrayList(java.util.ArrayList) List(java.util.List) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 94 with Cacheable

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) DefaultMetaDataRowKey(com.navercorp.pinpoint.common.server.bo.serializer.metadata.DefaultMetaDataRowKey) DefaultMetaDataRowKey(com.navercorp.pinpoint.common.server.bo.serializer.metadata.DefaultMetaDataRowKey) MetaDataRowKey(com.navercorp.pinpoint.common.server.bo.serializer.metadata.MetaDataRowKey) Get(org.apache.hadoop.hbase.client.Get) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

Cacheable (org.springframework.cache.annotation.Cacheable)94 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 Query (javax.persistence.Query)11 HashSet (java.util.HashSet)10 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)7 LinkedHashMap (java.util.LinkedHashMap)6 NextProtException (org.nextprot.api.commons.exception.NextProtException)6 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)5 IOException (java.io.IOException)5 List (java.util.List)5 Set (java.util.Set)5 TypedQuery (javax.persistence.TypedQuery)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Workbook (org.apache.poi.ss.usermodel.Workbook)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Region (com.sequenceiq.cloudbreak.cloud.model.Region)3 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 Application (ai.elimu.model.admin.Application)2