Remove async from softlayer

This commit is contained in:
Andrew Bayer 2013-08-01 13:07:09 -07:00
parent 82fe701c77
commit dae2c67d79
29 changed files with 228 additions and 552 deletions

View File

@ -19,42 +19,41 @@ package org.jclouds.softlayer;
import java.io.Closeable;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.softlayer.features.AccountClient;
import org.jclouds.softlayer.features.DatacenterClient;
import org.jclouds.softlayer.features.ProductPackageClient;
import org.jclouds.softlayer.features.VirtualGuestClient;
import org.jclouds.softlayer.features.AccountApi;
import org.jclouds.softlayer.features.DatacenterApi;
import org.jclouds.softlayer.features.ProductPackageApi;
import org.jclouds.softlayer.features.VirtualGuestApi;
/**
* Provides synchronous access to SoftLayer.
* <p/>
*
* @see SoftLayerAsyncClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
public interface SoftLayerClient extends Closeable {
public interface SoftLayerApi extends Closeable {
/**
* Provides synchronous access to VirtualGuest features.
*/
@Delegate
VirtualGuestClient getVirtualGuestClient();
VirtualGuestApi getVirtualGuestApi();
/**
* Provides synchronous access to Datacenter features.
*/
@Delegate
DatacenterClient getDatacenterClient();
DatacenterApi getDatacenterApi();
/**
* Provides synchronous access to ProductPackage features.
*/
@Delegate
ProductPackageClient getProductPackageClient();
ProductPackageApi getProductPackageApi();
/**
* Provides synchronous access to Account features.
*/
@Delegate
AccountClient getAccountClient();
AccountApi getAccountApi();
}

View File

