@Override public Location get() { Set<? extends Location> locations = locationsSupplier.get(); try { return find(locations, isZone()); } catch (NoSuchElementException e) { throw new NoSuchElementException("none to of the locations are scope ZONE: " + transform(locations, ToIdAndScope.INSTANCE)); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Set<? extends Image> get() { if (amiOwners.length == 0) { logger.debug(">> no owners specified, skipping image parsing"); return ImmutableSet.of(); } else { logger.debug(">> providing images"); Iterable<Entry<String, DescribeImagesOptions>> queries = getDescribeQueriesForOwnersInRegions(regions.get(), amiOwners); Iterable<? extends Image> parsedImages = ImmutableSet.copyOf(filter(transform(describer.apply(queries), parser), Predicates .notNull())); Map<RegionAndName, ? extends Image> imageMap = ImagesToRegionAndIdMap.imagesToMap(parsedImages); cache.get().invalidateAll(); cache.get().asMap().putAll((Map)imageMap); logger.debug("<< images(%d)", imageMap.size()); return Sets.newLinkedHashSet(imageMap.values()); } }
@Override public Location get() { Set<? extends Location> locations = locationsSupplier.get(); try { return find(locations, isRegion()); } catch (NoSuchElementException e) { throw new NoSuchElementException("none to of the locations are scope REGION: " + transform(locations, ToIdAndScope.INSTANCE)); } }
@Override public Map<String, Supplier<URI>> get() { FluentIterable<Service> services = FluentIterable.from(access.get()).filter(apiTypeEquals); if (services.toSet().size() == 0) throw new NoSuchElementException(String.format("apiType %s not found in catalog %s", apiType, services)); Iterable<Endpoint> endpoints = concat(services); if (size(endpoints) == 0) throw new NoSuchElementException( String.format("no endpoints for apiType %s in services %s", apiType, services)); boolean checkVersionId = any(endpoints, versionAware); Multimap<String, Endpoint> locationToEndpoints = index(endpoints, endpointToLocationId); Map<String, Endpoint> locationToEndpoint; if (checkVersionId && apiVersion != null) { locationToEndpoint = refineToVersionSpecificEndpoint(locationToEndpoints); if (locationToEndpoint.size() == 0) throw new NoSuchElementException(String.format( "no endpoints for apiType %s are of version %s, or version agnostic: %s", apiType, apiVersion, locationToEndpoints)); } else { locationToEndpoint = firstEndpointInLocation(locationToEndpoints); } logger.debug("endpoints for apiType %s and version %s: %s", apiType, apiVersion, locationToEndpoints); return Maps.transformValues(locationToEndpoint, endpointToSupplierURI); }
@Override public Location get() { Set<? extends Location> locations = locationsSupplier.get(); try { return find(locations, isNetwork()); } catch (NoSuchElementException e) { throw new NoSuchElementException( "none of the locations are scope NETWORK: " + transform(locations, ToIdAndScope.INSTANCE)); } }
@Override public Set<? extends NodeMetadata> listNodesByIds(Iterable<String> ids) { Multimap<String, String> idsByHandles = index(ids, splitHandle(1)); Multimap<String, String> idsByRegions = transformValues(idsByHandles, splitHandle(0)); Multimap<String, String> idsByConfiguredRegions = filterKeys(idsByRegions, in(regions.get())); if (idsByConfiguredRegions.isEmpty()) { return ImmutableSet.of(); } Iterable<? extends RunningInstance> instances = pollRunningInstancesByRegionsAndIds(idsByConfiguredRegions); Iterable<? extends NodeMetadata> nodes = transform(filter(instances, notNull()), runningInstanceToNodeMetadata); return ImmutableSet.copyOf(nodes); }
@Override public Set<? extends Location> get() { return ImmutableSet.of(new LocationBuilder().scope(LocationScope.PROVIDER).id(providerName) .description(endpointSupplier.get().toASCIIString()).iso3166Codes(isoCodesSupplier).build()); }
@Override public Set<? extends Location> get() { Location provider = Iterables.getOnlyElement(justProvider.get()); Set<String> zoneIds = zoneIdsSupplier.get(); checkState(zoneIds.size() > 0, "no zones found for provider %s, using supplier %s", provider, zoneIdsSupplier); Map<String, Supplier<Set<String>>> isoCodesById = isoCodesByIdSupplier.get(); Builder<Location> locations = ImmutableSet.builder(); for (String zoneId : zoneIds) { LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(zoneId).description(zoneId) .parent(provider); if (isoCodesById.containsKey(zoneId)) builder.iso3166Codes(isoCodesById.get(zoneId).get()); locations.add(builder.build()); } return locations.build(); }
public Location apply(String bucket) { Set<? extends Location> locations = this.locations.get(); if (locations.size() == 1) return get(locations, 0); final Optional<String> region = bucketToRegion.apply(bucket); if (region.isPresent()) { try { return find(locations, idEquals(region.get())); } catch (NoSuchElementException e) { logger.debug("could not get location for region %s in %s", region, locations); } } else { logger.debug("could not get region for %s", bucket); } return null; } }
@Singleton @Zone @Override public Map<String, Supplier<Set<String>>> get() { Set<String> regions = regionsSupplier.get(); if (regions.size() == 0) { logger.debug("no regions configured for provider %s", provider); return ImmutableMap.of(); } Builder<String, Supplier<Set<String>>> regionToZones = ImmutableMap.builder(); for (String region : regions) { String configKey = PROPERTY_REGION + "." + region + ".zones"; String zones = config.apply(configKey); if (zones == null) logger.debug("config key %s not present", configKey); else regionToZones.put(region, Suppliers.<Set<String>> ofInstance(ImmutableSet.copyOf(Splitter.on(',').split( zones)))); } return regionToZones.build(); } }
/** * returns {@link Endpoint#isV1Default()} or first endpoint for service */ @Override public String get() { Auth authResponse = auth.get(); Iterable<Endpoint> endpointsForService = authResponse.getServiceCatalog().get(apiType); Optional<Endpoint> defaultEndpoint = tryFind(endpointsForService, new Predicate<Endpoint>() { @Override public boolean apply(Endpoint in) { return in.isV1Default(); } }); return endpointToRegion.apply(defaultEndpoint.or(Iterables.get(endpointsForService, 0))); }
private HttpRequest signForTemporaryAccess(HttpRequest request, long timeInSeconds) { Credentials currentCreds = checkNotNull(creds.get(), "credential supplier returned null"); // accessKey is of the form tenantName:accessKeyId (not tenantId) String accessKeyId = currentCreds.identity.substring(currentCreds.identity.indexOf(':') + 1); String secretKey = currentCreds.credential; String tenantId = access.get().getToken().getTenant().get().getId(); HttpRequest.Builder<?> builder = request.toBuilder(); // HP Cloud does not use X-Auth-Token for temporary signed URLs and // leaking this allows clients arbitrary privileges until token timeout. builder.filters(filter(request.getFilters(), not(instanceOf(AuthenticateRequest.class)))); long expiresInSeconds = unixEpochTimestampProvider.get() + timeInSeconds; String signature = createSignature(secretKey, createStringToSign(request.getMethod().toUpperCase(), request, expiresInSeconds)); builder.addQueryParam("temp_url_sig", String.format("%s:%s:%s", tenantId, accessKeyId, signature)); builder.addQueryParam("temp_url_expires", "" + expiresInSeconds); return builder.build(); }
private void scrubCells(TransactionManager txManager, Multimap<TableReference, Cell> tableNameToCells, long scrubTimestamp, Transaction.TransactionType transactionType) { Map<TableReference, Multimap<Cell, Long>> allCellsToMarkScrubbed = Maps.newHashMapWithExpectedSize(tableNameToCells.keySet().size()); for (Entry<TableReference, Collection<Cell>> entry : tableNameToCells.asMap().entrySet()) { TableReference tableRef = entry.getKey(); log.debug("Attempting to immediately scrub {} cells from table {}", entry.getValue().size(), tableRef); for (List<Cell> cells : Iterables.partition(entry.getValue(), batchSizeSupplier.get())) { Multimap<Cell, Long> allTimestamps = keyValueService.getAllTimestamps( tableRef, ImmutableSet.copyOf(cells), scrubTimestamp); Multimap<Cell, Long> timestampsToDelete = Multimaps.filterValues( allTimestamps, v -> !v.equals(Value.INVALID_VALUE_TIMESTAMP)); // If transactionType == TransactionType.AGGRESSIVE_HARD_DELETE this might // force other transactions to abort or retry deleteCellsAtTimestamps(txManager, tableRef, timestampsToDelete, transactionType); Multimap<Cell, Long> cellsToMarkScrubbed = HashMultimap.create(allTimestamps); for (Cell cell : cells) { cellsToMarkScrubbed.put(cell, scrubTimestamp); } allCellsToMarkScrubbed.put(tableRef, cellsToMarkScrubbed); } log.debug("Immediately scrubbed {} cells from table {}", entry.getValue().size(), tableRef); } scrubberStore.markCellsAsScrubbed(allCellsToMarkScrubbed, batchSizeSupplier.get()); }
/** * Terremark does not provide vApp templates in the vDC resourceEntity list. Rather, you must * query the catalog. */ @Override public Set<? extends Image> get() { logger.debug(">> providing vAppTemplates"); return newLinkedHashSet(concat(transform(organizationsForLocations.apply(locations.get()), imagesInOrg))); } }