Skip to content

Commit

Permalink
Merge pull request #4 from CoScale/1.1.0
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
cristianciutea committed Jun 4, 2016
2 parents c943b6f + fb7036f commit 63160b5
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 9 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To use the client add the project declaration to your `pom.xml`:
<dependency>
<groupId>com.coscale.sdk-java</groupId>
<artifactId>coscale-sdk-java</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
</dependency>
```

Expand All @@ -38,6 +38,7 @@ Resources this API supports:
- [Data](#data)
- [Servers](#servers)
- [Events](#events)
- [Requests](#requests)


## Authentication
Expand Down Expand Up @@ -129,6 +130,12 @@ Server server = apiFactory.getServersApi().insert(serverInsert);
// To get a server by the name we can add a filter.
Options filter = new Builder().selectBy("name", "Ubuntu Server").build();
apiFactory.getServersApi().all(filter);

// Get the server attributes.
Options options = new Options.Builder().expand("attributes").build();
Server server = serversApi.getServer(server.id, options);
// or
List<Server> servers = serversApi.all(options);
```

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

### Requests

```java
// Get a request by id.
Request request = requestsApi.get(request.id);

// Get all Requests.
List<Request> requests = requestsApi.all();

// Get all Requests and filter by attributes.
Options options = new Options.Builder().selectBy("name", "example.coscale.com").build();
List<Request> requests = requestsApi.all(options);
```

## Subject

A metric or a event is defined on either a "SERVER" or "APPLICATION".
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.coscale.sdk-java</groupId>
<artifactId>coscale-sdk-java</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
<packaging>jar</packaging>
<name>CoScale SDK</name>
<description>Java SDK for integrating apps with CoScale Web Performance Monitoring platform.</description>
Expand Down
111 changes: 111 additions & 0 deletions src/main/java/com/coscale/client/requests/Request.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.coscale.client.requests;

import java.util.List;

import javax.annotation.Nullable;

import com.coscale.sdk.client.commons.Protocol;
import com.coscale.sdk.client.metrics.State;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

