mirror of https://github.com/apache/jclouds.git
Issue 29: added monitoring services
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2525 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
57aea2d47b
commit
5613f7662c
|
@ -28,6 +28,7 @@ import org.jclouds.aws.ec2.services.AMIAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient;
|
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.InstanceAsyncClient;
|
import org.jclouds.aws.ec2.services.InstanceAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
|
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
|
||||||
|
import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
|
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
import com.google.inject.ImplementedBy;
|
||||||
|
@ -64,4 +65,9 @@ public interface EC2AsyncClient {
|
||||||
*/
|
*/
|
||||||
SecurityGroupAsyncClient getSecurityGroupServices();
|
SecurityGroupAsyncClient getSecurityGroupServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to Monitoring services.
|
||||||
|
*/
|
||||||
|
MonitoringAsyncClient getMonitoringServices();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.jclouds.aws.ec2.services.AMIClient;
|
||||||
import org.jclouds.aws.ec2.services.ElasticIPAddressClient;
|
import org.jclouds.aws.ec2.services.ElasticIPAddressClient;
|
||||||
import org.jclouds.aws.ec2.services.InstanceClient;
|
import org.jclouds.aws.ec2.services.InstanceClient;
|
||||||
import org.jclouds.aws.ec2.services.KeyPairClient;
|
import org.jclouds.aws.ec2.services.KeyPairClient;
|
||||||
|
import org.jclouds.aws.ec2.services.MonitoringClient;
|
||||||
import org.jclouds.aws.ec2.services.SecurityGroupClient;
|
import org.jclouds.aws.ec2.services.SecurityGroupClient;
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
import com.google.inject.ImplementedBy;
|
||||||
|
@ -64,4 +65,8 @@ public interface EC2Client {
|
||||||
*/
|
*/
|
||||||
SecurityGroupClient getSecurityGroupServices();
|
SecurityGroupClient getSecurityGroupServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to Monitoring services.
|
||||||
|
*/
|
||||||
|
MonitoringClient getMonitoringServices();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ import org.jclouds.aws.ec2.services.InstanceAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.InstanceClient;
|
import org.jclouds.aws.ec2.services.InstanceClient;
|
||||||
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
|
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.KeyPairClient;
|
import org.jclouds.aws.ec2.services.KeyPairClient;
|
||||||
|
import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
|
||||||
|
import org.jclouds.aws.ec2.services.MonitoringClient;
|
||||||
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
|
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.SecurityGroupClient;
|
import org.jclouds.aws.ec2.services.SecurityGroupClient;
|
||||||
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
|
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
|
||||||
|
@ -113,18 +115,18 @@ public class EC2RestClientModule extends AbstractModule {
|
||||||
return SyncProxy.create(AMIClient.class, client);
|
return SyncProxy.create(AMIClient.class, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected ElasticIPAddressAsyncClient provideElasticIPAddressAsyncClient(RestClientFactory factory) {
|
protected ElasticIPAddressAsyncClient provideElasticIPAddressAsyncClient(
|
||||||
return factory.create( ElasticIPAddressAsyncClient.class);
|
RestClientFactory factory) {
|
||||||
|
return factory.create(ElasticIPAddressAsyncClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public ElasticIPAddressClient provideElasticIPAddressClient( ElasticIPAddressAsyncClient client) throws IllegalArgumentException,
|
public ElasticIPAddressClient provideElasticIPAddressClient(ElasticIPAddressAsyncClient client)
|
||||||
SecurityException, NoSuchMethodException {
|
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||||
return SyncProxy.create( ElasticIPAddressClient.class, client);
|
return SyncProxy.create(ElasticIPAddressClient.class, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -135,10 +137,11 @@ public class EC2RestClientModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public InstanceClient provideInstanceClient(InstanceAsyncClient client) throws IllegalArgumentException,
|
public InstanceClient provideInstanceClient(InstanceAsyncClient client)
|
||||||
SecurityException, NoSuchMethodException {
|
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||||
return SyncProxy.create(InstanceClient.class, client);
|
return SyncProxy.create(InstanceClient.class, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected KeyPairAsyncClient provideKeyPairAsyncClient(RestClientFactory factory) {
|
protected KeyPairAsyncClient provideKeyPairAsyncClient(RestClientFactory factory) {
|
||||||
|
@ -147,10 +150,11 @@ public class EC2RestClientModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public KeyPairClient provideKeyPairClient(KeyPairAsyncClient client) throws IllegalArgumentException,
|
public KeyPairClient provideKeyPairClient(KeyPairAsyncClient client)
|
||||||
SecurityException, NoSuchMethodException {
|
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||||
return SyncProxy.create(KeyPairClient.class, client);
|
return SyncProxy.create(KeyPairClient.class, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected SecurityGroupAsyncClient provideSecurityGroupAsyncClient(RestClientFactory factory) {
|
protected SecurityGroupAsyncClient provideSecurityGroupAsyncClient(RestClientFactory factory) {
|
||||||
|
@ -159,10 +163,24 @@ public class EC2RestClientModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public SecurityGroupClient provideSecurityGroupClient(SecurityGroupAsyncClient client) throws IllegalArgumentException,
|
public SecurityGroupClient provideSecurityGroupClient(SecurityGroupAsyncClient client)
|
||||||
SecurityException, NoSuchMethodException {
|
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||||
return SyncProxy.create(SecurityGroupClient.class, client);
|
return SyncProxy.create(SecurityGroupClient.class, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
protected MonitoringAsyncClient provideMonitoringAsyncClient(RestClientFactory factory) {
|
||||||
|
return factory.create(MonitoringAsyncClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
public MonitoringClient provideMonitoringClient(MonitoringAsyncClient client)
|
||||||
|
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||||
|
return SyncProxy.create(MonitoringClient.class, client);
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@EC2
|
@EC2
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.aws.ec2.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.jclouds.aws.ec2.services.InstanceClient;
|
||||||
|
import org.jclouds.aws.ec2.services.MonitoringClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* State of monitoring for the instance.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
* @see InstanceClient#runInstances
|
||||||
|
* @see MonitoringClient#monitorInstances
|
||||||
|
* @see MonitoringClient#UnmonitorInstances
|
||||||
|
*/
|
||||||
|
public enum MonitoringState {
|
||||||
|
|
||||||
|
PENDING, ENABLED, DISABLING, DISABLED;
|
||||||
|
|
||||||
|
public String value() {
|
||||||
|
return name().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MonitoringState fromValue(String state) {
|
||||||
|
return valueOf(checkNotNull(state, "state").toUpperCase());
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,6 +33,7 @@ import org.jclouds.aws.ec2.services.AMIAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient;
|
import org.jclouds.aws.ec2.services.ElasticIPAddressAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.InstanceAsyncClient;
|
import org.jclouds.aws.ec2.services.InstanceAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
|
import org.jclouds.aws.ec2.services.KeyPairAsyncClient;
|
||||||
|
import org.jclouds.aws.ec2.services.MonitoringAsyncClient;
|
||||||
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
|
import org.jclouds.aws.ec2.services.SecurityGroupAsyncClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,18 +48,20 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
|
||||||
private final InstanceAsyncClient instanceServices;
|
private final InstanceAsyncClient instanceServices;
|
||||||
private final KeyPairAsyncClient keyPairServices;
|
private final KeyPairAsyncClient keyPairServices;
|
||||||
private final SecurityGroupAsyncClient securityGroupServices;
|
private final SecurityGroupAsyncClient securityGroupServices;
|
||||||
|
private final MonitoringAsyncClient monitoringServices;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public EC2AsyncClientImpl(AMIAsyncClient AMIServices,
|
public EC2AsyncClientImpl(AMIAsyncClient AMIServices,
|
||||||
ElasticIPAddressAsyncClient elasticIPAddressServices,
|
ElasticIPAddressAsyncClient elasticIPAddressServices,
|
||||||
InstanceAsyncClient instanceServices, KeyPairAsyncClient keyPairServices,
|
InstanceAsyncClient instanceServices, KeyPairAsyncClient keyPairServices,
|
||||||
SecurityGroupAsyncClient securityGroupServices) {
|
SecurityGroupAsyncClient securityGroupServices, MonitoringAsyncClient monitoringServices) {
|
||||||
this.AMIServices = checkNotNull(AMIServices, "AMIServices");
|
this.AMIServices = checkNotNull(AMIServices, "AMIServices");
|
||||||
this.elasticIPAddressServices = checkNotNull(elasticIPAddressServices,
|
this.elasticIPAddressServices = checkNotNull(elasticIPAddressServices,
|
||||||
"elasticIPAddressServices");
|
"elasticIPAddressServices");
|
||||||
this.instanceServices = checkNotNull(instanceServices, "instanceServices");
|
this.instanceServices = checkNotNull(instanceServices, "instanceServices");
|
||||||
this.keyPairServices = checkNotNull(keyPairServices, "keyPairServices");
|
this.keyPairServices = checkNotNull(keyPairServices, "keyPairServices");
|
||||||
this.securityGroupServices = checkNotNull(securityGroupServices, "securityGroupServices");
|
this.securityGroupServices = checkNotNull(securityGroupServices, "securityGroupServices");
|
||||||
|
this.monitoringServices = checkNotNull(monitoringServices, "monitoringServices");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,4 +99,12 @@ public class EC2AsyncClientImpl implements EC2AsyncClient {
|
||||||
return securityGroupServices;
|
return securityGroupServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MonitoringAsyncClient getMonitoringServices() {
|
||||||
|
return monitoringServices;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.aws.ec2.services.AMIClient;
|
||||||
import org.jclouds.aws.ec2.services.ElasticIPAddressClient;
|
import org.jclouds.aws.ec2.services.ElasticIPAddressClient;
|
||||||
import org.jclouds.aws.ec2.services.InstanceClient;
|
import org.jclouds.aws.ec2.services.InstanceClient;
|
||||||
import org.jclouds.aws.ec2.services.KeyPairClient;
|
import org.jclouds.aws.ec2.services.KeyPairClient;
|
||||||
|
import org.jclouds.aws.ec2.services.MonitoringClient;
|
||||||
import org.jclouds.aws.ec2.services.SecurityGroupClient;
|
import org.jclouds.aws.ec2.services.SecurityGroupClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,17 +48,19 @@ public class EC2ClientImpl implements EC2Client {
|
||||||
private final InstanceClient instanceServices;
|
private final InstanceClient instanceServices;
|
||||||
private final KeyPairClient keyPairServices;
|
private final KeyPairClient keyPairServices;
|
||||||
private final SecurityGroupClient securityGroupServices;
|
private final SecurityGroupClient securityGroupServices;
|
||||||
|
private final MonitoringClient monitoringServices;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public EC2ClientImpl(AMIClient AMIServices, ElasticIPAddressClient elasticIPAddressServices,
|
public EC2ClientImpl(AMIClient AMIServices, ElasticIPAddressClient elasticIPAddressServices,
|
||||||
InstanceClient instanceServices, KeyPairClient keyPairServices,
|
InstanceClient instanceServices, KeyPairClient keyPairServices,
|
||||||
SecurityGroupClient securityGroupServices) {
|
SecurityGroupClient securityGroupServices, MonitoringClient monitoringServices) {
|
||||||
this.AMIServices = checkNotNull(AMIServices, "AMIServices");
|
this.AMIServices = checkNotNull(AMIServices, "AMIServices");
|
||||||
this.elasticIPAddressServices = checkNotNull(elasticIPAddressServices,
|
this.elasticIPAddressServices = checkNotNull(elasticIPAddressServices,
|
||||||
"elasticIPAddressServices");
|
"elasticIPAddressServices");
|
||||||
this.instanceServices = checkNotNull(instanceServices, "instanceServices");
|
this.instanceServices = checkNotNull(instanceServices, "instanceServices");
|
||||||
this.keyPairServices = checkNotNull(keyPairServices, "keyPairServices");
|
this.keyPairServices = checkNotNull(keyPairServices, "keyPairServices");
|
||||||
this.securityGroupServices = checkNotNull(securityGroupServices, "securityGroupServices");
|
this.securityGroupServices = checkNotNull(securityGroupServices, "securityGroupServices");
|
||||||
|
this.monitoringServices = checkNotNull(monitoringServices, "monitoringServices");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,4 +98,11 @@ public class EC2ClientImpl implements EC2Client {
|
||||||
return securityGroupServices;
|
return securityGroupServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public MonitoringClient getMonitoringServices() {
|
||||||
|
return monitoringServices;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.aws.ec2.services;
|
||||||
|
|
||||||
|
import static org.jclouds.aws.ec2.reference.EC2Parameters.ACTION;
|
||||||
|
import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
|
import org.jclouds.aws.ec2.EC2;
|
||||||
|
import org.jclouds.aws.ec2.binders.BindInstanceIdsToIndexedFormParams;
|
||||||
|
import org.jclouds.aws.ec2.domain.MonitoringState;
|
||||||
|
import org.jclouds.aws.ec2.filters.FormSigner;
|
||||||
|
import org.jclouds.aws.ec2.xml.MonitoringStateHandler;
|
||||||
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
|
import org.jclouds.rest.annotations.Endpoint;
|
||||||
|
import org.jclouds.rest.annotations.FormParams;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.VirtualHost;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides access to EC2 Monitoring Services via their REST API.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Endpoint(EC2.class)
|
||||||
|
@RequestFilters(FormSigner.class)
|
||||||
|
@FormParams(keys = VERSION, values = "2009-11-30")
|
||||||
|
@VirtualHost
|
||||||
|
public interface MonitoringAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Monitoring#monitorInstances
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = ACTION, values = "MonitorInstances")
|
||||||
|
@XMLResponseParser(MonitoringStateHandler.class)
|
||||||
|
Future<? extends Map<String, MonitoringState>> monitorInstances(
|
||||||
|
@FormParam("InstanceId.0") String instanceId,
|
||||||
|
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Monitoring#monitorInstances
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = ACTION, values = "UnmonitorInstances")
|
||||||
|
@XMLResponseParser(MonitoringStateHandler.class)
|
||||||
|
Future<? extends Map<String, MonitoringState>> unmonitorInstances(
|
||||||
|
@FormParam("InstanceId.0") String instanceId,
|
||||||
|
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.aws.ec2.services;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.aws.ec2.domain.MonitoringState;
|
||||||
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides monitoring services for EC2. For more information, refer to the Amazon CloudWatch Developer Guide.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface MonitoringClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables monitoring for a running instance. For more information, refer to the Amazon CloudWatch Developer Guide.
|
||||||
|
*
|
||||||
|
* @see InstanceClient#runInstances
|
||||||
|
* @see #unmonitorInstances
|
||||||
|
*
|
||||||
|
* @see <a href=
|
||||||
|
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-MonitorInstances.html"
|
||||||
|
* />
|
||||||
|
*/
|
||||||
|
Map<String, MonitoringState> monitorInstances(String instanceId, String... instanceIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables monitoring for a running instance. For more information, refer to the Amazon CloudWatch Developer Guide.
|
||||||
|
*
|
||||||
|
* @see InstanceClient#runInstances
|
||||||
|
* @see #monitorInstances
|
||||||
|
*
|
||||||
|
* @see <a href=
|
||||||
|
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-UnmonitorInstances.html"
|
||||||
|
* />
|
||||||
|
*/
|
||||||
|
Map<String, MonitoringState> unmonitorInstances(String instanceId, String... instanceIds);
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.aws.ec2.xml;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jclouds.aws.ec2.domain.MonitoringState;
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class MonitoringStateHandler extends
|
||||||
|
ParseSax.HandlerWithResult<Map<String, MonitoringState>> {
|
||||||
|
private StringBuilder currentText = new StringBuilder();
|
||||||
|
|
||||||
|
private Map<String, MonitoringState> monitoringState = Maps.newHashMap();
|
||||||
|
private String instanceId;
|
||||||
|
private MonitoringState state;
|
||||||
|
|
||||||
|
public Map<String, MonitoringState> getResult() {
|
||||||
|
return monitoringState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endElement(String uri, String name, String qName) {
|
||||||
|
if (qName.equals("instanceId")) {
|
||||||
|
instanceId = currentText.toString().trim();
|
||||||
|
} else if (qName.equals("state")) {
|
||||||
|
state = MonitoringState.fromValue(currentText.toString().trim());
|
||||||
|
} else if (qName.equals("item")) {
|
||||||
|
monitoringState.put(instanceId, state);
|
||||||
|
this.instanceId = null;
|
||||||
|
this.state = null;
|
||||||
|
}
|
||||||
|
currentText = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void characters(char ch[], int start, int length) {
|
||||||
|
currentText.append(ch, start, length);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,137 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.aws.ec2.services;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.aws.ec2.EC2;
|
||||||
|
import org.jclouds.aws.ec2.filters.FormSigner;
|
||||||
|
import org.jclouds.aws.ec2.xml.MonitoringStateHandler;
|
||||||
|
import org.jclouds.aws.reference.AWSConstants;
|
||||||
|
import org.jclouds.date.TimeStamp;
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.logging.Logger.LoggerFactory;
|
||||||
|
import org.jclouds.rest.RestClientTest;
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
import org.jclouds.util.Jsr330;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code MonitoringAsyncClient}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "ec2.MonitoringAsyncClientTest")
|
||||||
|
public class MonitoringAsyncClientTest extends RestClientTest<MonitoringAsyncClient> {
|
||||||
|
|
||||||
|
public void testUnmonitorInstances() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
|
Method method = MonitoringAsyncClient.class.getMethod("unmonitorInstances", String.class,
|
||||||
|
Array.newInstance(String.class, 0).getClass());
|
||||||
|
GeneratedHttpRequest<MonitoringAsyncClient> httpMethod = processor.createRequest(method,
|
||||||
|
"instance1", "instance2");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpMethod,
|
||||||
|
"Content-Length: 67\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
|
||||||
|
assertPayloadEquals(httpMethod,
|
||||||
|
"Version=2009-11-30&Action=UnmonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2");
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMonitorInstances() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
|
Method method = MonitoringAsyncClient.class.getMethod("monitorInstances", String.class,
|
||||||
|
Array.newInstance(String.class, 0).getClass());
|
||||||
|
GeneratedHttpRequest<MonitoringAsyncClient> httpMethod = processor.createRequest(method,
|
||||||
|
"instance1", "instance2");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpMethod,
|
||||||
|
"Content-Length: 65\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
|
||||||
|
assertPayloadEquals(httpMethod,
|
||||||
|
"Version=2009-11-30&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2");
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpMethod);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void checkFilters(GeneratedHttpRequest<MonitoringAsyncClient> httpMethod) {
|
||||||
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
|
assertEquals(httpMethod.getFilters().get(0).getClass(), FormSigner.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TypeLiteral<RestAnnotationProcessor<MonitoringAsyncClient>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<MonitoringAsyncClient>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Module createModule() {
|
||||||
|
return new AbstractModule() {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(URI.class).annotatedWith(EC2.class).toInstance(
|
||||||
|
URI.create("https://ec2.amazonaws.com"));
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to(
|
||||||
|
"user");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_SECRETACCESSKEY))
|
||||||
|
.to("key");
|
||||||
|
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||||
|
public Logger getLogger(String category) {
|
||||||
|
return Logger.NULL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Provides
|
||||||
|
@TimeStamp
|
||||||
|
String provide() {
|
||||||
|
return "2009-11-08T15:54:08.897Z";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.aws.ec2.services;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jclouds.aws.ec2.EC2AsyncClient;
|
||||||
|
import org.jclouds.aws.ec2.EC2Client;
|
||||||
|
import org.jclouds.aws.ec2.EC2ContextFactory;
|
||||||
|
import org.jclouds.aws.ec2.domain.MonitoringState;
|
||||||
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.testng.annotations.BeforeGroups;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code MonitoringClient}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "live", sequential = true, testName = "ec2.MonitoringClientLiveTest")
|
||||||
|
public class MonitoringClientLiveTest {
|
||||||
|
|
||||||
|
private MonitoringClient client;
|
||||||
|
private static final String DEFAULT_INSTANCE = "i-TODO";
|
||||||
|
private RestContext<EC2AsyncClient, EC2Client> context;
|
||||||
|
|
||||||
|
@BeforeGroups(groups = { "live" })
|
||||||
|
public void setupClient() {
|
||||||
|
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
||||||
|
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||||
|
|
||||||
|
context = EC2ContextFactory.createContext(user, password, new Log4JLoggingModule());
|
||||||
|
client = context.getApi().getMonitoringServices();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false)
|
||||||
|
// TODO get instance
|
||||||
|
public void testMonitorInstances() {
|
||||||
|
Map<String, MonitoringState> monitoringState = client.monitorInstances(DEFAULT_INSTANCE);
|
||||||
|
assertEquals(monitoringState.get(DEFAULT_INSTANCE), MonitoringState.PENDING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false)
|
||||||
|
// TODO get instance
|
||||||
|
public void testUnmonitorInstances() {
|
||||||
|
Map<String, MonitoringState> monitoringState = client.unmonitorInstances(DEFAULT_INSTANCE);
|
||||||
|
assertEquals(monitoringState.get(DEFAULT_INSTANCE), MonitoringState.PENDING);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.aws.ec2.xml;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jclouds.aws.ec2.domain.MonitoringState;
|
||||||
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code MonitoringStateHandler}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "ec2.MonitoringStateHandlerTest")
|
||||||
|
public class MonitoringStateHandlerTest extends BaseHandlerTest {
|
||||||
|
public void testApplyInputStream() {
|
||||||
|
|
||||||
|
InputStream is = getClass().getResourceAsStream("/ec2/monitoring.xml");
|
||||||
|
|
||||||
|
Map<String, MonitoringState> expected = ImmutableMap.<String, MonitoringState> of(
|
||||||
|
"i-43a4412a", MonitoringState.PENDING, "i-23a3397d", MonitoringState.PENDING);
|
||||||
|
|
||||||
|
Map<String, MonitoringState> result = factory.create(
|
||||||
|
injector.getInstance(MonitoringStateHandler.class)).parse(is);
|
||||||
|
|
||||||
|
assertEquals(result, expected);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<UnmonitorInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
|
||||||
|
<instancesSet>
|
||||||
|
<item>
|
||||||
|
<instanceId> i-43a4412a</instanceId>
|
||||||
|
<monitoring>
|
||||||
|
<state>pending</state>
|
||||||
|
</monitoring>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<instanceId>i-23a3397d</instanceId>
|
||||||
|
<monitoring>
|
||||||
|
<state>pending</state>
|
||||||
|
</monitoring>
|
||||||
|
</item>
|
||||||
|
</instancesSet>
|
||||||
|
</UnmonitorInstancesResponse>
|
Loading…
Reference in New Issue