Skip to content

Commit dab6416

Browse files
committed
java
1 parent 139ad6c commit dab6416

34 files changed

+791
-236
lines changed

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
# Astra Software Development Kit
22

33
[![License Apache2](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)
4-
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/datastax/astra-sdk-java/Java%20SDK%20Tests)
54
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.datastax.astra/astra-sdk/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.datastax.astra/astra-sdk/)
65

7-
<img src="https://github.com/datastax/astra-sdk-java/blob/main/docs/img/astra-sdk-logo.png?raw/true" height="70" align="left"/>
8-
96
## Overview
10-
####
117

128
This SDK *(Software Development Kit)* makes it easy to call Stargate and/or Astra services using idiomatic Java APIs.
139

14-
<center>
15-
<img src="https://github.com/datastax/astra-sdk-java/blob/main/docs/img/sdk-overview.png?raw/true" />
16-
</center>
17-
1810
- **The Stargate SDK** works with both Stargate standalone installations and Stargate deployed in Astra. With standalone Stargate deployments you will initialize the framework with the class `StargateClient` and provide a list of nodes (IP). To start locally please follow [Stargate SDK quickstart](https://github.com/datastax/astra-sdk-java/wiki/Stargate-SDK-Quickstart) guide. The nodes will run in Docker.
1911

2012
- **The Astra SDK** reuses the previous library and setup the connection to work with AstraDB cloud-based service. You work with the class `AstraClient` (that configure `StargateClient` for you). As you can see on the figure below the `AstraClient` handles not only Stargate Apis but also Astra Devops Api and Apache Pulsar. To get started follow the [Astra SDK quickstart](https://github.com/datastax/astra-sdk-java/wiki/Astra-SDK-Quickstart) guide.
@@ -27,5 +19,3 @@ This SDK *(Software Development Kit)* makes it easy to call Stargate and/or Astr
2719
2. [QuickStart for Astra](https://github.com/datastax/astra-sdk-java/wiki/Astra-SDK-Quickstart)
2820
3. [QuickStart for Astra Spring Boot Starter](https://github.com/datastax/astra-sdk-java/wiki/Spring-Boot-Starter-Quickstart)
2921

30-
31-

astra-archetype-spring/pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>astra-archetype-spring</artifactId>
7+
<name>+ astra-archetype-spring</name>
8+
9+
<parent>
10+
<artifactId>astra-sdk-parent</artifactId>
11+
<groupId>com.datastax.astra</groupId>
12+
<version>0.4.1-SNAPSHOT</version>
13+
</parent>
14+
15+
<properties>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>com.datastax.astra</groupId>
23+
<artifactId>astra-spring-boot-starter</artifactId>
24+
<version>${project.version}</version>
25+
</dependency>
26+
</dependencies>
27+
28+
29+
</project>

astra-sdk-devops/src/main/java/com/dtsx/astra/sdk/db/DbAccessListsClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.dtsx.astra.sdk.utils.JsonUtils;
1111
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
1212

13+
import java.util.ArrayList;
1314
import java.util.Arrays;
1415

1516
/**
@@ -49,6 +50,7 @@ public AccessList get() {
4950
AccessList ac = new AccessList();
5051
ac.setDatabaseId(db.getId());
5152
ac.setOrganizationId(db.getOrgId());
53+
ac.setAddresses(new ArrayList<>());
5254
ac.setConfigurations(new AccessList.Configurations(false));
5355
return ac;
5456
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.dtsx.astra.sdk.db.telemetry;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* Hold configuration to export metrics to datadog.
7+
*/
8+
public class DatadogTelemetryRequest {
9+
10+
/**
11+
* API key to authenticate to the Datadog API
12+
*/
13+
@JsonProperty("api_key")
14+
private String apiKey;
15+
16+
/**
17+
* The Datadog site to send data to, which should be the site parameter corresponding to the Datadog site URL
18+
*/
19+
private String site;
20+
21+
/**
22+
* Gets apiKey
23+
*
24+
* @return value of apiKey
25+
*/
26+
public String getApiKey() {
27+
return apiKey;
28+
}
29+
30+
/**
31+
* Set value for apiKey
32+
*
33+
* @param apiKey
34+
* new value for apiKey
35+
*/
36+
public void setApiKey(String apiKey) {
37+
this.apiKey = apiKey;
38+
}
39+
40+
/**
41+
* Gets site
42+
*
43+
* @return value of site
44+
*/
45+
public String getSite() {
46+
return site;
47+
}
48+
49+
/**
50+
* Set value for site
51+
*
52+
* @param site
53+
* new value for site
54+
*/
55+
public void setSite(String site) {
56+
this.site = site;
57+
}
58+
}

astra-sdk-devops/src/main/java/com/dtsx/astra/sdk/db/telemetry/TelemetryClientKafka.java renamed to astra-sdk-devops/src/main/java/com/dtsx/astra/sdk/db/telemetry/SpecializedTelemetryClient.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.dtsx.astra.sdk.db.telemetry;
22

3-
import com.dtsx.astra.sdk.utils.HttpClientWrapper;
43
import com.dtsx.astra.sdk.utils.ApiResponseHttp;
54
import com.dtsx.astra.sdk.utils.Assert;
5+
import com.dtsx.astra.sdk.utils.HttpClientWrapper;
66
import com.dtsx.astra.sdk.utils.JsonUtils;
77
import com.fasterxml.jackson.core.type.TypeReference;
88
import org.slf4j.Logger;
@@ -16,24 +16,20 @@
1616
/**
1717
* Kafka Client.
1818
*/
19-
public class TelemetryClientKafka {
19+
public class SpecializedTelemetryClient<T> {
2020

2121
/** Logger for our Client. */
22-
private static final Logger LOGGER = LoggerFactory.getLogger(TelemetryClientKafka.class);
23-
24-
/** key kafka. */
25-
private static final String KEY_KAFKA = "kafka";
26-
27-
/** Wrapper handling header and error management as a singleton. */
28-
private final HttpClientWrapper http = HttpClientWrapper.getInstance();
22+
private static final Logger LOGGER = LoggerFactory.getLogger(SpecializedTelemetryClient.class);
2923

3024
/** Load Database responses. */
31-
private static final TypeReference<Map<String, KafkaTelemetryRequest>> RESPONSE_KAFKA =
32-
new TypeReference<Map<String, KafkaTelemetryRequest>>(){};
25+
private final TypeReference<Map<String, T>> RESPONSE = new TypeReference<Map<String, T>>(){};
3326

3427
/** unique db identifier. */
3528
private final String token;
3629

30+
/** unique db identifier. */
31+
private final String key;
32+
3733
/** Reference to upper resource. */
3834
private final String telemetryEndpoint;
3935

@@ -45,10 +41,11 @@ public class TelemetryClientKafka {
4541
* @param telemetryEndpoint
4642
* endpoint
4743
*/
48-
public TelemetryClientKafka(String token, String telemetryEndpoint) {
44+
public SpecializedTelemetryClient(String token, String telemetryEndpoint, String key) {
4945
Assert.notNull(token,"databasesClient");
5046
Assert.hasLength(telemetryEndpoint, "telemetryEndpoint");
5147
this.token = token;
48+
this.key = key;
5249
this.telemetryEndpoint = telemetryEndpoint;
5350
}
5451

@@ -60,10 +57,10 @@ public TelemetryClientKafka(String token, String telemetryEndpoint) {
6057
* @return
6158
* http response
6259
*/
63-
public ApiResponseHttp setup(KafkaTelemetryRequest ktr) {
64-
Map<String, KafkaTelemetryRequest> bodyMap = new HashMap<>();
65-
bodyMap.put(KEY_KAFKA, ktr);
66-
return http.POST(telemetryEndpoint, token, JsonUtils.mapAsJson(bodyMap));
60+
public ApiResponseHttp setup(T ktr) {
61+
Map<String, T> bodyMap = new HashMap<>();
62+
bodyMap.put(key, ktr);
63+
return HttpClientWrapper.getInstance().POST(telemetryEndpoint, token, JsonUtils.mapAsJson(bodyMap));
6764
}
6865

6966
/**
@@ -72,15 +69,15 @@ public ApiResponseHttp setup(KafkaTelemetryRequest ktr) {
7269
* @return
7370
* telemetry request
7471
*/
75-
public Optional<KafkaTelemetryRequest> find() {
76-
ApiResponseHttp res = http.GET(telemetryEndpoint, token);
72+
public Optional<T> find() {
73+
ApiResponseHttp res = HttpClientWrapper.getInstance().GET(telemetryEndpoint, token);
7774
try{
7875
if (res.getCode() == HttpURLConnection.HTTP_OK) {
7976
return Optional.ofNullable(JsonUtils
80-
.unmarshallType(res.getBody(), RESPONSE_KAFKA).get(KEY_KAFKA));
77+
.unmarshallType(res.getBody(), RESPONSE).get(key));
8178
}
8279
} catch(Exception e) {
83-
LOGGER.warn("Cannot read telemetry configuration for kafka", e);
80+
LOGGER.warn("Cannot read telemetry configuration for " + key, e);
8481
}
8582
return Optional.empty();
8683
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.dtsx.astra.sdk.db.telemetry;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* Represent a request to setup connectivity to Splunk.
7+
*/
8+
public class SplunkTelemetryRequest {
9+
10+
/**
11+
* Path for Splunk endpoint, which should always be a full HTTPS address.
12+
*/
13+
private String endpoint;
14+
15+
/**
16+
* Splunk index to write metrics to. Index must be set so the Splunk token has permission to write to it.
17+
*/
18+
private String index;
19+
20+
/**
21+
* Token for Splunk Authentication
22+
*/
23+
private String token;
24+
25+
/**
26+
* Source of events sent to this sink. If unset, we set it to a default value, eg. "astradb".
27+
*/
28+
private String source;
29+
30+
/**
31+
* Source type of events sent to this sink. If unset, we set it to a default value, eg. "astradb-metrics".
32+
*/
33+
@JsonProperty("sourcetype")
34+
private String sourceType;
35+
36+
/**
37+
* Gets endpoint
38+
*
39+
* @return value of endpoint
40+
*/
41+
public String getEndpoint() {
42+
return endpoint;
43+
}
44+
45+
/**
46+
* Set value for endpoint
47+
*
48+
* @param endpoint
49+
* new value for endpoint
50+
*/
51+
public void setEndpoint(String endpoint) {
52+
this.endpoint = endpoint;
53+
}
54+
55+
/**
56+
* Gets index
57+
*
58+
* @return value of index
59+
*/
60+
public String getIndex() {
61+
return index;
62+
}
63+
64+
/**
65+
* Set value for index
66+
*
67+
* @param index
68+
* new value for index
69+
*/
70+
public void setIndex(String index) {
71+
this.index = index;
72+
}
73+
74+
/**
75+
* Gets token
76+
*
77+
* @return value of token
78+
*/
79+
public String getToken() {
80+
return token;
81+
}
82+
83+
/**
84+
* Set value for token
85+
*
86+
* @param token
87+
* new value for token
88+
*/
89+
public void setToken(String token) {
90+
this.token = token;
91+
}
92+
93+
/**
94+
* Gets source
95+
*
96+
* @return value of source
97+
*/
98+
public String getSource() {
99+
return source;
100+
}
101+
102+
/**
103+
* Set value for source
104+
*
105+
* @param source
106+
* new value for source
107+
*/
108+
public void setSource(String source) {
109+
this.source = source;
110+
}
111+
112+
/**
113+
* Gets sourceType
114+
*
115+
* @return value of sourceType
116+
*/
117+
public String getSourceType() {
118+
return sourceType;
119+
}
120+
121+
/**
122+
* Set value for sourceType
123+
*
124+
* @param sourceType
125+
* new value for sourceType
126+
*/
127+
public void setSourceType(String sourceType) {
128+
this.sourceType = sourceType;
129+
}
130+
}

0 commit comments

Comments
 (0)