mirror of https://github.com/apache/jclouds.git
Issue 158: Added parent location
This commit is contained in:
parent
626b45ee46
commit
89db566131
|
@ -18,6 +18,11 @@
|
|||
*/
|
||||
package org.jclouds.softlayer.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
|
@ -25,6 +30,7 @@ import org.jclouds.softlayer.domain.Address;
|
|||
import org.jclouds.softlayer.domain.Datacenter;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
|
@ -32,7 +38,14 @@ import com.google.common.collect.ImmutableSet;
|
|||
* Converts an Datacenter into a Location.
|
||||
*/
|
||||
public class DatacenterToLocation implements Function<Datacenter,Location> {
|
||||
private final Provider<Supplier<Location>> provider;
|
||||
|
||||
// allow us to lazy discover the provider of a resource
|
||||
@Inject
|
||||
public DatacenterToLocation(Provider<Supplier<Location>> provider) {
|
||||
this.provider = checkNotNull(provider, "provider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location apply(Datacenter datacenter) {
|
||||
return new LocationBuilder().scope(LocationScope.ZONE)
|
||||
|
@ -40,6 +53,7 @@ public class DatacenterToLocation implements Function<Datacenter,Location> {
|
|||
.description(datacenter.getLongName())
|
||||
.id(Long.toString(datacenter.getId()))
|
||||
.iso3166Codes(createIso3166Codes(datacenter.getLocationAddress()))
|
||||
.parent(provider.get().get())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@ import org.jclouds.softlayer.domain.Datacenter;
|
|||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
|
@ -41,7 +44,7 @@ public class DatacenterToLocationTest {
|
|||
|
||||
@BeforeMethod
|
||||
public void setup() {
|
||||
function = new DatacenterToLocation();
|
||||
function = new DatacenterToLocation(Providers.of(Suppliers.ofInstance((Location) null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -52,6 +55,7 @@ public class DatacenterToLocationTest {
|
|||
.country("US")
|
||||
.state("TX")
|
||||
.description("This is Texas!").build()).build();
|
||||
|
||||
Location location = function.apply(address);
|
||||
|
||||
assertEquals(location.getId(), Long.toString(address.getId()));
|
||||
|
|
Loading…
Reference in New Issue