Skip to content

Commit

Permalink
Moving architecture inside VirtualMachineProduct
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimov committed Mar 4, 2015
1 parent 84c32eb commit 0a73f7b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
37 changes: 29 additions & 8 deletions src/main/java/org/dasein/cloud/compute/VirtualMachineProduct.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

@SuppressWarnings("UnusedDeclaration")
public class VirtualMachineProduct implements Serializable {
Expand All @@ -40,17 +45,20 @@ public class VirtualMachineProduct implements Serializable {
private float standardHourlyRate;
private VisibleScope visibleScope;
private String dataCenterId;
private Architecture[] architectures;

public enum Status { CURRENT, DEPRECATED; }
public enum Status {CURRENT, DEPRECATED;}

private Status status = Status.CURRENT;

public VirtualMachineProduct() { }

public VirtualMachineProduct() {
}

// TODO(stas): shouldn't this also compare other attributes?
public boolean equals(Object ob) {
return (ob != null && (ob == this || getClass().getName().equals(ob.getClass().getName()) && getProviderProductId().equals(((VirtualMachineProduct) ob).getProviderProductId())));
return ( ob != null && ( ob == this || getClass().getName().equals(ob.getClass().getName()) && getProviderProductId().equals(( ( VirtualMachineProduct ) ob ).getProviderProductId()) ) );
}

public String getName() {
return name;
}
Expand All @@ -74,11 +82,11 @@ public String getDescription() {
public void setDescription(String description) {
this.description = description;
}

public String getProviderProductId() {
return providerProductId;
}

public void setProviderProductId(@Nonnull String providerProductId) {
this.providerProductId = providerProductId;
}
Expand All @@ -88,7 +96,7 @@ public Storage<Gigabyte> getRootVolumeSize() {
}

public void setRootVolumeSize(Storage<?> rootVolumeSize) {
this.rootVolumeSize = (Storage<Gigabyte>)rootVolumeSize.convertTo(Storage.GIGABYTE);
this.rootVolumeSize = ( Storage<Gigabyte> ) rootVolumeSize.convertTo(Storage.GIGABYTE);
}

public Storage<Megabyte> getRamSize() {
Expand Down Expand Up @@ -131,6 +139,19 @@ public void setStatusDeprecated() {
this.status = Status.DEPRECATED;
}

public void setArchitectures(Architecture ... architectures) {
this.architectures = architectures;
}

/**
* List of supported architectures. This is of type List as opposed to Iterable as this is a model class,
* so all data is already pre-populated.
* @return
*/
public @Nonnull Architecture[] getArchitectures() {
return architectures != null ? architectures : new Architecture[0];
}

public String toString() {
return (name + " [" + providerProductId + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;

/**
* Options for filtering virtual machine products when querying the cloud provider. You may optionally filter on
Expand All @@ -40,6 +41,7 @@ public class VirtualMachineProductFilterOptions{
private int cpuCount = 0;
private Storage<Megabyte> ramSize;
private String dataCenterId;
private Architecture architecture;

/**
* Constructs an empty set of filtering options that will force match against any VM Product by default.
Expand Down Expand Up @@ -109,7 +111,7 @@ public int getCpuCount(){
* @return true if this filter options object has any criteria associated with it
*/
public boolean hasCriteria() {
return (cpuCount > 0 || (ramSize != null && ramSize.intValue() > 0) || regex != null || dataCenterId != null);
return (cpuCount > 0 || (ramSize != null && ramSize.intValue() > 0) || regex != null || dataCenterId != null || architecture != null);
}

/**
Expand Down Expand Up @@ -165,6 +167,11 @@ public boolean isMatchesAny() {
return this;
}

public @Nonnull VirtualMachineProductFilterOptions withArchitecture(@Nonnull Architecture architecture) {
this.architecture = architecture;
return this;
}

/**
* Matches a VM Product against the criteria in this set of filter options.
* @param product the VM Product to test
Expand Down Expand Up @@ -198,7 +205,7 @@ else if( matches && matchesAny ) {
return true;
}
}
else if( dataCenterId != null && product.getDataCenterId() != null){
else if(dataCenterId != null && product.getDataCenterId() != null){
boolean matches = product.getDataCenterId().equals(dataCenterId);
if( !matches && !matchesAny ) {
return false;
Expand All @@ -207,6 +214,15 @@ else if( matches && matchesAny ) {
return true;
}
}
else if(architecture != null && product.getArchitectures() != null) {
boolean matches = Arrays.binarySearch(product.getArchitectures(), architecture) >= 0;
if( !matches && !matchesAny ) {
return false;
}
else if( matches && matchesAny ) {
return true;
}
}
return !matchesAny;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ public interface VirtualMachineSupport extends AccessControlledService {
* @return the list of server sizes available for the specified architecture
* @throws InternalException an error occurred within the Dasein Cloud API implementation
* @throws CloudException an error occurred within the cloud provider
* @deprecated
*/
public @Nonnull Iterable<VirtualMachineProduct> listProducts(@Nullable Architecture architecture) throws InternalException, CloudException;

Expand All @@ -423,6 +424,7 @@ public interface VirtualMachineSupport extends AccessControlledService {
* @return the list of server sizes available matching the filter
* @throws InternalException an error occurred within the Dasein Cloud API implementation
* @throws CloudException an error occurred within the cloud provider
* @deprecated
*/
public @Nonnull Iterable<VirtualMachineProduct> listProducts(@Nullable VirtualMachineProductFilterOptions options, @Nullable Architecture architecture) throws InternalException, CloudException;

Expand Down

0 comments on commit 0a73f7b

Please sign in to comment.