Skip to content

Commit

Permalink
A lot of changes that improve the code and readability
Browse files Browse the repository at this point in the history
  • Loading branch information
augustocristian committed Nov 14, 2024
1 parent 6eff011 commit 3901449
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 495 deletions.
Original file line number Diff line number Diff line change
@@ -1,52 +1,21 @@
package giis.retorch.orchestration.model;

/**
* RETORCH access mode that represents how a test case uses a resource
*/
public class AccessModeEntity {

private AccessModeTypesEntity accessMode;
private boolean sharing = false;
private int concurrency = 1;
private ResourceEntity resource;

public AccessModeEntity() {
}
/**
* RETORCH access mode copy constructor
*/
public AccessModeEntity() {}

public AccessModeEntity(AccessModeEntity accessMode) {
this.accessMode = accessMode.getAccessMode();
this.concurrency = accessMode.getConcurrency();
this.resource = accessMode.getResource();
this.sharing = accessMode.getSharing();
}

public AccessModeTypesEntity getAccessMode() {
return accessMode;
}
public int getConcurrency() {
return concurrency;
}
public ResourceEntity getResource() {
return resource;
}
public boolean getSharing() {
return sharing;
}
public void setSharing(boolean sharing) {
this.sharing = sharing;
}
public void setResource(ResourceEntity resource) {
this.resource = resource;
}
public void setConcurrency(int concurrency) {
this.concurrency = concurrency;
}
public void setAccessMode(AccessModeTypesEntity accessMode) {
this.accessMode = accessMode;
}

/**
* Access mode constructor
* @param accessMode {@link AccessModeTypesEntity} that could be READONLY,WRITEONLY,READWRITE,DYNAMIC or NOACCESS
Expand All @@ -68,8 +37,7 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (!obj.getClass().equals(this.getClass())) return false;
if ((obj == null) || (!obj.getClass().equals(this.getClass()))) return false;
AccessModeEntity objToCompare = ((AccessModeEntity) obj);

return objToCompare.getSharing() == this.sharing && objToCompare.getConcurrency() == this.concurrency
Expand All @@ -80,4 +48,31 @@ public boolean equals(Object obj) {
public String toString() {
return "a.m.{" + accessMode + ", " + sharing + ", " + concurrency + ",'" + resource + '\'' + '}';
}

public AccessModeTypesEntity getAccessMode() {
return accessMode;
}
public int getConcurrency() {
return concurrency;
}
public ResourceEntity getResource() {
return resource;
}
public boolean getSharing() {
return sharing;
}

public void setSharing(boolean sharing) {
this.sharing = sharing;
}
public void setResource(ResourceEntity resource) {
this.resource = resource;
}
public void setConcurrency(int concurrency) {
this.concurrency = concurrency;
}
public void setAccessMode(AccessModeTypesEntity accessMode) {
this.accessMode = accessMode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

/**
* This class is used as AccessMode parser for given a string representation of a RETORCH access mode (i.e:
* READONLY,READWRITE...)
* convert it into the proper enumeration
* READONLY,READWRITE...) convert it into the proper enumeration. Also provides
*/
public class AccessModeTypesEntity {

private final String accessStringType; //String with the access mode
private type accessModeType; //Current type of access mode
public enum type {READONLY, READWRITE, WRITEONLY, DYNAMIC, NOACCESS}

private final String accessStringType;

private type accessModeType;

/**
* Access Mode constructor, takes the access mode in String format and gives the correct type:
* @param typeOfAccess String with the access mode: READONLY,READWRITE,WRITEONLY,DYNAMIC or NOACESS
*/
public AccessModeTypesEntity(String typeOfAccess) {
this.accessStringType = typeOfAccess;
switch (typeOfAccess) {
Expand All @@ -36,39 +34,33 @@ public AccessModeTypesEntity(String typeOfAccess) {
break;
}
}
/**
* Support method that checks if the given String is valid access mode
* @param accessMode String with the access mode: READONLY,READWRITE,WRITEONLY,DYNAMIC or NOACESS
*/
public static boolean isValidAccessMode(String accessMode) {
//Conditions that check the different access modes
boolean isReadOnly = accessMode.equals("READONLY");
boolean isReadWrite = accessMode.equals("READWRITE");
boolean isWriteOnly = accessMode.equals("WRITEONLY");
boolean isDynamic = accessMode.equals("DYNAMIC");
boolean isNoAccess = accessMode.equals("NOACCESS");

return isReadOnly || isReadWrite || isWriteOnly || isDynamic || isNoAccess;
}
@Override
public int hashCode() {
return super.hashCode();
}

@Override
public String toString() {
return this.accessStringType;
}

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (!obj.getClass().equals(this.getClass())) return false;
if ((obj == null)||(!obj.getClass().equals(this.getClass()))) return false;
AccessModeTypesEntity currentType = ((AccessModeTypesEntity) obj);
return currentType.getAccessModeType() == this.getAccessModeType();
}

public type getAccessModeType() {
return accessModeType;
}
@Override
public String toString() {
return this.accessStringType;
}

public enum type {READONLY, READWRITE, WRITEONLY, DYNAMIC, NOACCESS}//Enumeration with the different access modes
// allowed
/**
* Support method that checks if the given String is valid access mode
* @param accessMode String with the access mode: READONLY,READWRITE,WRITEONLY,DYNAMIC or NOACESS
*/
public static boolean isValidAccessMode(String accessMode) {
return accessMode.equals("READONLY") || accessMode.equals("READWRITE") || accessMode.equals("WRITEONLY")
|| accessMode.equals("DYNAMIC") || accessMode.equals("NOACCESS");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;


/**
* The {@code Capacity} class represents a capacity of with a name and a quantity.
* It provides methods to add to the quantity and to get and set the name and quantity. The capacity names that
Expand All @@ -18,21 +18,16 @@
public class CapacityEntity {

private static final Logger log = LoggerFactory.getLogger(CapacityEntity.class);
private String name;
private double quantity;
public static final String MEMORY_NAME = "memory";
public static final String PROCESSOR_NAME = "processor";
public static final String SLOTS_NAME = "slots";
public static final String STORAGE_NAME = "storage";

protected static final Set<String> LIST_CAPACITIES;
static {
LIST_CAPACITIES = new HashSet<>();
LIST_CAPACITIES.add(MEMORY_NAME);
LIST_CAPACITIES.add(PROCESSOR_NAME);
LIST_CAPACITIES.add(SLOTS_NAME);
LIST_CAPACITIES.add(STORAGE_NAME);
}
private String name;
private double quantity;

protected static final Set<String> LIST_CAPACITIES = new HashSet<>();
static {Collections.addAll(LIST_CAPACITIES, MEMORY_NAME, PROCESSOR_NAME, SLOTS_NAME, STORAGE_NAME);}

public CapacityEntity(@JsonProperty("name") String name, @JsonProperty("quantity") double quantity) {
if (LIST_CAPACITIES.contains(name)) {
Expand All @@ -44,8 +39,22 @@ public CapacityEntity(@JsonProperty("name") String name, @JsonProperty("quantity
setQuantity(quantity);
}

public void addQuantity(double number) {
this.quantity += number;
@Override
public int hashCode() {
return Objects.hash(name, quantity);
}

@Override
public String toString() {
return "{"+"name:"+ getName() + ", "+"quantity:" + getQuantity() + "}";
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CapacityEntity that = (CapacityEntity) o;
return Objects.equals(this.getName(), that.getName()) && Objects.equals(this.getQuantity(), that.getQuantity());
}

public String getName() {
Expand All @@ -61,20 +70,7 @@ public void setQuantity(double quantity) {
this.quantity = quantity;
}

@Override
public int hashCode() {
return Objects.hash(name, quantity);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CapacityEntity that = (CapacityEntity) o;
return Objects.equals(this.getName(), that.getName()) && Objects.equals(this.getQuantity(), that.getQuantity());
}

@Override
public String toString() {
return "{"+"name:"+ getName() + ", "+"quantity:" + getQuantity() + "}";
public void addQuantity(double number) {
this.quantity += number;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* RETORCH Elasticity model: Represents the elasticity of the resource i.e. the maximum amount of resources to be
* deployed,
* the cost of each instance
*/
public class ElasticityModelEntity {

private String elasticityID;
private int elasticity;
private double elasticityCost;

public ElasticityModelEntity(String idElasticity) {
public ElasticityModelEntity(String idElasticity) {this.elasticityID = idElasticity;}

this.elasticityID = idElasticity;
}
/**
* Elasticity model constructor
* @param elasticity Integer with the maximum amount of resources that can be deployed
Expand All @@ -30,18 +23,25 @@ public ElasticityModelEntity(@JsonProperty("elasticityID") String elasticityID,
this.elasticity = elasticity;
this.elasticityCost = elasticityCost;
}

@Override
public int hashCode() {
return super.hashCode();
}

@Override
public String toString() {
return "elas{" + "'" + elasticityID + '\'' + ", e=" + elasticity + ", cost=" + elasticityCost + '}';
}

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (!obj.getClass().equals(this.getClass())) return false;
if ((obj == null) ||(!obj.getClass().equals(this.getClass()))) return false;
ElasticityModelEntity currentType = ((ElasticityModelEntity) obj);
return currentType.getElasticity() == this.elasticity && currentType.getElasticityCost() == this.elasticityCost &&
currentType.getElasticityID().equals(this.getElasticityID());
}

public int getElasticity() {
return elasticity;
}
Expand All @@ -51,6 +51,7 @@ public double getElasticityCost() {
public String getElasticityID() {
return elasticityID;
}

public void setElasticityID(String elasticityID) {
this.elasticityID = elasticityID;
}
Expand All @@ -60,8 +61,5 @@ public void setElasticityCost(double elasticityCost) {
public void setElasticity(int elasticity) {
this.elasticity = elasticity;
}
@Override
public String toString() {
return "elas{" + "'" + elasticityID + '\'' + ", e=" + elasticity + ", cost=" + elasticityCost + '}';
}

}
Loading

0 comments on commit 3901449

Please sign in to comment.