Skip to content

Commit 22e3474

Browse files
authored
feat: onboard resource manager (#2)
* generate resource manager
1 parent 0da8476 commit 22e3474

Some content is hidden

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

47 files changed

+12917
-0
lines changed

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# Package Files #
8+
*.jar
9+
*.war
10+
*.nar
11+
*.ear
12+
*.zip
13+
*.tar.gz
14+
*.rar
15+
16+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
17+
hs_err_pid*
18+
replay_pid*
19+
20+
# Gradle
21+
.gradle
22+
**/build/
23+
!**/src/**/build/
24+
25+
# Ignore Gradle GUI config
26+
gradle-app.setting
27+
28+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
29+
!gradle-wrapper.jar
30+
31+
# Avoid ignore Gradle wrappper properties
32+
!gradle-wrapper.properties
33+
34+
# Cache of project
35+
.gradletasknamecache
36+
37+
# Eclipse Gradle plugin generated files
38+
# Eclipse Core
39+
.project
40+
# JDT-specific (Eclipse Java Development Tools)
41+
.classpath

services/resourcemanager/README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# stackit-sdk-resourcemanager
2+
3+
Resource Manager API
4+
5+
- API version: 2.0
6+
7+
API v2 to manage resource containers - organizations, folders, projects incl. labels
8+
9+
### Resource Management
10+
STACKIT resource management handles the terms _Organization_, _Folder_, _Project_, _Label_, and the hierarchical structure between them. Technically, organizations,
11+
folders, and projects are _Resource Containers_ to which a _Label_ can be attached to. The STACKIT _Resource Manager_ provides CRUD endpoints to query and to modify the state.
12+
13+
### Organizations
14+
STACKIT organizations are the base element to create and to use cloud-resources. An organization is bound to one customer account. Organizations have a lifecycle.
15+
- Organizations are always the root node in resource hierarchy and do not have a parent
16+
17+
### Projects
18+
STACKIT projects are needed to use cloud-resources. Projects serve as wrapper for underlying technical structures and processes. Projects have a lifecycle. Projects compared to folders may have different policies.
19+
- Projects are optional, but mandatory for cloud-resource usage
20+
- A project can be created having either an organization, or a folder as parent
21+
- A project must not have a project as parent
22+
- Project names under the same parent must not be unique
23+
- Root organization cannot be changed
24+
25+
### Label
26+
STACKIT labels are key-value pairs including a resource container reference. Labels can be defined and attached freely to resource containers by which resources can be organized and queried.
27+
- Policy-based, immutable labels may exists
28+
29+
For more information, please visit [https://support.stackit.cloud/servicedesk](https://support.stackit.cloud/servicedesk)
30+
31+
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.
32+
33+
34+
## Requirements
35+
36+
Building the API client library requires:
37+
1. Java 1.8+
38+
39+
## Installation
40+
41+
To install the API client library to your local Maven repository, simply execute:
42+
43+
```shell
44+
./gradlew publishToMavenLocal
45+
```
46+
47+
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
48+
49+
```shell
50+
# TODO: follow up story
51+
# ./gradlew publishToMavenCentral
52+
```
53+
54+
Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.
55+
56+
### Maven users
57+
58+
Add this dependency to your project's POM:
59+
60+
```xml
61+
<dependency>
62+
<groupId>cloud.stackit</groupId>
63+
<artifactId>stackit-sdk-resourcemanager</artifactId>
64+
<version><SDK_VERSION></version>
65+
<scope>compile</scope>
66+
</dependency>
67+
```
68+
69+
### Gradle users
70+
71+
Add this dependency to your project's build file:
72+
73+
```groovy
74+
repositories {
75+
mavenCentral() // Needed if the 'stackit-sdk-resourcemanager' jar has been published to maven central.
76+
mavenLocal() // Needed if the 'stackit-sdk-resourcemanager' jar has been published to the local maven repo.
77+
}
78+
79+
dependencies {
80+
implementation "cloud.stackit:stackit-sdk-resourcemanager:<SDK_VERSION>"
81+
}
82+
```
83+
84+
### Others
85+
86+
At first generate the JAR by executing:
87+
88+
```shell
89+
mvn clean package
90+
```
91+
92+
Then manually install the following JARs:
93+
94+
- `target/stackit-sdk-resourcemanager-<SDK_VERSION>.jar`
95+
- `target/lib/*.jar`
96+
97+
## Getting Started
98+
99+
Please follow the [installation](#installation) instruction and execute the following Java code:
100+
101+
```java
102+
103+
import cloud.stackit.sdk.resourcemanager.*;
104+
import cloud.stackit.sdk.resourcemanager.auth.*;
105+
import cloud.stackit.sdk.resourcemanager.model.*;
106+
import cloud.stackit.sdk.resourcemanager.api.DefaultApi;
107+
108+
public class DefaultApiExample {
109+
110+
public static void main(String[] args) {
111+
ApiClient defaultClient = Configuration.getDefaultApiClient();
112+
defaultClient.setBasePath("https://resource-manager.api.stackit.cloud");
113+
114+
DefaultApi apiInstance = new DefaultApi(defaultClient);
115+
CreateFolderPayload createFolderPayload = new CreateFolderPayload(); // CreateFolderPayload |
116+
try {
117+
FolderResponse result = apiInstance.createFolder(createFolderPayload);
118+
System.out.println(result);
119+
} catch (ApiException e) {
120+
System.err.println("Exception when calling DefaultApi#createFolder");
121+
System.err.println("Status code: " + e.getCode());
122+
System.err.println("Reason: " + e.getResponseBody());
123+
System.err.println("Response headers: " + e.getResponseHeaders());
124+
e.printStackTrace();
125+
}
126+
}
127+
}
128+
129+
```
130+
131+
## Recommendation
132+
133+
It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
apply plugin: 'idea'
2+
apply plugin: 'eclipse'
3+
apply plugin: 'java'
4+
apply plugin: 'com.diffplug.spotless'
5+
6+
group = 'cloud.stackit'
7+
version = '2.0'
8+
9+
buildscript {
10+
repositories {
11+
mavenCentral()
12+
}
13+
dependencies {
14+
classpath 'com.android.tools.build:gradle:2.3.+'
15+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
16+
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.11.0'
17+
}
18+
}
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
sourceSets {
24+
main.java.srcDirs = ['src/main/java']
25+
}
26+
27+
if(hasProperty('target') && target == 'android') {
28+
29+
apply plugin: 'com.android.library'
30+
apply plugin: 'com.github.dcendents.android-maven'
31+
32+
android {
33+
compileSdkVersion 25
34+
buildToolsVersion '25.0.2'
35+
defaultConfig {
36+
minSdkVersion 14
37+
targetSdkVersion 25
38+
}
39+
compileOptions {
40+
sourceCompatibility JavaVersion.VERSION_1_8
41+
targetCompatibility JavaVersion.VERSION_1_8
42+
}
43+
44+
// Rename the aar correctly
45+
libraryVariants.all { variant ->
46+
variant.outputs.each { output ->
47+
def outputFile = output.outputFile
48+
if (outputFile != null && outputFile.name.endsWith('.aar')) {
49+
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
50+
output.outputFile = new File(outputFile.parent, fileName)
51+
}
52+
}
53+
}
54+
55+
dependencies {
56+
provided "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
57+
}
58+
}
59+
60+
afterEvaluate {
61+
android.libraryVariants.all { variant ->
62+
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
63+
task.description = "Create jar artifact for ${variant.name}"
64+
task.dependsOn variant.javaCompile
65+
task.from variant.javaCompile.destinationDirectory
66+
task.destinationDirectory = project.file("${project.buildDir}/outputs/jar")
67+
task.archiveFileName = "${project.name}-${variant.baseName}-${version}.jar"
68+
artifacts.add('archives', task)
69+
}
70+
}
71+
72+
task sourcesJar(type: Jar) {
73+
from android.sourceSets.main.java.srcDirs
74+
classifier = 'sources'
75+
}
76+
77+
artifacts {
78+
archives sourcesJar
79+
}
80+
81+
} else {
82+
83+
apply plugin: 'java'
84+
apply plugin: 'maven-publish'
85+
86+
sourceCompatibility = JavaVersion.VERSION_1_8
87+
targetCompatibility = JavaVersion.VERSION_1_8
88+
89+
publishing {
90+
publications {
91+
maven(MavenPublication) {
92+
artifactId = 'stackit-sdk-resourcemanager'
93+
from components.java
94+
}
95+
}
96+
}
97+
98+
task execute(type:JavaExec) {
99+
main = System.getProperty('mainClass')
100+
classpath = sourceSets.main.runtimeClasspath
101+
}
102+
}
103+
104+
ext {
105+
jakarta_annotation_version = "1.3.5"
106+
}
107+
108+
dependencies {
109+
implementation "com.google.code.findbugs:jsr305:3.0.2"
110+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
111+
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
112+
implementation 'com.google.code.gson:gson:2.9.1'
113+
implementation 'io.gsonfire:gson-fire:1.9.0'
114+
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6'
115+
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
116+
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0'
117+
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
118+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
119+
testImplementation 'org.mockito:mockito-core:3.12.4'
120+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3'
121+
}
122+
123+
javadoc {
124+
options.tags = [ "http.response.details:a:Http Response Details" ]
125+
}
126+
127+
// Use spotless plugin to automatically format code, remove unused import, etc
128+
// To apply changes directly to the file, run `gradlew spotlessApply`
129+
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
130+
spotless {
131+
// comment out below to run spotless as part of the `check` task
132+
enforceCheck false
133+
134+
format 'misc', {
135+
// define the files (e.g. '*.gradle', '*.md') to apply `misc` to
136+
target '.gitignore'
137+
138+
// define the steps to apply to those files
139+
trimTrailingWhitespace()
140+
indentWithSpaces() // Takes an integer argument if you don't like 4
141+
endWithNewline()
142+
}
143+
java {
144+
// don't need to set target, it is inferred from java
145+
146+
// apply a specific flavor of google-java-format
147+
googleJavaFormat('1.8').aosp().reflowLongStrings()
148+
149+
removeUnusedImports()
150+
importOrder()
151+
}
152+
}
153+
154+
test {
155+
// Enable JUnit 5 (Gradle 4.6+).
156+
useJUnitPlatform()
157+
158+
// Always run tests, even when nothing changed.
159+
dependsOn 'cleanTest'
160+
161+
// Show test results.
162+
testLogging {
163+
events "passed", "skipped", "failed"
164+
}
165+
166+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This file is automatically generated by OpenAPI Generator (https://github.com/openAPITools/openapi-generator).
2+
# To include other gradle properties as part of the code generation process, please use the `gradleProperties` option.
3+
#
4+
# Gradle properties reference: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
5+
# For example, uncomment below to build for Android
6+
#target = android
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)