Skip to content

Commit ad8d80d

Browse files
stackit-pipelinemarceljkSerseusWasTaken
authored
Generator: Update SDK /services/automation (#914)
Co-authored-by: Marcel Jacek <Marcel.Jacek@digits.schwarz> Co-authored-by: Jonas Schlecht <73650029+SerseusWasTaken@users.noreply.github.com>
1 parent 62dfba4 commit ad8d80d

117 files changed

Lines changed: 40562 additions & 0 deletions

File tree

Some content is hidden

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

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## Release (2026-MM-DD)
2+
3+
- `automation`: [v0.1.0](services/automation/CHANGELOG.md#v010)
4+
- Initial onboarding of STACKIT Java SDK for Automation service
25
- `objectstorage`: [v0.4.0](services/objectstorage/CHANGELOG.md#v040)
36
- `v1api`:
47
- **Feature:** New model class `RateLimitError`

‎examples/automation/build.gradle‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies {
2+
implementation project (':services:automation')
3+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
4+
}
5+
6+
ext.mainClassName = 'cloud.stackit.sdk.automation.examples.AutomationExample'
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
package cloud.stackit.sdk.automation.examples;
2+
3+
import cloud.stackit.sdk.automation.v1api.api.AutomationApi;
4+
import cloud.stackit.sdk.automation.v1api.model.*;
5+
import cloud.stackit.sdk.automation.v1api.model.VolumeExecutionResponse.StatusEnum;
6+
import cloud.stackit.sdk.core.exception.ApiException;
7+
import java.io.IOException;
8+
import java.util.*;
9+
import java.util.concurrent.TimeUnit;
10+
11+
final class AutomationExample {
12+
13+
private AutomationExample() {}
14+
15+
@SuppressWarnings({
16+
"PMD.CyclomaticComplexity",
17+
"PMD.CognitiveComplexity",
18+
"PMD.DoubleBraceInitialization",
19+
"PMD.NPathComplexity",
20+
"PMD.NcssCount",
21+
"PMD.SystemPrintln",
22+
"PMD.AvoidDuplicateLiterals",
23+
"PMD.AvoidThrowingRawExceptionTypes"
24+
})
25+
public static void main(String[] args) throws IOException {
26+
// Credentials are read from the credentialsFile in
27+
// `~/.stackit/credentials.json` or the env
28+
// STACKIT_SERVICE_ACCOUNT_KEY_PATH / STACKIT_SERVICE_ACCOUNT_KEY
29+
AutomationApi automationApi = new AutomationApi();
30+
31+
// the id of your STACKIT project, read from env var for this example
32+
String projectId = System.getenv("STACKIT_PROJECT_ID");
33+
if (projectId == null || projectId.isEmpty()) {
34+
System.err.println("Environment variable 'STACKIT_PROJECT_ID' not found.");
35+
return;
36+
}
37+
38+
// the region which should be used to interact with the automation service
39+
String region = "eu01";
40+
41+
System.out.println("Running automation v1 example\n");
42+
try {
43+
/*
44+
* ///////////////////////////////////////////////////////
45+
* // V O L U M E T E M P L A T E S //
46+
* ///////////////////////////////////////////////////////
47+
*/
48+
/* list all available volume templates */
49+
ListTemplatesResponse listTemplates =
50+
automationApi.listVolumeTemplates(projectId, region, null, null);
51+
System.out.println("Listing volume templates:");
52+
Objects.requireNonNull(listTemplates.getItems());
53+
for (Template template : listTemplates.getItems()) {
54+
System.out.println("* Template ID: " + template.getId());
55+
}
56+
/* if there is a nextPageToken, fetch next page of results */
57+
while (listTemplates.getNextPageToken() != null
58+
&& !"".equals(listTemplates.getNextPageToken())) {
59+
listTemplates =
60+
automationApi.listVolumeTemplates(
61+
projectId, region, null, listTemplates.getNextPageToken());
62+
System.out.println("Listing next page of volume templates:");
63+
Objects.requireNonNull(listTemplates.getItems());
64+
for (Template template : listTemplates.getItems()) {
65+
System.out.println("* Template ID: " + template.getId());
66+
}
67+
}
68+
69+
/* get one specific volume template */
70+
GetVolumeTemplateResponse template =
71+
automationApi.getVolumeTemplate(
72+
projectId, region, listTemplates.getItems().get(0).getId());
73+
System.out.println("\n\nFetched volume template:");
74+
System.out.println("* Template ID: " + template.getId());
75+
System.out.println("* Template name: " + template.getName());
76+
System.out.println("* Template description: " + template.getDescription());
77+
78+
/*
79+
* ///////////////////////////////////////////////////////
80+
* // V O L U M E A U T O M A T I O N //
81+
* ///////////////////////////////////////////////////////
82+
*/
83+
/* create a volume automation with a schedule trigger (daily at 02:00) */
84+
VolumeAutomation volumeAutomation =
85+
automationApi.createVolumeAutomation(
86+
projectId,
87+
region,
88+
new CreateVolumeAutomationPayload()
89+
.description(
90+
"Creates daily recovery points for all volumes with specified label")
91+
.name("My Daily Volume Recovery Point Creation Automation")
92+
.templateId(UUID.fromString(template.getId()))
93+
.input(
94+
new VolumeAutomationInput()
95+
.kind("VolumeRecoveryPointManagement")
96+
.putAdditionalProperty(
97+
"inheritVolumeLabels", true)
98+
.putAdditionalProperty(
99+
"recoveryPointLabels",
100+
Collections.singletonMap(
101+
"exampleLabelKey1",
102+
"exampleLabelValue1"))
103+
.putAdditionalProperty(
104+
"snapshotRetentionPolicy",
105+
new HashMap<String, Object>() {
106+
{
107+
put("kind", "count");
108+
put("value", 2);
109+
}
110+
})
111+
.putAdditionalProperty(
112+
"volumeLabelSelector",
113+
"myLabelkey1=myLabelValue,myLabelKey2=myOtherLabelValue"))
114+
.triggers(
115+
new AutomationTriggers()
116+
.schedule(
117+
new AutomationScheduleTrigger()
118+
.rrule(
119+
"DTSTART;TZID=Europe/Sofia:20200803T023000\nRRULE:FREQ=DAILY;INTERVAL=1"))));
120+
System.out.println("\n\nCreated volume automation:");
121+
System.out.println("* Automation ID: " + volumeAutomation.getId());
122+
System.out.println("* Automation name: " + volumeAutomation.getName());
123+
System.out.println("* Automation description: " + volumeAutomation.getDescription());
124+
125+
/* list all volume automations */
126+
ListAutomationsResponse listAutomations =
127+
automationApi.listVolumeAutomations(projectId, region, null, null);
128+
System.out.println("\n\nListing volume automations:");
129+
Objects.requireNonNull(listAutomations.getItems());
130+
for (ListAutomationsItem automation : listAutomations.getItems()) {
131+
System.out.println("* Automation ID: " + automation.getId());
132+
}
133+
/* if there is a nextPageToken, fetch next page of results */
134+
while (listAutomations.getNextPageToken() != null
135+
&& !"".equals(listAutomations.getNextPageToken())) {
136+
listAutomations =
137+
automationApi.listVolumeAutomations(
138+
projectId, region, null, listAutomations.getNextPageToken());
139+
System.out.println("\nListing next page of volume automations:");
140+
Objects.requireNonNull(listAutomations.getItems());
141+
for (ListAutomationsItem automation : listAutomations.getItems()) {
142+
System.out.println("* Automation ID: " + automation.getId());
143+
}
144+
}
145+
146+
/* update an automation */
147+
VolumeAutomation updatedAutomation =
148+
automationApi.partialUpdateVolumeAutomation(
149+
projectId,
150+
region,
151+
volumeAutomation.getId().toString(),
152+
null,
153+
new PartialUpdateVolumeAutomationPayload()
154+
.description("Updated daily recovery points automation")
155+
.name(
156+
"Updated Daily Volume Recovery Point Creation Automation"));
157+
System.out.println("\n\nUpdated volume automation:");
158+
System.out.println("* Automation ID: " + updatedAutomation.getId());
159+
System.out.println("* Automation name: " + updatedAutomation.getName());
160+
System.out.println("* Automation description: " + updatedAutomation.getDescription());
161+
162+
/* get one specific volume automation */
163+
VolumeAutomation fetchedAutomation =
164+
automationApi.getVolumeAutomation(
165+
projectId, region, volumeAutomation.getId().toString());
166+
System.out.println("\n\nFetched updated volume template:");
167+
System.out.println("* Automation ID: " + fetchedAutomation.getId());
168+
System.out.println("* Automation name: " + fetchedAutomation.getName());
169+
System.out.println("* Automation description: " + fetchedAutomation.getDescription());
170+
171+
/*
172+
* ///////////////////////////////////////////////////////
173+
* // E X E C U T I O N S //
174+
* ///////////////////////////////////////////////////////
175+
*/
176+
177+
/* trigger an automation execution */
178+
VolumeExecutionResponse createdExecution =
179+
automationApi.createVolumeExecution(
180+
projectId, region, volumeAutomation.getId().toString());
181+
System.out.println("\n\nTriggered volume automation execution:");
182+
System.out.println("* Execution ID: " + createdExecution.getId());
183+
System.out.println("* Execution status: " + createdExecution.getStatus());
184+
185+
/* wait for the automation executing to complete */
186+
while (createdExecution.getStatus() == StatusEnum.PENDING
187+
|| createdExecution.getStatus() == StatusEnum.RUNNING) {
188+
System.out.println("* Waiting for automation execution to complete ...");
189+
TimeUnit.SECONDS.sleep(2);
190+
createdExecution =
191+
automationApi.getVolumeExecution(
192+
projectId,
193+
region,
194+
volumeAutomation.getId().toString(),
195+
createdExecution.getId().toString());
196+
}
197+
System.out.println("* Automation execution completed");
198+
199+
/* list all executions of a specifc volume automation */
200+
ListExecutionsResponse listExecutions =
201+
automationApi.listVolumeExecutions(
202+
projectId, region, volumeAutomation.getId().toString(), null, null);
203+
System.out.println("\n\nListing executions of the volume automation:");
204+
Objects.requireNonNull(listExecutions.getItems());
205+
for (ListExecutionsItem execution : listExecutions.getItems()) {
206+
System.out.println("* Execution ID: " + execution.getId());
207+
}
208+
209+
/*
210+
* ///////////////////////////////////////////////////////
211+
* // D E L E T I O N //
212+
* ///////////////////////////////////////////////////////
213+
*/
214+
/* trigger deletion of the created volume automation */
215+
System.out.println("\n\nDeleting created volume automation");
216+
automationApi.deleteVolumeAutomation(
217+
projectId, region, volumeAutomation.getId().toString());
218+
System.out.printf(
219+
"* Successfully deleted automation with ID \"%s\"",
220+
volumeAutomation.getId().toString());
221+
} catch (ApiException | InterruptedException e) {
222+
throw new RuntimeException(e);
223+
}
224+
}
225+
}

0 commit comments

Comments
 (0)