diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java index c4a9829877..2b19d9155a 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/DomainWrapper.java @@ -35,6 +35,9 @@ import org.jclouds.abiquo.domain.exception.WrapperException; import org.jclouds.abiquo.domain.task.AsyncTask; import org.jclouds.abiquo.domain.util.LinkUtils; import org.jclouds.abiquo.reference.ValidationErrors; +import org.jclouds.abiquo.rest.internal.ExtendedUtils; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseXMLWithJAXB; import org.jclouds.rest.RestContext; import com.abiquo.model.rest.RESTLink; @@ -46,6 +49,7 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableList; 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 @@ -84,6 +88,22 @@ public abstract class DomainWrapper { 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"); + + ExtendedUtils utils = (ExtendedUtils) context.getUtils(); + HttpResponse response = utils.getAbiquoHttpClient().get(link); + + ParseXMLWithJAXB parser = new ParseXMLWithJAXB(utils.getXml(), + TypeLiteral.get((Class) target.getClass())); + + target = parser.apply(response); + } + /** * Read the ID of the parent resource from the given link. * diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java index 592de3c520..9f93668b7a 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/Conversion.java @@ -58,20 +58,6 @@ public class Conversion extends DomainWithTasksWrapper { super(context, target); } - // Domain methods - - public void refresh() { - RESTLink link = checkNotNull(target.searchLink("edit"), ValidationErrors.MISSING_REQUIRED_LINK + "edit"); - - ExtendedUtils utils = (ExtendedUtils) context.getUtils(); - HttpResponse response = checkNotNull(utils.getAbiquoHttpClient().get(link), "conversion"); - - ParseXMLWithJAXB parser = new ParseXMLWithJAXB(utils.getXml(), - TypeLiteral.get(ConversionDto.class)); - - target = parser.apply(response); - } - // Parent access /** diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java index 6b2084ff5f..29a2ac3fe1 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/cloud/VirtualMachine.java @@ -220,18 +220,6 @@ public class VirtualMachine extends DomainWithTasksWrapper parser = new ParseXMLWithJAXB( - utils.getXml(), TypeLiteral.get(VirtualMachineWithNodeExtendedDto.class)); - - target = parser.apply(response); - } - // Parent access /** diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StoragePool.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StoragePool.java index a137391576..b5a79210ba 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StoragePool.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/StoragePool.java @@ -112,6 +112,7 @@ public class StoragePool extends DomainWrapper { target = context.getApi().getInfrastructureApi().updateStoragePool(target); } + @Override public void refresh() { target = context.getApi().getInfrastructureApi() .refreshStoragePool(target, StoragePoolOptions.builder().sync(true).build()); @@ -187,7 +188,6 @@ public class StoragePool extends DomainWrapper { private String name; private Long totalSizeInMb; - public Builder(final RestContext context, final StorageDevice storageDevice) { super(); checkNotNull(storageDevice, ValidationErrors.NULL_RESOURCE + StorageDevice.class); @@ -206,13 +206,11 @@ public class StoragePool extends DomainWrapper { return this; } - public Builder totalSizeInMb(final long totalSizeInMb) { this.totalSizeInMb = totalSizeInMb; return this; } - public StoragePool build() { StoragePoolDto dto = new StoragePoolDto(); dto.setName(name); @@ -223,8 +221,7 @@ public class StoragePool extends DomainWrapper { } public static Builder fromStoragePool(final StoragePool in) { - Builder builder = StoragePool.builder(in.context, in.getStorageDevice()) - .totalSizeInMb(in.getTotalSizeInMb()); + Builder builder = StoragePool.builder(in.context, in.getStorageDevice()).totalSizeInMb(in.getTotalSizeInMb()); return builder; } diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncTask.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncTask.java index 7cf5d999a1..4a3ac50576 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncTask.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/domain/task/AsyncTask.java @@ -23,8 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.List; -import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.AbiquoApi; +import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.domain.DomainWrapper; import org.jclouds.abiquo.reference.ValidationErrors; import org.jclouds.rest.RestContext; @@ -52,6 +52,7 @@ public class AsyncTask extends DomainWrapper { /** * Refresh the state of the task. */ + @Override public void refresh() { RESTLink self = checkNotNull(target.searchLink("self"), ValidationErrors.MISSING_REQUIRED_LINK + "self");