mirror of https://github.com/apache/jclouds.git
Merge pull request #211 from richardcloudsoft/cloudstack-monitoring
Implement the CloudStack 'alerts' API
This commit is contained in:
commit
f1334fb999
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.cloudstack;
|
||||
|
||||
import org.jclouds.cloudstack.features.GlobalAccountAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertAsyncClient;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
/**
|
||||
|
@ -34,10 +35,16 @@ import org.jclouds.rest.annotations.Delegate;
|
|||
public interface CloudStackGlobalAsyncClient extends CloudStackDomainAsyncClient {
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Accounts
|
||||
* Provides asynchronous access to Accounts
|
||||
*/
|
||||
@Delegate
|
||||
@Override
|
||||
GlobalAccountAsyncClient getAccountClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Alerts
|
||||
*/
|
||||
@Delegate
|
||||
GlobalAlertAsyncClient getAlertClient();
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudstack;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.features.GlobalAccountClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertClient;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
|
@ -43,4 +44,11 @@ public interface CloudStackGlobalClient extends CloudStackDomainClient {
|
|||
@Delegate
|
||||
@Override
|
||||
GlobalAccountClient getAccountClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Alerts
|
||||
*/
|
||||
@Delegate
|
||||
GlobalAlertClient getAlertClient();
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.cloudstack.CloudStackAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.CloudStackDomainAsyncClient;
|
||||
|
@ -44,6 +44,8 @@ import org.jclouds.cloudstack.features.FirewallAsyncClient;
|
|||
import org.jclouds.cloudstack.features.FirewallClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAccountAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAccountClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertClient;
|
||||
import org.jclouds.cloudstack.features.GuestOSAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GuestOSClient;
|
||||
import org.jclouds.cloudstack.features.HypervisorAsyncClient;
|
||||
|
@ -90,8 +92,7 @@ import org.jclouds.rest.config.BinderUtils;
|
|||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Configures the cloudstack connection.
|
||||
|
@ -128,6 +129,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
|||
.put(ISOClient.class, ISOAsyncClient.class)//
|
||||
.put(VolumeClient.class, VolumeAsyncClient.class)//
|
||||
.put(SnapshotClient.class, SnapshotAsyncClient.class)//
|
||||
.put(GlobalAlertClient.class, GlobalAlertAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Represents an alert issued by Cloudstack
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class Alert implements Comparable<Alert> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private long id;
|
||||
private String description;
|
||||
private Date sent;
|
||||
private String type;
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder sent(Date sent) {
|
||||
this.sent = sent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Alert build() {
|
||||
return new Alert(id, description, sent, type);
|
||||
}
|
||||
}
|
||||
|
||||
private long id;
|
||||
private String description;
|
||||
private Date sent;
|
||||
private String type;
|
||||
|
||||
/* exists for the deserializer, only */
|
||||
Alert() {
|
||||
}
|
||||
|
||||
private Alert(long id, String description, Date sent, String type) {
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
this.sent = sent;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Date getSent() {
|
||||
return sent;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Alert alert = (Alert) o;
|
||||
|
||||
if (id != alert.id) return false;
|
||||
if (description != null ? !description.equals(alert.description) : alert.description != null) return false;
|
||||
if (sent != null ? !sent.equals(alert.sent) : alert.sent != null) return false;
|
||||
if (type != null ? !type.equals(alert.type) : alert.type != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) (id ^ (id >>> 32));
|
||||
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||
result = 31 * result + (sent != null ? sent.hashCode() : 0);
|
||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Alert{" +
|
||||
"id=" + id +
|
||||
", description='" + description + '\'' +
|
||||
", sent=" + sent +
|
||||
", type='" + type + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Alert other) {
|
||||
return Long.valueOf(this.getId()).compareTo(other.getId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* 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 com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.cloudstack.domain.Alert;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListAlertsOptions;
|
||||
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;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to CloudStack Account features available to Global
|
||||
* Admin users.
|
||||
*
|
||||
* @author Richard Downer
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html"
|
||||
* />
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface GlobalAlertAsyncClient {
|
||||
|
||||
/**
|
||||
* @see GlobalAlertClient#listAlerts(org.jclouds.cloudstack.options.ListAlertsOptions...)
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listAlerts")
|
||||
@SelectJson("alert")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Alert>> listAlerts(ListAlertsOptions...options);
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* 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 org.jclouds.cloudstack.domain.Alert;
|
||||
import org.jclouds.cloudstack.options.ListAlertsOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack Alerts features available to Global
|
||||
* Admin users.
|
||||
*
|
||||
* @author Richard Downer
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html"
|
||||
* />
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface GlobalAlertClient {
|
||||
|
||||
/**
|
||||
* List Alerts
|
||||
*
|
||||
* @return alert list or null if not found
|
||||
*/
|
||||
Set<Alert> listAlerts(ListAlertsOptions... options);
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Options to the listAlerts command.
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class ListAlertsOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListAlertsOptions NONE = new ListAlertsOptions();
|
||||
|
||||
public ListAlertsOptions id(long id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListAlertsOptions keyword(String keyword) {
|
||||
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListAlertsOptions type(String type) {
|
||||
this.queryParameters.replaceValues("type", ImmutableSet.of(type));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
public static ListAlertsOptions id(long id) {
|
||||
final ListAlertsOptions options = new ListAlertsOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
public static ListAlertsOptions keyword(String keyword) {
|
||||
final ListAlertsOptions options = new ListAlertsOptions();
|
||||
return options.keyword(keyword);
|
||||
}
|
||||
|
||||
public static ListAlertsOptions type(String type) {
|
||||
final ListAlertsOptions options = new ListAlertsOptions();
|
||||
return options.type(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,22 +18,20 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.get;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import org.jclouds.cloudstack.CloudStackAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.CloudStackContext;
|
||||
import org.jclouds.cloudstack.CloudStackDomainAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackDomainClient;
|
||||
import org.jclouds.cloudstack.CloudStackGlobalAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackGlobalClient;
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.Template;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
|
@ -63,13 +61,16 @@ import org.jclouds.sshj.config.SshjSshClientModule;
|
|||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.get;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -78,6 +79,8 @@ import com.google.inject.Module;
|
|||
public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
|
||||
protected String domainAdminIdentity;
|
||||
protected String domainAdminCredential;
|
||||
protected String globalAdminIdentity;
|
||||
protected String globalAdminCredential;
|
||||
|
||||
public BaseCloudStackClientLiveTest() {
|
||||
provider = "cloudstack";
|
||||
|
@ -88,9 +91,11 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
|
|||
super.setupCredentials();
|
||||
domainAdminIdentity = emptyToNull(System.getProperty("test." + provider + ".domainAdminIdentity"));
|
||||
domainAdminCredential = emptyToNull(System.getProperty("test." + provider + ".domainAdminCredential"));
|
||||
globalAdminIdentity = emptyToNull(System.getProperty("test." + provider + ".globalAdminIdentity"));
|
||||
globalAdminCredential = emptyToNull(System.getProperty("test." + provider + ".globalAdminCredential"));
|
||||
}
|
||||
|
||||
protected Properties setupAdminProperties() {
|
||||
protected Properties setupDomainAdminProperties() {
|
||||
if (domainAdminIdentity != null && domainAdminCredential != null) {
|
||||
Properties overrides = setupProperties();
|
||||
overrides.setProperty(provider + ".identity", domainAdminIdentity);
|
||||
|
@ -101,6 +106,17 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
protected Properties setupGlobalAdminProperties() {
|
||||
if (globalAdminIdentity != null && globalAdminCredential != null) {
|
||||
Properties overrides = setupProperties();
|
||||
overrides.setProperty(provider + ".identity", globalAdminIdentity);
|
||||
overrides.setProperty(provider + ".credential", globalAdminCredential);
|
||||
return overrides;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static long defaultTemplateOrPreferredInZone(Long defaultTemplate, CloudStackClient client, long zoneId) {
|
||||
long templateId = defaultTemplate != null ? defaultTemplate : getTemplateForZone(client, zoneId);
|
||||
return templateId;
|
||||
|
@ -157,6 +173,12 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
|
|||
protected CloudStackClient domainAdminClient;
|
||||
protected User domainAdminUser;
|
||||
|
||||
protected boolean globalAdminEnabled;
|
||||
protected CloudStackContext globalAdminComputeContext;
|
||||
protected RestContext<CloudStackGlobalClient, CloudStackGlobalAsyncClient> globalAdminContext;
|
||||
protected CloudStackGlobalClient globalAdminClient;
|
||||
protected User globalAdminUser;
|
||||
|
||||
protected void checkSSH(IPSocket socket) {
|
||||
socketTester.apply(socket);
|
||||
SshClient client = sshFactory.create(socket, new Credentials("root", password));
|
||||
|
@ -183,18 +205,28 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
|
|||
client = context.getApi();
|
||||
user = verifyCurrentUserIsOfType(context, Account.Type.USER);
|
||||
|
||||
domainAdminEnabled = setupAdminProperties() != null;
|
||||
|
||||
domainAdminEnabled = setupDomainAdminProperties() != null;
|
||||
if (domainAdminEnabled) {
|
||||
domainAdminComputeContext = CloudStackContext.class.cast(new ComputeServiceContextFactory(setupRestProperties()).
|
||||
createContext(provider, ImmutableSet.<Module> of(
|
||||
new Log4JLoggingModule(), new SshjSshClientModule()), setupAdminProperties()));
|
||||
new Log4JLoggingModule(), new SshjSshClientModule()), setupDomainAdminProperties()));
|
||||
domainAdminContext = domainAdminComputeContext.getDomainContext();
|
||||
domainAdminClient = domainAdminContext.getApi();
|
||||
domainAdminUser = verifyCurrentUserIsOfType(domainAdminContext, Account.Type.DOMAIN_ADMIN);
|
||||
adminClient = domainAdminContext.getApi();
|
||||
}
|
||||
|
||||
globalAdminEnabled = setupDomainAdminProperties() != null;
|
||||
if (globalAdminEnabled) {
|
||||
globalAdminComputeContext = CloudStackContext.class.cast(new ComputeServiceContextFactory(setupRestProperties()).
|
||||
createContext(provider, ImmutableSet.<Module> of(
|
||||
new Log4JLoggingModule(), new SshjSshClientModule()), setupGlobalAdminProperties()));
|
||||
globalAdminContext = globalAdminComputeContext.getGlobalContext();
|
||||
globalAdminClient = globalAdminContext.getApi();
|
||||
globalAdminUser = verifyCurrentUserIsOfType(globalAdminContext, Account.Type.ADMIN);
|
||||
adminClient = globalAdminContext.getApi();
|
||||
}
|
||||
|
||||
injector = Guice.createInjector(new SshjSshClientModule(), new Log4JLoggingModule());
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, 1, TimeUnit.SECONDS);
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* 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 com.google.inject.TypeLiteral;
|
||||
import org.jclouds.cloudstack.options.ListAlertsOptions;
|
||||
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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobalAlertsAsyncClient}
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during
|
||||
// surefire
|
||||
@Test(groups = "unit", testName = "GlobalAlertAsyncClientTest")
|
||||
public class GlobalAlertAsyncClientTest extends BaseCloudStackAsyncClientTest<GlobalAlertAsyncClient> {
|
||||
|
||||
public void testListAlerts() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = GlobalAlertAsyncClient.class.getMethod("listAlerts", ListAlertsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listAlerts 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 testListAlertsOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = GlobalAlertAsyncClient.class.getMethod("listAlerts", ListAlertsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListAlertsOptions.Builder.id(42).keyword("jclouds").type("TEMPLATE"));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listAlerts&id=42&keyword=jclouds&type=TEMPLATE 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<GlobalAlertAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GlobalAlertAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* 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 org.jclouds.cloudstack.domain.Alert;
|
||||
import org.jclouds.cloudstack.options.ListAlertsOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobalAlertsClient}
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "GlobalAlertClientLiveTest")
|
||||
public class GlobalAlertClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
@Test(groups = "live", enabled = true)
|
||||
public void testListAlerts() throws Exception {
|
||||
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
|
||||
|
||||
final Set<Alert> response = globalAdminClient.getAlertClient().listAlerts(ListAlertsOptions.Builder.id(20));
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
int count = 0;
|
||||
for (Alert alert : response) {
|
||||
assertNotNull(alert.getDescription());
|
||||
assertNotSame(alert.getId(), 0);
|
||||
assertNotNull(alert.getType());
|
||||
assertNotNull(alert.getSent());
|
||||
count++;
|
||||
}
|
||||
assertTrue(count > 0, "No alerts were returned, so I couldn't test");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListAlertsOptions.Builder.id;
|
||||
import static org.jclouds.cloudstack.options.ListAlertsOptions.Builder.keyword;
|
||||
import static org.jclouds.cloudstack.options.ListAlertsOptions.Builder.type;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListAlertsOptions}
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListAlertsOptionsTest {
|
||||
|
||||
public void testId() {
|
||||
ListAlertsOptions options = new ListAlertsOptions().id(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testIdStatic() {
|
||||
ListAlertsOptions options = id(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testKeyword() {
|
||||
ListAlertsOptions options = new ListAlertsOptions().keyword("fred");
|
||||
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword"));
|
||||
}
|
||||
|
||||
public void testKeywordStatic() {
|
||||
ListAlertsOptions options = keyword("fred");
|
||||
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword"));
|
||||
}
|
||||
|
||||
public void testType() {
|
||||
ListAlertsOptions options = new ListAlertsOptions().type("42");
|
||||
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("type"));
|
||||
}
|
||||
|
||||
public void testTypeStatic() {
|
||||
ListAlertsOptions options = type("42");
|
||||
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("type"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* 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.parse;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jclouds.cloudstack.config.CloudStackParserModule;
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.Account.State;
|
||||
import org.jclouds.cloudstack.domain.Account.Type;
|
||||
import org.jclouds.cloudstack.domain.Alert;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.json.BaseSetParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
import sun.util.resources.CalendarData;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListAlertsResponseTest extends BaseSetParserTest<Alert> {
|
||||
|
||||
@Override
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new CloudStackParserModule(), new GsonModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/listalertsresponse.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("alert")
|
||||
public Set<Alert> expected() {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.YEAR, 2011);
|
||||
c.set(Calendar.MONTH, Calendar.DECEMBER);
|
||||
c.set(Calendar.DAY_OF_MONTH, 4);
|
||||
c.set(Calendar.HOUR_OF_DAY, 12);
|
||||
c.set(Calendar.MINUTE, 5);
|
||||
c.set(Calendar.SECOND, 2);
|
||||
return ImmutableSet.of(Alert.builder()
|
||||
.id(20).description("Failed to deploy Vm with Id: 52").sent(c.getTime()).type("7").build());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{ "listalertsresponse" : { "count":1 ,"alert" : [ {"id":20,"type":7,"description":"Failed to deploy Vm with Id: 52","sent":"2011-12-04T10:05:02+0200"} ] } }
|
Loading…
Reference in New Issue