Skip to content

Commit 9ae7be7

Browse files
author
Cristi
committed
added support for request api and server attributes
1 parent c943b6f commit 9ae7be7

File tree

7 files changed

+312
-7
lines changed

7 files changed

+312
-7
lines changed
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
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.coscale.sdk.client.servers;
2+
3+
import javax.annotation.Nullable;
4+
5+
import com.google.common.base.MoreObjects;
6+
import com.google.common.base.Objects;
7+
8+
public class ServerAttribute {
9+
10+
@Nullable
11+
public Long id;
12+
13+
@Nullable
14+
public String source;
15+
16+
@Nullable
17+
public String value;
18+
19+
@Nullable
20+
public Boolean locked;
21+
22+
@Nullable
23+
public String key;
24+
25+
@Nullable
26+
public Long version;
27+
28+
public ServerAttribute(Long id, String source, String value, Boolean locked, String key,
29+
Long version) {
30+
this.id = id;
31+
this.source = source;
32+
this.value = value;
33+
this.locked = locked;
34+
this.key = key;
35+
this.version = version;
36+
}
37+
38+
public ServerAttribute() {
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return MoreObjects.toStringHelper(this).add("id", id).add("source", source)
44+
.add("value", value).add("locked", locked).add("key", key).add("version", version)
45+
.toString();
46+
}
47+
48+
@Override
49+
public boolean equals(Object obj) {
50+
if (obj == null) {
51+
return false;
52+
}
53+
if (getClass() != obj.getClass()) {
54+
return false;
55+
}
56+
final ServerAttribute other = (ServerAttribute) obj;
57+
58+
return Objects.equal(this.id, other.id) && Objects.equal(this.source, other.source)
59+
&& Objects.equal(this.value, other.value)
60+
&& Objects.equal(this.locked, other.locked) && Objects.equal(this.key, other.key)
61+
&& Objects.equal(this.version, other.version);
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
return Objects.hashCode(id, source, value, locked, key, version);
67+
}
68+
69+
}

0 commit comments

Comments
 (0)