Skip to content

Commit 17fdd42

Browse files
Get location & hardware by cloud (#126)
* update getHardware by cloudId * include param value for hardware and index node canidate * support location by cloud id * documentation update
1 parent 1392df6 commit 17fdd42

File tree

8 files changed

+41
-14
lines changed

8 files changed

+41
-14
lines changed

endpoints/2-cloud-endpoints.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Allows you to specify any blacklisted regions (e.g. locations). Use `null` if no
204204
🟢 GET {{protocol}}://{{sal_host}}:{{sal_port}}/sal/cloud/images
205205
```
206206

207-
**Path Variable (optional):** cloudid = {{cloud_name}}
207+
**Path Variable (optional):** `cloudid` = {{cloud_name}}
208208

209209
**Headers:** `sessionid`
210210

@@ -222,7 +222,7 @@ Allows you to specify any blacklisted regions (e.g. locations). Use `null` if no
222222
🟢 GET {{protocol}}://{{sal_host}}:{{sal_port}}/sal/cloud/location
223223
```
224224

225-
**Path Variable (optional):** cloudid = {{cloud_name}} -> TBD: this is not implemented yet
225+
**Path Variable (optional):** `cloudid` = {{cloud_name}}
226226

227227
**Headers:** `sessionid`
228228

@@ -240,7 +240,7 @@ Allows you to specify any blacklisted regions (e.g. locations). Use `null` if no
240240
🟢 GET {{protocol}}://{{sal_host}}:{{sal_port}}/sal/cloud/hardware
241241
```
242242

243-
**Path Variable (optional):** cloudid = {{cloud_name}} -> TBD: this is not implemented yet
243+
**Path Variable (optional):** `cloudid` = {{cloud_name}}
244244

245245
**Headers:** `sessionid`
246246

sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
@Accessors(chain = true)
3636
@EqualsAndHashCode
3737
@Entity
38-
@Table(name = "HARDWARE")
38+
@Table(name = "HARDWARE", indexes = { @Index(name = "idx_hardware_id", columnList = "ID") })
3939
public class Hardware implements Serializable {
4040

4141
// JSON property constants
@@ -64,7 +64,7 @@ public class Hardware implements Serializable {
6464
public static final String JSON_OWNER = "owner";
6565

6666
@Id
67-
@Column(name = "ID")
67+
@Column(name = "ID", unique = true, nullable = false)
6868
@JsonProperty(JSON_ID)
6969
private String id = null;
7070

sal-common/src/main/java/org/ow2/proactive/sal/model/Location.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@AllArgsConstructor
3333
@NoArgsConstructor
3434
@Entity
35-
@Table(name = "LOCATION")
35+
@Table(name = "LOCATION", indexes = @Index(name = "idx_location_id", columnList = "ID"))
3636
@Accessors(chain = true)
3737
@EqualsAndHashCode
3838
@Getter
@@ -57,7 +57,7 @@ public class Location implements Serializable {
5757
public static final String JSON_OWNER = "owner";
5858

5959
@Id
60-
@Column(name = "ID")
60+
@Column(name = "ID", nullable = false, unique = true)
6161
@JsonProperty(JSON_ID)
6262
private String id = null;
6363

sal-common/src/main/java/org/ow2/proactive/sal/model/NodeCandidate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
@Getter
4141
@Setter
4242
@Entity
43-
@Table(name = "NODE_CANDIDATE")
43+
@Table(name = "NODE_CANDIDATE", indexes = { @Index(name = "idx_nodecandidate_id", columnList = "ID") })
4444
public class NodeCandidate implements Serializable {
4545
public static final String JSON_ID = "id";
4646

@@ -71,7 +71,7 @@ public class NodeCandidate implements Serializable {
7171
@Id
7272
@GeneratedValue(generator = "system-uuid")
7373
@GenericGenerator(name = "system-uuid", strategy = "uuid")
74-
@Column(name = "ID")
74+
@Column(name = "ID", nullable = false, unique = true)
7575
@JsonProperty(JSON_ID)
7676
private String id = null;
7777

sal-service/src/main/java/org/ow2/proactive/sal/service/repository/HardwareRepository.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@
1111
import org.springframework.data.jpa.repository.JpaRepository;
1212
import org.springframework.data.jpa.repository.Modifying;
1313
import org.springframework.data.jpa.repository.Query;
14+
import org.springframework.data.repository.query.Param;
1415
import org.springframework.stereotype.Repository;
1516
import org.springframework.transaction.annotation.Transactional;
1617

1718

1819
@Repository
1920
public interface HardwareRepository extends JpaRepository<Hardware, String> {
2021

22+
@Transactional(readOnly = true)
23+
@Query("SELECT h FROM Hardware h WHERE LOWER(h.id) LIKE CONCAT(LOWER(:cloudId), '%')")
24+
List<Hardware> findByCloudId(@Param("cloudId") String cloudId);
25+
2126
@Transactional(readOnly = true)
2227
@Query(value = "SELECT id FROM Hardware WHERE id NOT IN (SELECT hardware.id FROM NodeCandidate GROUP BY hardware.id)")
2328
List<String> getOrphanHardwareIds();
2429

2530
@Modifying(clearAutomatically = true)
2631
@Query(value = "DELETE FROM Hardware WHERE id NOT IN (SELECT hardware.id FROM NodeCandidate GROUP BY hardware.id)")
2732
void deleteOrphanHardwareIds();
28-
2933
}

sal-service/src/main/java/org/ow2/proactive/sal/service/repository/LocationRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.data.jpa.repository.JpaRepository;
1212
import org.springframework.data.jpa.repository.Modifying;
1313
import org.springframework.data.jpa.repository.Query;
14+
import org.springframework.data.repository.query.Param;
1415
import org.springframework.stereotype.Repository;
1516
import org.springframework.transaction.annotation.Transactional;
1617

@@ -25,4 +26,8 @@ public interface LocationRepository extends JpaRepository<Location, String> {
2526
@Modifying(clearAutomatically = true)
2627
@Query(value = "DELETE FROM Location WHERE id NOT IN (SELECT location.id FROM NodeCandidate GROUP BY location.id)")
2728
void deleteOrphanLocationIds();
29+
30+
@Transactional(readOnly = true)
31+
@Query("SELECT l FROM Location l WHERE LOWER(l.id) LIKE CONCAT(LOWER(:cloudId), '%')")
32+
List<Location> findByCloudId(@Param("cloudId") String cloudId);
2833
}

sal-service/src/main/java/org/ow2/proactive/sal/service/service/CloudService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,10 @@ public List<Image> getAllCloudImages(String sessionId) throws NotConnectedExcept
403403
* @return A list of available hardware
404404
*/
405405
public List<Hardware> getCloudHardware(String sessionId, String cloudId) throws NotConnectedException {
406-
LOGGER.warn("Feature not implemented yet. All hardware will be returned.");
407-
return getAllCloudHardware(sessionId);
406+
if (!paGatewayService.isConnectionActive(sessionId)) {
407+
throw new NotConnectedException();
408+
}
409+
return repositoryService.listHardwares(cloudId);
408410
}
409411

410412
/**
@@ -416,8 +418,9 @@ public List<Hardware> getAllCloudHardware(String sessionId) throws NotConnectedE
416418
if (!paGatewayService.isConnectionActive(sessionId)) {
417419
throw new NotConnectedException();
418420
}
419-
List<Hardware> allHardware = repositoryService.listHardwares();
421+
return repositoryService.listHardwares();
420422

423+
/** only defined for the AWS and JClouds -> braking since Azure is integrated
421424
return allHardware.stream()
422425
.filter(hardware -> JCloudsInstancesUtils.isHandledHardwareInstanceType(repositoryService.findFirstNodeCandidateWithHardware(hardware)
423426
.getCloud()
@@ -426,6 +429,7 @@ public List<Hardware> getAllCloudHardware(String sessionId) throws NotConnectedE
426429
hardware.getName()) ||
427430
WhiteListedInstanceTypesUtils.isHandledHardwareInstanceType(hardware.getName()))
428431
.collect(Collectors.toList());
432+
**/
429433
}
430434

431435
/**
@@ -436,7 +440,7 @@ public List<Hardware> getAllCloudHardware(String sessionId) throws NotConnectedE
436440
*/
437441
public List<Location> getCloudLocations(String sessionId, String cloudId) throws NotConnectedException {
438442
LOGGER.warn("Feature not implemented yet. All locations will be returned.");
439-
return getAllCloudLocations(sessionId);
443+
return repositoryService.listLocations(cloudId);
440444
}
441445

442446
/**

sal-service/src/main/java/org/ow2/proactive/sal/service/service/RepositoryService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,13 @@ public List<Hardware> listHardwares() {
404404
return hardwareRepository.findAll();
405405
}
406406

407+
/**
408+
* List Hardware for specific clouds entries
409+
*/
410+
public List<Hardware> listHardwares(String cloudId) {
411+
return hardwareRepository.findByCloudId(cloudId);
412+
}
413+
407414
/**
408415
* Add or update the instance data given in param
409416
* @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<Location> listLocations() {
567574
return locationRepository.findAll();
568575
}
569576

577+
/**
578+
* List Location for specific clouds entries
579+
*/
580+
public List<Location> listLocations(String cloudId) {
581+
return locationRepository.findByCloudId(cloudId);
582+
}
583+
570584
/**
571585
* Add or update the instance data given in param
572586
* @param location is the instance data to add or update, its instance id will be use as a key

0 commit comments

Comments
 (0)