Event#listEventTypes implementation.

This commit is contained in:
vijaykiran 2011-11-07 18:11:31 +01:00
parent 68f817ab29
commit 087cec22ca
10 changed files with 362 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import org.jclouds.cloudstack.features.AccountAsyncClient;
import org.jclouds.cloudstack.features.AddressAsyncClient;
import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
import org.jclouds.cloudstack.features.ConfigurationAsyncClient;
import org.jclouds.cloudstack.features.EventAsyncClient;
import org.jclouds.cloudstack.features.FirewallAsyncClient;
import org.jclouds.cloudstack.features.GuestOSAsyncClient;
import org.jclouds.cloudstack.features.HypervisorAsyncClient;
@ -32,8 +33,8 @@ import org.jclouds.cloudstack.features.OfferingAsyncClient;
import org.jclouds.cloudstack.features.SSHKeyPairAsyncClient;
import org.jclouds.cloudstack.features.SecurityGroupAsyncClient;
import org.jclouds.cloudstack.features.TemplateAsyncClient;
import org.jclouds.cloudstack.features.VirtualMachineAsyncClient;
import org.jclouds.cloudstack.features.VMGroupAsyncClient;
import org.jclouds.cloudstack.features.VirtualMachineAsyncClient;
import org.jclouds.cloudstack.features.ZoneAsyncClient;
import org.jclouds.rest.annotations.Delegate;
@ -150,4 +151,10 @@ public interface CloudStackAsyncClient {
@Delegate
VMGroupAsyncClient getVMGroupClient();
/**
* Provides synchronous access to Events
*/
@Delegate
EventAsyncClient getEventClient();
}

View File

@ -24,6 +24,7 @@ import org.jclouds.cloudstack.features.AccountClient;
import org.jclouds.cloudstack.features.AddressClient;
import org.jclouds.cloudstack.features.AsyncJobClient;
import org.jclouds.cloudstack.features.ConfigurationClient;
import org.jclouds.cloudstack.features.EventClient;
import org.jclouds.cloudstack.features.FirewallClient;
import org.jclouds.cloudstack.features.GuestOSClient;
import org.jclouds.cloudstack.features.HypervisorClient;
@ -153,4 +154,10 @@ public interface CloudStackClient {
@Delegate
VMGroupClient getVMGroupClient();
/**
* Provides synchronous access to Events
*/
@Delegate
EventClient getEventClient();
}

View File

@ -30,6 +30,8 @@ import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
import org.jclouds.cloudstack.features.AsyncJobClient;
import org.jclouds.cloudstack.features.ConfigurationAsyncClient;
import org.jclouds.cloudstack.features.ConfigurationClient;
import org.jclouds.cloudstack.features.EventAsyncClient;
import org.jclouds.cloudstack.features.EventClient;
import org.jclouds.cloudstack.features.FirewallAsyncClient;
import org.jclouds.cloudstack.features.FirewallClient;
import org.jclouds.cloudstack.features.GuestOSAsyncClient;
@ -96,6 +98,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
.put(HypervisorClient.class, HypervisorAsyncClient.class)//
.put(ConfigurationClient.class, ConfigurationAsyncClient.class)//
.put(AccountClient.class, AccountAsyncClient.class)//
.put(EventClient.class, EventAsyncClient.class)//
.put(SSHKeyPairClient.class, SSHKeyPairAsyncClient.class)//
.put(VMGroupClient.class, VMGroupAsyncClient.class)//
.build();

View File

@ -0,0 +1,99 @@
/**
* 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 com.google.gson.annotations.SerializedName;
/**
* @author Vijay Kiran
*/
public class EventType implements Comparable<EventType> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String name;
public Builder name(String name) {
this.name = name;
return this;
}
public EventType build() {
return new EventType(name);
}
}
// for deserialization
EventType() {
}
@SerializedName("name")
private String name;
public EventType(String name) {
this.name = name;
}
/**
* @return the name/name of the OS type
*/
public String getName() {
return name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
EventType other = (EventType) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
return "[name=" + name + "]";
}
@Override
public int compareTo(EventType arg0) {
return name.compareTo(arg0.getName());
}
}

View File

