mirror of https://github.com/apache/jclouds.git
added ops to vm and datacenter features to softlayer
This commit is contained in:
parent
743b94c767
commit
bbf6ba525d
|
@ -20,6 +20,7 @@
|
|||
package org.jclouds.softlayer;
|
||||
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.softlayer.features.DatacenterAsyncClient;
|
||||
import org.jclouds.softlayer.features.VirtualGuestAsyncClient;
|
||||
|
||||
/**
|
||||
|
@ -38,4 +39,9 @@ public interface SoftLayerAsyncClient {
|
|||
@Delegate
|
||||
VirtualGuestAsyncClient getVirtualGuestClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Datacenter features.
|
||||
*/
|
||||
@Delegate
|
||||
DatacenterAsyncClient getDatacenterClient();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.softlayer.features.DatacenterClient;
|
||||
import org.jclouds.softlayer.features.VirtualGuestClient;
|
||||
|
||||
/**
|
||||
|
@ -42,4 +43,9 @@ public interface SoftLayerClient {
|
|||
@Delegate
|
||||
VirtualGuestClient getVirtualGuestClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Datacenter features.
|
||||
*/
|
||||
@Delegate
|
||||
DatacenterClient getDatacenterClient();
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ import org.jclouds.rest.ConfiguresRestClient;
|
|||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.softlayer.SoftLayerAsyncClient;
|
||||
import org.jclouds.softlayer.SoftLayerClient;
|
||||
import org.jclouds.softlayer.features.DatacenterAsyncClient;
|
||||
import org.jclouds.softlayer.features.DatacenterClient;
|
||||
import org.jclouds.softlayer.features.VirtualGuestAsyncClient;
|
||||
import org.jclouds.softlayer.features.VirtualGuestClient;
|
||||
import org.jclouds.softlayer.handlers.SoftLayerErrorHandler;
|
||||
|
@ -51,6 +53,7 @@ public class SoftLayerRestClientModule extends RestClientModule<SoftLayerClient,
|
|||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
|
||||
.put(VirtualGuestClient.class, VirtualGuestAsyncClient.class)//
|
||||
.put(DatacenterClient.class, DatacenterAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
public SoftLayerRestClientModule() {
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.softlayer.domain;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a href= "http://sldn.softlayer.com/wiki/index.php/SoftLayer_Location_Datacenter_%28type%29"
|
||||
* />
|
||||
*/
|
||||
public class Datacenter implements Comparable<Datacenter> {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private long id = -1;
|
||||
private String name;
|
||||
private String longName;
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder longName(String longName) {
|
||||
this.longName = longName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Datacenter build() {
|
||||
return new Datacenter(id, name, longName);
|
||||
}
|
||||
|
||||
public static Builder fromDatacenter(Datacenter in) {
|
||||
return Datacenter.builder().id(in.getId()).name(in.getName()).longName(in.getLongName());
|
||||
}
|
||||
}
|
||||
|
||||
private long id = -1;
|
||||
private String name;
|
||||
private String longName;
|
||||
|
||||
// for deserializer
|
||||
Datacenter() {
|
||||
|
||||
}
|
||||
|
||||
public Datacenter(long id, String name, String longName) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.longName = longName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Datacenter arg0) {
|
||||
return new Long(id).compareTo(arg0.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The unique identifier of a specific location.
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A short location description.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A longer location description.
|
||||
*/
|
||||
public String getLongName() {
|
||||
return longName;
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return Builder.fromDatacenter(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.softlayer.features;
|
||||
|
||||
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.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.softlayer.domain.Datacenter;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to LocationDatacenter via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see DatacenterClient
|
||||
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Path("/v{jclouds.api-version}")
|
||||
public interface DatacenterAsyncClient {
|
||||
|
||||
/**
|
||||
* @see LocationDatacenterClient#listDatacenters
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Location_Datacenter/Datacenters.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Datacenter>> listDatacenters();
|
||||
|
||||
/**
|
||||
* @see LocationDatacenterClient#getLocationDatacenter
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Location_Datacenter/{id}.json")
|
||||
@QueryParams(keys = "objectMask", values = "locationAddress")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Datacenter> getDatacenter(@PathParam("id") long id);
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.softlayer.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.softlayer.domain.Datacenter;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to LocationDatacenter.
|
||||
* <p/>
|
||||
*
|
||||
* @see DatacenterAsyncClient
|
||||
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS)
|
||||
public interface DatacenterClient {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return an account's associated datacenter objects.
|
||||
*/
|
||||
Set<Datacenter> listDatacenters();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* id of the datacenter
|
||||
* @return datacenter or null if not found
|
||||
*/
|
||||
Datacenter getDatacenter(long id);
|
||||
|
||||
}
|
|
@ -29,9 +29,11 @@ import javax.ws.rs.core.MediaType;
|
|||
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
@ -47,12 +49,14 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
@RequestFilters(BasicAuthentication.class)
|
||||
@Path("/v{jclouds.api-version}")
|
||||
public interface VirtualGuestAsyncClient {
|
||||
public static String GUEST_MASK = "powerState;networkVlans;operatingSystem.passwords;datacenter";
|
||||
|
||||
/**
|
||||
* @see VirtualGuestClient#listVirtualGuests
|
||||
*/
|
||||
@GET
|
||||
@Path("/VirtualGuest_Account/VirtualGuests.json")
|
||||
@Path("/SoftLayer_Account/VirtualGuests.json")
|
||||
@QueryParams(keys = "objectMask", values = GUEST_MASK)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<VirtualGuest>> listVirtualGuests();
|
||||
|
@ -61,8 +65,54 @@ public interface VirtualGuestAsyncClient {
|
|||
* @see VirtualGuestClient#getVirtualGuest
|
||||
*/
|
||||
@GET
|
||||
@Path("/VirtualGuest_Virtual_Guest/{id}.json")
|
||||
@Path("/SoftLayer_Virtual_Guest/{id}.json")
|
||||
@QueryParams(keys = "objectMask", values = GUEST_MASK)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<VirtualGuest> getVirtualGuest(@PathParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualGuestClient#rebootHardVirtualGuest
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Virtual_Guest/{id}/rebootHard.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> rebootHardVirtualGuest(@PathParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualGuestClient#powerOffVirtualGuest
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Virtual_Guest/{id}/powerOff.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> powerOffVirtualGuest(@PathParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualGuestClient#powerOnVirtualGuest
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Virtual_Guest/{id}/powerOn.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> powerOnVirtualGuest(@PathParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualGuestClient#pauseVirtualGuest
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Virtual_Guest/{id}/pause.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> pauseVirtualGuest(@PathParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualGuestClient#resumeVirtualGuest
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Virtual_Guest/{id}/resume.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> resumeVirtualGuest(@PathParam("id") long id);
|
||||
}
|
||||
|
|
|
@ -50,4 +50,43 @@ public interface VirtualGuestClient {
|
|||
*/
|
||||
VirtualGuest getVirtualGuest(long id);
|
||||
|
||||
/**
|
||||
* hard reboot the guest.
|
||||
*
|
||||
* @param id
|
||||
* id of the virtual guest
|
||||
*/
|
||||
void rebootHardVirtualGuest(long id);
|
||||
|
||||
/**
|
||||
* Power off a guest
|
||||
*
|
||||
* @param id
|
||||
* id of the virtual guest
|
||||
*/
|
||||
void powerOffVirtualGuest(long id);
|
||||
|
||||
/**
|
||||
* Power on a guest
|
||||
*
|
||||
* @param id
|
||||
* id of the virtual guest
|
||||
*/
|
||||
void powerOnVirtualGuest(long id);
|
||||
|
||||
/**
|
||||
* pause the guest.
|
||||
*
|
||||
* @param id
|
||||
* id of the virtual guest
|
||||
*/
|
||||
void pauseVirtualGuest(long id);
|
||||
|
||||
/**
|
||||
* resume the guest.
|
||||
*
|
||||
* @param id
|
||||
* id of the virtual guest
|
||||
*/
|
||||
void resumeVirtualGuest(long id);
|
||||
}
|
||||
|
|
|
@ -44,10 +44,12 @@ public class SoftLayerAsyncClientTest extends BaseSoftLayerAsyncClientTest<SoftL
|
|||
|
||||
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
assert syncClient.getVirtualGuestClient() != null;
|
||||
assert syncClient.getDatacenterClient() != null;
|
||||
}
|
||||
|
||||
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
assert asyncClient.getVirtualGuestClient() != null;
|
||||
assert asyncClient.getDatacenterClient() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.softlayer.features;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code DatacenterAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class DatacenterAsyncClientTest extends BaseSoftLayerAsyncClientTest<DatacenterAsyncClient> {
|
||||
|
||||
public void testListDatacenters() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = DatacenterAsyncClient.class.getMethod("listDatacenters");
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// now make sure request filters apply by replaying
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json HTTP/1.1");
|
||||
// for example, using basic authentication, we should get "only one"
|
||||
// header
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\nAuthorization: Basic YXBpS2V5OnNlY3JldEtleQ==\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetDatacenter() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = DatacenterAsyncClient.class.getMethod("getDatacenter", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/1234.json?objectMask=locationAddress HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<DatacenterAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<DatacenterAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.softlayer.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.softlayer.domain.Datacenter;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code DatacenterClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live")
|
||||
public class DatacenterClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
super.setupClient();
|
||||
client = context.getApi().getDatacenterClient();
|
||||
}
|
||||
|
||||
private DatacenterClient client;
|
||||
|
||||
@Test
|
||||
public void testListDatacenters() throws Exception {
|
||||
Set<Datacenter> response = client.listDatacenters();
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
for (Datacenter vg : response) {
|
||||
Datacenter newDetails = client.getDatacenter(vg.getId());
|
||||
assertEquals(vg.getId(), newDetails.getId());
|
||||
checkDatacenter(vg);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDatacenter(Datacenter vg) {
|
||||
assert vg.getId() > 0 : vg;
|
||||
assert vg.getName() != null : vg;
|
||||
assert vg.getLongName() != null : vg;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,8 +24,10 @@ import java.lang.reflect.Method;
|
|||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -44,8 +46,9 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
|
|||
Method method = VirtualGuestAsyncClient.class.getMethod("listVirtualGuests");
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/VirtualGuest_Account/VirtualGuests.json HTTP/1.1");
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -53,12 +56,13 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
|
|||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/VirtualGuest_Account/VirtualGuests.json HTTP/1.1");
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter HTTP/1.1");
|
||||
// for example, using basic authentication, we should get "only one"
|
||||
// header
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\nAuthorization: Basic YXBpS2V5OnNlY3JldEtleQ==\n");
|
||||
"Accept: application/json\nAuthorization: Basic YXBpS2V5OnNlY3JldEtleQ==\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
|
@ -73,8 +77,9 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
|
|||
Method method = VirtualGuestAsyncClient.class.getMethod("getVirtualGuest", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/VirtualGuest_Virtual_Guest/1234.json HTTP/1.1");
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -86,6 +91,90 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
|
|||
|
||||
}
|
||||
|
||||
public void testRebootHardVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualGuestAsyncClient.class.getMethod("rebootHardVirtualGuest", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/rebootHard.json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testPowerOffVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualGuestAsyncClient.class.getMethod("powerOffVirtualGuest", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/powerOff.json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testPowerOnVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualGuestAsyncClient.class.getMethod("powerOnVirtualGuest", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/powerOn.json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testPauseVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualGuestAsyncClient.class.getMethod("pauseVirtualGuest", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/pause.json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testResumeVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualGuestAsyncClient.class.getMethod("resumeVirtualGuest", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/resume.json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<VirtualGuestAsyncClient>> createTypeLiteral() {
|
||||
|
|
Loading…
Reference in New Issue