mirror of https://github.com/apache/jclouds.git
commit
91193721d9
|
@ -0,0 +1,274 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Vijay Kiran
|
||||
*/
|
||||
public class Event implements Comparable<Event> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private long id;
|
||||
private String account;
|
||||
private String description;
|
||||
private Date created;
|
||||
private String domain;
|
||||
private long domainId;
|
||||
//TODO Change to enum : the event level (INFO, WARN, ERROR)
|
||||
private String level;
|
||||
private String parentId;
|
||||
private String state;
|
||||
//Event Type
|
||||
private String type;
|
||||
private String username;
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder account(String account) {
|
||||
this.account = account;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder created(Date created) {
|
||||
this.created = created;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder domain(String domain) {
|
||||
this.domain = domain;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder domainId(long domainId) {
|
||||
this.domainId = domainId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder level(String level) {
|
||||
this.level = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder state(String state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder username(String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Event build() {
|
||||
return new Event(id, account, description, created, domain, domainId, level, parentId, state, type, username);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private long id;
|
||||
private String account;
|
||||
private String description;
|
||||
private Date created;
|
||||
private String domain;
|
||||
private long domainId;
|
||||
//TODO Change to enum : the event level (INFO, WARN, ERROR)
|
||||
private String level;
|
||||
private String parentId;
|
||||
private String state;
|
||||
//Event Type
|
||||
private String type;
|
||||
private String username;
|
||||
|
||||
public Event(long id, String account, String description, Date created, String domain, long domainId, String level,
|
||||
String parentId, String state, String type, String username) {
|
||||
this.id = id;
|
||||
this.account = account;
|
||||
this.description = description;
|
||||
this.created = created;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.level = level;
|
||||
this.parentId = parentId;
|
||||
this.state = state;
|
||||
this.type = type;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*/
|
||||
Event() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ID of the event
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the account name for the account that owns the object being acted on in the event
|
||||
* (e.g. the owner of the virtual machine, ip address, or security group)
|
||||
*/
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the date the event was created
|
||||
*/
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description of the event
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the account's domain
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id of the account's domain
|
||||
*/
|
||||
public long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the event level (INFO, WARN, ERROR)
|
||||
*/
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the event is parented
|
||||
*/
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the state of the event
|
||||
*/
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type of the event (see event types)
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the user who performed the action (can be different from the account if
|
||||
* an admin is performing an action for a user, e.g. starting/stopping a user's virtual machine)
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Event arg0) {
|
||||
return new Long(id).compareTo(arg0.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Event event = (Event) o;
|
||||
|
||||
if (domainId != event.domainId) return false;
|
||||
if (id != event.id) return false;
|
||||
if (account != null ? !account.equals(event.account) : event.account != null) return false;
|
||||
if (created != null ? !created.equals(event.created) : event.created != null) return false;
|
||||
if (description != null ? !description.equals(event.description) : event.description != null) return false;
|
||||
if (domain != null ? !domain.equals(event.domain) : event.domain != null) return false;
|
||||
if (level != null ? !level.equals(event.level) : event.level != null) return false;
|
||||
if (parentId != null ? !parentId.equals(event.parentId) : event.parentId != null) return false;
|
||||
if (state != null ? !state.equals(event.state) : event.state != null) return false;
|
||||
if (type != null ? !type.equals(event.type) : event.type != null) return false;
|
||||
if (username != null ? !username.equals(event.username) : event.username != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) (id ^ (id >>> 32));
|
||||
result = 31 * result + (account != null ? account.hashCode() : 0);
|
||||
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||
result = 31 * result + (created != null ? created.hashCode() : 0);
|
||||
result = 31 * result + (domain != null ? domain.hashCode() : 0);
|
||||
result = 31 * result + (int) (domainId ^ (domainId >>> 32));
|
||||
result = 31 * result + (level != null ? level.hashCode() : 0);
|
||||
result = 31 * result + (parentId != null ? parentId.hashCode() : 0);
|
||||
result = 31 * result + (state != null ? state.hashCode() : 0);
|
||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||
result = 31 * result + (username != null ? username.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[id=%d, account=%s, description=%s, created=%s, domain=%s, domainId=%d, level=%s, " +
|
||||
"parentId=%s, state=%s, type=%s, username=%s]",
|
||||
id, account, description, created, domain, domainId, level, parentId, state, type, username);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -24,12 +24,15 @@ import javax.ws.rs.core.MediaType;
|
|||
import java.util.Set;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.cloudstack.domain.Event;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.functions.ParseEventTypesFromHttpResponse;
|
||||
import org.jclouds.cloudstack.options.ListEventsOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
|
||||
/**
|
||||
|
@ -53,4 +56,14 @@ public interface EventAsyncClient {
|
|||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<String>> listEventTypes();
|
||||
|
||||
/**
|
||||
* @see EventClient#listEventTypes()
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listEvents")
|
||||
@SelectJson("event")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Event>> listEvents(ListEventsOptions...options);
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.jclouds.cloudstack.features;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Event;
|
||||
import org.jclouds.cloudstack.options.ListEventsOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
|
@ -39,4 +41,13 @@ public interface EventClient {
|
|||
* @return event types or null if not found
|
||||
*/
|
||||
Set<String> listEventTypes();
|
||||
|
||||
/**
|
||||
* List Events
|
||||
*
|
||||
* @return event list or null if not found
|
||||
*/
|
||||
Set<Event> listEvents(ListEventsOptions... options);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Options used to control what events are returned
|
||||
*
|
||||
|
@ -26,6 +31,102 @@ package org.jclouds.cloudstack.options;
|
|||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/user/listEvents.html"
|
||||
* />
|
||||
*/
|
||||
public class ListEventsOptions {
|
||||
public class ListEventsOptions extends BaseHttpRequestOptions {
|
||||
public static final ListEventsOptions NONE = new ListEventsOptions();
|
||||
|
||||
public ListEventsOptions account(String account) {
|
||||
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListEventsOptions domainId(long domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListEventsOptions duration(String duration) {
|
||||
this.queryParameters.replaceValues("duration", ImmutableSet.of(duration));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListEventsOptions endDate(Date enddate) {
|
||||
this.queryParameters.replaceValues("enddate", ImmutableSet.of(enddate + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListEventsOptions entryTime(Date entrytime) {
|
||||
this.queryParameters.replaceValues("entrytime", ImmutableSet.of(entrytime + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListEventsOptions id(String id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListEventsOptions keyword(String keyword) {
|
||||
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListEventsOptions level(String level) {
|
||||
this.queryParameters.replaceValues("level", ImmutableSet.of(level));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListEventsOptions type(String type) {
|
||||
this.queryParameters.replaceValues("type", ImmutableSet.of(type));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
public static ListEventsOptions account(String account) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
return options.account(account);
|
||||
}
|
||||
|
||||
public static ListEventsOptions domainId(long domainId) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
return options.domainId(domainId);
|
||||
}
|
||||
|
||||
public static ListEventsOptions duration(String duration) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
return options.duration(duration);
|
||||
}
|
||||
|
||||
public static ListEventsOptions endDate(Date enddate) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
return options.endDate(enddate);
|
||||
}
|
||||
|
||||
public static ListEventsOptions entryTime(Date entrytime) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
return options.entryTime(entrytime);
|
||||
}
|
||||
|
||||
public static ListEventsOptions id(String id) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
public static ListEventsOptions keyword(String keyword) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
return options.keyword(keyword);
|
||||
}
|
||||
|
||||
public static ListEventsOptions level(String level) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
return options.level(level);
|
||||
}
|
||||
|
||||
public static ListEventsOptions type(String type) {
|
||||
final ListEventsOptions options = new ListEventsOptions();
|
||||
return options.type(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,9 @@ import java.lang.reflect.Method;
|
|||
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.cloudstack.functions.ParseEventTypesFromHttpResponse;
|
||||
import org.jclouds.cloudstack.options.ListEventsOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -51,6 +53,39 @@ public class EventAsyncClientTest extends BaseCloudStackAsyncClientTest<EventAsy
|
|||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testListEvents() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = EventAsyncClient.class.getMethod("listEvents", ListEventsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listEvents HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testEventsListOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = EventAsyncClient.class.getMethod("listEvents", ListEventsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListEventsOptions.Builder.account("jclouds"));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listEvents&account=jclouds HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import static org.testng.Assert.assertTrue;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Event;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -33,7 +34,7 @@ import org.testng.annotations.Test;
|
|||
public class EventClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testlistEventTypes() throws Exception {
|
||||
Set<String> response = client.getEventClient().listEventTypes();
|
||||
final Set<String> response = client.getEventClient().listEventTypes();
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
for (String type : response) {
|
||||
|
@ -41,6 +42,27 @@ public class EventClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
public void testlistEvents() throws Exception {
|
||||
final Set<Event> response = client.getEventClient().listEvents();
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
for (Event event : response) {
|
||||
checkEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEvent(Event event) {
|
||||
assert event.getAccount() != null : event;
|
||||
assert event.getCreated() != null : event;
|
||||
assert event.getDescription() != null : event;
|
||||
assert event.getDomain() != null : event;
|
||||
assert event.getId() != 0 : event;
|
||||
assert event.getLevel() != null : event;
|
||||
assert event.getState() != null : event;
|
||||
assert event.getType() != null : event;
|
||||
assert event.getUsername() != null : event;
|
||||
}
|
||||
|
||||
protected void checkEventType(String eventType) {
|
||||
assert eventType != null : eventType;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ public class LimitClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
}
|
||||
|
||||
private void checkResourceLimit(ResourceLimit resourceLimit) {
|
||||
System.out.println(resourceLimit);
|
||||
assert resourceLimit.getAccount() != null : resourceLimit;
|
||||
assert resourceLimit.getDomain() != null : resourceLimit;
|
||||
assert resourceLimit.getResourceType() != ResourceLimit.ResourceType.UNRECOGNIZED : resourceLimit;
|
||||
|
|
Loading…
Reference in New Issue