public class Request {

@Nullable
public Protocol protocol;

public State state;

@Nullable
public String classifierConfig;

@Nullable
public Long version;

@Nullable
public Long id;

@Nullable
public Long parentId;

@Nullable
public RequestClassifierType classifierType;

@Nullable
public List<Request> requests;

@Nullable
public String source;

@Nullable
public String description;

@Nullable
public Integer priority;

@Nullable
public String name;

public Request(State state) {
this.state = state;
}

public Request(Protocol protocol, State state, String classifierConfig, Long version, Long id,
Long parentId, RequestClassifierType classifierType, List<Request> requests,
String source, String description, Integer priority, String name) {
this.protocol = protocol;
this.state = state;
this.classifierConfig = classifierConfig;
this.version = version;
this.id = id;
this.parentId = parentId;
this.classifierType = classifierType;
this.requests = requests;
this.source = source;
this.description = description;
this.priority = priority;
this.name = name;
}

public Request() {
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("protocol", protocol).add("state", state)
.add("classifierConfig", classifierConfig).add("version", version).add("id", id)
.add("parentId", parentId).add("classifierType", classifierType)
.add("requests", requests).add("source", source).add("description", description)
.add("priority", priority).add("name", name).toString();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Request other = (Request) obj;

return Objects.equal(this.protocol, other.protocol)
&& Objects.equal(this.state, other.state)
&& Objects.equal(this.classifierConfig, other.classifierConfig)
&& Objects.equal(this.version, other.version) && Objects.equal(this.id, other.id)
&& Objects.equal(this.parentId, other.parentId)
&& Objects.equal(this.classifierType, other.classifierType)
&& Objects.equal(this.requests, other.requests)
&& Objects.equal(this.source, other.source)
&& Objects.equal(this.description, other.description)
&& Objects.equal(this.priority, other.priority)
&& Objects.equal(this.name, other.name);
}

@Override
public int hashCode() {
return Objects.hashCode(protocol, state, classifierConfig, version, id, parentId,
classifierType, requests, source, description, priority, name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.coscale.client.requests;

public enum RequestClassifierType {

HOST,
PAGE,
URL,
METHOD;

}
88 changes: 88 additions & 0 deletions src/main/java/com/coscale/client/requests/RequestsApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.coscale.client.requests;

import java.io.IOException;
import java.util.List;

import com.coscale.sdk.client.ApiClient;
import com.coscale.sdk.client.commons.Options;
import com.fasterxml.jackson.core.type.TypeReference;

/**
* CoScale API client for Requests CoScale endpoint.
*
* @author cristi
*
*/
public class RequestsApi {

/** ApiClient used to make HTTP requests. */
private final ApiClient api;

/**
* RequestsApi constructor.
*
* @param api
* ApiClient.
*/
public RequestsApi(ApiClient api) {
this.api = api;
}

/** Requests end point calls */

/**
* all is used to get a list of all requests.
*
* @return List<Request>
* @throws IOException
*/
public List<Request> all() throws IOException {
return api.callWithAuth("GET", "/requests/", null, new TypeReference<List<Request>>() {
});
}

/**
* all is used to get a list of all requests.
*
* @param options
* which contain query parameters
* @return List<Request>
* @throws IOException
*/
public List<Request> all(Options options) throws IOException {
String url = "/requests/";
url += (options.hasQuery() ? "?" : "&") + options.query();
return api.callWithAuth("GET", url, null, new TypeReference<List<Request>>() {
});
}

/**
* get a request by the id.
*
* @param id
* id of the request.
* @return Request
* @throws IOException
*/
public Request get(long id) throws IOException {
return api.callWithAuth("GET", "/requests/" + id + '/', null, new TypeReference<Request>() {
});
}

/**
* get a request by the id.
*
* @param id
* id of the request.
* @param options
* which contain query parameters
* @return Request
* @throws IOException
*/
public Request get(long id, Options options) throws IOException {
String url = "/requests/" + id + '/';
url += (options.hasQuery() ? "?" : "&") + options.query();
return api.callWithAuth("GET", url, null, new TypeReference<Request>() {
});
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/coscale/sdk/client/ApiFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coscale.sdk.client;

import com.coscale.client.requests.RequestsApi;
import com.coscale.sdk.client.data.DataApi;
import com.coscale.sdk.client.events.EventsApi;
import com.coscale.sdk.client.metrics.MetricsApi;
Expand Down Expand Up @@ -72,4 +73,13 @@ public ServersApi getServersApi() {
public DataApi getDataApi() {
return new DataApi(api);
}

/**
* Get a instance of RequestsApi.
*
* @return RequestsApi.
*/
public RequestsApi getRequestsApi() {
return new RequestsApi(api);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/coscale/sdk/client/commons/Protocol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.coscale.sdk.client.commons;

public enum Protocol {

HTTP,
DATABASE,
PAGE;

}
22 changes: 15 additions & 7 deletions src/main/java/com/coscale/sdk/client/servers/Server.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.coscale.sdk.client.servers;

import java.util.List;

import javax.annotation.Nullable;

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

@Nullable
public java.util.List<Metric> metrics;
public List<Metric> metrics;

@Nullable
public String description;
Expand All @@ -27,20 +29,24 @@ public class Server {
public State state;

@Nullable
public java.util.List<Server> children;
public List<Server> children;

@Nullable
public String type;

@Nullable
public Long version;

@Nullable
public List<ServerAttribute> attributes;

public Server(State state) {
this.state = state;
}

public Server(Long id, String source, java.util.List<Metric> metrics, String description,
String name, State state, java.util.List<Server> children, String type, Long version) {
public Server(Long id, String source, List<Metric> metrics, String description, String name,
State state, List<Server> children, String type, Long version,
List<ServerAttribute> attributes) {
this.id = id;
this.source = source;
this.metrics = metrics;
Expand All @@ -50,6 +56,7 @@ public Server(Long id, String source, java.util.List<Metric> metrics, String des
this.children = children;
this.type = type;
this.version = version;
this.attributes = attributes;
}

public Server() {
Expand All @@ -60,7 +67,7 @@ public String toString() {
return MoreObjects.toStringHelper(this).add("id", id).add("source", source)
.add("metrics", metrics).add("description", description).add("name", name)
.add("state", state).add("children", children).add("type", type)
.add("version", version).toString();
.add("version", version).add("attributes", attributes).toString();
}

@Override
Expand All @@ -79,13 +86,14 @@ public boolean equals(Object obj) {
&& Objects.equal(this.name, other.name) && Objects.equal(this.state, other.state)
&& Objects.equal(this.children, other.children)
&& Objects.equal(this.type, other.type)
&& Objects.equal(this.version, other.version);
&& Objects.equal(this.version, other.version)
&& Objects.equal(this.attributes, other.attributes);
}

@Override
public int hashCode() {
return Objects.hashCode(id, source, metrics, description, name, state, children, type,
version);
version, attributes);
}

}
Loading

0 comments on commit 63160b5

Please sign in to comment.