@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()); } }
private OsFamily extractOsFamily(final String name) { final String lowerCaseName = name.toLowerCase(); Optional<OsFamily> family = tryFind(asList(OsFamily.values()), new Predicate<OsFamily>() { @Override public boolean apply(OsFamily input) { return lowerCaseName.startsWith(input.name().toLowerCase()); } }); if (!family.isPresent()) { logger.warn("could not find the operating system family for image: %s", name); } return family.or(OsFamily.UNRECOGNIZED); }
@Override public InputStream apply(URI input) { try { if (input.getScheme() != null && input.getScheme().equals("classpath")) return getClass().getResourceAsStream(input.getPath()); return input.toURL().openStream(); } catch (IOException e) { logger.error(e, "URI could not be read: %s", url); throw Throwables.propagate(e); } }
protected NoSuchElementException throwNoSuchElementExceptionAfterLoggingHardwareIds(String message, Iterable<? extends Hardware> hardwares) { NoSuchElementException exception = new NoSuchElementException(message); if (logger.isTraceEnabled()) logger.warn(exception, "hardware ids that didn't match: %s", transform(hardwares, hardwareToId)); throw exception; }
@Override public ListenableFuture<DriveInfo> apply(String input) { try { return Futures.immediateFuture(cache.getUnchecked(input)); } catch (CacheLoader.InvalidCacheLoadException e) { logger.debug("drive %s not found", input); } catch (UncheckedExecutionException e) { logger.warn(e, "error finding drive %s: %s", input, e.getMessage()); } return Futures.immediateFuture(null); }
@Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder(); Multimap<String, String> regionToInstanceIds = transformValues(index(regionAndIds, regionFunction()), nameFunction()); for (Map.Entry<String, Collection<String>> entry : regionToInstanceIds.asMap().entrySet()) { String region = entry.getKey(); Collection<String> instanceIds = entry.getValue(); logger.trace("looking for instances %s in region %s", instanceIds, region); builder.addAll(concat(client.getInstanceApi().get().describeInstancesInRegion(region, toArray(instanceIds, String.class)))); } return builder.build(); }
private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) { Optional<? extends SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId); if (securityGroupApi.isPresent()) { for (String group : groups) { for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().list(), SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) { ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName()); logger.debug(">> deleting securityGroup(%s)", zoneAndName); securityGroupApi.get().delete(securityGroup.getId()); // TODO: test this clear happens securityGroupMap.invalidate(zoneAndName); logger.debug("<< deleted securityGroup(%s)", zoneAndName); } } } }
protected Set<RunningInstance> getSpots(Set<RegionAndName> regionAndIds) { Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder(); Multimap<String, String> regionToSpotIds = transformValues(index(regionAndIds, regionFunction()), nameFunction()); for (Map.Entry<String, Collection<String>> entry : regionToSpotIds.asMap().entrySet()) { String region = entry.getKey(); Collection<String> spotIds = entry.getValue(); logger.trace("looking for spots %s in region %s", spotIds, region); builder.addAll(transform( client.getSpotInstanceApi().get().describeSpotInstanceRequestsInRegion(region, toArray(spotIds, String.class)), spotConverter)); } return builder.build(); }
protected Set<RunningInstance> createNodesInRegionAndZone(String region, String zone, String group, int count, Template template, RunInstancesOptions instanceOptions) { int countStarted = 0; int tries = 0; Set<RunningInstance> started = ImmutableSet.<RunningInstance> of(); while (countStarted < count && tries++ < count) { if (logger.isDebugEnabled()) logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count - countStarted, region, zone, template.getImage().getProviderId(), instanceOptions.buildFormParameters()); started = ImmutableSet.copyOf(concat( started, client.getInstanceServices().runInstancesInRegion(region, zone, template.getImage().getProviderId(), 1, count - countStarted, instanceOptions))); countStarted = size(started); if (countStarted < count) logger.debug(">> not enough instances (%d/%d) started, attempting again", countStarted, count); } return started; }
@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(); } }
@Test(groups = { "integration", "live" }, singleThreaded = true) public void testListSecurityGroupsForNode() throws RunNodesException, InterruptedException, ExecutionException { skipIfSecurityGroupsNotSupported(); ComputeService computeService = view.getComputeService(); Optional<SecurityGroupExtension> securityGroupExtension = computeService.getSecurityGroupExtension(); assertTrue(securityGroupExtension.isPresent(), "security extension was not present"); for (SecurityGroup securityGroup : securityGroupExtension.get().listSecurityGroupsForNode("uk-1/97374b9f-c706-4c4a-ae5a-48b6d2e58db9")) { logger.info(securityGroup.toString()); } }
public ExecResponse runAction(String action) { ExecResponse returnVal; String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action)) ? execScriptAsRoot(action) : execScriptAsDefaultUser(action); returnVal = runCommand(command); if (ImmutableSet.of("status", "stdout", "stderr").contains(action)) logger.trace("<< %s(%d)", action, returnVal.getExitStatus()); else if (computeLogger.isTraceEnabled()) computeLogger.trace("<< %s[%s]", action, returnVal); else computeLogger.debug("<< %s(%d)", action, returnVal.getExitStatus()); return returnVal; }
/** * Prioritizes endpoint.versionId over endpoint.id when matching */ private Optional<Endpoint> strictMatchEndpointVersion(Iterable<Endpoint> endpoints, String locationId) { Optional<Endpoint> endpointOfVersion = tryFind(endpoints, apiVersionEqualsVersionId); if (!endpointOfVersion.isPresent()) logger.debug("no endpoints of apiType %s matched expected version %s in location %s: %s", apiType, apiVersion, locationId, endpoints); return endpointOfVersion; }
private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) { Zone zone = zoneIdToZone.get().getUnchecked(zoneId); if (supportsSecurityGroups().apply(zone)) { for (String group : groups) { for (SecurityGroup securityGroup : Iterables.filter(client.getSecurityGroupApi().listSecurityGroups(), SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) { ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName()); logger.debug(">> deleting securityGroup(%s)", zoneAndName); client.getSecurityGroupApi().deleteSecurityGroup(securityGroup.getId()); // TODO: test this clear happens securityGroupMap.invalidate(zoneAndName); logger.debug("<< deleted securityGroup(%s)", zoneAndName); } } } }
/** * 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))); } }
@Override public ZoneAndId apply(ZoneAndId id) { FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(id.getZone()).get(); for (FloatingIP ip : floatingIpCache.getUnchecked(id)) { logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id); floatingIpApi.removeFromServer(ip.getIp(), id.getId()); logger.debug(">> deallocating floatingIp(%s)", ip); floatingIpApi.delete(ip.getId()); } floatingIpCache.invalidate(id); return id; }
@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); }