Skip to content
Browse files

JCLOUDS-208: The datacenter link has been added to the Limits object …

…construction. This link is used in the 2.4 version of the Abiquo API to establish a relation between an enterprise and the datacenter it is restricted to
  • Loading branch information...
1 parent 880c1c7 commit 320a74d061ef10e7a8a84dc2557520d8f40250aa Carlos Garcia committed Jul 30, 2013
View
2 abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Enterprise.java
@@ -360,7 +360,7 @@ public Limits allowDatacenter(final Datacenter datacenter) {
try {
// Create new limits
- Limits limits = Limits.builder(context).build();
+ Limits limits = Limits.builder(context, datacenter).build();
// Save new limits
dto = context.getApi().getEnterpriseApi().createLimits(target, datacenter.unwrap(), limits.unwrap());
View
30 abiquo/src/main/java/org/jclouds/abiquo/domain/enterprise/Limits.java
@@ -16,12 +16,19 @@
*/
package org.jclouds.abiquo.domain.enterprise;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.domain.DomainWithLimitsWrapper;
import org.jclouds.abiquo.domain.builder.LimitsBuilder;
+import org.jclouds.abiquo.domain.infrastructure.Datacenter;
+import org.jclouds.abiquo.reference.ValidationErrors;
+import org.jclouds.abiquo.reference.rest.ParentLinkName;
import org.jclouds.rest.ApiContext;
+import com.abiquo.model.rest.RESTLink;
import com.abiquo.server.core.enterprise.DatacenterLimitsDto;
+import com.abiquo.server.core.infrastructure.DatacenterDto;
/**
* Adds high level functionality to {@link DatacenterLimitsDto}.
@@ -57,8 +64,8 @@ public void update() {
// Builder
- public static Builder builder(final ApiContext<AbiquoApi> context) {
- return new Builder(context);
+ public static Builder builder(final ApiContext<AbiquoApi> context, Datacenter datacenter) {
+ return new Builder(context, datacenter);
}
public static class Builder extends LimitsBuilder<Builder> {
@@ -67,10 +74,13 @@ public static Builder builder(final ApiContext<AbiquoApi> context) {
protected Long repositorySoft = Long.valueOf(DEFAULT_LIMITS);
protected Long repositoryHard = Long.valueOf(DEFAULT_LIMITS);
+
+ protected Datacenter datacenter;
- public Builder(final ApiContext<AbiquoApi> context) {
+ public Builder(final ApiContext<AbiquoApi> context, final Datacenter datacenter) {
super();
this.context = context;
+ this.datacenter = datacenter;
}
public Builder repositoryLimits(final long soft, final long hard) {
@@ -89,14 +99,19 @@ public Limits build() {
dto.setPublicIPLimits(publicIpsSoft, publicIpsHard);
dto.setRepositoryHardLimitsInMb(repositoryHard);
dto.setRepositorySoftLimitsInMb(repositorySoft);
+
+ // Establish the relation with the physical datacenter
+ dto.addLink(new RESTLink(ParentLinkName.DATACENTER, checkNotNull(datacenter.unwrap().getEditLink(),
+ "missing edit link").getHref()));
Limits limits = new Limits(context, dto);
return limits;
}
public static Builder fromEnterprise(final Limits in) {
- return Limits.builder(in.context).ramLimits(in.getRamSoftLimitInMb(), in.getRamHardLimitInMb())
+ return Limits.builder(in.context, in.getDatacenter())
+ .ramLimits(in.getRamSoftLimitInMb(), in.getRamHardLimitInMb())
.cpuCountLimits(in.getCpuCountSoftLimit(), in.getCpuCountHardLimit())
.hdLimitsInMb(in.getHdSoftLimitInMb(), in.getHdHardLimitInMb())
.storageLimits(in.getStorageSoft(), in.getStorageHard())
@@ -132,6 +147,13 @@ public void setRepositoryLimits(final long soft, final long hard) {
public void setRepositorySoft(final long repositorySoft) {
target.setRepositorySoftLimitsInMb(repositorySoft);
}
+
+ public Datacenter getDatacenter() {
+ Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER);
+ checkNotNull(datacenterId, ValidationErrors.MISSING_REQUIRED_LINK);
+ DatacenterDto dto = context.getApi().getInfrastructureApi().getDatacenter(datacenterId);
+ return wrap(context, Datacenter.class, dto);
+ }
@Override
public String toString() {

0 comments on commit 320a74d

Please sign in to comment.
Something went wrong with that request. Please try again.