1 | /** |
2 | * |
3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
4 | * |
5 | * ==================================================================== |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * you may not use this file except in compliance with the License. |
8 | * You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
17 | * ==================================================================== |
18 | */ |
19 | package org.jclouds.cloudservers.compute.suppliers; |
20 | |
21 | import static org.jclouds.cloudservers.options.ListOptions.Builder.withDetails; |
22 | |
23 | import java.util.Set; |
24 | |
25 | import javax.annotation.Resource; |
26 | import javax.inject.Inject; |
27 | import javax.inject.Named; |
28 | import javax.inject.Singleton; |
29 | |
30 | import org.jclouds.compute.domain.Image; |
31 | import org.jclouds.compute.reference.ComputeServiceConstants; |
32 | import org.jclouds.logging.Logger; |
33 | import org.jclouds.cloudservers.CloudServersClient; |
34 | |
35 | import com.google.common.base.Function; |
36 | import com.google.common.base.Supplier; |
37 | import com.google.common.collect.Iterables; |
38 | import com.google.common.collect.Sets; |
39 | |
40 | /** |
41 | * |
42 | * @author Adrian Cole |
43 | */ |
44 | @Singleton |
45 | public class CloudServersImageSupplier implements Supplier<Set<? extends Image>> { |
46 | |
47 | @Resource |
48 | @Named(ComputeServiceConstants.COMPUTE_LOGGER) |
49 | protected Logger logger = Logger.NULL; |
50 | |
51 | protected final CloudServersClient sync; |
52 | protected final Function<org.jclouds.cloudservers.domain.Image, Image> cloudServersImageToImage; |
53 | |
54 | @Inject |
55 | CloudServersImageSupplier(CloudServersClient sync, |
56 | Function<org.jclouds.cloudservers.domain.Image, Image> cloudServersImageToImage) { |
57 | this.sync = sync; |
58 | this.cloudServersImageToImage = cloudServersImageToImage; |
59 | } |
60 | |
61 | @Override |
62 | public Set<? extends Image> get() { |
63 | Set<Image> images; |
64 | logger.debug(">> providing images"); |
65 | images = Sets.<Image> newLinkedHashSet(Iterables.transform(sync.listImages(withDetails()), |
66 | cloudServersImageToImage)); |
67 | logger.debug("<< images(%d)", images.size()); |
68 | return images; |
69 | } |
70 | } |