mirror of https://github.com/apache/jclouds.git
rimu related changes for Issue 826
This commit is contained in:
parent
dc78a443de
commit
e45aaa8a3c
|
@ -23,11 +23,8 @@ import java.util.Set;
|
|||
import org.jclouds.compute.config.BindComputeSuppliersByClass;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingDefaultLocationSupplier;
|
||||
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingHardwareSupplier;
|
||||
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingImageSupplier;
|
||||
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingLocationSupplier;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
|
@ -42,14 +39,4 @@ public class RimuHostingBindComputeSuppliersByClass extends BindComputeSuppliers
|
|||
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||
return RimuHostingImageSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||
return RimuHostingLocationSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
|
||||
return RimuHostingDefaultLocationSupplier.class;
|
||||
}
|
||||
}
|
|
@ -29,13 +29,18 @@ import org.jclouds.http.RequiresHttp;
|
|||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||
import org.jclouds.json.config.GsonModule.PropertiesAdapter;
|
||||
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
|
||||
import org.jclouds.location.suppliers.LocationsSupplier;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rimuhosting.miro.RimuHostingAsyncClient;
|
||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
||||
import org.jclouds.rimuhosting.miro.location.RimuHostingDefaultLocationSupplier;
|
||||
import org.jclouds.rimuhosting.miro.location.RimuHostingLocationSupplier;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -78,4 +83,11 @@ public class RimuHostingRestClientModule extends RestClientModule<RimuHostingCli
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installLocations() {
|
||||
super.installLocations();
|
||||
bind(ImplicitLocationSupplier.class).to(RimuHostingDefaultLocationSupplier.class).in(Scopes.SINGLETON);
|
||||
bind(LocationsSupplier.class).to(RimuHostingLocationSupplier.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.rimuhosting.miro.compute.suppliers;
|
||||
package org.jclouds.rimuhosting.miro.location;
|
||||
|
||||
import static org.jclouds.rimuhosting.miro.reference.RimuHostingConstants.PROPERTY_RIMUHOSTING_DEFAULT_DC;
|
||||
|
||||
|
@ -28,6 +28,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -38,7 +39,7 @@ import com.google.common.collect.Iterables;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class RimuHostingDefaultLocationSupplier implements Supplier<Location> {
|
||||
public class RimuHostingDefaultLocationSupplier implements ImplicitLocationSupplier {
|
||||
private final Supplier<Set<? extends Location>> locations;
|
||||
private final String defaultDC;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.rimuhosting.miro.compute.suppliers;
|
||||
package org.jclouds.rimuhosting.miro.location;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
@ -32,13 +32,15 @@ import org.jclouds.domain.LocationBuilder;
|
|||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.location.Iso3166;
|
||||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.location.suppliers.JustProvider;
|
||||
import org.jclouds.location.suppliers.LocationsSupplier;
|
||||
import org.jclouds.location.suppliers.all.JustProvider;
|
||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
||||
import org.jclouds.rimuhosting.miro.domain.DataCenter;
|
||||
import org.jclouds.rimuhosting.miro.domain.PricingPlan;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
@ -48,17 +50,17 @@ import com.google.common.collect.ImmutableSet.Builder;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class RimuHostingLocationSupplier extends JustProvider {
|
||||
public class RimuHostingLocationSupplier extends JustProvider implements LocationsSupplier {
|
||||
|
||||
private final RimuHostingClient sync;
|
||||
private final Map<String, Set<String>> isoCodesById;
|
||||
private final Supplier<Map<String, Supplier<Set<String>>>> isoCodesByIdSupplier;
|
||||
|
||||
@Inject
|
||||
RimuHostingLocationSupplier(@Iso3166 Set<String> isoCodes, @Provider String providerName, @Provider URI endpoint,
|
||||
RimuHostingClient sync, @Iso3166 Map<String, Set<String>> isoCodesById) {
|
||||
RimuHostingClient sync, @Iso3166 Supplier<Map<String, Supplier<Set<String>>>> isoCodesByIdSupplier) {
|
||||
super(providerName, endpoint, isoCodes);
|
||||
this.sync = checkNotNull(sync, "sync");
|
||||
this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById");
|
||||
this.isoCodesByIdSupplier = checkNotNull(isoCodesByIdSupplier, "isoCodesByIdSupplier");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,14 +78,16 @@ public class RimuHostingLocationSupplier extends JustProvider {
|
|||
Location provider = Iterables.getOnlyElement(super.get());
|
||||
if (Iterables.size(list) == 0)
|
||||
locations.add(provider);
|
||||
else
|
||||
else{
|
||||
Map<String, Supplier<Set<String>>> isoCodesById = isoCodesByIdSupplier.get();
|
||||
for (DataCenter from : list) {
|
||||
LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(from.getId()).description(
|
||||
from.getName()).parent(provider);
|
||||
if (isoCodesById.containsKey(from.getId()))
|
||||
builder.iso3166Codes(isoCodesById.get(from.getId()));
|
||||
builder.iso3166Codes(isoCodesById.get(from.getId()).get());
|
||||
locations.add(builder.build());
|
||||
}
|
||||
}
|
||||
return locations.build();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue