mirror of https://github.com/apache/jclouds.git
Add GlobalHost[Async]Client.addCluster()
This commit is contained in:
parent
533e13fc44
commit
4734505310
|
@ -22,6 +22,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
import org.jclouds.cloudstack.domain.Cluster;
|
||||
import org.jclouds.cloudstack.domain.Host;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.AddClusterOptions;
|
||||
import org.jclouds.cloudstack.options.AddHostOptions;
|
||||
import org.jclouds.cloudstack.options.AddSecondaryStorageOptions;
|
||||
import org.jclouds.cloudstack.options.DeleteHostOptions;
|
||||
|
@ -173,4 +174,20 @@ public interface GlobalHostAsyncClient {
|
|||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Cluster>> listClusters(ListClustersOptions... options);
|
||||
|
||||
/**
|
||||
* Adds a new cluster.
|
||||
*
|
||||
* @param zoneId the Zone ID for the cluster
|
||||
* @param clusterName the cluster name
|
||||
* @param clusterType type of the cluster
|
||||
* @param hypervisor hypervisor type of the cluster
|
||||
* @param options optional arguments
|
||||
* @return the new cluster.
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "addCluster")
|
||||
@SelectJson("cluster")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Cluster> addCluster(@QueryParam("zoneid") long zoneId, @QueryParam("clustername") String clusterName, @QueryParam("clustertype") Host.ClusterType clusterType, @QueryParam("hypervisor") String hypervisor, AddClusterOptions... options);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.cloudstack.features;
|
|||
|
||||
import org.jclouds.cloudstack.domain.Cluster;
|
||||
import org.jclouds.cloudstack.domain.Host;
|
||||
import org.jclouds.cloudstack.options.AddClusterOptions;
|
||||
import org.jclouds.cloudstack.options.AddHostOptions;
|
||||
import org.jclouds.cloudstack.options.AddSecondaryStorageOptions;
|
||||
import org.jclouds.cloudstack.options.DeleteHostOptions;
|
||||
|
@ -131,4 +132,16 @@ public interface GlobalHostClient {
|
|||
* @return clusters matching query, or empty set if no clusters match
|
||||
*/
|
||||
Set<Cluster> listClusters(ListClustersOptions... options);
|
||||
|
||||
/**
|
||||
* Adds a new cluster.
|
||||
*
|
||||
* @param zoneId the Zone ID for the cluster
|
||||
* @param clusterName the cluster name
|
||||
* @param clusterType type of the cluster
|
||||
* @param hypervisor hypervisor type of the cluster
|
||||
* @param options optional arguments
|
||||
* @return the new cluster.
|
||||
*/
|
||||
Cluster addCluster(long zoneId, String clusterName, Host.ClusterType clusterType, String hypervisor, AddClusterOptions... options);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* 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.cloudstack.domain.Host;
|
||||
import org.jclouds.functions.JoinOnComma;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Options to the GlobalHostClient.addHost() API call
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class AddClusterOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final AddClusterOptions NONE = new AddClusterOptions();
|
||||
|
||||
/**
|
||||
* @param allocationState Allocation state of this Host for allocation of new resources
|
||||
*/
|
||||
public AddClusterOptions allocationState(Host.AllocationState allocationState) {
|
||||
this.queryParameters.replaceValues("allocationstate", ImmutableSet.of(allocationState.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param password the password for the host
|
||||
*/
|
||||
public AddClusterOptions password(String password) {
|
||||
this.queryParameters.replaceValues("password", ImmutableSet.of(password));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param podId the Pod ID for the host
|
||||
*/
|
||||
public AddClusterOptions podId(long podId) {
|
||||
this.queryParameters.replaceValues("podid", ImmutableSet.of(podId + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url the URL
|
||||
*/
|
||||
public AddClusterOptions url(String url) {
|
||||
this.queryParameters.replaceValues("url", ImmutableSet.of(url));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param username the username for the cluster
|
||||
*/
|
||||
public AddClusterOptions username(String username) {
|
||||
this.queryParameters.replaceValues("username", ImmutableSet.of(username));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @param allocationState Allocation state of this Host for allocation of new resources
|
||||
*/
|
||||
public static AddClusterOptions allocationState(Host.AllocationState allocationState) {
|
||||
return new AddClusterOptions().allocationState(allocationState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param password the password for the host
|
||||
*/
|
||||
public static AddClusterOptions password(String password) {
|
||||
return new AddClusterOptions().password(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param podId the Pod ID for the host
|
||||
*/
|
||||
public static AddClusterOptions podId(long podId) {
|
||||
return new AddClusterOptions().podId(podId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url the URL
|
||||
*/
|
||||
public static AddClusterOptions url(String url) {
|
||||
return new AddClusterOptions().url(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param username the username for the cluster
|
||||
*/
|
||||
public static AddClusterOptions username(String username) {
|
||||
return new AddClusterOptions().username(username);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import org.jclouds.cloudstack.CloudStackContext;
|
|||
import org.jclouds.cloudstack.domain.Cluster;
|
||||
import org.jclouds.cloudstack.domain.ConfigurationEntry;
|
||||
import org.jclouds.cloudstack.domain.Host;
|
||||
import org.jclouds.cloudstack.options.AddClusterOptions;
|
||||
import org.jclouds.cloudstack.options.AddHostOptions;
|
||||
import org.jclouds.cloudstack.options.AddSecondaryStorageOptions;
|
||||
import org.jclouds.cloudstack.options.DeleteHostOptions;
|
||||
|
@ -265,6 +266,24 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe
|
|||
assertEquals(client.listClusters(), ImmutableSet.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddClusterWhenResponseIs2xx() {
|
||||
HttpRequest request = HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=addCluster&zoneid=1&clustertype=CloudManaged&clustername=Xen%20Clust%201&hypervisor=XenServer&allocationstate=Enabled&podid=1&url=http%3A%2F%2Fexample.com%2Fcluster&username=fred&password=sekrit&apiKey=identity&signature=2uIQ5qF0bVycXK111wxvogWp1Yw%3D"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
|
||||
.build();
|
||||
HttpResponse response = HttpResponse.builder()
|
||||
.payload(payloadFromResource("/addclusterresponse.json"))
|
||||
.statusCode(200).build();
|
||||
|
||||
Cluster expected = Cluster.builder().id(1).name("Xen Clust 1").podId(1).podName("Dev Pod 1").zoneId(1).zoneName("Dev Zone 1").hypervisor("XenServer").clusterType(Host.ClusterType.CLOUD_MANAGED).allocationState(Host.AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build();
|
||||
|
||||
Cluster actual = requestSendsResponse(request, response).addCluster(1, "Xen Clust 1", Host.ClusterType.CLOUD_MANAGED, "XenServer", AddClusterOptions.Builder.allocationState(Host.AllocationState.ENABLED).podId(1).url("http://example.com/cluster").username("fred").password("sekrit"));
|
||||
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
|
||||
private Date makeDate(int year, int month, int date, int hour, int minute, int second, String timeZoneName) {
|
||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneName));
|
||||
cal.set(Calendar.YEAR, year);
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* 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.jclouds.cloudstack.domain.Host;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.jclouds.cloudstack.options.AddClusterOptions.Builder.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code AddClusterOptions}
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class AddClusterOptionsTest {
|
||||
|
||||
public void testAllocationState() {
|
||||
AddClusterOptions options = new AddClusterOptions().allocationState(Host.AllocationState.ENABLED);
|
||||
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
|
||||
}
|
||||
|
||||
public void testAllocationStateStatic() {
|
||||
AddClusterOptions options = allocationState(Host.AllocationState.ENABLED);
|
||||
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
|
||||
}
|
||||
|
||||
public void testPassword() {
|
||||
AddClusterOptions options = new AddClusterOptions().password("sekrit");
|
||||
assertEquals(ImmutableList.of("sekrit"), options.buildQueryParameters().get("password"));
|
||||
}
|
||||
|
||||
public void testPasswordStatic() {
|
||||
AddClusterOptions options = password("sekrit");
|
||||
assertEquals(ImmutableList.of("sekrit"), options.buildQueryParameters().get("password"));
|
||||
}
|
||||
|
||||
public void testPodId() {
|
||||
AddClusterOptions options = new AddClusterOptions().podId(42L);
|
||||
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("podid"));
|
||||
}
|
||||
|
||||
public void testPodIdStatic() {
|
||||
AddClusterOptions options = podId(42L);
|
||||
assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("podid"));
|
||||
}
|
||||
|
||||
public void testUrl() {
|
||||
AddClusterOptions options = new AddClusterOptions().url("http://example.com");
|
||||
assertEquals(ImmutableList.of("http://example.com"), options.buildQueryParameters().get("url"));
|
||||
}
|
||||
|
||||
public void testUrlStatic() {
|
||||
AddClusterOptions options = url("http://example.com");
|
||||
assertEquals(ImmutableList.of("http://example.com"), options.buildQueryParameters().get("url"));
|
||||
}
|
||||
|
||||
public void testUsername() {
|
||||
AddClusterOptions options = new AddClusterOptions().username("fred");
|
||||
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("username"));
|
||||
}
|
||||
|
||||
public void testUsernameStatic() {
|
||||
AddClusterOptions options = username("fred");
|
||||
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("username"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{ "addclusterresponse" : { "cluster" : {"warning":"this test data is fabricated","id":1,"name":"Xen Clust 1","podid":1,"podname":"Dev Pod 1","zoneid":1,"zonename":"Dev Zone 1","hypervisortype":"XenServer","clustertype":"CloudManaged","allocationstate":"Enabled","managedstate":"Managed"} } }
|
Loading…
Reference in New Issue