http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java deleted file mode 100644 index 55ab1ad..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWithTasksWrapper.java +++ /dev/null @@ -1,60 +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 java.util.Collections; -import java.util.List; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.task.AsyncTask; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.transport.SingleResourceTransportDto; -import com.abiquo.server.core.task.TaskDto; -import com.abiquo.server.core.task.TasksDto; -import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; -import com.google.common.primitives.Longs; - -/** - * This class is used to decorate transport objects that are owners of some - * {@link TaskDto} - */ -public abstract class DomainWithTasksWrapper<T extends SingleResourceTransportDto> extends DomainWrapper<T> { - - protected DomainWithTasksWrapper(final ApiContext<AbiquoApi> context, final T target) { - super(context, target); - } - - public Iterable<AsyncTask<?, ?>> listTasks() { - TasksDto result = context.getApi().getTaskApi().listTasks(target); - List<AsyncTask<?, ?>> tasks = Lists.newArrayList(); - for (TaskDto dto : result.getCollection()) { - tasks.add(newTask(context, dto)); - } - - // Return the most recent task first - Collections.sort(tasks, new Ordering<AsyncTask<?, ?>>() { - @Override - public int compare(final AsyncTask<?, ?> left, final AsyncTask<?, ?> right) { - return Longs.compare(left.getTimestamp(), right.getTimestamp()); - } - }.reverse()); - - return tasks; - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java deleted file mode 100644 index 908edcc..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java +++ /dev/null @@ -1,279 +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 static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.transform; -import static org.jclouds.reflect.Reflection2.constructor; - -import java.lang.reflect.InvocationTargetException; -import java.net.URI; -import java.util.Collection; -import java.util.List; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.exception.WrapperException; -import org.jclouds.abiquo.domain.task.AsyncTask; -import org.jclouds.abiquo.domain.task.ConversionTask; -import org.jclouds.abiquo.domain.task.VirtualMachineTask; -import org.jclouds.abiquo.domain.task.VirtualMachineTemplateTask; -import org.jclouds.abiquo.domain.util.LinkUtils; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseXMLWithJAXB; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.model.transport.AcceptedRequestDto; -import com.abiquo.model.transport.SingleResourceTransportDto; -import com.abiquo.model.transport.WrapperDto; -import com.abiquo.server.core.task.TaskDto; -import com.abiquo.server.core.task.enums.TaskType; -import com.google.common.base.Function; -import com.google.common.collect.Lists; -import com.google.common.reflect.Invokable; -import com.google.inject.TypeLiteral; - -/** - * This class is used to decorate transport objects with high level - * functionality. - */ -public abstract class DomainWrapper<T extends SingleResourceTransportDto> { - /** The rest context. */ - protected ApiContext<AbiquoApi> context; - - /** The wrapped object. */ - protected T target; - - protected DomainWrapper(final ApiContext<AbiquoApi> context, final T target) { - super(); - this.context = checkNotNull(context, "context"); - this.target = checkNotNull(target, "target"); - } - - /** - * Returns the URI that identifies the transport object - * - * @return The URI identifying the transport object - */ - public URI getURI() { - RESTLink link = LinkUtils.getSelfLink(target); - return link == null ? null : URI.create(link.getHref()); - } - - /** - * Returns the wrapped object. - */ - public T unwrap() { - return target; - } - - /** - * Refresh the state of the current object. - */ - @SuppressWarnings("unchecked") - public void refresh() { - RESTLink link = checkNotNull(LinkUtils.getSelfLink(target), ValidationErrors.MISSING_REQUIRED_LINK + " edit/self"); - - HttpResponse response = context.getApi().get(link); - - ParseXMLWithJAXB<T> parser = new ParseXMLWithJAXB<T>(context.utils().xml(), TypeLiteral.get((Class<T>) target - .getClass())); - - target = parser.apply(response); - } - - /** - * Read the ID of the parent resource from the given link. - * - * @param parentLinkRel - * The link to the parent resource. - * @return The ID of the parent resource. - */ - protected Integer getParentId(final String parentLinkRel) { - return target.getIdFromLink(parentLinkRel); - } - - /** - * Wraps an object in the given wrapper class. - */ - public static <T extends SingleResourceTransportDto, W extends DomainWrapper<T>> W wrap( - final ApiContext<AbiquoApi> context, final Class<W> wrapperClass, @Nullable final T target) { - if (target == null) { - return null; - } - - try { - Invokable<W, W> cons = constructor(wrapperClass, ApiContext.class, target.getClass()); - return cons.invoke(null, context, target); - } catch (InvocationTargetException e) { - throw new WrapperException(wrapperClass, target, e.getTargetException()); - } catch (IllegalAccessException e) { - throw new WrapperException(wrapperClass, target, e); - } - } - - /** - * Wrap a collection of objects to the given wrapper class. - */ - public static <T extends SingleResourceTransportDto, W extends DomainWrapper<T>> Iterable<W> wrap( - final ApiContext<AbiquoApi> context, final Class<W> wrapperClass, @Nullable final Iterable<T> targets) { - if (targets == null) { - return null; - } - - return transform(targets, new Function<T, W>() { - @Override - public W apply(final T input) { - return wrap(context, wrapperClass, input); - } - }); - } - - /** - * Unwrap a collection of objects. - */ - public static <T extends SingleResourceTransportDto, W extends DomainWrapper<T>> Iterable<T> unwrap( - final Iterable<W> targets) { - return transform(targets, new Function<W, T>() { - @Override - public T apply(final W input) { - return input.unwrap(); - } - }); - } - - /** - * Update or creates a link of "target" with the uri of a link from "source". - */ - protected <T1 extends SingleResourceTransportDto, T2 extends SingleResourceTransportDto> void updateLink( - final T1 target, final String targetLinkRel, final T2 source, final String sourceLinkRel) { - RESTLink parent = null; - - checkNotNull(source.searchLink(sourceLinkRel), ValidationErrors.MISSING_REQUIRED_LINK); - - // Insert - if ((parent = target.searchLink(targetLinkRel)) == null) { - target.addLink(new RESTLink(targetLinkRel, source.searchLink(sourceLinkRel).getHref())); - } - // Replace - else { - parent.setHref(source.searchLink(sourceLinkRel).getHref()); - } - } - - /** - * Join a collection of {@link WrapperDto} objects in a single collection - * with all the elements of each wrapper object. - */ - public static <T extends SingleResourceTransportDto> Iterable<T> join( - final Iterable<? extends WrapperDto<T>> collection) { - return concat(transform(collection, new Function<WrapperDto<T>, Collection<T>>() { - @Override - public Collection<T> apply(WrapperDto<T> input) { - return input.getCollection(); - } - })); - } - - /** - * Utility method to get an {@link AsyncTask} given an - * {@link AcceptedRequestDto}. - * - * @param acceptedRequest - * The accepted request dto. - * @return The async task. - */ - protected AsyncTask<?, ?> getTask(final AcceptedRequestDto<String> acceptedRequest) { - RESTLink taskLink = acceptedRequest.getStatusLink(); - checkNotNull(taskLink, ValidationErrors.MISSING_REQUIRED_LINK + AsyncTask.class); - - // This will return null on untrackable tasks - TaskDto dto = context.getApi().getTaskApi().getTask(taskLink); - return newTask(context, dto); - } - - /** - * Utility method to get all {@link AsyncTask} related to an - * {@link AcceptedRequestDto}. - * - * @param acceptedRequest - * The accepted request dto. - * @return The async task array. - */ - protected AsyncTask<?, ?>[] getTasks(final AcceptedRequestDto<String> acceptedRequest) { - List<AsyncTask<?, ?>> tasks = Lists.newArrayList(); - - for (RESTLink link : acceptedRequest.getLinks()) { - // This will return null on untrackable tasks - TaskDto dto = context.getApi().getTaskApi().getTask(link); - if (dto != null) { - tasks.add(newTask(context, dto)); - } - } - - AsyncTask<?, ?>[] taskArr = new AsyncTask<?, ?>[tasks.size()]; - return tasks.toArray(taskArr); - } - - /** - * Creates a new {@link AsyncTask} for the given {@link TaskDto} and the - * given result class. - * - * @param context - * The API context. - * @param dto - * The dto used to generate the domain object. - * @return The task domain object. - */ - protected static AsyncTask<?, ?> newTask(final ApiContext<AbiquoApi> context, final TaskDto dto) { - // Can be null in untrackable tasks - if (dto == null) { - return null; - } - - Class<? extends AsyncTask<?, ?>> taskClass = null; - - switch (dto.getType().getOwnerType()) { - case CONVERSION: - taskClass = ConversionTask.class; - break; - case VIRTUAL_MACHINE_TEMPLATE: - taskClass = VirtualMachineTemplateTask.class; - break; - case VIRTUAL_MACHINE: - // A VirtualMachine task can generate a template (if task is an - // instance) - taskClass = dto.getType() == TaskType.INSTANCE || dto.getType() == TaskType.INSTANCE_PERSISTENT ? VirtualMachineTemplateTask.class - : VirtualMachineTask.class; - break; - } - - try { - Invokable<? extends AsyncTask<?, ?>, ? extends AsyncTask<?, ?>> cons = constructor(taskClass, - ApiContext.class, dto.getClass()); - return cons.invoke(null, context, dto); - } catch (InvocationTargetException e) { - throw new WrapperException(taskClass, dto, e.getTargetException()); - } catch (IllegalAccessException e) { - throw new WrapperException(taskClass, dto, e); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/PaginatedCollection.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/PaginatedCollection.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/PaginatedCollection.java deleted file mode 100644 index ddf3933..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/PaginatedCollection.java +++ /dev/null @@ -1,158 +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 static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.collect.PagedIterables.advance; -import static org.jclouds.collect.PagedIterables.onlyPage; - -import java.util.Iterator; -import java.util.List; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; -import org.jclouds.http.functions.ParseXMLWithJAXB; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.model.transport.WrapperDto; -import com.google.common.base.Function; -import com.google.common.base.Optional; - -/** - * This class represents a collection that is paginated. - * <p> - * Contains a single page of the collection, and all the information needed to - * fetch the next page on demand. - * - * - * @see PagedIterable - */ -public class PaginatedCollection<T, W extends WrapperDto<T>> extends IterableWithMarker<T> { - protected final AbiquoApi api; - protected final W delegate; - protected final ParseXMLWithJAXB<W> parser; - - public PaginatedCollection(AbiquoApi api, W delegate, ParseXMLWithJAXB<W> parser) { - this.api = checkNotNull(api, "api must not be null"); - this.delegate = checkNotNull(delegate, "delegate must not be null"); - this.parser = checkNotNull(parser, "parser must not be null"); - } - - @Override - public Iterator<T> iterator() { - return delegate.getCollection().iterator(); - } - - @Override - public Optional<Object> nextMarker() { - return Optional.<Object> fromNullable(delegate.searchLink("next")); - } - - /** - * Transforms this {@link PaginatedCollection} into a {@link PagedIterable} - * so next the pages can be easily fetched. - * - * @return A PagedIterable that is capable of fetching more pages. - */ - public PagedIterable<T> toPagedIterable() { - return new ToPagedIterable<T, W>(api, parser).apply(this); - } - - /** - * Returns a function that transforms the PaginatedCollection into a - * {@link PagedIterable}. - * <p> - * The PagedIterable will fetch the next pages based on the <code>next</code> - * link of the current object. - * <p> - * Subclasses may overwrite this one, to provide a concrete type for the - * parser parameter, so this function can be injected in the different api - * methods and be used as a transformer for the returned collection. - * - */ - public static class ToPagedIterable<T, W extends WrapperDto<T>> implements - Function<PaginatedCollection<T, W>, PagedIterable<T>> { - protected final AbiquoApi api; - protected final ParseXMLWithJAXB<W> parser; - - public ToPagedIterable(AbiquoApi api, ParseXMLWithJAXB<W> parser) { - this.api = checkNotNull(api, "api must not be null"); - this.parser = checkNotNull(parser, "parser must not be null"); - } - - @Override - public PagedIterable<T> apply(final PaginatedCollection<T, W> input) { - return input.nextMarker().isPresent() ? advance(input, nextPage(input)) : onlyPage(input); - } - - protected Function<Object, IterableWithMarker<T>> nextPage(final PaginatedCollection<T, W> input) { - return new Function<Object, IterableWithMarker<T>>() { - @Override - public IterableWithMarker<T> apply(Object marker) { - checkArgument(marker instanceof RESTLink, "Marker must be a RESTLink"); - RESTLink next = RESTLink.class.cast(marker); - - // The Abiquo API does not provide the media types in the - // pagination links, but it will be the same type than the - // current page, so just set it. - next.setType(input.delegate.getMediaType()); - - W nextPage = parser.apply(api.get(next)); - return new PaginatedCollection<T, W>(api, nextPage, parser); - } - }; - } - - } - - // Delegate methods - - public Integer getTotalSize() { - return delegate.getTotalSize(); - } - - public List<RESTLink> getLinks() { - return delegate.getLinks(); - } - - public RESTLink searchLink(String rel) { - return delegate.searchLink(rel); - } - - public List<RESTLink> searchLinks(String rel) { - return delegate.searchLinks(rel); - } - - public RESTLink searchLink(String rel, String title) { - return delegate.searchLink(rel, title); - } - - public RESTLink searchLinkByHref(String href) { - return delegate.searchLinkByHref(href); - } - - public Integer getIdFromLink(String rel) { - return delegate.getIdFromLink(rel); - } - - public String getMediaType() { - return delegate.getMediaType(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/builder/LimitsBuilder.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/builder/LimitsBuilder.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/builder/LimitsBuilder.java deleted file mode 100644 index 7b11d3c..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/builder/LimitsBuilder.java +++ /dev/null @@ -1,94 +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.builder; - -/** - * Base class for all builders that represent limits. - * - * @param <T> - * The type of the target builder. - */ -public abstract class LimitsBuilder<T extends LimitsBuilder<T>> { - /** The default limits for enterprises (unlimited). */ - protected static final int DEFAULT_LIMITS = 0; - - protected Integer ramSoftLimitInMb = DEFAULT_LIMITS; - - protected Integer ramHardLimitInMb = DEFAULT_LIMITS; - - protected Integer cpuCountSoftLimit = DEFAULT_LIMITS; - - protected Integer cpuCountHardLimit = DEFAULT_LIMITS; - - protected Long hdSoftLimitInMb = Long.valueOf(DEFAULT_LIMITS); - - protected Long hdHardLimitInMb = Long.valueOf(DEFAULT_LIMITS); - - protected Long storageSoft = Long.valueOf(DEFAULT_LIMITS); - - protected Long storageHard = Long.valueOf(DEFAULT_LIMITS); - - protected Long vlansSoft = Long.valueOf(DEFAULT_LIMITS); - - protected Long vlansHard = Long.valueOf(DEFAULT_LIMITS); - - protected Long publicIpsSoft = Long.valueOf(DEFAULT_LIMITS); - - protected Long publicIpsHard = Long.valueOf(DEFAULT_LIMITS); - - @SuppressWarnings("unchecked") - public T ramLimits(final int soft, final int hard) { - this.ramSoftLimitInMb = soft; - this.ramHardLimitInMb = hard; - return (T) this; - } - - @SuppressWarnings("unchecked") - public T cpuCountLimits(final int soft, final int hard) { - this.cpuCountSoftLimit = soft; - this.cpuCountHardLimit = hard; - return (T) this; - } - - @SuppressWarnings("unchecked") - public T hdLimitsInMb(final long soft, final long hard) { - this.hdSoftLimitInMb = soft; - this.hdHardLimitInMb = hard; - return (T) this; - } - - @SuppressWarnings("unchecked") - public T storageLimits(final long soft, final long hard) { - this.storageSoft = soft; - this.storageHard = hard; - return (T) this; - } - - @SuppressWarnings("unchecked") - public T vlansLimits(final long soft, final long hard) { - this.vlansSoft = soft; - this.vlansHard = hard; - return (T) this; - } - - @SuppressWarnings("unchecked") - public T publicIpsLimits(final long soft, final long hard) { - this.publicIpsSoft = soft; - this.publicIpsHard = hard; - return (T) this; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java deleted file mode 100644 index 73abdd4..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java +++ /dev/null @@ -1,123 +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.cloud; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Date; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWithTasksWrapper; -import org.jclouds.abiquo.domain.task.ConversionTask; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseXMLWithJAXB; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.enumerator.ConversionState; -import com.abiquo.model.enumerator.DiskFormatType; -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.appslibrary.ConversionDto; -import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; -import com.google.inject.TypeLiteral; - -/** - * Adds high level functionality to {@link ConversionDto}. - * - * @see API: <a - * href="http://community.abiquo.com/display/ABI20/Conversion+Resource"> - * http://community.abiquo.com/display/ABI20/Conversion+Resource</a> - */ -public class Conversion extends DomainWithTasksWrapper<ConversionDto> { - /** - * Constructor to be used only by the builder. - */ - protected Conversion(final ApiContext<AbiquoApi> context, final ConversionDto target) { - super(context, target); - } - - // Parent access - - /** - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Machine+Template+Resource" - * > http://community.abiquo.com/display/ABI20/Virtual+Machine+Template+ - * Resource</a> - */ - public VirtualMachineTemplate getVirtualMachineTemplate() { - RESTLink link = checkNotNull(target.searchLink(ParentLinkName.VIRTUAL_MACHINE_TEMPLATE), - ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.VIRTUAL_MACHINE_TEMPLATE); - - HttpResponse response = context.getApi().get(link); - - ParseXMLWithJAXB<VirtualMachineTemplateDto> parser = new ParseXMLWithJAXB<VirtualMachineTemplateDto>( - context.utils().xml(), TypeLiteral.get(VirtualMachineTemplateDto.class)); - - return wrap(context, VirtualMachineTemplate.class, parser.apply(response)); - } - - /** - * Starts a new BPM task to regenerate a failed conversion. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Conversion+Resource#ConversionResource-UpdateConversion" - * > http://community.abiquo.com/display/ABI20/Conversion+Resource# - * ConversionResource- UpdateConversion</a> - * @return The task reference to track its progress - */ - public ConversionTask restartFailedConversion() { - return getVirtualMachineTemplate().requestConversion(getTargetFormat()); - } - - // Delegate methods - - public String getSourcePath() { - return target.getSourcePath(); - } - - public ConversionState getState() { - return target.getState(); - } - - public String getTargetPath() { - return target.getTargetPath(); - } - - public Long getTargetSizeInBytes() { - return target.getTargetSizeInBytes(); - } - - public DiskFormatType getSourceFormat() { - return target.getSourceFormat(); - } - - public DiskFormatType getTargetFormat() { - return target.getTargetFormat(); - } - - public Date getStartTimestamp() { - return target.getStartTimestamp(); - } - - @Override - public String toString() { - return "Conversion [sourcePath=" + getSourcePath() + ", sourceFormat=" + getSourceFormat() + ", targetPath=" - + getTargetPath() + ", targetFormat=" + getTargetFormat() + ", targetSizeInBytes=" + getTargetSizeInBytes() - + ", startTimestamp=" + getStartTimestamp() + ", state=" + getState() + "]"; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/HardDisk.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/HardDisk.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/HardDisk.java deleted file mode 100644 index b08b850..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/HardDisk.java +++ /dev/null @@ -1,158 +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.cloud; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.cloud.VirtualDatacenterDto; -import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; - -/** - * Represents a disk attached to a virtual machine. - * <p> - * This disks will be created when a virtual machine is deployed, and will be - * destroyed when it is undeployed. If there is a need to use persistent - * storage, a persistent {@link Volume} should be used instead. - * - * @see API: <a - * href="http://community.abiquo.com/display/ABI20/Hard+Disks+Resource"> - * http://community.abiquo.com/display/ABI20/Hard+Disks+Resource</a> - */ -public class HardDisk extends DomainWrapper<DiskManagementDto> { - /** The virtual datacenter where the hard disk belongs. */ - private VirtualDatacenter virtualDatacenter; - - /** - * Constructor to be used only by the builder. - */ - protected HardDisk(final ApiContext<AbiquoApi> context, final DiskManagementDto target) { - super(context, target); - } - - // Domain operations - - /** - * Creates the hard disk in the selected virtual datacenter. - * <p> - * Once the hard disk has been created it can be attached to a virtual - * machine of the virtual datacenter. - */ - public void save() { - target = context.getApi().getCloudApi().createHardDisk(virtualDatacenter.unwrap(), target); - } - - /** - * Deletes the hard disk. - */ - public void delete() { - context.getApi().getCloudApi().deleteHardDisk(target); - target = null; - } - - // Parent access - - /** - * Gets the virtual datacenter where the hard disk belongs to. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-RetrieveaVirtualDatacenter" - * > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# VirtualDatacenterResource-RetrieveaVirtualDatacenter</a> - */ - public VirtualDatacenter getVirtualDatacenter() { - Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER); - VirtualDatacenterDto dto = context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId); - virtualDatacenter = wrap(context, VirtualDatacenter.class, dto); - return virtualDatacenter; - } - - // Builder - - public static Builder builder(final ApiContext<AbiquoApi> context, final VirtualDatacenter virtualDatacenter) { - return new Builder(context, virtualDatacenter); - } - - public static class Builder { - private ApiContext<AbiquoApi> context; - - private Long sizeInMb; - - private VirtualDatacenter virtualDatacenter; - - public Builder(final ApiContext<AbiquoApi> context, final VirtualDatacenter virtualDatacenter) { - super(); - checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + VirtualDatacenter.class); - this.context = context; - this.virtualDatacenter = virtualDatacenter; - } - - public Builder sizeInMb(final long sizeInMb) { - this.sizeInMb = sizeInMb; - return this; - } - - public HardDisk build() { - DiskManagementDto dto = new DiskManagementDto(); - dto.setSizeInMb(sizeInMb); - - HardDisk hardDisk = new HardDisk(context, dto); - hardDisk.virtualDatacenter = virtualDatacenter; - - return hardDisk; - } - } - - // Delegate methods. Since a hard disk cannot be edited, setters are not - // visible - - /** - * Returns the id of the hard disk. - */ - public Integer getId() { - // TODO: DiskManagementDto does not have an id field - return target.getEditLink() == null ? null : target.getIdFromLink("edit"); - } - - /** - * Returns the size of the hard disk in MB. - */ - public Long getSizeInMb() { - return target.getSizeInMb(); - } - - /** - * Returns the sequence number of the hard disk. - * <p> - * It will be computed when attaching the hard disk to a virtual machine and - * will determine the attachment order of the disk in the virtual machine. - */ - public Integer getSequence() { - return target.getSequence(); - } - - @Override - public String toString() { - return "HardDisk [id=" + getId() + ", sizeInMb=" + getSizeInMb() + ", sequence=" + getSequence() + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java deleted file mode 100644 index 92be637..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualAppliance.java +++ /dev/null @@ -1,344 +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.cloud; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Arrays; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.domain.PaginatedCollection; -import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.task.AsyncTask; -import org.jclouds.abiquo.domain.task.VirtualMachineTask; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.collect.PagedIterable; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.transport.AcceptedRequestDto; -import com.abiquo.server.core.cloud.VirtualApplianceDto; -import com.abiquo.server.core.cloud.VirtualApplianceState; -import com.abiquo.server.core.cloud.VirtualApplianceStateDto; -import com.abiquo.server.core.cloud.VirtualDatacenterDto; -import com.abiquo.server.core.cloud.VirtualMachineTaskDto; -import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; -import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; -import com.abiquo.server.core.enterprise.EnterpriseDto; - -/** - * Represents a virtual appliance. - * <p> - * A virtual appliance is a logic container for virtual machines that together - * make an appliance. - * - * @see API: <a - * href="http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource" - * > - * http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource</a> - */ -public class VirtualAppliance extends DomainWrapper<VirtualApplianceDto> { - /** The virtual datacenter where the virtual appliance belongs. */ - private VirtualDatacenter virtualDatacenter; - - /** - * Constructor to be used only by the builder. - */ - protected VirtualAppliance(final ApiContext<AbiquoApi> context, final VirtualApplianceDto target) { - super(context, target); - } - - // Domain operations - - /** - * Deletes the virtual appliance. - */ - public void delete() { - context.getApi().getCloudApi().deleteVirtualAppliance(target); - target = null; - } - - /** - * Creates the virtual appliance in the selected virtual datacenter. - */ - public void save() { - target = context.getApi().getCloudApi().createVirtualAppliance(virtualDatacenter.unwrap(), target); - } - - /** - * Updates the virtual appliance information when some of its properties have - * changed. - */ - public void update() { - target = context.getApi().getCloudApi().updateVirtualAppliance(target); - } - - // Parent access - - /** - * Gets the virtual datacenter where the virtual appliance belongs to. - * - * @return The virtual datacenter where the virtual appliance belongs to. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-RetrieveaVirtualDatacenter" - * > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# VirtualDatacenterResource-RetrieveaVirtualDatacenter</a> - */ - public VirtualDatacenter getVirtualDatacenter() { - Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER); - VirtualDatacenterDto dto = context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId); - virtualDatacenter = wrap(context, VirtualDatacenter.class, dto); - return virtualDatacenter; - } - - /** - * Gets the enterprise where the virtual appliance belongs to. - * - * @return The enterprise where the virtual appliance belongs to. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource-RetrieveaEnterprise" - * > http://community.abiquo.com/display/ABI20/Enterprise+Resource# - * EnterpriseResource- RetrieveaEnterprise</a> - */ - public Enterprise getEnterprise() { - Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE); - EnterpriseDto dto = context.getApi().getEnterpriseApi().getEnterprise(enterpriseId); - return wrap(context, Enterprise.class, dto); - } - - /** - * Gets the current state of the virtual appliance. - * - * @return The current state of the virtual appliance. - */ - public VirtualApplianceState getState() { - VirtualApplianceStateDto stateDto = context.getApi().getCloudApi().getVirtualApplianceState(target); - return stateDto.getPower(); - } - - // Children access - - /** - * Gets the list of virtual machines in the virtual appliance. - * - * @return The list of virtual machines in the virtual appliance. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource#VirtualMachineResource-RetrievethelistofVirtualMachines." - * > http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource# - * VirtualMachineResource -RetrievethelistofVirtualMachines.</a> - */ - public Iterable<VirtualMachine> listVirtualMachines() { - PagedIterable<VirtualMachineWithNodeExtendedDto> vms = context.getApi().getCloudApi().listVirtualMachines(target); - return wrap(context, VirtualMachine.class, vms.concat()); - } - - /** - * Gets the list of virtual machines in the virtual appliance. - * - * @return The list of virtual machines in the virtual appliance. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource#VirtualMachineResource-RetrievethelistofVirtualMachines." - * > http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource# - * VirtualMachineResource -RetrievethelistofVirtualMachines.</a> - */ - public Iterable<VirtualMachine> listVirtualMachines(final VirtualMachineOptions options) { - PaginatedCollection<VirtualMachineWithNodeExtendedDto, VirtualMachinesWithNodeExtendedDto> vms = context.getApi() - .getCloudApi().listVirtualMachines(target, options); - return wrap(context, VirtualMachine.class, vms.toPagedIterable().concat()); - } - - /** - * Gets a concrete virtual machine in the virtual appliance. - * - * @param id - * The id of the virtual machine. - * @return The requested virtual machine. - */ - public VirtualMachine getVirtualMachine(final Integer id) { - VirtualMachineWithNodeExtendedDto vm = context.getApi().getCloudApi().getVirtualMachine(target, id); - return wrap(context, VirtualMachine.class, vm); - } - - // Actions - - /** - * Deploys the virtual appliance. - * <p> - * This method will start the deployment of all the virtual machines in the - * virtual appliance, and will return an {@link AsyncTask} reference for each - * deployment operation. The deployment will finish when all individual tasks - * finish. - * - * @return The list of tasks corresponding to the deploy process of each - * virtual machine in the appliance. - */ - public VirtualMachineTask[] deploy() { - return deploy(false); - } - - /** - * Deploys the virtual appliance. - * <p> - * This method will start the deployment of all the virtual machines in the - * virtual appliance, and will return an {@link AsyncTask} reference for each - * deploy operation. The deployment will finish when all individual tasks - * finish. - * - * @param forceEnterpriseSoftLimits - * Boolean indicating if the deployment must be executed even if - * the enterprise soft limits are reached. - * @return The list of tasks corresponding to the deploy process of each - * virtual machine in the appliance. - */ - public VirtualMachineTask[] deploy(final boolean forceEnterpriseSoftLimits) { - VirtualMachineTaskDto force = new VirtualMachineTaskDto(); - force.setForceEnterpriseSoftLimits(forceEnterpriseSoftLimits); - - AcceptedRequestDto<String> response = context.getApi().getCloudApi().deployVirtualAppliance(unwrap(), force); - - AsyncTask<?, ?>[] tasks = getTasks(response); - return Arrays.copyOf(tasks, tasks.length, VirtualMachineTask[].class); - } - - /** - * Undeploys the virtual appliance. - * <p> - * This method will start the undeploy of all the virtual machines in the - * virtual appliance, and will return an {@link AsyncTask} reference for each - * undeploy operation. The undeploy will finish when all individual tasks - * finish. - * - * @return The list of tasks corresponding to the undeploy process of each - * virtual machine in the appliance. - */ - public VirtualMachineTask[] undeploy() { - return undeploy(false); - } - - /** - * Undeploys the virtual appliance. - * <p> - * This method will start the undeploy of all the virtual machines in the - * virtual appliance, and will return an {@link AsyncTask} reference for each - * undeploy operation. The undeploy will finish when all individual tasks - * finish. - * - * @param forceUndeploy - * Boolean flag to force the undeploy even if the virtual appliance - * contains imported virtual machines. - * @return The list of tasks corresponding to the undeploy process of each - * virtual machine in the appliance. - */ - public VirtualMachineTask[] undeploy(final boolean forceUndeploy) { - VirtualMachineTaskDto force = new VirtualMachineTaskDto(); - force.setForceUndeploy(forceUndeploy); - - AcceptedRequestDto<String> response = context.getApi().getCloudApi().undeployVirtualAppliance(unwrap(), force); - - AsyncTask<?, ?>[] tasks = getTasks(response); - return Arrays.copyOf(tasks, tasks.length, VirtualMachineTask[].class); - } - - /** - * Returns a String message with the price info of the virtual appliance. - * - * @return The price of the virtual appliance - */ - public String getPrice() { - return context.getApi().getCloudApi().getVirtualAppliancePrice(target); - } - - // Builder - - public static Builder builder(final ApiContext<AbiquoApi> context, final VirtualDatacenter virtualDatacenter) { - return new Builder(context, virtualDatacenter); - } - - public static class Builder { - private ApiContext<AbiquoApi> context; - - private String name; - - private VirtualDatacenter virtualDatacenter; - - public Builder(final ApiContext<AbiquoApi> context, final VirtualDatacenter virtualDatacenter) { - super(); - checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + VirtualDatacenter.class); - this.virtualDatacenter = virtualDatacenter; - this.context = context; - } - - public Builder name(final String name) { - this.name = name; - return this; - } - - public Builder virtualDatacenter(final VirtualDatacenter virtualDatacenter) { - checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + VirtualDatacenter.class); - this.virtualDatacenter = virtualDatacenter; - return this; - } - - public VirtualAppliance build() { - VirtualApplianceDto dto = new VirtualApplianceDto(); - dto.setName(name); - - VirtualAppliance virtualAppliance = new VirtualAppliance(context, dto); - virtualAppliance.virtualDatacenter = virtualDatacenter; - - return virtualAppliance; - } - - public static Builder fromVirtualAppliance(final VirtualAppliance in) { - return VirtualAppliance.builder(in.context, in.virtualDatacenter).name(in.getName()); - } - } - - // Delegate methods - - public int getError() { - return target.getError(); - } - - public Integer getId() { - return target.getId(); - } - - public String getName() { - return target.getName(); - } - - public void setHighDisponibility(final int highDisponibility) { - target.setHighDisponibility(highDisponibility); - } - - public void setName(final String name) { - target.setName(name); - } - - public void setPublicApp(final int publicApp) { - target.setPublicApp(publicApp); - } - - @Override - public String toString() { - return "VirtualAppliance [id=" + getId() + ", name=" + getName() + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java deleted file mode 100644 index 36321aa..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualDatacenter.java +++ /dev/null @@ -1,481 +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.cloud; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.find; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWithLimitsWrapper; -import org.jclouds.abiquo.domain.PaginatedCollection; -import org.jclouds.abiquo.domain.builder.LimitsBuilder; -import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions; -import org.jclouds.abiquo.domain.cloud.options.VolumeOptions; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.domain.infrastructure.Tier; -import org.jclouds.abiquo.domain.network.ExternalNetwork; -import org.jclouds.abiquo.domain.network.Network; -import org.jclouds.abiquo.domain.network.PrivateNetwork; -import org.jclouds.abiquo.domain.network.PublicIp; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.collect.PagedIterable; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.enumerator.HypervisorType; -import com.abiquo.model.enumerator.NetworkType; -import com.abiquo.model.enumerator.StatefulInclusion; -import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; -import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; -import com.abiquo.server.core.cloud.VirtualApplianceDto; -import com.abiquo.server.core.cloud.VirtualAppliancesDto; -import com.abiquo.server.core.cloud.VirtualDatacenterDto; -import com.abiquo.server.core.infrastructure.network.PublicIpDto; -import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; -import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; -import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; -import com.abiquo.server.core.infrastructure.storage.DisksManagementDto; -import com.abiquo.server.core.infrastructure.storage.TierDto; -import com.abiquo.server.core.infrastructure.storage.TiersDto; -import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; -import com.abiquo.server.core.infrastructure.storage.VolumesManagementDto; -import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; - -/** - * Represents a virtual datacenter. - * <p> - * Virtual datacenters expose a set of compute, storage and networking resources - * that can be consumed by the tenants. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource"> - * http - * ://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource</a> - */ -public class VirtualDatacenter extends DomainWithLimitsWrapper<VirtualDatacenterDto> { - /** The enterprise where the rack belongs. */ - private Enterprise enterprise; - - /** The datacenter where the virtual datacenter will be deployed. */ - private Datacenter datacenter; - - /** - * Constructor to be used only by the builder. - */ - protected VirtualDatacenter(final ApiContext<AbiquoApi> context, final VirtualDatacenterDto target) { - super(context, target); - } - - // Domain operations - - /** - * Delete the virtual datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-DeleteanexistingVirtualDatacenter" - * > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# - * VirtualDatacenterResource-DeleteanexistingVirtualDatacenter</a> - */ - public void delete() { - context.getApi().getCloudApi().deleteVirtualDatacenter(target); - target = null; - } - - /** - * Creates the virtual datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-CreateanewVirtualDatacenter" - * > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# VirtualDatacenterResource-CreateanewVirtualDatacenter</a> - */ - public void save() { - target = context.getApi().getCloudApi().createVirtualDatacenter(target, datacenter.unwrap(), enterprise.unwrap()); - } - - /** - * Updates the virtual datacenter information when some of its properties - * have changed. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-UpdatesanexistingVirtualDatacenter" - * > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# - * VirtualDatacenterResource-UpdatesanexistingVirtualDatacenter</a> - */ - public void update() { - target = context.getApi().getCloudApi().updateVirtualDatacenter(target); - } - - // Parent access - - /** - * Gets the datacenter where this virtual datacenter is assigned. - * - * @return The datacenter where this virtual datacenter is assigned. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Datacenter+Resource#DatacenterResource-RetrieveaDatacenter" - * > http://community.abiquo.com/display/ABI20/Datacenter+Resource# - * DatacenterResource- RetrieveaDatacenter</a> - */ - public Datacenter getDatacenter() { - final Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER); - datacenter = find(getEnterprise().listAllowedDatacenters(), new Predicate<Datacenter>() { - @Override - public boolean apply(Datacenter input) { - return input.getId().equals(datacenterId); - } - }); - return datacenter; - } - - /** - * Gets the enterprise that owns this virtual datacenter. - * - * @return The enterprise that owns this virtual datacenter. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource-RetrieveanEnterprise" - * > http://community.abiquo.com/display/ABI20/Enterprise+Resource# - * EnterpriseResource- RetrieveanEnterprise</a> - */ - public Enterprise getEnterprise() { - Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE); - enterprise = wrap(context, Enterprise.class, context.getApi().getEnterpriseApi().getEnterprise(enterpriseId)); - return enterprise; - } - - // Children access - - /** - * Lists all the virtual appliances in the virtual datacenter. - * - * @return The list of virtual appliances in the virtual datacenter. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource#VirtualApplianceResource-RetrievethelistofVirtualAppliances" - * >http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource - * # VirtualApplianceResource-RetrievethelistofVirtualAppliances</a> - */ - public Iterable<VirtualAppliance> listVirtualAppliances() { - VirtualAppliancesDto vapps = context.getApi().getCloudApi().listVirtualAppliances(target); - return wrap(context, VirtualAppliance.class, vapps.getCollection()); - } - - /** - * Gets the virtual appliance with the given id in the current virtual - * datacenter. - * - * @param id - * The id of the virtual appliance to get. - * @return The virtual appliance. - */ - public VirtualAppliance getVirtualAppliance(final Integer id) { - VirtualApplianceDto vapp = context.getApi().getCloudApi().getVirtualAppliance(target, id); - return wrap(context, VirtualAppliance.class, vapp); - } - - /** - * Lists the storage tiers that are available to the virtual datacenter. - * - * @return The list of storage tiers that are available to the virtual - * datacenter. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-Retrieveenabledtiers" - * > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# VirtualDatacenterResource-Retrieveenabledtiers</a> - */ - public Iterable<Tier> listStorageTiers() { - TiersDto tiers = context.getApi().getCloudApi().listStorageTiers(target); - return wrap(context, Tier.class, tiers.getCollection()); - } - - /** - * Gets the storage tier with the given id from the current virtual - * datacenter. - * - * @param id - * The id of the storage tier. - * @return The storage tier. - */ - public Tier getStorageTier(final Integer id) { - TierDto tier = context.getApi().getCloudApi().getStorageTier(target, id); - return wrap(context, Tier.class, tier); - } - - /** - * Lists all persistent volumes in the virtual datacenter. - * - * @return The list of all persistent volumes in the virtual datacenter. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Volume+Resource#VolumeResource-Retrievethelistofvolumes" - * > http://community.abiquo.com/display/ABI20/Volume+Resource# - * VolumeResource- Retrievethelistofvolumes</a> - */ - public Iterable<Volume> listVolumes() { - PagedIterable<VolumeManagementDto> volumes = context.getApi().getCloudApi().listVolumes(target); - return wrap(context, Volume.class, volumes.concat()); - } - - public Iterable<Volume> listVolumes(VolumeOptions options) { - PaginatedCollection<VolumeManagementDto, VolumesManagementDto> volumes = context.getApi().getCloudApi() - .listVolumes(target, options); - return wrap(context, Volume.class, volumes.toPagedIterable().concat()); - } - - public Volume getVolume(final Integer id) { - VolumeManagementDto volume = context.getApi().getCloudApi().getVolume(target, id); - return wrap(context, Volume.class, volume); - } - - /** - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Hard+Disks+Resource#HardDisksResource-GetthelistofHardDisksofaVirtualDatacenter" - * > http://community.abiquo.com/display/ABI20/Hard+Disks+Resource# - * HardDisksResource- GetthelistofHardDisksofaVirtualDatacenter</a> - */ - public Iterable<HardDisk> listHardDisks() { - DisksManagementDto hardDisks = context.getApi().getCloudApi().listHardDisks(target); - return wrap(context, HardDisk.class, hardDisks.getCollection()); - } - - public HardDisk getHardDisk(final Integer id) { - DiskManagementDto hardDisk = context.getApi().getCloudApi().getHardDisk(target, id); - return wrap(context, HardDisk.class, hardDisk); - } - - /** - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-GetdefaultVLANusedbydefaultinVirtualDatacenter" - * > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# - * VirtualDatacenterResource-GetdefaultVLANusedbydefaultinVirtualDatacenter - * </a> - */ - public Network<?> getDefaultNetwork() { - VLANNetworkDto network = context.getApi().getCloudApi().getDefaultNetwork(target); - return wrap(context, network.getType() == NetworkType.INTERNAL ? PrivateNetwork.class : ExternalNetwork.class, - network); - } - - /** - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Private+Network+Resource#PrivateNetworkResource-RetrievealistofPrivateNetworks" - * > http://community.abiquo.com/display/ABI20/Private+Network+Resource# - * PrivateNetworkResource -RetrievealistofPrivateNetworks</a> - */ - public Iterable<PrivateNetwork> listPrivateNetworks() { - VLANNetworksDto networks = context.getApi().getCloudApi().listPrivateNetworks(target); - return wrap(context, PrivateNetwork.class, networks.getCollection()); - } - - public PrivateNetwork getPrivateNetwork(final Integer id) { - VLANNetworkDto network = context.getApi().getCloudApi().getPrivateNetwork(target, id); - return wrap(context, PrivateNetwork.class, network); - } - - public Iterable<VirtualMachineTemplate> listAvailableTemplates() { - PagedIterable<VirtualMachineTemplateDto> templates = context.getApi().getCloudApi() - .listAvailableTemplates(target); - return wrap(context, VirtualMachineTemplate.class, templates.concat()); - } - - public Iterable<VirtualMachineTemplate> listAvailableTemplates(final VirtualMachineTemplateOptions options) { - PaginatedCollection<VirtualMachineTemplateDto, VirtualMachineTemplatesDto> templates = context.getApi() - .getCloudApi().listAvailableTemplates(target, options); - return wrap(context, VirtualMachineTemplate.class, templates.toPagedIterable().concat()); - } - - public VirtualMachineTemplate getAvailableTemplate(final Integer id) { - PaginatedCollection<VirtualMachineTemplateDto, VirtualMachineTemplatesDto> templates = context.getApi() - .getCloudApi() - .listAvailableTemplates(target, VirtualMachineTemplateOptions.builder().idTemplate(id).build()); - - FluentIterable<VirtualMachineTemplateDto> all = templates.toPagedIterable().concat(); - return wrap(context, VirtualMachineTemplate.class, all.first().orNull()); - } - - public VirtualMachineTemplate getAvailablePersistentTemplate(final Integer id) { - PaginatedCollection<VirtualMachineTemplateDto, VirtualMachineTemplatesDto> templates = context - .getApi() - .getCloudApi() - .listAvailableTemplates(target, - VirtualMachineTemplateOptions.builder().idTemplate(id).persistent(StatefulInclusion.ALL).build()); - - FluentIterable<VirtualMachineTemplateDto> all = templates.toPagedIterable().concat(); - return wrap(context, VirtualMachineTemplate.class, all.first().orNull()); - } - - /** - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-ListofPublicIPstopurchasebyVirtualDatacenter" - * > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# - * VirtualDatacenterResource-ListofPublicIPstopurchasebyVirtualDatacenter - * </a> - */ - public Iterable<PublicIp> listAvailablePublicIps() { - PagedIterable<PublicIpDto> ips = context.getApi().getCloudApi().listAvailablePublicIps(target); - return wrap(context, PublicIp.class, ips.concat()); - } - - /** - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-ListofpurchasedPublicIPsbyVirtualDatacenter" - * > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+ - * Resource# - * VirtualDatacenterResource-ListofpurchasedPublicIPsbyVirtualDatacenter - * </a> - */ - public Iterable<PublicIp> listPurchasedPublicIps() { - PagedIterable<PublicIpDto> ips = context.getApi().getCloudApi().listPurchasedPublicIps(target); - return wrap(context, PublicIp.class, ips.concat()); - } - - public void purchasePublicIp(final PublicIp ip) { - checkNotNull(ip.unwrap().searchLink("purchase"), ValidationErrors.MISSING_REQUIRED_LINK); - context.getApi().getCloudApi().purchasePublicIp(ip.unwrap()); - } - - public void releasePublicIp(final PublicIp ip) { - checkNotNull(ip.unwrap().searchLink("release"), ValidationErrors.MISSING_REQUIRED_LINK); - context.getApi().getCloudApi().releasePublicIp(ip.unwrap()); - } - - // Actions - - public void setDefaultNetwork(final Network<?> network) { - context.getApi().getCloudApi().setDefaultNetwork(target, network.unwrap()); - } - - // Builder - - public static Builder builder(final ApiContext<AbiquoApi> context, final Datacenter datacenter, - final Enterprise enterprise) { - return new Builder(context, datacenter, enterprise); - } - - public static class Builder extends LimitsBuilder<Builder> { - private ApiContext<AbiquoApi> context; - - private String name; - - private HypervisorType hypervisorType; - - private Enterprise enterprise; - - private Datacenter datacenter; - - private PrivateNetwork network; - - public Builder(final ApiContext<AbiquoApi> context, final Datacenter datacenter, final Enterprise enterprise) { - super(); - checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); - this.datacenter = datacenter; - checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); - this.enterprise = enterprise; - this.context = context; - } - - public Builder name(final String name) { - this.name = name; - return this; - } - - public Builder hypervisorType(final HypervisorType hypervisorType) { - this.hypervisorType = hypervisorType; - return this; - } - - public Builder datacenter(final Datacenter datacenter) { - checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class); - this.datacenter = datacenter; - return this; - } - - public Builder enterprise(final Enterprise enterprise) { - checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class); - this.enterprise = enterprise; - return this; - } - - public Builder network(final PrivateNetwork network) { - checkNotNull(network, ValidationErrors.NULL_RESOURCE + PrivateNetwork.class); - this.network = network; - return this; - } - - public VirtualDatacenter build() { - VirtualDatacenterDto dto = new VirtualDatacenterDto(); - dto.setName(name); - dto.setRamLimitsInMb(ramSoftLimitInMb, ramHardLimitInMb); - dto.setCpuCountLimits(cpuCountSoftLimit, cpuCountHardLimit); - dto.setHdLimitsInMb(hdSoftLimitInMb, hdHardLimitInMb); - dto.setStorageLimits(storageSoft, storageHard); - dto.setVlansLimits(vlansSoft, vlansHard); - dto.setPublicIPLimits(publicIpsSoft, publicIpsHard); - dto.setName(name); - dto.setHypervisorType(hypervisorType); - dto.setVlan(network.unwrap()); - - VirtualDatacenter virtualDatacenter = new VirtualDatacenter(context, dto); - virtualDatacenter.datacenter = datacenter; - virtualDatacenter.enterprise = enterprise; - - return virtualDatacenter; - } - - public static Builder fromVirtualDatacenter(final VirtualDatacenter in) { - return VirtualDatacenter.builder(in.context, in.datacenter, in.enterprise).name(in.getName()) - .ramLimits(in.getRamSoftLimitInMb(), in.getRamHardLimitInMb()) - .cpuCountLimits(in.getCpuCountSoftLimit(), in.getCpuCountHardLimit()) - .hdLimitsInMb(in.getHdSoftLimitInBytes(), in.getHdHardLimitInBytes()) - .storageLimits(in.getStorageSoft(), in.getStorageHard()) - .vlansLimits(in.getVlansSoft(), in.getVlansHard()) - .publicIpsLimits(in.getPublicIpsSoft(), in.getPublicIpsHard()).hypervisorType(in.getHypervisorType()); - } - } - - // Delegate methods - - public HypervisorType getHypervisorType() { - return target.getHypervisorType(); - } - - public Integer getId() { - return target.getId(); - } - - public String getName() { - return target.getName(); - } - - public void setHypervisorType(final HypervisorType hypervisorType) { - target.setHypervisorType(hypervisorType); - } - - public void setName(final String name) { - target.setName(name); - } - - @Override - public String toString() { - return "VirtualDatacenter [id=" + getId() + ", type=" + getHypervisorType() + ", name=" + getName() + "]"; - } - -}