@ -0,0 +1,56 @@
/**
* 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.features;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.core.MediaType;
import java.util.Set;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.cloudstack.domain.EventType;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
/**
* Provides asynchronous access to cloudstack via their REST API.
* <p/>
*
* @author Vijay Kiran
* @see org.jclouds.cloudstack.features.AccountClient
* @see <a href="http://download.cloud.com/releases/2.2.0/api_2.2.8/TOC_User.html" />
*/
@RequestFilters(QuerySigner.class)
@QueryParams(keys = "response", values = "json")
public interface EventAsyncClient {
/**
* @see EventClient#listEventTypes()
*/
@GET
@QueryParams(keys = "command", values = "listEventTypes")
@SelectJson("eventtype")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<EventType>> listEventTypes();
}

View File

@ -0,0 +1,43 @@
/**
* 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.features;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.cloudstack.domain.EventType;
import org.jclouds.concurrent.Timeout;
/**
* Provides synchronous access to CloudStack Event features.
* <p/>
*
* @author Vijay Kiran
* @see <a href="http://download.cloud.com/releases/2.2.0/api/TOC_User.html" />
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface EventClient {
/**
* List Event Types
*
* @return event types or null if not found
*/
Set<EventType> listEventTypes();
}

View File

@ -0,0 +1,31 @@
/**
* 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.options;
/**
* Options used to control what events are returned
*
* @author Vijay Kiran
* @see <a href=
* "http://download.cloud.com/releases/2.2.0/api_2.2.8/user/listEvents.html"
* />
*/
public class ListEventsOptions {
}

View File

@ -0,0 +1,64 @@
/**
* 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.features;
import java.io.IOException;
import java.lang.reflect.Method;
import com.google.inject.TypeLiteral;
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;
/**
* Tests behavior of {@code EventAsyncClient}
*
* @author Vijay Kiran
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "EventAsyncClientTest")
public class EventAsyncClientTest extends BaseCloudStackAsyncClientTest<EventAsyncClient> {
public void testListEventTypes() throws SecurityException, NoSuchMethodException, IOException {
Method method = EventAsyncClient.class.getMethod("listEventTypes");
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listEventTypes 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);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<EventAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<EventAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,49 @@
/**
* 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.features;
import static org.testng.Assert.assertTrue;
import java.util.Set;
import org.jclouds.cloudstack.domain.EventType;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code EventClient}
*
* @author Vijay Kiran
*/
@Test(groups = "live", singleThreaded = true, testName = "EventClientLiveTest")
public class EventClientLiveTest extends BaseCloudStackClientLiveTest {
public void testlistEventTypes() throws Exception {
Set<EventType> response = client.getEventClient().listEventTypes();
assert null != response;
assertTrue(response.size() >= 0);
for (EventType type : response) {
checkEventType(type);
}
}
protected void checkEventType(EventType eventType) {
assert eventType.getName() != null : eventType;
}
}

View File

