Skip to content

Commit 63160b5

Browse files
Merge pull request #4 from CoScale/1.1.0
1.1.0
2 parents c943b6f + fb7036f commit 63160b5

File tree

9 files changed

+335
-9
lines changed

9 files changed

+335
-9
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ To use the client add the project declaration to your `pom.xml`:
2626
<dependency>
2727
<groupId>com.coscale.sdk-java</groupId>
2828
<artifactId>coscale-sdk-java</artifactId>
29-
<version>1.0.1</version>
29+
<version>1.1.0</version>
3030
</dependency>
3131
```
3232

@@ -38,6 +38,7 @@ Resources this API supports:
3838
- [Data](#data)
3939
- [Servers](#servers)
4040
- [Events](#events)
41+
- [Requests](#requests)
4142

4243

4344
## Authentication
@@ -129,6 +130,12 @@ Server server = apiFactory.getServersApi().insert(serverInsert);
129130
// To get a server by the name we can add a filter.
130131
Options filter = new Builder().selectBy("name", "Ubuntu Server").build();
131132
apiFactory.getServersApi().all(filter);
133+
134+
// Get the server attributes.
135+
Options options = new Options.Builder().expand("attributes").build();
136+
Server server = serversApi.getServer(server.id, options);
137+
// or
138+
List<Server> servers = serversApi.all(options);
132139
```
133140

