Skip to content

Commit

Permalink
refactor Location - PACloud
Browse files Browse the repository at this point in the history
  • Loading branch information
ankicabarisic committed Dec 20, 2024
1 parent b171045 commit fa053ad
Show file tree
Hide file tree
Showing 20 changed files with 261 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import lombok.Getter;
import lombok.Setter;


@Getter
@Setter
@MappedSuperclass
public abstract class AbstractNode implements Node {

// JSON field constants
public static final String JSON_ID = "id";

public static final String JSON_NODE_CANDIDATE = "nodeCandidate";

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
package org.ow2.proactive.sal.model;

import java.io.Serializable;
import java.util.Objects;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Embeddable;

import org.ow2.proactive.sal.util.ModelUtils;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;


/**
Expand All @@ -23,85 +29,36 @@
@AllArgsConstructor
@NoArgsConstructor
@Embeddable
@EqualsAndHashCode
@Getter
@Setter
public class CloudCredential implements Serializable {
public static final String JSON_USER = "user";

public static final String JSON_SECRET = "secret";

@Column(name = "USER")
@JsonProperty("user")
@JsonProperty(JSON_USER)
private String user = null;

@Column(name = "SECRET")
@JsonProperty("secret")
@JsonProperty(JSON_SECRET)
private String secret = null;

public CloudCredential user(String user) {
this.user = user;
return this;
}

/**
* Username for authentication at the cloud provider's API
* @return user
**/
public String getUser() {
return user;
}

public void setUser(String user) {
this.user = user;
}

public CloudCredential secret(String secret) {
this.secret = secret;
return this;
}

/**
* Secret (e.g. Password) for authentication at the cloud provider's API
* @return secret
**/
public String getSecret() {
return secret;
}

public void setSecret(String secret) {
this.secret = secret;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CloudCredential cloudCredential = (CloudCredential) o;
return Objects.equals(this.user, cloudCredential.user) && Objects.equals(this.secret, cloudCredential.secret);
}

@Override
public int hashCode() {
return Objects.hash(user, secret);
}

* Custom toString() method for the class to format the output.
* This method creates a formatted string representation of the class object.
* It uses a map of field names (represented as JSON constants) and their corresponding values
* to build a human-readable string. The method leverages the {@link ModelUtils#buildToString}
* utility method to generate the string, ensuring that all fields are included with proper formatting.
*
* @return A formatted string representation of the Hardware object, with each field on a new line.
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class CloudCredential {\n");

sb.append(" user: ").append(toIndentedString(user)).append("\n");
sb.append(" secret: ").append(toIndentedString(secret)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
Map<String, Object> fields = new LinkedHashMap<>();
fields.put(JSON_USER, user);
fields.put(JSON_SECRET, secret);
return ModelUtils.buildToString(getClass().getSimpleName(), fields);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import javax.persistence.*;
import javax.ws.rs.NotSupportedException;

import org.ow2.proactive.sal.util.ModelUtils;

import com.fasterxml.jackson.annotation.*;

import lombok.*;
Expand Down Expand Up @@ -129,6 +131,15 @@ private void setTaskById(String taskId) {
this.task.addDeployment(this);
}

/**
* Custom toString() method for the class to format the output.
* This method creates a formatted string representation of the class object.
* It uses a map of field names (represented as JSON constants) and their corresponding values
* to build a human-readable string. The method leverages the {@link ModelUtils#buildToString}
* utility method to generate the string, ensuring that all fields are included with proper formatting.
*
* @return A formatted string representation of the Hardware object, with each field on a new line.
*/
@Override
public String toString() {
String commonFields = JSON_NODE_NAME + "='" + nodeName + "', " + JSON_IS_DEPLOYED + "='" + isDeployed + "', " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ public String composeNodeSourceName() {
return "EDGE_NS_" + this.systemArch + "_" + this.id;
}

/**
* Custom toString() method for the class to format the output.
* This method creates a formatted string representation of the class object.
* It uses a map of field names (represented as JSON constants) and their corresponding values
* to build a human-readable string. The method leverages the {@link ModelUtils#buildToString}
* utility method to generate the string, ensuring that all fields are included with proper formatting.
*
* @return A formatted string representation of the Hardware object, with each field on a new line.
*/
@Override
public String toString() {
Map<String, Object> fields = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package org.ow2.proactive.sal.model;

import java.io.Serializable;
import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

import org.ow2.proactive.sal.util.ModelUtils;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.ow2.proactive.sal.util.ModelUtils;


/**
* Node candidate environment
Expand All @@ -36,6 +44,15 @@ public class Environment implements Serializable {
@JsonProperty(JSON_RUNTIME)
private Runtime runtime = null;

/**
* Custom toString() method for the class to format the output.
* This method creates a formatted string representation of the class object.
* It uses a map of field names (represented as JSON constants) and their corresponding values
* to build a human-readable string. The method leverages the {@link ModelUtils#buildToString}
* utility method to generate the string, ensuring that all fields are included with proper formatting.
*
* @return A formatted string representation of the Hardware object, with each field on a new line.
*/
@Override
public String toString() {
// Using LinkedHashMap to preserve field order
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package org.ow2.proactive.sal.model;

import java.io.Serializable;
Expand All @@ -7,14 +12,15 @@
import javax.persistence.Column;
import javax.persistence.Embeddable;

import org.ow2.proactive.sal.util.ModelUtils;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.ow2.proactive.sal.util.ModelUtils;


/**
Expand All @@ -30,8 +36,11 @@ public class GeoLocation implements Serializable {

// JSON field names as constants
public static final String JSON_CITY = "city";

public static final String JSON_COUNTRY = "country";

public static final String JSON_LATITUDE = "latitude";

public static final String JSON_LONGITUDE = "longitude";

@Column(name = "CITY")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ public boolean equals(Object o) {
}

public String toString() {
return "GeoLocationData{" +
GeoLocation.JSON_CITY + "='" + city + '\'' +
", " + GeoLocation.JSON_COUNTRY + "='" + country + '\'' +
", " + GeoLocation.JSON_LATITUDE + "=" + latitude +
", " + GeoLocation.JSON_LONGITUDE + "=" + longitude +
", region='" + region + '\'' +
", cloud='" + cloud + '\'' +
'}';
return "GeoLocationData{" + GeoLocation.JSON_CITY + "='" + city + '\'' + ", " + GeoLocation.JSON_COUNTRY +
"='" + country + '\'' + ", " + GeoLocation.JSON_LATITUDE + "=" + latitude + ", " +
GeoLocation.JSON_LONGITUDE + "=" + longitude + ", region='" + region + '\'' + ", cloud='" + cloud +
'\'' + '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
@Entity
@Table(name = "HARDWARE")
public class Hardware implements Serializable {
// Class name constant
public static final String CLASS_NAME = "Hardware";

// JSON property constants
public static final String JSON_ID = "id";
Expand Down Expand Up @@ -255,8 +253,8 @@ public void setCloudGpu(CloudProviderType cloudProvider, String machineType) {
}

/**
* Custom toString() method for the Hardware class to format the output.
* This method creates a formatted string representation of the Hardware object.
* Custom toString() method for the class to format the output.
* This method creates a formatted string representation of the class object.
* It uses a map of field names (represented as JSON constants) and their corresponding values
* to build a human-readable string. The method leverages the {@link ModelUtils#buildToString}
* utility method to generate the string, ensuring that all fields are included with proper formatting.
Expand All @@ -279,7 +277,7 @@ public String toString() {
fields.put(JSON_STATE, state);
fields.put(JSON_OWNER, owner);

return ModelUtils.buildToString(CLASS_NAME, fields);
return ModelUtils.buildToString(getClass().getSimpleName(), fields);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

import java.util.LinkedHashMap;
import java.util.Map;
import org.ow2.proactive.sal.util.ModelUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import org.ow2.proactive.sal.util.ModelUtils;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
Expand All @@ -21,6 +22,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;


@AllArgsConstructor
@NoArgsConstructor
@Entity
Expand Down
15 changes: 12 additions & 3 deletions sal-common/src/main/java/org/ow2/proactive/sal/model/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
package org.ow2.proactive.sal.model;

import java.io.Serializable;

import javax.persistence.*;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.persistence.*;

import org.ow2.proactive.sal.util.ModelUtils;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -34,6 +35,8 @@
@Entity
@Table(name = "IMAGE")
public class Image implements Serializable {

// JSON property constants
public static final String JSON_ID = "id";

public static final String JSON_NAME = "name";
Expand Down Expand Up @@ -79,7 +82,13 @@ public class Image implements Serializable {
private String owner = null;

/**
* Custom toString() method for the Image class to format the output
* Custom toString() method for the class to format the output.
* This method creates a formatted string representation of the class object.
* It uses a map of field names (represented as JSON constants) and their corresponding values
* to build a human-readable string. The method leverages the {@link ModelUtils#buildToString}
* utility method to generate the string, ensuring that all fields are included with proper formatting.
*
* @return A formatted string representation of the Hardware object, with each field on a new line.
*/
@Override
public String toString() {
Expand Down
Loading

0 comments on commit fa053ad

Please sign in to comment.