diff --git a/endpoints/2-cloud-endpoints.md b/endpoints/2-cloud-endpoints.md index 07561ae0..1fdf12f7 100644 --- a/endpoints/2-cloud-endpoints.md +++ b/endpoints/2-cloud-endpoints.md @@ -204,7 +204,7 @@ Allows you to specify any blacklisted regions (e.g. locations). Use `null` if no 🟢 GET {{protocol}}://{{sal_host}}:{{sal_port}}/sal/cloud/images ``` -**Path Variable (optional):** cloudid = {{cloud_name}} +**Path Variable (optional):** `cloudid` = {{cloud_name}} **Headers:** `sessionid` @@ -222,7 +222,7 @@ Allows you to specify any blacklisted regions (e.g. locations). Use `null` if no 🟢 GET {{protocol}}://{{sal_host}}:{{sal_port}}/sal/cloud/location ``` -**Path Variable (optional):** cloudid = {{cloud_name}} -> TBD: this is not implemented yet +**Path Variable (optional):** `cloudid` = {{cloud_name}} **Headers:** `sessionid` @@ -240,7 +240,7 @@ Allows you to specify any blacklisted regions (e.g. locations). Use `null` if no 🟢 GET {{protocol}}://{{sal_host}}:{{sal_port}}/sal/cloud/hardware ``` -**Path Variable (optional):** cloudid = {{cloud_name}} -> TBD: this is not implemented yet +**Path Variable (optional):** `cloudid` = {{cloud_name}} **Headers:** `sessionid` diff --git a/sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java b/sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java index 9fe5fed8..eac816f3 100644 --- a/sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java +++ b/sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java @@ -35,7 +35,7 @@ @Accessors(chain = true) @EqualsAndHashCode @Entity -@Table(name = "HARDWARE") +@Table(name = "HARDWARE", indexes = { @Index(name = "idx_hardware_id", columnList = "ID") }) public class Hardware implements Serializable { // JSON property constants @@ -64,7 +64,7 @@ public class Hardware implements Serializable { public static final String JSON_OWNER = "owner"; @Id - @Column(name = "ID") + @Column(name = "ID", unique = true, nullable = false) @JsonProperty(JSON_ID) private String id = null; diff --git a/sal-common/src/main/java/org/ow2/proactive/sal/model/Location.java b/sal-common/src/main/java/org/ow2/proactive/sal/model/Location.java index bd7041d1..f3cbe878 100644 --- a/sal-common/src/main/java/org/ow2/proactive/sal/model/Location.java +++ b/sal-common/src/main/java/org/ow2/proactive/sal/model/Location.java @@ -32,7 +32,7 @@ @AllArgsConstructor @NoArgsConstructor @Entity -@Table(name = "LOCATION") +@Table(name = "LOCATION", indexes = @Index(name = "idx_location_id", columnList = "ID")) @Accessors(chain = true) @EqualsAndHashCode @Getter @@ -57,7 +57,7 @@ public class Location implements Serializable { public static final String JSON_OWNER = "owner"; @Id - @Column(name = "ID") + @Column(name = "ID", nullable = false, unique = true) @JsonProperty(JSON_ID) private String id = null; diff --git a/sal-common/src/main/java/org/ow2/proactive/sal/model/NodeCandidate.java b/sal-common/src/main/java/org/ow2/proactive/sal/model/NodeCandidate.java index 70216de4..bc5cbabf 100644 --- a/sal-common/src/main/java/org/ow2/proactive/sal/model/NodeCandidate.java +++ b/sal-common/src/main/java/org/ow2/proactive/sal/model/NodeCandidate.java @@ -40,7 +40,7 @@ @Getter @Setter @Entity -@Table(name = "NODE_CANDIDATE") +@Table(name = "NODE_CANDIDATE", indexes = { @Index(name = "idx_nodecandidate_id", columnList = "ID") }) public class NodeCandidate implements Serializable { public static final String JSON_ID = "id"; @@ -71,7 +71,7 @@ public class NodeCandidate implements Serializable { @Id @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - @Column(name = "ID") + @Column(name = "ID", nullable = false, unique = true) @JsonProperty(JSON_ID) private String id = null; diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/repository/HardwareRepository.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/repository/HardwareRepository.java index 8347906f..b019ee8b 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/repository/HardwareRepository.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/repository/HardwareRepository.java @@ -11,6 +11,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -18,6 +19,10 @@ @Repository public interface HardwareRepository extends JpaRepository { + @Transactional(readOnly = true) + @Query("SELECT h FROM Hardware h WHERE LOWER(h.id) LIKE CONCAT(LOWER(:cloudId), '%')") + List findByCloudId(@Param("cloudId") String cloudId); + @Transactional(readOnly = true) @Query(value = "SELECT id FROM Hardware WHERE id NOT IN (SELECT hardware.id FROM NodeCandidate GROUP BY hardware.id)") List getOrphanHardwareIds(); @@ -25,5 +30,4 @@ public interface HardwareRepository extends JpaRepository { @Modifying(clearAutomatically = true) @Query(value = "DELETE FROM Hardware WHERE id NOT IN (SELECT hardware.id FROM NodeCandidate GROUP BY hardware.id)") void deleteOrphanHardwareIds(); - } diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/repository/LocationRepository.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/repository/LocationRepository.java index fec65fc6..43d27625 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/repository/LocationRepository.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/repository/LocationRepository.java @@ -11,6 +11,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -25,4 +26,8 @@ public interface LocationRepository extends JpaRepository { @Modifying(clearAutomatically = true) @Query(value = "DELETE FROM Location WHERE id NOT IN (SELECT location.id FROM NodeCandidate GROUP BY location.id)") void deleteOrphanLocationIds(); + + @Transactional(readOnly = true) + @Query("SELECT l FROM Location l WHERE LOWER(l.id) LIKE CONCAT(LOWER(:cloudId), '%')") + List findByCloudId(@Param("cloudId") String cloudId); } diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/CloudService.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/CloudService.java index 46742039..fa5acd30 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/CloudService.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/CloudService.java @@ -393,8 +393,10 @@ public List getAllCloudImages(String sessionId) throws NotConnectedExcept * @return A list of available hardware */ public List getCloudHardware(String sessionId, String cloudId) throws NotConnectedException { - LOGGER.warn("Feature not implemented yet. All hardware will be returned."); - return getAllCloudHardware(sessionId); + if (!paGatewayService.isConnectionActive(sessionId)) { + throw new NotConnectedException(); + } + return repositoryService.listHardwares(cloudId); } /** @@ -406,8 +408,9 @@ public List getAllCloudHardware(String sessionId) throws NotConnectedE if (!paGatewayService.isConnectionActive(sessionId)) { throw new NotConnectedException(); } - List allHardware = repositoryService.listHardwares(); + return repositoryService.listHardwares(); + /** only defined for the AWS and JClouds -> braking since Azure is integrated return allHardware.stream() .filter(hardware -> JCloudsInstancesUtils.isHandledHardwareInstanceType(repositoryService.findFirstNodeCandidateWithHardware(hardware) .getCloud() @@ -416,6 +419,7 @@ public List getAllCloudHardware(String sessionId) throws NotConnectedE hardware.getName()) || WhiteListedInstanceTypesUtils.isHandledHardwareInstanceType(hardware.getName())) .collect(Collectors.toList()); + **/ } /** @@ -426,7 +430,7 @@ public List getAllCloudHardware(String sessionId) throws NotConnectedE */ public List getCloudLocations(String sessionId, String cloudId) throws NotConnectedException { LOGGER.warn("Feature not implemented yet. All locations will be returned."); - return getAllCloudLocations(sessionId); + return repositoryService.listLocations(cloudId); } /** diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/RepositoryService.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/RepositoryService.java index 074fd2b0..c67876f2 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/RepositoryService.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/RepositoryService.java @@ -404,6 +404,13 @@ public List listHardwares() { return hardwareRepository.findAll(); } + /** + * List Hardware for specific clouds entries + */ + public List listHardwares(String cloudId) { + return hardwareRepository.findByCloudId(cloudId); + } + /** * Add or update the instance data given in param * @param hardware is the instance data to add or update, its instance id will be use as a key @@ -567,6 +574,13 @@ public List listLocations() { return locationRepository.findAll(); } + /** + * List Location for specific clouds entries + */ + public List listLocations(String cloudId) { + return locationRepository.findByCloudId(cloudId); + } + /** * Add or update the instance data given in param * @param location is the instance data to add or update, its instance id will be use as a key