Adding Host Administration extension

This commit is contained in:
Adam Lowe 2012-04-19 07:25:41 +01:00
parent eef27bbe4e
commit 400221820a
10 changed files with 453 additions and 2 deletions

View File

@ -24,8 +24,10 @@ import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Zone;
import org.jclouds.location.functions.ZoneToEndpoint;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.HostAdministrationAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.SimpleTenantUsageAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.ExtensionAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.FlavorAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.ImageAsyncClient;
@ -103,4 +105,12 @@ public interface NovaAsyncClient {
@Delegate
Optional<KeyPairAsyncClient> getKeyPairExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Host Administration features.
*/
@Delegate
Optional<HostAdministrationAsyncClient> getHostAdministrationExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
}

View File

@ -26,8 +26,10 @@ import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Zone;
import org.jclouds.location.functions.ZoneToEndpoint;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
import org.jclouds.openstack.nova.v1_1.extensions.HostAdministrationClient;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClient;
import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupClient;
import org.jclouds.openstack.nova.v1_1.extensions.SimpleTenantUsageClient;
import org.jclouds.openstack.nova.v1_1.features.ExtensionClient;
import org.jclouds.openstack.nova.v1_1.features.FlavorClient;
import org.jclouds.openstack.nova.v1_1.features.ImageClient;
@ -106,4 +108,11 @@ public interface NovaClient {
Optional<KeyPairClient> getKeyPairExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Host Administration features.
*/
@Delegate
Optional<HostAdministrationClient> getHostAdministrationExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
}

View File

