JCLOUDS-208: Changes for the Abiquo 2.4 procedure to limit enterprises to datacenters #17

Closed
wants to merge 3 commits into
from
@@ -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());
@@ -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) {
@demobox

demobox Jul 31, 2013

Owner

I assume there is no way to provide a backwards-compatible version of this call? Then again, this is master, so probably no need...

@nacx

nacx Aug 1, 2013

Owner

There is no backwards compatible version, but I don't think it should be a problem. This builder will rarely be used directly, since the functionality is usually invoked from the Enterprise.allowDatacenter method.

+ return new Builder(context, datacenter);
}
public static class Builder extends LimitsBuilder<Builder> {
@@ -67,10 +74,12 @@ 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) {
- super();
- this.context = context;
+ public Builder(final ApiContext<AbiquoApi> context, final Datacenter datacenter) {
+ this.context = checkNotNull(context, "missing context object");
+ this.datacenter = checkNotNull(datacenter, "missing datacenter object");
}
public Builder repositoryLimits(final long soft, final long hard) {
@@ -89,14 +98,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())
@demobox

demobox Jul 31, 2013

Owner

If this is purely a formatting change, align with the following lines?

.cpuCountLimits(in.getCpuCountSoftLimit(), in.getCpuCountHardLimit())
.hdLimitsInMb(in.getHdSoftLimitInMb(), in.getHdHardLimitInMb())
.storageLimits(in.getStorageSoft(), in.getStorageHard())
@@ -132,6 +146,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() {