134141
### Events
@@ -154,6 +161,20 @@ EventData eventData = eventsApi.getData(event.id, eventData.id);
154161
Msg msg = eventsApi.deleteData(event.id, eventData.id);
155162
```
156163

164+
### Requests
165+
166+
```java
167+
// Get a request by id.
168+
Request request = requestsApi.get(request.id);
169+
170+
// Get all Requests.
171+
List<Request> requests = requestsApi.all();
172+
173+
// Get all Requests and filter by attributes.
174+
Options options = new Options.Builder().selectBy("name", "example.coscale.com").build();
175+
List<Request> requests = requestsApi.all(options);
176+
```
177+
157178
## Subject
158179

159180
A metric or a event is defined on either a "SERVER" or "APPLICATION".

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.coscale.sdk-java</groupId>
77
<artifactId>coscale-sdk-java</artifactId>
8-
<version>1.0.1</version>
8+
<version>1.1.0</version>
99
<packaging>jar</packaging>
1010
<name>CoScale SDK</name>
1111
<description>Java SDK for integrating apps with CoScale Web Performance Monitoring platform.</description>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package com.coscale.client.requests;
2+
3+
import java.util.List;
4+
5+
import javax.annotation.Nullable;
6+
7+
import com.coscale.sdk.client.commons.Protocol;
8+
import com.coscale.sdk.client.metrics.State;
9+
import com.google.common.base.MoreObjects;
10+
import com.google.common.base.Objects;
11+
12+
public class Request {
13+
14+
@Nullable
15+
public Protocol protocol;
16+
17+
public State state;
18+
19+
@Nullable
20+
public String classifierConfig;
21+
22+
@Nullable
23+
public Long version;
24+
25+
@Nullable
26+
public Long id;
27+
28+
@Nullable
29+
public Long parentId;
30+
31+
@Nullable
32+
public RequestClassifierType classifierType;
33+
34+
@Nullable
35+
public List<Request> requests;
36+
37+
@Nullable
38+
public String source;
39+
40+
@Nullable
41+
public String description;
42+
43+
@Nullable
44+
public Integer priority;
45+
46+
@Nullable
47+
public String name;
48+
49+
public Request(State state) {
50+
this.state = state;
51+
}
52+
53+
public Request(Protocol protocol, State state, String classifierConfig, Long version, Long id,
54+
Long parentId, RequestClassifierType classifierType, List<Request> requests,
55+
String source, String description, Integer priority, String name) {
56+
this.protocol = protocol;
57+
this.state = state;
58+
this.classifierConfig = classifierConfig;
59+
this.version = version;
60+
this.id = id;
61+
this.parentId = parentId;
62+
this.classifierType = classifierType;
63+
this.requests = requests;
64+
this.source = source;
65+
this.description = description;
66+
this.priority = priority;
67+
this.name = name;
68+
}
69+
70+
public Request() {
71+
}
72+
73+
@Override
74+
public String toString() {
75+
return MoreObjects.toStringHelper(this).add("protocol", protocol).add("state", state)
76+
.add("classifierConfig", classifierConfig).add("version", version).add("id", id)
77+
.add("parentId", parentId).add("classifierType", classifierType)
78+
.add("requests", requests).add("source", source).add("description", description)
79+
.add("priority", priority).add("name", name).toString();
80+
}
81+
82+
@Override
83+
public boolean equals(Object obj) {
84+
if (obj == null) {
85+
return false;
86+
}
87+
if (getClass() != obj.getClass()) {
88+
return false;
89+
}
90+
final Request other = (Request) obj;
91+
92+
return Objects.equal(this.protocol, other.protocol)
93+
&& Objects.equal(this.state, other.state)
94+
&& Objects.equal(this.classifierConfig, other.classifierConfig)
95+
&& Objects.equal(this.version, other.version) && Objects.equal(this.id, other.id)
96+
&& Objects.equal(this.parentId, other.parentId)
97+
&& Objects.equal(this.classifierType, other.classifierType)
98+
&& Objects.equal(this.requests, other.requests)
99+
&& Objects.equal(this.source, other.source)
100+
&& Objects.equal(this.description, other.description)
101+
&& Objects.equal(this.priority, other.priority)
102+
&& Objects.equal(this.name, other.name);
103+
}
104+
105+
@Override
106+
public int hashCode() {
107+
return Objects.hashCode(protocol, state, classifierConfig, version, id, parentId,
108+
classifierType, requests, source, description, priority, name);
109+
}
110+
111+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coscale.client.requests;
2+
3+
public enum RequestClassifierType {
4+
5+
HOST,
6+
PAGE,
7+
URL,
8+
METHOD;
9+
10+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.coscale.client.requests;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
import com.coscale.sdk.client.ApiClient;
7+
import com.coscale.sdk.client.commons.Options;
8+
import com.fasterxml.jackson.core.type.TypeReference;
9+
10+
/**
11+
* CoScale API client for Requests CoScale endpoint.
12+
*
13+
* @author cristi
14+
*
15+
*/
16+
public class RequestsApi {
17+
18+
/** ApiClient used to make HTTP requests. */
19+
private final ApiClient api;
20+
21+
/**
22+
* RequestsApi constructor.
23+
*
24+
* @param api
25+
* ApiClient.
26+
*/
27+
public RequestsApi(ApiClient api) {
28+
this.api = api;
29+
}
30+
31+
/** Requests end point calls */
32+
33+
/**
34+
* all is used to get a list of all requests.
35+
*
36+
* @return List<Request>
37+
* @throws IOException
38+
*/
39+
public List<Request> all() throws IOException {
40+
return api.callWithAuth("GET", "/requests/", null, new TypeReference<List<Request>>() {
41+
});
42+
}
43+
44+
/**
45+
* all is used to get a list of all requests.
46+
*
47+
* @param options
48+
* which contain query parameters
49+
* @return List<Request>
50+
* @throws IOException
51+
*/
52+
public List<Request> all(Options options) throws IOException {
53+
String url = "/requests/";
54+
url += (options.hasQuery() ? "?" : "&") + options.query();
55+
return api.callWithAuth("GET", url, null, new TypeReference<List<Request>>() {
56+
});
57+
}
58+
59+
/**
60+
* get a request by the id.
61+
*
62+
* @param id
63+
* id of the request.
64+
* @return Request
65+
* @throws IOException
66+
*/
67+
public Request get(long id) throws IOException {
68+
return api.callWithAuth("GET", "/requests/" + id + '/', null, new TypeReference<Request>() {
69+
});
70+
}
71+
72+
/**
73+
* get a request by the id.
74+
*
75+
* @param id
76+
* id of the request.
77+
* @param options
78+
* which contain query parameters
79+
* @return Request
80+
* @throws IOException
81+
*/
82+
public Request get(long id, Options options) throws IOException {
83+
String url = "/requests/" + id + '/';
84+
url += (options.hasQuery() ? "?" : "&") + options.query();
85+
return api.callWithAuth("GET", url, null, new TypeReference<Request>() {
86+
});
87+
}
88+
}

src/main/java/com/coscale/sdk/client/ApiFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.coscale.sdk.client;
22

3+
import com.coscale.client.requests.RequestsApi;
34
import com.coscale.sdk.client.data.DataApi;
45
import com.coscale.sdk.client.events.EventsApi;
56
import com.coscale.sdk.client.metrics.MetricsApi;
@@ -72,4 +73,13 @@ public ServersApi getServersApi() {
7273
public DataApi getDataApi() {
7374
return new DataApi(api);
7475
}
76+
77+
/**
78+
* Get a instance of RequestsApi.
79+
*
80+
* @return RequestsApi.
81+
*/
82+
public RequestsApi getRequestsApi() {
83+
return new RequestsApi(api);
84+
}
7585
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.coscale.sdk.client.commons;
2+
3+
public enum Protocol {
4+
5+
HTTP,
6+
DATABASE,
7+
PAGE;
8+
9+
}

src/main/java/com/coscale/sdk/client/servers/Server.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.coscale.sdk.client.servers;
22

3+
import java.util.List;
4+
35
import javax.annotation.Nullable;
46

57
import com.coscale.sdk.client.metrics.Metric;
@@ -16,7 +18,7 @@ public class Server {
1618
public String source;
1719

1820
@Nullable
19-
public java.util.List<Metric> metrics;
21+
public List<Metric> metrics;
2022

2123
@Nullable
2224
public String description;
@@ -27,20 +29,24 @@ public class Server {
2729
public State state;
2830

2931
@Nullable
30-
public java.util.List<Server> children;
32+
public List<Server> children;
3133

3234
@Nullable
3335
public String type;
3436

3537
@Nullable
3638
public Long version;
3739

40+
@Nullable
41+
public List<ServerAttribute> attributes;
42+
3843
public Server(State state) {
3944
this.state = state;
4045
}
4146

42-
public Server(Long id, String source, java.util.List<Metric> metrics, String description,
43-
String name, State state, java.util.List<Server> children, String type, Long version) {
47+
public Server(Long id, String source, List<Metric> metrics, String description, String name,
48+
State state, List<Server> children, String type, Long version,
49+
List<ServerAttribute> attributes) {
4450
this.id = id;
4551
this.source = source;
4652
this.metrics = metrics;
@@ -50,6 +56,7 @@ public Server(Long id, String source, java.util.List<Metric> metrics, String des
5056
this.children = children;
5157
this.type = type;
5258
this.version = version;
59+
this.attributes = attributes;
5360
}
5461

5562
public Server() {
@@ -60,7 +67,7 @@ public String toString() {
6067
return MoreObjects.toStringHelper(this).add("id", id).add("source", source)
6168
.add("metrics", metrics).add("description", description).add("name", name)
6269
.add("state", state).add("children", children).add("type", type)
63-
.add("version", version).toString();
70+
.add("version", version).add("attributes", attributes).toString();
6471
}
6572

6673
@Override
@@ -79,13 +86,14 @@ public boolean equals(Object obj) {
7986
&& Objects.equal(this.name, other.name) && Objects.equal(this.state, other.state)
8087
&& Objects.equal(this.children, other.children)
8188
&& Objects.equal(this.type, other.type)
82-
&& Objects.equal(this.version, other.version);
89+
&& Objects.equal(this.version, other.version)
90+
&& Objects.equal(this.attributes, other.attributes);
8391
}
8492

8593
@Override
8694
public int hashCode() {
8795
return Objects.hashCode(id, source, metrics, description, name, state, children, type,
88-
version);
96+
version, attributes);
8997
}
9098

9199
}

0 commit comments

Comments
 (0)