@ -37,6 +37,8 @@ import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.domain.Extension;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
import org.jclouds.openstack.nova.v1_1.extensions.HostAdministrationAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.HostAdministrationClient;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClient;
import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupAsyncClient;
@ -75,7 +77,9 @@ public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsync
.put(ImageClient.class, ImageAsyncClient.class).put(ExtensionClient.class, ExtensionAsyncClient.class)
.put(FloatingIPClient.class, FloatingIPAsyncClient.class)
.put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)
.put(KeyPairClient.class, KeyPairAsyncClient.class).build();
.put(KeyPairClient.class, KeyPairAsyncClient.class)
.put(HostAdministrationClient.class, HostAdministrationAsyncClient.class)
.build();
public NovaRestClientModule() {
super(DELEGATE_MAP);

View File

@ -0,0 +1,126 @@
/**
* 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.openstack.nova.v1_1.domain;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/**
* Class Host
*/
public class Host {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromHost(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
private String name;
private String service;
public T name(String name) {
this.name = name;
return self();
}
public T service(String service) {
this.service = service;
return self();
}
public Host build() {
return new Host(this);
}
public T fromHost(Host in) {
return this
.name(in.getName())
.service(in.getService())
;
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
@SerializedName(value="host_name")
private final String name;
private final String service;
protected Host(Builder<?> builder) {
this.name = builder.name;
this.service = builder.service;
}
/**
*/
@Nullable
public String getName() {
return this.name;
}
/**
*/
@Nullable
public String getService() {
return this.service;
}
@Override
public int hashCode() {
return Objects.hashCode(name, service);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Host that = Host.class.cast(obj);
return Objects.equal(this.name, that.name)
&& Objects.equal(this.service, that.service)
;
}
protected ToStringHelper string() {
return Objects.toStringHelper("")
.add("name", name)
.add("service", service)
;
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -0,0 +1,163 @@
/**
* 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.openstack.nova.v1_1.domain;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/**
* Class HostResourceUsage
*/
public class HostResourceUsage {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromHostResourceUsage(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
private String host;
private String memoryMb;
private int cpu;
private int diskGb;
public T host(String host) {
this.host = host;
return self();
}
public T memoryMb(String memoryMb) {
this.memoryMb = memoryMb;
return self();
}
public T cpu(int cpu) {
this.cpu = cpu;
return self();
}
public T diskGb(int diskGb) {
this.diskGb = diskGb;
return self();
}
public HostResourceUsage build() {
return new HostResourceUsage(this);
}
public T fromHostResourceUsage(HostResourceUsage in) {
return this
.host(in.getHost())
.memoryMb(in.getMemoryMb())
.cpu(in.getCpu())
.diskGb(in.getDiskGb())
;
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String host;
@SerializedName(value = "memory_mb")
private final String memoryMb;
private final int cpu;
@SerializedName(value = "disk_gb")
private final int diskGb;
protected HostResourceUsage(Builder<?> builder) {
this.host = builder.host;
this.memoryMb = builder.memoryMb;
this.cpu = builder.cpu;
this.diskGb = builder.diskGb;
}
/**
*/
@Nullable
public String getHost() {
return this.host;
}
/**
*/
@Nullable
public String getMemoryMb() {
return this.memoryMb;
}
/**
*/
@Nullable
public int getCpu() {
return this.cpu;
}
/**
*/
@Nullable
public int getDiskGb() {
return this.diskGb;
}
@Override
public int hashCode() {
return Objects.hashCode(host, memoryMb, cpu, diskGb);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
HostResourceUsage that = HostResourceUsage.class.cast(obj);
return Objects.equal(this.host, that.host)
&& Objects.equal(this.memoryMb, that.memoryMb)
&& Objects.equal(this.cpu, that.cpu)
&& Objects.equal(this.diskGb, that.diskGb)
;
}
protected ToStringHelper string() {
return Objects.toStringHelper("")
.add("host", host)
.add("memoryMb", memoryMb)
.add("cpu", cpu)
.add("diskGb", diskGb)
;
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -0,0 +1,78 @@
/**
* 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.openstack.nova.v1_1.extensions;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v1_1.domain.Host;
import org.jclouds.openstack.nova.v1_1.domain.HostResourceUsage;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to Host Administration features via the REST API.
* <p/>
*
* @author Adam Lowe
* @see SimpleTenantUsageClient
* @see <a href= "http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html"/>
* @see <a href="http://nova.openstack.org/api_ext" />
* @see <a href="http://nova.openstack.org/api/nova.api.openstack.compute.contrib.hosts.html" />
*/
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.HOSTS)
@SkipEncoding({'/', '='})
@RequestFilters(AuthenticateRequest.class)
public interface HostAdministrationAsyncClient {
/**
* @see HostAdministrationClient#listHosts()
*/
@GET
@Path("/os-hosts")
@SelectJson("hosts")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Host>> listHosts();
/**
* @see HostAdministrationClient#getHostResourceUsage(String)
*/
@GET
@Path("/os-hosts/{id}")
@SelectJson("host")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Set<HostResourceUsage>> getHostResourceUsage(@PathParam("id") String hostId);
}

View File

@ -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.openstack.nova.v1_1.extensions;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.PathParam;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.nova.v1_1.domain.Host;
import org.jclouds.openstack.nova.v1_1.domain.HostResourceUsage;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
/**
* Provides asynchronous access to Host Administration features via the REST API.
* <p/>
*
* @author Adam Lowe
* @see HostAdministrationAsyncClient
*/
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.HOSTS)
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface HostAdministrationClient {
/**
* Returns the list of hosts
* @return the usage information
*/
Set<Host> listHosts();
/**
* Retrieves the physical/usage resource on a specific host
* @return the usage information
*/
Set<HostResourceUsage> getHostResourceUsage(@PathParam("id") String hostId);
}

View File

@ -43,7 +43,7 @@ import com.google.common.collect.Multimap;
/**
* We use the annotation {@link org.jclouds.openstack.services.Extension} to
* bind a class that is an extension to an extension found in the
* {@link ExtensionsClient#listExtensions} call.
* {@link org.jclouds.openstack.nova.v1_1.features.ExtensionClient#listExtensions} call.
*
* @author Adrian Cole
*
@ -62,6 +62,10 @@ public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensio
URI.create("http://docs.openstack.org/compute/ext/floating_ips/api/v1.1"))
.put(URI.create(ExtensionNamespaces.KEYPAIRS),
URI.create("http://docs.openstack.org/compute/ext/keypairs/api/v1.1"))
.put(URI.create(ExtensionNamespaces.SIMPLE_TENANT_USAGE),
URI.create("http://docs.openstack.org/compute/ext/os-simple-tenant-usage/api/v1.1"))
.put(URI.create(ExtensionNamespaces.HOSTS),
URI.create("http://docs.openstack.org/compute/ext/hosts/api/v1.1"))
.build();
@Inject

View File

@ -0,0 +1 @@
{"host": [{"resource": {"project": "(total)", "memory_mb": 16083, "host": "ubuntu", "cpu": 4, "disk_gb": 181}}, {"resource": {"project": "(used_now)", "memory_mb": 3396, "host": "ubuntu", "cpu": 3, "disk_gb": 5}}, {"resource": {"project": "(used_max)", "memory_mb": 6144, "host": "ubuntu", "cpu": 3, "disk_gb": 80}}, {"resource": {"project": "f8535069c3fb404cb61c873b1a0b4921", "memory_mb": 6144, "host": "ubuntu", "cpu": 3, "disk_gb": 80}}]}

View File

@ -0,0 +1 @@
["hosts": [{"host_name": "ubuntu", "service": "compute"}]