Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions endpoints/2-cloud-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -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`

Expand All @@ -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`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@
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;


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

@Transactional(readOnly = true)
@Query("SELECT h FROM Hardware h WHERE LOWER(h.id) LIKE CONCAT(LOWER(:cloudId), '%')")
List<Hardware> 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<String> getOrphanHardwareIds();

@Modifying(clearAutomatically = true)
@Query(value = "DELETE FROM Hardware WHERE id NOT IN (SELECT hardware.id FROM NodeCandidate GROUP BY hardware.id)")
void deleteOrphanHardwareIds();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,4 +26,8 @@ public interface LocationRepository extends JpaRepository<Location, String> {
@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<Location> findByCloudId(@Param("cloudId") String cloudId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,10 @@ public List<Image> getAllCloudImages(String sessionId) throws NotConnectedExcept
* @return A list of available hardware
*/
public List<Hardware> 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);
}

/**
Expand All @@ -406,8 +408,9 @@ public List<Hardware> getAllCloudHardware(String sessionId) throws NotConnectedE
if (!paGatewayService.isConnectionActive(sessionId)) {
throw new NotConnectedException();
}
List<Hardware> 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()
Expand All @@ -416,6 +419,7 @@ public List<Hardware> getAllCloudHardware(String sessionId) throws NotConnectedE
hardware.getName()) ||
WhiteListedInstanceTypesUtils.isHandledHardwareInstanceType(hardware.getName()))
.collect(Collectors.toList());
**/
}

/**
Expand All @@ -426,7 +430,7 @@ public List<Hardware> getAllCloudHardware(String sessionId) throws NotConnectedE
*/
public List<Location> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ public List<Hardware> listHardwares() {
return hardwareRepository.findAll();
}

/**
* List Hardware for specific clouds entries
*/
public List<Hardware> 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
Expand Down Expand Up @@ -567,6 +574,13 @@ public List<Location> listLocations() {
return locationRepository.findAll();
}

/**
* List Location for specific clouds entries
*/
public List<Location> 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
Expand Down
Loading