http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPath.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPath.java b/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPath.java deleted file mode 100644 index 3d4a41e..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPath.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.infrastructure; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.abiquo.binders.AppendToPath; -import org.jclouds.abiquo.functions.infrastructure.ParseMachineId; -import org.jclouds.http.HttpRequest; - -/** - * Append the {@link Machine} id to the request URI. - */ -@Singleton -public class AppendMachineIdToPath extends AppendToPath { - private ParseMachineId parser; - - @Inject - public AppendMachineIdToPath(final ParseMachineId parser) { - super(); - this.parser = parser; - } - - @Override - protected <R extends HttpRequest> String getValue(final R request, final Object input) { - return parser.apply(input); - } - -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPath.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPath.java b/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPath.java deleted file mode 100644 index 29d0943..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPath.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.infrastructure; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.abiquo.binders.AppendToPath; -import org.jclouds.abiquo.functions.infrastructure.ParseRemoteServiceType; -import org.jclouds.http.HttpRequest; - -/** - * Append the {@link RemoteServiceType} service to the request URI. - * <p> - * This method assumes that the input object is a {@link RemoteServiceType} - * enumeration. - */ -@Singleton -public class AppendRemoteServiceTypeToPath extends AppendToPath { - private ParseRemoteServiceType parser; - - @Inject - public AppendRemoteServiceTypeToPath(final ParseRemoteServiceType parser) { - super(); - this.parser = parser; - } - - @Override - protected <R extends HttpRequest> String getValue(final R request, final Object input) { - return parser.apply(input); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPath.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPath.java b/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPath.java deleted file mode 100644 index 2de3f33..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPath.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.infrastructure; - -import javax.inject.Singleton; - -import org.jclouds.abiquo.binders.BindToPath; -import org.jclouds.rest.internal.GeneratedHttpRequest; - -/** - * Binds the given link to the uri appends the supported devices action path. - */ -@Singleton -public class BindSupportedDevicesLinkToPath extends BindToPath { - - @Override - protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) { - return super.getNewEndpoint(gRequest, input) + "/action/supported"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java deleted file mode 100644 index 7e7282d..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/config/AbiquoComputeServiceContextModule.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.config; - -import org.jclouds.abiquo.compute.functions.DatacenterToLocation; -import org.jclouds.abiquo.compute.functions.VirtualDatacenterToLocation; -import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateInVirtualDatacenterToHardware; -import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateToImage; -import org.jclouds.abiquo.compute.functions.VirtualMachineToNodeMetadata; -import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions; -import org.jclouds.abiquo.compute.strategy.AbiquoComputeServiceAdapter; -import org.jclouds.abiquo.compute.strategy.CreateGroupBeforeCreatingNodes; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.config.ComputeServiceAdapterContextModule; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet; -import org.jclouds.domain.Location; -import org.jclouds.location.suppliers.ImplicitLocationSupplier; -import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone; - -import com.google.common.base.Function; -import com.google.inject.Scopes; -import com.google.inject.TypeLiteral; - -/** - * Abiquo Compute service configuration module. - */ -public class AbiquoComputeServiceContextModule - extends - ComputeServiceAdapterContextModule<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter> { - - @Override - protected void configure() { - super.configure(); - bind( - new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>>() { - }).to(AbiquoComputeServiceAdapter.class); - bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>() { - }).to(VirtualMachineToNodeMetadata.class); - bind(new TypeLiteral<Function<VirtualMachineTemplate, Image>>() { - }).to(VirtualMachineTemplateToImage.class); - bind(new TypeLiteral<Function<VirtualMachineTemplateInVirtualDatacenter, Hardware>>() { - }).to(VirtualMachineTemplateInVirtualDatacenterToHardware.class); - bind(new TypeLiteral<Function<Datacenter, Location>>() { - }).to(DatacenterToLocation.class); - bind(new TypeLiteral<Function<VirtualDatacenter, Location>>() { - }).to(VirtualDatacenterToLocation.class); - bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON); - bind(TemplateOptions.class).to(AbiquoTemplateOptions.class); - bind(CreateNodesInGroupThenAddToSet.class).to(CreateGroupBeforeCreatingNodes.class); - install(new LocationsFromComputeServiceAdapterModule<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>() { - }); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/DatacenterToLocation.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/DatacenterToLocation.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/DatacenterToLocation.java deleted file mode 100644 index eba7a9c..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/DatacenterToLocation.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.functions; - -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationBuilder; -import org.jclouds.domain.LocationScope; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -/** - * Converts a {@link Datacenter} to a {@link Location} one. - * <p> - * Physical datacenters will be considered regions. - */ -@Singleton -public class DatacenterToLocation implements Function<Datacenter, Location> { - - @Override - public Location apply(final Datacenter datacenter) { - LocationBuilder builder = new LocationBuilder(); - builder.id(datacenter.getId().toString()); - builder.description(datacenter.getName() + " [" + datacenter.getLocation() + "]"); - builder.metadata(ImmutableMap.<String, Object> of()); - builder.scope(LocationScope.REGION); - builder.iso3166Codes(ImmutableSet.<String> of()); - - builder.parent(new LocationBuilder().scope(LocationScope.PROVIDER).id("abiquo").description("abiquo").build()); - - return builder.build(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualDatacenterToLocation.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualDatacenterToLocation.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualDatacenterToLocation.java deleted file mode 100644 index 0681844..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualDatacenterToLocation.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.collect.Memoized; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationBuilder; -import org.jclouds.domain.LocationScope; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -/** - * Converts a {@link VirtualDatacenter} to a {@link Location} one. - * <p> - * Virtual datacenters will be considered zones, since images will be deployed - * in a virtual datacenter. Each zone will be scoped into a physical datacenter - * (region). - */ -@Singleton -public class VirtualDatacenterToLocation implements Function<VirtualDatacenter, Location> { - private final Function<Datacenter, Location> datacenterToLocation; - - private final Supplier<Map<Integer, Datacenter>> regionMap; - - @Inject - public VirtualDatacenterToLocation(final Function<Datacenter, Location> datacenterToLocation, - @Memoized final Supplier<Map<Integer, Datacenter>> regionMap) { - this.datacenterToLocation = checkNotNull(datacenterToLocation, "datacenterToLocation"); - this.regionMap = checkNotNull(regionMap, "regionMap"); - } - - @Override - public Location apply(final VirtualDatacenter vdc) { - LocationBuilder builder = new LocationBuilder(); - builder.id(vdc.getId().toString()); - builder.description(vdc.getName()); - builder.metadata(ImmutableMap.<String, Object> of()); - builder.scope(LocationScope.ZONE); - builder.iso3166Codes(ImmutableSet.<String> of()); - - Datacenter parent = regionMap.get().get(vdc.unwrap().getIdFromLink(ParentLinkName.DATACENTER)); - builder.parent(datacenterToLocation.apply(parent)); - - return builder.build(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeState.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeState.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeState.java deleted file mode 100644 index 311bad2..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeState.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.functions; - -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata.Status; - -import com.abiquo.server.core.cloud.VirtualMachineState; -import com.google.common.base.Function; - -/** - * Converts a {@link VirtualMachineState} object to a {@link Status} one. - */ -@Singleton -public class VirtualMachineStateToNodeState implements Function<VirtualMachineState, Status> { - - @Override - public Status apply(final VirtualMachineState state) { - switch (state) { - case ALLOCATED: - case LOCKED: - case CONFIGURED: - case NOT_ALLOCATED: - return Status.PENDING; - case ON: - return Status.RUNNING; - case OFF: - case PAUSED: - return Status.SUSPENDED; - case UNKNOWN: - default: - return Status.UNRECOGNIZED; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateInVirtualDatacenterToHardware.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateInVirtualDatacenterToHardware.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateInVirtualDatacenterToHardware.java deleted file mode 100644 index bd2631a..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateInVirtualDatacenterToHardware.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.domain.VolumeBuilder; -import org.jclouds.compute.predicates.ImagePredicates; -import org.jclouds.domain.Location; - -import com.google.common.base.Function; - -/** - * Transforms a {@link VirtualMachineTemplate} into an {@link Hardware}. - * <p> - * Each {@link Image} ({@link VirtualMachineTemplate}) will have one - * {@link Hardware} entity for each zone (scoped to a virtualization technology) - * supported by the image. - */ -@Singleton -public class VirtualMachineTemplateInVirtualDatacenterToHardware implements - Function<VirtualMachineTemplateInVirtualDatacenter, Hardware> { - /** The default core speed, 2.0Ghz. */ - public static final double DEFAULT_CORE_SPEED = 2.0; - - private final Function<VirtualDatacenter, Location> virtualDatacenterToLocation; - - @Inject - public VirtualMachineTemplateInVirtualDatacenterToHardware( - final Function<VirtualDatacenter, Location> virtualDatacenterToLocation) { - this.virtualDatacenterToLocation = checkNotNull(virtualDatacenterToLocation, "virtualDatacenterToLocation"); - } - - @Override - public Hardware apply(final VirtualMachineTemplateInVirtualDatacenter templateInVirtualDatacenter) { - VirtualMachineTemplate template = templateInVirtualDatacenter.getTemplate(); - VirtualDatacenter virtualDatacenter = templateInVirtualDatacenter.getZone(); - - HardwareBuilder builder = new HardwareBuilder(); - builder.providerId(template.getId().toString()); - builder.id(template.getId().toString() + "/" + virtualDatacenter.getId()); - builder.uri(template.getURI()); - - builder.name(template.getName()); - builder.processor(new Processor(template.getCpuRequired(), DEFAULT_CORE_SPEED)); - builder.ram(template.getRamRequired()); - - // Location information - builder.location(virtualDatacenterToLocation.apply(virtualDatacenter)); - builder.hypervisor(virtualDatacenter.getHypervisorType().name()); - builder.supportsImage(ImagePredicates.idEquals(template.getId().toString())); - - VolumeBuilder volumeBuilder = new VolumeBuilder(); - volumeBuilder.bootDevice(true); - volumeBuilder.size(toGb(template.getHdRequired())); - volumeBuilder.type(Volume.Type.LOCAL); - volumeBuilder.durable(false); - builder.volume(volumeBuilder.build()); - - return builder.build(); - } - - private static float toGb(final long bytes) { - return bytes / (float) (1024 * 1024 * 1024); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImage.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImage.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImage.java deleted file mode 100644 index 0bf5125..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImage.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.collect.Memoized; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Image.Status; -import org.jclouds.compute.domain.ImageBuilder; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.domain.Location; - -import com.abiquo.model.rest.RESTLink; -import com.google.common.base.Function; -import com.google.common.base.Supplier; - -/** - * Transforms a {@link VirtualMachineTemplate} into an {@link Image}. - * <p> - * Images are scoped to a region (physical datacenter). - */ -@Singleton -public class VirtualMachineTemplateToImage implements Function<VirtualMachineTemplate, Image> { - private final Function<Datacenter, Location> datacenterToLocation; - - private final Supplier<Map<Integer, Datacenter>> regionMap; - - @Inject - public VirtualMachineTemplateToImage(final Function<Datacenter, Location> datacenterToLocation, - @Memoized final Supplier<Map<Integer, Datacenter>> regionMap) { - this.datacenterToLocation = checkNotNull(datacenterToLocation, "datacenterToLocation"); - this.regionMap = checkNotNull(regionMap, "regionMap"); - } - - @Override - public Image apply(final VirtualMachineTemplate template) { - ImageBuilder builder = new ImageBuilder(); - builder.ids(template.getId().toString()); - builder.name(template.getName()); - builder.description(template.getDescription()); - - // Location information - Datacenter region = regionMap.get().get(template.unwrap().getIdFromLink(ParentLinkName.DATACENTER)); - builder.location(datacenterToLocation.apply(region)); - - // Only conversions have a status - builder.status(Status.AVAILABLE); - builder.backendStatus(Status.AVAILABLE.name()); // Abiquo images do not - // have a status - - RESTLink downloadLink = template.unwrap().searchLink("diskfile"); - builder.uri(downloadLink == null ? null : URI.create(downloadLink.getHref())); - - // TODO: Operating system not implemented in Abiquo Templates - // TODO: Image credentials still not present in Abiquo template metadata - // Will be added in Abiquo 2.4: - // http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3647 - builder.operatingSystem(OperatingSystem.builder().description(template.getName()).build()); - - return builder.build(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadata.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadata.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadata.java deleted file mode 100644 index 4b18546..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadata.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter; -import org.jclouds.abiquo.domain.network.Ip; -import org.jclouds.abiquo.domain.network.PrivateIp; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.domain.Processor; -import org.jclouds.domain.Location; -import org.jclouds.logging.Logger; - -import com.abiquo.server.core.cloud.VirtualMachineState; -import com.google.common.base.Function; -import com.google.common.base.Predicates; -import com.google.common.collect.Lists; - -/** - * Links a {@link VirtualMachine} object to a {@link NodeMetadata} one. - */ -@Singleton -public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, NodeMetadata> { - @Resource - protected Logger logger = Logger.NULL; - - private final VirtualMachineTemplateToImage virtualMachineTemplateToImage; - - private final VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware; - - private final VirtualMachineStateToNodeState virtualMachineStateToNodeState; - - private final Function<VirtualDatacenter, Location> virtualDatacenterToLocation; - - @Inject - public VirtualMachineToNodeMetadata(final VirtualMachineTemplateToImage virtualMachineTemplateToImage, - final VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware, - final VirtualMachineStateToNodeState virtualMachineStateToNodeState, - final Function<VirtualDatacenter, Location> virtualDatacenterToLocation) { - this.virtualMachineTemplateToImage = checkNotNull(virtualMachineTemplateToImage, "virtualMachineTemplateToImage"); - this.virtualMachineTemplateToHardware = checkNotNull(virtualMachineTemplateToHardware, - "virtualMachineTemplateToHardware"); - this.virtualMachineStateToNodeState = checkNotNull(virtualMachineStateToNodeState, - "virtualMachineStateToNodeState"); - this.virtualDatacenterToLocation = checkNotNull(virtualDatacenterToLocation, "virtualDatacenterToLocation"); - } - - @Override - public NodeMetadata apply(final VirtualMachine vm) { - NodeMetadataBuilder builder = new NodeMetadataBuilder(); - builder.ids(vm.getId().toString()); - builder.uri(vm.getURI()); - builder.name(vm.getNameLabel()); - builder.group(vm.getVirtualAppliance().getName()); - - // TODO: Node credentials still not present in Abiquo template metadata - // Will be added in Abiquo 2.4: - // http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3647 - - // Location details - VirtualDatacenter vdc = vm.getVirtualDatacenter(); - builder.location(virtualDatacenterToLocation.apply(vdc)); - - // Image details - VirtualMachineTemplate template = vm.getTemplate(); - Image image = virtualMachineTemplateToImage.apply(template); - builder.imageId(image.getId().toString()); - builder.operatingSystem(image.getOperatingSystem()); - - // Hardware details - Hardware defaultHardware = virtualMachineTemplateToHardware.apply(new VirtualMachineTemplateInVirtualDatacenter( - template, vdc)); - - Hardware hardware = HardwareBuilder - .fromHardware(defaultHardware) - .ram(vm.getRam()) - .processors( - Lists.newArrayList(new Processor(vm.getCpu(), - VirtualMachineTemplateInVirtualDatacenterToHardware.DEFAULT_CORE_SPEED))) // - .build(); - - builder.hardware(hardware); - - // Networking configuration - Iterable<Ip<?, ?>> nics = vm.listAttachedNics(); - builder.privateAddresses(ips(filter(nics, Predicates.instanceOf(PrivateIp.class)))); - builder.publicAddresses(ips(filter(nics, Predicates.not(Predicates.instanceOf(PrivateIp.class))))); - - // Node state - VirtualMachineState state = vm.getState(); - builder.status(virtualMachineStateToNodeState.apply(state)); - builder.backendStatus(state.name()); - - return builder.build(); - } - - private static Iterable<String> ips(final Iterable<Ip<?, ?>> nics) { - return transform(nics, new Function<Ip<?, ?>, String>() { - @Override - public String apply(final Ip<?, ?> nic) { - return nic.getIp(); - } - }); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptions.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptions.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptions.java deleted file mode 100644 index 805d8ce..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptions.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.options; - -import org.jclouds.compute.options.TemplateOptions; - -/** - * Contains options supported by the ComputeService on the <em>Abiquo</em> - * provider. - */ -public class AbiquoTemplateOptions extends TemplateOptions implements Cloneable { - public static final AbiquoTemplateOptions NONE = new AbiquoTemplateOptions(); - - private Integer overrideCores; - - private Integer overrideRam; - - private String vncPassword; - - @Override - public TemplateOptions clone() { - AbiquoTemplateOptions options = new AbiquoTemplateOptions(); - copyTo(options); - return options; - } - - @Override - public void copyTo(final TemplateOptions to) { - super.copyTo(to); - if (to instanceof AbiquoTemplateOptions) { - AbiquoTemplateOptions options = AbiquoTemplateOptions.class.cast(to); - options.overrideCores(overrideCores); - options.overrideRam(overrideRam); - options.vncPassword(vncPassword); - } - } - - /** - * Override the number of cores set by the hardware profile. - * - * @return The template options with the number of cores. - */ - public AbiquoTemplateOptions overrideCores(final Integer overrideCores) { - this.overrideCores = overrideCores; - return this; - } - - public Integer getOverrideCores() { - return overrideCores; - } - - /** - * Override the amount of ram set by the hardware profile. - * - * @return The template options with the amount of ram. - */ - public AbiquoTemplateOptions overrideRam(final Integer overrideRam) { - this.overrideRam = overrideRam; - return this; - } - - public Integer getOverrideRam() { - return overrideRam; - } - - /** - * Set the VNC password to access the virtual machine. - * <p> - * By default virtual machines does not have VNC access password protected. - * - * @return The template options with the VNC password. - */ - public AbiquoTemplateOptions vncPassword(final String vncPassword) { - this.vncPassword = vncPassword; - return this; - } - - public String getVncPassword() { - return vncPassword; - } - - public static class Builder { - /** - * @see AbiquoTemplateOptions#overrideCores(int) - */ - public static AbiquoTemplateOptions overrideCores(final Integer overrideCores) { - AbiquoTemplateOptions options = new AbiquoTemplateOptions(); - return options.overrideCores(overrideCores); - } - - /** - * @see AbiquoTemplateOptions#overrideRam(int) - */ - public static AbiquoTemplateOptions overrideRam(final Integer overrideRam) { - AbiquoTemplateOptions options = new AbiquoTemplateOptions(); - return options.overrideRam(overrideRam); - } - - /** - * @see AbiquoTemplateOptions#vncPassword(String) - */ - public static AbiquoTemplateOptions vncPassword(final String vncPassword) { - AbiquoTemplateOptions options = new AbiquoTemplateOptions(); - return options.vncPassword(vncPassword); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java deleted file mode 100644 index 616eaee..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/AbiquoComputeServiceAdapter.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.strategy; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.contains; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.get; -import static com.google.common.collect.Iterables.isEmpty; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Iterables.tryFind; - -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.domain.network.ExternalNetwork; -import org.jclouds.abiquo.domain.network.Ip; -import org.jclouds.abiquo.domain.network.Network; -import org.jclouds.abiquo.domain.network.PublicIp; -import org.jclouds.abiquo.features.services.AdministrationService; -import org.jclouds.abiquo.features.services.CloudService; -import org.jclouds.abiquo.features.services.MonitoringService; -import org.jclouds.abiquo.monitor.VirtualMachineMonitor; -import org.jclouds.abiquo.predicates.IpPredicates; -import org.jclouds.collect.Memoized; -import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; -import org.jclouds.logging.Logger; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.cloud.VirtualMachineState; -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableList; -import com.google.common.primitives.Ints; -import com.google.inject.Inject; - -/** - * Defines the connection between the {@link AbiquoApi} implementation and the - * jclouds {@link ComputeService}. - * - * - * @see CreateGroupBeforeCreatingNodes - */ -@Singleton -public class AbiquoComputeServiceAdapter - implements - ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter> { - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - private final ApiContext<AbiquoApi> context; - - private final AdministrationService adminService; - - private final CloudService cloudService; - - private final MonitoringService monitoringService; - - private final FindCompatibleVirtualDatacenters compatibleVirtualDatacenters; - - private final Supplier<Map<Integer, Datacenter>> regionMap; - - private final Timeouts timeouts; - - @Inject - public AbiquoComputeServiceAdapter(final ApiContext<AbiquoApi> context, final AdministrationService adminService, - final CloudService cloudService, final MonitoringService monitoringService, - final FindCompatibleVirtualDatacenters compatibleVirtualDatacenters, - @Memoized final Supplier<Map<Integer, Datacenter>> regionMap, Timeouts timeouts) { - this.context = checkNotNull(context, "context"); - this.adminService = checkNotNull(adminService, "adminService"); - this.cloudService = checkNotNull(cloudService, "cloudService"); - this.monitoringService = checkNotNull(monitoringService, "monitoringService"); - this.compatibleVirtualDatacenters = checkNotNull(compatibleVirtualDatacenters, "compatibleVirtualDatacenters"); - this.regionMap = checkNotNull(regionMap, "regionMap"); - this.timeouts = checkNotNull(timeouts, "timeouts"); - } - - @Override - public NodeAndInitialCredentials<VirtualMachine> createNodeWithGroupEncodedIntoName(final String group, - final String name, final Template template) { - checkArgument(template instanceof VirtualApplianceCachingTemplate, - "A VirtualApplianceCachingTemplate is required"); - return createNodeWithGroupEncodedIntoName(name, VirtualApplianceCachingTemplate.class.cast(template)); - } - - protected NodeAndInitialCredentials<VirtualMachine> createNodeWithGroupEncodedIntoName(final String name, - final VirtualApplianceCachingTemplate template) { - AbiquoTemplateOptions options = template.getOptions().as(AbiquoTemplateOptions.class); - Enterprise enterprise = adminService.getCurrentEnterprise(); - - // Get the region where the template is available - Datacenter datacenter = regionMap.get().get(Integer.valueOf(template.getImage().getLocation().getId())); - - // Load the template - VirtualMachineTemplate virtualMachineTemplate = enterprise.getTemplateInRepository(datacenter, - Integer.valueOf(template.getImage().getId())); - - Integer overrideCores = options.getOverrideCores(); - Integer overrideRam = options.getOverrideRam(); - - VirtualMachine vm = VirtualMachine.builder(context, template.getVirtualAppliance(), virtualMachineTemplate) // - .nameLabel(name) // - .cpu(overrideCores != null ? overrideCores : totalCores(template.getHardware())) // - .ram(overrideRam != null ? overrideRam : template.getHardware().getRam()) // - .password(options.getVncPassword()) // Can be null - .build(); - - vm.save(); - - configureNetworking(vm, template, datacenter, options); - - // This is an async operation, but jclouds already waits until the node is - // RUNNING, so there is no need to block here - vm.deploy(); - - return new NodeAndInitialCredentials<VirtualMachine>(vm, vm.getId().toString(), null); - } - - @Override - public Iterable<VirtualMachineTemplateInVirtualDatacenter> listHardwareProfiles() { - // In Abiquo, images are scoped to a region (physical datacenter), and - // hardware profiles are scoped to a zone (a virtual datacenter in the - // region, with a concrete virtualization technology) - - return concat(transform(listImages(), - new Function<VirtualMachineTemplate, Iterable<VirtualMachineTemplateInVirtualDatacenter>>() { - @Override - public Iterable<VirtualMachineTemplateInVirtualDatacenter> apply(final VirtualMachineTemplate template) { - Iterable<VirtualDatacenter> compatibleZones = compatibleVirtualDatacenters.execute(template); - - return transform(compatibleZones, - new Function<VirtualDatacenter, VirtualMachineTemplateInVirtualDatacenter>() { - @Override - public VirtualMachineTemplateInVirtualDatacenter apply(final VirtualDatacenter vdc) { - return new VirtualMachineTemplateInVirtualDatacenter(template, vdc); - } - }); - } - })); - } - - @Override - public Iterable<VirtualMachineTemplate> listImages() { - Enterprise enterprise = adminService.getCurrentEnterprise(); - return enterprise.listTemplates(); - } - - @Override - public VirtualMachineTemplate getImage(final String id) { - return find(listImages(), new Predicate<VirtualMachineTemplate>() { - @Override - public boolean apply(VirtualMachineTemplate input) { - return input.getId().toString().equals(id); - } - }, null); - } - - @Override - public Iterable<VirtualDatacenter> listLocations() { - return cloudService.listVirtualDatacenters(); - } - - @Override - public VirtualMachine getNode(final String id) { - return find(cloudService.listVirtualMachines(), vmId(id), null); - } - - @Override - public void destroyNode(final String id) { - VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor(); - VirtualMachine vm = getNode(id); - vm.undeploy(true); - monitor.awaitCompletionUndeploy(timeouts.nodeTerminated, TimeUnit.MILLISECONDS, vm); - vm.delete(); - } - - @Override - public void rebootNode(final String id) { - VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor(); - VirtualMachine vm = getNode(id); - vm.reboot(); - monitor.awaitState(timeouts.nodeRunning, TimeUnit.MILLISECONDS, VirtualMachineState.ON, vm); - } - - @Override - public void resumeNode(final String id) { - VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor(); - VirtualMachine vm = getNode(id); - vm.changeState(VirtualMachineState.ON); - monitor.awaitState(timeouts.nodeRunning, TimeUnit.MILLISECONDS, VirtualMachineState.ON, vm); - } - - @Override - public void suspendNode(final String id) { - VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor(); - VirtualMachine vm = getNode(id); - vm.changeState(VirtualMachineState.PAUSED); - monitor.awaitState(timeouts.nodeSuspended, TimeUnit.MILLISECONDS, VirtualMachineState.PAUSED, vm); - } - - @Override - public Iterable<VirtualMachine> listNodes() { - return cloudService.listVirtualMachines(); - } - - @Override - public Iterable<VirtualMachine> listNodesByIds(final Iterable<String> ids) { - return filter(listNodes(), new Predicate<VirtualMachine>() { - - @Override - public boolean apply(VirtualMachine machine) { - return contains(ids, Integer.toString(machine.getId())); - } - }); - } - - /** - * Configures the networking for the created virtual machine. - * <ul> - * <li>If the template options have been configured with a set of network - * identifiers, jclouds will assign the virtual machine one IP address of - * each network.</li> - * <li>If no network ids have been defined, jclouds will try to assign a - * public IP address.</li> - * <li>If no public IP addresses are available in the user account, then an - * IP address in the virtual datacenter's default network will be assigned.</li> - * </ul> - */ - private void configureNetworking(VirtualMachine vm, VirtualApplianceCachingTemplate template, Datacenter datacenter, - TemplateOptions options) { - - if (!options.getNetworks().isEmpty()) { - ImmutableList.Builder<Ip<?, ?>> ips = ImmutableList.<Ip<?, ?>> builder(); - - Enterprise enterprise = adminService.getCurrentEnterprise(); - Iterable<ExternalNetwork> externalNetworks = enterprise.listExternalNetworks(datacenter); - - for (String networkId : options.getNetworks()) { - Network<? extends Ip<?, ?>> network = template.getVirtualDatacenter().getPrivateNetwork( - Ints.tryParse(networkId)); - - if (network == null) { - // If the given network is not a private network, it should be an - // external one - final Integer id = Ints.tryParse(networkId); - network = find(externalNetworks, new Predicate<Network<?>>() { - @Override - public boolean apply(final Network<?> input) { - return id.equals(input.getId()); - } - }, null); - } - - checkArgument(network != null, "No network was found with id: %s", networkId); - - Iterable<? extends Ip<?, ?>> unusedIps = network.listUnusedIps(); - checkArgument(!isEmpty(unusedIps), "There are no available ips in network: %s", networkId); - - // Get the first available ip - Ip<?, ?> availableIp = get(unusedIps, 0); - logger.debug(">> Found available ip: %s", availableIp); - ips.add(availableIp); - } - - // Assign all ips to the virtual machine - vm.setNics(ips.build()); - } else { - Optional<PublicIp> publicIp = tryFind(template.getVirtualDatacenter().listPurchasedPublicIps(), - IpPredicates.<PublicIp> notUsed()); - if (publicIp.isPresent()) { - logger.debug(">> Found available public ip %s", publicIp.get().getIp()); - vm.setNics(ImmutableList.<Ip<?, ?>> of(publicIp.get())); - } else { - logger.debug(">> No available public ip found. Using a private ip"); - } - } - } - - private static Predicate<VirtualMachine> vmId(final String id) { - return new Predicate<VirtualMachine>() { - @Override - public boolean apply(final VirtualMachine input) { - return Integer.valueOf(id).equals(input.getId()); - } - }; - } - - private static int totalCores(final Hardware hardware) { - double cores = 0; - for (Processor processor : hardware.getProcessors()) { - cores += processor.getCores(); - } - return Double.valueOf(cores).intValue(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/CreateGroupBeforeCreatingNodes.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/CreateGroupBeforeCreatingNodes.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/CreateGroupBeforeCreatingNodes.java deleted file mode 100644 index d77b021..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/CreateGroupBeforeCreatingNodes.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.strategy; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.tryFind; - -import java.util.Map; -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.VirtualAppliance; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.features.services.CloudService; -import org.jclouds.compute.config.CustomizationResponse; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.functions.GroupNamingConvention; -import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName; -import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap; -import org.jclouds.compute.strategy.ListNodesStrategy; -import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet; -import org.jclouds.rest.ApiContext; - -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.collect.Multimap; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; - -/** - * Creates the group before concurrently creating the nodes, to avoid creating - * more than one group with the same name. - */ -@Singleton -public class CreateGroupBeforeCreatingNodes extends CreateNodesWithGroupEncodedIntoNameThenAddToSet { - - protected final ApiContext<AbiquoApi> context; - - protected final CloudService cloudService; - - @Inject - protected CreateGroupBeforeCreatingNodes( - CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy, - ListNodesStrategy listNodesStrategy, - GroupNamingConvention.Factory namingConvention, - @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, - CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, - ApiContext<AbiquoApi> context, CloudService cloudService) { - super(addNodeWithGroupStrategy, listNodesStrategy, namingConvention, userExecutor, - customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory); - this.context = checkNotNull(context, "context must not be null"); - this.cloudService = checkNotNull(cloudService, "cloudService must not be null"); - } - - @Override - public Map<?, ListenableFuture<Void>> execute(final String group, int count, Template template, - Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes, - Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { - // Get the zone where the template will be deployed - Integer locationId = Integer.valueOf(template.getHardware().getLocation().getId()); - VirtualDatacenter vdc = cloudService.getVirtualDatacenter(locationId); - - // Check if it already exists a group with the given name - Iterable<VirtualAppliance> existingGroups = vdc.listVirtualAppliances(); - Optional<VirtualAppliance> vapp = tryFind(existingGroups, new Predicate<VirtualAppliance>() { - @Override - public boolean apply(VirtualAppliance input) { - return input.getName().equals(group); - } - }); - - // Create the group if still does not exist - VirtualAppliance newVapp = null; - if (!vapp.isPresent()) { - logger.debug(">> Creating group %s", group); - newVapp = VirtualAppliance.builder(context, vdc).name(group).build(); - newVapp.save(); - logger.debug("<< group(%s) created", newVapp.getId()); - } else { - logger.debug(">> Using existing group(%s)", vapp.get().getId()); - } - - VirtualApplianceCachingTemplate abiquoTemplate = VirtualApplianceCachingTemplate // - .from(template) // - .withVirtualDatacenter(vdc) // - .withVirtualAppliance(vapp.or(newVapp)) // - .build(); - - return super.execute(group, count, abiquoTemplate, goodNodes, badNodes, customizationResponses); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/FindCompatibleVirtualDatacenters.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/FindCompatibleVirtualDatacenters.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/FindCompatibleVirtualDatacenters.java deleted file mode 100644 index 10896b9..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/FindCompatibleVirtualDatacenters.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.strategy; - -import org.jclouds.abiquo.compute.strategy.internal.FindCompatibleVirtualDatacentersForImageAndConversions; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; - -import com.google.inject.ImplementedBy; - -/** - * Finds all virtual datacenters where the given {@link VirtualMachineTemplate} - * can be deployed. - */ -@ImplementedBy(FindCompatibleVirtualDatacentersForImageAndConversions.class) -public interface FindCompatibleVirtualDatacenters { - Iterable<VirtualDatacenter> execute(VirtualMachineTemplate template); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/VirtualApplianceCachingTemplate.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/VirtualApplianceCachingTemplate.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/VirtualApplianceCachingTemplate.java deleted file mode 100644 index 1d05756..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/VirtualApplianceCachingTemplate.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.strategy; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.abiquo.domain.cloud.VirtualAppliance; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.domain.Location; - -import com.google.common.base.Objects; - -/** - * A {@link Template} implementation that caches the {@link VirtualAppliance} - * and the {@link VirtualDatacenter} where the nodes will be deployed. - * <p> - * When deploying multiple nodes at the same time, all go to the same virtual - * appliance and virtual datacenter. Having both cached in the template saves a - * couple extra api calls for each deployed node. - * <p> - * This class is not public as it is intended to be used internally. - * - * - * @see CreateGroupBeforeCreatingNodes - * @see AbiquoComputeServiceAdapter - */ -class VirtualApplianceCachingTemplate implements Template { - - private final Template delegate; - private final VirtualDatacenter virtualDatacenter; - private final VirtualAppliance virtualAppliance; - - private VirtualApplianceCachingTemplate(Template delegate, VirtualDatacenter virtualDatacenter, - VirtualAppliance virtualAppliance) { - this.delegate = checkNotNull(delegate, "delegate"); - this.virtualDatacenter = checkNotNull(virtualDatacenter, "virtualDatacenter"); - this.virtualAppliance = checkNotNull(virtualAppliance, "virtualAppliance"); - } - - public VirtualDatacenter getVirtualDatacenter() { - return virtualDatacenter; - } - - public VirtualAppliance getVirtualAppliance() { - return virtualAppliance; - } - - // Delegate methods - - @Override - public Image getImage() { - return delegate.getImage(); - } - - @Override - public Hardware getHardware() { - return delegate.getHardware(); - } - - @Override - public Location getLocation() { - return delegate.getLocation(); - } - - @Override - public TemplateOptions getOptions() { - return delegate.getOptions(); - } - - @Override - public VirtualApplianceCachingTemplate clone() { - return new VirtualApplianceCachingTemplate(delegate.clone(), virtualDatacenter, virtualAppliance); - } - - @Override - public String toString() { - return delegate.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - VirtualApplianceCachingTemplate that = VirtualApplianceCachingTemplate.class.cast(o); - return delegate.equals(that) && virtualAppliance.getId().equals(that.virtualAppliance.getId()) - && virtualDatacenter.getId().equals(that.virtualDatacenter.getId()); - } - - @Override - public int hashCode() { - return Objects.hashCode(getImage(), getHardware(), getLocation(), getOptions(), virtualDatacenter, - virtualAppliance); - } - - static Builder from(Template template) { - return new Builder(template); - } - - static class Builder { - private Template template; - private VirtualDatacenter virtualDatacenter; - private VirtualAppliance virtualAppliance; - - public Builder(Template template) { - this.template = template; - } - - public Builder withVirtualDatacenter(VirtualDatacenter virtualDatacenter) { - this.virtualDatacenter = virtualDatacenter; - return this; - } - - public Builder withVirtualAppliance(VirtualAppliance virtualAppliance) { - this.virtualAppliance = virtualAppliance; - return this; - } - - public VirtualApplianceCachingTemplate build() { - return new VirtualApplianceCachingTemplate(template, virtualDatacenter, virtualAppliance); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageAndConversions.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageAndConversions.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageAndConversions.java deleted file mode 100644 index 656b711..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageAndConversions.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; -import static org.jclouds.abiquo.predicates.VirtualDatacenterPredicates.compatibleWithTemplateOrConversions; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.compute.strategy.FindCompatibleVirtualDatacenters; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.features.services.CloudService; -import org.jclouds.abiquo.predicates.VirtualDatacenterPredicates; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.infrastructure.DatacenterDto; - -/** - * Default implementation for the {@link FindCompatibleVirtualDatacenters} - * strategy. - * <p> - * This strategy assumes that the datacenter will have different hypervisor - * technologies, and images will have conversions to each of them. - */ -@Singleton -public class FindCompatibleVirtualDatacentersForImageAndConversions implements FindCompatibleVirtualDatacenters { - private final ApiContext<AbiquoApi> context; - - private final CloudService cloudService; - - @Inject - public FindCompatibleVirtualDatacentersForImageAndConversions(final ApiContext<AbiquoApi> context, - final CloudService cloudService) { - this.context = checkNotNull(context, "context"); - this.cloudService = checkNotNull(cloudService, "cloudService"); - } - - @Override - public Iterable<VirtualDatacenter> execute(final VirtualMachineTemplate template) { - // Build the transport object with the available information to avoid - // making an unnecessary call to the target API (we only need the id of - // the datacenter, and it is present in the link). - DatacenterDto datacenterDto = new DatacenterDto(); - datacenterDto.setId(template.unwrap().getIdFromLink(ParentLinkName.DATACENTER_REPOSITORY)); - Datacenter datacenter = wrap(context, Datacenter.class, datacenterDto); - - Iterable<VirtualDatacenter> vdcs = filter(cloudService.listVirtualDatacenters(), - VirtualDatacenterPredicates.datacenter(datacenter)); - - return filter(vdcs, compatibleWithTemplateOrConversions(template)); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageBaseFormat.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageBaseFormat.java b/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageBaseFormat.java deleted file mode 100644 index fa3e743..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/compute/strategy/internal/FindCompatibleVirtualDatacentersForImageBaseFormat.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.compute.strategy.FindCompatibleVirtualDatacenters; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.features.services.CloudService; -import org.jclouds.abiquo.predicates.VirtualDatacenterPredicates; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.enumerator.HypervisorType; -import com.abiquo.server.core.infrastructure.DatacenterDto; -import com.google.common.base.Predicate; - -/** - * Implementation for the {@link FindCompatibleVirtualDatacenters} strategy to - * be used in homogeneous datacenters. - * <p> - * For providers that only have one hypervisor technology in the physical - * datacenter and use compatible images, there is no need to check if the images - * have conversions to other formats. - * <p> - * This strategy will only consider the base disk format of the image. - */ -@Singleton -public class FindCompatibleVirtualDatacentersForImageBaseFormat implements FindCompatibleVirtualDatacenters { - private final ApiContext<AbiquoApi> context; - - private final CloudService cloudService; - - @Inject - public FindCompatibleVirtualDatacentersForImageBaseFormat(final ApiContext<AbiquoApi> context, - final CloudService cloudService) { - this.context = checkNotNull(context, "context"); - this.cloudService = checkNotNull(cloudService, "cloudService"); - } - - @Override - public Iterable<VirtualDatacenter> execute(final VirtualMachineTemplate template) { - // Build the transport object with the available information to avoid - // making an unnecessary call to the target API (we only need the id of - // the datacenter, and it is present in the link). - DatacenterDto datacenterDto = new DatacenterDto(); - datacenterDto.setId(template.unwrap().getIdFromLink(ParentLinkName.DATACENTER_REPOSITORY)); - Datacenter datacenter = wrap(context, Datacenter.class, datacenterDto); - - Iterable<VirtualDatacenter> vdcs = filter(cloudService.listVirtualDatacenters(), - VirtualDatacenterPredicates.datacenter(datacenter)); - - return filter(vdcs, new Predicate<VirtualDatacenter>() { - @Override - public boolean apply(final VirtualDatacenter vdc) { - HypervisorType type = vdc.getHypervisorType(); - return type.isCompatible(template.getDiskFormatType()); - } - }); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoHttpApiModule.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoHttpApiModule.java b/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoHttpApiModule.java index f64f09b..583e0db 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoHttpApiModule.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoHttpApiModule.java @@ -16,37 +16,14 @@ */ package org.jclouds.abiquo.config; -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; - -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import javax.inject.Named; - import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.enterprise.User; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; import org.jclouds.abiquo.handlers.AbiquoErrorHandler; -import org.jclouds.collect.Memoized; import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; -import org.jclouds.rest.ApiContext; -import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ConfiguresHttpApi; import org.jclouds.rest.config.HttpApiModule; -import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import com.google.common.collect.Maps; -import com.google.inject.Provides; -import com.google.inject.Singleton; /** * Configures the Abiquo connection. @@ -60,61 +37,4 @@ public class AbiquoHttpApiModule extends HttpApiModule<AbiquoApi> { bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(AbiquoErrorHandler.class); bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(AbiquoErrorHandler.class); } - - @Provides - @Singleton - @Memoized - public Supplier<User> getCurrentUser(final AtomicReference<AuthorizationException> authException, - @Named(PROPERTY_SESSION_INTERVAL) final long seconds, final ApiContext<AbiquoApi> context) { - return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, new Supplier<User>() { - @Override - public User get() { - return wrap(context, User.class, context.getApi().getAdminApi().getCurrentUser()); - } - }, seconds, TimeUnit.SECONDS); - } - - @Provides - @Singleton - @Memoized - public Supplier<Enterprise> getCurrentEnterprise(final AtomicReference<AuthorizationException> authException, - @Named(PROPERTY_SESSION_INTERVAL) final long seconds, @Memoized final Supplier<User> currentUser) { - return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, - new Supplier<Enterprise>() { - @Override - public Enterprise get() { - return currentUser.get().getEnterprise(); - } - }, seconds, TimeUnit.SECONDS); - } - - @Provides - @Singleton - @Memoized - public Supplier<Map<Integer, Datacenter>> getAvailableRegionsIndexedById( - final AtomicReference<AuthorizationException> authException, - @Named(PROPERTY_SESSION_INTERVAL) final long seconds, @Memoized final Supplier<Enterprise> currentEnterprise) { - Supplier<Map<Integer, Datacenter>> availableRegionsMapSupplier = Suppliers.compose( - new Function<Iterable<Datacenter>, Map<Integer, Datacenter>>() { - @Override - public Map<Integer, Datacenter> apply(final Iterable<Datacenter> datacenters) { - // Index available regions by id - return Maps.uniqueIndex(datacenters, new Function<Datacenter, Integer>() { - @Override - public Integer apply(final Datacenter input) { - return input.getId(); - } - }); - } - }, new Supplier<Iterable<Datacenter>>() { - @Override - public Iterable<Datacenter> get() { - // Get the list of regions available for the user's tenant - return currentEnterprise.get().listAllowedDatacenters(); - } - }); - - return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, - availableRegionsMapSupplier, seconds, TimeUnit.SECONDS); - } } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoProperties.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoProperties.java b/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoProperties.java index 35b39c1..44dff3d 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoProperties.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoProperties.java @@ -28,15 +28,6 @@ public final class AbiquoProperties { public static final String CREDENTIAL_TYPE = "abiquo.credential-type"; /** - * The delay (in ms) used between requests by the - * <code>MonitoringService<code> - * when monitoring asynchronous task state. - * <p> - * Default value: 5000 ms - */ - public static final String ASYNC_TASK_MONITOR_DELAY = "abiquo.monitor-delay"; - - /** * The name of the Abiquo logger. */ public static final String ABIQUO_LOGGER = "jclouds.abiquo"; http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithLimitsWrapper.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithLimitsWrapper.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithLimitsWrapper.java deleted file mode 100644 index b0172ed..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithLimitsWrapper.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.domain; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.transport.SingleResourceWithLimitsDto; - -/** - * This class is used to decorate transport objects that have limits with high - * level functionality. - */ -public abstract class DomainWithLimitsWrapper<T extends SingleResourceWithLimitsDto> extends DomainWrapper<T> { - - protected DomainWithLimitsWrapper(final ApiContext<AbiquoApi> context, final T target) { - super(context, target); - } - - // Delegate methods - - public int getCpuCountHardLimit() { - return target.getCpuCountHardLimit(); - } - - public int getCpuCountSoftLimit() { - return target.getCpuCountSoftLimit(); - } - - public long getHdHardLimitInBytes() { - // Due to a bug in Abiquo, the hard drive limits are interpreted as bytes, - // though the name of the method makes reference to Mb - return target.getHdHardLimitInMb(); - } - - public long getHdSoftLimitInBytes() { - // Due to a bug in Abiquo, the hard drive limits are interpreted as bytes, - // though the name of the method makes reference to Mb - return target.getHdSoftLimitInMb(); - } - - public long getPublicIpsHard() { - return target.getPublicIpsHard(); - } - - public long getPublicIpsSoft() { - return target.getPublicIpsSoft(); - } - - public int getRamHardLimitInMb() { - return target.getRamHardLimitInMb(); - } - - public int getRamSoftLimitInMb() { - return target.getRamSoftLimitInMb(); - } - - public long getStorageHard() { - return target.getStorageHard(); - } - - public long getStorageSoft() { - return target.getStorageSoft(); - } - - public long getVlansHard() { - return target.getVlansHard(); - } - - public long getVlansSoft() { - return target.getVlansSoft(); - } - - public void setCpuCountHardLimit(final int cpuCountHardLimit) { - target.setCpuCountHardLimit(cpuCountHardLimit); - } - - public void setCpuCountLimits(final int softLimit, final int hardLimit) { - target.setCpuCountLimits(softLimit, hardLimit); - } - - public void setCpuCountSoftLimit(final int cpuCountSoftLimit) { - target.setCpuCountSoftLimit(cpuCountSoftLimit); - } - - public void setHdHardLimitInBytes(final long hdHardLimit) { - // Due to a bug in Abiquo, the hard drive limits are interpreted as bytes, - // though the name of the method makes reference to Mb - target.setHdHardLimitInMb(hdHardLimit); - } - - public void setHdLimitsInBytes(final long softLimit, final long hardLimit) { - // Due to a bug in Abiquo, the hard drive limits are interpreted as bytes, - // though the name of the method makes reference to Mb - target.setHdLimitsInMb(softLimit, hardLimit); - } - - public void setHdSoftLimitInBytes(final long hdSoftLimit) { - // Due to a bug in Abiquo, the hard drive limits are interpreted as bytes, - // though the name of the method makes reference to Mb - target.setHdSoftLimitInMb(hdSoftLimit); - } - - public void setPublicIPLimits(final long softLimit, final long hardLimit) { - target.setPublicIPLimits(softLimit, hardLimit); - } - - public void setPublicIpsHard(final long publicIpsHard) { - target.setPublicIpsHard(publicIpsHard); - } - - public void setPublicIpsSoft(final long publicIpsSoft) { - target.setPublicIpsSoft(publicIpsSoft); - } - - public void setRamHardLimitInMb(final int ramHardLimitInMb) { - target.setRamHardLimitInMb(ramHardLimitInMb); - } - - public void setRamLimitsInMb(final int softLimit, final int hardLimit) { - target.setRamLimitsInMb(softLimit, hardLimit); - } - - public void setRamSoftLimitInMb(final int ramSoftLimitInMb) { - target.setRamSoftLimitInMb(ramSoftLimitInMb); - } - - public void setStorageHard(final long storageHard) { - target.setStorageHard(storageHard); - } - - public void setStorageLimits(final long softLimit, final long hardLimit) { - target.setStorageLimits(softLimit, hardLimit); - } - - public void setStorageSoft(final long storageSoft) { - target.setStorageSoft(storageSoft); - } - - public void setVlansHard(final long vlansHard) { - target.setVlansHard(vlansHard); - } - - public void setVlansLimits(final long softLimit, final long hardLimit) { - target.setVlansLimits(softLimit, hardLimit); - } - - public void setVlansSoft(final long vlansSoft) { - target.setVlansSoft(vlansSoft); - } -}
