Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
- Bump dependency `cloud.stackit.sdk.core` to v0.4.1
- [v0.1.0](services/serverupdate/CHANGELOG.md#v010)
- Initial onboarding of STACKIT Java SDK for Server Update service
- `serverbackup`: [v0.1.0](services/serverbackup/CHANGELOG.md#v010)
- Initial onboarding of STACKIT Java SDK for serverbackup service

## Release (2025-10-29)
- `core`:
Expand Down
7 changes: 7 additions & 0 deletions examples/serverbackup/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies {
implementation project (':services:iaas')
implementation project (':services:serverbackup')
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
}

ext.mainClassName = 'cloud.stackit.sdk.serverbackup.examples.ServerBackupExample'
1 change: 1 addition & 0 deletions examples/serverbackup/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
package cloud.stackit.sdk.serverbackup.examples;

import cloud.stackit.sdk.core.exception.ApiException;
import cloud.stackit.sdk.iaas.api.IaasApi;
import cloud.stackit.sdk.iaas.model.*;
import cloud.stackit.sdk.serverbackup.api.ServerBackupApi;
import cloud.stackit.sdk.serverbackup.model.*;
import cloud.stackit.sdk.serverbackup.model.Backup;
import cloud.stackit.sdk.serverbackup.model.CreateBackupPayload;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

final class ServerBackupExample {
private static final String REGION = "eu01";

private ServerBackupExample() {}

@SuppressWarnings({
"PMD.CyclomaticComplexity",
"PMD.CognitiveComplexity",
"PMD.NPathComplexity",
"PMD.NcssCount",
"PMD.SystemPrintln",
"PMD.AvoidThrowingRawExceptionTypes"
})
public static void main(String[] args) throws IOException {
/*
* Credentials are read from the credentialsFile in `~/.stackit/credentials.json` or the env
* STACKIT_SERVICE_ACCOUNT_KEY_PATH / STACKIT_SERVICE_ACCOUNT_KEY
* */
IaasApi iaasApi = new IaasApi();
ServerBackupApi serverBackupApi = new ServerBackupApi();

// the id of your STACKIT project, read from env var for this example
String projectIdString = System.getenv("STACKIT_PROJECT_ID");
if (projectIdString == null || projectIdString.isEmpty()) {
System.err.println("Environment variable 'STACKIT_PROJECT_ID' not found.");
return;
}
UUID projectId = UUID.fromString(projectIdString);

// the id of your STACKIT server, read from env var for this example
String serverIdString = System.getenv("STACKIT_SERVER_ID");
if (serverIdString == null || serverIdString.isEmpty()) {
System.err.println("Environment variable 'STACKIT_SERVER_ID' not found.");
return;
}
UUID serverId = UUID.fromString(serverIdString);

try {
Server server = iaasApi.getServer(projectId, serverId, true);
assert server.getId() != null;
assert server.getVolumes() != null;

// enable the backup service for the server
serverBackupApi.enableServiceResource(
projectIdString,
server.getId().toString(),
REGION,
new EnableServiceResourcePayload());

// BACKUP POLICIES

// list backup policies
GetBackupPoliciesResponse policies =
serverBackupApi.listBackupPolicies(projectIdString);
assert policies.getItems() != null;
System.out.println("\nAvailable backup policies: ");
for (BackupPolicy p : policies.getItems()) {
System.out.println(p.getId() + " | " + p.getName());
}

// BACKUP SCHEDULES

List<String> volumeIds =
server.getVolumes().stream().map(UUID::toString).collect(Collectors.toList());

// create new backup schedule
BackupSchedule newBackupSchedule =
serverBackupApi.createBackupSchedule(
projectIdString,
server.getId().toString(),
REGION,
new CreateBackupSchedulePayload()
.name("java-sdk-example-backup-schedule")
.enabled(true)
.rrule(
"DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
.backupProperties(
new BackupProperties()
.name("java-sdk-example-backup")
.retentionPeriod(5)
.volumeIds(volumeIds)));

// list backup schedules
GetBackupSchedulesResponse backupSchedules =
serverBackupApi.listBackupSchedules(
projectIdString, server.getId().toString(), REGION);
System.out.println("\nAvailable backup schedules: ");
assert backupSchedules.getItems() != null;
for (BackupSchedule s : backupSchedules.getItems()) {
System.out.println(s.getId() + " | " + s.getName());
}

// delete backup schedule
serverBackupApi.deleteBackupSchedule(
projectIdString,
server.getId().toString(),
REGION,
newBackupSchedule.getId().toString());

// BACKUPS

// create backup
BackupJob newBackup =
serverBackupApi.createBackup(
projectIdString,
server.getId().toString(),
REGION,
new CreateBackupPayload()
.name("java-sdk-example-single-backup")
.retentionPeriod(5)
.volumeIds(volumeIds));

// wait for creation of the backup
System.out.println("\nWaiting for backup creation...");
Backup.StatusEnum backupStatus;
do {
TimeUnit.SECONDS.sleep(30);
Backup backup =
serverBackupApi.getBackup(
projectIdString,
server.getId().toString(),
REGION,
newBackup.getId());
backupStatus = backup.getStatus();
} while (backupStatus == Backup.StatusEnum.IN_PROGRESS);
System.out.println(backupStatus);

// list backups
GetBackupsListResponse backups =
serverBackupApi.listBackups(projectIdString, server.getId().toString(), REGION);
System.out.println("\nAvailable backups: ");
assert backups.getItems() != null;
for (Backup b : backups.getItems()) {
System.out.println(b.getId() + " | " + b.getName());
}

// trigger restore of a backup
serverBackupApi.restoreBackup(
projectIdString,
server.getId().toString(),
REGION,
newBackup.getId(),
new RestoreBackupPayload().startServerAfterRestore(true).volumeIds(volumeIds));

// wait for restore of the backup
System.out.println("\nWaiting for backup restore...");
do {
TimeUnit.SECONDS.sleep(5);
Backup backup =
serverBackupApi.getBackup(
projectIdString,
server.getId().toString(),
REGION,
newBackup.getId());
backupStatus = backup.getStatus();
} while (backupStatus == Backup.StatusEnum.IN_PROGRESS);

// delete backup
serverBackupApi.deleteBackup(
projectIdString, server.getId().toString(), REGION, newBackup.getId(), true);

// disable the backup service for the server
serverBackupApi.disableServiceResource(
projectIdString, server.getId().toString(), REGION);

} catch (ApiException | InterruptedException e) {
throw new RuntimeException(e);
}
}
}
2 changes: 2 additions & 0 deletions services/serverbackup/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## v0.1.0
- Initial onboarding of STACKIT Java SDK for serverbackup service
85 changes: 85 additions & 0 deletions services/serverbackup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# STACKIT Java SDK for STACKIT Server Backup Management API

- API version: 2.0

API endpoints for Server Backup Operations on STACKIT Servers.


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.

## Installation from Maven Central (recommended)

The release artifacts for this SDK submodule are available on [Maven Central](https://central.sonatype.com/artifact/cloud.stackit.sdk/serverbackup).

### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
<groupId>cloud.stackit.sdk</groupId>
<artifactId>serverbackup</artifactId>
<version><SDK_VERSION></version>
<scope>compile</scope>
</dependency>
```

### Gradle users

Add this dependency to your project's build file:

```groovy
repositories {
mavenCentral()
}

dependencies {
implementation "cloud.stackit.sdk:serverbackup:<SDK_VERSION>"
}
```

## Installation from local build

Building the API client library requires:
1. Java SDK (version 11 to 21 should be supported) installed on your system

To install the API client library to your local Maven repository, simply execute:

```shell
./gradlew services:serverbackup:publishToMavenLocal
```

### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
<groupId>cloud.stackit.sdk</groupId>
<artifactId>serverbackup</artifactId>
<version><SDK_VERSION></version>
<scope>compile</scope>
</dependency>
```

### Gradle users

Add this dependency to your project's build file:

```groovy
repositories {
mavenLocal()
}

dependencies {
implementation "cloud.stackit.sdk:serverbackup:<SDK_VERSION>"
}
```

## Getting Started

See the [serverbackup examples](https://github.com/stackitcloud/stackit-sdk-java/tree/main/examples/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/examples).

## Recommendation

It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.
1 change: 1 addition & 0 deletions services/serverbackup/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
19 changes: 19 additions & 0 deletions services/serverbackup/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

ext {
jakarta_annotation_version = "1.3.5"
}

dependencies {
implementation "com.google.code.findbugs:jsr305:3.0.2"
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'io.gsonfire:gson-fire:1.9.0'
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6'
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0'
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
testImplementation 'org.mockito:mockito-core:3.12.4'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* STACKIT Server Backup Management API
* API endpoints for Server Backup Operations on STACKIT Servers.
*
* The version of the OpenAPI document: 2.0
* Contact: support@stackit.de
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package cloud.stackit.sdk.serverbackup;

import cloud.stackit.sdk.core.exception.ApiException;
import java.util.List;
import java.util.Map;

/**
* Callback for asynchronous API call.
*
* @param <T> The return type
*/
public interface ApiCallback<T> {
/**
* This is called when the API call fails.
*
* @param e The exception causing the failure
* @param statusCode Status code of the response if available, otherwise it would be 0
* @param responseHeaders Headers of the response if available, otherwise it would be null
*/
void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders);

/**
* This is called when the API call succeeded.
*
* @param result The result deserialized from response
* @param statusCode Status code of the response
* @param responseHeaders Headers of the response
*/
void onSuccess(T result, int statusCode, Map<String, List<String>> responseHeaders);

/**
* This is called when the API upload processing.
*
* @param bytesWritten bytes Written
* @param contentLength content length of request body
* @param done write end
*/
void onUploadProgress(long bytesWritten, long contentLength, boolean done);

/**
* This is called when the API download processing.
*
* @param bytesRead bytes Read
* @param contentLength content length of the response
* @param done Read end
*/
void onDownloadProgress(long bytesRead, long contentLength, boolean done);
}
Loading