@ -0,0 +1 @@
{ "listeventtypesresponse" : { "count":123 ,"eventtype" : [ {"name":"VM.CREATE"}, {"name":"VM.DESTROY"}, {"name":"VM.START"}, {"name":"VM.STOP"}, {"name":"VM.REBOOT"}, {"name":"VM.UPDATE"}, {"name":"VM.UPGRADE"}, {"name":"VM.RESETPASSWORD"}, {"name":"VM.MIGRATE"}, {"name":"ROUTER.CREATE"}, {"name":"ROUTER.DESTROY"}, {"name":"ROUTER.START"}, {"name":"ROUTER.STOP"}, {"name":"ROUTER.REBOOT"}, {"name":"ROUTER.HA"}, {"name":"ROUTER.UPGRADE"}, {"name":"PROXY.CREATE"}, {"name":"PROXY.DESTROY"}, {"name":"PROXY.START"}, {"name":"PROXY.STOP"}, {"name":"PROXY.REBOOT"}, {"name":"PROXY.HA"}, {"name":"VNC.CONNECT"}, {"name":"VNC.DISCONNECT"}, {"name":"NET.IPASSIGN"}, {"name":"NET.IPRELEASE"}, {"name":"NET.RULEADD"}, {"name":"NET.RULEDELETE"}, {"name":"NET.RULEMODIFY"}, {"name":"NETWORK.CREATE"}, {"name":"NETWORK.DELETE"}, {"name":"NETWORK.UPDATE"}, {"name":"LB.ASSIGN.TO.RULE"}, {"name":"LB.REMOVE.FROM.RULE"}, {"name":"LB.CREATE"}, {"name":"LB.DELETE"}, {"name":"LB.UPDATE"}, {"name":"ACCOUNT.DISABLE"}, {"name":"ACCOUNT.CREATE"}, {"name":"ACCOUNT.DELETE"}, {"name":"USER.LOGIN"}, {"name":"USER.LOGOUT"}, {"name":"USER.CREATE"}, {"name":"USER.DELETE"}, {"name":"USER.DISABLE"}, {"name":"USER.UPDATE"}, {"name":"USER.ENABLE"}, {"name":"TEMPLATE.CREATE"}, {"name":"TEMPLATE.DELETE"}, {"name":"TEMPLATE.UPDATE"}, {"name":"TEMPLATE.DOWNLOAD.START"}, {"name":"TEMPLATE.DOWNLOAD.SUCCESS"}, {"name":"TEMPLATE.DOWNLOAD.FAILED"}, {"name":"TEMPLATE.COPY"}, {"name":"TEMPLATE.EXTRACT"}, {"name":"TEMPLATE.UPLOAD"}, {"name":"TEMPLATE.CLEANUP"}, {"name":"VOLUME.CREATE"}, {"name":"VOLUME.DELETE"}, {"name":"VOLUME.ATTACH"}, {"name":"VOLUME.DETACH"}, {"name":"VOLUME.EXTRACT"}, {"name":"VOLUME.UPLOAD"}, {"name":"DOMAIN.CREATE"}, {"name":"DOMAIN.DELETE"}, {"name":"DOMAIN.UPDATE"}, {"name":"SNAPSHOT.CREATE"}, {"name":"SNAPSHOT.DELETE"}, {"name":"SNAPSHOTPOLICY.CREATE"}, {"name":"SNAPSHOTPOLICY.UPDATE"}, {"name":"SNAPSHOTPOLICY.DELETE"}, {"name":"ISO.CREATE"}, {"name":"ISO.DELETE"}, {"name":"ISO.COPY"}, {"name":"ISO.ATTACH"}, {"name":"ISO.DETACH"}, {"name":"ISO.EXTRACT"}, {"name":"ISO.UPLOAD"}, {"name":"SSVM.CREATE"}, {"name":"SSVM.DESTROY"}, {"name":"SSVM.START"}, {"name":"SSVM.STOP"}, {"name":"SSVM.REBOOT"}, {"name":"SSVM.HA"}, {"name":"SERVICE.OFFERING.CREATE"}, {"name":"SERVICE.OFFERING.EDIT"}, {"name":"SERVICE.OFFERING.DELETE"}, {"name":"DISK.OFFERING.CREATE"}, {"name":"DISK.OFFERING.EDIT"}, {"name":"DISK.OFFERING.DELETE"}, {"name":"NETWORK.OFFERING.CREATE"}, {"name":"NETWORK.OFFERING.ASSIGN"}, {"name":"NETWORK.OFFERING.EDIT"}, {"name":"NETWORK.OFFERING.REMOVE"}, {"name":"NETWORK.OFFERING.DELETE"}, {"name":"POD.CREATE"}, {"name":"POD.EDIT"}, {"name":"POD.DELETE"}, {"name":"ZONE.CREATE"}, {"name":"ZONE.EDIT"}, {"name":"ZONE.DELETE"}, {"name":"VLAN.IP.RANGE.CREATE"}, {"name":"VLAN.IP.RANGE.DELETE"}, {"name":"CONFIGURATION.VALUE.EDIT"}, {"name":"SG.AUTH.INGRESS"}, {"name":"SG.REVOKE.INGRESS"}, {"name":"SG.CREATE"}, {"name":"SG.DELETE"}, {"name":"HOST.RECONNECT"}, {"name":"MAINT.CANCEL"}, {"name":"MAINT.CANCEL.PS"}, {"name":"MAINT.PREPARE"}, {"name":"MAINT.PREPARE.PS"}, {"name":"VPN.REMOTE.ACCESS.CREATE"}, {"name":"VPN.REMOTE.ACCESS.DESTROY"}, {"name":"VPN.USER.ADD"}, {"name":"VPN.USER.REMOVE"}, {"name":"NETWORK.RESTART"}, {"name":"UPLOAD.CUSTOM.CERTIFICATE"}, {"name":"STATICNAT.ENABLE"}, {"name":"STATICNAT.DISABLE"}, {"name":"ZONE.VLAN.ASSIGN"}, {"name":"ZONE.VLAN.RELEASE"} ] } }