Skip to content

Commit

Permalink
Fixed #9 and #10, some volume fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Siewert committed Apr 5, 2019
1 parent a0ed689 commit 7bb1884
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Hetzner Cloud API for Java

Simple Java client for the Hetzner Cloud API.

The current version is **2.5.0**.
The current version is **2.5.1**.

It would be nice, if you submit pull requests.

Expand Down Expand Up @@ -37,7 +37,7 @@ Dependency:
<dependency>
<groupId>me.tomsdevsn</groupId>
<artifactId>hetznercloud-api</artifactId>
<version>2.5.0</version>
<version>2.5.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand All @@ -55,10 +55,10 @@ repositories({
})
dependencies({
compile "me.tomsdevsn:hetznercloud-api:2.5.0"
compile "me.tomsdevsn:hetznercloud-api:2.5.1"
})
```

## JavaDocs

The JavaDocs are available [here](https://docs.hcloud.tomsdevsn.me)
The JavaDocs are available [here](https://docs.hcloud.siewert.io)
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.tomsdevsn</groupId>
<artifactId>hetznercloud-api</artifactId>
<version>2.5.0</version>
<version>2.5.1</version>

<name>HetznerCloud-API</name>
<description>Java-client for the Hetzner Cloud</description>
Expand All @@ -33,8 +33,8 @@
<developer>
<id>TomSDEVSN</id>
<name>Tom Siewert</name>
<email>tom@tomsdevsn.me</email>
<url>https://tomsdevsn.me</url>
<email>tom@siewert.io</email>
<url>https://siewert.io</url>
</developer>
</developers>

Expand Down
14 changes: 11 additions & 3 deletions src/main/java/me/tomsdevsn/hetznercloud/HetznerCloudAPI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.tomsdevsn.hetznercloud;

import me.tomsdevsn.hetznercloud.exception.InvalidFormatException;
import me.tomsdevsn.hetznercloud.exception.InvalidParametersException;
import me.tomsdevsn.hetznercloud.objects.request.*;
import me.tomsdevsn.hetznercloud.objects.response.*;
Expand Down Expand Up @@ -88,9 +89,13 @@ public GetServerResponse getServerById(long id) {
* @return response of the API
*/
public ServerResponse createServer(ServerRequest serverRequest) {
serverRequest.getSshKeys().forEach(object -> {
if (!(object instanceof Long || object instanceof String)) throw new InvalidParametersException("Object not Long or String");
});
if (serverRequest.getSshKeys() != null) {
serverRequest.getSshKeys().forEach(object -> {
if (!(object instanceof Long || object instanceof String))
throw new InvalidParametersException("Object not Long or String");
});
}
serverRequest.setServerType(serverRequest.getServerType().toLowerCase()); // Case-sensitive fix
return restTemplate.postForEntity(API_URL + "/servers", new HttpEntity<>(serverRequest, httpHeaders), ServerResponse.class).getBody();
}

Expand Down Expand Up @@ -804,6 +809,9 @@ public VolumeResponse createVolume(VolumeRequest volumeRequest) {
if (volumeRequest.getSize() < 10 || volumeRequest.getSize() > 10240) throw new InvalidParametersException("Size have to be between 10 and 10240");
if (volumeRequest.getName() == null) throw new InvalidParametersException("Name must be given");
if (volumeRequest.getLocation() == null) throw new InvalidParametersException("Location must be given."); // Normally not needed, but currently if not defined, it will throw an exception
if (volumeRequest.getFormat() != null && (volumeRequest.getFormat().equals("ext4") || volumeRequest.getFormat().equals("xfs"))) throw new InvalidFormatException("Invalid filesystem. Currently only ext4 and xfs");
if ((volumeRequest.getServer() == null && volumeRequest.isAutomount())) throw new InvalidParametersException("server has to be specified if automount is used.");
volumeRequest.setFormat(volumeRequest.getFormat().toLowerCase()); // case-sensitive fix
return restTemplate.postForEntity(API_URL + "/volumes", new HttpEntity<>(volumeRequest, httpHeaders), VolumeResponse.class).getBody();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.tomsdevsn.hetznercloud.exception;

/**
* The Exception will be called, if you use an invalid format for the volume.
*/
public class InvalidFormatException extends RuntimeException {

private static final long serialVersionUID = 51574845136874L;

public InvalidFormatException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.tomsdevsn.hetznercloud.deserialize.DateDeserializer;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
public class Volume {
Expand All @@ -20,7 +22,9 @@ public class Volume {
@JsonProperty("linux_device")
private String linuxDevice;
private Protect protection;
private Map<String, String> labels = new HashMap<>();
private String status;
private String format;

@Data
public static class Protect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import lombok.Builder;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
@Builder
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UpdateVolumeRequest {

private String name;
private Map<String, String> labels = new HashMap<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import lombok.Builder;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
@Builder
@AllArgsConstructor
Expand All @@ -14,4 +17,8 @@ public class VolumeRequest {
private Long size;
private String name;
private String location;
private boolean automount;
private String format;
private Long server;
private Map<String, String> labels = new HashMap<>();
}

0 comments on commit 7bb1884

Please sign in to comment.