@ -23,12 +23,11 @@ import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.rest.internal.BaseRestApiMetadata;
import org.jclouds.rest.internal.BaseHttpApiMetadata;
import org.jclouds.softlayer.compute.config.SoftLayerComputeServiceContextModule;
import org.jclouds.softlayer.config.SoftLayerRestClientModule;
import org.jclouds.softlayer.config.SoftLayerHttpApiModule;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
/**
@ -36,17 +35,9 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class SoftLayerApiMetadata extends BaseRestApiMetadata {
public class SoftLayerApiMetadata extends BaseHttpApiMetadata<SoftLayerApi> {
/**
* @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(SoftLayerClient.class)} as
* {@link SoftLayerAsyncClient} interface will be removed in jclouds 1.7.
*/
@Deprecated
public static final TypeToken<org.jclouds.rest.RestContext<SoftLayerClient, SoftLayerAsyncClient>> CONTEXT_TOKEN = new TypeToken<org.jclouds.rest.RestContext<SoftLayerClient, SoftLayerAsyncClient>>() {
private static final long serialVersionUID = 1L;
};
@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
@ -61,17 +52,16 @@ public class SoftLayerApiMetadata extends BaseRestApiMetadata {
}
public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties();
Properties properties = BaseHttpApiMetadata.defaultProperties();
properties.setProperty("jclouds.ssh.max-retries", "5");
properties.setProperty("jclouds.ssh.retry-auth", "true");
return properties;
}
public static class Builder extends BaseRestApiMetadata.Builder<Builder> {
public static class Builder extends BaseHttpApiMetadata.Builder<SoftLayerApi, Builder> {
@SuppressWarnings("deprecation")
protected Builder() {
super(SoftLayerClient.class, SoftLayerAsyncClient.class);
id("softlayer")
.name("SoftLayer API")
.identityName("API Username")
@ -81,7 +71,7 @@ public class SoftLayerApiMetadata extends BaseRestApiMetadata {
.defaultEndpoint("https://api.softlayer.com/rest")
.defaultProperties(SoftLayerApiMetadata.defaultProperties())
.view(typeToken(ComputeServiceContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(SoftLayerRestClientModule.class, SoftLayerComputeServiceContextModule.class));
.defaultModules(ImmutableSet.<Class<? extends Module>>of(SoftLayerHttpApiModule.class, SoftLayerComputeServiceContextModule.class));
}
@Override

View File

@ -1,63 +0,0 @@
/*
* 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.softlayer;
import java.io.Closeable;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.softlayer.features.AccountAsyncClient;
import org.jclouds.softlayer.features.DatacenterAsyncClient;
import org.jclouds.softlayer.features.ProductPackageAsyncClient;
import org.jclouds.softlayer.features.VirtualGuestAsyncClient;
/**
* Provides asynchronous access to SoftLayer via their REST API.
* <p/>
*
* @see SoftLayerClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
* @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(SoftLayerClient.class)} as
* {@link SoftLayerAsyncClient} interface will be removed in jclouds 1.7.
*/
@Deprecated
public interface SoftLayerAsyncClient extends Closeable {
/**
* Provides asynchronous access to VirtualGuest features.
*/
@Delegate
VirtualGuestAsyncClient getVirtualGuestClient();
/**
* Provides asynchronous access to Datacenter features.
*/
@Delegate
DatacenterAsyncClient getDatacenterClient();
/**
* Provides asynchronous access to ProductPackage features.
*/
@Delegate
ProductPackageAsyncClient getProductPackageClient();
/**
* Provides asynchronous access to Account features.
*/
@Delegate
AccountAsyncClient getAccountClient();
}

View File

@ -37,7 +37,7 @@ import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.softlayer.SoftLayerApi;
import org.jclouds.softlayer.compute.functions.DatacenterToLocation;
import org.jclouds.softlayer.compute.functions.ProductItemToImage;
import org.jclouds.softlayer.compute.functions.ProductItemsToHardware;
@ -49,8 +49,8 @@ import org.jclouds.softlayer.domain.ProductItem;
import org.jclouds.softlayer.domain.ProductItemPrice;
import org.jclouds.softlayer.domain.ProductPackage;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.jclouds.softlayer.features.AccountClient;
import org.jclouds.softlayer.features.ProductPackageClient;
import org.jclouds.softlayer.features.AccountApi;
import org.jclouds.softlayer.features.ProductPackageApi;
import com.google.common.base.Function;
import com.google.common.base.Objects;
@ -93,16 +93,16 @@ public class SoftLayerComputeServiceContextModule extends
@Singleton
@Memoized
public Supplier<ProductPackage> getProductPackage(AtomicReference<AuthorizationException> authException,
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final SoftLayerClient client,
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final SoftLayerApi client,
@Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) final String virtualGuestPackageName) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
new Supplier<ProductPackage>() {
@Override
public ProductPackage get() {
AccountClient accountClient = client.getAccountClient();
ProductPackageClient productPackageClient = client.getProductPackageClient();
ProductPackage p = find(accountClient.getActivePackages(), named(virtualGuestPackageName));
return productPackageClient.getProductPackage(p.getId());
AccountApi accountApi = client.getAccountApi();
ProductPackageApi productPackageApi = client.getProductPackageApi();
ProductPackage p = find(accountApi.getActivePackages(), named(virtualGuestPackageName));
return productPackageApi.getProductPackage(p.getId());
}
@Override

View File

@ -34,7 +34,7 @@ import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.domain.Location;
import org.jclouds.location.predicates.LocationPredicates;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.softlayer.SoftLayerApi;
import org.jclouds.softlayer.domain.ProductItem;
import org.jclouds.softlayer.domain.ProductOrder;
import org.jclouds.softlayer.domain.VirtualGuest;
@ -105,13 +105,13 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
@Singleton
public static class GetHardwareForVirtualGuest {
private final SoftLayerClient client;
private final SoftLayerApi api;
private final Function<Iterable<ProductItem>, Hardware> productItemsToHardware;
@Inject
public GetHardwareForVirtualGuest(SoftLayerClient client,
public GetHardwareForVirtualGuest(SoftLayerApi api,
Function<Iterable<ProductItem>, Hardware> productItemsToHardware) {
this.client = checkNotNull(client, "client");
this.api = checkNotNull(api, "api");
this.productItemsToHardware = checkNotNull(productItemsToHardware, "productItemsToHardware");
}
@ -120,7 +120,7 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
// 'bad' orders have no start cpu's and cause the order lookup to fail.
if (guest.getStartCpus() < 1)
return null;
ProductOrder order = client.getVirtualGuestClient().getOrderTemplate(guest.getId());
ProductOrder order = api.getVirtualGuestApi().getOrderTemplate(guest.getId());
if (order == null)
return null;
Iterable<ProductItem> items = Iterables.transform(order.getPrices(), ProductItems.item());
@ -131,18 +131,18 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
@Singleton
public static class GetImageForVirtualGuest {
private SoftLayerClient client;
private SoftLayerApi api;
@Inject
public GetImageForVirtualGuest(SoftLayerClient client) {
this.client = client;
public GetImageForVirtualGuest(SoftLayerApi api) {
this.api = api;
}
public Image getImage(VirtualGuest guest) {
// 'bad' orders have no start cpu's and cause the order lookup to fail.
if (guest.getStartCpus() < 1)
return null;
ProductOrder order = client.getVirtualGuestClient().getOrderTemplate(guest.getId());
ProductOrder order = api.getVirtualGuestApi().getOrderTemplate(guest.getId());
if (order == null)
return null;
Iterable<ProductItem> items = Iterables.transform(order.getPrices(), ProductItems.item());

View File

@ -48,7 +48,7 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.Logger;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.softlayer.SoftLayerApi;
import org.jclouds.softlayer.compute.functions.ProductItemToImage;
import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions;
import org.jclouds.softlayer.domain.Datacenter;
@ -65,10 +65,9 @@ import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Iterables;
/**
* defines the connection between the {@link SoftLayerClient} implementation and
* defines the connection between the {@link SoftLayerApi} implementation and
* the jclouds {@link ComputeService}
*
*/
@ -80,7 +79,7 @@ public class SoftLayerComputeServiceAdapter implements
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final SoftLayerClient client;
private final SoftLayerApi client;
private final Supplier<ProductPackage> productPackageSupplier;
private final Predicate<VirtualGuest> loginDetailsTester;
private final long guestLoginDelay;
@ -90,7 +89,7 @@ public class SoftLayerComputeServiceAdapter implements
private final Iterable<ProductItemPrice> prices;
@Inject
public SoftLayerComputeServiceAdapter(SoftLayerClient client,
public SoftLayerComputeServiceAdapter(SoftLayerApi client,
VirtualGuestHasLoginDetailsPresent virtualGuestHasLoginDetailsPresent,
@Memoized Supplier<ProductPackage> productPackageSupplier, Iterable<ProductItemPrice> prices,
@Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX) String cpuRegex,
@ -127,7 +126,7 @@ public class SoftLayerComputeServiceAdapter implements
.virtualGuests(newGuest).build();
logger.debug(">> ordering new virtualGuest domain(%s) hostname(%s)", domainName, name);
ProductOrderReceipt productOrderReceipt = client.getVirtualGuestClient().orderVirtualGuest(order);
ProductOrderReceipt productOrderReceipt = client.getVirtualGuestApi().orderVirtualGuest(order);
VirtualGuest result = get(productOrderReceipt.getOrderDetails().getVirtualGuests(), 0);
logger.trace("<< virtualGuest(%s)", result.getId());
@ -137,7 +136,7 @@ public class SoftLayerComputeServiceAdapter implements
checkState(orderInSystem, "order for guest %s doesn't have login details within %sms", result,
Long.toString(guestLoginDelay));
result = client.getVirtualGuestClient().getVirtualGuest(result.getId());
result = client.getVirtualGuestApi().getVirtualGuest(result.getId());
Password pw = get(result.getOperatingSystem().getPasswords(), 0);
return new NodeAndInitialCredentials<VirtualGuest>(result, result.getId() + "", LoginCredentials.builder().user(pw.getUsername()).password(
@ -197,7 +196,7 @@ public class SoftLayerComputeServiceAdapter implements
@Override
public Iterable<VirtualGuest> listNodes() {
return filter(client.getVirtualGuestClient().listVirtualGuests(), new Predicate<VirtualGuest>() {
return filter(client.getVirtualGuestApi().listVirtualGuests(), new Predicate<VirtualGuest>() {
@Override
public boolean apply(VirtualGuest arg0) {
@ -230,7 +229,7 @@ public class SoftLayerComputeServiceAdapter implements
@Override
public VirtualGuest getNode(String id) {
long serverId = Long.parseLong(id);
return client.getVirtualGuestClient().getVirtualGuest(serverId);
return client.getVirtualGuestApi().getVirtualGuest(serverId);
}
@Override
@ -244,29 +243,29 @@ public class SoftLayerComputeServiceAdapter implements
id));
logger.debug(">> canceling service for guest(%s) billingItem(%s)", id, guest.getBillingItemId());
client.getVirtualGuestClient().cancelService(guest.getBillingItemId());
client.getVirtualGuestApi().cancelService(guest.getBillingItemId());
}
@Override
public void rebootNode(String id) {
client.getVirtualGuestClient().rebootHardVirtualGuest(Long.parseLong(id));
client.getVirtualGuestApi().rebootHardVirtualGuest(Long.parseLong(id));
}
@Override
public void resumeNode(String id) {
client.getVirtualGuestClient().resumeVirtualGuest(Long.parseLong(id));
client.getVirtualGuestApi().resumeVirtualGuest(Long.parseLong(id));
}
@Override
public void suspendNode(String id) {
client.getVirtualGuestClient().pauseVirtualGuest(Long.parseLong(id));
client.getVirtualGuestApi().pauseVirtualGuest(Long.parseLong(id));
}
public static class VirtualGuestHasLoginDetailsPresent implements Predicate<VirtualGuest> {
private final SoftLayerClient client;
private final SoftLayerApi client;
@Inject
public VirtualGuestHasLoginDetailsPresent(SoftLayerClient client) {
public VirtualGuestHasLoginDetailsPresent(SoftLayerApi client) {
this.client = checkNotNull(client, "client was null");
}
@ -274,7 +273,7 @@ public class SoftLayerComputeServiceAdapter implements
public boolean apply(VirtualGuest guest) {
checkNotNull(guest, "virtual guest was null");
VirtualGuest newGuest = client.getVirtualGuestClient().getVirtualGuest(guest.getId());
VirtualGuest newGuest = client.getVirtualGuestApi().getVirtualGuest(guest.getId());
boolean hasBackendIp = newGuest.getPrimaryBackendIpAddress() != null;
boolean hasPrimaryIp = newGuest.getPrimaryIpAddress() != null;
boolean hasPasswords = newGuest.getOperatingSystem() != null

View File

@ -16,8 +16,6 @@
*/
package org.jclouds.softlayer.config;
import java.util.Map;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.annotation.ClientError;
@ -28,20 +26,10 @@ import org.jclouds.location.config.LocationModule;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone;
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.AccountAsyncClient;
import org.jclouds.softlayer.features.AccountClient;
import org.jclouds.softlayer.features.DatacenterAsyncClient;
import org.jclouds.softlayer.features.DatacenterClient;
import org.jclouds.softlayer.features.ProductPackageAsyncClient;
import org.jclouds.softlayer.features.ProductPackageClient;
import org.jclouds.softlayer.features.VirtualGuestAsyncClient;
import org.jclouds.softlayer.features.VirtualGuestClient;
import org.jclouds.rest.config.HttpApiModule;
import org.jclouds.softlayer.SoftLayerApi;
import org.jclouds.softlayer.handlers.SoftLayerErrorHandler;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Scopes;
/**
@ -50,18 +38,7 @@ import com.google.inject.Scopes;
* @author Adrian Cole
*/
@ConfiguresRestClient
public class SoftLayerRestClientModule extends RestClientModule<SoftLayerClient, SoftLayerAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(VirtualGuestClient.class, VirtualGuestAsyncClient.class)//
.put(DatacenterClient.class, DatacenterAsyncClient.class)//
.put(ProductPackageClient.class, ProductPackageAsyncClient.class)//
.put(AccountClient.class, AccountAsyncClient.class)//
.build();
public SoftLayerRestClientModule() {
super(DELEGATE_MAP);
}
public class SoftLayerHttpApiModule extends HttpApiModule<SoftLayerApi> {
@Override
protected void configure() {

View File

@ -23,34 +23,37 @@ import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.Fallbacks;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.softlayer.domain.ProductPackage;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to Account via their REST API.
* Provides synchronous access to Account.
* <p/>
*
* @see AccountClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Jason King
*/
@RequestFilters(BasicAuthentication.class)
@Path("/v{jclouds.api-version}")
public interface AccountAsyncClient {
public interface AccountApi {
/**
* @see AccountClient#getActivePackages()
*
* @return Gets all the active packages.
* This will give you a basic description of the packages that are currently
* active and from which you can order a server or additional services.
*
* Calling ProductPackage.getItems() will return an empty set.
* Use ProductPackageApi.getProductPackage(long id) to obtain items data.
* @see ProductPackageApi#getProductPackage
*/
@GET
@Path("/SoftLayer_Account/ActivePackages.json")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
ListenableFuture<Set<ProductPackage>> getActivePackages();
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
Set<ProductPackage> getActivePackages();
}

View File

@ -1,44 +0,0 @@
/*
* 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.softlayer.features;
import java.util.Set;
import org.jclouds.softlayer.domain.ProductPackage;
/**
* Provides synchronous access to Account.
* <p/>
*
* @see AccountAsyncClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Jason King
*/
public interface AccountClient {
/**
*
* @return Gets all the active packages.
* This will give you a basic description of the packages that are currently
* active and from which you can order a server or additional services.
*
* Calling ProductPackage.getItems() will return an empty set.
* Use ProductPackageClient.getProductPackage(long id) to obtain items data.
* @see ProductPackageClient#getProductPackage
*/
Set<ProductPackage> getActivePackages();
}

View File

@ -24,45 +24,46 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.Fallbacks;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.softlayer.domain.Datacenter;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to LocationDatacenter via their REST API.
* Provides synchronous access to LocationDatacenter.
* <p/>
*
* @see DatacenterClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@RequestFilters(BasicAuthentication.class)
@Path("/v{jclouds.api-version}")
public interface DatacenterAsyncClient {
public interface DatacenterApi {
/**
* @see DatacenterClient#listDatacenters
*
* @return an account's associated datacenter objects.
*/
@GET
@Path("/SoftLayer_Location_Datacenter/Datacenters.json")
@QueryParams(keys = "objectMask", values = "locationAddress;regions")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(EmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Datacenter>> listDatacenters();
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
Set<Datacenter> listDatacenters();
/**
* @see DatacenterClient#getDatacenter
*
* @param id
* id of the datacenter
* @return datacenter or null if not found
*/
@GET
@Path("/SoftLayer_Location_Datacenter/{id}.json")
@QueryParams(keys = "objectMask", values = "locationAddress;regions")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
ListenableFuture<Datacenter> getDatacenter(@PathParam("id") long id);
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
Datacenter getDatacenter(@PathParam("id") long id);
}

View File

@ -1,46 +0,0 @@
/*
* 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.softlayer.features;
import java.util.Set;
import org.jclouds.softlayer.domain.Datacenter;
/**
* Provides synchronous access to LocationDatacenter.
* <p/>
*
* @see DatacenterAsyncClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
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);
}

View File

@ -22,37 +22,36 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.Fallbacks;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.softlayer.domain.ProductPackage;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to ProductPackage via their REST API.
* Provides synchronous access to ProductPackage.
* <p/>
*
* @see ProductPackageClient
*
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@RequestFilters(BasicAuthentication.class)
@Path("/v{jclouds.api-version}")
public interface ProductPackageAsyncClient {
public interface ProductPackageApi {
public static String PRODUCT_MASK = "items.prices;items.categories;locations.locationAddress;locations.regions";
/**
* @see ProductPackageClient#getProductPackage
*
* @param id
* id of the product package
* @return product package or null if not found
*/
@GET
@Path("/SoftLayer_Product_Package/{id}.json")
@QueryParams(keys = "objectMask", values = PRODUCT_MASK)
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
ListenableFuture<ProductPackage> getProductPackage(@PathParam("id") long id);
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
ProductPackage getProductPackage(@PathParam("id") long id);
}

View File

@ -1,39 +0,0 @@
/*
* 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.softlayer.features;
import org.jclouds.softlayer.domain.ProductPackage;
/**
* Provides synchronous access to ProductPackage.
* <p/>
*
* @see ProductPackageAsyncClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
public interface ProductPackageClient {
/**
*
* @param id
* id of the product package
* @return product package or null if not found
*/
ProductPackage getProductPackage(long id);
}

View File

@ -25,10 +25,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
import org.jclouds.Fallbacks;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
@ -39,114 +36,143 @@ import org.jclouds.softlayer.domain.ProductOrder;
import org.jclouds.softlayer.domain.ProductOrderReceipt;
import org.jclouds.softlayer.domain.VirtualGuest;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to VirtualGuest via their REST API.
* Provides synchronous access to VirtualGuest.
* <p/>
*
* @see VirtualGuestClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
@RequestFilters(BasicAuthentication.class)
@Path("/v{jclouds.api-version}")
public interface VirtualGuestAsyncClient {
public interface VirtualGuestApi {
public static String LIST_GUEST_MASK = "virtualGuests.powerState;virtualGuests.networkVlans;virtualGuests.operatingSystem.passwords;virtualGuests.datacenter;virtualGuests.billingItem";
public static String GUEST_MASK = "powerState;networkVlans;operatingSystem.passwords;datacenter;billingItem";
/**
* @see VirtualGuestClient#listVirtualGuests
*
* @return an account's associated virtual guest objects.
*/
@GET
@Path("/SoftLayer_Account/VirtualGuests.json")
@QueryParams(keys = "objectMask", values = LIST_GUEST_MASK)
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(EmptySetOnNotFoundOr404.class)
ListenableFuture<Set<VirtualGuest>> listVirtualGuests();
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
Set<VirtualGuest> listVirtualGuests();
/**
* @see VirtualGuestClient#getVirtualGuest
*
* @param id
* id of the virtual guest
* @return virtual guest or null if not found
*/
@GET
@Path("/SoftLayer_Virtual_Guest/{id}.json")
@QueryParams(keys = "objectMask", values = GUEST_MASK)
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
ListenableFuture<VirtualGuest> getVirtualGuest(@PathParam("id") long id);
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
VirtualGuest getVirtualGuest(@PathParam("id") long id);
/**
* @see VirtualGuestClient#rebootHardVirtualGuest
* hard reboot the guest.
*
* @param id
* id of the virtual guest
*/
@GET
@Path("/SoftLayer_Virtual_Guest/{id}/rebootHard.json")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(VoidOnNotFoundOr404.class)
ListenableFuture<Void> rebootHardVirtualGuest(@PathParam("id") long id);
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
void rebootHardVirtualGuest(@PathParam("id") long id);
/**
* @see VirtualGuestClient#powerOffVirtualGuest
* Power off a guest
*
* @param id
* id of the virtual guest
*/
@GET
@Path("/SoftLayer_Virtual_Guest/{id}/powerOff.json")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(VoidOnNotFoundOr404.class)
ListenableFuture<Void> powerOffVirtualGuest(@PathParam("id") long id);
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
void powerOffVirtualGuest(@PathParam("id") long id);
/**
* @see VirtualGuestClient#powerOnVirtualGuest
* Power on a guest
*
* @param id
* id of the virtual guest
*/
@GET
@Path("/SoftLayer_Virtual_Guest/{id}/powerOn.json")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(VoidOnNotFoundOr404.class)
ListenableFuture<Void> powerOnVirtualGuest(@PathParam("id") long id);
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
void powerOnVirtualGuest(@PathParam("id") long id);
/**
* @see VirtualGuestClient#pauseVirtualGuest
* pause the guest.
*
* @param id
* id of the virtual guest
*/
@GET
@Path("/SoftLayer_Virtual_Guest/{id}/pause.json")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(VoidOnNotFoundOr404.class)
ListenableFuture<Void> pauseVirtualGuest(@PathParam("id") long id);
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
void pauseVirtualGuest(@PathParam("id") long id);
/**
* @see VirtualGuestClient#resumeVirtualGuest
* resume the guest.
*
* @param id
* id of the virtual guest
*/
@GET
@Path("/SoftLayer_Virtual_Guest/{id}/resume.json")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(VoidOnNotFoundOr404.class)
ListenableFuture<Void> resumeVirtualGuest(@PathParam("id") long id);
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
void resumeVirtualGuest(@PathParam("id") long id);
/**
* @see VirtualGuestClient#cancelService
* Cancel the resource or service for a billing Item
*
* @param id
* The id of the billing item to cancel
* @return true or false
*/
@GET
@Path("/SoftLayer_Billing_Item/{id}/cancelService.json")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(FalseOnNotFoundOr404.class)
ListenableFuture<Boolean> cancelService(@PathParam("id") long id);
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean cancelService(@PathParam("id") long id);
/**
* @see org.jclouds.softlayer.features.VirtualGuestClient#orderVirtualGuest
* Use this method for placing server orders and additional services orders.
* @param order
* Details required to order.
* @return A receipt for the order
* @see <a href="http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder" />
*/
@POST
@Path("/SoftLayer_Product_Order/placeOrder.json")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
ListenableFuture<ProductOrderReceipt> orderVirtualGuest(@BinderParam(ProductOrderToJson.class)ProductOrder order);
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
ProductOrderReceipt orderVirtualGuest(@BinderParam(ProductOrderToJson.class)ProductOrder order);
/**
* Throws an Internal Server Error if called on bad orders (mapped to HttpResponseException)
* @see VirtualGuestClient#getOrderTemplate
* @throws org.jclouds.http.HttpResponseException if called with a 'bad' order.
* Obtain an order container that is ready to be sent to the orderVirtualGuest method.
* This container will include all services that the selected computing instance has.
* If desired you may remove prices which were returned.
* @see <a href=" @see <a href="http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder" />
* @param id
* The id of the existing Virtual Guest
* @return
* The ProductOrder used to create the VirtualGust or null if not available
*/
@GET
@Path("SoftLayer_Virtual_Guest/{id}/getOrderTemplate/MONTHLY.json")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
ListenableFuture<ProductOrder> getOrderTemplate(@PathParam("id") long id);
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
ProductOrder getOrderTemplate(@PathParam("id") long id);
}

View File

@ -1,118 +0,0 @@
/*
* 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.softlayer.features;
import java.util.Set;
import org.jclouds.softlayer.domain.ProductOrder;
import org.jclouds.softlayer.domain.ProductOrderReceipt;
import org.jclouds.softlayer.domain.VirtualGuest;
/**
* Provides synchronous access to VirtualGuest.
* <p/>
*
* @see VirtualGuestAsyncClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @author Adrian Cole
*/
public interface VirtualGuestClient {
/**
*
* @return an account's associated virtual guest objects.
*/
Set<VirtualGuest> listVirtualGuests();
/**
*
* @param id
* id of the virtual guest
* @return virtual guest or null if not found
*/
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);
/**
* Cancel the resource or service for a billing Item
*
* @param id
* The id of the billing item to cancel
* @return true or false
*/
boolean cancelService(long id);
/**
* Use this method for placing server orders and additional services orders.
* @param order
* Details required to order.
* @return A receipt for the order
* @see <a href="http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder" />
*/
ProductOrderReceipt orderVirtualGuest(ProductOrder order);
/**
* Obtain an order container that is ready to be sent to the orderVirtualGuest method.
* This container will include all services that the selected computing instance has.
* If desired you may remove prices which were returned.
* @see <a href=" @see <a href="http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder" />
* @param id
* The id of the existing Virtual Guest
* @return
* The ProductOrder used to create the VirtualGust or null if not available
*/
ProductOrder getOrderTemplate(long id);
}

View File

@ -20,40 +20,32 @@ import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.jclouds.http.HttpRequest;
import org.jclouds.softlayer.features.BaseSoftLayerAsyncClientTest;
import org.jclouds.softlayer.features.BaseSoftLayerApiTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code SoftLayerAsyncClient}
* Tests behavior of {@code SoftLayerApi}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "SoftLayerAsyncClientTest")
public class SoftLayerAsyncClientTest extends BaseSoftLayerAsyncClientTest<SoftLayerAsyncClient> {
@Test(groups = "unit", testName = "SoftLayerApiTest")
public class SoftLayerApiTest extends BaseSoftLayerApiTest<SoftLayerApi> {
private SoftLayerAsyncClient asyncClient;
private SoftLayerClient syncClient;
private SoftLayerApi syncClient;
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
assert syncClient.getVirtualGuestClient() != null;
assert syncClient.getDatacenterClient() != null;
assert syncClient.getProductPackageClient() != null;
}
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
assert asyncClient.getVirtualGuestClient() != null;
assert asyncClient.getDatacenterClient() != null;
assert asyncClient.getProductPackageClient() != null;
assert syncClient.getVirtualGuestApi() != null;
assert syncClient.getDatacenterApi() != null;
assert syncClient.getProductPackageApi() != null;
}
@BeforeClass
@Override
protected void setupFactory() throws IOException {
super.setupFactory();
asyncClient = injector.getInstance(SoftLayerAsyncClient.class);
syncClient = injector.getInstance(SoftLayerClient.class);
syncClient = injector.getInstance(SoftLayerApi.class);
}
@Override

View File

@ -29,12 +29,12 @@ import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.softlayer.SoftLayerApi;
import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions;
import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter;
import org.jclouds.softlayer.domain.ProductItem;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.jclouds.softlayer.features.BaseSoftLayerClientLiveTest;
import org.jclouds.softlayer.features.BaseSoftLayerApiLiveTest;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.sshj.config.SshjSshClientModule;
@ -49,7 +49,7 @@ import com.google.inject.Injector;
import com.google.inject.Module;
@Test(groups = "live", singleThreaded = true, testName = "SoftLayerComputeServiceAdapterLiveTest")
public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientLiveTest {
public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerApiLiveTest {
private SoftLayerComputeServiceAdapter adapter;
private TemplateBuilder templateBuilder;
@ -57,12 +57,12 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL
private NodeAndInitialCredentials<VirtualGuest> guest;
@Override
protected SoftLayerClient create(Properties props, Iterable<Module> modules) {
protected SoftLayerApi create(Properties props, Iterable<Module> modules) {
Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
adapter = injector.getInstance(SoftLayerComputeServiceAdapter.class);
templateBuilder = injector.getInstance(TemplateBuilder.class);
sshFactory = injector.getInstance(SshClient.Factory.class);
return injector.getInstance(SoftLayerClient.class);
return injector.getInstance(SoftLayerApi.class);
}
@Test

View File

@ -31,7 +31,7 @@ import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.domain.Location;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.softlayer.SoftLayerApi;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.jclouds.softlayer.parse.ParseBadVirtualGuest;
import org.jclouds.softlayer.parse.ParseVirtualGuestHaltedTest;
@ -192,7 +192,7 @@ public class VirtualGuestToNodeMetadataTest {
private static class GetHardwareForVirtualGuestMock extends VirtualGuestToNodeMetadata.GetHardwareForVirtualGuest {
@SuppressWarnings("unchecked")
public GetHardwareForVirtualGuestMock() {
super(createNiceMock(SoftLayerClient.class), createNiceMock(Function.class));
super(createNiceMock(SoftLayerApi.class), createNiceMock(Function.class));
}
@Override

View File

@ -24,16 +24,16 @@ import org.jclouds.softlayer.domain.ProductPackage;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code AccountClient}
* Tests behavior of {@code AccountApi}
*
* @author Jason King
*/
@Test(groups = "live")
public class AccountClientLiveTest extends BaseSoftLayerClientLiveTest {
public class AccountApiLiveTest extends BaseSoftLayerApiLiveTest {
@Test
public void testGetActivePackages() {
Set<ProductPackage> response = api.getAccountClient().getActivePackages();
Set<ProductPackage> response = api.getAccountApi().getActivePackages();
assert null != response;
assertTrue(response.size() >= 0);

View File

@ -28,15 +28,15 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.reflect.Invokable;
/**
* Tests annotation parsing of {@code AccountAsyncClient}
* Tests annotation parsing of {@code AccountApi}
*
* @author Jason King
*/
@Test(groups = "unit")
public class AccountAsyncClientTest extends BaseSoftLayerAsyncClientTest<AccountAsyncClient> {
public class AccountApiTest extends BaseSoftLayerApiTest<AccountApi> {
public void testGetActivePackages() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(AccountAsyncClient.class, "getActivePackages");
Invokable<?, ?> method = method(AccountApi.class, "getActivePackages");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
assertRequestLineEquals(

View File

@ -17,18 +17,18 @@
package org.jclouds.softlayer.features;
import org.jclouds.apis.BaseApiLiveTest;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.softlayer.SoftLayerApi;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code SoftLayerClient}
* Tests behavior of {@code SoftLayerApi}
*
* @author Adrian Cole
*/
@Test(groups = "live")
public class BaseSoftLayerClientLiveTest extends BaseApiLiveTest<SoftLayerClient> {
public class BaseSoftLayerApiLiveTest extends BaseApiLiveTest<SoftLayerApi> {
public BaseSoftLayerClientLiveTest() {
public BaseSoftLayerApiLiveTest() {
this.provider = "softlayer";
}
}

View File

@ -27,7 +27,7 @@ import org.jclouds.softlayer.SoftLayerProviderMetadata;
/**
* @author Adrian Cole
*/
public abstract class BaseSoftLayerAsyncClientTest<T> extends BaseAsyncClientTest<T> {
public abstract class BaseSoftLayerApiTest<T> extends BaseAsyncClientTest<T> {
@Override
protected void checkFilters(HttpRequest request) {

View File

@ -30,12 +30,12 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
/**
* Tests behavior of {@code DatacenterClient}
* Tests behavior of {@code DatacenterApi}
*
* @author Adrian Cole
*/
@Test(groups = "live")
public class DatacenterClientLiveTest extends BaseSoftLayerClientLiveTest {
public class DatacenterApiLiveTest extends BaseSoftLayerApiLiveTest {
@Test
public void testListDatacenters() {
@ -79,8 +79,8 @@ public class DatacenterClientLiveTest extends BaseSoftLayerClientLiveTest {
}
}
private DatacenterClient api() {
return api.getDatacenterClient();
private DatacenterApi api() {
return api.getDatacenterApi();
}
private void checkDatacenter(Datacenter dc) {

View File

@ -30,15 +30,15 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.reflect.Invokable;
/**
* Tests annotation parsing of {@code DatacenterAsyncClient}
* Tests annotation parsing of {@code DatacenterApi}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class DatacenterAsyncClientTest extends BaseSoftLayerAsyncClientTest<DatacenterAsyncClient> {
public class DatacenterApiTest extends BaseSoftLayerApiTest<DatacenterApi> {
public void testListDatacenters() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(DatacenterAsyncClient.class, "listDatacenters");
Invokable<?, ?> method = method(DatacenterApi.class, "listDatacenters");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
assertRequestLineEquals(httpRequest,
@ -67,7 +67,7 @@ public class DatacenterAsyncClientTest extends BaseSoftLayerAsyncClientTest<Data
}
public void testGetDatacenter() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(DatacenterAsyncClient.class, "getDatacenter", long.class);
Invokable<?, ?> method = method(DatacenterApi.class, "getDatacenter", long.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
assertRequestLineEquals(httpRequest,

View File

@ -43,12 +43,12 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
/**
* Tests behavior of {@code ProductPackageClient}
* Tests behavior of {@code ProductPackageApi}
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "ProductPackageClientLiveTest")
public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
@Test(groups = "live", singleThreaded = true, testName = "ProductPackageApiLiveTest")
public class ProductPackageApiLiveTest extends BaseSoftLayerApiLiveTest {
/**
* Name of the package used for ordering virtual guests. For real this is
@ -62,24 +62,24 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
@BeforeGroups(groups = { "live" })
public void setup() {
super.setup();
client = api.getProductPackageClient();
accountClient = api.getAccountClient();
client = api.getProductPackageApi();
accountApi = api.getAccountApi();
// This is used several times, so cache to speed up the test.
cloudServerPackageId = Iterables.find(accountClient.getActivePackages(), named(CLOUD_SERVER_PACKAGE_NAME))
cloudServerPackageId = Iterables.find(accountApi.getActivePackages(), named(CLOUD_SERVER_PACKAGE_NAME))
.getId();
cloudServerProductPackage = client.getProductPackage(cloudServerPackageId);
}
private ProductPackageClient client;
private AccountClient accountClient;
private ProductPackageApi client;
private AccountApi accountApi;
private int cloudServerPackageId;
private ProductPackage cloudServerProductPackage;
@Test
public void testGetProductPackage() {
for (ProductPackage productPackage : accountClient.getActivePackages()) {
for (ProductPackage productPackage : accountApi.getActivePackages()) {
ProductPackage response = client.getProductPackage(productPackage.getId());
assert null != response;

View File

@ -28,15 +28,15 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.reflect.Invokable;
/**
* Tests annotation parsing of {@code ProductPackageAsyncClient}
* Tests annotation parsing of {@code ProductPackageApi}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ProductPackageAsyncClientTest extends BaseSoftLayerAsyncClientTest<ProductPackageAsyncClient> {
public class ProductPackageApiTest extends BaseSoftLayerApiTest<ProductPackageApi> {
public void testGetProductPackage() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ProductPackageAsyncClient.class, "getProductPackage", long.class);
Invokable<?, ?> method = method(ProductPackageApi.class, "getProductPackage", long.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
assertRequestLineEquals(

View File

@ -19,7 +19,7 @@ package org.jclouds.softlayer.features;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.internal.BaseRestClientExpectTest;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.softlayer.SoftLayerApi;
import org.testng.annotations.Test;
/**
@ -27,10 +27,10 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "SoftLayerClientExpectTest")
public class VirtualGuestClientExpectTest extends BaseRestClientExpectTest<SoftLayerClient> {
public class VirtualGuestApiExpectTest extends BaseRestClientExpectTest<SoftLayerApi> {
public VirtualGuestClientExpectTest() {
public VirtualGuestApiExpectTest() {
provider = "softlayer";
}
@ -43,16 +43,16 @@ public class VirtualGuestClientExpectTest extends BaseRestClientExpectTest<SoftL
HttpResponse found = HttpResponse.builder().statusCode(200).build();
SoftLayerClient clientWhenServiceExists = requestSendsResponse(cancelGuest11, found);
SoftLayerApi clientWhenServiceExists = requestSendsResponse(cancelGuest11, found);
assert clientWhenServiceExists.getVirtualGuestClient().cancelService(11l);
assert clientWhenServiceExists.getVirtualGuestApi().cancelService(11l);
HttpResponse notFound = HttpResponse.builder().statusCode(404).build();
SoftLayerClient clientWhenServiceDoesntExist = requestSendsResponse(cancelGuest11, notFound);
SoftLayerApi clientWhenServiceDoesntExist = requestSendsResponse(cancelGuest11, notFound);
assert !clientWhenServiceDoesntExist.getVirtualGuestClient().cancelService(11l);
assert !clientWhenServiceDoesntExist.getVirtualGuestApi().cancelService(11l);
}
}

View File

@ -29,7 +29,7 @@ import java.util.Properties;
import java.util.Random;
import java.util.Set;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.softlayer.SoftLayerApi;
import org.jclouds.softlayer.compute.functions.ProductItems;
import org.jclouds.softlayer.domain.ProductItem;
import org.jclouds.softlayer.domain.ProductItemPrice;
@ -50,12 +50,12 @@ import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VirtualGuestClient}
* Tests behavior of {@code VirtualGuestApi}
*
* @author Adrian Cole
*/
@Test(groups = "live")
public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
public class VirtualGuestApiLiveTest extends BaseSoftLayerApiLiveTest {
private static final String TEST_HOSTNAME_PREFIX = "livetest";
@ -86,9 +86,9 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
}
}
int pkgId = Iterables.find(api.getAccountClient().getActivePackages(),
named(ProductPackageClientLiveTest.CLOUD_SERVER_PACKAGE_NAME)).getId();
ProductPackage productPackage = api.getProductPackageClient().getProductPackage(pkgId);
int pkgId = Iterables.find(api.getAccountApi().getActivePackages(),
named(ProductPackageApiLiveTest.CLOUD_SERVER_PACKAGE_NAME)).getId();
ProductPackage productPackage = api.getProductPackageApi().getProductPackage(pkgId);
Iterable<ProductItem> ramItems = Iterables.filter(productPackage.getItems(), Predicates.and(categoryCode("ram"),
capacity(2.0f)));
@ -133,15 +133,15 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
private Iterable<ProductItemPrice> defaultPrices;
@Override
protected SoftLayerClient create(Properties props, Iterable<Module> modules) {
protected SoftLayerApi create(Properties props, Iterable<Module> modules) {
Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
defaultPrices = injector.getInstance(Key.get(new TypeLiteral<Iterable<ProductItemPrice>>() {
}));
return injector.getInstance(SoftLayerClient.class);
return injector.getInstance(SoftLayerApi.class);
}
private VirtualGuestClient api() {
return api.getVirtualGuestClient();
private VirtualGuestApi api() {
return api.getVirtualGuestApi();
}
private void checkVirtualGuest(VirtualGuest vg) {

View File

@ -32,15 +32,15 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.reflect.Invokable;
/**
* Tests annotation parsing of {@code VirtualGuestAsyncClient}
* Tests annotation parsing of {@code VirtualGuestApi}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<VirtualGuestAsyncClient> {
public class VirtualGuestApiTest extends BaseSoftLayerApiTest<VirtualGuestApi> {
public void testListVirtualGuests() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "listVirtualGuests");
Invokable<?, ?> method = method(VirtualGuestApi.class, "listVirtualGuests");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
assertRequestLineEquals(
@ -71,7 +71,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
}
public void testGetVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "getVirtualGuest", long.class);
Invokable<?, ?> method = method(VirtualGuestApi.class, "getVirtualGuest", long.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
assertRequestLineEquals(
@ -89,7 +89,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
}
public void testRebootHardVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "rebootHardVirtualGuest", long.class);
Invokable<?, ?> method = method(VirtualGuestApi.class, "rebootHardVirtualGuest", long.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
assertRequestLineEquals(httpRequest,
@ -106,7 +106,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
}
public void testPowerOffVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "powerOffVirtualGuest", long.class);
Invokable<?, ?> method = method(VirtualGuestApi.class, "powerOffVirtualGuest", long.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
assertRequestLineEquals(httpRequest,
@ -123,7 +123,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
}
public void testPowerOnVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "powerOnVirtualGuest", long.class);
Invokable<?, ?> method = method(VirtualGuestApi.class, "powerOnVirtualGuest", long.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
assertRequestLineEquals(httpRequest,
@ -140,7 +140,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
}
public void testPauseVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "pauseVirtualGuest", long.class);
Invokable<?, ?> method = method(VirtualGuestApi.class, "pauseVirtualGuest", long.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
assertRequestLineEquals(httpRequest,
@ -157,7 +157,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
}
public void testResumeVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "resumeVirtualGuest", long.class);
Invokable<?, ?> method = method(VirtualGuestApi.class, "resumeVirtualGuest", long.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
assertRequestLineEquals(httpRequest,