Commit 3c27d182 authored by Ali Fahs's avatar Ali Fahs
Browse files

Add BYON Node Candidates and Cloud

parent 8fac1110
......@@ -627,24 +627,97 @@ public class PAGateway {
Validate.notNull(byonNodeDefinition, "The received Byon node definition is empty. Nothing to be registered.");
Validate.notNull(jobId, "The received jobId is empty. Nothing to be registered.");
Job job = EntityManagerHelper.find(Job.class, jobId);
// assert job is not null
EntityManagerHelper.begin();
NodeCandidate byonNC = createByonNodeCandidate(byonNodeDefinition, jobId);
ByonNode newByonNode = new ByonNode();
newByonNode.setName(byonNodeDefinition.getName());
newByonNode.setLoginCredential(byonNodeDefinition.getLoginCredential());
newByonNode.setIpAddresses(byonNodeDefinition.getIpAddresses());
newByonNode.setNodeProperties(byonNodeDefinition.getNodeProperties());
newByonNode.setJob(job);
newByonNode.setNodeCandidate(byonNC);
EntityManagerHelper.persist(newByonNode);
EntityManagerHelper.commit();
return newByonNode;
/*TODO:
* Avoid duplicate nodes in the database
/* TODO:
* Avoid duplicate nodes in the database
* Create the NC here
*/
}
/**
* Create a dummy object of class Cloud to be used for the node candidates
* @return the created byonCloud object
*/
private Cloud createByonCloud() {
EntityManagerHelper.begin();
//Check if the Byon cloud already exists
List<Cloud> clouds =EntityManagerHelper.createQuery("SELECT cloud FROM Cloud cloud", Cloud.class).getResultList();;
for(Cloud cloud : clouds ) {
if(cloud.getCloudType()==CloudType.BYON && cloud.getOwner().equals("BYON") && cloud.getId().equals("byon")) {
// Halt, the Byon Cloud already exist
return cloud;}
}
//else, Byon cloud will be created
Cloud byonCloud = new Cloud();
byonCloud.setCloudType(CloudType.BYON);
byonCloud.setOwner("BYON");
byonCloud.setId("byon");
//Add the Byon cloud to the database
EntityManagerHelper.persist(byonCloud);
EntityManagerHelper.commit();
return byonCloud;
/* TODO :
* Check if we have to add other variables to the new cloud
*/
}
/**
* @param byonDef an Object of class ByonDefinition that contains all the nodes Definition
* @return an object of class NodeCandidate
*/
public NodeCandidate createByonNodeCandidate( ByonDefinition byonDef, String jobId) {
//create a dummy cloud
Cloud byoncloud = createByonCloud();
//set the image
Image image = new Image();
image.setOperatingSystem(byonDef.getNodeProperties().getOperatingSystem());
//image.setId("Byon_Image_"+jobId);
//set the hardware
Hardware hardware = new Hardware();
hardware.setCores(byonDef.getNodeProperties().getNumberOfCores());
hardware.setDisk((double) byonDef.getNodeProperties().getDisk());
hardware.setRam(byonDef.getNodeProperties().getMemory());
//hardware.setId("ByonHardware_"+jobId);
//set the location
Location location = new Location();
location.setGeoLocation(byonDef.getNodeProperties().getGeoLocation());
//location.setId("Byon_Location_"+jobId);
//define a dummy NC
NodeCandidate byonNC = new NodeCandidate();
//byonNC.setId("Byon_NC_"+jobId);
byonNC.setNodeCandidateType(NodeCandidate.NodeCandidateTypeEnum.BYON);
byonNC.setJobIdForBYON(jobId);
byonNC.setPrice(0.0);
byonNC.setMemoryPrice(0.0);
byonNC.setPricePerInvocation(0.0);
byonNC.setCloud(byoncloud);
byonNC.setImage(image);
byonNC.setHardware(hardware);
byonNC.setLocation(location);
return byonNC;
}
/**
* Return the List of registered BYON nodes
* @param jobId A constructed job identifier, If "0" is passed as the JobId all the Byon Nodes will be returned
......
......@@ -19,6 +19,8 @@ import java.util.Objects;
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Getter
@Setter
@Table(name = "BYON_NODE")
public class ByonNode implements Serializable {
@Id
......@@ -51,9 +53,8 @@ public class ByonNode implements Serializable {
@JsonProperty("diagnostic")
private String diagnostic = null;
@Column(name = "NODE_CANDIDATE")
@JsonProperty("nodeCandidate")
private String nodeCandidate = null;
@OneToOne(fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.REFRESH)
private NodeCandidate nodeCandidate = null;
@Column(name = "USER_ID")
@JsonProperty("userId")
......@@ -63,8 +64,6 @@ public class ByonNode implements Serializable {
@JsonProperty("allocated")
private Boolean allocated = null;
@Setter
@Getter
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
private Job job;
......@@ -149,85 +148,24 @@ public class ByonNode implements Serializable {
return this;
}
/**
* Reason this node was created
* @return reason
**/
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public ByonNode diagnostic(String diagnostic) {
this.diagnostic = diagnostic;
return this;
}
/**
* Diagnostic information about the node state
* @return diagnostic
**/
public String getDiagnostic() {
return diagnostic;
}
public void setDiagnostic(String diagnostic) {
this.diagnostic = diagnostic;
}
public ByonNode nodeCandidate(String nodeCandidate) {
this.nodeCandidate = nodeCandidate;
return this;
}
/**
* The node candidate this node was created from if applicable.
* @return nodeCandidate
**/
public String getNodeCandidate() {
return nodeCandidate;
}
public void setNodeCandidate(String nodeCandidate) {
this.nodeCandidate = nodeCandidate;
}
public ByonNode id(String id) {
this.id = id;
return this;
}
/**
* Unique identifier of this BYON.
* @return id
**/
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public ByonNode userId(String userId) {
this.userId = userId;
return this;
}
/**
* User id of the owner of this node.
* @return userId
**/
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public ByonNode allocated(Boolean allocated) {
this.allocated = allocated;
......@@ -242,11 +180,6 @@ public class ByonNode implements Serializable {
return allocated;
}
public void setAllocated(Boolean allocated) {
this.allocated = allocated;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
......
......@@ -14,6 +14,8 @@ public enum CloudType {
PUBLIC("PUBLIC"),
BYON("BYON"),
SIMULATION("SIMULATION");
private String value;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment