@Override protected IterableWithMarker<Image> fetchPageUsingOptions(ImageListOptions options, Optional<Object> arg0) { return api.imageApi().list(options); } }
@Override protected IterableWithMarker<Image> fetchPageUsingOptions(ImageListOptions options, Optional<Object> arg0) { return api.imageApi().list(options); } }
@Override protected IterableWithMarker<Image> fetchPageUsingOptions(ImageListOptions options, Optional<Object> arg0) { return api.imageApi().list(options); } }
@Override public Iterable<ImageInRegion> listImages() { // Images can claim to be available in a region that is currently marked as "unavailable". We shouldn't return // the images scoped to those regions. final Set<String> availableRegionsIds = newHashSet(transform(listLocations(), new Function<Region, String>() { @Override public String apply(Region input) { return input.slug(); } })); // Public images re globally available, but non-public ones can only be available in certain regions. // For these kind of images, return one instance of an ImageInRegion for each region where the image is // available. This way we can properly scope global and concrete images so they can be properly looked up. return concat(filter(api.imageApi().list().concat().transform(new Function<Image, Iterable<ImageInRegion>>() { @Override public Iterable<ImageInRegion> apply(final Image image) { return transform(image.regions(), new Function<String, ImageInRegion>() { @Override public ImageInRegion apply(String region) { return availableRegionsIds.contains(region) ? ImageInRegion.create(image, region) : null; } }); } }), notNull())); }
@Override public Iterable<ImageInRegion> listImages() { // Images can claim to be available in a region that is currently marked as "unavailable". We shouldn't return // the images scoped to those regions. final Set<String> availableRegionsIds = newHashSet(transform(listLocations(), new Function<Region, String>() { @Override public String apply(Region input) { return input.slug(); } })); // Public images re globally available, but non-public ones can only be available in certain regions. // For these kind of images, return one instance of an ImageInRegion for each region where the image is // available. This way we can properly scope global and concrete images so they can be properly looked up. return concat(filter(api.imageApi().list().concat().transform(new Function<Image, Iterable<ImageInRegion>>() { @Override public Iterable<ImageInRegion> apply(final Image image) { return transform(image.regions(), new Function<String, ImageInRegion>() { @Override public ImageInRegion apply(String region) { return availableRegionsIds.contains(region) ? ImageInRegion.create(image, region) : null; } }); } }), notNull())); }
@Override public Iterable<ImageInRegion> listImages() { // Images can claim to be available in a region that is currently marked as "unavailable". We shouldn't return // the images scoped to those regions. final Set<String> availableRegionsIds = newHashSet(transform(listLocations(), new Function<Region, String>() { @Override public String apply(Region input) { return input.slug(); } })); // Public images re globally available, but non-public ones can only be available in certain regions. // For these kind of images, return one instance of an ImageInRegion for each region where the image is // available. This way we can properly scope global and concrete images so they can be properly looked up. return concat(filter(api.imageApi().list().concat().transform(new Function<Image, Iterable<ImageInRegion>>() { @Override public Iterable<ImageInRegion> apply(final Image image) { return transform(image.regions(), new Function<String, ImageInRegion>() { @Override public ImageInRegion apply(String region) { return availableRegionsIds.contains(region) ? ImageInRegion.create(image, region) : null; } }); } }), notNull())); }
@Override public Image call() throws Exception { if (imageAvailablePredicate.apply(snapshotEvent.id())) { org.jclouds.digitalocean2.domain.Image snapshot = api.imageApi().list().concat() .firstMatch(new Predicate<org.jclouds.digitalocean2.domain.Image>() { @Override public boolean apply(org.jclouds.digitalocean2.domain.Image input) { return input.name().equals(cloneTemplate.getName()); } }).get(); return imageTransformer.apply(ImageInRegion.create(snapshot, droplet.region().slug())); } throw new UncheckedTimeoutException("Image was not created within the time limit: " + cloneTemplate.getName()); } });
@Override public Image call() throws Exception { if (imageAvailablePredicate.apply(snapshotEvent.id())) { org.jclouds.digitalocean2.domain.Image snapshot = api.imageApi().list().concat() .firstMatch(new Predicate<org.jclouds.digitalocean2.domain.Image>() { @Override public boolean apply(org.jclouds.digitalocean2.domain.Image input) { return input.name().equals(cloneTemplate.getName()); } }).get(); return imageTransformer.apply(ImageInRegion.create(snapshot, droplet.region().slug())); } throw new UncheckedTimeoutException("Image was not created within the time limit: " + cloneTemplate.getName()); } });
@Override public Image call() throws Exception { if (imageAvailablePredicate.apply(snapshotEvent.id())) { org.jclouds.digitalocean2.domain.Image snapshot = api.imageApi().list().concat() .firstMatch(new Predicate<org.jclouds.digitalocean2.domain.Image>() { @Override public boolean apply(org.jclouds.digitalocean2.domain.Image input) { return input.name().equals(cloneTemplate.getName()); } }).get(); return imageTransformer.apply(ImageInRegion.create(snapshot, droplet.region().slug())); } throw new UncheckedTimeoutException("Image was not created within the time limit: " + cloneTemplate.getName()); } });
public void testListImages() { final AtomicInteger found = new AtomicInteger(0); // DigitalOcean return 25 records per page by default. Inspect at most 2 pages assertTrue(api().list().concat().limit(50).allMatch(new Predicate<Image>() { @Override public boolean apply(Image input) { found.incrementAndGet(); return !isNullOrEmpty(input.name()); } }), "All images must have the 'name' field populated"); assertTrue(found.get() > 0, "Expected some images to be returned"); }
public void testListImagesOnePage() { final AtomicInteger found = new AtomicInteger(0); assertTrue(api().list(page(1).perPage(5)).allMatch(new Predicate<Image>() { @Override public boolean apply(Image input) { found.incrementAndGet(); return !isNullOrEmpty(input.name()); } }), "All images must have the 'name' field populated"); assertTrue(found.get() > 0, "Expected some images to be returned"); }
public void testListImagesByType() { final AtomicInteger found = new AtomicInteger(0); assertTrue(api().list(type("distribution").perPage(5)).allMatch(new Predicate<Image>() { @Override public boolean apply(Image input) { found.incrementAndGet(); return !isNullOrEmpty(input.distribution()); } }), "All images must have the 'distribution' field populated"); assertTrue(found.get() > 0, "Expected some images to be returned"); }
protected Image ubuntuImageInRegion(final Region region) { return api.imageApi().list().concat().firstMatch(new Predicate<Image>() { @Override public boolean apply(Image input) { return "Ubuntu".equalsIgnoreCase(input.distribution()) && !isNullOrEmpty(input.slug()) && input.regions().contains(region.slug()); } }).get(); }
public void testGetImageBySlug() { Optional<Image> first = api().list().concat().firstMatch(new Predicate<Image>() { @Override public boolean apply(Image input) { return !isNullOrEmpty(input.slug()); } }); assertTrue(first.isPresent(), "At least one image with the 'slug' field set was expected to exist"); assertNotNull(api().get(first.get().slug())); }
public void testGetImage() { Optional<Image> first = api().list().concat().first(); assertTrue(first.isPresent(), "At least one image was expected to exist"); assertNotNull(api().get(first.get().id())); }
public void testListImagesReturns404() throws InterruptedException { server.enqueue(response404()); Iterable<Image> images = api.imageApi().list().concat(); assertTrue(isEmpty(images)); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/images"); }
public void testListImagesWithOptions() throws InterruptedException { server.enqueue(jsonResponse("/images-first.json")); Iterable<Image> images = api.imageApi().list(page(1).perPage(5).type("distribution")); assertEquals(size(images), 5); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/images?page=1&per_page=5&type=distribution"); }
public void testListImagesWithOptionsReturns404() throws InterruptedException { server.enqueue(response404()); Iterable<Image> images = api.imageApi().list(page(1).perPage(5).type("distribution")); assertTrue(isEmpty(images)); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/images?page=1&per_page=5&type=distribution"); }
public void testListImages() throws InterruptedException { server.enqueue(jsonResponse("/images-first.json")); server.enqueue(jsonResponse("/images-last.json")); Iterable<Image> images = api.imageApi().list().concat(); assertEquals(size(images), 10); // Force the PagedIterable to advance assertEquals(server.getRequestCount(), 2); assertSent(server, "GET", "/images"); assertSent(server, "GET", "/images?page=2&per_page=5&type=distribution"); }