mirror of https://github.com/apache/jclouds.git
Add GlobalHost[Async]Client.addSecondaryStorage()
This commit is contained in:
parent
20f58c4a12
commit
533e13fc44
|
@ -23,6 +23,7 @@ import org.jclouds.cloudstack.domain.Cluster;
|
|||
import org.jclouds.cloudstack.domain.Host;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.AddHostOptions;
|
||||
import org.jclouds.cloudstack.options.AddSecondaryStorageOptions;
|
||||
import org.jclouds.cloudstack.options.DeleteHostOptions;
|
||||
import org.jclouds.cloudstack.options.ListClustersOptions;
|
||||
import org.jclouds.cloudstack.options.ListHostsOptions;
|
||||
|
@ -150,6 +151,19 @@ public interface GlobalHostAsyncClient {
|
|||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Long> reconnectHost(@QueryParam("id") long hostId);
|
||||
|
||||
/**
|
||||
* Adds secondary storage.
|
||||
*
|
||||
* @param url the URL for the secondary storage
|
||||
* @param options optional arguments
|
||||
* @return the host of the storage.
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "addSecondaryStorage")
|
||||
@SelectJson("host")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Host> addSecondaryStorage(@QueryParam("url") String url, AddSecondaryStorageOptions... options);
|
||||
|
||||
/**
|
||||
* @see GlobalHostClient#listClusters
|
||||
*/
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features;
|
|||
import org.jclouds.cloudstack.domain.Cluster;
|
||||
import org.jclouds.cloudstack.domain.Host;
|
||||
import org.jclouds.cloudstack.options.AddHostOptions;
|
||||
import org.jclouds.cloudstack.options.AddSecondaryStorageOptions;
|
||||
import org.jclouds.cloudstack.options.DeleteHostOptions;
|
||||
import org.jclouds.cloudstack.options.ListClustersOptions;
|
||||
import org.jclouds.cloudstack.options.ListHostsOptions;
|
||||
|
@ -114,6 +115,15 @@ public interface GlobalHostClient {
|
|||
*/
|
||||
Long reconnectHost(long hostId);
|
||||
|
||||
/**
|
||||
* Adds secondary storage.
|
||||
*
|
||||
* @param url the URL for the secondary storage
|
||||
* @param options optional arguments
|
||||
* @return the host of the storage.
|
||||
*/
|
||||
Host addSecondaryStorage(String url, AddSecondaryStorageOptions... options);
|
||||
|
||||
/**
|
||||
* Lists clusters
|
||||
*
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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 for the GlobalHostClient.addSecondaryStorage() API call
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class AddSecondaryStorageOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final AddSecondaryStorageOptions NONE = new AddSecondaryStorageOptions();
|
||||
|
||||
/**
|
||||
* @param zoneId
|
||||
* the ID of the zone
|
||||
*/
|
||||
public AddSecondaryStorageOptions zoneId(long zoneId) {
|
||||
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @param zoneId
|
||||
* the ID of the zone
|
||||
*/
|
||||
public static AddSecondaryStorageOptions zoneId(long zoneId) {
|
||||
return new AddSecondaryStorageOptions().zoneId(zoneId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ import org.jclouds.cloudstack.domain.Cluster;
|
|||
import org.jclouds.cloudstack.domain.ConfigurationEntry;
|
||||
import org.jclouds.cloudstack.domain.Host;
|
||||
import org.jclouds.cloudstack.options.AddHostOptions;
|
||||
import org.jclouds.cloudstack.options.AddSecondaryStorageOptions;
|
||||
import org.jclouds.cloudstack.options.DeleteHostOptions;
|
||||
import org.jclouds.cloudstack.options.UpdateHostOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
|
@ -210,6 +211,27 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe
|
|||
assertEquals(actual, Long.valueOf(2036L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSecondaryStorageWhenResponseIs2xx() {
|
||||
HttpRequest request = HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=addSecondaryStorage&url=nfs%3A%2F%2F10.26.26.165%2Fmnt%2Fnfs%2Fcs_sec&zoneid=1&apiKey=identity&signature=MccRKx1yPP43ImiO70WlhVDlAIA%3D"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
|
||||
.build();
|
||||
HttpResponse response = HttpResponse.builder()
|
||||
.payload(payloadFromResource("/addsecondarystorageresponse.json"))
|
||||
.statusCode(200).build();
|
||||
|
||||
Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC");
|
||||
Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "UTC");
|
||||
Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC");
|
||||
Host expected = Host.builder().id(2).name("nfs://10.26.26.165/mnt/nfs/cs_sec").state(Host.State.ALERT).disconnected(disconnected).type(Host.Type.SECONDARY_STORAGE).ipAddress("nfs").zoneId(1).zoneName("Dev Zone 1").version("2.2.12.20110928142833").hypervisor("None").lastPinged(lastPinged).localStorageActive(false).created(created).events("ManagementServerDown; AgentDisconnected; Remove; MaintenanceRequested; AgentConnected; Ping").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build();
|
||||
|
||||
Host actual = requestSendsResponse(request, response).addSecondaryStorage("nfs://10.26.26.165/mnt/nfs/cs_sec", AddSecondaryStorageOptions.Builder.zoneId(1));
|
||||
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListClustersWhenResponseIs2xx() {
|
||||
HttpRequest request = HttpRequest.builder()
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* 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.AddSecondaryStorageOptions.Builder.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code AddSecondaryStorageOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class AddSecondaryStorageOptionsTest {
|
||||
|
||||
public void testZoneId() {
|
||||
AddSecondaryStorageOptions options = new AddSecondaryStorageOptions().zoneId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
|
||||
public void testZoneIdStatic() {
|
||||
AddSecondaryStorageOptions options = zoneId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{ "addsecondarystorageresponse" : { "host" :
|
||||
{"warning":"this test data is fabricated","id":2,"name":"nfs://10.26.26.165/mnt/nfs/cs_sec","state":"Alert","disconnected":"2011-11-26T23:33:38+0200","type":"SecondaryStorage","ipaddress":"nfs","zoneid":1,"zonename":"Dev Zone 1","version":"2.2.12.20110928142833","hypervisor":"None","lastpinged":"1970-01-16T00:42:30+0200","islocalstorageactive":false,"created":"2011-11-26T23:33:38+0200","events":"ManagementServerDown; AgentDisconnected; Remove; MaintenanceRequested; AgentConnected; Ping","hasEnoughCapacity":false,"allocationstate":"Enabled"},
|
||||
} }
|
Loading…
Reference in New Issue