Skip to content

Commit 18c1201

Browse files
Generator: Update SDK /services/serverbackup (#235)
relates to STACKITSDK-252 Co-authored-by: Ruben Hoenle <Ruben.Hoenle@stackit.cloud>
1 parent 972c7b1 commit 18c1201

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+11971
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
- Bump dependency `cloud.stackit.sdk.core` to v0.4.1
3232
- [v0.1.0](services/serverupdate/CHANGELOG.md#v010)
3333
- Initial onboarding of STACKIT Java SDK for Server Update service
34+
- `serverbackup`: [v0.1.0](services/serverbackup/CHANGELOG.md#v010)
35+
- Initial onboarding of STACKIT Java SDK for serverbackup service
3436

3537
## Release (2025-10-29)
3638
- `core`:

examples/serverbackup/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dependencies {
2+
implementation project (':services:iaas')
3+
implementation project (':services:serverbackup')
4+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
5+
}
6+
7+
ext.mainClassName = 'cloud.stackit.sdk.serverbackup.examples.ServerBackupExample'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package cloud.stackit.sdk.serverbackup.examples;
2+
3+
import cloud.stackit.sdk.core.exception.ApiException;
4+
import cloud.stackit.sdk.iaas.api.IaasApi;
5+
import cloud.stackit.sdk.iaas.model.*;
6+
import cloud.stackit.sdk.serverbackup.api.ServerBackupApi;
7+
import cloud.stackit.sdk.serverbackup.model.*;
8+
import cloud.stackit.sdk.serverbackup.model.Backup;
9+
import cloud.stackit.sdk.serverbackup.model.CreateBackupPayload;
10+
import java.io.IOException;
11+
import java.util.*;
12+
import java.util.concurrent.TimeUnit;
13+
import java.util.stream.Collectors;
14+
15+
final class ServerBackupExample {
16+
private static final String REGION = "eu01";
17+
18+
private ServerBackupExample() {}
19+
20+
@SuppressWarnings({
21+
"PMD.CyclomaticComplexity",
22+
"PMD.SystemPrintln",
23+
"PMD.AvoidThrowingRawExceptionTypes"
24+
})
25+
public static void main(String[] args) throws IOException {
26+
/*
27+
* Credentials are read from the credentialsFile in `~/.stackit/credentials.json` or the env
28+
* STACKIT_SERVICE_ACCOUNT_KEY_PATH / STACKIT_SERVICE_ACCOUNT_KEY
29+
* */
30+
IaasApi iaasApi = new IaasApi();
31+
ServerBackupApi serverBackupApi = new ServerBackupApi();
32+
33+
// the id of your STACKIT project, read from env var for this example
34+
String projectIdString = System.getenv("STACKIT_PROJECT_ID");
35+
if (projectIdString == null || projectIdString.isEmpty()) {
36+
System.err.println("Environment variable 'STACKIT_PROJECT_ID' not found.");
37+
return;
38+
}
39+
UUID projectId = UUID.fromString(projectIdString);
40+
41+
// the id of your STACKIT server, read from env var for this example
42+
String serverIdString = System.getenv("STACKIT_SERVER_ID");
43+
if (serverIdString == null || serverIdString.isEmpty()) {
44+
System.err.println("Environment variable 'STACKIT_SERVER_ID' not found.");
45+
return;
46+
}
47+
UUID serverId = UUID.fromString(serverIdString);
48+
49+
try {
50+
Server server = iaasApi.getServer(projectId, serverId, true);
51+
assert server.getId() != null;
52+
assert server.getVolumes() != null;
53+
54+
// enable the backup service for the server
55+
serverBackupApi.enableServiceResource(
56+
projectIdString,
57+
server.getId().toString(),
58+
REGION,
59+
new EnableServiceResourcePayload());
60+
61+
// BACKUP POLICIES
62+
63+
// list backup policies
64+
GetBackupPoliciesResponse policies =
65+
serverBackupApi.listBackupPolicies(projectIdString);
66+
assert policies.getItems() != null;
67+
System.out.println("\nAvailable backup policies: ");
68+
for (BackupPolicy p : policies.getItems()) {
69+
System.out.println(p.getId() + " | " + p.getName());
70+
}
71+
72+
// BACKUP SCHEDULES
73+
74+
List<String> volumeIds =
75+
server.getVolumes().stream().map(UUID::toString).collect(Collectors.toList());
76+
77+
// create new backup schedule
78+
BackupSchedule newBackupSchedule =
79+
serverBackupApi.createBackupSchedule(
80+
projectIdString,
81+
server.getId().toString(),
82+
REGION,
83+
new CreateBackupSchedulePayload()
84+
.name("java-sdk-example-backup-schedule")
85+
.enabled(true)
86+
.rrule(
87+
"DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
88+
.backupProperties(
89+
new BackupProperties()
90+
.name("java-sdk-example-backup")
91+
.retentionPeriod(5)
92+
.volumeIds(volumeIds)));
93+
94+
// list backup schedules
95+
GetBackupSchedulesResponse backupSchedules =
96+
serverBackupApi.listBackupSchedules(
97+
projectIdString, server.getId().toString(), REGION);
98+
System.out.println("\nAvailable backup schedules: ");
99+
assert backupSchedules.getItems() != null;
100+
for (BackupSchedule s : backupSchedules.getItems()) {
101+
System.out.println(s.getId() + " | " + s.getName());
102+
}
103+
104+
// delete backup schedule
105+
serverBackupApi.deleteBackupSchedule(
106+
projectIdString,
107+
server.getId().toString(),
108+
REGION,
109+
newBackupSchedule.getId().toString());
110+
111+
// BACKUPS
112+
113+
// create backup
114+
BackupJob newBackup =
115+
serverBackupApi.createBackup(
116+
projectIdString,
117+
server.getId().toString(),
118+
REGION,
119+
new CreateBackupPayload()
120+
.name("java-sdk-example-single-backup")
121+
.retentionPeriod(5)
122+
.volumeIds(volumeIds));
123+
124+
// wait for creation of the backup
125+
System.out.println("\nWaiting for backup creation...");
126+
Backup.StatusEnum backupStatus;
127+
do {
128+
TimeUnit.SECONDS.sleep(30);
129+
Backup backup =
130+
serverBackupApi.getBackup(
131+
projectIdString,
132+
server.getId().toString(),
133+
REGION,
134+
newBackup.getId());
135+
backupStatus = backup.getStatus();
136+
} while (backupStatus == Backup.StatusEnum.IN_PROGRESS);
137+
System.out.println(backupStatus);
138+
139+
// list backups
140+
GetBackupsListResponse backups =
141+
serverBackupApi.listBackups(projectIdString, server.getId().toString(), REGION);
142+
System.out.println("\nAvailable backups: ");
143+
assert backups.getItems() != null;
144+
for (Backup b : backups.getItems()) {
145+
System.out.println(b.getId() + " | " + b.getName());
146+
}
147+
148+
// trigger restore of a backup
149+
serverBackupApi.restoreBackup(
150+
projectIdString,
151+
server.getId().toString(),
152+
REGION,
153+
newBackup.getId(),
154+
new RestoreBackupPayload().startServerAfterRestore(true).volumeIds(volumeIds));
155+
156+
// wait for restore of the backup
157+
System.out.println("\nWaiting for backup restore...");
158+
do {
159+
TimeUnit.SECONDS.sleep(5);
160+
Backup backup =
161+
serverBackupApi.getBackup(
162+
projectIdString,
163+
server.getId().toString(),
164+
REGION,
165+
newBackup.getId());
166+
backupStatus = backup.getStatus();
167+
} while (backupStatus == Backup.StatusEnum.IN_PROGRESS);
168+
169+
// delete backup
170+
serverBackupApi.deleteBackup(
171+
projectIdString, server.getId().toString(), REGION, newBackup.getId(), true);
172+
173+
// disable the backup service for the server
174+
serverBackupApi.disableServiceResource(
175+
projectIdString, server.getId().toString(), REGION);
176+
177+
} catch (ApiException | InterruptedException e) {
178+
throw new RuntimeException(e);
179+
}
180+
}
181+
}

services/serverbackup/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## v0.1.0
2+
- Initial onboarding of STACKIT Java SDK for serverbackup service

services/serverbackup/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# STACKIT Java SDK for STACKIT Server Backup Management API
2+
3+
- API version: 2.0
4+
5+
API endpoints for Server Backup Operations on STACKIT Servers.
6+
7+
8+
This package is part of the STACKIT Java SDK. For additional information, please visit the [GitHub repository](https://github.com/stackitcloud/stackit-sdk-java) of the SDK.
9+
10+
## Installation from Maven Central (recommended)
11+
12+
The release artifacts for this SDK submodule are available on [Maven Central](https://central.sonatype.com/artifact/cloud.stackit.sdk/serverbackup).
13+
14+
### Maven users
15+
16+
Add this dependency to your project's POM:
17+
18+
```xml
19+
<dependency>
20+
<groupId>cloud.stackit.sdk</groupId>
21+
<artifactId>serverbackup</artifactId>
22+
<version><SDK_VERSION></version>
23+
<scope>compile</scope>
24+
</dependency>
25+
```
26+
27+
### Gradle users
28+
29+
Add this dependency to your project's build file:
30+
31+
```groovy
32+
repositories {
33+
mavenCentral()
34+
}
35+
36+
dependencies {
37+
implementation "cloud.stackit.sdk:serverbackup:<SDK_VERSION>"
38+
}
39+
```
40+
41+
## Installation from local build
42+
43+
Building the API client library requires:
44+
1. Java SDK (version 11 to 21 should be supported) installed on your system
45+
46+
To install the API client library to your local Maven repository, simply execute:
47+
48+
```shell
49+
./gradlew services:serverbackup:publishToMavenLocal
50+
```
51+
52+
### Maven users
53+
54+
Add this dependency to your project's POM:
55+
56+
```xml
57+
<dependency>
58+
<groupId>cloud.stackit.sdk</groupId>
59+
<artifactId>serverbackup</artifactId>
60+
<version><SDK_VERSION></version>
61+
<scope>compile</scope>
62+
</dependency>
63+
```
64+
65+
### Gradle users
66+
67+
Add this dependency to your project's build file:
68+
69+
```groovy
70+
repositories {
71+
mavenLocal()
72+
}
73+
74+
dependencies {
75+
implementation "cloud.stackit.sdk:serverbackup:<SDK_VERSION>"
76+
}
77+
```
78+
79+
## Getting Started
80+
81+
See the [serverbackup examples](https://github.com/stackitcloud/stackit-sdk-java/tree/main/examples/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/examples).
82+
83+
## Recommendation
84+
85+
It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.

services/serverbackup/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

services/serverbackup/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
ext {
3+
jakarta_annotation_version = "1.3.5"
4+
}
5+
6+
dependencies {
7+
implementation "com.google.code.findbugs:jsr305:3.0.2"
8+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
9+
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
10+
implementation 'com.google.code.gson:gson:2.9.1'
11+
implementation 'io.gsonfire:gson-fire:1.9.0'
12+
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6'
13+
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
14+
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0'
15+
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
16+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
17+
testImplementation 'org.mockito:mockito-core:3.12.4'
18+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3'
19+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* STACKIT Server Backup Management API
3+
* API endpoints for Server Backup Operations on STACKIT Servers.
4+
*
5+
* The version of the OpenAPI document: 2.0
6+
* Contact: support@stackit.de
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
package cloud.stackit.sdk.serverbackup;
14+
15+
import cloud.stackit.sdk.core.exception.ApiException;
16+
import java.util.List;
17+
import java.util.Map;
18+
19+
/**
20+
* Callback for asynchronous API call.
21+
*
22+
* @param <T> The return type
23+
*/
24+
public interface ApiCallback<T> {
25+
/**
26+
* This is called when the API call fails.
27+
*
28+
* @param e The exception causing the failure
29+
* @param statusCode Status code of the response if available, otherwise it would be 0
30+
* @param responseHeaders Headers of the response if available, otherwise it would be null
31+
*/
32+
void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders);
33+
34+
/**
35+
* This is called when the API call succeeded.
36+
*
37+
* @param result The result deserialized from response
38+
* @param statusCode Status code of the response
39+
* @param responseHeaders Headers of the response
40+
*/
41+
void onSuccess(T result, int statusCode, Map<String, List<String>> responseHeaders);
42+
43+
/**
44+
* This is called when the API upload processing.
45+
*
46+
* @param bytesWritten bytes Written
47+
* @param contentLength content length of request body
48+
* @param done write end
49+
*/
50+
void onUploadProgress(long bytesWritten, long contentLength, boolean done);
51+
52+
/**
53+
* This is called when the API download processing.
54+
*
55+
* @param bytesRead bytes Read
56+
* @param contentLength content length of the response
57+
* @param done Read end
58+
*/
59+
void onDownloadProgress(long bytesRead, long contentLength, boolean done);
60+
}

0 commit comments

Comments
 (0)